0

I've the following gulp build process in place.

gulp.task("watch", function(){
    gulp.watch("public/admin/js/**/*.js", ["login"]);
}

gulp.task("login", function() {
    var js = [
        "!public/admin/js/api",
        "public/admin/js/*.js",
        "public/admin/js/controller/**/*.js",
        "public/admin/js/model/**/*.js",
        "public/admin/js/view/**/*.js"
    ];
    gulp.src(js)
        .pipe(concat("app.min.js"))
        .pipe(gulp.dest("public/admin/js"));
});

1) I'm unable to add files that are in the root. public/admin/js/*.js, is not working

2) I feel there's a bit of duplication involved, if someone can please help me rewrite this. In short I want to concatenate all under /public/admin minus /public/admin/api

P.S. and of course don't wanna include app.min.js again from the last build which is of course will be on the root.

P.P.S I've this build process repeated for several project folders over and over again, any ideas for re-using this logic. right now I'm setting up different watches for each folder and building their app.min.js.

user2727195
  • 7,122
  • 17
  • 70
  • 118

1 Answers1

0

"public/admin/js/" is repeated and im betting those aren't the only tasks that use it. In which case why don't you set it as a global variable via module.exports in your own config file? That way you can require it and set it to $ in which case your tasks will look something like:

module.exports.JSadmin = "public/admin/js/"

var $ = require('./globalConfig');

gulp.task("watch", function(){
    gulp.watch($.JSadmin + "**/*.js", ["login"]);
}

and for your other task you could create a dynamic array by looping through and appending the base directory, then using that array for your src as normal.

Not being able to add files in root, i believe its because you're exclusion statement is first (can't remember why), furthermore it is not necessary since you're stating which subdirectories to use in your array.

Check glob syntax for more info.

marblewraith
  • 768
  • 5
  • 16