javascript - Including/excluding globs for gulp.src -
javascript - Including/excluding globs for gulp.src -
i'm trying setup glob array javascript concat build task in gulp. directory construction looks follows:
├── │ └── about.js ├── assets ├── contact ├── core │ ├── navbar │ │ ├── navbar.js │ │ └── navbar.test.js │ ├── routing.js │ ├── routing.test.js │ ├── utils.js │ └── utils.test.js ├── generated │ ├── footer.js │ ├── header.js │ └── templates.js ├── home ├── app.js └── config.js
the order of files important:
generated/header.js app.js any of *.js files, except here below generated/templates.js generated/footer.jsi've wildly tried kinds of wildcards combination, globbing isn't strong me.
var inputfiles = [ 'generated/header.js', 'app.js', '!(generated)**/*.js', // <=---- ??? 'generated/templates.js', 'generated/footer.js', '!**/*.test.js' ];
so how include *.js
files except subdirectory?
thanks.
the best came with:
var gulp = require('gulp'); var tap = require('gulp-tap'); gulp.task('default', function() { homecoming gulp.src([ 'generated/header.js', 'app.js', '*.js', './!(generated)/**/*.js', // <- subdirs except 'generated' 'generated/{templates,footer}.js', '!**/*.test.js', '!node_modules/**' ]).pipe(tap(function(file) { console.log(file.path); })); });
running it:
∴ glob-test gulp [20:07:51] using gulpfile ~/desktop/glob-test/gulpfile.js [20:07:51] starting 'default'... /users/heikki/desktop/glob-test/generated/header.js /users/heikki/desktop/glob-test/app.js /users/heikki/desktop/glob-test/config.js /users/heikki/desktop/glob-test/gulpfile.js /users/heikki/desktop/glob-test/about/about.js /users/heikki/desktop/glob-test/core/routing.js /users/heikki/desktop/glob-test/core/utils.js /users/heikki/desktop/glob-test/core/navbar/navbar.js /users/heikki/desktop/glob-test/generated/templates.js /users/heikki/desktop/glob-test/generated/footer.js [20:07:51] finished 'default' after 326 ms
the main trick avoiding "!" character @ origin of glob when including files.
https://github.com/isaacs/minimatch#comparisons-to-other-fnmatchglob-implementations
"if pattern starts ! character, negated."
ps. placement of negated globs doesn't matter. moved end behind scenes.
javascript node.js gulp glob minimatch
Comments
Post a Comment