feat: rewrite filenames

This commit is contained in:
cha0s 2022-03-07 02:44:48 -06:00
parent 8d834f7a2e
commit a210f636bc
4 changed files with 23 additions and 7 deletions

View File

@ -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});

View File

@ -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('<summary>Implementations</summary>');
source.push('<ul>');
implementations.forEach(({filename, loc: {start: {column, line}}}) => {
source.push(`<li>${filename}:${line}:${column}</li>`);
source.push(`<li>${rewriteFilename(filename, line, column)}</li>`);
});
source.push('</ul>');
source.push('</details>');
@ -46,7 +56,7 @@ export const generateHookPage = (hooks) => {
source.push('<summary>Invocations</summary>');
source.push('<ul>');
invocations.forEach(({filename, loc: {start: {column, line}}}) => {
source.push(`<li>${filename}:${line}:${column}</li>`);
source.push(`<li>${rewriteFilename(filename, line, column)}</li>`);
});
source.push('</ul>');
source.push('</details>');
@ -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}`);
});

View File

@ -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);
}),
);

View File

@ -5,5 +5,8 @@ import commands from './commands';
export default {
[Hooks]: {
'@flecks/core/commands': commands,
'@flecks/core/config': () => ({
filenameRewriters: [],
}),
},
};