mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-04 07:19:52 +00:00
Merge pull request #1527 from heygen-com/fix/capture-default-output
fix(cli): default `capture` output to ./capture (auto-suffix capture-2, capture-3 on re-run)
This commit is contained in:
@@ -3,8 +3,8 @@ import { resolve } from "node:path";
|
||||
import type { Example } from "./_examples.js";
|
||||
|
||||
export const examples: Example[] = [
|
||||
["Capture a website", "hyperframes capture https://stripe.com"],
|
||||
["Capture to a specific directory", "hyperframes capture https://linear.app -o linear-video"],
|
||||
["Capture a website into ./capture/", "hyperframes capture https://stripe.com"],
|
||||
["Capture to a different directory", "hyperframes capture https://linear.app -o linear-video"],
|
||||
["JSON output for AI agents", "hyperframes capture https://example.com --json"],
|
||||
[
|
||||
"Pull a video from the captured manifest by index",
|
||||
@@ -29,7 +29,7 @@ export default defineCommand({
|
||||
},
|
||||
output: {
|
||||
type: "string",
|
||||
description: "Output directory name",
|
||||
description: "Output directory name (default: ./capture, then ./capture-2/, ./capture-3/, …)",
|
||||
alias: "o",
|
||||
},
|
||||
"skip-assets": {
|
||||
@@ -69,6 +69,7 @@ export default defineCommand({
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
// fallow-ignore-next-line complexity
|
||||
async run({ args }) {
|
||||
if (args.video) {
|
||||
const { runVideoMode } = await import("./capture/video.js");
|
||||
@@ -96,13 +97,25 @@ export default defineCommand({
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Determine output directory — default to captures/<hostname> to keep repo root clean
|
||||
let outputName = args.output as string | undefined;
|
||||
if (!outputName) {
|
||||
const hostname = new URL(url).hostname.replace(/^www\./, "");
|
||||
outputName = `captures/${hostname.replace(/\./g, "-")}`;
|
||||
const isDefaultOutput = !args.output;
|
||||
let outputName = (args.output as string | undefined) ?? "capture";
|
||||
let outputDir = resolve(outputName);
|
||||
|
||||
if (isDefaultOutput) {
|
||||
const { existsSync } = await import("node:fs");
|
||||
// Auto-suffix when ./capture/ is taken: capture-2, capture-3, … so re-runs
|
||||
// never silently merge into a previous capture's artifacts.
|
||||
let n = 2;
|
||||
while (existsSync(outputDir) && n < 100) {
|
||||
outputName = `capture-${n}`;
|
||||
outputDir = resolve(outputName);
|
||||
n++;
|
||||
}
|
||||
if (existsSync(outputDir)) {
|
||||
console.error(`./capture-{2..99} are all taken. Pass -o <name> to pick a directory.`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
const outputDir = resolve(outputName);
|
||||
|
||||
const isJson = args.json as boolean;
|
||||
|
||||
@@ -110,6 +123,9 @@ export default defineCommand({
|
||||
const { c } = await import("../ui/colors.js");
|
||||
console.log();
|
||||
console.log(c.dim("◆") + " Capturing " + c.bold(url));
|
||||
if (isDefaultOutput && outputName !== "capture") {
|
||||
console.log(` ${c.dim(`(./capture/ exists; writing to ./${outputName}/)`)}`);
|
||||
}
|
||||
console.log();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,8 +84,8 @@ async function extractVideoFrameToBuffer(
|
||||
}
|
||||
|
||||
export const examples: Example[] = [
|
||||
["Capture 5 key frames from a composition", "snapshot captures/stripe"],
|
||||
["Capture 10 evenly-spaced frames", "snapshot captures/stripe --frames 10"],
|
||||
["Capture 5 key frames from a composition", "snapshot capture"],
|
||||
["Capture 10 evenly-spaced frames", "snapshot capture --frames 10"],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user