blob: 47afa5f6b11fb2b436e3910ef1f51c9b1b3b3224 [file]
const { readFileSync } = require('fs');
const md = process.argv[2];
const title = process.argv[3];
const content = readFileSync(md, {encoding: 'utf8'});
// replace the //packages/foo from the docs with references to @npm//@bazel/foo
// @npm is not the required name, but it seems to be the common case
// this reflects the similar transformation made when publishing the packages to npm
// via pkg_npm defined in //tools:defaults.bzl
const out = content.replace(/(?:@.*)*?\/\/packages\/([^/:"\s]*)/g, (str, pkg) => {
const parts = pkg.split('/');
return `@npm//@bazel/${parts[parts.length - 1]}`;
});
// stamp the frontmatter into the post processed stardoc HTML
const frontmatter = [
'---',
`title: ${title}`,
'layout: default',
'toc: true',
'nav: rule',
'---',
'<!-- *********************',
' DO NOT EDIT THIS FILE',
' It is a generated build output from Stardoc.',
' Instead you must edit the .bzl file where the rules are declared,',
' or possibly a markdown file next to the .bzl file',
' ********************* -->\n'
].join('\n');
// write out to stdout, this script is run as part of a genrule that redirects the output the to expected file
process.stdout.write(frontmatter + out);