2014-04-07 11:31:41 -07:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var browserify = require('browserify');
|
|
|
|
var browserPack = require('browser-pack');
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2014-08-14 07:30:53 -07:00
|
|
|
var pack = function(params) {
|
2014-04-07 11:31:41 -07:00
|
|
|
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');
|
|
|
|
params.preludePath = preludePath;
|
|
|
|
return browserPack(params);
|
|
|
|
};
|
|
|
|
|
2014-05-14 17:02:01 -07:00
|
|
|
var createVersion = function() {
|
|
|
|
var json = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
|
|
var content = 'module.exports="' + json.version + '";';
|
|
|
|
fs.writeFileSync("./version.js", content);
|
|
|
|
};
|
|
|
|
|
2014-04-07 11:31:41 -07:00
|
|
|
var createBundle = function(opts) {
|
|
|
|
opts.dir = opts.dir || 'js/';
|
|
|
|
|
|
|
|
var bopts = {
|
|
|
|
pack: pack,
|
|
|
|
debug: true,
|
|
|
|
standalone: 'copay',
|
|
|
|
insertGlobals: true
|
|
|
|
};
|
|
|
|
var b = browserify(bopts);
|
2014-05-13 09:43:05 -07:00
|
|
|
|
|
|
|
b.require('bitcore/node_modules/browserify-buffertools/buffertools.js', {
|
|
|
|
expose: 'buffertools'
|
|
|
|
});
|
|
|
|
|
2014-04-07 11:31:41 -07:00
|
|
|
b.require('./copay', {
|
|
|
|
expose: 'copay'
|
|
|
|
});
|
2014-05-14 17:02:01 -07:00
|
|
|
b.require('./version');
|
2014-08-13 15:04:55 -07:00
|
|
|
// b.external('bitcore');
|
2014-06-15 20:55:23 -07:00
|
|
|
b.require('./js/models/core/WalletFactory', {
|
|
|
|
expose: '../js/models/core/WalletFactory'
|
|
|
|
});
|
2014-04-16 17:39:42 -07:00
|
|
|
b.require('./js/models/core/Wallet');
|
|
|
|
b.require('./js/models/core/Wallet', {
|
|
|
|
expose: '../js/models/core/Wallet'
|
|
|
|
});
|
2014-08-14 07:30:53 -07:00
|
|
|
b.require('./js/models/core/Wallet', {
|
|
|
|
expose: '../js/models/core/Wallet'
|
|
|
|
});
|
2014-08-11 14:08:18 -07:00
|
|
|
b.require('./js/models/core/Wallet', {
|
|
|
|
expose: '../../js/models/core/Wallet'
|
|
|
|
});
|
2014-04-16 17:39:42 -07:00
|
|
|
b.require('./test/mocks/FakeStorage', {
|
|
|
|
expose: './mocks/FakeStorage'
|
|
|
|
});
|
2014-06-15 20:55:23 -07:00
|
|
|
b.require('./test/mocks/FakeBlockchain', {
|
|
|
|
expose: './mocks/FakeBlockchain'
|
|
|
|
});
|
2014-04-29 13:44:35 -07:00
|
|
|
b.require('./test/mocks/FakeNetwork', {
|
|
|
|
expose: './mocks/FakeNetwork'
|
|
|
|
});
|
2014-08-14 07:30:53 -07:00
|
|
|
b.require('./test/mocks/FakePayProServer', {
|
|
|
|
expose: '../../mocks/FakePayProServer'
|
|
|
|
});
|
2014-04-17 13:13:29 -07:00
|
|
|
b.require('./js/models/network/WebRTC', {
|
2014-08-06 12:05:06 -07:00
|
|
|
expose: '../js/models/network/WebRTC'
|
2014-04-17 13:13:29 -07:00
|
|
|
});
|
|
|
|
b.require('./js/models/blockchain/Insight', {
|
|
|
|
expose: '../js/models/blockchain/Insight'
|
|
|
|
});
|
|
|
|
b.require('./js/models/core/PrivateKey', {
|
|
|
|
expose: '../js/models/core/PrivateKey'
|
|
|
|
});
|
2014-04-17 14:25:53 -07:00
|
|
|
b.require('./js/models/core/PublicKeyRing', {
|
|
|
|
expose: '../js/models/core/PublicKeyRing'
|
|
|
|
});
|
2014-04-30 06:52:39 -07:00
|
|
|
b.require('./js/models/core/Passphrase', {
|
|
|
|
expose: '../js/models/core/Passphrase'
|
|
|
|
});
|
2014-04-07 11:31:41 -07:00
|
|
|
|
2014-08-14 07:30:53 -07:00
|
|
|
if (opts.dontminify) {
|
2014-06-15 20:55:23 -07:00
|
|
|
//include dev dependencies
|
|
|
|
b.require('sinon');
|
|
|
|
b.require('blanket');
|
|
|
|
b.require('soop');
|
2014-06-16 13:40:59 -07:00
|
|
|
}
|
2014-06-15 20:55:23 -07:00
|
|
|
|
2014-08-14 07:30:53 -07:00
|
|
|
if (!opts.dontminify) {
|
2014-04-07 11:31:41 -07:00
|
|
|
b.transform({
|
|
|
|
global: true
|
|
|
|
}, 'uglifyify');
|
|
|
|
}
|
|
|
|
var bundle = b.bundle();
|
|
|
|
return bundle;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
var list = function(val) {
|
|
|
|
return val.split(',');
|
|
|
|
};
|
|
|
|
var program = require('commander');
|
|
|
|
program
|
2014-08-14 07:30:53 -07:00
|
|
|
.version('0.0.1')
|
|
|
|
.option('-d, --dontminify', 'Development. Don\'t minify the code.')
|
|
|
|
.option('-o, --stdout', 'Specify output as stdout')
|
|
|
|
.parse(process.argv);
|
2014-05-14 17:02:01 -07:00
|
|
|
|
|
|
|
createVersion();
|
2014-04-07 11:31:41 -07:00
|
|
|
var copayBundle = createBundle(program);
|
2014-04-10 08:36:17 -07:00
|
|
|
copayBundle.pipe(program.stdout ? process.stdout : fs.createWriteStream('js/copayBundle.js'));
|
2014-04-07 11:31:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.createBundle = createBundle;
|