From dd116de20c04526bbdc82579d9d741b4c21de64e Mon Sep 17 00:00:00 2001 From: cha0s Date: Fri, 26 Jan 2024 09:08:57 -0600 Subject: [PATCH] feat(dox): rewrite filenames --- package.json | 2 +- packages/dox/build/commands.js | 33 ++++++++++++++++++++++++++++++++- packages/dox/build/generate.js | 18 +++++++----------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 1cea19c..1451136 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "build": "lerna run build", "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", "publish": "lerna publish --conventional-commits --contents=dist --registry https://registry.npmjs.org", "test": "lerna exec 'yarn && yarn test'" diff --git a/packages/dox/build/commands.js b/packages/dox/build/commands.js index 80a3f52..9134f66 100644 --- a/packages/dox/build/commands.js +++ b/packages/dox/build/commands.js @@ -14,7 +14,7 @@ module.exports = (program, flecks) => { const commands = {}; commands.dox = { description: 'Generate documentation', - action: async (subcommand, outputPath) => { + action: async (subcommand, outputPath, {rewriteFilenames = []}) => { let actualOutputPath = outputPath; if (!actualOutputPath) { switch (subcommand) { @@ -32,6 +32,34 @@ module.exports = (program, flecks) => { await mkdir(actualOutputPath, {recursive: true}); let output; 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) { case 'docusaurus': output = Object.fromEntries( @@ -62,6 +90,9 @@ module.exports = (program, flecks) => { .choices(['docusaurus', 'json']), program.createArgument('[output path]', 'Where the files are output'), ], + options: [ + program.createOption('-r, --rewrite-filenames [pairs...]', 'rewrite filenames'), + ], }; return commands; }; diff --git a/packages/dox/build/generate.js b/packages/dox/build/generate.js index a40d35b..157982d 100644 --- a/packages/dox/build/generate.js +++ b/packages/dox/build/generate.js @@ -125,8 +125,8 @@ exports.generateDocusaurusHookPage = (hooks) => { source.push('
'); source.push('Implementations'); source.push(''); source.push('
'); @@ -136,8 +136,8 @@ exports.generateDocusaurusHookPage = (hooks) => { source.push('
'); source.push('Invocations'); source.push(''); source.push('
'); @@ -216,7 +216,7 @@ exports.generateJson = async function generate(flecks) { r.buildFiles.push(...buildFiles); r.todos.push(...todos.map((todo) => ({ ...todo, - filename: join(`**${root}**`, path), + filename: join(root, path), }))); if (config.length > 0) { let fleck = root; @@ -230,9 +230,7 @@ exports.generateJson = async function generate(flecks) { hookImplementations.forEach(({column, hook, line}) => { ensureHook(hook); r.hooks[hook].implementations.push({ - column, - filename: join(`**${root}**`, path), - line, + filename: [join(root, path), line, column].join(':'), }); }); hookInvocations.forEach(({ @@ -243,9 +241,7 @@ exports.generateJson = async function generate(flecks) { }) => { ensureHook(hook); r.hooks[hook].invocations.push({ - column, - filename: join(`**${root}**`, path), - line, + filename: [join(root, path), line, column].join(':'), type, }); });