2016-08-14 12:26:49 -04:00
|
|
|
/*jshint esversion: 6 */
|
2016-08-13 10:48:00 -04:00
|
|
|
var async = require('async');
|
2017-02-28 23:29:16 -05:00
|
|
|
//require("./core/debug_util.js")(__filename, async);
|
|
|
|
|
2016-08-14 11:10:34 -04:00
|
|
|
var colors = require('colors');
|
2016-08-14 08:04:34 -04:00
|
|
|
|
2017-03-03 01:22:12 -05:00
|
|
|
var Engine = require('./core/engine.js');
|
|
|
|
|
2017-02-19 12:51:32 -05:00
|
|
|
var Test = require('./core/test.js');
|
|
|
|
|
|
|
|
var IPFS = require('./upload/ipfs.js');
|
|
|
|
var Swarm = require('./upload/swarm.js');
|
|
|
|
|
2017-03-08 23:52:17 +09:00
|
|
|
var version = require('../package.json').version;
|
2015-06-15 06:07:40 -04:00
|
|
|
|
2017-03-10 23:43:52 +09:00
|
|
|
var Embark = function () {
|
|
|
|
function initConfig (env, options) {
|
|
|
|
var Events = require('./core/events.js');
|
|
|
|
var Logger = require('./core/logger.js');
|
|
|
|
var Config = require('./core/config.js');
|
2016-08-17 20:29:41 -04:00
|
|
|
|
2017-02-24 06:18:57 -05:00
|
|
|
this.events = new Events();
|
2016-09-23 06:24:01 +08:00
|
|
|
this.logger = new Logger({logLevel: 'debug'});
|
2017-01-26 06:34:00 -05:00
|
|
|
|
2017-03-04 12:42:24 -05:00
|
|
|
this.config = new Config({env: env, logger: this.logger, events: this.events});
|
2017-01-26 06:34:00 -05:00
|
|
|
this.config.loadConfigFiles(options);
|
|
|
|
this.plugins = this.config.plugins;
|
2017-03-10 23:43:52 +09:00
|
|
|
}
|
2016-08-14 10:34:42 -04:00
|
|
|
|
2017-03-10 23:43:52 +09:00
|
|
|
function blockchain (env, client) {
|
|
|
|
return require('./cmds/blockchain/blockchain.js')(this.config.blockchainConfig, client, env).run();
|
|
|
|
}
|
2017-02-19 13:18:43 -05:00
|
|
|
|
2017-03-10 23:43:52 +09:00
|
|
|
function simulator (options) {
|
|
|
|
var Simulator = require('./cmds/simulator.js');
|
2017-02-19 13:18:43 -05:00
|
|
|
var simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
|
|
|
|
simulator.run(options);
|
2017-03-10 23:43:52 +09:00
|
|
|
}
|
2017-02-19 13:18:43 -05:00
|
|
|
|
2017-03-10 23:43:52 +09:00
|
|
|
function generateTemplate (templateName, destinationFolder, name) {
|
|
|
|
var TemplateGenerator = require('./cmds/template_generator.js');
|
2017-02-19 13:18:43 -05:00
|
|
|
var templateGenerator = new TemplateGenerator(templateName);
|
|
|
|
templateGenerator.generate(destinationFolder, name);
|
2017-03-10 23:43:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function run (options) {
|
|
|
|
var Dashboard = require('./dashboard/dashboard.js');
|
2017-02-19 13:18:43 -05:00
|
|
|
|
2016-10-25 19:33:24 -04:00
|
|
|
var env = options.env;
|
2017-02-24 22:49:34 -05:00
|
|
|
|
2017-03-03 01:22:12 -05:00
|
|
|
var engine = new Engine({
|
|
|
|
env: options.env,
|
|
|
|
embarkConfig: 'embark.json'
|
|
|
|
});
|
|
|
|
engine.init();
|
|
|
|
|
2017-02-24 22:49:34 -05:00
|
|
|
if (!options.useDashboard) {
|
|
|
|
console.log('========================'.bold.green);
|
|
|
|
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
|
|
|
|
console.log('========================'.bold.green);
|
|
|
|
}
|
|
|
|
|
|
|
|
async.parallel([
|
2017-02-20 18:02:17 -05:00
|
|
|
function startDashboard(callback) {
|
2016-10-29 22:30:41 -04:00
|
|
|
if (!options.useDashboard) {
|
|
|
|
return callback();
|
|
|
|
}
|
2017-01-15 18:46:40 -05:00
|
|
|
|
2017-02-24 22:49:34 -05:00
|
|
|
var dashboard = new Dashboard({
|
2017-03-03 01:22:12 -05:00
|
|
|
logger: engine.logger,
|
|
|
|
plugins: engine.plugins,
|
|
|
|
version: engine.version,
|
|
|
|
env: engine.env
|
2017-02-20 18:02:17 -05:00
|
|
|
});
|
2017-02-24 22:49:34 -05:00
|
|
|
dashboard.start(function() {
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.events.on('abi-vanila', function(abi) {
|
2017-02-24 22:49:34 -05:00
|
|
|
dashboard.console.runCode(abi);
|
|
|
|
});
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
2016-09-23 06:24:01 +08:00
|
|
|
},
|
2017-02-24 22:49:34 -05:00
|
|
|
function (callback) {
|
2017-03-03 01:22:12 -05:00
|
|
|
var pluginList = engine.plugins.listPlugins();
|
2017-02-15 20:56:18 -05:00
|
|
|
if (pluginList.length > 0) {
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
2017-02-15 20:56:18 -05:00
|
|
|
}
|
2017-02-25 15:47:35 -05:00
|
|
|
|
2017-03-03 01:22:12 -05:00
|
|
|
if (options.useDashboard) {
|
|
|
|
engine.startService("monitor", {
|
|
|
|
serverHost: options.serverHost,
|
|
|
|
serverPort: options.serverPort,
|
|
|
|
runWebserver: options.runWebserver
|
|
|
|
});
|
2016-10-29 22:30:41 -04:00
|
|
|
}
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.startService("pipeline");
|
|
|
|
engine.startService("abi");
|
|
|
|
engine.startService("deployment");
|
|
|
|
|
|
|
|
engine.deployManager.deployContracts(function() {
|
|
|
|
engine.startService("fileWatcher");
|
|
|
|
if (options.runWebserver) {
|
|
|
|
engine.startService("webServer", {
|
|
|
|
host: options.serverHost,
|
|
|
|
port: options.serverPort
|
|
|
|
});
|
2017-03-02 20:23:03 -05:00
|
|
|
}
|
2017-02-25 15:47:35 -05:00
|
|
|
callback();
|
|
|
|
});
|
2016-08-21 12:02:02 -04:00
|
|
|
}
|
|
|
|
], function(err, result) {
|
2016-10-30 22:04:25 -04:00
|
|
|
if (err) {
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.logger.error(err.message);
|
|
|
|
} else {
|
|
|
|
engine.logger.setStatus("Ready".green);
|
|
|
|
engine.logger.info("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
|
|
|
|
engine.logger.info("Ready".underline);
|
2017-03-05 11:00:47 -05:00
|
|
|
engine.events.emit('firstDeploymentDone');
|
2016-10-30 22:04:25 -04:00
|
|
|
}
|
2016-08-21 11:02:50 -04:00
|
|
|
});
|
2017-03-10 23:43:52 +09:00
|
|
|
}
|
2016-08-21 11:02:50 -04:00
|
|
|
|
2017-03-10 23:43:52 +09:00
|
|
|
function build (options) {
|
2017-03-03 01:22:12 -05:00
|
|
|
|
|
|
|
var engine = new Engine({
|
|
|
|
env: options.env,
|
|
|
|
embarkConfig: 'embark.json',
|
|
|
|
interceptLogs: false
|
|
|
|
});
|
|
|
|
engine.init();
|
|
|
|
|
2016-08-21 12:02:02 -04:00
|
|
|
async.waterfall([
|
2017-03-03 01:22:12 -05:00
|
|
|
function startServices(callback) {
|
|
|
|
var pluginList = engine.plugins.listPlugins();
|
2017-02-25 20:45:40 -05:00
|
|
|
if (pluginList.length > 0) {
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
2017-02-25 20:45:40 -05:00
|
|
|
}
|
|
|
|
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.startService("pipeline");
|
|
|
|
engine.startService("abi");
|
|
|
|
engine.startService("deployment");
|
|
|
|
callback();
|
2016-08-21 12:02:02 -04:00
|
|
|
},
|
2017-03-03 01:22:12 -05:00
|
|
|
function deploy(callback) {
|
|
|
|
engine.deployManager.deployContracts(function() {
|
|
|
|
callback();
|
2016-11-28 17:14:39 -03:00
|
|
|
});
|
2016-08-21 12:02:02 -04:00
|
|
|
}
|
|
|
|
], function(err, result) {
|
2016-10-30 22:04:25 -04:00
|
|
|
if (err) {
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.logger.error(err.message);
|
2016-10-30 22:04:25 -04:00
|
|
|
} else {
|
2017-03-03 01:22:12 -05:00
|
|
|
engine.logger.info("finished building".underline);
|
2016-10-30 22:04:25 -04:00
|
|
|
}
|
2017-02-25 22:39:40 -05:00
|
|
|
// needed due to child processes
|
|
|
|
process.exit();
|
2016-08-21 11:02:50 -04:00
|
|
|
});
|
2017-03-10 23:43:52 +09:00
|
|
|
}
|
2016-08-21 11:02:50 -04:00
|
|
|
|
2017-03-10 23:43:52 +09:00
|
|
|
function initTests (options) {
|
2016-08-21 18:05:35 -04:00
|
|
|
return new Test(options);
|
2017-03-10 23:43:52 +09:00
|
|
|
}
|
2016-10-02 17:26:57 -04:00
|
|
|
|
|
|
|
// TODO: should deploy if it hasn't already
|
2017-03-10 23:43:52 +09:00
|
|
|
function upload (platform) {
|
2017-01-07 20:37:48 -05:00
|
|
|
if (platform === 'ipfs') {
|
2017-02-10 07:44:06 -05:00
|
|
|
var ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
2017-01-07 20:37:48 -05:00
|
|
|
ipfs.deploy();
|
|
|
|
} else if (platform === 'swarm') {
|
2017-02-10 07:44:06 -05:00
|
|
|
var swarm = new Swarm({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
2017-01-07 20:37:48 -05:00
|
|
|
swarm.deploy();
|
|
|
|
} else {
|
|
|
|
console.log(("unknown platform: " + platform).red);
|
|
|
|
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
|
|
|
}
|
2017-02-18 08:01:03 -05:00
|
|
|
}
|
|
|
|
|
2017-03-10 23:43:52 +09:00
|
|
|
return {
|
|
|
|
version: version,
|
|
|
|
initConfig: initConfig,
|
|
|
|
blockchain: blockchain,
|
|
|
|
simulator: simulator,
|
|
|
|
generateTemplate: generateTemplate,
|
|
|
|
run: run,
|
|
|
|
build: build,
|
|
|
|
initTests: initTests,
|
|
|
|
upload: upload
|
|
|
|
};
|
|
|
|
|
2016-08-17 20:29:41 -04:00
|
|
|
};
|
2016-08-14 08:04:34 -04:00
|
|
|
|
2016-08-17 20:29:41 -04:00
|
|
|
module.exports = Embark;
|
2016-08-14 11:10:34 -04:00
|
|
|
|