Skip to content

Commit

Permalink
chore: Added support for generating a toc file for docs (#1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiranya911 authored May 27, 2021
1 parent 70d830b commit 5d91953
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
22 changes: 22 additions & 0 deletions docgen/post-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ async function fixTitles() {
for (const file of files) {
await fixTitleOf(path.join(markdownDir, file));
}

const tocFile = path.join(markdownDir, 'toc.yaml');
await fixTocTitles(tocFile);
}

async function fixTitleOf(file) {
Expand Down Expand Up @@ -92,6 +95,25 @@ async function fixTitleOf(file) {
}
}

async function fixTocTitles(file) {
const reader = readline.createInterface({
input: fs.createReadStream(file),
});

const buffer = [];
for await (let line of reader) {
if (line.includes('- title: firebase-admin.')) {
line = line.replace(/firebase-admin\./, 'firebase-admin/');
}

buffer.push(line);
}

console.log(`Updating titles in ${file}`);
const content = Buffer.from(buffer.join('\r\n'));
await fs.writeFile(file, content);
}

async function getExtraFiles() {
const extrasPath = path.join(__dirname, 'extras');
const files = await fs.readdir(extrasPath);
Expand Down
49 changes: 28 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
"test:coverage": "nyc npm run test:unit",
"lint:src": "eslint src/ --ext .ts",
"lint:test": "eslint test/ --ext .ts",
"apidocs": "run-s api-extractor:local api-documenter api-documenter:post",
"apidocs": "run-s api-extractor:local api-documenter api-documenter:toc api-documenter:post",
"api-extractor": "node generate-reports.js",
"api-extractor:local": "npm run build && node generate-reports.js --local",
"esm-wrap": "node generate-esm-wrapper.js",
"api-documenter": "api-documenter-fire markdown --input temp --output docgen/markdown -s",
"api-documenter:toc": "api-documenter-fire toc --input temp --output docgen/markdown -p /docs/reference/admin/node -s",
"api-documenter:post": "node docgen/post-process.js"
},
"nyc": {
Expand Down Expand Up @@ -155,7 +156,7 @@
"@google-cloud/storage": "^5.3.0"
},
"devDependencies": {
"@firebase/api-documenter": "^0.1.1",
"@firebase/api-documenter": "^0.1.2",
"@firebase/app": "^0.6.13",
"@firebase/auth": "^0.16.2",
"@firebase/auth-types": "^0.10.1",
Expand Down

0 comments on commit 5d91953

Please sign in to comment.