Skip to content

Instantly share code, notes, and snippets.

@AntouanK
Created February 26, 2014 11:20
Show Gist options
  • Select an option

  • Save AntouanK/9227788 to your computer and use it in GitHub Desktop.

Select an option

Save AntouanK/9227788 to your computer and use it in GitHub Desktop.
Gulp recipe
var gulp = require('gulp'),
fs = require('fs'),
rimraf = require('gulp-rimraf'),
Q = require('q'),
copyFilesTo;
// clean the target folder, so we can copy there the new build output
gulp.task('cleanTargetFolder', function(done){
gulp
// get everything except the gulpfile
.src(['*', '!gulpfile.js', '!dev'], { read: false })
.pipe(rimraf())
.on('end', function(){
console.log('target folder ' + __dirname + ' is now clean');
done();
});
});
copyFilesTo = function(path, cb){
gulp
.src('dev/**/*')
//.pipe(doSomethingHere())
.pipe(gulp.dest(path))
.on('end',cb);
};
// we have a task that makes our new directories, which depends on the 'cleanTargetFolder' task
gulp.task('makeDirs', ['cleanTargetFolder'], function(){
var dirNames = ['A','B','C'],
deferred = Q.defer();
dirNames.forEach(function(dir, index){
fs.mkdirSync(dir); // we use the sync version so we are sure
// the directories are there when we exit the task
// copy our files ( after we do whatever we want on them )
copyFilesTo(dir,function(){
if((index+1) === dirNames.length){
// when in last directory, resolve the promise so the task can finish
deferred.resolve();
}
});
});
return deferred.promise;
});
// depends only on makeDirs
gulp.task('default', ['makeDirs'],function(){
// deafult task here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment