From eaf1adeeef183409d8236611abf0d545008ddf11 Mon Sep 17 00:00:00 2001 From: Michael Stramel Date: Sun, 16 Apr 2017 04:55:04 -0500 Subject: [PATCH] New: option shorthand on installDependencies method (#1015) --- lib/actions/install.js | 24 +++++++++++++++++------- test/install.js | 10 ++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/actions/install.js b/lib/actions/install.js index 38e56c3d..3ad1e50d 100644 --- a/lib/actions/install.js +++ b/lib/actions/install.js @@ -82,10 +82,16 @@ install.runInstall = function (installer, paths, options, spawnOptions) { * npm: true * }).then(() => console.log('Everything is ready!')); * + * @example + * this.installDependencies({ + * yarn: {force: true}, + * npm: false + * }).then(() => console.log('Everything is ready!')); + * * @param {Object} [options] - * @param {Boolean} [options.npm=true] - whether to run `npm install` - * @param {Boolean} [options.bower=true] - whether to run `bower install` - * @param {Boolean} [options.yarn=false] - whether to run `yarn install` + * @param {Boolean|Object} [options.npm=true] - whether to run `npm install` or can be options to pass to `dargs` as arguments + * @param {Boolean|Object} [options.bower=true] - whether to run `bower install` or can be options to pass to `dargs` as arguments + * @param {Boolean|Object} [options.yarn=false] - whether to run `yarn install` or can be options to pass to `dargs` as arguments * @param {Boolean} [options.skipMessage=false] - whether to log the used commands * @return {Promise} Resolved once done, rejected if errors */ @@ -100,20 +106,24 @@ install.installDependencies = function (options) { '<% if (!skipInstall) { %> If this fails, try running the command yourself.<% } %>\n\n') }; + const getOptions = options => { + return typeof options === 'object' ? options : null; + }; + if (options.npm !== false) { msg.commands.push('npm install'); commands.push(cb => { - this.npmInstall(null, null).then( + this.npmInstall(null, getOptions(options.npm)).then( val => cb(null, val), cb ); }); } - if (options.yarn === true) { + if (options.yarn) { msg.commands.push('yarn install'); commands.push(cb => { - this.yarnInstall(null, null).then( + this.yarnInstall(null, getOptions(options.yarn)).then( val => cb(null, val), cb ); @@ -123,7 +133,7 @@ install.installDependencies = function (options) { if (options.bower !== false) { msg.commands.push('bower install'); commands.push(cb => { - this.bowerInstall(null, null).then( + this.bowerInstall(null, getOptions(options.bower)).then( val => cb(null, val), cb ); diff --git a/test/install.js b/test/install.js index 8d882c43..88d17293 100644 --- a/test/install.js +++ b/test/install.js @@ -191,5 +191,15 @@ describe('Base (actions/install mixin)', () => { this.dummy.run(); return promise; }); + + it('spawn yarn and bower with options', function () { + const promise = this.dummy.installDependencies({yarn: {force: true}, bower: {depth: 0}, npm: false}).then(() => { + sinon.assert.calledTwice(this.spawnCommandStub); + sinon.assert.calledWithExactly(this.spawnCommandStub, 'bower', ['install', '--depth=0'], {}); + sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['install', '--force'], {}); + }); + this.dummy.run(); + return promise; + }); }); });