in sites/website/src/generate-docs.js [274:359]
async function buildAPIMarkdown() {
await copyAPI();
await new Promise((resolve, reject) =>
exec(
"yarn api-documenter markdown -i src/docs/api -o docs/api",
(err, stdout, stderr) => {
console.log(stdout);
console.error(stderr);
if (err) {
return reject(err);
}
return resolve();
}
)
);
const dir = "./docs/api";
const docFiles = await fs.readdir(dir);
for (const docFile of docFiles) {
try {
const { name: id, ext } = path.parse(docFile);
if (ext !== ".md") {
continue;
}
const pkg = identifyPackage(docFile);
const isAPIHome = id === pkg;
const docPath = path.join(dir, docFile);
const input = fs.createReadStream(docPath);
const output = [];
const lines = createInterface({
input,
crlfDelay: Infinity,
});
let title = "";
lines.on("line", line => {
let skip = false;
if (!title) {
const titleLine = line.match(/## (.*)/);
if (titleLine) {
title = titleLine[1];
if (title.indexOf("package") !== -1) {
title = title.replace("package", "");
skip = true;
}
}
}
const homeLink = line.match(/\[Home\]\(.\/index\.md\) > (.*)/);
if (homeLink) {
if (!isAPIHome) {
output.push(homeLink[1]);
}
skip = true;
}
if (!skip) {
output.push(line);
}
});
await new Promise(resolve => lines.once("close", resolve));
input.close();
const header = [
"---",
`id: ${id}`,
`title: ${title}`,
`hide_title: ${!isAPIHome}`,
"---",
];
await safeWrite(docPath, header.concat(output).join("\n"));
} catch (err) {
console.error(`Could not process ${docFile}: ${err}`);
}
}
}