From 34f92b605d87527f81559b72f42110386e9eb442 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Thu, 13 Mar 2014 12:41:11 -0400 Subject: [PATCH 01/12] soop may not be in the bitcore directory If bitcore is being built inside of another project that uses soop, soop may not be in the bitcore directory. We need to find the location of soop and then find the custom_prelude script relative to that. --- browser/build.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/browser/build.js b/browser/build.js index 4deae00..ca91ca6 100644 --- a/browser/build.js +++ b/browser/build.js @@ -40,7 +40,9 @@ if (!program.includeall && (!program.submodules || program.submodules.length === } var pack = function (params) { - var preludePath = 'node_modules/soop/example/custom_prelude.js'; + var file = require.resolve('soop'); + var dir = file.substr(0, file.length - String('soop.js').length); + var preludePath = dir + 'example/custom_prelude.js'; params.raw = true; params.sourceMapPrefix = '//#'; params.prelude = fs.readFileSync(preludePath, 'utf8'); From dabfbc0cf3a5cf4437d42ff7a28a03c4a658ce7a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 14:24:51 -0300 Subject: [PATCH 02/12] modularize browser build.js --- browser/build.js | 132 +++++++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 56 deletions(-) diff --git a/browser/build.js b/browser/build.js index ca91ca6..56f2116 100644 --- a/browser/build.js +++ b/browser/build.js @@ -1,18 +1,8 @@ 'use strict'; -/* - * - * The key parameter 'pack' - * The supplied 'custom_prelude.js' file is needed for - * .load function of soop. - */ - 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; var sys = require('sys'); var puts = function(error, stdout, stderr) { @@ -21,24 +11,6 @@ var puts = function(error, stdout, stderr) { sys.puts(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('-d, --dontminify', 'Don\'t minify the code.') - .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 file = require.resolve('soop'); var dir = file.substr(0, file.length - String('soop.js').length); @@ -82,40 +54,88 @@ var modules = [ 'util/VersionedData', ]; -var opts = {}; -opts.pack = pack; -opts.debug = true; -opts.standalone = 'bitcore'; -opts.insertGlobals = true; - -var b = browserify(opts); -b.require('browserify-bignum/bignumber.js', {expose: 'bignum'} ); -b.require('browserify-buffertools/buffertools.js', {expose:'buffertools'}); -b.require('base58-native', {expose: 'base58-native'}); -b.require('./bitcore', {expose: 'bitcore'}); -modules.forEach(function(m) { - if (program.includeall || program.submodules.indexOf(m) > -1) { - console.log('Including '+m+' in the browser bundle'); - b.require('./' + m + '.js' , {expose: './'+m} ); +var createBitcore = function(opts) { + + // concat browser vendor files + exec('cd browser; sh concat.sh', puts); + + if (!opts.includeall && (!opts.submodules || opts.submodules.length === 0)) { + console.log('Must use either -s or -a option. For more info use the --help option'); + process.exit(1); } -}); -if (!program.dontminify) { - b.transform({ - global: true - }, 'uglifyify'); -} + var bopts = { + pack : pack, + debug : true, + standalone : 'bitcore', + insertGlobals: true + }; + var b = browserify(bopts); + + b.require('browserify-bignum/bignumber.js', { + expose: 'bignum' + }); + b.require('browserify-buffertools/buffertools.js', { + expose: 'buffertools' + }); + b.require('base58-native', { + expose: 'base58-native' + }); + b.require('./bitcore', { + expose: 'bitcore' + }); + modules.forEach(function(m) { + if (opts.includeall || opts.submodules.indexOf(m) > -1) { + console.log('Including ' + m + ' in the browser bundle'); + b.require('./' + m + '.js', { + expose: './' + m + }); + } + }); + + if (!opts.dontminify) { + b.transform({ + global: true + }, 'uglifyify'); + } -var bundle = b.bundle(); -bundle = bundle.pipe(fs.createWriteStream('browser/bundle.js')); + var bundle = b.bundle(); + return bundle; +}; -opts.standalone = 'testdata'; -var tb = browserify(opts); -tb.require('./test/testdata', {expose: 'testdata'}); -tb.transform('brfs'); +var createTestData = function() { + var bopts = { + pack : pack, + debug : true, + standalone : 'testdata', + insertGlobals: true + }; + var tb = browserify(bopts); + tb.require('./test/testdata', { + expose: 'testdata' + }); + tb.transform('brfs'); + + return tb.bundle(); +}; -tb.bundle().pipe(fs.createWriteStream('browser/testdata.js')); +if (require.main === module) { + var list = function(val) { + return val.split(','); + }; + var program = require('commander'); + program + .version('0.0.1') + .option('-a, --includeall', 'Include all submodules.') + .option('-d, --dontminify', 'Don\'t minify the code.') + .option('-s, --submodules ', 'Include the listed comma-separated submodules.', list) + .parse(process.argv); + var bitcoreBundle = createBitcore(program); + var testBundle = createTestData(program); + testBundle.pipe(fs.createWriteStream('browser/testdata.js')); + bitcoreBundle.pipe(fs.createWriteStream('browser/bundle.js')); +} From e0557d0deab3c6ed2d2570b8c7170fb279edf5a2 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 15:06:13 -0300 Subject: [PATCH 03/12] check submodule validity --- browser/build.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/browser/build.js b/browser/build.js index 56f2116..bcfc838 100644 --- a/browser/build.js +++ b/browser/build.js @@ -63,6 +63,13 @@ var createBitcore = function(opts) { console.log('Must use either -s or -a option. For more info use the --help option'); process.exit(1); } + + if (opts.submodules) { + for (var i = 0; i Date: Thu, 13 Mar 2014 15:28:14 -0300 Subject: [PATCH 04/12] add exports --- browser/build.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/browser/build.js b/browser/build.js index bcfc838..101efb1 100644 --- a/browser/build.js +++ b/browser/build.js @@ -144,5 +144,7 @@ if (require.main === module) { testBundle.pipe(fs.createWriteStream('browser/testdata.js')); bitcoreBundle.pipe(fs.createWriteStream('browser/bundle.js')); - } + +module.exports.createBitcore = createBitcore; +module.exports.createTestData = createTestData; From b1c038b4d04aa6933dd788d86909ed699a39882a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 16:05:04 -0300 Subject: [PATCH 05/12] add dir option --- browser/build.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/browser/build.js b/browser/build.js index 101efb1..aec2603 100644 --- a/browser/build.js +++ b/browser/build.js @@ -56,8 +56,11 @@ var modules = [ var createBitcore = function(opts) { + + opts.dir = opts.dir || ''; + // concat browser vendor files - exec('cd browser; sh concat.sh', puts); + exec('cd '+opts.dir+'browser; sh concat.sh', puts); if (!opts.includeall && (!opts.submodules || opts.submodules.length === 0)) { console.log('Must use either -s or -a option. For more info use the --help option'); From a675f4566c7145560ac561b1f32de12f29663612 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 16:33:46 -0300 Subject: [PATCH 06/12] fix paths --- browser/build.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/build.js b/browser/build.js index aec2603..d0cabdf 100644 --- a/browser/build.js +++ b/browser/build.js @@ -91,13 +91,13 @@ var createBitcore = function(opts) { b.require('base58-native', { expose: 'base58-native' }); - b.require('./bitcore', { + b.require('./'+ opts.dir +'bitcore', { expose: 'bitcore' }); modules.forEach(function(m) { if (opts.includeall || opts.submodules.indexOf(m) > -1) { console.log('Including ' + m + ' in the browser bundle'); - b.require('./' + m + '.js', { + b.require('./' + opts.dir + m + '.js', { expose: './' + m }); } From c9607e5821fa53d8e961bcf1525df6b275d4c455 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 16:45:10 -0300 Subject: [PATCH 07/12] fix paths --- browser/build.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/browser/build.js b/browser/build.js index d0cabdf..6f98619 100644 --- a/browser/build.js +++ b/browser/build.js @@ -82,13 +82,13 @@ var createBitcore = function(opts) { }; var b = browserify(bopts); - b.require('browserify-bignum/bignumber.js', { + b.require(opts.dir + 'browserify-bignum/bignumber.js', { expose: 'bignum' }); - b.require('browserify-buffertools/buffertools.js', { + b.require(opts.dir + 'browserify-buffertools/buffertools.js', { expose: 'buffertools' }); - b.require('base58-native', { + b.require(opts.dir + 'base58-native', { expose: 'base58-native' }); b.require('./'+ opts.dir +'bitcore', { From b696dae603cf810ee51c6efdc76a171f4b95773e Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 18:54:48 -0300 Subject: [PATCH 08/12] make stdout output possible --- browser/build.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/browser/build.js b/browser/build.js index 6f98619..469e527 100644 --- a/browser/build.js +++ b/browser/build.js @@ -60,24 +60,24 @@ var createBitcore = function(opts) { opts.dir = opts.dir || ''; // concat browser vendor files - exec('cd '+opts.dir+'browser; sh concat.sh', puts); + exec('cd ' + opts.dir + 'browser; sh concat.sh', puts); if (!opts.includeall && (!opts.submodules || opts.submodules.length === 0)) { console.log('Must use either -s or -a option. For more info use the --help option'); process.exit(1); } - + if (opts.submodules) { - for (var i = 0; i', 'Include the listed comma-separated submodules.', list) .parse(process.argv); var bitcoreBundle = createBitcore(program); var testBundle = createTestData(program); testBundle.pipe(fs.createWriteStream('browser/testdata.js')); - bitcoreBundle.pipe(fs.createWriteStream('browser/bundle.js')); + bitcoreBundle.pipe(program.stdout ? process.stdout : fs.createWriteStream('browser/bundle.js')); } module.exports.createBitcore = createBitcore; From f9d4c66c0faf99505a3b0a9f698a00593cdafc66 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 19:10:28 -0300 Subject: [PATCH 09/12] remove extra prints --- browser/build.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/browser/build.js b/browser/build.js index 469e527..a0df956 100644 --- a/browser/build.js +++ b/browser/build.js @@ -7,8 +7,8 @@ var exec = require('child_process').exec; var sys = require('sys'); var puts = function(error, stdout, stderr) { if (error) console.log(error); - sys.puts(stdout); - sys.puts(stderr); + //sys.puts(stdout); + //sys.puts(stderr); }; var pack = function (params) { @@ -63,7 +63,7 @@ var createBitcore = function(opts) { exec('cd ' + opts.dir + 'browser; sh concat.sh', puts); if (!opts.includeall && (!opts.submodules || opts.submodules.length === 0)) { - console.log('Must use either -s or -a option. For more info use the --help option'); + if (!opts.stdout) console.log('Must use either -s or -a option. For more info use the --help option'); process.exit(1); } @@ -96,7 +96,7 @@ var createBitcore = function(opts) { }); modules.forEach(function(m) { if (opts.includeall || opts.submodules.indexOf(m) > -1) { - console.log('Including ' + m + ' in the browser bundle'); + if (!opts.stdout) console.log('Including ' + m + ' in the browser bundle'); b.require('./' + opts.dir + m + '.js', { expose: './' + m }); From 5e0ae915f2e29fe20f036411680b09a65c399921 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 19:21:15 -0300 Subject: [PATCH 10/12] muting testdata for stdout --- browser/build.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/browser/build.js b/browser/build.js index a0df956..8635ccf 100644 --- a/browser/build.js +++ b/browser/build.js @@ -143,10 +143,11 @@ if (require.main === module) { .option('-o, --stdout', 'Specify output as stdout') .option('-s, --submodules ', 'Include the listed comma-separated submodules.', list) .parse(process.argv); + if (!program.stdout) { + var testBundle = createTestData(program); + testBundle.pipe(fs.createWriteStream('browser/testdata.js')); + } var bitcoreBundle = createBitcore(program); - var testBundle = createTestData(program); - - testBundle.pipe(fs.createWriteStream('browser/testdata.js')); bitcoreBundle.pipe(program.stdout ? process.stdout : fs.createWriteStream('browser/bundle.js')); } From eb90bc152be7038feaa0c6b7081f29a75f79eeff Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 19:23:04 -0300 Subject: [PATCH 11/12] base dir --- browser/build.js | 1 + 1 file changed, 1 insertion(+) diff --git a/browser/build.js b/browser/build.js index 8635ccf..27718ea 100644 --- a/browser/build.js +++ b/browser/build.js @@ -141,6 +141,7 @@ if (require.main === module) { .option('-a, --includeall', 'Include all submodules.') .option('-d, --dontminify', 'Don\'t minify the code.') .option('-o, --stdout', 'Specify output as stdout') + .option('-D, --dir', 'Specify a base directory') .option('-s, --submodules ', 'Include the listed comma-separated submodules.', list) .parse(process.argv); if (!program.stdout) { From e8013cfed0b155d6f652f2d801aff35ee4f0708a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 13 Mar 2014 19:55:26 -0300 Subject: [PATCH 12/12] fix dir --- browser/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/build.js b/browser/build.js index 27718ea..14f14ed 100644 --- a/browser/build.js +++ b/browser/build.js @@ -141,7 +141,7 @@ if (require.main === module) { .option('-a, --includeall', 'Include all submodules.') .option('-d, --dontminify', 'Don\'t minify the code.') .option('-o, --stdout', 'Specify output as stdout') - .option('-D, --dir', 'Specify a base directory') + .option('-D, --dir ', 'Specify a base directory') .option('-s, --submodules ', 'Include the listed comma-separated submodules.', list) .parse(process.argv); if (!program.stdout) {