bitcore/gulpfile.js

123 lines
3.0 KiB
JavaScript
Raw Normal View History

2014-11-22 12:50:08 -08:00
/**
* @file gulpfile.js
*
* Defines tasks that can be run on gulp.
*
* Summary:
* * test - Run tests
* * watch:test - Waits for filesystem changes and runs tests
*
*/
'use strict';
2014-11-22 12:50:08 -08:00
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var closureCompiler = require('gulp-closure-compiler');
var jsdoc = require('gulp-jsdoc');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var shell = require('gulp-shell');
2014-11-26 08:19:15 -08:00
2014-11-22 12:50:08 -08:00
var files = ['lib/**/*.js'];
var tests = ['test/**/*.js'];
var alljs = files.concat(tests);
var jsdocReadme = 'doc/README.md';
2014-11-26 08:19:15 -08:00
2014-11-22 12:50:08 -08:00
function ignoreError() {
/* jshint ignore:start */ // using `this` in this context is weird
this.emit('end');
/* jshint ignore:end */
}
2014-11-26 13:50:53 -08:00
var testMocha = function() {
return gulp.src(tests).pipe(new mocha({
reporter: 'spec'
}));
};
var testKarma = shell.task([
'./node_modules/karma/bin/karma start --single-run --browsers Firefox'
]);
2014-11-22 12:50:08 -08:00
gulp.task('test', testMocha);
2014-11-26 13:50:53 -08:00
gulp.task('test-all', function(callback) {
runSequence(['test'], ['karma'], callback);
});
2014-11-22 12:50:08 -08:00
gulp.task('test-nofail', function() {
return testMocha().on('error', ignoreError);
});
gulp.task('watch:test', function() {
// TODO: Only run tests that are linked to file changes by doing
// something smart like reading through the require statements
return gulp.watch(alljs, ['test-nofail']);
});
2014-11-22 12:50:08 -08:00
gulp.task('watch:lint', function() {
// TODO: Only lint files that are linked to file changes by doing
// something smart like reading through the require statements
return gulp.watch(alljs, ['lint']);
});
2014-11-26 13:50:53 -08:00
gulp.task('watch:browser', function() {
return gulp.watch(alljs, ['browser', 'browser-test']);
});
2014-11-26 08:19:15 -08:00
gulp.task('coverage', shell.task(['istanbul cover _mocha -- --recursive']));
2014-11-22 12:50:08 -08:00
gulp.task('jsdoc', function() {
return gulp.src(files.concat([jsdocReadme]))
.pipe(jsdoc.parser())
.pipe(jsdoc.generator('./apiref', {
path: 'ink-docstrap',
theme: 'flatly',
}));
});
2014-11-22 12:50:08 -08:00
gulp.task('lint', function() {
return gulp.src(alljs)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('browser', function() {
return gulp.src('index.js')
.pipe(browserify({
insertGlobals: true
}))
.pipe(rename('bitcore.js'))
.pipe(gulp.dest('browser'));
});
2014-11-26 13:50:53 -08:00
gulp.task('browser-test', function() {
shell.task([
'find test/ -type f -name "*.js" | xargs browserify -o ./browser/tests.js'
]);
});
2014-11-22 12:50:08 -08:00
2014-11-26 13:50:53 -08:00
gulp.task('karma', testKarma);
2014-11-22 12:50:08 -08:00
gulp.task('minify', function() {
return gulp.src('dist/bitcore.js')
.pipe(closureCompiler({
fileName: 'bitcore.min.js',
compilerPath: 'node_modules/closure-compiler-jar/compiler.jar',
compilerFlags: {
language_in: 'ECMASCRIPT5',
jscomp_off: 'suspiciousCode'
}
}))
.pipe(gulp.dest('dist'));
});
gulp.task('default', function(callback) {
return runSequence(['lint', 'jsdoc', 'browser', 'test'], ['coverage', 'minify'], callback);
});