Search code examples
node.jsyeomanyeoman-generatoryo

do not run loop queue when specify argument in yeoman generator


Yeoman generator will run through all defined functions by default, Now I want to specify a argument with yo my_generator model username:string password:string as an isolation command to create model files, but do not run prompt and copy templates

module.exports = class extends Generator {
  constructor(args, opts) {
    super(args, opts);

    this.argument('model', {desc: 'model generete', required: false, type: String})
  }

  prompting(){
    ....
  }

  copyTemplates(){
    ...
  }

  model(){
    this.log('only run when "model" argument provide')
  }
};

Solution

  • There's sub generators for that: yo my_generator:model

    See the folder tree section of official documentation