diff --git a/lib/buildtime/RoutifyBuildtime.js b/lib/buildtime/RoutifyBuildtime.js index 44ab0de5..e5240127 100644 --- a/lib/buildtime/RoutifyBuildtime.js +++ b/lib/buildtime/RoutifyBuildtime.js @@ -17,6 +17,7 @@ import { createParallelHooksCollection } from 'hookar' import { devHelperPlugin } from './plugins/devHelper/helper.js' import { metaCapturePlugin } from './plugins/metaCapture/index.js' import { log, logs } from './logMsgs.js' +import { omitDirFromPathPlugin } from './plugins/omitFromPath/index.js' /** @returns {Partial} */ const getDefaults = () => ({ @@ -46,6 +47,7 @@ const getDefaults = () => ({ watcherPlugin, devHelperPlugin, metaCapturePlugin, + omitDirFromPathPlugin, ], watch: false, }) diff --git a/lib/buildtime/plugins/omitFromPath/index.js b/lib/buildtime/plugins/omitFromPath/index.js new file mode 100644 index 00000000..25d51531 --- /dev/null +++ b/lib/buildtime/plugins/omitFromPath/index.js @@ -0,0 +1,18 @@ +/** @type {RoutifyBuildtimePlugin} */ +export const omitDirFromPathPlugin = { + name: 'omitDirFromPath', + after: 'filemapper', + before: 'bundler', + build: ({ instance }) => { + // find file names that are enclosed in a parenthesis + const omittedDir = node => node.file.name.match(/\(([^)]+)\)/) + + // remove the node and move its children to the parent + instance.nodeIndex.filter(omittedDir).forEach(node => { + node.children.forEach(child => { + child.parent = node.parent + node.remove() + }) + }) + }, +}