From ff3963b410362ed0af57096b1ac59f1c1e041873 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Mon, 12 Jan 2015 17:34:41 -0300 Subject: [PATCH] Move to gulp-bitcore --- .gitignore | 3 ++ gulpfile.js | 90 ++------------------------------------------- karma.conf.js | 29 +++++++++++++-- lib/errors/build.js | 47 +++++++++++++++++++++++ lib/errors/spec.js | 13 +++++++ package.json | 13 ++----- test/index.html | 2 +- 7 files changed, 97 insertions(+), 100 deletions(-) create mode 100644 lib/errors/build.js create mode 100644 lib/errors/spec.js diff --git a/.gitignore b/.gitignore index 789d62d..cf634a9 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/gulpfile.js b/gulpfile.js index 95b91ae..0fbb376 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,92 +1,8 @@ -/** - * @file gulpfile.js - * - * Defines tasks that can be run on gulp. - * - * Summary: - */ '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']); diff --git a/karma.conf.js b/karma.conf.js index cc5620a..dc5d597 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -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' ] }); + }; diff --git a/lib/errors/build.js b/lib/errors/build.js new file mode 100644 index 0000000..fe9dc8a --- /dev/null +++ b/lib/errors/build.js @@ -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)); diff --git a/lib/errors/spec.js b/lib/errors/spec.js new file mode 100644 index 0000000..d49c0ac --- /dev/null +++ b/lib/errors/spec.js @@ -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}') +}]; diff --git a/package.json b/package.json index e64cf8f..8f752c6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/index.html b/test/index.html index 54742fd..3280e5e 100644 --- a/test/index.html +++ b/test/index.html @@ -10,7 +10,7 @@
- +