Created
July 3, 2014 11:23
-
-
Save newtriks/96c306e9cdde5c26f2b1 to your computer and use it in GitHub Desktop.
Gulp task to run bower install/update and remove dependencies.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var bower = require('bower'); | |
var del = require('del'); | |
var _ = require('lodash'); | |
var deleteDeps = function (deps, cb) { | |
var path = bower.config.cwd + "/" + bower.config.directory; | |
_.each(deps, function (dep) { | |
del(path + "/" + dep, function (e) {}); | |
}); | |
cb(); | |
}; | |
var bowerTask = function (fn, cb) { | |
var deps = _.chain(require(bower.config.cwd + '/bower.json').dependencies).keys().value(); | |
var pkgs = []; | |
bower.commands[fn](deps) | |
.on('log', function (o) { | |
if (o.id !== 'install') { | |
return; | |
} | |
pkgs.push(o.data.endpoint.name); | |
}) | |
.on('end', function (installed) { | |
deleteDeps(_.difference(pkgs, deps), cb); | |
}); | |
}; | |
gulp.task('bowerInstall', function (cb) { | |
bowerTask('install', cb); | |
}); | |
gulp.task('bowerUpdate', function (cb) { | |
bowerTask('update', cb); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this task when using Restangular (not Browserify compatible) in a Browserify based project. Restangular dependencies include Angular and Lodash, I already have these via npm, so do not need the duplication.
This takes no prisoners, all dependencies of the installed packages are removed!
If I have missed a Bower configuration option that disables installing dependencies I would be keen to hear!