Replace grunt with gulp

This commit is contained in:
Esteban Ordano 2014-11-22 17:50:08 -03:00
parent 3cf7a54845
commit 4b201a8db1
19 changed files with 162 additions and 133 deletions

4
.gitignore vendored
View File

@ -10,3 +10,7 @@ LICENSE.html
README.html
examples.html
npm-debug.log
apiref
bower_components
dist

View File

@ -27,7 +27,7 @@
"maxstatements": 15, // Maximum number of statements in a function
"maxcomplexity": 4, // Cyclomatic complexity (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
"maxdepth": 4, // Maximum depth of nested control structures
"maxlen": 600 // Maximum number of lines of code in a file
"maxlen": 600, // Maximum number of lines of code in a file
"predef": [ // Extra globals.
"define",

View File

@ -1,48 +0,0 @@
'use strict';
module.exports = function(grunt) {
//Load NPM tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-markdown');
grunt.loadNpmTasks('grunt-shell');
// Project Configuration
grunt.initConfig({
shell: {
browserify: {
options: {
stdout: true,
stderr: true
},
command: grunt.option('target') === 'dev' ?
'./browser/build; docco lib/* ' : './browser/build'
}
},
watch: {
readme: {
files: ['README.md', 'CONTRIBUTING.md'],
tasks: ['markdown']
},
scripts: {
files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js', '!docs/**', '!*.md', '!README.html', '!CONTRIBUTING.html'],
tasks: ['shell'],
},
},
markdown: {
all: {
files: [{
expand: true,
src: '*.md',
dest: '.',
ext: '.html'
}]
}
}
});
grunt.registerTask('default', ['shell','watch']);
};

View File

@ -1,4 +0,0 @@
#!/bin/bash
browserify index.js -o browser/bitcore.js
find test/ -type f -name "*.js" | xargs browserify -o browser/tests.js

4
docs/README.md Normal file
View File

@ -0,0 +1,4 @@
Bitcore API Reference
=======
This site contains the reference docs for the bitcore library.

View File

@ -1,25 +1,113 @@
var gulp = require('gulp'),
concat = require('gulp-concat'),
path = require('path'),
es = require('event-stream');
/**
* @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';
var format = es.through(
function (file) {
if (file.isNull()) return this.emit('data', file); // pass along
if (file.isStream()) return this.emit('error', new Error('Streaming not supported'));
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var closureCompiler = require('gulp-closure-compiler');
var istanbul = require('gulp-istanbul');
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');
var tap = require('gulp-tap');
//add indentation
var contents = "\t" + file.contents.toString("utf8").split("\n").join("\n\t");
//add header
contents = ["#", path.basename(file.path), "\n", contents].join("");
file.contents = new Buffer(contents, "utf8");
this.emit('data', file);
});
var files = ['lib/**/*.js'];
var tests = ['test/**/*.js'];
var alljs = files.concat(tests);
var jsdocReadme = 'doc/README.md';
gulp.task('examples', function () {
//concat .js files from ./examples folder into ./examples.md
return gulp.src("./examples/*.js").pipe(format).pipe(concat('examples.md')).pipe(gulp.dest('./'));
function ignoreError() {
/* jshint ignore:start */ // using `this` in this context is weird
this.emit('end');
/* jshint ignore:end */
}
function testMocha() {
return gulp.src(tests).pipe(new mocha({reporter: 'spec'}));
}
gulp.task('test', testMocha);
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']);
});
gulp.task('default', ["examples"]);
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']);
});
gulp.task('coverage', function() {
gulp.src(files)
.pipe(istanbul())
.pipe(tap(function(f) {
// Make sure all files are loaded to get accurate coverage data
require(f.path);
}))
.on('end', testMocha.pipe(
istanbul.writeReports('coverage')
));
});
gulp.task('jsdoc', function() {
return gulp.src(files.concat([jsdocReadme]))
.pipe(jsdoc.parser())
.pipe(jsdoc.generator('./apiref', {
path: 'ink-docstrap',
theme: 'flatly',
}));
});
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'));
});
gulp.task('browser-test', function() {
return shell('find test/ -type f -name "*.js" | xargs browserify -o browser/tests.js');
});
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);
});

View File

@ -39,8 +39,6 @@ bitcore.deps.bnjs = require('bn.js');
bitcore.deps.bs58 = require('bs58');
bitcore.deps.Buffer = Buffer;
bitcore.deps.elliptic = require('elliptic');
bitcore.deps.hashjs = require('hash.js');
bitcore.deps.sha512 = require('sha512');
//bitcore.scriptexec = require('lib/scriptexec');
//bitcore.tx = require('lib/tx');

