mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 09:16:55 +00:00
fix(cli): split add's per-item install, and keep soundfx folders as sfx
This commit is contained in:
@@ -173,36 +173,43 @@ export function severalAddJson(
|
||||
return installJson(results, errors);
|
||||
}
|
||||
|
||||
async function installEach(
|
||||
names: readonly string[],
|
||||
context: {
|
||||
projectDir: string;
|
||||
force: boolean | undefined;
|
||||
vars: string | undefined;
|
||||
json: boolean;
|
||||
},
|
||||
) {
|
||||
interface InstallContext {
|
||||
projectDir: string;
|
||||
force: boolean | undefined;
|
||||
vars: string | undefined;
|
||||
json: boolean;
|
||||
}
|
||||
|
||||
type InstallOutcome = { result: RunAddResult } | { name: string; error: string };
|
||||
|
||||
async function installOne(name: string, context: InstallContext): Promise<InstallOutcome> {
|
||||
try {
|
||||
const result = await runAdd({
|
||||
name,
|
||||
projectDir: context.projectDir,
|
||||
skipClipboard: true,
|
||||
force: context.force,
|
||||
vars: context.vars,
|
||||
});
|
||||
if (!context.json) {
|
||||
for (const warning of result.warnings) console.log(` ${c.warn("Warning:")} ${warning}`);
|
||||
console.log(` ${c.success("✓")} ${result.name}`);
|
||||
}
|
||||
return { result };
|
||||
} catch (err) {
|
||||
const reason = err instanceof Error ? err.message : String(err);
|
||||
if (!context.json) console.log(` ${c.error("✗")} ${name} (skipped: ${reason})`);
|
||||
return { name, error: reason };
|
||||
}
|
||||
}
|
||||
|
||||
async function installEach(names: readonly string[], context: InstallContext) {
|
||||
const results: RunAddResult[] = [];
|
||||
const errors: Array<{ name: string; error: string }> = [];
|
||||
for (const name of names) {
|
||||
try {
|
||||
const result = await runAdd({
|
||||
name,
|
||||
projectDir: context.projectDir,
|
||||
skipClipboard: true,
|
||||
force: context.force,
|
||||
vars: context.vars,
|
||||
});
|
||||
results.push(result);
|
||||
for (const warning of result.warnings) {
|
||||
if (!context.json) console.log(` ${c.warn("Warning:")} ${warning}`);
|
||||
}
|
||||
if (!context.json) console.log(` ${c.success("✓")} ${result.name}`);
|
||||
} catch (err) {
|
||||
const reason = err instanceof Error ? err.message : String(err);
|
||||
errors.push({ name, error: reason });
|
||||
if (!context.json) console.log(` ${c.error("✗")} ${name} (skipped: ${reason})`);
|
||||
}
|
||||
const outcome = await installOne(name, context);
|
||||
if ("result" in outcome) results.push(outcome.result);
|
||||
else errors.push(outcome);
|
||||
}
|
||||
return { results, errors };
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ function audioKind(filePath) {
|
||||
const words = filePath.toLowerCase().split(/[^a-z0-9]+/);
|
||||
const has = (test) => words.some(test);
|
||||
if (has((w) => w === "bgm" || w === "music" || w === "soundtrack")) return "bgm";
|
||||
if (has((w) => w === "sfx" || w === "fx" || w === "sound" || w === "sounds")) return "sfx";
|
||||
if (has((w) => w === "sfx" || w === "fx" || (w.startsWith("sound") && w !== "soundtrack")))
|
||||
return "sfx";
|
||||
if (has((w) => w.startsWith("voice") || w.startsWith("narrat"))) return "voice";
|
||||
return "bgm";
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ function runTests() {
|
||||
drop("narration.mp3");
|
||||
drop("soundtrack/main.mp3");
|
||||
drop("track.mp3");
|
||||
drop("soundfx/pop.mp3");
|
||||
const types = Object.fromEntries(
|
||||
adoptExistingAssets(tmp).map((record) => [record.path, record.type]),
|
||||
);
|
||||
@@ -90,6 +91,7 @@ function runTests() {
|
||||
"assets/narration.mp3": "voice",
|
||||
"assets/soundtrack/main.mp3": "bgm",
|
||||
"assets/track.mp3": "bgm",
|
||||
"assets/soundfx/pop.mp3": "sfx",
|
||||
});
|
||||
cleanup();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user