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);
|
|
|
|
};
|
|
|
|
|
|
|
|
var pack = function (params) {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
var createBundle = function(opts) {
|
|
|
|
|
|
|
|
|
|
|
|
opts.dir = opts.dir || 'js/';
|
|
|
|
|
|
|
|
// concat browser vendor files
|
|
|
|
exec('cd ' + opts.dir + 'browser; sh concat.sh', puts);
|
|
|
|
|
|
|
|
var bopts = {
|
|
|
|
pack: pack,
|
|
|
|
debug: true,
|
|
|
|
standalone: 'copay',
|
|
|
|
insertGlobals: true
|
|
|
|
};
|
|
|
|
var b = browserify(bopts);
|
|
|
|
b.require('./copay', {
|
|
|
|
expose: 'copay'
|
|
|
|
});
|
2014-04-16 15:14:58 -07:00
|
|
|
b.require('./js/models/core/WalletFactory.js');
|
|
|
|
|
2014-04-07 11:31:41 -07:00
|
|
|
|
|
|
|
if (!opts.dontminify) {
|
|
|
|
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
|
|
|
|
.version('0.0.1')
|
|
|
|
.option('-d, --dontminify', 'Don\'t minify the code.')
|
|
|
|
.option('-o, --stdout', 'Specify output as stdout')
|
|
|
|
.parse(process.argv);
|
|
|
|
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;
|