Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigItem.output.path as string or function #57

Open
danieletulone opened this issue Apr 22, 2021 · 1 comment
Open

ConfigItem.output.path as string or function #57

danieletulone opened this issue Apr 22, 2021 · 1 comment

Comments

@danieletulone
Copy link

danieletulone commented Apr 22, 2021

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.

@codeBelt
Copy link
Owner

sure you can create a pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants