Skip to content

Commit d47816d

Browse files
committed
fix(cli): wire --video onto from-file even with --example blank
One resolver picks the scaffold. Spawned init --video asserts a-roll src.
1 parent f0728ac commit d47816d

2 files changed

Lines changed: 40 additions & 18 deletions

File tree

‎packages/cli/src/commands/init.test.ts‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { describe, expect, it } from "vitest";
22
import { spawnSync } from "node:child_process";
3-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3+
import {
4+
copyFileSync,
5+
existsSync,
6+
mkdirSync,
7+
mkdtempSync,
8+
readFileSync,
9+
rmSync,
10+
writeFileSync,
11+
} from "node:fs";
412
import { tmpdir } from "node:os";
513
import { join, resolve } from "node:path";
614
import { fileURLToPath } from "node:url";
@@ -192,20 +200,32 @@ describe("hyperframes init flag rename", () => {
192200
expect(injected).not.toContain("setTimeout");
193201
});
194202

195-
it("packs from-file and selects it when --video is set without --example", () => {
203+
it("packs from-file and wires --video into the composition", () => {
196204
const copySource = readFileSync(
197205
new URL("../../scripts/build-copy.mjs", import.meta.url),
198206
"utf-8",
199207
);
200-
expect(copySource).toContain('"from-file"');
201-
expect(copySource).not.toMatch(/for \(const tmpl of \[[^\]]*"[^"]*agent[^"]*"/);
202-
expect(initSource).toMatch(/videoFlag \|\| audioFlag \? "from-file"/);
203-
expect(initSource).toMatch(
204-
/else if \(videoFlag \|\| audioFlag\) \{\s*templateId = "from-file"/,
208+
expect(copySource).toContain('for (const tmpl of ["blank", "from-file", "_shared"])');
209+
const dir = mkdtempSync(join(tmpdir(), "hf-init-test-"));
210+
const target = join(dir, "proj");
211+
const clip = join(dir, "clip.mp4");
212+
copyFileSync(
213+
resolve(
214+
fileURLToPath(import.meta.url),
215+
"../../../../studio/tests/e2e/fixtures/design-panel-qa/assets/test.mp4",
216+
),
217+
clip,
205218
);
206-
expect(
207-
existsSync(resolve(fileURLToPath(import.meta.url), "../../templates/from-file/index.html")),
208-
).toBe(true);
219+
try {
220+
const res = runInit([target, "--non-interactive", "--skip-transcribe", "--video", clip]);
221+
expect(res.status).toBe(0);
222+
const html = readFileSync(join(target, "index.html"), "utf-8");
223+
expect(html).toContain('id="a-roll"');
224+
expect(html).toContain('src="clip.mp4"');
225+
expect(existsSync(join(target, "clip.mp4"))).toBe(true);
226+
} finally {
227+
rmSync(dir, { recursive: true, force: true });
228+
}
209229
});
210230

211231
it("-v works as the short alias for --video", () => {

‎packages/cli/src/commands/init.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ import {
5454
type CanvasResolution,
5555
} from "@hyperframes/core";
5656

57+
function resolveScaffoldTemplateId(exampleFlag: string | undefined, hasMediaFile: boolean): string {
58+
const example = exampleFlag === "agent" ? "blank" : exampleFlag;
59+
if (example && example !== "blank") return example;
60+
if (hasMediaFile) return "from-file";
61+
return "blank";
62+
}
63+
5764
interface VideoMeta {
5865
durationSeconds: number;
5966
width: number;
@@ -822,10 +829,7 @@ export default defineCommand({
822829
// Non-interactive mode — all inputs from flags, defaults where missing
823830
// -----------------------------------------------------------------------
824831
if (!interactive) {
825-
const templateId =
826-
exampleFlag === "agent"
827-
? "blank"
828-
: (exampleFlag ?? (videoFlag || audioFlag ? "from-file" : "blank"));
832+
const templateId = resolveScaffoldTemplateId(exampleFlag, Boolean(videoFlag || audioFlag));
829833
const name = args.name ?? "my-video";
830834
const destDir = resolve(name);
831835

@@ -1086,10 +1090,8 @@ export default defineCommand({
10861090
// 3. Pick example — skip prompt if --example was provided
10871091
let templateId: string;
10881092

1089-
if (exampleFlag) {
1090-
templateId = exampleFlag === "agent" ? "blank" : exampleFlag;
1091-
} else if (videoFlag || audioFlag) {
1092-
templateId = "from-file";
1093+
if (exampleFlag || videoFlag || audioFlag) {
1094+
templateId = resolveScaffoldTemplateId(exampleFlag, Boolean(videoFlag || audioFlag));
10931095
} else {
10941096
// Resolve full template list (bundled + remote)
10951097
const allTemplates = await resolveTemplateList();

0 commit comments

Comments
 (0)