Search code examples
javascriptnode.jsyeomanyeoman-generator

Yeoman: install dependencies from cache


I want to add an option for when debugging my generator or when working offline that will download npm and bower stuff from cache (by using --cache-min 999999 and --offline respectively).

Currently, this is my code (which both installs the dependencies and calls grunt bower):

CallumGenerator.prototype.installDeps = function () {
    var cb = this.async();

    this.installDependencies({
        skipInstall: this.options['skip-install'],
        callback: function () {
            this.spawnCommand('grunt', ['bower'])
                .on('close', function () {
                    cb();
                });
        }.bind(this)
    });
};

It looks like I'll most likely have to call .npmInstall() and .bowerInstall() manually in order to specify options (I think?), but I don't know how to specify any options. To clarify, this is how I would do it in the console:

npm install --cache-min 999999 --save-dev grunt-contrib-less
bower install --offline --save jquery#1.10.2

Solution

  • You can't specify options directly from #installDependencies see: https://github.com/yeoman/generator/blob/master/lib/actions/install.js#L44-L69

    You can specify them for both #npmInstall and bowerInstall https://github.com/yeoman/generator/blob/master/lib/actions/install.js#L121-L143

    The options you pass are in the form of an object hash and will be parsed by dargs node modules, so you should follow the module conventions for declaring options