callumacrae
callumacrae

Reputation: 8433

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

Upvotes: 3

Views: 1447

Answers (2)

callumacrae
callumacrae

Reputation: 8433

The code I used, which should be fine for anyone to use (you might want to get rid of the final callback, though):

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

    this.npmInstall(null, {
        skipInstall: this.options['skip-install'],
        cacheMin: this.cachedDeps ? 999999 : 0
    }, function () {
        this.bowerInstall(null, {
            skipInstall: this.options['skip-install'],
            offline: this.cachedDeps
        }, function () {
            this.spawnCommand('grunt', ['bower'])
                .on('close', function () {
                    cb();
                });
        }.bind(this));
    }.bind(this));
};

It works fine. this.cachedDeps will define whether the cache is used or not.

Upvotes: 0

Simon Boudrias
Simon Boudrias

Reputation: 44599

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

Upvotes: 2

Related Questions