embark-area-51/lib/index.js

215 lines
6.3 KiB
JavaScript
Raw Normal View History

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