View File

@ -31,6 +31,7 @@ _.extend(livenet, {
var testnet = new Network();
_.extend(testnet, {
name: 'testnet',
alias: 'testnet',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,

View File

@ -5,14 +5,20 @@
"author": "BitPay <dev@bitpay.com>",
"main": "index.js",
"scripts": {
"test": "mocha --recursive --reporter spec",
"coverage": "istanbul cover _mocha -- --recursive"
"lint": "gulp lint",
"test": "gulp test",
"coverage": "gulp coverage",
"build": "gulp"
},
"contributors": [
{
"name": "Daniel Cousens",
"email": "bitcoin@dcousens.com"
},
{
"name": "Esteban Ordano",
"email": "eordano@gmail.com"
},
{
"name": "Gordon Hall",
"email": "gordon@bitpay.com"
@ -74,12 +80,25 @@
"devDependencies": {
"browserify": "~6.3.3",
"chai": "~1.10.0",
"closure-compiler-jar": "git://github.com/eordano/closure-compiler-jar.git",
"grunt": "^0.4.5",
"grunt-contrib-watch": "^0.6.1",
"grunt-markdown": "^0.6.1",
"grunt-shell": "^1.1.1",
"lodash": "=2.4.1",
"mocha": "~2.0.1"
"gulp": "^3.8.10",
"gulp-browserify": "^0.5.0",
"gulp-closure-compiler": "^0.2.9",
"gulp-insert": "^0.4.0",
"gulp-istanbul": "^0.4.0",
"gulp-jsdoc": "^0.1.4",
"gulp-jshint": "^1.9.0",
"gulp-mocha": "^2.0.0",
"gulp-rename": "^1.2.0",
"gulp-shell": "^0.2.10",
"gulp-tap": "^0.1.3",
"lodash": "^2.4.1",
"mocha": "~2.0.1",
"run-sequence": "^1.0.2"
},
"license": "MIT"
}

View File

@ -112,14 +112,14 @@ describe('ECDSA', function() {
ecdsa.sig = new Signature();
ecdsa.sig.r = BN(0);
ecdsa.sig.s = BN(0);
ecdsa.sigError().should.equal("r and s not in range");
ecdsa.sigError().should.equal('r and s not in range');
});
it('should return an error if the signature is incorrect', function() {
ecdsa.sig = new Signature();
ecdsa.sig.fromString('3046022100e9915e6236695f093a4128ac2a956c40ed971531de2f4f41ba05fac7e2bd019c02210094e6a4a769cc7f2a8ab3db696c7cd8d56bcdbfff860a8c81de4bc6a798b90827');
ecdsa.sig.r = ecdsa.sig.r.add(BN(1));
ecdsa.sigError().should.equal("Invalid signature");
ecdsa.sigError().should.equal('Invalid signature');
});
});

View File

@ -99,7 +99,7 @@ describe('Hash', function() {
});
describe("#sha512hmac", function() {
describe('#sha512hmac', function() {
it('should calculate this known empty test vector correctly', function() {
var hex = 'b936cee86c9f87aa5d3c6f2e84cb5a4239a5fe50480a6ec66b70ab5b1f4ac6730c6c515421b327ec1d69402e53dfb49ad7381eb067b338fd7b0cb22247225d47';
@ -108,8 +108,8 @@ describe('Hash', function() {
it('should calculate this known non-empty test vector correctly', function() {
var hex = 'c40bd7c15aa493b309c940e08a73ffbd28b2e4cb729eb94480d727e4df577b13cc403a78e6150d83595f3b17c4cc331f12ca5952691de3735a63c1d4c69a2bac';
var data = new Buffer("test1");
var key = new Buffer("test2");
var data = new Buffer('test1');
var key = new Buffer('test2');
Hash.sha512hmac(data, key).toString('hex').should.equal(hex);
});

View File

@ -1,6 +1,5 @@
'use strict';
var should = require('chai').should();
var bitcore = require('../..');
var Random = bitcore.crypto.Random;
@ -31,34 +30,4 @@ describe('Random', function() {
});
describe('@getPseudoRandomBuffer', function() {
it('should generate 7 random bytes', function() {
var buf = Random.getPseudoRandomBuffer(7);
buf.length.should.equal(7);
});
it('should generate 8 random bytes', function() {
var buf = Random.getPseudoRandomBuffer(8);
buf.length.should.equal(8);
});
it('should generate 9 random bytes', function() {
var buf = Random.getPseudoRandomBuffer(9);
buf.length.should.equal(9);
});
it('should generate 90 random bytes', function() {
var buf = Random.getPseudoRandomBuffer(90);
buf.length.should.equal(90);
});
it('should generate two 8 byte buffers that are not equal', function() {
var buf1 = Random.getPseudoRandomBuffer(8);
var buf2 = Random.getPseudoRandomBuffer(8);
buf1.toString('hex').should.not.equal(buf2.toString('hex'));
});
});
});

View File

@ -41,7 +41,7 @@ describe('Base58', function() {
it('should throw an error when the Input is not a buffer', function() {
(function() {
Base58.encode("string")
Base58.encode('string');
}).should.throw('Input should be a buffer');
});

View File

@ -40,7 +40,7 @@ describe('Base58Check', function() {
it('should throw an error when the input is not a buffer', function() {
(function() {
Base58Check.encode("string")
Base58Check.encode('string');
}).should.throw('Input must be a buffer');
});

View File

@ -12,11 +12,12 @@ describe('Networks', function() {
should.exist(Networks.mainnet);
});
describe('contain all constants for livenet and testnet', function() {
var makeTest = function(key) {
Networks.testnet.hasOwnProperty(key).should.equal(true);
};
for (var key in Networks.livenet) {
if (Networks.livenet.hasOwnProperty(key)) {
it('all should contain '+key, function() {
Networks.testnet.hasOwnProperty(key).should.equal(true);
});
it('all should contain ' + key, makeTest(key));
}
}
});

View File

@ -1,5 +1,6 @@
'use strict';
var _ = require('lodash');
var should = require('chai').should();
var bitcore = require('..');
var Opcode = bitcore.Opcode;
@ -58,11 +59,7 @@ describe('Opcode', function() {
describe('@map', function() {
it('should have a map containing 116 elements', function() {
var i = 0;
for (var key in Opcode.map) {
i++;
}
i.should.equal(116);
_.size(Opcode.map).should.equal(116);
});
});

View File

@ -237,7 +237,7 @@ describe('Script', function() {
});
it('should classify this known non-pubkeyhashout as not pubkeyhashout', function() {
Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000').isPublicKeyHashOut().should.equal(false)
Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000').isPublicKeyHashOut().should.equal(false);
});
});

View File

@ -89,8 +89,8 @@ describe('Signature', function() {
var sighex = '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72';
var sig = new Buffer(sighex, 'hex');
var parsed = Signature.parseDER(sig);
parsed.header.should.equal(0x30)
parsed.length.should.equal(69)
parsed.header.should.equal(0x30);
parsed.length.should.equal(69);
parsed.rlength.should.equal(33);
parsed.rneg.should.equal(true);
parsed.rbuf.toString('hex').should.equal('008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa');
@ -105,8 +105,8 @@ describe('Signature', function() {
var sighex = '3043021f59e4705959cc78acbfcf8bd0114e9cc1b389a4287fb33152b73a38c319b50302202f7428a27284c757e409bf41506183e9e49dfb54d5063796dfa0d403a4deccfa';
var sig = new Buffer(sighex, 'hex');
var parsed = Signature.parseDER(sig);
parsed.header.should.equal(0x30)
parsed.length.should.equal(67)
parsed.header.should.equal(0x30);
parsed.length.should.equal(67);
parsed.rlength.should.equal(31);
parsed.rneg.should.equal(false);
parsed.rbuf.toString('hex').should.equal('59e4705959cc78acbfcf8bd0114e9cc1b389a4287fb33152b73a38c319b503');
@ -121,8 +121,8 @@ describe('Signature', function() {
var sighex = '3042021e17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632022061bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a51';
var sig = new Buffer(sighex, 'hex');
var parsed = Signature.parseDER(sig);
parsed.header.should.equal(0x30)
parsed.length.should.equal(66)
parsed.header.should.equal(0x30);
parsed.length.should.equal(66);
parsed.rlength.should.equal(30);
parsed.rneg.should.equal(false);
parsed.rbuf.toString('hex').should.equal('17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632');

View File

@ -12,7 +12,7 @@ describe('Txin', function() {
var txidbuf = new Buffer(32);
txidbuf.fill(0);
var txoutnum = 0;
var script = Script().fromString("OP_CHECKMULTISIG");
var script = Script().fromString('OP_CHECKMULTISIG');
var scriptvi = Varint(script.toBuffer().length);
var seqnum = 0;
var txin = Txin().set({
@ -73,7 +73,7 @@ describe('Txin', function() {
describe('#toJSON', function() {
it('should set these vars', function() {
var json = txin.toJSON()
var json = txin.toJSON();
should.exist(json.txidbuf);
should.exist(json.txoutnum);
should.exist(json.scriptvi);