diff --git a/packages/dox/src/commands.js b/packages/dox/src/commands.js index d422de7..d87d91a 100644 --- a/packages/dox/src/commands.js +++ b/packages/dox/src/commands.js @@ -21,10 +21,10 @@ export default (program, flecks) => { const state = await parseFlecks(flecks); debug('parsed'); debug('Generating hooks page...'); - const hookPage = generateHookPage(state.hooks); + const hookPage = generateHookPage(state.hooks, flecks); debug('generated'); debug('Generating TODO page...'); - const todoPage = generateTodoPage(state.todos); + const todoPage = generateTodoPage(state.todos, flecks); debug('generated'); const output = join(FLECKS_CORE_ROOT, 'dox'); await mkdir(output, {recursive: true}); diff --git a/packages/dox/src/generate.js b/packages/dox/src/generate.js index 4dbff40..b7b94e2 100644 --- a/packages/dox/src/generate.js +++ b/packages/dox/src/generate.js @@ -1,4 +1,14 @@ -export const generateHookPage = (hooks) => { +const makeFilenameRewriter = (filenameRewriters) => (filename, line, column) => ( + Object.entries(filenameRewriters) + .reduce( + (filename, [from, to]) => filename.replace(new RegExp(from), to), + `${filename}:${line}:${column}`, + ) +); + +export const generateHookPage = (hooks, flecks) => { + const {filenameRewriters} = flecks.get('@flecks/dox'); + const rewriteFilename = makeFilenameRewriter(filenameRewriters); const source = []; source.push('# Hooks'); source.push(''); @@ -35,7 +45,7 @@ export const generateHookPage = (hooks) => { source.push('Implementations'); source.push(''); source.push(''); @@ -46,7 +56,7 @@ export const generateHookPage = (hooks) => { source.push('Invocations'); source.push(''); source.push(''); @@ -68,7 +78,9 @@ export const generateHookPage = (hooks) => { return source.join('\n'); }; -export const generateTodoPage = (todos) => { +export const generateTodoPage = (todos, flecks) => { + const {filenameRewriters} = flecks.get('@flecks/dox'); + const rewriteFilename = makeFilenameRewriter(filenameRewriters); const source = []; source.push('# TODO'); source.push(''); @@ -76,7 +88,7 @@ export const generateTodoPage = (todos) => { source.push(''); if (todos.length > 0) { todos.forEach(({filename, loc: {start: {column, line}}, text}) => { - source.push(`- ${filename}:${line}:${column}`); + source.push(`- ${rewriteFilename(filename, line, column)}`); text.split('\n').forEach((line) => { source.push(` > ${line}`); }); diff --git a/packages/dox/src/parser.js b/packages/dox/src/parser.js index b62218d..b7d4e41 100644 --- a/packages/dox/src/parser.js +++ b/packages/dox/src/parser.js @@ -225,6 +225,7 @@ export const parseFleckRoot = async (root, state) => { const sources = await fleckSources(resolved); await Promise.all( sources.map(async (source) => { + // @todo Aliased fleck paths are gonna be bad. await parseFile(source, join(root, source.slice(resolved.length)), state); }), ); diff --git a/packages/dox/src/server.js b/packages/dox/src/server.js index a98b237..6a49875 100644 --- a/packages/dox/src/server.js +++ b/packages/dox/src/server.js @@ -5,5 +5,8 @@ import commands from './commands'; export default { [Hooks]: { '@flecks/core/commands': commands, + '@flecks/core/config': () => ({ + filenameRewriters: [], + }), }, };