const makeFilenameRewriter = (filenameRewriters) => (filename, line, column) => (
Object.entries(filenameRewriters)
.reduce(
(filename, [from, to]) => filename.replace(new RegExp(from), to),
[filename, ...(line ? [line, column] : [])].join(':'),
)
);
exports.generateBuildFilesPage = (buildFiles) => {
const source = [];
source.push('---');
source.push('title: Build files');
source.push('description: All the build files in this project.');
source.push('---');
source.push('');
source.push('This page documents all the build configuration files in this project.');
source.push('');
if (buildFiles.length > 0) {
buildFiles
.sort(({filename: l}, {filename: r}) => (l < r ? -1 : 1))
.forEach(({filename, description}) => {
source.push(`## \`${filename}\``);
source.push('');
source.push(description);
source.push('');
});
}
return source.join('\n');
};
exports.generateConfigPage = (configs) => {
const source = [];
source.push('---');
source.push('title: Fleck configuration');
source.push('description: All the configurable flecks in this project.');
source.push('---');
source.push('');
source.push("import CodeBlock from '@theme/CodeBlock';");
source.push('');
source.push('');
source.push('');
source.push('This page documents all configurable flecks in this project.');
source.push('');
Object.entries(configs)
.sort(([l], [r]) => (l < r ? -1 : 1))
.forEach(([fleck, configs]) => {
source.push(`## \`${fleck}\``);
source.push('|Name|Default|Description|');
source.push('|-|-|-|');
configs.forEach(({defaultValue, description, key}) => {
// Leading and trailing empty cell to make table rendering easier.
const row = ['', key];
let code = defaultValue.replace(/`/g, '\\`');
// Multiline code. Fix indentation.
if (defaultValue.includes('\n')) {
const defaultValueLines = code.split('\n');
const [first, ...rest] = defaultValueLines;
const indent = (rest[0].length - rest[0].trimStart().length) - 2;
code = [first, ...rest.map((line) => line.substring(indent))].join('\\n');
}
row.push(`${name}: ${type}
`);
source.push('');
source.push(`
${description.trim()}
`); source.push(''); }); source.push(''); } if (implementations.length > 0) { source.push('