Files
wehub-resource-sync e30e75b5d4
Code Quality / Oxlint + Oxfmt (push) Waiting to run
Code Quality / Template Sync (push) Waiting to run
Code Quality / Build Changed Packages (push) Waiting to run
Code Quality / Test Changed Packages (push) Waiting to run
Deploy Expo Example / Deploy Production (push) Waiting to run
Deploy Ink Example / Deploy Production (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.12) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Waiting to run
Deploy Shadcn Registry / Deploy Production (push) Waiting to run
Template Metrics / LOC + Bundle Size (push) Waiting to run
Changesets / Create Version PR (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

96 lines
2.0 KiB
TypeScript

import { execFileSync } from "node:child_process";
import { promises as fs } from "node:fs";
import path from "node:path";
const DOCS_ROOT = process.cwd();
const REPO_ROOT = path.resolve(DOCS_ROOT, "../..");
const OUTPUT_DIR = path.join(DOCS_ROOT, "generated");
const OUTPUT_PATH = path.join(OUTPUT_DIR, "source-snapshot.json");
const READ_CONCURRENCY = 32;
const SOURCE_SNAPSHOT_EXCLUDE = [
/pnpm-lock\.yaml$/,
/package-lock\.json$/,
/yarn\.lock$/,
/\.png$/,
/\.jpg$/,
/\.jpeg$/,
/\.gif$/,
/\.ico$/,
/\.svg$/,
/\.woff2?$/,
/\.ttf$/,
/\.eot$/,
/\.mp[34]$/,
/\.webm$/,
/\.webp$/,
/\.pdf$/,
/\.zip$/,
/\.tar$/,
/\.gz$/,
/\/dist\//,
/\/\.next\//,
];
async function main() {
const files = listTrackedFiles()
.map((filePath) => filePath.replace(/\\/g, "/"))
.filter(
(filePath) => !SOURCE_SNAPSHOT_EXCLUDE.some((re) => re.test(filePath)),
);
const snapshot = await buildSnapshot(files);
await fs.mkdir(OUTPUT_DIR, { recursive: true });
await fs.writeFile(OUTPUT_PATH, JSON.stringify(snapshot));
}
async function buildSnapshot(files: string[]) {
const snapshot: Record<string, string> = {};
let index = 0;
async function worker() {
while (true) {
const currentIndex = index++;
if (currentIndex >= files.length) return;
const filePath = files[currentIndex]!;
try {
snapshot[filePath] = await fs.readFile(
path.join(REPO_ROOT, filePath),
"utf-8",
);
} catch (error) {
if (
error &&
typeof error === "object" &&
"code" in error &&
error.code === "ENOENT"
) {
continue;
}
throw error;
}
}
}
await Promise.all(
Array.from({ length: Math.min(READ_CONCURRENCY, files.length) }, () =>
worker(),
),
);
return snapshot;
}
function listTrackedFiles() {
const output = execFileSync("git", ["ls-files", "-z"], {
cwd: REPO_ROOT,
encoding: "utf-8",
});
return output.split("\0").filter(Boolean);
}
await main();