Skip to content

Instantly share code, notes, and snippets.

@kimsk
Created October 31, 2015 23:50
Show Gist options
  • Save kimsk/5629e93fe8f32c80c72d to your computer and use it in GitHub Desktop.
Save kimsk/5629e93fe8f32c80c72d to your computer and use it in GitHub Desktop.
gulp for node ES6 dev, babel, eslint, gulp-watch, gulp-util, run-sequence, del, mocha
var gulp = require('gulp'),
sequence = require('run-sequence'),
gutil = require('gulp-util'),
sourcemaps = require('gulp-sourcemaps'),
babel = require('gulp-babel'),
eslint = require('gulp-eslint'),
watch = require('gulp-watch'),
mocha = require('gulp-mocha'),
del = require('del');
var ci = false;
function onError(err) {
if (ci) {
// stop in CI
process.exit(1);
} else {
// keep going in non-CI
gutil.log(err);
gutil.beep();
this.emit('end');
}
}
var paths = {
src: 'src/**/*.js',
dist: 'dist',
tests: 'dist/**/test.js'
};
gulp.task('lint', function () {
return gulp.src([paths.src])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError())
.on("error", onError);
});
gulp.task('babel', function(){
return gulp.src(paths.src)
.pipe(sourcemaps.init())
.pipe(babel())
.on("error", onError)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dist));
});
gulp.task('mocha', function(){
return gulp.src(paths.tests, {read: false})
.pipe(mocha({reporter: 'nyan'}))
.on("error", onError);
});
gulp.task('watch', ['full'], function() {
watch(paths.src, function (){
gulp.start('full');
});
});
gulp.task('clean', function (done){
del([paths.dist], done);
done();
});
gulp.task('full', function(done) {
sequence('clean', 'lint', 'babel', 'mocha', done);
});
gulp.task('default', ['full']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment