bitcore-lib-zcash/gulpfile.js

336 lines
8.8 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.
*
2014-12-16 10:13:35 -08:00
* Summary: <ul>
* <li> `test` - runs all the tests on node and the browser (mocha and karma)
* <ul>
* <li> `test:node`
* <li> `test:node:nofail` - internally used for watching (due to bug on gulp-mocha)
* <li> `test:browser`
* </ul>`
* <li> `watch:test` - watch for file changes and run tests
* <ul>
* <li> `watch:test:node`
* <li> `watch:test:browser`
* </ul>`
* <li> `browser` - generate files needed for browser (browserify)
* <ul>
* <li> `browser:uncompressed` - build `browser/bitcore.js`
* <li> `browser:compressed` - build `browser/bitcore.min.js`
* <li> `browser:maketests` - build `browser/tests.js`, needed for testing without karma
* </ul>`
2014-12-23 13:34:37 -08:00
* <li> `errors` - autogenerate the `./lib/errors/index.js` file with error definitions
2014-12-16 10:13:35 -08:00
* <li> `lint` - run `jshint`
* <li> `coverage` - run `istanbul` with mocha to generate a report of test coverage
* <li> `jsdoc` - run `jsdoc` to generate the API reference
2014-12-17 17:53:28 -08:00
* <li> `coveralls` - updates coveralls info
2014-12-23 13:34:37 -08:00
* <li> `release` - automates release process (only for bitcore maintainers)
2014-12-16 10:13:35 -08:00
* </ul>
2014-11-22 12:50:08 -08:00
*/
'use strict';
2014-11-22 12:50:08 -08:00
var gulp = require('gulp');
2014-12-17 17:53:28 -08:00
var coveralls = require('gulp-coveralls');
2014-11-22 12:50:08 -08:00
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var runSequence = require('run-sequence');
var shell = require('gulp-shell');
var through = require('through2');
var gutil = require('gulp-util');
var jsdoc2md = require('jsdoc-to-markdown');
var mfs = require('more-fs');
2014-12-23 13:34:37 -08:00
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var bump = require('gulp-bump');
var git = require('gulp-git');
2014-11-22 12:50:08 -08:00
var files = ['lib/**/*.js'];
var tests = ['test/**/*.js'];
var alljs = files.concat(tests);
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'
2014-11-26 13:50:53 -08:00
]);
2014-12-16 10:13:35 -08:00
/**
* Testing
*/
2014-11-22 12:50:08 -08:00
2014-12-16 10:13:35 -08:00
gulp.task('test:node', ['errors'], testMocha);
2014-11-22 12:50:08 -08:00
2014-12-16 10:13:35 -08:00
gulp.task('test:node:nofail', ['errors'], function() {
2014-11-22 12:50:08 -08:00
return testMocha().on('error', ignoreError);
});
2014-12-16 10:13:35 -08:00
gulp.task('test:browser', ['browser:uncompressed', 'browser:maketests'], testKarma);
gulp.task('test', function(callback) {
runSequence(['test:node'], ['test:browser'], callback);
});
2014-12-16 10:13:35 -08:00
/**
* File generation
*/
2014-12-16 18:00:14 -08:00
gulp.task('browser:makefolder', shell.task([
'if [ ! -d "browser" ]; then mkdir browser; fi'
]));
gulp.task('browser:uncompressed', ['browser:makefolder', 'errors'], shell.task([
2014-12-16 10:13:35 -08:00
'./node_modules/.bin/browserify index.js --insert-global-vars=true --standalone=bitcore -o browser/bitcore.js'
]));
2014-12-23 13:34:37 -08:00
gulp.task('browser:compressed', ['browser:uncompressed'], function() {
return gulp.src('browser/bitcore.js')
.pipe(uglify({
mangle: true,
compress: true
2014-12-16 10:13:35 -08:00
}))
2014-12-23 13:34:37 -08:00
.pipe(rename('bitcore.min.js'))
.pipe(gulp.dest('browser'))
.on('error', gutil.log);
2014-11-27 14:03:27 -08:00
});
2014-12-16 18:00:14 -08:00
gulp.task('browser:maketests', ['browser:makefolder'], shell.task([
2014-12-16 10:13:35 -08:00
'find test/ -type f -name "*.js" | xargs ./node_modules/.bin/browserify -t brfs -o browser/tests.js'
]));
2014-12-23 13:34:37 -08:00
gulp.task('browser', function(callback) {
runSequence(['browser:compressed'], ['browser:maketests'], callback);
2014-11-22 12:50:08 -08:00
});
2014-12-16 10:13:35 -08:00
gulp.task('errors', shell.task([
'node ./lib/errors/build.js'
]));
/**
* Code quality and documentation
*/
gulp.task('lint', function() {
return gulp.src(alljs)
.pipe(jshint())
.pipe(jshint.reporter('default'));
2014-11-26 13:50:53 -08:00
});
2014-12-17 08:29:41 -08:00
gulp.task('plato', shell.task(['plato -d report -r -l .jshintrc -t bitcore lib']));
2014-12-16 10:13:35 -08:00
gulp.task('jsdoc', function() {
function jsdoc() {
return through.obj(function(file, enc, cb) {
2014-12-23 13:34:37 -08:00
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-jsdoc2md', 'Streaming not supported'));
return;
}
2014-12-23 13:34:37 -08:00
var destination = 'docs/api/' + file.path.replace(file.base, '').replace(/\.js$/, '.md');
jsdoc2md.render(file.path, {})
.on('error', function(err) {
gutil.log(gutil.colors.red('jsdoc2md failed', err.message));
})
.pipe(mfs.writeStream(destination));
cb(null, file);
});
}
2014-12-23 13:34:37 -08:00
return gulp.src(files).pipe(jsdoc());
});
2014-11-22 12:50:08 -08:00
gulp.task('coverage', shell.task(['node_modules/.bin/./istanbul cover node_modules/.bin/_mocha -- --recursive']));
2014-12-17 17:53:28 -08:00
gulp.task('coveralls', ['coverage'], function() {
gulp.src('coverage/lcov.info').pipe(coveralls());
});
2014-12-16 10:13:35 -08:00
/**
* Watch tasks
*/
2014-11-22 12:50:08 -08:00
2014-12-16 10:13:35 -08:00
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']);
});
2014-11-22 12:50:08 -08:00
2014-12-16 10:13:35 -08:00
gulp.task('watch:test:node', 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:node']);
});
2014-11-22 12:50:08 -08:00
2014-12-16 10:13:35 -08:00
gulp.task('watch:test:browser', 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:browser']);
2014-11-26 14:33:50 -08:00
});
2014-12-16 10:13:35 -08:00
gulp.task('watch:jsdoc', 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, ['jsdoc']);
});
2014-12-16 10:13:35 -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-12-16 10:13:35 -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-29 13:23:38 -08:00
2014-12-16 10:13:35 -08:00
gulp.task('watch:browser', function() {
return gulp.watch(alljs, ['browser']);
2014-11-22 12:50:08 -08:00
});
2014-12-16 10:13:35 -08:00
/**
2014-12-23 13:34:37 -08:00
* Release automation
2014-12-16 10:13:35 -08:00
*/
2014-12-23 13:34:37 -08:00
gulp.task('release:install', function() {
return shell.task([
'npm install',
]);
});
gulp.task('release:bump', function() {
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({
type: 'patch'
}))
.pipe(gulp.dest('./'));
});
gulp.task('release:checkout-releases', function(cb) {
2014-12-24 06:44:13 -08:00
git.checkout('releases', {
args: ''
}, cb);
2014-12-23 13:34:37 -08:00
});
gulp.task('release:merge-master', function(cb) {
2014-12-24 06:44:13 -08:00
git.merge('master', {
args: ''
}, cb);
2014-12-23 13:34:37 -08:00
});
gulp.task('release:checkout-master', function(cb) {
2014-12-24 06:44:13 -08:00
git.checkout('master', {
args: ''
}, cb);
2014-12-23 13:34:37 -08:00
});
gulp.task('release:add-built-files', function() {
return gulp.src(['./browser/bitcore.js', './browser/bitcore.min.js', './package.json', './bower.json'])
2014-12-24 06:44:13 -08:00
.pipe(git.add({
args: '-f'
}));
2014-12-23 13:34:37 -08:00
});
gulp.task('release:build-commit', ['release:add-built-files'], function() {
var pjson = require('./package.json');
return gulp.src(['./browser/bitcore.js', './browser/bitcore.min.js', './package.json', './bower.json'])
2014-12-24 06:44:13 -08:00
.pipe(git.commit('Build: ' + pjson.version, {
args: ''
}));
2014-12-23 13:34:37 -08:00
});
gulp.task('release:version-commit', function() {
var pjson = require('./package.json');
var files = ['./package.json', './bower.json'];
return gulp.src(files)
2014-12-24 06:44:13 -08:00
.pipe(git.commit('Bump package version to ' + pjson.version, {
args: ''
}));
2014-12-23 13:34:37 -08:00
});
gulp.task('release:push-releases', function(cb) {
2014-12-24 06:15:20 -08:00
git.push('bitpay', 'releases', {
2014-12-23 13:34:37 -08:00
args: ''
}, cb);
});
gulp.task('release:push', function(cb) {
2014-12-24 06:15:20 -08:00
git.push('bitpay', 'master', {
2014-12-23 13:34:37 -08:00
args: ''
}, cb);
});
gulp.task('release:push-tag', function(cb) {
var pjson = require('./package.json');
var name = 'v' + pjson.version;
git.tag(name, 'Release ' + name, function() {
2014-12-24 06:44:13 -08:00
git.push('bitpay', name, cb);
2014-12-23 13:34:37 -08:00
});
});
gulp.task('release:publish', shell.task([
'npm publish'
]));
// requires https://hub.github.com/
gulp.task('release', function(cb) {
runSequence(
// Checkout the `releases` branch
['release:checkout-releases'],
// Merge the master branch
['release:merge-master'],
// Run npm install
['release:install'],
// Build browser bundle
['browser:compressed'],
// Run tests with gulp test
['test'],
// Update package.json and bower.json
['release:bump'],
// Commit
['release:build-commit'],
// Run git push bitpay $VERSION
['release:push-tag'],
// Push to releases branch
['release:push-releases'],
// Run npm publish
['release:publish'],
// Checkout the `master` branch
['release:checkout-master'],
// Bump package.json and bower.json, again
['release:bump'],
// Version commit with no binary files to master
['release:version-commit'],
// Push to master
['release:push'],
cb);
});
/* Default task */
2014-11-22 12:50:08 -08:00
gulp.task('default', function(callback) {
2014-12-23 13:34:37 -08:00
return runSequence(['lint', 'jsdoc'], ['browser:uncompressed', 'test'], ['coverage', 'browser:compressed'],
callback);
2014-11-22 12:50:08 -08:00
});