Last active
August 29, 2015 13:56
-
-
Save jamescrowley/9058433 to your computer and use it in GitHub Desktop.
Output a file per folder in gulp
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 fs = require('fs'); | |
var path = require('path'); | |
var es = require('event-stream'); | |
var gulp = require('gulp'); | |
var concat = require('gulp-concat'); | |
var rename = require('gulp-rename'); | |
var uglify = require('gulp-uglify'); | |
var scriptsPath = './src/scripts/'; | |
function getFolders(dir){ | |
return fs.readdirSync(dir) | |
.filter(function(file){ | |
return fs.statSync(path.join(dir, file)).isDirectory(); | |
}); | |
} | |
gulp.task('scripts', function() { | |
var folders = getFolders(scriptsPath); | |
var tasks = folders.map(function(folder) { | |
// concat into foldername.js | |
// write to output | |
// minify | |
// rename to folder.min.js | |
// write to output again | |
return gulp.src(path.join(scriptsPath, folder, '/*.js')) | |
.pipe(concat(folder + '.js')) | |
.pipe(gulp.dest(scriptsPath)) | |
.pipe(uglify()) | |
.pipe(rename(folder + '.min.js')) | |
.pipe(gulp.dest(scriptsPath)); | |
}); | |
return es.concat.apply(null, tasks); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment