Fix generate script race condition

This commit is contained in:
bkellam 2025-02-12 15:04:15 -08:00
parent 98becf531a
commit ba333ddb21

View file

@ -6,20 +6,22 @@ import { glob } from "glob";
const BANNER_COMMENT = '// THIS IS A AUTO-GENERATED FILE. DO NOT MODIFY MANUALLY!\n';
// const SCHEMAS: string[] = ["github.json", "shared.json"];
(async () => {
const cwd = process.cwd();
const schemasBasePath = path.resolve(`${cwd}/../../schemas`);
const schemas = await glob(`${schemasBasePath}/**/*.json`)
const outDirRoot = path.resolve(`${cwd}/src`);
const schemas = await glob(`${schemasBasePath}/**/*.json`);
// Clean output directory first
await rm(outDirRoot, { recursive: true, force: true });
await Promise.all(schemas.map(async (schemaPath) => {
const name = path.parse(schemaPath).name;
const version = path.basename(path.dirname(schemaPath));
const outDir = path.join(cwd, `src/${version}`);
const outDir = path.join(outDirRoot, version);
// Clean output directory first
await rm(outDir, { recursive: true, force: true });
await mkdir(outDir, { recursive: true });
// Generate schema