Skip to content

Commit

Permalink
Rebuild type index after removing stale type folders
Browse files Browse the repository at this point in the history
  • Loading branch information
shenglol committed May 2, 2024
1 parent e8c2e62 commit 620f5eb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/generator/src/cmd/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ ${err}
await buildTypeIndex(defaultLogger, outputBaseDir);

// log if there are any type dirs with no corresponding readme (e.g. if a swagger directory has been removed).
await logStaleReadmes(defaultLogger, outputBaseDir, specsPath, readmePaths);
const shouldRebuildTypeIndex = await clearStaleTypeFolders(defaultLogger, outputBaseDir, specsPath, readmePaths);

if (shouldRebuildTypeIndex) {
await buildTypeIndex(defaultLogger, outputBaseDir);
}
});

function normalizeJsonPath(jsonPath: string) {
Expand Down Expand Up @@ -243,7 +247,7 @@ async function findReadmePaths(specsPath: string) {
});
}

async function logStaleReadmes(logger: ILogger, outputBaseDir: string, specsPath: string, readmePaths: string[]) {
async function clearStaleTypeFolders(logger: ILogger, outputBaseDir: string, specsPath: string, readmePaths: string[]) {
const typesPaths = await findRecursive(outputBaseDir, filePath => {
return path.basename(filePath) === 'types.json';
});
Expand All @@ -262,6 +266,8 @@ async function logStaleReadmes(logger: ILogger, outputBaseDir: string, specsPath
for (const basePath of staleBasePaths) {
await rm(`${outputBaseDir}/${basePath}`, { recursive: true, force: true, });
}

return staleBasePaths.length > 0;
}

async function buildTypeIndex(logger: ILogger, baseDir: string) {
Expand Down

0 comments on commit 620f5eb

Please sign in to comment.