Skip to content

Commit

Permalink
[docs-infra] Fix --grep option when building docs (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert authored Dec 13, 2024
1 parent adf3bee commit aabaa43
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 20 additions & 5 deletions scripts/buildApiDocs/buildReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -18,12 +19,26 @@ interface CommonOverrides {
types: Record<string, string>;
}

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<string, string[]> = JSON.parse(readFileSync(ORDER_JSON, 'utf-8'));

Expand Down
2 changes: 1 addition & 1 deletion scripts/buildApiDocs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type CommandOptions = { grep?: string };
async function run(argv: ArgumentsCamelCase<CommandOptions>) {
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))
Expand Down

0 comments on commit aabaa43

Please sign in to comment.