Compare commits

..

1 Commits

Author SHA1 Message Date
Esteban Ordano ebf1dfe890 Drop the default task 2015-01-12 17:58:01 -03:00
5 changed files with 84 additions and 357 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
node_modules/

View File

@ -1,41 +0,0 @@
# bitcore-build-zcash
A helper to add tasks to gulp.
## Getting started
Install with:
```sh
npm install bitcore-build-zcash
```
and use and require in your gulp file:
```javascript
var gulp = require('gulp');
var bitcoreTasks = require('bitcore-build-zcash');
bitcoreTasks('submodule');
gulp.task('default', ['lint', 'test', 'browser', 'coverage']);
```
### Notes
* There's no default task to allow for each submodule to set up their own configuration
* If the module is node-only, avoid adding the browser tasks with:
```javascript
var bitcoreTasks = require('bitcore-build-zcash');
bitcoreTasks('submodule', {skipBrowsers: true});
```
## Contributing
See [CONTRIBUTING.md](https://github.com/bitpay/bitcore) on the main bitcore repo for information about how to contribute.
## License
Code released under [the MIT license](https://github.com/bitpay/bitcore/blob/master/LICENSE).
Copyright 2015 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.

333
index.js
View File

@ -1,3 +1,7 @@
'use strict';
var gulp = require('gulp');
/** /**
* @file gulpfile.js * @file gulpfile.js
* *
@ -17,54 +21,38 @@
* </ul>` * </ul>`
* <li> `browser` - generate files needed for browser (browserify) * <li> `browser` - generate files needed for browser (browserify)
* <ul> * <ul>
* <li> `browser:uncompressed` - build uncomprssed browser bundle (`bitcore-*.js`) * <li> `browser:uncompressed` - build `bitcore-*.js`
* <li> `browser:compressed` - build compressed browser bundle (`bitcore-*.min.js`) * <li> `browser:compressed` - build `bitcore-*.min.js`
* <li> `browser:maketests` - build `tests.js`, needed for testing without karma * <li> `browser:maketests` - build `tests.js`, needed for testing without karma
* </ul>` * </ul>`
* <li> `errors` - autogenerate the `./lib/errors/index.js` file with error definitions
* <li> `lint` - run `jshint` * <li> `lint` - run `jshint`
* <li> `coverage` - run `istanbul` with mocha to generate a report of test coverage * <li> `coverage` - run `istanbul` with mocha to generate a report of test coverage
* <li> `coveralls` - updates coveralls info * <li> `coveralls` - updates coveralls info
* <li> `release` - automates release process (only for maintainers) * <li> `release` - automates release process (only for bitcore maintainers)
* </ul> * </ul>
*/ */
'use strict'; function startGulp(name) {
var gulp = require('gulp'); var coveralls = require('gulp-coveralls');
var gutil = require('gulp-util');
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');
var uglify = require('gulp-uglify');
var coveralls = require('gulp-coveralls');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var runsequence = require('run-sequence');
runsequence.use(gulp);
var shell = require('gulp-shell');
var uglify = require('gulp-uglify');
var bump = require('gulp-bump');
var git = require('gulp-git');
function ignoreerror() {
/* jshint ignore:start */ // using `this` in this context is weird
this.emit('end');
/* jshint ignore:end */
}
function startGulp(name, opts) {
opts = opts || {};
var browser = !opts.skipBrowser;
var fullname = name ? 'bitcore-' + name : 'bitcore';
var files = ['lib/**/*.js']; var files = ['lib/**/*.js'];
var tests = ['test/**/*.js']; var tests = ['test/**/*.js'];
var alljs = files.concat(tests); var alljs = files.concat(tests);
var buildPath = './node_modules/bitcore-build-zcash/'; function ignoreerror() {
var buildModulesPath = buildPath + 'node_modules/'; /* jshint ignore:start */ // using `this` in this context is weird
var buildBinPath = buildPath + 'node_modules/.bin/'; this.emit('end');
/* jshint ignore:end */
}
/**
* testing
*/
var testmocha = function() { var testmocha = function() {
return gulp.src(tests).pipe(new mocha({ return gulp.src(tests).pipe(new mocha({
reporter: 'spec' reporter: 'spec'
@ -72,68 +60,61 @@ function startGulp(name, opts) {
}; };
var testkarma = shell.task([ var testkarma = shell.task([
buildModulesPath + 'karma/bin/karma start ' + buildPath + 'karma.conf.js' './node_modules/karma/bin/karma start'
]); ]);
gulp.task('test:node', testmocha); /**
* testing
*/
gulp.task('test:node:nofail', function() { gulp.task('test:node', ['errors'], testmocha);
gulp.task('test:node:nofail', ['errors'], function() {
return testmocha().on('error', ignoreerror); return testmocha().on('error', ignoreerror);
}); });
gulp.task('test:browser', ['browser:uncompressed', 'browser:maketests'], testkarma); gulp.task('test:browser', ['browser:uncompressed', 'browser:maketests'], testkarma);
if (browser) { gulp.task('test', function(callback) {
gulp.task('test', function(callback) { runsequence(['test:node'], ['test:browser'], callback);
runsequence(['test:node'], ['test:browser'], callback);
});
} else {
gulp.task('test', ['test:node']);
}
gulp.task('noop', function() {
}); });
/** /**
* file generation * file generation
*/ */
if (browser) {
var browserifyCommand; gulp.task('browser:uncompressed', ['errors'], shell.task([
'./node_modules/.bin/browserify index.js --insert-global-vars=true --standalone=bitcore-' +
name + ' -o bitcore-' + name + '.js'
]));
if (name !== 'lib') { gulp.task('browser:compressed', ['browser:uncompressed'], function() {
browserifyCommand = buildBinPath + 'browserify --require ./index.js:' + fullname + ' --external bitcore-lib-zcash -o ' + fullname + '.js'; return gulp.src('bitcore-' + name + '.js')
} else { .pipe(uglify({
browserifyCommand = buildBinPath + 'browserify --require ./index.js:bitcore-lib-zcash -o bitcore-lib-zcash.js'; mangle: true,
} compress: true
}))
.pipe(rename('bitcore-' + name + '.min.js'))
.pipe(gulp.dest('.'))
.on('error', gutil.log);
});
gulp.task('browser:uncompressed', shell.task([ gulp.task('browser:maketests', shell.task([
browserifyCommand 'find test/ -type f -name "*.js" | xargs ./node_modules/.bin/browserify -t brfs -o tests.js'
])); ]));
gulp.task('browser:compressed', ['browser:uncompressed'], function() { gulp.task('browser', function(callback) {
return gulp.src(fullname + '.js') runsequence(['browser:compressed'], ['browser:maketests'], callback);
.pipe(uglify({ });
mangle: true,
compress: true
}))
.pipe(rename(fullname + '.min.js'))
.pipe(gulp.dest('.'))
.on('error', gutil.log);
});
gulp.task('browser:maketests', shell.task([ gulp.task('errors', shell.task([
'find test/ -type f -name "*.js" | xargs ' + buildBinPath + 'browserify -t brfs -o tests.js' 'node ./lib/errors/build.js'
])); ]));
gulp.task('browser', function(callback) {
runsequence(['browser:compressed'], callback);
});
}
/** /**
* code quality and documentation * code quality and documentation
*/ */
gulp.task('lint', function() { gulp.task('lint', function() {
return gulp.src(alljs) return gulp.src(alljs)
@ -141,17 +122,17 @@ function startGulp(name, opts) {
.pipe(jshint.reporter('default')); .pipe(jshint.reporter('default'));
}); });
gulp.task('plato', shell.task([buildBinPath + 'plato -d report -r -l .jshintrc -t ' + fullname + ' lib'])); gulp.task('plato', shell.task(['plato -d report -r -l .jshintrc -t bitcore-' + name + ' lib']));
gulp.task('coverage', shell.task([buildBinPath + './istanbul cover ' + buildBinPath + '_mocha -- --recursive'])); gulp.task('coverage', shell.task(['node_modules/.bin/./istanbul cover node_modules/.bin/_mocha -- --recursive']));
gulp.task('coveralls', ['coverage'], function() { gulp.task('coveralls', ['coverage'], function() {
gulp.src('coverage/lcov.info').pipe(coveralls()); gulp.src('coverage/lcov.info').pipe(coveralls());
}); });
/** /**
* watch tasks * watch tasks
*/ */
gulp.task('watch:test', function() { gulp.task('watch:test', function() {
// todo: only run tests that are linked to file changes by doing // todo: only run tests that are linked to file changes by doing
@ -165,13 +146,17 @@ function startGulp(name, opts) {
return gulp.watch(alljs, ['test:node']); return gulp.watch(alljs, ['test:node']);
}); });
if (browser) { gulp.task('watch:test:browser', function() {
gulp.task('watch:test:browser', function() { // todo: only run tests that are linked to file changes by doing
// todo: only run tests that are linked to file changes by doing // something smart like reading through the require statements
// something smart like reading through the require statements return gulp.watch(alljs, ['test:browser']);
return gulp.watch(alljs, ['test:browser']); });
});
} 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']);
});
gulp.task('watch:coverage', function() { gulp.task('watch:coverage', function() {
// todo: only run tests that are linked to file changes by doing // todo: only run tests that are linked to file changes by doing
@ -185,177 +170,9 @@ function startGulp(name, opts) {
return gulp.watch(alljs, ['lint']); return gulp.watch(alljs, ['lint']);
}); });
if (browser) { gulp.task('watch:browser', function() {
gulp.task('watch:browser', function() { return gulp.watch(alljs, ['browser']);
return gulp.watch(alljs, ['browser']);
});
}
/**
* Release automation
*/
gulp.task('release:install', function() {
return shell.task([
'npm install',
]);
}); });
var releaseFiles = ['./package.json'];
if (browser) {
releaseFiles.push('./bower.json');
}
var bump_version = function(importance) {
return gulp.src(releaseFiles)
.pipe(bump({
type: importance
}))
.pipe(gulp.dest('./'));
};
var tempBranch = 'releases/' + new Date().getTime() + '-build';
gulp.task('release:checkout-releases', function(cb) {
git.branch(tempBranch, {
args: ''
}, function() {
git.checkout(tempBranch, {
args: ''
}, cb);
});
});
gulp.task('release:cleanup', function(cb) {
git.branch(tempBranch, {
args: '-D'
}, cb);
});
gulp.task('release:checkout-master', function(cb) {
git.checkout('master', {
args: ''
}, cb);
});
gulp.task('release:sign-built-files', shell.task([
'gpg --yes --out ' + fullname + '.js.sig --detach-sig ' + fullname + '.js',
'gpg --yes --out ' + fullname + '.min.js.sig --detach-sig ' + fullname + '.min.js'
]));
var buildFiles = ['./package.json'];
var signatureFiles = [];
if (browser) {
buildFiles.push(fullname + '.js');
buildFiles.push(fullname + '.js.sig');
buildFiles.push(fullname + '.min.js');
buildFiles.push(fullname + '.min.js.sig');
buildFiles.push('./bower.json');
signatureFiles.push(fullname + '.js.sig');
signatureFiles.push(fullname + '.min.js.sig');
}
var addFiles = function() {
var pjson = require('../../package.json');
return gulp.src(buildFiles)
.pipe(git.add({
args: '-f'
}));
};
var buildCommit = function() {
var pjson = require('../../package.json');
return gulp.src(buildFiles)
.pipe(git.commit('Build: ' + pjson.version, {
args: ''
}));
};
gulp.task('release:add-signed-files', ['release:sign-built-files'], addFiles);
gulp.task('release:add-built-files', addFiles);
if (browser) {
gulp.task('release:build-commit', [
'release:add-signed-files'
], buildCommit);
} else {
gulp.task('release:build-commit', [
'release:add-built-files'
], buildCommit);
}
gulp.task('release:version-commit', function() {
var pjson = require('../../package.json');
return gulp.src(releaseFiles)
.pipe(git.commit('Bump package version to ' + pjson.version, {
args: ''
}));
});
gulp.task('release:push', function(cb) {
git.push('bitpay', 'master', {
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() {
git.push('bitpay', name, cb);
});
});
gulp.task('release:publish', shell.task([
'npm publish'
]));
// requires https://hub.github.com/
var release = function(importance, cb) {
var bumper = 'release:bump:' + importance;
return runsequence(
// Checkout the release temporal branch
'release:checkout-releases',
// Run npm install
'release:install',
// Run tests with gulp test
'test',
// Update package.json and bower.json
bumper,
// build browser files
browser ? 'browser' : 'noop',
// Commit
'release:build-commit',
// Run git push bitpay $VERSION
'release:push-tag',
// Run npm publish
'release:publish',
// Checkout the `master` branch
'release:checkout-master',
// Bump package.json and bower.json, again
bumper,
// Version commit with no binary files to master
'release:version-commit',
// Push to master
'release:push',
// remove release branch
'release:cleanup',
cb);
};
['patch', 'minor', 'major'].forEach(function(importance) {
gulp.task('release:' + importance, function(cb) {
release(importance, cb);
});
gulp.task('release:bump:' + importance, function() {
bump_version(importance);
});
});
gulp.task('release', ['release:patch']);
} }
module.exports = startGulp; module.exports = startGulp;

View File

@ -1,19 +0,0 @@
'use strict';
// karma.conf.js
module.exports = function(config) {
config.set({
browsers: ['Firefox'],
frameworks: ['mocha'],
singleRun: true,
files: [
'./../../tests.js' // project root
],
plugins: [
'karma-mocha',
'karma-firefox-launcher'
]
});
};

View File

@ -1,65 +1,37 @@
{ {
"name": "bitcore-build-zcash", "name": "gulp-bitcore",
"version": "0.5.4", "version": "0.2.0",
"description": "A helper for common tasks to build bitcore-zcash modules'", "description": "A helper for common tasks across bitcore modules'",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "gulp test" "test": "gulp test"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/str4d/bitcore-build-zcash" "url": "git://github.com/bitpay/gulp-bitcore"
}, },
"keywords": [ "keywords": [
"bitcore" "bitcore"
], ],
"contributors": [ "author": "Esteban Ordano",
{
"name": "Esteban Ordano",
"email": "esteban@bitpay.com"
},
{
"name": "Manuel Araoz",
"email": "maraoz@bitpay.com"
},
{
"name": "Braydon Fuller",
"email": "braydon@bitpay.com"
},
{
"name": "Yemel Jardi",
"email": "yemel@bitpay.com"
}
],
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/str4d/bitcore-build-zcash/issues" "url": "https://github.com/bitpay/gulp-bitcore/issues"
}, },
"homepage": "https://github.com/str4d/bitcore-build-zcash", "homepage": "https://github.com/bitpay/gulp-bitcore",
"dependencies": { "dependencies": {
"brfs": "^1.2.0", "brfs": "^1.2.0",
"browserify": "~13.1.0", "browserify": "~6.3.3",
"chai": "~1.10.0",
"gulp": "^3.8.10", "gulp": "^3.8.10",
"gulp-bump": "^0.1.11",
"gulp-coveralls": "^0.1.3", "gulp-coveralls": "^0.1.3",
"gulp-git": "^0.5.5",
"gulp-jshint": "^1.9.0", "gulp-jshint": "^1.9.0",
"gulp-mocha": "^2.0.0", "gulp-mocha": "^2.0.0",
"gulp-rename": "^1.2.0", "gulp-rename": "^1.2.0",
"gulp-shell": "^0.2.10", "gulp-shell": "^0.2.10",
"gulp-uglify": "^1.0.2", "gulp-uglify": "^1.0.2",
"gulp-util": "=3.0.1", "gulp-util": "=3.0.1",
"istanbul": "^0.3.5",
"karma": "^0.12.28",
"karma-chrome-launcher": "^0.1.8",
"karma-detect-browsers": "^2.0.0",
"karma-firefox-launcher": "^0.1.4",
"karma-mocha": "^0.1.9",
"lodash": "^2.4.1", "lodash": "^2.4.1",
"mocha": "^2.0.1",
"plato": "^1.3.0", "plato": "^1.3.0",
"run-sequence": "^1.0.2", "run-sequence": "^1.0.2"
"zuul": "1.16.3"
} }
} }