generate-template-files icon indicating copy to clipboard operation
generate-template-files copied to clipboard

ConfigItem.output.path as string or function

Open danieletulone opened this issue 3 years ago • 1 comments

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:

  1. I want to create a Vue File and I'm using Atomic Design Pattern
  2. 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.

danieletulone avatar Apr 22 '21 04:04 danieletulone

sure you can create a pr

codeBelt avatar Apr 22 '21 13:04 codeBelt