Skip to content

Commit

Permalink
Add Blueprint.prototype.addBowerPackageToProject.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Aug 31, 2014
1 parent 330be3d commit 66a1e28
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/models/blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,36 @@ Blueprint.prototype.addPackageToProject = function(packageName, version) {
return this._exec(command);
};

/*
Used to add a package to the projects `bower.json`.
Generally, this would be done from the `afterInstall` hook, to
ensure that a package that is required by a given blueprint is
available.
@method addBowerPackageToProject
@param {String} packageName
@param {String} target
@return {Promise}
*/
Blueprint.prototype.addBowerPackageToProject = function(packageName, target) {
var BowerInstallTask = require('../tasks/bower-install');
var task = new BowerInstallTask({
ui: this.ui,
project: this.project
});
var packageNameAndVersion = packageName;

if (target) {
packageNameAndVersion += '#' + target;
}

return task.run({
verbose: true,
packages: [packageNameAndVersion]
});
};

/*
@private
@method _exec
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/bower-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ module.exports = Task.extend({
var bower = this.bower;
var bowerConfig = this.bowerConfig;
var ui = this.ui;
var packages = options.packages || [];

ui.pleasantProgress.start(chalk.green('Installing browser packages via Bower'), chalk.green('.'));

var config = bowerConfig.read();
config.interactive = true;

return new Promise(function(resolve, reject) {
bower.commands.install([], { save: true }, config) // Packages, options, config
bower.commands.install(packages, { save: true }, config) // Packages, options, config
.on('log', logBowerMessage)
.on('prompt', ui.prompt.bind(ui))
.on('error', reject)
Expand Down

0 comments on commit 66a1e28

Please sign in to comment.