generate-template-files
generate-template-files copied to clipboard
ConfigItem.output.path as string or function
Hi, I'm clone this repo and I make an implementation for write output.path not only as string but also as function that return a string.
Reason:
- I want to create a Vue File and I'm using Atomic Design Pattern
- I want to create an atom, molecole, organism, template or page file.
So path, instead of be a simple string, will be a function that check input data and generate different output paths.
This is my working configuration:
const items = [
{
option: 'Vue File',
defaultCase: '(pascalCase)',
entry: {
folderPath: './tools/templates/vue/__file__.vue',
},
stringReplacers: ['__type__', '__file__'],
output: {
path: (replacers, configItem) => {
function search(key, replacers){
let i = 0
let l = replacers.length
for (i; i < l; i++) {
if (replacers[i].slot === key) {
return replacers[i];
}
}
}
const type = search('__type__(kebabCase)', replacers)
if (type.slotValue === 'page') {
return `./src/pages/__file__.vue`
} else if (['atom', 'component', 'organism'].includes(type.slotValue)) {
return `./src/components/__type__(kebabCase)s/__file__.vue`
}
throw new Error('Type specified is not valid.')
},
pathAndFileNameDefaultCase: '(pascalCase)',
},
},
]
If possibile, I want to create a pull request for this new feature.
sure you can create a pr