@scenar/cli 0.1.20 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/package.json +17 -5
  2. package/src/__tests__/publish-command.test.ts +46 -0
  3. package/src/__tests__/publish-flow.test.ts +220 -0
  4. package/src/__tests__/read-viewport.test.ts +45 -0
  5. package/src/__tests__/run-publish.test.ts +92 -0
  6. package/src/__tests__/serve-command.test.ts +44 -0
  7. package/src/__tests__/serve-request-path.test.ts +67 -0
  8. package/src/__tests__/serve-static-server.test.ts +88 -0
  9. package/src/api.d.ts +31 -0
  10. package/src/api.d.ts.map +1 -0
  11. package/src/api.js +28 -0
  12. package/src/api.js.map +1 -0
  13. package/src/api.ts +55 -0
  14. package/src/bundle/read-viewport.d.ts +23 -0
  15. package/src/bundle/read-viewport.d.ts.map +1 -0
  16. package/src/bundle/read-viewport.js +25 -0
  17. package/src/bundle/read-viewport.js.map +1 -0
  18. package/src/bundle/read-viewport.ts +36 -0
  19. package/src/commands/deploy.d.ts.map +1 -1
  20. package/src/commands/deploy.js +8 -24
  21. package/src/commands/deploy.js.map +1 -1
  22. package/src/commands/deploy.ts +10 -28
  23. package/src/commands/narrate.d.ts.map +1 -1
  24. package/src/commands/narrate.js +39 -170
  25. package/src/commands/narrate.js.map +1 -1
  26. package/src/commands/narrate.ts +48 -289
  27. package/src/commands/pack.d.ts.map +1 -1
  28. package/src/commands/pack.js +12 -112
  29. package/src/commands/pack.js.map +1 -1
  30. package/src/commands/pack.ts +12 -128
  31. package/src/commands/publish.d.ts +3 -0
  32. package/src/commands/publish.d.ts.map +1 -0
  33. package/src/commands/publish.js +64 -0
  34. package/src/commands/publish.js.map +1 -0
  35. package/src/commands/publish.ts +86 -0
  36. package/src/commands/render.d.ts.map +1 -1
  37. package/src/commands/render.js +12 -194
  38. package/src/commands/render.js.map +1 -1
  39. package/src/commands/render.ts +19 -286
  40. package/src/commands/serve.d.ts +3 -0
  41. package/src/commands/serve.d.ts.map +1 -0
  42. package/src/commands/serve.js +91 -0
  43. package/src/commands/serve.js.map +1 -0
  44. package/src/commands/serve.ts +112 -0
  45. package/src/index.d.ts.map +1 -1
  46. package/src/index.js +4 -0
  47. package/src/index.js.map +1 -1
  48. package/src/index.ts +4 -0
  49. package/src/narrate/run-narrate.d.ts +43 -0
  50. package/src/narrate/run-narrate.d.ts.map +1 -0
  51. package/src/narrate/run-narrate.js +174 -0
  52. package/src/narrate/run-narrate.js.map +1 -0
  53. package/src/narrate/run-narrate.ts +298 -0
  54. package/src/pack/run-pack.d.ts +34 -0
  55. package/src/pack/run-pack.d.ts.map +1 -0
  56. package/src/pack/run-pack.js +117 -0
  57. package/src/pack/run-pack.js.map +1 -0
  58. package/src/pack/run-pack.ts +163 -0
  59. package/src/publish/github.d.ts +11 -0
  60. package/src/publish/github.d.ts.map +1 -0
  61. package/src/publish/github.js +197 -0
  62. package/src/publish/github.js.map +1 -0
  63. package/src/publish/github.ts +216 -0
  64. package/src/publish/publish-flow.d.ts +110 -0
  65. package/src/publish/publish-flow.d.ts.map +1 -0
  66. package/src/publish/publish-flow.js +117 -0
  67. package/src/publish/publish-flow.js.map +1 -0
  68. package/src/publish/publish-flow.ts +199 -0
  69. package/src/publish/run-publish.d.ts +41 -0
  70. package/src/publish/run-publish.d.ts.map +1 -0
  71. package/src/publish/run-publish.js +77 -0
  72. package/src/publish/run-publish.js.map +1 -0
  73. package/src/publish/run-publish.ts +131 -0
  74. package/src/render/run-render.d.ts +31 -0
  75. package/src/render/run-render.d.ts.map +1 -0
  76. package/src/render/run-render.js +196 -0
  77. package/src/render/run-render.js.map +1 -0
  78. package/src/render/run-render.ts +287 -0
  79. package/src/serve/request-path.d.ts +23 -0
  80. package/src/serve/request-path.d.ts.map +1 -0
  81. package/src/serve/request-path.js +52 -0
  82. package/src/serve/request-path.js.map +1 -0
  83. package/src/serve/request-path.ts +55 -0
  84. package/src/serve/run-serve.d.ts +31 -0
  85. package/src/serve/run-serve.d.ts.map +1 -0
  86. package/src/serve/run-serve.js +35 -0
  87. package/src/serve/run-serve.js.map +1 -0
  88. package/src/serve/run-serve.ts +68 -0
  89. package/src/serve/static-server.d.ts +38 -0
  90. package/src/serve/static-server.d.ts.map +1 -0
  91. package/src/serve/static-server.js +91 -0
  92. package/src/serve/static-server.js.map +1 -0
  93. package/src/serve/static-server.ts +118 -0
  94. package/tsconfig.tsbuildinfo +1 -1
