Files
hyperframes/scripts/generate-skill-module-copies.mjs
T
Miguel Ángel 49671b73dd feat(media-use): source sound effects from Openverse with the bundled library offline (#5753)
* feat(media-use): source sound effects from Openverse with the bundled library offline

* docs(media-use): name the resolve credits file without a dead path

* style(skills): restore the slideshow harness formatting the pinned formatter expects

* fix(media-use): keep Openverse credit text to one safe line and read credits without a race

* fix(media-use): Openverse sound effects record as the engine's, so a rerun writes no copy

* fix(media-use): two sound effect resolves at once each keep their credit line

* fix(media-use): the standalone media-use copy takes the same credit lock

* fix(media-use): a sound effect credit is always one safe line with a provider link

writeSfxCredit cleans the credit and source link itself, since the CLI writes
credits from a saved record. Backticks, brackets, angle brackets and backslashes
are stripped, and a source link must be https on an Openverse audio provider host
(Freesound, Jamendo, Wikimedia Commons) or it is left out.
2026-10-18 04:35:08 +00:00

61 lines
2.2 KiB
JavaScript

import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const workflows = ["faceless-explainer", "pr-to-video", "product-launch-video"];
export const skillModuleCopies = [
[
"packages/cli/src/media-use/lib/media-fetch.mjs",
["skills/media-use/scripts/lib/media-fetch.mjs"],
],
[
"packages/cli/src/media-use/lib/openverse.mjs",
["skills/media-use/audio/scripts/lib/openverse.mjs"],
],
[
"skills/media-use/audio/scripts/lib/bgm-volume.mjs",
workflows.map((skill) => `skills/${skill}/scripts/lib/bgm-volume.mjs`),
],
[
"skills/media-use/audio/scripts/lib/host-audio.mjs",
workflows.map((skill) => `skills/${skill}/scripts/lib/host-audio.mjs`),
],
[
"skills/hyperframes/scripts/lib/main-module.mjs",
[
...[...workflows, "general-video", "hyperframes-audio", "media-use/audio"].map(
(skill) => `skills/${skill}/scripts/lib/main-module.mjs`,
),
"packages/cli/src/media-use/lib/main-module.mjs",
],
],
[
"skills/hyperframes/scripts/lib/frame-packets-core.mjs",
[...workflows, "general-video"].map(
(skill) => `skills/${skill}/scripts/lib/frame-packets-core.mjs`,
),
],
];
function synchronizeCopy(content, target, check) {
const path = resolve(root, target);
if (check) return readFileSync(path, "utf8") !== content;
mkdirSync(dirname(path), { recursive: true });
writeFileSync(path, content);
return false;
}
export function generateSkillModuleCopies({ check = false } = {}) {
return skillModuleCopies.flatMap(([source, targets]) => {
const content = readFileSync(resolve(root, source), "utf8");
return targets.filter((target) => synchronizeCopy(content, target, check));
});
}
if (process.argv[1] && pathToFileURL(realpathSync(process.argv[1])).href === import.meta.url) {
const drifted = generateSkillModuleCopies({ check: process.argv.includes("--check") });
if (drifted.length) throw new Error("Regenerate skill module copies: " + drifted.join(", "));
console.log("Skill module copies are in sync");
}