/**
 * This file is part of Shoop.
 *
 * Copyright (c) 2012-2015, Shoop Ltd. All rights reserved.
 *
 * This source code is licensed under the AGPLv3 license found in the
 * LICENSE file in the root directory of this source tree.
 */
var gulp = require("gulp");
var glob = require("glob");
var bower = require("bower");
var gutil = require("gulp-util");
var _ = require("lodash");
var path = require("path");
var fs = require("fs");


gulp.task('bower', [], function(complete) {
    glob("{modules,static_src}/**/bower.json", function(er, files) {
        files = _.reject(files, function(path) {
            return /node_modules/.test(path)
        });
        files = _.reject(files, function(path) {
            return /bower_components/.test(path)
        });
        var deferredComplete = _.after(files.length, complete);
        _.each(files, function(bowerJsonPath) {
            var dir = path.dirname(bowerJsonPath);
            var bowerComponentsDir = path.join(dir, "bower_components");
            gutil.log("Bower start:", bowerJsonPath);
            if(!fs.existsSync(bowerComponentsDir)) {
                fs.mkdirSync(bowerComponentsDir);
                gutil.log("  mkdir:", bowerComponentsDir);
            }
            var install = bower.commands.install(
                [],
                {},
                {cwd: dir, directory: "bower_components"}
            );
            install.on('log', function(log) {
                gutil.log("Bower/" + bowerJsonPath + ":" + log.message);
            });
            install.on('end', function() {
                gutil.log("Bower complete:", bowerJsonPath);
                deferredComplete();
            });
        });
    });
});

@@ -442,15 +442,15 @@
 ask(
-'
+%22
 bower
-'
+%22
 , %5B%5D
@@ -523,245 +523,103 @@
 n%22, 
-function(er, files) %7B%0A        files = _.reject(files, function(path) %7B%0A            return /node_modules/.test(path)%0A        %7D);%0A        files = _.reject(files, function(path) %7B%0A            return /bower_components/.test(path)%0A        %7D);
+%7B%0A        ignore: %5B%22**/node_modules/**%22, %22**/bower_components/**%22%5D%0A    %7D, function(er, files) %7B
 %0A   
@@ -1271,13 +1271,13 @@
 .on(
-'log'
+%22log%22
 , fu
@@ -1406,13 +1406,13 @@
 .on(
-'end'
+%22end%22
 , fu

Use `glob`'s ignore instead of baking our own.