codeBelt / generate-template-files

A simple generator to create custom template files for any application
https://medium.com/@robertsavian/generate-template-files-with-ease-19b320615359
MIT License
209 stars 31 forks source link

Adds support for generateAll method #28

Closed helizabethwhite closed 5 years ago

helizabethwhite commented 5 years ago

rather than prompting the user to select from the list of template options provided in the config, generateAll allows users to process all of the options in one batch.

example config:

generateTemplateFiles([
    {
        option: 'Create new JS class',
        defaultCase: '(upperCase)',
        entry: {
            folderPath: './templates/new-service-js-class/',
        },
        stringReplacers: ['{{ServiceName}}'],
        output: {
            path: './scripts/',
        },
    },
    {
        option: 'Create new C# API',
        defaultCase: '(upperCase)',
        entry: {
            folderPath: './templates/new-service-cs-api/',
        },
        stringReplacers: ['{{ServiceName}}'],
        output: {
            path: './API/controllers/',
        },
    },
], true);

note the extra argument to the function

experience:

generate-template-files-demo

@codeBelt - please let me know if this potential enhancement makes sense to you. my inspiration was wanting to generate files in multiple directories with the same stringReplacer value(s), as this was all part of the same boilerplate step~ 🙂

codeBelt commented 5 years ago

@helizabethwhite I will look at this in the next couple of days.

codeBelt commented 5 years ago

@helizabethwhite I just tried this and you can do this with the current version (v2.1.0). Let me know if this satisfies you needs?

gen

generateTemplateFiles([
    {
        option: 'All',
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/DotNet',
        },
        stringReplacers: ['{{ServiceName}}', 'new-service-cs-api', 'new-service-js-class'],
        output: {
            path: './src/',
            pathAndFileNameDefaultCase: '(noCase)',
        },
    },
    {
        option: 'Create new JS class',
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/DotNet/new-service-js-class',
        },
        stringReplacers: ['{{ServiceName}}'],
        output: {
            path: './src/scripts/',
            pathAndFileNameDefaultCase: '(noCase)',
        },
    },
    {
        option: 'Create new C# API',
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/DotNet/new-service-cs-api',
        },
        stringReplacers: ['{{ServiceName}}'],
        output: {
            path: './src/API/controllers/',
            pathAndFileNameDefaultCase: '(noCase)',
        },
    },
]);
codeBelt commented 5 years ago

Also if you don't want the user to type in the paths for 'new-service-cs-api', 'new-service-js-class' then you can name the folders:

Screenshot 2019-07-26 10 26 56

helizabethwhite commented 5 years ago

@codeBelt but this solution requires that the templates exist under the same parent directory (DotNet), right? in my case, i wanted the templates to spawn under different directories, so preserving the individual configs (each with their own output.path) seemed like the way to do that.

thoughts?

codeBelt commented 5 years ago

You could put them under templates. I put it under (DotNet) so the option didn't bring my angular, react or vue folders in.

I think I understand what you are trying to do. The library gets you 99% there. How about making the folders dynamic like show below?

Screenshot 2019-07-26 15 18 09

✔ What do you want to generate? · All
✔ Replace {{ServiceName}} with: · NewService
✔ Replace {{scriptsFolder}} with: · something
✔ Replace {{controllersFolder}} with: · API/controllers/somthing
✔ Output path: · ./src/
✔ Overwrite files, continue? (y/N) · true

Screenshot 2019-07-26 15 26 45

At this point I feel the library provides you with the functionality you need. If need some thing more. You can check out https://yeoman.io or https://slushjs.github.io