bitcore/gulpfile.js

131 lines
3.4 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 closureCompiler = require('gulp-closure-compiler');
var jsdoc = require('gulp-jsdoc');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
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
2014-11-29 13:23:38 -08:00
gulp.task('test', ['errors'], testMocha);
2014-11-22 12:50:08 -08:00
2014-11-29 13:23:38 -08:00
gulp.task('test-all', ['errors'], function(callback) {
2014-11-26 13:50:53 -08:00
runSequence(['test'], ['karma'], callback);
});
2014-11-29 13:23:38 -08:00
gulp.task('test-nofail', ['errors'], function() {
2014-11-22 12:50:08 -08:00
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-27 14:03:27 -08:00
gulp.task('watch:coverage', 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, ['coverage']);
});
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() {
2014-11-26 14:48:28 -08:00
return gulp.watch(alljs, ['browser-all']);
2014-11-26 13:50:53 -08:00
});
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'));
});
2014-12-04 20:30:32 -08:00
gulp.task('browser', ['errors'], shell.task([
'./node_modules/.bin/browserify index.js --insert-global-vars=true --standalone=bitcore -o browser/bitcore.js'
2014-12-04 20:30:32 -08:00
]));
2014-11-22 12:50:08 -08:00
2014-11-26 15:13:03 -08:00
gulp.task('browser-test', shell.task([
'find test/ -type f -name "*.js" | xargs ./node_modules/.bin/browserify -t brfs -o browser/tests.js'
2014-11-26 15:13:03 -08:00
]));
2014-11-22 12:50:08 -08:00
2014-11-29 13:23:38 -08:00
gulp.task('browser-all', ['errors'], function(callback) {
2014-11-26 14:33:50 -08:00
runSequence(['browser'], ['browser-test'], callback);
});
2014-12-03 05:21:15 -08:00
gulp.task('karma', ['browser-all'], testKarma);
2014-11-29 13:23:38 -08:00
gulp.task('errors', shell.task([
'node ./lib/errors/build.js'
]));
gulp.task('minify', ['errors'], function() {
2014-11-22 12:50:08 -08:00
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) {
2014-11-29 13:23:38 -08:00
return runSequence(['lint', 'jsdoc'],
['browser', 'test'],
['coverage', 'minify'],
callback);
2014-11-22 12:50:08 -08:00
});