Search code examples
javascriptscaffolding

Scaffolding - Extend a js object


I'm working with scaffolt (https://www.npmjs.com/package/scaffolt) to generate some default templates.

I am using handlebars to handle the template.

This works as expected, but i would also like ot extend a JS object while scaffolding.

Basically, i have an object that looks like this:

module.export = {
    name: {
        "main": ["test"],
        "plus": ["test", "test2"],
    },
    value: {
        "test": [...],
        "test2": [...]
    }
};

and i would like to extend this when i run scaffold and append to both name and value the name of the template i'm scaffolding.

So for instance, if i run scaffolt -g generators template abc the js file will look like this:

module.export = {
   name: {
      "main": ["test"],
      "plus": ["test", "test2"],
      "abc" : []
   },
   value: {
      "test": [...],
      "test2": [...],
      "abc": []
   }
};

(where abc was added)

Is it possbile?

Thanks


Solution

  • At the end i managed to solve this but running as a "callback" a postscript.

    Basically, in the package.json file i added the command i need to run and i callled it "scaffolt". Then, i've added a postscaffolt command to run a gulp task to inject the stuff i need in place.

    The package.json file look something like this:

    scripts: {
     "scaffolt" "....",
     "postscaffolt": "..."
    }