feat(dox): rewrite filenames

This commit is contained in:
cha0s 2024-01-26 09:08:57 -06:00
parent 6314093ba2
commit dd116de20c
3 changed files with 40 additions and 13 deletions

View File

@ -9,7 +9,7 @@
"scripts": { "scripts": {
"build": "lerna run build", "build": "lerna run build",
"clean": "lerna exec yarn clean", "clean": "lerna exec yarn clean",
"dox": "flecks dox docusaurus && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus", "dox": "flecks dox docusaurus -r @flecks=https://github.com/cha0s/flecks/tree/master/packages -r ':([0-9]+):[0-9]=#L$1' && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus",
"lint": "lerna run lint", "lint": "lerna run lint",
"publish": "lerna publish --conventional-commits --contents=dist --registry https://registry.npmjs.org", "publish": "lerna publish --conventional-commits --contents=dist --registry https://registry.npmjs.org",
"test": "lerna exec 'yarn && yarn test'" "test": "lerna exec 'yarn && yarn test'"

View File

@ -14,7 +14,7 @@ module.exports = (program, flecks) => {
const commands = {}; const commands = {};
commands.dox = { commands.dox = {
description: 'Generate documentation', description: 'Generate documentation',
action: async (subcommand, outputPath) => { action: async (subcommand, outputPath, {rewriteFilenames = []}) => {
let actualOutputPath = outputPath; let actualOutputPath = outputPath;
if (!actualOutputPath) { if (!actualOutputPath) {
switch (subcommand) { switch (subcommand) {
@ -32,6 +32,34 @@ module.exports = (program, flecks) => {
await mkdir(actualOutputPath, {recursive: true}); await mkdir(actualOutputPath, {recursive: true});
let output; let output;
const json = await generateJson(flecks); const json = await generateJson(flecks);
const pairs = rewriteFilenames
.map((pair) => pair.split('='))
.map(([from, to]) => [new RegExp(from), to]);
const rewrite = (array) => (
array.map(
(object) => ({
...object,
filename: pairs.reduce(
(filename, [from, to]) => filename.replace(from, to),
object.filename,
),
}),
)
);
json.hooks = Object.fromEntries(
Object.entries(json.hooks)
.map(([hook, {implementations, invocations, specification}]) => (
[
hook,
{
implementations: rewrite(implementations),
invocations: rewrite(invocations),
specification,
},
]
)),
);
json.todos = rewrite(json.todos);
switch (subcommand) { switch (subcommand) {
case 'docusaurus': case 'docusaurus':
output = Object.fromEntries( output = Object.fromEntries(
@ -62,6 +90,9 @@ module.exports = (program, flecks) => {
.choices(['docusaurus', 'json']), .choices(['docusaurus', 'json']),
program.createArgument('[output path]', 'Where the files are output'), program.createArgument('[output path]', 'Where the files are output'),
], ],
options: [
program.createOption('-r, --rewrite-filenames [pairs...]', 'rewrite filenames'),
],
}; };
return commands; return commands;
}; };

View File

@ -125,8 +125,8 @@ exports.generateDocusaurusHookPage = (hooks) => {
source.push('<details>'); source.push('<details>');
source.push('<summary>Implementations</summary>'); source.push('<summary>Implementations</summary>');
source.push('<ul>'); source.push('<ul>');
implementations.forEach(({filename, column, line}) => { implementations.forEach(({filename}) => {
source.push(`<li>${[filename, line, column].join(':')}</li>`); source.push(`<li>${filename}</li>`);
}); });
source.push('</ul>'); source.push('</ul>');
source.push('</details>'); source.push('</details>');
@ -136,8 +136,8 @@ exports.generateDocusaurusHookPage = (hooks) => {
source.push('<details>'); source.push('<details>');
source.push('<summary>Invocations</summary>'); source.push('<summary>Invocations</summary>');
source.push('<ul>'); source.push('<ul>');
invocations.forEach(({filename, column, line}) => { invocations.forEach(({filename, type}) => {
source.push(`<li>${[filename, line, column].join(':')}</li>`); source.push(`<li>${filename} (\`${type}\`)</li>`);
}); });
source.push('</ul>'); source.push('</ul>');
source.push('</details>'); source.push('</details>');
@ -216,7 +216,7 @@ exports.generateJson = async function generate(flecks) {
r.buildFiles.push(...buildFiles); r.buildFiles.push(...buildFiles);
r.todos.push(...todos.map((todo) => ({ r.todos.push(...todos.map((todo) => ({
...todo, ...todo,
filename: join(`**${root}**`, path), filename: join(root, path),
}))); })));
if (config.length > 0) { if (config.length > 0) {
let fleck = root; let fleck = root;
@ -230,9 +230,7 @@ exports.generateJson = async function generate(flecks) {
hookImplementations.forEach(({column, hook, line}) => { hookImplementations.forEach(({column, hook, line}) => {
ensureHook(hook); ensureHook(hook);
r.hooks[hook].implementations.push({ r.hooks[hook].implementations.push({
column, filename: [join(root, path), line, column].join(':'),
filename: join(`**${root}**`, path),
line,
}); });
}); });
hookInvocations.forEach(({ hookInvocations.forEach(({
@ -243,9 +241,7 @@ exports.generateJson = async function generate(flecks) {
}) => { }) => {
ensureHook(hook); ensureHook(hook);
r.hooks[hook].invocations.push({ r.hooks[hook].invocations.push({
column, filename: [join(root, path), line, column].join(':'),
filename: join(`**${root}**`, path),
line,
type, type,
}); });
}); });