Yeoman composeWith: change directory?

I have a yoman generator (GenA) that uses a subgenerator (GenB). GenA will create a folder in my application structure public/

, and I want GenB to run from that folder and place all of its files in /public

(mainly because I want to be able to install dependencies via Bower in GenB).

Relevant GenA Part:

prompting: function() {
  this.prompt(prompts, function(ans) {
    this.composeWith('GenB', {
      options: {
        application_name: this.application_name
      }
    },
    {
      local: require.resolve('path/to/GenB')
    });
    done();
  }.bind(this))
};

      

Relevant GenB part:

this.bowConfig = {
  "directory": "public/bower_components"
};
this.fs.writeJSON('.bowerrc', this.bowConfig);

this.bow = {
  "name": this.name,
  "version": "1.0.0",
  "description": "foo",
  "dependencies": { ... },
  "devDependencies": { ... }
};
this.fs.writeJSON('bower.json', this.bow);

// and a little later...
install: function() {
  this.bowerInstall() // this looks for bower.json in the current directory
  // ...
}

      

If I change my settings to what I write instead public/bower.json

, then when yoman calls this.bowerInstall

, it doesn't see my file bower.json

and therefore doesn't install my dependencies.

If I try to change the root path for all GenBs like so:

constructor: function () {
  generators.Base.apply(this, arguments);
  this.destinationRoot('public/')
}

      

then all generated files, including those from the parent GenA, are created based on the changed destinationRoot.

Is there any other way to specify where to put the files generated via the generated and composeWith ()? Should I handle a directory other than the parent generator in a different way?

Any help is appreciated.


+3


source to share


1 answer


You can spawn the command with cwd. You can start the banning process manually, specify cwd and it will work.

I'm not 100% sure if this will work, but maybe it will work as well:



this.bowerInstall(null, {cwd: 'public/'});

      

0


source







All Articles