2014-04-07 15:31:41 -03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
|
var browserify = require('browserify');
|
|
|
|
|
var exec = require('child_process').exec;
|
2014-08-27 11:51:50 -03:00
|
|
|
var shell = require('shelljs');
|
|
|
|
|
|
2014-04-07 15:31:41 -03:00
|
|
|
var puts = function(error, stdout, stderr) {
|
|
|
|
|
if (error) console.log(error);
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-27 11:51:50 -03:00
|
|
|
var getCommitHash = function() {
|
|
|
|
|
//exec git command to get the hash of the current commit
|
|
|
|
|
//git rev-parse HEAD
|
|
|
|
|
|
2014-09-05 15:54:44 -07:00
|
|
|
var hash = shell.exec('git rev-parse HEAD', {
|
|
|
|
|
silent: true
|
|
|
|
|
}).output.trim().substr(0, 7);
|
2014-08-27 11:51:50 -03:00
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 21:02:01 -03:00
|
|
|
var createVersion = function() {
|
|
|
|
|
var json = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
2014-08-27 11:51:50 -03:00
|
|
|
var content = 'module.exports.version="' + json.version + '";';
|
|
|
|
|
|
2014-09-05 15:54:44 -07:00
|
|
|
content = content + '\nmodule.exports.commitHash="' + getCommitHash() + '";';
|
2014-05-14 21:02:01 -03:00
|
|
|
fs.writeFileSync("./version.js", content);
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-07 15:31:41 -03:00
|
|
|
var createBundle = function(opts) {
|
|
|
|
|
opts.dir = opts.dir || 'js/';
|
|
|
|
|
|
|
|
|
|
var bopts = {
|
|
|
|
|
debug: true,
|
|
|
|
|
standalone: 'copay',
|
|
|
|
|
insertGlobals: true
|
|
|
|
|
};
|
|
|
|
|
var b = browserify(bopts);
|
2014-05-13 13:43:05 -03:00
|
|
|
|
|
|
|
|
b.require('bitcore/node_modules/browserify-buffertools/buffertools.js', {
|
|
|
|
|
expose: 'buffertools'
|
|
|
|
|
});
|
2014-08-29 10:50:52 -03:00
|
|
|
b.require('browser-request', {
|
|
|
|
|
expose: 'request'
|
|
|
|
|
});
|
2014-10-25 19:57:12 -03:00
|
|
|
b.require('lodash');
|
2014-10-22 00:14:48 -03:00
|
|
|
b.require('querystring');
|
2014-09-05 15:54:44 -07:00
|
|
|
b.require('assert');
|
|
|
|
|
b.require('preconditions');
|
2014-05-13 13:43:05 -03:00
|
|
|
|
2014-04-07 15:31:41 -03:00
|
|
|
b.require('./copay', {
|
|
|
|
|
expose: 'copay'
|
|
|
|
|
});
|
2014-05-14 21:02:01 -03:00
|
|
|
b.require('./version');
|
2014-09-02 10:36:31 -03:00
|
|
|
|
2014-08-13 15:04:55 -07:00
|
|
|
// b.external('bitcore');
|
2014-09-26 05:00:43 -03:00
|
|
|
b.require('./js/models/Identity', {
|
|
|
|
|
expose: '../js/models/Identity'
|
2014-06-15 20:55:23 -07:00
|
|
|
});
|
2014-09-23 15:24:57 -03:00
|
|
|
b.require('./js/models/Wallet');
|
|
|
|
|
b.require('./js/models/Wallet', {
|
|
|
|
|
expose: '../../js/models/Wallet'
|
2014-08-11 17:08:18 -04:00
|
|
|
});
|
2014-09-23 15:24:57 -03:00
|
|
|
b.require('./js/models/Insight', {
|
|
|
|
|
expose: '../js/models/Insight'
|
2014-04-17 17:13:29 -03:00
|
|
|
});
|
2014-10-27 21:05:22 -03:00
|
|
|
b.require('./js/models/Compatibility', {
|
|
|
|
|
expose: '../js/models/Compatibility'
|
|
|
|
|
});
|
2014-09-23 15:24:57 -03:00
|
|
|
b.require('./js/models/PrivateKey', {
|
|
|
|
|
expose: '../js/models/PrivateKey'
|
2014-04-17 17:13:29 -03:00
|
|
|
});
|
2014-09-23 15:24:57 -03:00
|
|
|
b.require('./js/models/PublicKeyRing', {
|
|
|
|
|
expose: '../js/models/PublicKeyRing'
|
2014-04-17 18:25:53 -03:00
|
|
|
});
|
2014-09-23 15:24:57 -03:00
|
|
|
b.require('./js/models/HDPath', {
|
|
|
|
|
expose: '../js/models/HDPath'
|
2014-08-14 10:45:52 -04:00
|
|
|
});
|
2014-09-23 15:24:57 -03:00
|
|
|
b.require('./js/models/PluginManager', {
|
|
|
|
|
expose: '../js/models/PluginManager'
|
2014-09-01 15:40:31 -03:00
|
|
|
});
|
2014-09-01 16:31:35 -03:00
|
|
|
if (!opts.disablePlugins) {
|
2014-10-24 12:24:44 -03:00
|
|
|
b.require('./js/plugins/GoogleDrive', {
|
2014-09-01 16:31:35 -03:00
|
|
|
expose: '../plugins/GoogleDrive'
|
|
|
|
|
});
|
2014-10-24 12:24:44 -03:00
|
|
|
b.require('./js/plugins/InsightStorage', {
|
2014-10-23 15:47:24 -03:00
|
|
|
expose: '../plugins/InsightStorage'
|
|
|
|
|
});
|
2014-10-24 12:24:44 -03:00
|
|
|
b.require('./js/plugins/LocalStorage', {
|
2014-09-01 23:44:35 -03:00
|
|
|
expose: '../plugins/LocalStorage'
|
|
|
|
|
});
|
2014-10-24 12:24:44 -03:00
|
|
|
b.require('./js/plugins/EncryptedInsightStorage', {
|
|
|
|
|
expose: '../plugins/EncryptedInsightStorage'
|
|
|
|
|
});
|
2014-10-27 10:36:17 -03:00
|
|
|
b.require('./js/plugins/EncryptedLocalStorage', {
|
|
|
|
|
expose: '../plugins/EncryptedLocalStorage'
|
|
|
|
|
});
|
2014-09-01 16:31:35 -03:00
|
|
|
}
|
2014-09-23 15:24:57 -03:00
|
|
|
|
2014-08-14 10:42:25 -04:00
|
|
|
b.require('./config', {
|
|
|
|
|
expose: '../config'
|
|
|
|
|
});
|
2014-04-07 15:31:41 -03:00
|
|
|
|
2014-10-29 18:34:59 -03:00
|
|
|
|
|
|
|
|
// The following 2 lines fix karma tests
|
|
|
|
|
b.require('sjcl');
|
|
|
|
|
b.require('./js/log', {
|
|
|
|
|
expose: '../log.js'
|
|
|
|
|
});
|
|
|
|
|
|
2014-08-15 18:03:09 -04:00
|
|
|
if (opts.debug) {
|
2014-06-15 20:55:23 -07:00
|
|
|
//include dev dependencies
|
|
|
|
|
b.require('sinon');
|
|
|
|
|
b.require('blanket');
|
2014-10-29 18:34:59 -03:00
|
|
|
|
|
|
|
|
|
2014-08-15 13:00:33 -04:00
|
|
|
b.require('./test/mocks/FakeBlockchain', {
|
|
|
|
|
expose: './mocks/FakeBlockchain'
|
|
|
|
|
});
|
2014-08-29 10:50:52 -03:00
|
|
|
b.require('./test/mocks/FakeBlockchainSocket', {
|
|
|
|
|
expose: './mocks/FakeBlockchainSocket'
|
|
|
|
|
});
|
2014-08-15 13:00:33 -04:00
|
|
|
b.require('./test/mocks/FakeNetwork', {
|
|
|
|
|
expose: './mocks/FakeNetwork'
|
|
|
|
|
});
|
|
|
|
|
b.require('./test/mocks/FakePayProServer', {
|
|
|
|
|
expose: './mocks/FakePayProServer'
|
|
|
|
|
});
|
|
|
|
|
b.require('./test/mocks/FakePayProServer', {
|
|
|
|
|
expose: '../../mocks/FakePayProServer'
|
|
|
|
|
});
|
|
|
|
|
b.require('./test/mocks/FakeBuilder', {
|
|
|
|
|
expose: './mocks/FakeBuilder'
|
|
|
|
|
});
|
2014-06-16 17:40:59 -03:00
|
|
|
}
|
2014-06-15 20:55:23 -07:00
|
|
|
|
2014-08-15 19:33:32 -04:00
|
|
|
if (!opts.debug) {
|
2014-04-07 15:31:41 -03: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-09-05 15:54:44 -07:00
|
|
|
.version('0.0.1')
|
|
|
|
|
.option('-d, --debug', 'Development. Don\'t minify the codem and include debug packages.')
|
|
|
|
|
.option('-o, --stdout', 'Specify output as stdout')
|
|
|
|
|
.parse(process.argv);
|
2014-05-14 21:02:01 -03:00
|
|
|
|
|
|
|
|
createVersion();
|
2014-04-07 15:31:41 -03:00
|
|
|
var copayBundle = createBundle(program);
|
2014-04-10 12:36:17 -03:00
|
|
|
copayBundle.pipe(program.stdout ? process.stdout : fs.createWriteStream('js/copayBundle.js'));
|
2014-04-07 15:31:41 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports.createBundle = createBundle;
|