Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild type index after removing stale type folders #2143

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading