Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you follow the stack, <code>this.installDependencies</code> eventually works its way down to <a href="https://github.com/yeoman/generator/blob/45258c0a48edfb917ecf915e842b091a26d17f3e/lib/actions/install.js#L36" rel="noreferrer">https://github.com/yeoman/generator/blob/45258c0a48edfb917ecf915e842b091a26d17f3e/lib/actions/install.js#L36</a>:</p> <pre><code>this.spawnCommand(installer, args, cb) .on('error', cb) .on('exit', this.emit.bind(this, installer + 'Install:end', paths)) .on('exit', function (err) { if (err === 127) { this.log.error('Could not find ' + installer + '. Please install with ' + '`npm install -g ' + installer + '`.'); } cb(err); }.bind(this)); </code></pre> <p>Chasing this down further, <code>this.spawnCommand</code> comes from <a href="https://github.com/yeoman/generator/blob/master/lib/actions/spawn_command.js" rel="noreferrer">https://github.com/yeoman/generator/blob/master/lib/actions/spawn_command.js</a>:</p> <pre><code>var spawn = require('child_process').spawn; var win32 = process.platform === 'win32'; /** * Normalize a command across OS and spawn it. * * @param {String} command * @param {Array} args */ module.exports = function spawnCommand(command, args) { var winCommand = win32 ? 'cmd' : command; var winArgs = win32 ? ['/c'].concat(command, args) : args; return spawn(winCommand, winArgs, { stdio: 'inherit' }); }; </code></pre> <p>In other words, in your Generator's code, you can call <code>this.spawnCommand</code> anytime, and pass it the arguments you wish the terminal to run. As in, <code>this.spawnCommand('grunt', ['build'])</code>.</p> <p>So then the next question is where do you put that? Thinking linearly, you can only trust that <code>grunt build</code> will work after all of your dependencies have been installed. </p> <p>From <a href="https://github.com/yeoman/generator/blob/45258c0a48edfb917ecf915e842b091a26d17f3e/lib/actions/install.js#L67-69" rel="noreferrer">https://github.com/yeoman/generator/blob/45258c0a48edfb917ecf915e842b091a26d17f3e/lib/actions/install.js#L67-69</a>, <code>this.installDependencies</code> accepts a callback, so your code might look like this:</p> <pre><code>this.on('end', function () { this.installDependencies({ skipInstall: this.options['skip-install'], callback: function () { this.spawnCommand('grunt', ['build']); }.bind(this) // bind the callback to the parent scope }); }); </code></pre> <p>Give it a shot! If all goes well, you should add some error handling on top of that new <code>this.spawnCommand</code> call to be safe.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload