Skip to content

Ensure docgen script restores original files even if build fails #7151

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

Merged
merged 2 commits into from
Mar 28, 2023
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
116 changes: 62 additions & 54 deletions scripts/docgen/docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,29 @@ async function generateToc() {
);
}
}
await spawn(
'yarn',
[
'api-documenter-devsite',
'toc',
'--input',
'temp',
'-p',
'/docs/reference/js',
'-j'
],
{ stdio: 'inherit' }
);
console.log(`Restoring excluded packages' json files.`);
for (const excludedPackage of EXCLUDED_PACKAGES) {
if (fs.existsSync(`${projectRoot}/temp/${excludedPackage}.skip`)) {
fs.renameSync(
`${projectRoot}/temp/${excludedPackage}.skip`,
`${projectRoot}/temp/${excludedPackage}.api.json`
);
try {
await spawn(
'yarn',
[
'api-documenter-devsite',
'toc',
'--input',
'temp',
'-p',
'/docs/reference/js',
'-j'
],
{ stdio: 'inherit' }
);
} finally {
console.log(`Restoring excluded packages' json files.`);
for (const excludedPackage of EXCLUDED_PACKAGES) {
if (fs.existsSync(`${projectRoot}/temp/${excludedPackage}.skip`)) {
fs.renameSync(
`${projectRoot}/temp/${excludedPackage}.skip`,
`${projectRoot}/temp/${excludedPackage}.api.json`
);
}
}
}
}
Expand All @@ -131,6 +134,7 @@ async function generateDocs(
const outputFolder = forDevsite ? 'docs-devsite' : 'docs';
const command = forDevsite ? 'api-documenter-devsite' : 'api-documenter';

console.log(`Temporarily modifying auth api-extractor.json for docgen.`);
// Use a special d.ts file for auth for doc gen only.
const authApiConfigOriginal = fs.readFileSync(
`${projectRoot}/packages/auth/api-extractor.json`,
Expand All @@ -145,45 +149,49 @@ async function generateDocs(
`"mainEntryPointFilePath": "<projectFolder>/dist/esm5/index.d.ts"`,
`"mainEntryPointFilePath": "<projectFolder>/dist/esm5/index.doc.d.ts"`
);
fs.writeFileSync(
`${projectRoot}/packages/auth/api-extractor.json`,
authApiConfigModified
);

if (skipBuild) {
await spawn('yarn', ['api-report'], {
stdio: 'inherit'
});
} else {
// api-report is run as part of every build
await spawn(
'yarn',
[
'lerna',
'run',
'--scope',
'@firebase/*',
'--ignore',
'@firebase/*-compat',
'build'
],
{
try {
fs.writeFileSync(
`${projectRoot}/packages/auth/api-extractor.json`,
authApiConfigModified
);

if (skipBuild) {
await spawn('yarn', ['api-report'], {
stdio: 'inherit'
}
});
} else {
// api-report is run as part of every build
await spawn(
'yarn',
[
'lerna',
'run',
'--scope',
'@firebase/*',
'--ignore',
'@firebase/*-compat',
'build'
],
{
stdio: 'inherit'
}
);
}
} finally {
console.log(`Restoring original auth api-extractor.json contents.`);
// Restore original auth api-extractor.json contents.
fs.writeFileSync(
`${projectRoot}/packages/auth/api-extractor.json`,
authApiConfigOriginal
);
// Restore original auth.api.md
fs.writeFileSync(
`${projectRoot}/common/api-review/auth.api.md`,
authApiReportOriginal
);
}

// Restore original auth api-extractor.json contents.
fs.writeFileSync(
`${projectRoot}/packages/auth/api-extractor.json`,
authApiConfigOriginal
);
// Restore original auth.api.md
fs.writeFileSync(
`${projectRoot}/common/api-review/auth.api.md`,
authApiReportOriginal
);

if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir);
}
Expand Down