mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix(cli): default capture output to ./capture/ (auto-suffix capture-2/, capture-3/ on re-run)
`hyperframes capture <url>` (no -o) used to dump into `./captures/<hostname>/`, which buries the project two levels deep and silently merges re-runs into the previous dir — file-by-file, so leftover screenshots / assets from the prior run stay mixed in and any later `glob` sees both. Switch the default to `./capture/`. When it already exists, auto-suffix to `./capture-2/`, `./capture-3/`, … (up to -99). Each capture is its own clean directory — no crud, no friction, no clobber. The CLI prints a one-line note when the suffix kicks in so the user sees which dir actually got written. Explicit `-o <name>` is unaffected (still overwrite-tolerant).
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