diff --git a/package.json b/package.json index f6c99a9994..adf052c2ea 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,7 @@ "release:publish": "pnpm publish --recursive --tag latest", "release:publish:dry-run": "pnpm publish --recursive --tag latest --registry=\"http://localhost:4873/\"", "release:tag": "node scripts/releaseTag.mjs", - "docs:api": "rimraf --glob ./docs/pages/**/api-docs ./docs/pages/**/api && pnpm docs:api:build", - "docs:api:build": "tsx --tsconfig ./scripts/buildApiDocs/tsconfig.json ./scripts/buildApiDocs/index.ts", + "docs:api": "tsx --tsconfig ./scripts/buildApiDocs/tsconfig.json ./scripts/buildApiDocs/index.ts", "docs:build": "pnpm --filter docs build", "docs:deploy": "pnpm --filter docs run deploy", "docs:dev": "pnpm --filter docs dev", diff --git a/scripts/buildApiDocs/buildReference.ts b/scripts/buildApiDocs/buildReference.ts index 922c75ac6d..0c4bdc8210 100644 --- a/scripts/buildApiDocs/buildReference.ts +++ b/scripts/buildApiDocs/buildReference.ts @@ -10,6 +10,7 @@ const TEMP_PROP_DEFS_GLOB = join(process.cwd(), 'docs/reference/temp/components/ const TEMP_DESCRIPTIONS_GLOB = join(process.cwd(), 'docs/reference/temp/translations/**/*.json'); const COMMON_OVERRIDES_JSON = join(process.cwd(), 'docs/reference/overrides/common.json'); const OVERRIDES_GLOB = join(process.cwd(), 'docs/reference/overrides/*.json'); +const GENERATED_GLOB = join(process.cwd(), 'docs/reference/generated/*.json'); const ORDER_JSON = join(process.cwd(), 'docs/reference/order.json'); const FINAL_DIR = join(process.cwd(), 'docs/reference/generated'); @@ -18,12 +19,26 @@ interface CommonOverrides { types: Record; } -export async function buildReference() { - if (existsSync(FINAL_DIR)) { - rmSync(FINAL_DIR, { recursive: true }); - } +export async function buildReference(grep: RegExp | null = null) { + if (grep == null) { + if (existsSync(FINAL_DIR)) { + rmSync(FINAL_DIR, { recursive: true }); + } + + mkdirSync(FINAL_DIR); + } else { + if (!existsSync(FINAL_DIR)) { + mkdirSync(FINAL_DIR); + } + // the targeted files are all lowercased + const caseInsensitiveGrep = new RegExp(grep, 'i'); - mkdirSync(FINAL_DIR); + for (const pathname of globSync(GENERATED_GLOB)) { + if (caseInsensitiveGrep.test(pathname)) { + rmSync(pathname); + } + } + } const order: Record = JSON.parse(readFileSync(ORDER_JSON, 'utf-8')); diff --git a/scripts/buildApiDocs/index.ts b/scripts/buildApiDocs/index.ts index 365387144d..d56c74f2d8 100644 --- a/scripts/buildApiDocs/index.ts +++ b/scripts/buildApiDocs/index.ts @@ -8,7 +8,7 @@ type CommandOptions = { grep?: string }; async function run(argv: ArgumentsCamelCase) { const grep = argv.grep == null ? null : new RegExp(argv.grep); await buildApi([projectSettings], grep, true); - await buildReference(); + await buildReference(grep); } yargs(process.argv.slice(2))