103 lines
2.6 KiB
TypeScript
103 lines
2.6 KiB
TypeScript
#!/usr/bin/env bun
|
|
/**
|
|
* Regenerates barrel index.ts files across all workspace packages using ctix.
|
|
* Run: bun scripts/barrel.ts
|
|
*/
|
|
|
|
import { spawnSync } from "node:child_process";
|
|
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
import { join, relative, resolve } from "node:path";
|
|
|
|
const ROOT = resolve(import.meta.dir, "..");
|
|
const WORKSPACE_GLOBS = [
|
|
"universal/*/*",
|
|
"browser/*/*",
|
|
"gaming/*/*",
|
|
"react/*/*",
|
|
"api/*/*",
|
|
"r3f/*/*",
|
|
"server/*/*",
|
|
"mcp/*/*",
|
|
"finance/*/*",
|
|
"python/*/*",
|
|
];
|
|
|
|
function dirs(parent: string): string[] {
|
|
if (!existsSync(parent)) return [];
|
|
return readdirSync(parent).filter((d) =>
|
|
statSync(join(parent, d)).isDirectory()
|
|
);
|
|
}
|
|
|
|
function expandGlob(pattern: string): string[] {
|
|
// Pattern is always `<root>/*/*` — two wildcard levels
|
|
const segments = pattern.split("/");
|
|
let paths = [ROOT];
|
|
for (const seg of segments) {
|
|
if (seg === "*") {
|
|
paths = paths.flatMap((p) => dirs(p).map((d) => join(p, d)));
|
|
} else {
|
|
paths = paths.map((p) => join(p, seg));
|
|
}
|
|
}
|
|
return paths.filter((p) => existsSync(p) && statSync(p).isDirectory());
|
|
}
|
|
|
|
const TSCONFIG_NAMES = ["tsconfig.lib.json", "tsconfig.json"];
|
|
|
|
const packages = WORKSPACE_GLOBS.flatMap(expandGlob).filter((p) => {
|
|
return (
|
|
TSCONFIG_NAMES.some((t) => existsSync(join(p, t))) &&
|
|
existsSync(join(p, "src"))
|
|
);
|
|
});
|
|
|
|
console.log(`Found ${packages.length} packages\n`);
|
|
|
|
let ok = 0;
|
|
let fail = 0;
|
|
|
|
for (const pkg of packages) {
|
|
const rel = relative(ROOT, pkg);
|
|
const tsconfig =
|
|
TSCONFIG_NAMES.map((t) => join(pkg, t)).find(existsSync) ??
|
|
join(pkg, "tsconfig.lib.json");
|
|
|
|
const result = spawnSync(
|
|
"bunx",
|
|
[
|
|
"ctix",
|
|
"build",
|
|
"--project",
|
|
tsconfig,
|
|
"--start-from",
|
|
join(pkg, "src"),
|
|
"--mode",
|
|
"create",
|
|
"--generation-style",
|
|
"default-alias-named-destructive",
|
|
"--overwrite",
|
|
"--skip-empty-dir",
|
|
"--exclude-files",
|
|
"**/*.test.ts",
|
|
"--exclude-files",
|
|
"**/*.spec.ts",
|
|
"--exclude-files",
|
|
"**/*.stories.tsx",
|
|
],
|
|
{ cwd: ROOT, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
|
|
);
|
|
|
|
if (result.status === 0) {
|
|
console.log(` ok ${rel}`);
|
|
ok++;
|
|
} else {
|
|
console.error(` ERR ${rel}`);
|
|
if (result.stderr) console.error(result.stderr.trim());
|
|
fail++;
|
|
}
|
|
}
|
|
|
|
console.log(`\n${ok} ok, ${fail} failed`);
|
|
if (fail > 0) process.exit(1);
|