Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/cli/src/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,30 @@ describe("hyperframes init flag rename", () => {
}
});

it("wires --audio into the composition without creating a video clip", () => {
const dir = mkdtempSync(join(tmpdir(), "hf-init-audio-test-"));
const target = join(dir, "proj");
const audio = join(dir, "track.wav");
copyFileSync(
resolve(
fileURLToPath(import.meta.url),
"../../../../producer/tests/audio-mux-parity/src/assets/tone.wav",
),
audio,
);
try {
const res = runInit([target, "--non-interactive", "--skip-transcribe", "--audio", audio]);
expect(res.status).toBe(0);
const html = readFileSync(join(target, "index.html"), "utf-8");
expect(html).toMatch(/<audio\b[^>]*src="track\.wav"/);
expect(html).not.toMatch(/<video\b/);
expect(html).not.toContain("__VIDEO_SRC__");
expect(readFileSync(join(target, "track.wav"))).toEqual(readFileSync(audio));
} finally {
rmSync(dir, { recursive: true, force: true });
}
});

it("uses the video stream duration when audio outlasts the final video frame", () => {
expect(
resolveVideoDurationSeconds({
Expand Down
16 changes: 12 additions & 4 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ function patchVideoSrc(
dir: string,
videoFilename: string | undefined,
durationSeconds?: number,
audioFilename?: string,
): void {
const htmlFiles = readdirSync(dir, { withFileTypes: true, recursive: true })
.filter((e) => e.isFile() && e.name.endsWith(".html"))
Expand All @@ -360,9 +361,13 @@ function patchVideoSrc(
// Remove video elements with placeholder src
content = content.replace(/<video[^>]*src="__VIDEO_SRC__"[^>]*>[\s\S]*?<\/video>/g, "");
content = content.replace(/<video[^>]*src="__VIDEO_SRC__"[^>]*>/g, "");
// Remove audio elements with placeholder src
content = content.replace(/<audio[^>]*src="__VIDEO_SRC__"[^>]*>[\s\S]*?<\/audio>/g, "");
content = content.replace(/<audio[^>]*src="__VIDEO_SRC__"[^>]*>/g, "");
if (audioFilename) {
content = content.replaceAll("__VIDEO_SRC__", audioFilename);
} else {
// Remove audio elements with placeholder src
content = content.replace(/<audio[^>]*src="__VIDEO_SRC__"[^>]*>[\s\S]*?<\/audio>/g, "");
content = content.replace(/<audio[^>]*src="__VIDEO_SRC__"[^>]*>/g, "");
}
}
// Patch duration — use probed duration or default
const dur = durationSeconds ? String(Math.round(durationSeconds * 100) / 100) : "10";
Expand Down Expand Up @@ -561,6 +566,7 @@ async function scaffoldProject(
tailwind = false,
resolution?: CanvasResolution,
authoringSkill?: string,
localAudioName?: string,
): Promise<void> {
mkdirSync(destDir, { recursive: true });

Expand All @@ -573,7 +579,7 @@ async function scaffoldProject(
} else {
await fetchRemoteTemplate(templateId, destDir);
}
patchVideoSrc(destDir, localVideoName, durationSeconds);
patchVideoSrc(destDir, localVideoName, durationSeconds, localAudioName);
if (tailwind) writeTailwindSupport(destDir);
if (resolution) applyResolutionPreset(destDir, resolution);

Expand Down Expand Up @@ -913,6 +919,7 @@ export default defineCommand({
tailwind,
resolutionPreset,
args.skill,
audioFlag ? basename(audioFlag) : undefined,
);
} catch (err) {
console.error(
Expand Down Expand Up @@ -1128,6 +1135,7 @@ export default defineCommand({
tailwind,
resolutionPreset,
args.skill,
audioFlag ? basename(audioFlag) : undefined,
);
if (!isBundled) {
spin.stop(c.success(`Downloaded ${templateId}`));
Expand Down