Skip to content

Commit

Permalink
Build process changed to enable watching without unpiping
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrnac committed Oct 18, 2014
1 parent c9204b0 commit 7be4960
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
63 changes: 46 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,78 @@ var istanbul = require('gulp-istanbul');
var coveralls = require('gulp-coveralls');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var plumber = require('gulp-plumber');
var lazypipe = require('lazypipe');

var errorOccured = false;
var paths = {
scripts: './lib/jasstor.js',
tests: ['./test/jasstorClbkSpec.js', './test/jasstorPromiseSpec.js'],
dist: './dist/jasstor.js'
};

//Submit coverage report to overalls.io
gulp.task('coveralls', ['test', 'checkError'], function () {
return gulp.src('./coverage/lcov.info').pipe(coveralls());
});

//This task is here to exit from process with error code
//This way drone.io (CI server) knows that process failed
//It is needed because gulp-plumber forces 0 error code even when error occurs.
gulp.task('checkError', ['test'], function () {
if (errorOccured) {
console.log('Error occured, exitting build process... ');
process.exit(1);
}
});

var errorHandler = function () {
console.log('Error occured... ');
errorOccured = true;
};

var transpilePipe = lazypipe()
.pipe(plumber, {
errorHandler: errorHandler
})
.pipe(jshint)
.pipe(jshint.reporter, stylish)
.pipe(jshint.reporter, 'fail')
.pipe(traceur);

//Compiles ES6 into ES5
gulp.task('build', function () {
return gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'))
.pipe(traceur())
.pipe(plumber({
errorHandler: errorHandler
}))
.pipe(transpilePipe())
.pipe(gulp.dest('dist'));
});

//Transpile to ES5 and runs mocha test
gulp.task('test', ['build'], function (cb) {
gulp.src([paths.dist])
.pipe(plumber({
errorHandler: errorHandler
}))
.pipe(istanbul())
.on('finish', function () {
gulp.src(paths.tests)
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'))
.pipe(traceur())
.pipe(plumber({
errorHandler: errorHandler
}))
.pipe(transpilePipe())
.pipe(gulp.dest('tmp'))
.pipe(mocha())
.pipe(istanbul.writeReports())
.on('end', cb);
});
});

//Submit coverage report to overalls.io
gulp.task('coveralls', ['test'], function () {
return gulp.src('./coverage/lcov.info').pipe(coveralls({
error: false
}));
});

gulp.task('watch', function () {
gulp.watch([paths.scripts, paths.tests], ['test']);
var filesToWatch = paths.tests.concat(paths.scripts);
gulp.watch(filesToWatch, ['test']);
});

gulp.task('default', ['test', 'coveralls']);
gulp.task('default', ['test', 'checkError', 'coveralls']);
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
"bluebird": "^2.3.5",
"gulp": "^3.8.8",
"gulp-coveralls": "^0.1.3",
"gulp-debug": "^1.0.1",
"gulp-istanbul": "^0.3.1",
"gulp-jshint": "^1.8.5",
"gulp-mocha": "^1.1.1",
"gulp-plumber": "^0.6.6",
"gulp-traceur": "^0.13.0",
"gulp-watch": "^1.1.0",
"jshint-stylish": "^1.0.0",
"lazypipe": "^0.2.2",
"should": "^4.0.4"
},
"scripts": {
Expand Down

0 comments on commit 7be4960

Please sign in to comment.