Move to gulp-bitcore

This commit is contained in:
Esteban Ordano 2015-01-12 17:34:41 -03:00 committed by Braydon Fuller
parent 2b6e1d7e6c
commit ff3963b410
7 changed files with 97 additions and 100 deletions

3
.gitignore vendored
View File

@ -4,6 +4,9 @@ node_modules
lib/errors/index.js
npm-debug.log
bitcore-p2p.js
bitcore-p2p.min.js
tests.js
bower_components
report

View File

@ -1,92 +1,8 @@
/**
* @file gulpfile.js
*
* Defines tasks that can be run on gulp.
*
* Summary: <ul>
* <li> `test` - runs all the tests on node
* <li> `test:nofail` - internally used for watching (due to bug on gulp-mocha)
* <li> `watch:test` - watch for file changes and run tests
* <li> `lint` - run `jshint`
* <li> `coverage` - run `istanbul` with mocha to generate a report of test coverage
* <li> `coveralls` - updates coveralls info
* <li> `release` - automates release process (only for bitcore maintainers)
* </ul>
*/
'use strict';
var gulp = require('gulp');
var coveralls = require('gulp-coveralls');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var shell = require('gulp-shell');
var gulp_bitcore = require('gulp-bitcore');
var files = ['lib/**/*.js'];
var tests = ['test/**/*.js'];
var alljs = files.concat(tests);
gulp_bitcore('p2p');
function ignoreError() {
/* jshint ignore:start */ // using `this` in this context is weird
this.emit('end');
/* jshint ignore:end */
}
var testMocha = function() {
return gulp.src(tests).pipe(new mocha({
reporter: 'spec'
}));
};
/**
* Testing
*/
gulp.task('test', testMocha);
gulp.task('test:nofail', function() {
return testMocha().on('error', ignoreError);
});
/**
* 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(['node_modules/.bin/./istanbul cover node_modules/.bin/_mocha -- --recursive']));
gulp.task('coveralls', ['coverage'], function() {
gulp.src('coverage/lcov.info').pipe(coveralls());
});
/**
* 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']);
});
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']);
});
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']);
});
/* Default task */
gulp.task('default', ['lint', 'coverage'], function() { });
gulp.task('default', ['lint', 'coverage']);

View File

@ -2,12 +2,35 @@
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['mocha'],
browsers: ['Chrome', 'Firefox'],
browsers: ['Firefox'],
frameworks: ['mocha', 'detectBrowsers'],
detectBrowsers: {
enabled: true,
usePhantomJS: false,
postDetection: function(availableBrowser) {
// modify to enable additional browsers if available
var runBrowsers = ['Firefox', 'Chrome'];
var browsers = [];
for(var i = 0; i < runBrowsers.length; i++) {
if(~availableBrowser.indexOf(runBrowsers[i])) {
browsers.push(runBrowsers[i]);
}
}
return browsers;
}
},
singleRun: true,
files: [
'browser/tests.js'
'tests.js'
],
plugins: [
'karma-mocha',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers'
]
});
};

47
lib/errors/build.js Normal file
View File

@ -0,0 +1,47 @@
'use strict';
var _ = require('lodash');
var fs = require('fs');
var defineElement = function(fullName, baseClass, message) {
return fullName + ' = function() {\n' +
' this.message = ' + message + ';\n' +
' this.stack = this.message + \'\\n\' + (new Error()).stack;\n' +
'};\n' +
fullName + '.prototype = Object.create(' + baseClass + '.prototype);\n' +
fullName + '.prototype.name = "' + fullName + '";\n\n';
};
var traverseNode = function(baseClass, errorDefinition) {
var className = baseClass + '.' + errorDefinition.name;
var generated = defineElement(className, baseClass, errorDefinition.message);
if (errorDefinition.errors) {
generated += childDefinitions(className, errorDefinition.errors);
}
return generated;
};
/* jshint latedef: false */
var childDefinitions = function(parent, childDefinitions) {
var generated = '';
_.each(childDefinitions, function(childDefinition) {
generated += traverseNode(parent, childDefinition);
});
return generated;
};
/* jshint latedef: true */
var traverseRoot = function(errorsDefinition) {
var fullName = 'bitcore.errors';
var generated = '\'use strict\';\n\n';
generated += '/* jshint maxlen: 300 */\n';
generated += '/* jshint quotmark: false */\n';
generated += '/* AUTOGENERATED FILE. DON\'T EDIT, MODIFY "lib/errors/spec.js" INSTEAD */\n\n';
generated += 'var bitcore = require(\'bitcore\');\n\n';
generated += childDefinitions(fullName, errorsDefinition);
generated += 'module.exports = bitcore.errors;\n';
return generated;
};
var data = require('./spec');
fs.writeFileSync(__dirname + '/index.js', traverseRoot(data));

13
lib/errors/spec.js Normal file
View File

@ -0,0 +1,13 @@
'use strict';
function format(arg) {
return '\'' + arg
.replace('{0}', '\' + arguments[0] + \'')
.replace('{1}', '\' + arguments[1] + \'')
.replace('{2}', '\' + arguments[2] + \'') + '\'';
}
module.exports = [{
name: 'P2P',
message: format('Internal Error on bitcore-p2p Module {0}')
}];

View File

@ -55,25 +55,20 @@
"bitcore": "^0.8.6",
"bufferput": "^0.1.2",
"buffers": "^0.1.1",
"karma-detect-browsers": "^0.1.3",
"socks5-client": "^0.3.6"
},
"devDependencies": {
"brfs": "^1.2.0",
"browserify": "~6.3.3",
"chai": "~1.10.0",
"gulp": "^3.8.10",
"gulp-bump": "^0.1.11",
"gulp-coveralls": "^0.1.3",
"gulp-git": "^0.5.5",
"gulp-jshint": "^1.9.0",
"gulp-mocha": "^2.0.0",
"gulp-rename": "^1.2.0",
"gulp-shell": "^0.2.10",
"gulp-uglify": "^1.0.2",
"gulp-util": "=3.0.1",
"gulp-bitcore": "^0.1.2",
"istanbul": "^0.3.5",
"karma": "^0.12.28",
"karma-firefox-launcher": "^0.1.3",
"karma-mocha": "^0.1.9",
"lodash": "^2.4.1",
"mocha": "~2.0.1",
"plato": "^1.3.0",
"run-sequence": "^1.0.2",

View File

@ -10,7 +10,7 @@
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../browser/tests.js"></script>
<script src="../tests.js"></script>
<script>
mocha.run();
</script>