Files
hyperframes/packages/cli/src/utils/mountedCompositions.ts
T
Weiwei Wu a75e61f31c fix(cli): discover mounted scenes inside templates (#7822)
* fix(cli): discover mounted scenes inside templates

* test(cli): cover recursive template scene discovery

* test(cli): cover media edits in nested template scenes

* test(cli): cover nested audio edits and duplicate targets

* docs(cli): explain nested scene discovery and ambiguity
2026-11-15 08:47:04 +00:00

21 lines
894 B
TypeScript

import { existsSync, readFileSync } from "node:fs";
import { relative, resolve } from "node:path";
import { collectSubCompositionSrcs } from "@hyperframes/parsers/asset-resolution";
import { isPathInside } from "@hyperframes/core";
/** The entry file plus every sub-composition file it mounts, nested ones included, as project-relative paths. */
export function projectCompositionFiles(projectDir: string, entry = "index.html"): string[] {
const files: string[] = [];
const visit = (file: string): void => {
if (files.includes(file)) return;
const path = resolve(projectDir, file);
if (!isPathInside(path, projectDir) || !existsSync(path)) return;
files.push(file);
for (const src of collectSubCompositionSrcs(readFileSync(path, "utf8"))) {
visit(relative(projectDir, resolve(projectDir, src)).split("\\").join("/"));
}
};
visit(entry);
return files;
}