From 409bb093d55df2146fd649f532b71164416d088e Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 11 Mar 2014 17:53:46 -0300 Subject: [PATCH] configurable submodules for browser bundle --- Gruntfile.js | 4 ++-- browser/browserify.js | 21 +++++++++++++++++++-- package.json | 6 ++++-- test/index.html | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 090f98a..8bf4826 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,7 +16,7 @@ module.exports = function(grunt) { stdout: true, stderr: true }, - command: 'node ./browser/browserify.js', + command: 'node ./browser/browserify.js -a', } }, watch: { @@ -25,7 +25,7 @@ module.exports = function(grunt) { tasks: ['markdown'] }, scripts: { - files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js'], + files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js', '!browser/vendor-bundle.js'], tasks: ['shell'], }, }, diff --git a/browser/browserify.js b/browser/browserify.js index 1e8edbb..df52135 100644 --- a/browser/browserify.js +++ b/browser/browserify.js @@ -10,6 +10,7 @@ var fs = require('fs'); var browserify = require('browserify'); var browserPack = require('browser-pack'); +var program = require('commander'); // concat browser vendor files var exec = require('child_process').exec; @@ -22,6 +23,20 @@ var puts = function(error, stdout, stderr) { exec('cd browser; sh concat.sh', puts); +var list = function(val) { + return val.split(','); +}; + +program + .version('0.0.1') + .option('-a, --includeall', 'Include all submodules.') + .option('-s, --submodules ', 'Include the listed comma-separated submodules.', list) + .parse(process.argv); + +if (!program.includeall && (!program.submodules || program.submodules.length === 0)) { + console.log('Must use either -s or -a option. For more info use the --help option'); + process.exit(1); +} var pack = function (params) { var preludePath = 'node_modules/soop/example/custom_prelude.js'; @@ -75,9 +90,11 @@ b.require('./util/log'); b.require('./util/util'); b.require('./util/EncodedData'); b.require('./util/VersionedData'); -b.add('./browser/bignum_config.js'); modules.forEach(function(m) { - b.require('./' + m + '.js' ,{expose: './'+m} ); + if (program.includeall || program.submodules.indexOf(m) > -1) { + console.log('Including '+m+' in the browser bundle'); + b.require('./' + m + '.js' , {expose: './'+m} ); + } }); b.require('soop'); diff --git a/package.json b/package.json index 4efa62a..a66c77f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "url": "https://github.com/bitpay/bitcore.git" }, "scripts": { - "test": "mocha test -R spec" + "test": "mocha test -R spec", + "postinstall": "grunt shell" }, "dependencies": { "soop": "git://github.com/bitpay/soop.git", @@ -66,7 +67,8 @@ "browserify-buffertools": "~1.0.2", "chai": "~1.9.0", "brfs": "~1.0.0", - "async": "~0.2.10" + "async": "~0.2.10", + "commander": "~2.1.0" }, "license": "MIT" } diff --git a/test/index.html b/test/index.html index a21f79e..bbd0d61 100644 --- a/test/index.html +++ b/test/index.html @@ -38,6 +38,8 @@ +