I have a unknown number of folders inside a directory called app
that I am looping through to create a folderName.min.js
for each.
Gulp script:
var es = require('event-stream');
var uglify = require('gulp-uglifyjs');
var fs = require('fs');
var path = require('path');
function getFolders(dir) {
return fs.readdirSync(dir)
.filter(function (file) {
return fs.statSync(path.join(dir, file)).isDirectory();
})
}
gulp.task('js', function () {
var folders = getFolders('./src/app/');
var streams = folders.map(function (folder) {
return gulp.src(folder + '**/*.js')
.pipe(uglify(folder + '.min.js', {
mangle: true
}))
.pipe(gulp.dest('./dist/js'))
});
return es.concat.apply(null, streams);
});
The problem I am running in to is that not every folder contains *.js
files. When gulp-uglifyjs encounters this case, I get
gulp-uglifyjs - No files given; aborting minification
and the stream aborts and all subsequent tasks do not get run. Am I able to
a) tell uglifyjs to proceed anyway if it runs in to this case
b) skip the task if gulp.src returned no files?