Skip to content

Commit 572e111

Browse files
authored
Exclude unwanted packages in docgen script (#6469)
1 parent 8260149 commit 572e111

File tree

3 files changed

+95
-431
lines changed

3 files changed

+95
-431
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@ tsdoc-metadata.json
9393

9494
# generated html docs
9595
docs-*/
96-
docs/
96+
docs/
97+
toc/

scripts/docgen/docgen.ts

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,79 @@ https://github.com/firebase/firebase-js-sdk
3737
`;
3838

3939
const tmpDir = `${projectRoot}/temp`;
40+
const EXCLUDED_PACKAGES = ['app-compat', 'util', 'rules-unit-testing'];
4041

4142
yargs
42-
.command('$0', 'generate standard reference docs', {}, _argv =>
43-
generateDocs(/* forDevsite */ false)
43+
.command(
44+
'$0',
45+
'generate standard reference docs',
46+
{
47+
skipBuild: {
48+
type: 'boolean',
49+
default: false
50+
}
51+
},
52+
_argv => generateDocs(/* forDevsite */ false, _argv.skipBuild)
4453
)
45-
.command('devsite', 'generate reference docs for devsite', {}, _argv =>
46-
generateDocs(/* forDevsite */ true)
54+
.command(
55+
'devsite',
56+
'generate reference docs for devsite',
57+
{
58+
skipBuild: {
59+
type: 'boolean',
60+
default: false
61+
}
62+
},
63+
_argv => generateDocs(/* forDevsite */ true, _argv.skipBuild)
4764
)
65+
.command('toc', 'generate devsite TOC', {}, _argv => generateToc())
66+
.option('skipBuild', {
67+
describe:
68+
'Skip yarn build and api-report - only do this if you have already generated the most up to date .api.json files',
69+
type: 'boolean'
70+
})
4871
.demandCommand()
4972
.help().argv;
5073

74+
async function generateToc() {
75+
console.log(`Temporarily renaming excluded packages' json files.`);
76+
for (const excludedPackage of EXCLUDED_PACKAGES) {
77+
if (fs.existsSync(`${projectRoot}/temp/${excludedPackage}.api.json`)) {
78+
fs.renameSync(
79+
`${projectRoot}/temp/${excludedPackage}.api.json`,
80+
`${projectRoot}/temp/${excludedPackage}.skip`
81+
);
82+
}
83+
}
84+
await spawn(
85+
'yarn',
86+
[
87+
'api-documenter-devsite',
88+
'toc',
89+
'--input',
90+
'temp',
91+
'-p',
92+
'docs/reference/js/v9',
93+
'-j'
94+
],
95+
{ stdio: 'inherit' }
96+
);
97+
console.log(`Restoring excluded packages' json files.`);
98+
for (const excludedPackage of EXCLUDED_PACKAGES) {
99+
if (fs.existsSync(`${projectRoot}/temp/${excludedPackage}.skip`)) {
100+
fs.renameSync(
101+
`${projectRoot}/temp/${excludedPackage}.skip`,
102+
`${projectRoot}/temp/${excludedPackage}.api.json`
103+
);
104+
}
105+
}
106+
}
107+
51108
// create *.api.json files
52-
async function generateDocs(forDevsite: boolean = false) {
109+
async function generateDocs(
110+
forDevsite: boolean = false,
111+
skipBuild: boolean = false
112+
) {
53113
const outputFolder = forDevsite ? 'docs-devsite' : 'docs';
54114
const command = forDevsite ? 'api-documenter-devsite' : 'api-documenter';
55115

@@ -67,13 +127,15 @@ async function generateDocs(forDevsite: boolean = false) {
67127
authApiConfigModified
68128
);
69129

70-
await spawn('yarn', ['build'], {
71-
stdio: 'inherit'
72-
});
130+
if (!skipBuild) {
131+
await spawn('yarn', ['build'], {
132+
stdio: 'inherit'
133+
});
73134

74-
await spawn('yarn', ['api-report'], {
75-
stdio: 'inherit'
76-
});
135+
await spawn('yarn', ['api-report'], {
136+
stdio: 'inherit'
137+
});
138+
}
77139

78140
// Restore original auth api-extractor.json contents.
79141
fs.writeFileSync(
@@ -136,7 +198,24 @@ async function generateDocs(forDevsite: boolean = false) {
136198
}
137199
}
138200

139-
moveRulesUnitTestingDocs(outputFolder, command);
201+
await moveRulesUnitTestingDocs(outputFolder, command);
202+
await removeExcludedDocs(outputFolder);
203+
}
204+
205+
async function removeExcludedDocs(mainDocsFolder: string) {
206+
console.log('Removing excluded docs from', EXCLUDED_PACKAGES.join(', '));
207+
for (const excludedPackage of EXCLUDED_PACKAGES) {
208+
const excludedMdFiles = await new Promise<string[]>(resolve =>
209+
glob(`${mainDocsFolder}/${excludedPackage}.*`, (err, paths) => {
210+
if (err) throw err;
211+
resolve(paths);
212+
})
213+
);
214+
console.log('glob pattern', `${mainDocsFolder}/${excludedPackage}.*`);
215+
for (const excludedMdFile of excludedMdFiles) {
216+
fs.unlinkSync(excludedMdFile);
217+
}
218+
}
140219
}
141220

142221
// Create a docs-rut folder and move rules-unit-testing docs into it.
@@ -146,6 +225,8 @@ async function moveRulesUnitTestingDocs(
146225
) {
147226
const rulesOutputFolder = `${projectRoot}/docs-rut`;
148227

228+
console.log('Moving RUT docs to their own folder:', rulesOutputFolder);
229+
149230
if (!fs.existsSync(rulesOutputFolder)) {
150231
fs.mkdirSync(rulesOutputFolder);
151232
}
@@ -176,6 +257,5 @@ async function moveRulesUnitTestingDocs(
176257
`${jsReferencePath}/firestore`
177258
);
178259
fs.writeFileSync(destinationPath, alteredPathText);
179-
fs.unlinkSync(sourcePath);
180260
}
181261
}

0 commit comments

Comments
 (0)