jondot / hygen

The simple, fast, and scalable code generator that lives in your project.
http://www.hygen.io
MIT License
5.68k stars 256 forks source link

[Solved] JSON payload to generator #400

Open rogrdat opened 2 years ago

rogrdat commented 2 years ago

I used to be able to execute this code (ver 4.x I think).., where the input to the generator was a JSON entity.., but have not been able to in more recent code. Could be something I'm missing.

async function run() {
   await execa('hygen', ['typeGen', 'new', `--args=${JSON.stringify(types[0])}`]).stdout?.pipe(process.stdout);
}
rogrdat commented 2 years ago

Solved the issue this way --

async function run() {
   await execa('hygen', ['typeGen', 'new',  JSON.stringify(types[0]) ]).stdout?.pipe(process.stdout);
}

added a new index.js file to the generator folder with the following code ..,

module.exports = {
    params: ({ args }) => {
       return JSON.parse(args.name);
  }
}

While this works.. I think there could be a more elegant way to execute this approach without having to create the boiler-plate code. Suggestions for a more elegant option?

Anyway, love the library and simplicity.