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-12-05 23:14:46 +00:00
|
|
|
require('colors');
|
2016-08-14 12:04:34 +00:00
|
|
|
|
2018-04-09 20:14:07 +00:00
|
|
|
// Override process.chdir so that we have a partial-implementation PWD for Windows
|
|
|
|
const realChdir = process.chdir;
|
|
|
|
process.chdir = (...args) => {
|
|
|
|
if (!process.env.PWD) {
|
|
|
|
process.env.PWD = process.cwd();
|
|
|
|
}
|
|
|
|
realChdir(...args);
|
|
|
|
};
|
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
let Engine = require('./core/engine.js');
|
|
|
|
|
|
|
|
let version = require('../package.json').version;
|
|
|
|
|
2017-03-31 11:34:43 +00:00
|
|
|
class Embark {
|
2017-03-30 13:16:46 +00:00
|
|
|
|
|
|
|
constructor (options) {
|
|
|
|
this.version = version;
|
|
|
|
this.options = options || {};
|
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
initConfig(env, options) {
|
|
|
|
let Events = require('./core/events.js');
|
|
|
|
let Logger = require('./core/logger.js');
|
|
|
|
let Config = require('./core/config.js');
|
2017-03-30 11:12:39 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
this.events = new Events();
|
2018-03-15 21:18:20 +00:00
|
|
|
this.logger = new Logger({logLevel: 'debug', events: this.events});
|
2017-03-30 13:16:46 +00:00
|
|
|
|
|
|
|
this.config = new Config({env: env, logger: this.logger, events: this.events});
|
2017-03-30 11:12:39 +00:00
|
|
|
this.config.loadConfigFiles(options);
|
|
|
|
this.plugins = this.config.plugins;
|
2017-03-30 13:16:46 +00:00
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
blockchain(env, client) {
|
|
|
|
return require('./cmds/blockchain/blockchain.js')(this.config.blockchainConfig, client, env).run();
|
|
|
|
}
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
simulator(options) {
|
|
|
|
let Simulator = require('./cmds/simulator.js');
|
|
|
|
let simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
|
|
|
|
simulator.run(options);
|
|
|
|
}
|
2017-01-15 23:46:40 +00:00
|
|
|
|
2017-03-30 13:31:23 +00:00
|
|
|
generateTemplate(templateName, destinationFolder, name) {
|
2017-03-30 13:16:46 +00:00
|
|
|
let TemplateGenerator = require('./cmds/template_generator.js');
|
|
|
|
let templateGenerator = new TemplateGenerator(templateName);
|
|
|
|
templateGenerator.generate(destinationFolder, name);
|
|
|
|
}
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
run(options) {
|
2017-03-31 11:34:43 +00:00
|
|
|
let self = this;
|
2017-03-30 13:16:46 +00:00
|
|
|
let Dashboard = require('./dashboard/dashboard.js');
|
2017-12-19 20:14:09 +00:00
|
|
|
let windowSize = require('window-size');
|
2017-03-11 03:00:30 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
let engine = new Engine({
|
|
|
|
env: options.env,
|
2017-03-31 11:34:43 +00:00
|
|
|
version: this.version,
|
2018-03-10 18:45:56 +00:00
|
|
|
embarkConfig: options.embarkConfig || 'embark.json',
|
2018-04-17 06:17:59 +00:00
|
|
|
logfile: options.logfile,
|
|
|
|
logLevel: options.logLevel,
|
|
|
|
interceptLogs: true
|
2017-03-30 13:16:46 +00:00
|
|
|
});
|
|
|
|
engine.init();
|
|
|
|
|
|
|
|
if (!options.useDashboard) {
|
|
|
|
console.log('========================'.bold.green);
|
2017-03-31 11:34:43 +00:00
|
|
|
console.log(('Welcome to Embark ' + this.version).yellow.bold);
|
2017-03-30 13:16:46 +00:00
|
|
|
console.log('========================'.bold.green);
|
|
|
|
}
|
|
|
|
|
|
|
|
async.parallel([
|
|
|
|
function startDashboard(callback) {
|
|
|
|
if (!options.useDashboard) {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
let dashboard = new Dashboard({
|
2017-12-17 23:34:41 +00:00
|
|
|
events: engine.events,
|
2017-03-30 13:16:46 +00:00
|
|
|
logger: engine.logger,
|
|
|
|
plugins: engine.plugins,
|
2017-03-31 11:34:43 +00:00
|
|
|
version: self.version,
|
2017-07-06 23:50:36 +00:00
|
|
|
env: engine.env,
|
|
|
|
contractsConfig: engine.config.contractsConfig
|
2017-03-30 13:16:46 +00:00
|
|
|
});
|
|
|
|
dashboard.start(function () {
|
2017-07-06 22:48:20 +00:00
|
|
|
engine.events.on('code-generator-ready', function () {
|
2017-10-17 11:03:13 +00:00
|
|
|
engine.events.request('code-vanila-deployment', function (abi) {
|
2017-07-06 22:48:20 +00:00
|
|
|
dashboard.console.runCode(abi);
|
|
|
|
});
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
2017-03-03 06:22:12 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
engine.logger.info('dashboard start');
|
2017-02-25 20:47:35 +00:00
|
|
|
callback();
|
2017-03-30 13:16:46 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
function (callback) {
|
|
|
|
let pluginList = engine.plugins.listPlugins();
|
|
|
|
if (pluginList.length > 0) {
|
|
|
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2017-03-30 13:16:46 +00:00
|
|
|
|
|
|
|
engine.startMonitor();
|
2017-12-30 20:52:51 +00:00
|
|
|
engine.startService("libraryManager");
|
2017-03-30 13:16:46 +00:00
|
|
|
engine.startService("web3");
|
|
|
|
engine.startService("pipeline");
|
2017-08-03 23:29:09 +00:00
|
|
|
engine.startService("codeGenerator");
|
2017-03-30 13:16:46 +00:00
|
|
|
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');
|
|
|
|
});
|
2016-11-28 20:14:39 +00:00
|
|
|
});
|
2017-03-30 13:16:46 +00:00
|
|
|
|
|
|
|
engine.deployManager.deployContracts(function (err) {
|
|
|
|
engine.startService("fileWatcher");
|
|
|
|
if (options.runWebserver) {
|
|
|
|
engine.startService("webServer", {
|
|
|
|
host: options.serverHost,
|
|
|
|
port: options.serverPort
|
|
|
|
});
|
|
|
|
}
|
|
|
|
callback(err);
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
2017-03-30 13:16:46 +00:00
|
|
|
}
|
2017-12-05 23:14:46 +00:00
|
|
|
], function (err, _result) {
|
2017-03-30 13:16:46 +00:00
|
|
|
if (err) {
|
|
|
|
engine.logger.error(err.message);
|
|
|
|
engine.logger.info(err.stack);
|
2016-10-31 02:04:25 +00:00
|
|
|
} else {
|
2017-12-19 20:14:09 +00:00
|
|
|
engine.events.emit('firstDeploymentDone');
|
2018-02-27 20:49:21 +00:00
|
|
|
engine.events.emit("status", "Ready".green);
|
2017-03-30 13:16:46 +00:00
|
|
|
engine.logger.info("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
|
|
|
|
engine.logger.info("Ready".underline);
|
2017-12-19 20:14:09 +00:00
|
|
|
|
|
|
|
let size = windowSize.get();
|
|
|
|
if (size.height < 40 || size.width < 118) {
|
|
|
|
engine.logger.warn("tip: you can resize the terminal or disable the dashboard with " + "embark run --nodashboard".bold.underline);
|
|
|
|
}
|
2016-10-31 02:04:25 +00:00
|
|
|
}
|
2017-03-30 13:16:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-15 08:41:50 +00:00
|
|
|
build(options, engine, continueProcessing) {
|
|
|
|
if(!engine){
|
|
|
|
engine = new Engine({
|
|
|
|
env: options.env,
|
|
|
|
version: this.version,
|
|
|
|
embarkConfig: 'embark.json',
|
|
|
|
interceptLogs: false
|
|
|
|
});
|
|
|
|
engine.init();
|
|
|
|
}
|
2016-10-02 21:26:57 +00:00
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
async.waterfall([
|
|
|
|
function startServices(callback) {
|
|
|
|
let pluginList = engine.plugins.listPlugins();
|
|
|
|
if (pluginList.length > 0) {
|
|
|
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
|
|
|
}
|
|
|
|
|
2017-12-30 20:52:51 +00:00
|
|
|
engine.startService("libraryManager");
|
2017-03-30 13:16:46 +00:00
|
|
|
engine.startService("web3");
|
|
|
|
engine.startService("pipeline");
|
2017-08-03 23:29:09 +00:00
|
|
|
engine.startService("codeGenerator");
|
2017-03-30 13:16:46 +00:00
|
|
|
engine.startService("deployment");
|
2017-12-30 20:52:51 +00:00
|
|
|
engine.startService("ipfs");
|
2017-03-30 13:16:46 +00:00
|
|
|
callback();
|
|
|
|
},
|
|
|
|
function deploy(callback) {
|
|
|
|
engine.deployManager.deployContracts(function (err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
2017-12-05 23:14:46 +00:00
|
|
|
], function (err, _result) {
|
2017-03-30 13:16:46 +00:00
|
|
|
if (err) {
|
|
|
|
engine.logger.error(err.message);
|
|
|
|
engine.logger.debug(err.stack);
|
|
|
|
} else {
|
|
|
|
engine.logger.info("finished building".underline);
|
|
|
|
}
|
|
|
|
// needed due to child processes
|
2018-04-15 08:50:56 +00:00
|
|
|
if(err || !continueProcessing){
|
2018-04-15 08:41:50 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
2017-03-30 13:16:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-30 13:31:23 +00:00
|
|
|
initTests(options) {
|
2018-01-20 02:13:20 +00:00
|
|
|
let Test = require('./tests/test.js');
|
2017-03-30 13:16:46 +00:00
|
|
|
return new Test(options);
|
|
|
|
}
|
|
|
|
|
2018-03-22 19:09:01 +00:00
|
|
|
graph(options) {
|
|
|
|
options.onlyCompile = true;
|
|
|
|
|
|
|
|
let engine = new Engine({
|
|
|
|
env: options.env,
|
|
|
|
version: this.version,
|
|
|
|
embarkConfig: options.embarkConfig || 'embark.json',
|
|
|
|
logfile: options.logfile
|
|
|
|
});
|
|
|
|
engine.init();
|
|
|
|
|
|
|
|
|
|
|
|
async.parallel([
|
|
|
|
|
|
|
|
function (callback) {
|
|
|
|
let pluginList = engine.plugins.listPlugins();
|
|
|
|
if (pluginList.length > 0) {
|
|
|
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
|
|
|
}
|
|
|
|
|
|
|
|
engine.startMonitor();
|
|
|
|
engine.startService("libraryManager");
|
|
|
|
engine.startService("pipeline");
|
|
|
|
engine.startService("codeGenerator");
|
|
|
|
engine.startService("deployment", {onlyCompile: true});
|
|
|
|
|
|
|
|
engine.deployManager.deployContracts(function (err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
], function (err, _result) {
|
|
|
|
if (err) {
|
|
|
|
engine.logger.error(err.message);
|
|
|
|
engine.logger.info(err.stack);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const GraphGenerator = require('./cmds/graph.js');
|
2018-03-22 20:18:13 +00:00
|
|
|
let graphGen = new GraphGenerator(engine);
|
2018-03-22 19:09:01 +00:00
|
|
|
graphGen.generate();
|
|
|
|
|
|
|
|
engine.logger.info("Done".underline);
|
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-22 14:43:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 14:22:58 +00:00
|
|
|
reset() {
|
|
|
|
let resetCmd = require('./cmds/reset.js');
|
|
|
|
resetCmd();
|
|
|
|
}
|
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
// TODO: should deploy if it hasn't already
|
2018-04-12 10:46:04 +00:00
|
|
|
upload(platform, options) {
|
|
|
|
|
|
|
|
options.buildDir = 'dist/';
|
|
|
|
options.storageConfig = this.config.storageConfig;
|
|
|
|
|
2018-04-15 08:41:50 +00:00
|
|
|
// initialise embark engine
|
2018-04-12 10:46:04 +00:00
|
|
|
let engine = new Engine({
|
|
|
|
env: options.env,
|
|
|
|
version: this.version,
|
|
|
|
embarkConfig: options.embarkConfig || 'embark.json',
|
|
|
|
logfile: options.logfile
|
|
|
|
});
|
|
|
|
engine.init();
|
2017-12-27 00:55:42 +00:00
|
|
|
|
2018-04-15 08:41:50 +00:00
|
|
|
// load plugins
|
2017-12-27 00:55:42 +00:00
|
|
|
this.plugins.loadInternalPlugin('ipfs', options);
|
|
|
|
this.plugins.loadInternalPlugin('swarm', options);
|
|
|
|
|
2018-04-15 08:41:50 +00:00
|
|
|
let plugins = this.plugins;
|
2017-12-27 00:55:42 +00:00
|
|
|
let cmdPlugin;
|
2018-04-15 08:41:50 +00:00
|
|
|
let self = this;
|
|
|
|
async.waterfall([
|
|
|
|
function setupStoragePlugin(callback){
|
|
|
|
// check use has input existing storage plugin
|
|
|
|
let cmdPlugins = plugins.getPluginsFor('uploadCmds');
|
|
|
|
|
|
|
|
if (cmdPlugins.length > 0) {
|
|
|
|
cmdPlugin = cmdPlugins.find((pluginCmd) => {
|
|
|
|
return pluginCmd.name == platform;
|
2018-04-12 10:46:04 +00:00
|
|
|
});
|
|
|
|
}
|
2018-04-15 08:41:50 +00:00
|
|
|
if (!cmdPlugin) {
|
|
|
|
engine.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green);
|
|
|
|
callback({message: 'unknown platform: ' + platform});
|
2018-04-12 10:46:04 +00:00
|
|
|
} else {
|
2018-04-15 08:41:50 +00:00
|
|
|
callback();
|
2018-04-12 10:46:04 +00:00
|
|
|
}
|
2018-04-15 08:41:50 +00:00
|
|
|
},
|
|
|
|
function buildAndDeployContracts(callback){
|
|
|
|
// 2. upload to storage (outputDone event triggered after webpack finished)
|
|
|
|
engine.events.on('outputDone', function () {
|
|
|
|
engine.logger.info('deploying to ' + platform + '...');
|
|
|
|
cmdPlugin.uploadCmds[0].cb()
|
|
|
|
.then((success) => {
|
|
|
|
callback(null, success);
|
|
|
|
})
|
|
|
|
.catch(callback);
|
|
|
|
});
|
|
|
|
// 1. build the contracts and dapp webpack
|
|
|
|
self.build(options, engine, true);
|
|
|
|
}
|
|
|
|
], function (err, _result) {
|
|
|
|
if (err) {
|
|
|
|
engine.logger.error(err.message);
|
|
|
|
engine.logger.debug(err.stack);
|
|
|
|
} else {
|
|
|
|
engine.logger.info("finished building dapp and deploying to " + platform.underline);
|
|
|
|
}
|
2018-04-12 10:46:04 +00:00
|
|
|
|
2018-04-15 08:41:50 +00:00
|
|
|
// needed due to child processes
|
|
|
|
process.exit();
|
|
|
|
});
|
2017-03-29 15:37:30 +00:00
|
|
|
}
|
|
|
|
|
2017-07-02 15:32:16 +00:00
|
|
|
runTests(file) {
|
2018-01-20 02:13:20 +00:00
|
|
|
let RunTests = require('./tests/run_tests.js');
|
2017-07-02 15:32:16 +00:00
|
|
|
RunTests.run(file);
|
2017-07-02 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 13:16:46 +00:00
|
|
|
}
|
2017-03-12 02:49:12 +00:00
|
|
|
|
2017-06-26 13:01:54 +00:00
|
|
|
// temporary until next refactor
|
|
|
|
Embark.initTests = function(options) {
|
2018-01-20 02:13:20 +00:00
|
|
|
let Test = require('./tests/test.js');
|
2017-06-26 13:01:54 +00:00
|
|
|
return new Test(options);
|
2017-06-26 13:02:58 +00:00
|
|
|
};
|
2017-06-26 13:01:54 +00:00
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
module.exports = Embark;
|