From ba333ddb219a4108fd64f23a639644f1ae4aadcd Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 12 Feb 2025 15:04:15 -0800 Subject: [PATCH] Fix generate script race condition --- packages/schemas/tools/generate.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/schemas/tools/generate.ts b/packages/schemas/tools/generate.ts index a5911e27..14a3842e 100644 --- a/packages/schemas/tools/generate.ts +++ b/packages/schemas/tools/generate.ts @@ -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