Search code examples
node.jsgruntjsyeomanyeoman-generator

Is it possible to run the grunt command after a yeoman generator install?


Basically I'd like to run grunt after my generator finishes installing dependencies, I found that you can add a callback function to the installDependencies method to run after everything has been installed like this:

this.on('end', function () {
    this.installDependencies({
        skipInstall: options['skip-install'],
        callback: function () {
            console.log('All done!');
        }
    });
});

However I'm not sure how to run the grunt task (as in going to the terminal and running "grunt")


Solution

  • After this.on('end') add this lines

    // Now you can bind to the dependencies installed event
    this.on('dependenciesInstalled', function() {
        this.spawnCommand('grunt', ['build']);
    });
    

    check this topic for more details.

    But if you're using the latest update of yeomen, you'll need to make it like this

    this.on('end', function () {
      if (!this.options['skip-install']) {
        this.npmInstall();
        this.spawnCommand('grunt', ['prepare']); // change 'prepare' with your task.
      }
    });