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

When using slotValue I get TypeError: prop.split is not a function #23

Closed edhine closed 5 years ago

edhine commented 5 years ago

// Angular

    {
        option: "Angular Ngrx Store",
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/angular/ngrx-store/',
        },
        stringReplacers: [{slot:'__name__', slotValue: 'asdasdada'}, '__model__'],
        output: {
            path: './src/app/stores/__name__(lowerCase)',
            pathAndFileNameDefaultCase: '(kebabCase)',
        },
    },

√ What do you want to generate? · Angular Ngrx Store (node:19132) UnhandledPromiseRejectionWarning: TypeError: prop.split is not a function

codeBelt commented 5 years ago

stringReplacers only accepts an array of strings. It should be:

 stringReplacers: ['__name__', '__model__'],

I see that you are trying to use an object {slot:'__name__', slotValue: 'asdasdada'}. This is wrong. You will only see that structure in the onComplate callback.

edhine commented 5 years ago

Is there any way to define the variables in any file or other way without having to enter them by console?

codeBelt commented 5 years ago

Not at the moment but I could add that in. So you want some like this:

const someVarData = 'Dude!';

generateTemplateFiles([
    // Angular
    {
        option: "Angular Ngrx Store",
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/angular/ngrx-store/',
        },
        stringReplacers: [{slot:'__name__', slotValue: someVarData}, '__model__'],
        output: {
            path: './src/app/stores/__name__(lowerCase)',
            pathAndFileNameDefaultCase: '(kebabCase)',
        },
    },
]);

I am going to assume that the only question that will be asked is for __model__ because __name__ will already have a value. Anywhere in your templates __name__ will be replaced with Dude!. Does that sound correct?

edhine commented 5 years ago

yes, basically the objective is to define them both in a file or directly in the generator, since I want to upload the templates to git and to encode a process that downloads the git template and applies the already defined variables

codeBelt commented 5 years ago

I think I will create a new property dynamicReplacers. I will try to work on in the next day or two.

const someVarData = 'Dude!';

generateTemplateFiles([
    // Angular
    {
        option: "Angular Ngrx Store",
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/angular/ngrx-store/',
        },
        stringReplacers: ['__model__'],
        dynamicReplacers: [{slot:'__name__', slotValue: someVarData}],
        output: {
            path: './src/app/stores/__name__(lowerCase)',
            pathAndFileNameDefaultCase: '(kebabCase)',
        },
    },
]);
edhine commented 5 years ago

Thank you very much, I know it will help several people, I love how it is done, very good job: D! I'm sorry for the English I use because my native language is Spanish.

codeBelt commented 5 years ago

@Edhine check out my changes: https://github.com/codeBelt/generate-template-files/pull/24/files

Pull that branch down and do a yarn && yarn build. Then cd in to the examples folder and do yarn generate. If you look at the templates/angular/ngrx-store/__name__.reducer.spec.ts you can see I added

// Version: __version__(noCase)
// Description: __description__(noCase)

Here I am using data from the package.json file.

const config = require('../package.json');

generateTemplateFiles([
    // Angular
    {
        option: "Angular Ngrx Store",
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/angular/ngrx-store/',
        },
        stringReplacers: ['__name__', '__model__'],
        dynamicReplacers: [
            {slot:'__version__', slotValue: config.version},
            {slot:'__description__', slotValue: config.description}
        ],
        output: {
            path: './src/app/stores/__name__(lowerCase)',
            pathAndFileNameDefaultCase: '(kebabCase)',
        },
    }
]);

Let me know if this is what you wanted

edhine commented 5 years ago

It is exactly what I mentioned !!!

codeBelt commented 5 years ago

Ok, I will try to get a new build out tomorrow.

codeBelt commented 5 years ago

@Edhine This feature is now in version 2.1.0