MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / run

Function run

packages/cli/src/commands/preview.ts:146–284  ·  view source on GitHub ↗
({ args })

Source from the content-addressed store, hash-verified

144 },
145 },
146 async run({ args }) {
147 const startPort = parseInt(args.port ?? "3002", 10);
148 const preferredContextPort = hasExplicitPreviewPort(process.argv) ? startPort : undefined;
149
150 // --list: scan and display active servers
151 if (args.list) {
152 const servers = await scanActiveServers(startPort);
153 if (servers.length === 0) {
154 console.log("\n No active preview servers found.\n");
155 return;
156 }
157 console.log(`\n ${c.bold("Active preview servers:")}\n`);
158 for (const s of servers) {
159 const pidStr = s.pid ? c.dim(` (PID ${s.pid})`) : "";
160 console.log(
161 ` ${c.accent(`Port ${s.port}`)} ${s.projectName} ${c.dim(s.projectDir)}${pidStr}`,
162 );
163 }
164 console.log(`\n ${servers.length} server${servers.length === 1 ? "" : "s"} running.\n`);
165 return;
166 }
167
168 // --kill-all: kill all active servers
169 if (args["kill-all"]) {
170 const servers = await scanActiveServers(startPort);
171 if (servers.length === 0) {
172 console.log("\n No active preview servers to kill.\n");
173 return;
174 }
175 const killed = await killActiveServers(startPort);
176 console.log(`\n Killed ${killed} preview server${killed === 1 ? "" : "s"}.\n`);
177 return;
178 }
179
180 if (args.context) {
181 const project = resolveProject(args.dir);
182 return printCurrentContext(project.dir, startPort, {
183 json: Boolean(args.json),
184 fields: args["context-fields"] as string | undefined,
185 detail: args["context-detail"] as string | undefined,
186 ...(preferredContextPort === undefined ? {} : { preferredPort: preferredContextPort }),
187 });
188 }
189
190 if (args.selection) {
191 const project = resolveProject(args.dir);
192 return printCurrentSelection(
193 project.dir,
194 startPort,
195 Boolean(args.json),
196 preferredContextPort,
197 );
198 }
199
200 // Kill orphaned chrome-headless-shell processes from previous crashed sessions.
201 const orphansKilled = killOrphanedProcesses();
202 if (orphansKilled > 0) {
203 console.log(

Callers

nothing calls this directly

Calls 15

hasExplicitPreviewPortFunction · 0.85
scanActiveServersFunction · 0.85
killActiveServersFunction · 0.85
printCurrentContextFunction · 0.85
printCurrentSelectionFunction · 0.85
killOrphanedProcessesFunction · 0.85
basenameFunction · 0.85
lintProjectFunction · 0.85
formatLintFindingsFunction · 0.85
parseRemoteDebuggingPortFunction · 0.85
isDevModeFunction · 0.85

Tested by

no test coverage detected