@@ -1,11 +1,5 @@
1
- import { resolve, join } from "node:path";
2
- import { stat, mkdir, access, writeFile, rm } from "node:fs/promises";
3
- import { pathToFileURL } from "node:url";
4
1
  import { Command } from "commander";
5
- import { loadBundle, type CliBundle } from "../util/load-bundle.js";
6
- import { generateRemotionEntry } from "../render/generate-entry.js";
7
- import { resolveProvidersPath } from "../render/resolve-providers.js";
8
- import { detectRenderExport } from "../render/detect-render-export.js";
2
+ import { runRender } from "../render/run-render.js";
9
3
 
10
4
  interface RenderOptions {
11
5
  out?: string;
@@ -22,13 +16,13 @@ export function registerRenderCommand(program: Command): void {
22
16
  .command("render")
23
17
  .description(
24
18
  "Render a scenario as an MP4 video using Remotion.\n\n" +
25
- "Accepts a scenario directory containing steps.ts and an optional\n" +
26
- "narration/ subfolder with manifest.json + audio clips.\n\n" +
27
- "When the scenario directory contains an index.tsx that exports a\n" +
28
- "renderStep function, the CLI auto-generates the Remotion entry\n" +
29
- "point — no remotion/ directory or bundle.ts needed.\n\n" +
30
- "Output defaults to ./<scenario-id>.mp4 in the current working\n" +
31
- "directory. Use --out to write to a different path.",
19
+ "Accepts a scenario directory containing steps.ts and an optional\n" +
20
+ "narration/ subfolder with manifest.json + audio clips.\n\n" +
21
+ "When the scenario directory contains an index.tsx that exports a\n" +
22
+ "renderStep function, the CLI auto-generates the Remotion entry\n" +
23
+ "point — no remotion/ directory or bundle.ts needed.\n\n" +
24
+ "Output defaults to ./<scenario-id>.mp4 in the current working\n" +
25
+ "directory. Use --out to write to a different path.",
32
26
  )
33
27
  .argument("<dir>", "path to a scenario directory (must contain steps.ts)")
34
28
  .option("--out <path>", "output file path or directory for the MP4")
@@ -42,285 +36,24 @@ export function registerRenderCommand(program: Command): void {
42
36
  "path to a module that default-exports a Remotion WebpackOverrideFn",
43
37
  )
44
38
  .action(async (dir: string, options: RenderOptions) => {
45
- const resolved = resolve(dir);
46
-
47
- let info;
48
39
  try {
49
- info = await stat(resolved);
50
- } catch {
51
- process.stderr.write(`\x1b[31mError:\x1b[0m ${dir} does not exist.\n`);
52
- process.exitCode = 1;
53
- return;
54
- }
55
-
56
- if (!info.isDirectory()) {
57
- process.stderr.write(
58
- `\x1b[31mError:\x1b[0m ${dir} is not a directory.\n` +
59
- "The render command requires a scenario directory (with steps.ts).\n",
60
- );
61
- process.exitCode = 1;
62
- return;
63
- }
64
-
65
- const fps = Number(options.fps) || 30;
66
- const width = Number(options.width) || 1920;
67
- const height = Number(options.height) || 1080;
68
-
69
- let tempDir: string | undefined;
70
-
71
- try {
72
- const bundle = await loadBundle(resolved);
73
- const scenarioId = bundle.id;
74
- const compositionId = options.compositionId ?? scenarioId;
75
- const outputPath = resolveOutputPath(options.out, scenarioId);
76
-
77
- const { entryPoint, generated } = await resolveEntryPoint({
78
- entryOption: options.entry,
79
- scenarioDir: resolved,
80
- scenarioId,
81
- compositionId,
82
- hasNarration: !!bundle.narrationManifest,
83
- fps,
84
- width,
85
- height,
40
+ const result = await runRender({
41
+ scenarioDir: dir,
42
+ out: options.out,
43
+ fps: Number(options.fps) || 30,
44
+ width: Number(options.width) || 1920,
45
+ height: Number(options.height) || 1080,
46
+ compositionId: options.compositionId,
47
+ entry: options.entry,
48
+ webpackOverride: options.webpackOverride,
49
+ onLog: (message) => process.stderr.write(`${message}\n`),
86
50
  });
87
- tempDir = generated?.tempDir;
88
-
89
- const webpackOverride = options.webpackOverride
90
- ? await loadWebpackOverride(options.webpackOverride)
91
- : undefined;
92
-
93
- process.stderr.write(`Scenario: ${scenarioId}\n`);
94
- process.stderr.write(`Steps: ${bundle.steps.length}\n`);
95
- process.stderr.write(
96
- `Audio: ${bundle.narrationManifest ? "yes (manifest found)" : "none"}\n`,
97
- );
98
- process.stderr.write(`Entry: ${generated ? "(auto-generated)" : entryPoint}\n`);
99
- if (generated?.providersPath) {
100
- process.stderr.write(`Providers: ${generated.providersPath}\n`);
101
- }
102
- if (webpackOverride) {
103
- process.stderr.write(`Webpack: custom override loaded\n`);
104
- }
105
- process.stderr.write(`Output: ${outputPath}\n`);
106
- process.stderr.write(`Config: ${width}x${height} @ ${fps}fps\n\n`);
107
51
 
108
- await renderScenario({
109
- bundle,
110
- entryPoint,
111
- compositionId,
112
- outputPath,
113
- fps,
114
- width,
115
- height,
116
- webpackOverride,
117
- });
118
-
119
- process.stderr.write(`\n\x1b[32m✓\x1b[0m Video saved to ${outputPath}\n`);
52
+ process.stderr.write(`\n\x1b[32m✓\x1b[0m Video saved to ${result.outputPath}\n`);
120
53
  } catch (error) {
121
54
  const msg = error instanceof Error ? error.message : String(error);
122
55
  process.stderr.write(`\x1b[31mError:\x1b[0m ${msg}\n`);
123
56
  process.exitCode = 1;
124
- } finally {
125
- if (tempDir) {
126
- await rm(tempDir, { recursive: true, force: true }).catch(() => {});
127
- }
128
57
  }
129
58
  });
130
59
  }
131
-
132
- // ---------------------------------------------------------------------------
133
- // Output path resolution
134
- // ---------------------------------------------------------------------------
135
-
136
- function resolveOutputPath(outOption: string | undefined, scenarioId: string): string {
137
- if (!outOption) {
138
- return resolve(`./${scenarioId}.mp4`);
139
- }
140
- if (outOption.endsWith(".mp4")) {
141
- return resolve(outOption);
142
- }
143
- return resolve(join(outOption, `${scenarioId}.mp4`));
144
- }
145
-
146
- // ---------------------------------------------------------------------------
147
- // Entry point resolution
148
- // ---------------------------------------------------------------------------
149
-
150
- interface EntryResolutionInput {
151
- entryOption: string | undefined;
152
- scenarioDir: string;
153
- scenarioId: string;
154
- compositionId: string;
155
- hasNarration: boolean;
156
- fps: number;
157
- width: number;
158
- height: number;
159
- }
160
-
161
- interface EntryResolutionResult {
162
- entryPoint: string;
163
- generated?: {
164
- tempDir: string;
165
- providersPath: string | null;
166
- };
167
- }
168
-
169
- async function resolveEntryPoint(
170
- input: EntryResolutionInput,
171
- ): Promise<EntryResolutionResult> {
172
- // Explicit --entry: use as-is, no generation.
173
- if (input.entryOption) {
174
- const resolved = resolve(input.entryOption);
175
- try {
176
- await access(resolved);
177
- } catch {
178
- throw new Error(`Remotion entry point not found: ${input.entryOption}`);
179
- }
180
- return { entryPoint: resolved };
181
- }
182
-
183
- // Auto-generate: detect renderStep export, find providers, write temp entry.
184
- const renderFilePath = await detectRenderExport(input.scenarioDir);
185
- const providersPath = await resolveProvidersPath(input.scenarioDir);
186
-
187
- const entrySource = generateRemotionEntry({
188
- scenarioDir: input.scenarioDir,
189
- renderFilePath,
190
- scenarioId: input.scenarioId,
191
- hasNarration: input.hasNarration,
192
- providersPath,
193
- fps: input.fps,
194
- width: input.width,
195
- height: input.height,
196
- compositionId: input.compositionId,
197
- });
198
-
199
- // Write the entry inside the scenario directory so webpack's standard
200
- // node_modules resolution walks up from here into the consumer project.
201
- // A /tmp/ location would fail because no node_modules exist there.
202
- const tempDir = join(input.scenarioDir, ".scenar-render");
203
- await mkdir(tempDir, { recursive: true });
204
-
205
- const entryPath = join(tempDir, "index.tsx");
206
- await writeFile(entryPath, entrySource, "utf-8");
207
-
208
- return {
209
- entryPoint: entryPath,
210
- generated: { tempDir, providersPath },
211
- };
212
- }
213
-
214
- // ---------------------------------------------------------------------------
215
- // Webpack override loading
216
- // ---------------------------------------------------------------------------
217
-
218
- async function loadWebpackOverride(
219
- overridePath: string,
220
- ): Promise<(config: unknown) => unknown> {
221
- const resolved = resolve(overridePath);
222
-
223
- try {
224
- await access(resolved);
225
- } catch {
226
- throw new Error(`Webpack override file not found: ${overridePath}`);
227
- }
228
-
229
- let mod: Record<string, unknown>;
230
- try {
231
- mod = await import(pathToFileURL(resolved).href) as Record<string, unknown>;
232
- } catch (err) {
233
- const detail = err instanceof Error ? err.message : String(err);
234
- throw new Error(
235
- `Failed to import webpack override from ${overridePath}:\n${detail}`,
236
- );
237
- }
238
-
239
- const override = (mod.default ?? mod.webpackOverride) as unknown;
240
- if (typeof override !== "function") {
241
- throw new Error(
242
- `${overridePath} does not export a webpack override function.\n\n` +
243
- "Expected a default export or named 'webpackOverride' export:\n\n" +
244
- ' import type { WebpackOverrideFn } from "@remotion/bundler";\n\n' +
245
- " const webpackOverride: WebpackOverrideFn = (config) => ({\n" +
246
- " ...config,\n" +
247
- " // your overrides\n" +
248
- " });\n\n" +
249
- " export default webpackOverride;\n",
250
- );
251
- }
252
-
253
- return override as (config: unknown) => unknown;
254
- }
255
-
256
- // ---------------------------------------------------------------------------
257
- // Render orchestration
258
- // ---------------------------------------------------------------------------
259
-
260
- interface RenderConfig {
261
- bundle: CliBundle;
262
- entryPoint: string;
263
- compositionId: string;
264
- outputPath: string;
265
- fps: number;
266
- width: number;
267
- height: number;
268
- webpackOverride?: (config: unknown) => unknown;
269
- }
270
-
271
- async function renderScenario(config: RenderConfig): Promise<void> {
272
- const bundler = await import("@remotion/bundler").catch(() => {
273
- throw new Error(
274
- "Could not load @remotion/bundler.\n" +
275
- "Install it: pnpm add @remotion/bundler@4.0.448",
276
- );
277
- });
278
-
279
- const renderer = await import("@remotion/renderer").catch(() => {
280
- throw new Error(
281
- "Could not load @remotion/renderer.\n" +
282
- "Install it: pnpm add @remotion/renderer@4.0.448",
283
- );
284
- });
285
-
286
- process.stderr.write("Bundling Remotion project...\n");
287
-
288
- const bundleOptions: Record<string, unknown> = {
289
- entryPoint: config.entryPoint,
290
- };
291
- if (config.webpackOverride) {
292
- bundleOptions.webpackOverride = config.webpackOverride;
293
- }
294
- const serveUrl = await (bundler.bundle as (opts: Record<string, unknown>) => Promise<string>)(
295
- bundleOptions,
296
- );
297
-
298
- process.stderr.write(`Selecting composition: ${config.compositionId}\n`);
299
- const composition = await renderer.selectComposition({
300
- serveUrl,
301
- id: config.compositionId,
302
- });
303
-
304
- process.stderr.write(
305
- `Composition: ${composition.width}x${composition.height} @ ${composition.fps}fps, ` +
306
- `${composition.durationInFrames} frames ` +
307
- `(${(composition.durationInFrames / composition.fps).toFixed(1)}s)\n`,
308
- );
309
-
310
- const outDir = resolve(config.outputPath, "..");
311
- await mkdir(outDir, { recursive: true });
312
-
313
- process.stderr.write("Rendering...\n");
314
- await renderer.renderMedia({
315
- composition,
316
- serveUrl,
317
- codec: "h264" as const,
318
- outputLocation: config.outputPath,
319
- onProgress: ({ progress }) => {
320
- const pct = Math.round(progress * 100);
321
- process.stderr.write(`\r Progress: ${pct}%`);
322
- },
323
- });
324
-
325
- process.stderr.write("\n");
326
- }
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare function registerServeCommand(program: Command): void;
3
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/commands/serve.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4D3D"}
@@ -0,0 +1,91 @@
1
+ import { spawn } from "node:child_process";
2
+ import { platform } from "node:process";
3
+ import { runServe } from "../serve/run-serve.js";
4
+ /** Vite's preview port — the conventional "serve a built site" port. */
5
+ const DEFAULT_PORT = 4173;
6
+ /** Bind to loopback by default; a preview is a single-developer tool. */
7
+ const DEFAULT_HOST = "localhost";
8
+ export function registerServeCommand(program) {
9
+ program
10
+ .command("serve")
11
+ .description("Serve a packed bundle locally and print its embed URL.\n\n" +
12
+ "Takes a bundle directory produced by `scenar pack` and serves it as a\n" +
13
+ "static site on http://localhost:4173 (override with --port/--host).\n" +
14
+ "Prints the URL plus a ready-to-paste responsive <iframe> snippet, then\n" +
15
+ "stays running until you press Ctrl+C.\n\n" +
16
+ "This is the zero-infrastructure way to view an embed: no backend, no\n" +
17
+ "account. For a permanent public URL, use `scenar publish` (GitHub\n" +
18
+ "Pages) or `scenar deploy` (Scenar Cloud).")
19
+ .argument("<bundleDir>", "path to a packed bundle directory (from scenar pack)")
20
+ .option("--port <number>", `port to listen on (default: ${DEFAULT_PORT})`, String(DEFAULT_PORT))
21
+ .option("--host <host>", `host/interface to bind (default: ${DEFAULT_HOST})`, DEFAULT_HOST)
22
+ .option("--open", "open the embed in your default browser")
23
+ .action(async (bundleDir, options) => {
24
+ try {
25
+ const port = Number(options.port);
26
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
27
+ throw new Error(`invalid --port "${options.port}"; expected an integer between 0 and 65535.`);
28
+ }
29
+ const host = options.host ?? DEFAULT_HOST;
30
+ let result;
31
+ try {
32
+ result = await runServe({ bundleDir, port, host });
33
+ }
34
+ catch (error) {
35
+ if (isAddrInUse(error)) {
36
+ throw new Error(`port ${port} is already in use. Stop the other process or pass --port <number>.`);
37
+ }
38
+ throw error;
39
+ }
40
+ process.stderr.write(`\n\x1b[32m✓\x1b[0m Serving at ${result.url}\n`);
41
+ if (!result.recordedViewport) {
42
+ process.stderr.write(" Note: no recorded viewport; snippet uses the default " +
43
+ `${result.viewport.width}x${result.viewport.height}. Re-pack with the current CLI ` +
44
+ "to embed at the exact aspect ratio.\n");
45
+ }
46
+ process.stderr.write("\n Embed snippet (paste into any page):\n\n");
47
+ process.stderr.write(`${indent(result.snippet)}\n`);
48
+ process.stderr.write("\n Press Ctrl+C to stop.\n");
49
+ if (options.open) {
50
+ openInBrowser(result.url);
51
+ }
52
+ await runUntilInterrupted(result.handle);
53
+ }
54
+ catch (error) {
55
+ const msg = error instanceof Error ? error.message : String(error);
56
+ process.stderr.write(`\x1b[31mError:\x1b[0m ${msg}\n`);
57
+ process.exitCode = 1;
58
+ }
59
+ });
60
+ }
61
+ /** Block until SIGINT/SIGTERM, then close the server cleanly. */
62
+ function runUntilInterrupted(handle) {
63
+ return new Promise((resolvePromise) => {
64
+ const shutdown = () => {
65
+ process.stderr.write("\nStopping...\n");
66
+ void handle.close().finally(() => resolvePromise());
67
+ };
68
+ process.once("SIGINT", shutdown);
69
+ process.once("SIGTERM", shutdown);
70
+ });
71
+ }
72
+ /** Best-effort: launch the OS default browser. Failures are silent (non-fatal). */
73
+ function openInBrowser(url) {
74
+ const command = platform === "darwin" ? "open" : platform === "win32" ? "start" : "xdg-open";
75
+ try {
76
+ const child = spawn(command, [url], { stdio: "ignore", detached: true, shell: platform === "win32" });
77
+ child.on("error", () => { });
78
+ child.unref();
79
+ }
80
+ catch {
81
+ // Opening a browser is a convenience; never fail the command over it.
82
+ }
83
+ }
84
+ function isAddrInUse(error) {
85
+ return typeof error === "object" && error !== null && error.code === "EADDRINUSE";
86
+ }
87
+ /** Indent every line by two spaces (for nesting a block under a heading). */
88
+ function indent(block) {
89
+ return block.replace(/^/gm, " ");
90
+ }
91
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/commands/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,wEAAwE;AACxE,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B,yEAAyE;AACzE,MAAM,YAAY,GAAG,WAAW,CAAC;AAQjC,MAAM,UAAU,oBAAoB,CAAC,OAAgB;IACnD,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CACV,4DAA4D;QAC1D,yEAAyE;QACzE,uEAAuE;QACvE,0EAA0E;QAC1E,2CAA2C;QAC3C,wEAAwE;QACxE,qEAAqE;QACrE,2CAA2C,CAC9C;SACA,QAAQ,CAAC,aAAa,EAAE,sDAAsD,CAAC;SAC/E,MAAM,CAAC,iBAAiB,EAAE,+BAA+B,YAAY,GAAG,EAAE,MAAM,CAAC,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AQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;IAC7F,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,KAAK,OAAO,EAAE,CAAC,CAAC;QACtG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC5B,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,sEAAsE;IACxE,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAA2B,CAAC,IAAI,KAAK,YAAY,CAAC;AAC3G,CAAC;AAED,6EAA6E;AAC7E,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { spawn } from "node:child_process";
2
+ import { platform } from "node:process";
3
+ import { Command } from "commander";
4
+ import { runServe } from "../serve/run-serve.js";
5
+ import type { BundleServerHandle } from "../serve/static-server.js";
6
+
7
+ /** Vite's preview port — the conventional "serve a built site" port. */
8
+ const DEFAULT_PORT = 4173;
9
+
10
+ /** Bind to loopback by default; a preview is a single-developer tool. */
11
+ const DEFAULT_HOST = "localhost";
12
+
13
+ interface ServeOptions {
14
+ port?: string;
15
+ host?: string;
16
+ open?: boolean;
17
+ }
18
+
19
+ export function registerServeCommand(program: Command): void {
20
+ program
21
+ .command("serve")
22
+ .description(
23
+ "Serve a packed bundle locally and print its embed URL.\n\n" +
24
+ "Takes a bundle directory produced by `scenar pack` and serves it as a\n" +
25
+ "static site on http://localhost:4173 (override with --port/--host).\n" +
26
+ "Prints the URL plus a ready-to-paste responsive <iframe> snippet, then\n" +
27
+ "stays running until you press Ctrl+C.\n\n" +
28
+ "This is the zero-infrastructure way to view an embed: no backend, no\n" +
29
+ "account. For a permanent public URL, use `scenar publish` (GitHub\n" +
30
+ "Pages) or `scenar deploy` (Scenar Cloud).",
31
+ )
32
+ .argument("<bundleDir>", "path to a packed bundle directory (from scenar pack)")
33
+ .option("--port <number>", `port to listen on (default: ${DEFAULT_PORT})`, String(DEFAULT_PORT))
34
+ .option("--host <host>", `host/interface to bind (default: ${DEFAULT_HOST})`, DEFAULT_HOST)
35
+ .option("--open", "open the embed in your default browser")
36
+ .action(async (bundleDir: string, options: ServeOptions) => {
37
+ try {
38
+ const port = Number(options.port);
39
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
40
+ throw new Error(`invalid --port "${options.port}"; expected an integer between 0 and 65535.`);
41
+ }
42
+ const host = options.host ?? DEFAULT_HOST;
43
+
44
+ let result;
45
+ try {
46
+ result = await runServe({ bundleDir, port, host });
47
+ } catch (error) {
48
+ if (isAddrInUse(error)) {
49
+ throw new Error(
50
+ `port ${port} is already in use. Stop the other process or pass --port <number>.`,
51
+ );
52
+ }
53
+ throw error;
54
+ }
55
+
56
+ process.stderr.write(`\n\x1b[32m✓\x1b[0m Serving at ${result.url}\n`);
57
+ if (!result.recordedViewport) {
58
+ process.stderr.write(
59
+ " Note: no recorded viewport; snippet uses the default " +
60
+ `${result.viewport.width}x${result.viewport.height}. Re-pack with the current CLI ` +
61
+ "to embed at the exact aspect ratio.\n",
62
+ );
63
+ }
64
+ process.stderr.write("\n Embed snippet (paste into any page):\n\n");
65
+ process.stderr.write(`${indent(result.snippet)}\n`);
66
+ process.stderr.write("\n Press Ctrl+C to stop.\n");
67
+
68
+ if (options.open) {
69
+ openInBrowser(result.url);
70
+ }
71
+
72
+ await runUntilInterrupted(result.handle);
73
+ } catch (error) {
74
+ const msg = error instanceof Error ? error.message : String(error);
75
+ process.stderr.write(`\x1b[31mError:\x1b[0m ${msg}\n`);
76
+ process.exitCode = 1;
77
+ }
78
+ });
79
+ }
80
+
81
+ /** Block until SIGINT/SIGTERM, then close the server cleanly. */
82
+ function runUntilInterrupted(handle: BundleServerHandle): Promise<void> {
83
+ return new Promise<void>((resolvePromise) => {
84
+ const shutdown = () => {
85
+ process.stderr.write("\nStopping...\n");
86
+ void handle.close().finally(() => resolvePromise());
87
+ };
88
+ process.once("SIGINT", shutdown);
89
+ process.once("SIGTERM", shutdown);
90
+ });
91
+ }
92
+
93
+ /** Best-effort: launch the OS default browser. Failures are silent (non-fatal). */
94
+ function openInBrowser(url: string): void {
95
+ const command = platform === "darwin" ? "open" : platform === "win32" ? "start" : "xdg-open";
96
+ try {
97
+ const child = spawn(command, [url], { stdio: "ignore", detached: true, shell: platform === "win32" });
98
+ child.on("error", () => {});
99
+ child.unref();
100
+ } catch {
101
+ // Opening a browser is a convenience; never fail the command over it.
102
+ }
103
+ }
104
+
105
+ function isAddrInUse(error: unknown): boolean {
106
+ return typeof error === "object" && error !== null && (error as { code?: string }).code === "EADDRINUSE";
107
+ }
108
+
109
+ /** Indent every line by two spaces (for nesting a block under a heading). */
110
+ function indent(block: string): string {
111
+ return block.replace(/^/gm, " ");
112
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,aAAa,IAAI,OAAO,CAgBvC;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAGxC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,wBAAgB,aAAa,IAAI,OAAO,CAkBvC;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAGxC"}
package/src/index.js CHANGED
@@ -4,6 +4,8 @@ import { registerNarrateCommand } from "./commands/narrate.js";
4
4
  import { registerPreviewCommand } from "./commands/preview.js";
5
5
  import { registerRenderCommand } from "./commands/render.js";
6
6
  import { registerPackCommand } from "./commands/pack.js";
7
+ import { registerServeCommand } from "./commands/serve.js";
8
+ import { registerPublishCommand } from "./commands/publish.js";
7
9
  import { registerDeployCommand } from "./commands/deploy.js";
8
10
  export function createProgram() {
9
11
  const program = new Command();
@@ -16,6 +18,8 @@ export function createProgram() {
16
18
  registerRenderCommand(program);
17
19
  registerPreviewCommand(program);
18
20
  registerPackCommand(program);
21
+ registerServeCommand(program);
22
+ registerPublishCommand(program);
19
23
  registerDeployCommand(program);
20
24
  return program;
21
25
  }
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,UAAU,aAAa;IAC3B,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,OAAO;SACJ,IAAI,CAAC,QAAQ,CAAC;SACd,WAAW,CAAC,8FAA8F,CAAC;SAC3G,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB,uBAAuB,CAAC,OAAO,CAAC,CAAC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,CAAC,OAAO,CAAC,CAAC;IAChC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC7B,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAChC,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAE/B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,IAAc;IAChC,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ import { registerNarrateCommand } from "./commands/narrate.js";
4
4
  import { registerPreviewCommand } from "./commands/preview.js";
5
5
  import { registerRenderCommand } from "./commands/render.js";
6
6
  import { registerPackCommand } from "./commands/pack.js";
7
+ import { registerServeCommand } from "./commands/serve.js";
8
+ import { registerPublishCommand } from "./commands/publish.js";
7
9
  import { registerDeployCommand } from "./commands/deploy.js";
8
10
 
9
11
  export function createProgram(): Command {
@@ -19,6 +21,8 @@ export function createProgram(): Command {
19
21
  registerRenderCommand(program);
20
22
  registerPreviewCommand(program);
21
23
  registerPackCommand(program);
24
+ registerServeCommand(program);
25
+ registerPublishCommand(program);
22
26
  registerDeployCommand(program);
23
27
 
24
28
  return program;
@@ -0,0 +1,43 @@
1
+ /** Options for {@link runNarrate}. Paths may be relative; resolved here. */
2
+ export interface RunNarrateOptions {
3
+ /** A scenario YAML file, a .ts steps file, or a directory of scenarios. */
4
+ readonly target: string;
5
+ /** TTS provider name: echogarden, edge-tts, or openai (default echogarden). */
6
+ readonly tts?: string;
7
+ /** Output directory for audio (default: alongside the scenario). */
8
+ readonly out?: string;
9
+ /** Voice name (provider-specific). */
10
+ readonly voice?: string;
11
+ /** URL path prefix for the `src` fields written into the manifest. */
12
+ readonly baseUrl?: string;
13
+ /** Progress sink for per-step/per-scenario messages. */
14
+ readonly onLog?: (message: string) => void;
15
+ }
16
+ /** Per-scenario narration outcome. */
17
+ export interface NarratedScenario {
18
+ readonly id: string;
19
+ readonly generated: number;
20
+ readonly cached: number;
21
+ /** True when the scenario had no narration text (nothing to synthesize). */
22
+ readonly skipped: boolean;
23
+ }
24
+ /** Aggregate result of a narrate run. */
25
+ export interface NarrateResult {
26
+ readonly mode: "file" | "directory";
27
+ readonly scenarios: NarratedScenario[];
28
+ readonly totalGenerated: number;
29
+ readonly totalCached: number;
30
+ readonly totalSkipped: number;
31
+ readonly errors: Array<{
32
+ id: string;
33
+ message: string;
34
+ }>;
35
+ }
36
+ /**
37
+ * Generate narration audio for a scenario file or a directory of scenarios —
38
+ * the pure orchestration behind `scenar narrate`. Resolves the TTS provider,
39
+ * synthesizes per-step audio (incremental via a content-hash cache), writes each
40
+ * scenario's manifest, and returns aggregate stats. No process/exit coupling.
41
+ */
42
+ export declare function runNarrate(options: RunNarrateOptions): Promise<NarrateResult>;
43
+ //# sourceMappingURL=run-narrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-narrate.d.ts","sourceRoot":"","sources":["../../../src/narrate/run-narrate.ts"],"names":[],"mappings":"AAkBA,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAA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