Skip to content

Commit

Permalink
New: option shorthand on installDependencies method (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
stramel authored and SBoudrias committed Apr 16, 2017
1 parent e296e52 commit eaf1ade
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/actions/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
);
Expand All @@ -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
);
Expand Down
10 changes: 10 additions & 0 deletions test/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});

0 comments on commit eaf1ade

Please sign in to comment.