2016-08-14 16:26:49 +00:00
|
|
|
/*jshint esversion: 6 */
|
2017-03-29 15:37:30 +00:00
|
|
|
let async = require('async');
|
2017-03-12 15:21:19 +00:00
|
|
|
// require("./utils/debug_util.js")(__filename, async);
|
2017-03-01 04:29:16 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
let colors = require('colors');
|
2016-08-14 12:04:34 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
let IPFS = require('./upload/ipfs.js');
|
|
|
|
let Swarm = require('./upload/swarm.js');
|
2017-03-03 06:22:12 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
let EventEmitter = require('events').EventEmitter;
|
|
|
|
let Config = require('./core/config');
|
|
|
|
/**
|
|
|
|
* Initialize a new `Embark` instance.
|
|
|
|
*
|
|
|
|
* @return {Embark}
|
|
|
|
* @api public
|
|
|
|
*/
|
2017-02-19 17:51:32 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
let Embark = function (options) {
|
|
|
|
this.version = require('../package.json').version;
|
2015-06-15 10:07:40 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.env = options.environment || options.env || "development";
|
2016-08-18 00:29:41 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
|
|
|
this.config.loadConfigFiles(options);
|
|
|
|
this.plugins = this.config.plugins;
|
2017-01-26 11:34:00 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.blockchain = function (env, client) {
|
|
|
|
return require('./cmds/blockchain/blockchain.js')(Embark.prototype.config.blockchainConfig, client, env).run();
|
|
|
|
};
|
2017-02-19 18:18:43 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.simulator = function (options) {
|
|
|
|
let Simulator = require('./cmds/simulator.js');
|
|
|
|
let simulator = new Simulator({blockchainConfig: Embark.prototype.config.blockchainConfig});
|
2017-02-19 18:18:43 +00:00
|
|
|
simulator.run(options);
|
2017-03-29 15:37:30 +00:00
|
|
|
};
|
2017-02-19 18:18:43 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.generateTemplate = function (templateName, destinationFolder, name) {
|
|
|
|
let TemplateGenerator = require('./cmds/template_generator.js');
|
|
|
|
let templateGenerator = new TemplateGenerator(templateName);
|
2017-02-19 18:18:43 +00:00
|
|
|
templateGenerator.generate(destinationFolder, name);
|
2017-03-29 15:37:30 +00:00
|
|
|
};
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.run = function (options) {
|
|
|
|
let Dashboard = require('./dashboard/dashboard.js');
|
|
|
|
let Engine = require('./core/engine');
|
|
|
|
let engine = new Engine({
|
2017-03-03 06:22:12 +00:00
|
|
|
env: options.env,
|
|
|
|
embarkConfig: 'embark.json'
|
|
|
|
});
|
2017-03-29 15:37:30 +00:00
|
|
|
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.init();
|
|
|
|
|
2017-02-25 03:49:34 +00: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 23:02:17 +00:00
|
|
|
function startDashboard(callback) {
|
2016-10-30 02:30:41 +00:00
|
|
|
if (!options.useDashboard) {
|
|
|
|
return callback();
|
|
|
|
}
|
2017-01-15 23:46:40 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
let dashboard = new Dashboard({
|
2017-03-03 06:22:12 +00:00
|
|
|
logger: engine.logger,
|
|
|
|
plugins: engine.plugins,
|
|
|
|
version: engine.version,
|
|
|
|
env: engine.env
|
2017-02-20 23:02:17 +00:00
|
|
|
});
|
2017-03-29 15:37:30 +00:00
|
|
|
dashboard.start(function () {
|
|
|
|
Embark.on('abi-vanila', function (abi) {
|
2017-02-25 03:49:34 +00:00
|
|
|
dashboard.console.runCode(abi);
|
|
|
|
});
|
|
|
|
|
2017-03-11 03:00:30 +00:00
|
|
|
engine.logger.info('dashboard start');
|
2017-03-29 15:37:30 +00:00
|
|
|
Embark.on('servicesState', function (servicesState) {
|
2017-03-11 03:00:30 +00:00
|
|
|
dashboard.monitor.availableServices(servicesState);
|
|
|
|
});
|
|
|
|
|
2017-02-25 03:49:34 +00:00
|
|
|
callback();
|
|
|
|
});
|
2016-09-22 22:24:01 +00:00
|
|
|
},
|
2017-02-25 03:49:34 +00:00
|
|
|
function (callback) {
|
2017-03-29 15:37:30 +00:00
|
|
|
let pluginList = engine.plugins.listPlugins();
|
2017-02-16 01:56:18 +00:00
|
|
|
if (pluginList.length > 0) {
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
2017-02-16 01:56:18 +00:00
|
|
|
}
|
2017-02-25 20:47:35 +00:00
|
|
|
|
2017-03-11 17:27:10 +00:00
|
|
|
engine.startMonitor();
|
2017-03-11 15:29:45 +00:00
|
|
|
engine.startService("web3");
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.startService("pipeline");
|
|
|
|
engine.startService("abi");
|
|
|
|
engine.startService("deployment");
|
2017-03-11 03:00:30 +00:00
|
|
|
engine.startService("ipfs");
|
2017-03-03 06:22:12 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
Embark.on('check:backOnline:Ethereum', function () {
|
2017-03-11 17:27:10 +00:00
|
|
|
engine.logger.info('Ethereum node detected..');
|
|
|
|
engine.config.reloadConfig();
|
2017-03-29 15:37:30 +00:00
|
|
|
engine.deployManager.deployContracts(function () {
|
2017-03-11 17:27:10 +00:00
|
|
|
engine.logger.info('Deployment Done');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
engine.deployManager.deployContracts(function () {
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.startService("fileWatcher");
|
|
|
|
if (options.runWebserver) {
|
|
|
|
engine.startService("webServer", {
|
|
|
|
host: options.serverHost,
|
|
|
|
port: options.serverPort
|
|
|
|
});
|
2017-03-03 01:23:03 +00:00
|
|
|
}
|
2017-02-25 20:47:35 +00:00
|
|
|
callback();
|
|
|
|
});
|
2016-08-21 16:02:02 +00:00
|
|
|
}
|
2017-03-29 15:37:30 +00:00
|
|
|
], function (err) {
|
2016-10-31 02:04:25 +00:00
|
|
|
if (err) {
|
2017-03-03 06:22:12 +00: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-29 15:37:30 +00:00
|
|
|
Embark.emit('firstDeploymentDone');
|
2016-10-31 02:04:25 +00:00
|
|
|
}
|
2016-08-21 15:02:50 +00:00
|
|
|
});
|
2017-03-29 15:37:30 +00:00
|
|
|
};
|
2016-08-21 15:02:50 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.build = function (options) {
|
|
|
|
let Engine = require('./core/engine');
|
2017-03-03 06:22:12 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
let engine = new Engine({
|
2017-03-03 06:22:12 +00:00
|
|
|
env: options.env,
|
|
|
|
embarkConfig: 'embark.json',
|
|
|
|
interceptLogs: false
|
|
|
|
});
|
|
|
|
engine.init();
|
|
|
|
|
2016-08-21 16:02:02 +00:00
|
|
|
async.waterfall([
|
2017-03-03 06:22:12 +00:00
|
|
|
function startServices(callback) {
|
2017-03-29 15:37:30 +00:00
|
|
|
let pluginList = engine.plugins.listPlugins();
|
2017-02-26 01:45:40 +00:00
|
|
|
if (pluginList.length > 0) {
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
2017-02-26 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.startService("pipeline");
|
|
|
|
engine.startService("abi");
|
|
|
|
engine.startService("deployment");
|
|
|
|
callback();
|
2016-08-21 16:02:02 +00:00
|
|
|
},
|
2017-03-03 06:22:12 +00:00
|
|
|
function deploy(callback) {
|
2017-03-29 15:37:30 +00:00
|
|
|
engine.deployManager.deployContracts(function () {
|
2017-03-03 06:22:12 +00:00
|
|
|
callback();
|
2016-11-28 20:14:39 +00:00
|
|
|
});
|
2016-08-21 16:02:02 +00:00
|
|
|
}
|
2017-03-29 15:37:30 +00:00
|
|
|
], function (err) {
|
2016-10-31 02:04:25 +00:00
|
|
|
if (err) {
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.logger.error(err.message);
|
2016-10-31 02:04:25 +00:00
|
|
|
} else {
|
2017-03-03 06:22:12 +00:00
|
|
|
engine.logger.info("finished building".underline);
|
2016-10-31 02:04:25 +00:00
|
|
|
}
|
2017-02-26 03:39:40 +00:00
|
|
|
// needed due to child processes
|
|
|
|
process.exit();
|
2016-08-21 15:02:50 +00:00
|
|
|
});
|
2017-03-29 15:37:30 +00:00
|
|
|
};
|
2016-08-21 15:02:50 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
this.initTests = function (options) {
|
|
|
|
let Test = require('./core/test.js');
|
2016-08-21 22:05:35 +00:00
|
|
|
return new Test(options);
|
2017-03-29 15:37:30 +00:00
|
|
|
};
|
2016-10-02 21:26:57 +00:00
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
// TODO: should deploy if it hasn't already
|
|
|
|
this.upload = function (platform) {
|
2017-01-08 01:37:48 +00:00
|
|
|
if (platform === 'ipfs') {
|
2017-03-29 15:37:30 +00:00
|
|
|
let ipfs = new IPFS({buildDir: 'dist/', plugins: Embark.prototype.plugins, storageConfig: Embark.prototype.config.storageConfig});
|
2017-01-08 01:37:48 +00:00
|
|
|
ipfs.deploy();
|
|
|
|
} else if (platform === 'swarm') {
|
2017-03-29 15:37:30 +00:00
|
|
|
let swarm = new Swarm({buildDir: 'dist/', plugins: Embark.prototype.plugins, storageConfig: Embark.prototype.config.storageConfig});
|
2017-01-08 01:37:48 +00:00
|
|
|
swarm.deploy();
|
|
|
|
} else {
|
|
|
|
console.log(("unknown platform: " + platform).red);
|
|
|
|
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
|
|
|
}
|
2017-03-10 14:43:52 +00:00
|
|
|
};
|
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
if (!(this instanceof Embark)) {
|
|
|
|
return new Embark();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
Embark.prototype = Object.create(EventEmitter.prototype);
|
2017-03-12 02:49:12 +00:00
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
module.exports = Embark;
|
2016-08-14 15:10:34 +00:00
|
|
|
|