Refactor gulpfile
This commit is contained in:
parent
ed9a9f6da9
commit
4433bd422b
195
gulpfile.js
195
gulpfile.js
|
@ -3,10 +3,29 @@
|
|||
*
|
||||
* Defines tasks that can be run on gulp.
|
||||
*
|
||||
* Summary:
|
||||
* * test - Run tests
|
||||
* * watch:test - Waits for filesystem changes and runs tests
|
||||
*
|
||||
* 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>`
|
||||
* <li> `errors` - autogenerate the `./lib/errors/index.js` file with error definitions
|
||||
* <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
|
||||
* </ul>
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -41,21 +60,112 @@ var testKarma = shell.task([
|
|||
'./node_modules/karma/bin/karma start --single-run --browsers Firefox'
|
||||
]);
|
||||
|
||||
/**
|
||||
* Testing
|
||||
*/
|
||||
|
||||
gulp.task('test', ['errors'], testMocha);
|
||||
gulp.task('test:node', ['errors'], testMocha);
|
||||
|
||||
gulp.task('test-all', ['errors'], function(callback) {
|
||||
runSequence(['test'], ['karma'], callback);
|
||||
});
|
||||
|
||||
gulp.task('test-nofail', ['errors'], function() {
|
||||
gulp.task('test:node:nofail', ['errors'], function() {
|
||||
return testMocha().on('error', ignoreError);
|
||||
});
|
||||
|
||||
gulp.task('test:browser', ['browser:uncompressed', 'browser:maketests'], testKarma);
|
||||
|
||||
gulp.task('test', function(callback) {
|
||||
runSequence(['test:node'], ['test:browser'], callback);
|
||||
});
|
||||
|
||||
/**
|
||||
* File generation
|
||||
*/
|
||||
|
||||
gulp.task('browser:uncompressed', ['errors'], shell.task([
|
||||
'./node_modules/.bin/browserify index.js --insert-global-vars=true --standalone=bitcore -o browser/bitcore.js'
|
||||
]));
|
||||
|
||||
gulp.task('browser:compressed', ['errors'], 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('browser:maketests', shell.task([
|
||||
'find test/ -type f -name "*.js" | xargs ./node_modules/.bin/browserify -t brfs -o browser/tests.js'
|
||||
]));
|
||||
|
||||
gulp.task('browser', ['errors'], function(callback) {
|
||||
runSequence(['browser:uncompressed'], ['browser:compressed'], ['browser:maketests'], callback);
|
||||
});
|
||||
|
||||
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'));
|
||||
});
|
||||
|
||||
gulp.task('plato', shell.task[
|
||||
'plato -d report -r -l .jshintrc -t bitcore lib'
|
||||
]);
|
||||
|
||||
gulp.task('coverage', shell.task(['istanbul cover _mocha -- --recursive']));
|
||||
|
||||
gulp.task('jsdoc', function() {
|
||||
return gulp.src(files.concat([jsdocReadme]))
|
||||
.pipe(jsdoc.parser({
|
||||
name: 'bitcore',
|
||||
version: '0.8.0',
|
||||
description: 'API Reference for the bitcore bitcoin javascript library',
|
||||
plugins: ['plugins/markdown']
|
||||
}))
|
||||
.pipe(jsdoc.generator('./apiref', {
|
||||
path: 'ink-docstrap',
|
||||
theme: 'journal'
|
||||
}));
|
||||
});
|
||||
|
||||
/**
|
||||
* Watch tasks
|
||||
*/
|
||||
|
||||
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']);
|
||||
return gulp.watch(alljs, ['test']);
|
||||
});
|
||||
|
||||
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']);
|
||||
});
|
||||
|
||||
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']);
|
||||
});
|
||||
|
||||
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() {
|
||||
|
@ -71,68 +181,15 @@ gulp.task('watch:lint', function() {
|
|||
});
|
||||
|
||||
gulp.task('watch:browser', function() {
|
||||
return gulp.watch(alljs, ['browser-all']);
|
||||
});
|
||||
|
||||
gulp.task('coverage', shell.task(['istanbul cover _mocha -- --recursive']));
|
||||
|
||||
gulp.task('jsdoc', function() {
|
||||
return gulp.src(files.concat([jsdocReadme]))
|
||||
.pipe(jsdoc.parser({
|
||||
name: 'bitcore',
|
||||
version: '0.8.0',
|
||||
description: 'API Reference for the bitcore bitcoin javascript library'
|
||||
}))
|
||||
.pipe(jsdoc.generator('./apiref', {
|
||||
path: 'ink-docstrap',
|
||||
theme: 'journal'
|
||||
}));
|
||||
});
|
||||
|
||||
gulp.task('lint', function() {
|
||||
return gulp.src(alljs)
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter('default'));
|
||||
});
|
||||
|
||||
gulp.task('browser', ['errors'], shell.task([
|
||||
'./node_modules/.bin/browserify index.js --insert-global-vars=true --standalone=bitcore -o browser/bitcore.js'
|
||||
]));
|
||||
|
||||
gulp.task('browser-test', shell.task([
|
||||
'find test/ -type f -name "*.js" | xargs ./node_modules/.bin/browserify -t brfs -o browser/tests.js'
|
||||
]));
|
||||
|
||||
gulp.task('browser-all', ['errors'], function(callback) {
|
||||
runSequence(['browser'], ['browser-test'], callback);
|
||||
});
|
||||
|
||||
gulp.task('karma', ['browser-all'], testKarma);
|
||||
|
||||
gulp.task('plato', shell.task[
|
||||
'plato -d report -r -l .jshintrc -t bitcore lib'
|
||||
]);
|
||||
|
||||
gulp.task('errors', shell.task([
|
||||
'node ./lib/errors/build.js'
|
||||
]));
|
||||
|
||||
gulp.task('minify', ['errors'], 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'));
|
||||
return gulp.watch(alljs, ['browser']);
|
||||
});
|
||||
|
||||
/**
|
||||
* Default task
|
||||
*/
|
||||
gulp.task('default', function(callback) {
|
||||
return runSequence(['lint', 'jsdoc'],
|
||||
['browser', 'test'],
|
||||
['browser:compressed', 'test'],
|
||||
['coverage', 'minify'],
|
||||
callback);
|
||||
});
|
||||
|
|
|
@ -8,10 +8,16 @@ var JSUtil = require('./util/js');
|
|||
|
||||
/**
|
||||
* Instantiate an address from an address String or Buffer, a public key or script hash Buffer,
|
||||
* or an instance of PublicKey or Script.
|
||||
* or an instance of {@link PublicKey} or {@link Script}.
|
||||
*
|
||||
* This is an immutable class, and if the first parameter provided to this constructor is an
|
||||
* `Address` instance, the same argument will be returned.
|
||||
*
|
||||
* An address has two key properties: `network` and `type`. The type is either
|
||||
* `Address.PayToPublicKeyHash` (value is the `'pubkeyhash'` string)
|
||||
* or `Address.PayToScriptHash` (the string `'scripthash'`). The network is an instance of {@link Network}.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // validate that an input field is valid
|
||||
* var error = Address.getValidationError(input, 'testnet');
|
||||
* if (!error) {
|
||||
|
@ -24,9 +30,8 @@ var JSUtil = require('./util/js');
|
|||
* // get an address from a public key
|
||||
* var address = Address(publicKey, 'testnet').toString();
|
||||
*
|
||||
*
|
||||
* @param {String} data - The encoded data in various formats
|
||||
* @param {String} [network] - The network: 'livenet' or 'testnet'
|
||||
* @param {*} data - The encoded data in various formats
|
||||
* @param {Network|String|number} [network] - The network: 'livenet' or 'testnet'
|
||||
* @param {String} [type] - The type of address: 'script' or 'pubkey'
|
||||
* @returns {Address} A new valid and frozen instance of an Address
|
||||
* @constructor
|
||||
|
@ -90,7 +95,12 @@ function Address(data, network, type) {
|
|||
return this;
|
||||
}
|
||||
|
||||
/** @static */
|
||||
Address.PayToPublicKeyHash = 'pubkeyhash';
|
||||
/**
|
||||
* @static
|
||||
* @value 'scripthash'
|
||||
*/
|
||||
Address.PayToScriptHash = 'scripthash';
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,17 +16,17 @@ var Varint = require('./encoding/varint');
|
|||
* the properties of the Block
|
||||
*
|
||||
* @param {*} - A Buffer, JSON string, or Object
|
||||
* @returns {Block} - An instance of Block
|
||||
* @returns {Block}
|
||||
* @constructor
|
||||
*/
|
||||
var Block = function Block(arg) {
|
||||
function Block(arg) {
|
||||
if (!(this instanceof Block)) {
|
||||
return new Block(arg);
|
||||
}
|
||||
_.extend(this, Block._from(arg));
|
||||
this._setupProperties();
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} - A Buffer, JSON string or Object
|
||||
|
|
|
@ -398,20 +398,20 @@ HDPrivateKey.prototype.inspect = function() {
|
|||
/**
|
||||
* Returns a plain object with a representation of this private key.
|
||||
*
|
||||
* Fields include:
|
||||
* * network: either 'livenet' or 'testnet'
|
||||
* * depth: a number ranging from 0 to 255
|
||||
* * fingerPrint: a number ranging from 0 to 2^32-1, taken from the hash of the
|
||||
* associated public key
|
||||
* * parentFingerPrint: a number ranging from 0 to 2^32-1, taken from the hash
|
||||
* of this parent's associated public key or zero.
|
||||
* * childIndex: the index from which this child was derived (or zero)
|
||||
* * chainCode: an hexa string representing a number used in the derivation
|
||||
* * privateKey: the private key associated, in hexa representation
|
||||
* * xprivkey: the representation of this extended private key in checksum
|
||||
* base58 format
|
||||
* * checksum: the base58 checksum of xprivkey
|
||||
*
|
||||
* Fields include:<ul>
|
||||
* <li> network: either 'livenet' or 'testnet'
|
||||
* <li> depth: a number ranging from 0 to 255
|
||||
* <li> fingerPrint: a number ranging from 0 to 2^32-1, taken from the hash of the
|
||||
* <li> associated public key
|
||||
* <li> parentFingerPrint: a number ranging from 0 to 2^32-1, taken from the hash
|
||||
* <li> of this parent's associated public key or zero.
|
||||
* <li> childIndex: the index from which this child was derived (or zero)
|
||||
* <li> chainCode: an hexa string representing a number used in the derivation
|
||||
* <li> privateKey: the private key associated, in hexa representation
|
||||
* <li> xprivkey: the representation of this extended private key in checksum
|
||||
* <li> base58 format
|
||||
* <li> checksum: the base58 checksum of xprivkey
|
||||
* </ul>
|
||||
* @return {Object}
|
||||
*/
|
||||
HDPrivateKey.prototype.toObject = function toObject() {
|
||||
|
|
|
@ -361,18 +361,19 @@ HDPublicKey.prototype.inspect = function() {
|
|||
/**
|
||||
* Returns a plain javascript object with information to reconstruct a key.
|
||||
*
|
||||
* Fields are:
|
||||
* * network: 'livenet' or 'testnet'
|
||||
* * depth: a number from 0 to 255, the depth to the master extended key
|
||||
* * fingerPrint: a number of 32 bits taken from the hash of the public key
|
||||
* * fingerPrint: a number of 32 bits taken from the hash of this key's
|
||||
* parent's public key
|
||||
* * childIndex: index with which this key was derived
|
||||
* * chainCode: string in hexa encoding used for derivation
|
||||
* * publicKey: string, hexa encoded, in compressed key format
|
||||
* * checksum: BufferUtil.integerFromBuffer(this._buffers.checksum),
|
||||
* * xpubkey: the string with the base58 representation of this extended key
|
||||
* * checksum: the base58 checksum of xpubkey
|
||||
* Fields are: <ul>
|
||||
* <li> network: 'livenet' or 'testnet'
|
||||
* <li> depth: a number from 0 to 255, the depth to the master extended key
|
||||
* <li> fingerPrint: a number of 32 bits taken from the hash of the public key
|
||||
* <li> fingerPrint: a number of 32 bits taken from the hash of this key's
|
||||
* <li> parent's public key
|
||||
* <li> childIndex: index with which this key was derived
|
||||
* <li> chainCode: string in hexa encoding used for derivation
|
||||
* <li> publicKey: string, hexa encoded, in compressed key format
|
||||
* <li> checksum: BufferUtil.integerFromBuffer(this._buffers.checksum),
|
||||
* <li> xpubkey: the string with the base58 representation of this extended key
|
||||
* <li> checksum: the base58 checksum of xpubkey
|
||||
* </ul>
|
||||
*/
|
||||
HDPublicKey.prototype.toObject = function toObject() {
|
||||
return {
|
||||
|
@ -388,6 +389,10 @@ HDPublicKey.prototype.toObject = function toObject() {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Serializes this object into a JSON string
|
||||
* @return {string}
|
||||
*/
|
||||
HDPublicKey.prototype.toJSON = function toJSON() {
|
||||
return JSON.stringify(this.toObject());
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue