2016-08-14 16:26:49 +00:00
|
|
|
/*jshint esversion: 6 */
|
2016-08-13 14:48:00 +00:00
|
|
|
var async = require('async');
|
2017-03-01 04:29:16 +00:00
|
|
|
//require("./core/debug_util.js")(__filename, async);
|
|
|
|
|
2016-08-14 12:04:34 +00:00
|
|
|
var Web3 = require('web3');
|
2016-08-14 15:10:34 +00:00
|
|
|
var colors = require('colors');
|
2016-08-14 12:04:34 +00:00
|
|
|
|
2017-02-19 17:51:32 +00:00
|
|
|
var Blockchain = require('./cmds/blockchain/blockchain.js');
|
|
|
|
var Simulator = require('./cmds/simulator.js');
|
|
|
|
var TemplateGenerator = require('./cmds/template_generator.js');
|
|
|
|
|
2017-02-24 13:20:03 +00:00
|
|
|
var DeployManager = require('./contracts/deploy_manager.js');
|
2017-03-01 04:29:16 +00:00
|
|
|
var ABIGenerator = require('./contracts/abi.js');
|
2017-02-19 17:51:32 +00:00
|
|
|
|
|
|
|
var Test = require('./core/test.js');
|
|
|
|
var Logger = require('./core/logger.js');
|
|
|
|
var Config = require('./core/config.js');
|
|
|
|
var ServicesMonitor = require('./core/services.js');
|
2017-02-24 11:18:57 +00:00
|
|
|
var Events = require('./core/events.js');
|
2017-02-19 17:51:32 +00:00
|
|
|
|
2017-02-20 23:02:17 +00:00
|
|
|
var Dashboard = require('./dashboard/dashboard.js');
|
2017-02-19 17:51:32 +00:00
|
|
|
|
|
|
|
var Pipeline = require('./pipeline/pipeline.js');
|
|
|
|
var Server = require('./pipeline/server.js');
|
|
|
|
var Watch = require('./pipeline/watch.js');
|
|
|
|
|
|
|
|
var IPFS = require('./upload/ipfs.js');
|
|
|
|
var Swarm = require('./upload/swarm.js');
|
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
var Cmd = require('./cmd.js');
|
2015-06-15 10:07:40 +00:00
|
|
|
|
2016-08-13 14:48:00 +00:00
|
|
|
var Embark = {
|
2016-08-18 00:29:41 +00:00
|
|
|
|
2017-02-08 11:38:26 +00:00
|
|
|
version: '2.3.0',
|
2016-10-31 02:37:06 +00:00
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
process: function(args) {
|
|
|
|
var cmd = new Cmd(Embark);
|
|
|
|
cmd.process(args);
|
|
|
|
},
|
|
|
|
|
2016-08-22 03:40:05 +00:00
|
|
|
initConfig: function(env, options) {
|
2017-02-24 11:18:57 +00:00
|
|
|
this.events = new Events();
|
2016-09-22 22:24:01 +00:00
|
|
|
this.logger = new Logger({logLevel: 'debug'});
|
2017-01-26 11:34:00 +00:00
|
|
|
|
|
|
|
this.config = new Config({env: env, logger: this.logger});
|
|
|
|
this.config.loadConfigFiles(options);
|
|
|
|
this.plugins = this.config.plugins;
|
|
|
|
|
2016-08-14 12:04:34 +00:00
|
|
|
},
|
2016-08-14 14:34:42 +00:00
|
|
|
|
2017-02-19 18:18:43 +00:00
|
|
|
blockchain: function(env, client) {
|
2017-02-20 21:11:27 +00:00
|
|
|
var blockchain = Blockchain(this.config.blockchainConfig, client, env);
|
|
|
|
blockchain.run();
|
2017-02-19 18:18:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
simulator: function(options) {
|
|
|
|
var simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
|
|
|
|
simulator.run(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
generateTemplate: function(templateName, destinationFolder, name) {
|
|
|
|
var templateGenerator = new TemplateGenerator(templateName);
|
|
|
|
templateGenerator.generate(destinationFolder, name);
|
|
|
|
},
|
|
|
|
|
2016-10-25 23:33:24 +00:00
|
|
|
run: function(options) {
|
2016-08-22 03:40:05 +00:00
|
|
|
var self = this;
|
2016-10-25 23:33:24 +00:00
|
|
|
var env = options.env;
|
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-02-25 03:49:34 +00:00
|
|
|
var dashboard = new Dashboard({
|
2017-02-20 23:02:17 +00:00
|
|
|
logger: Embark.logger,
|
|
|
|
plugins: self.plugins,
|
|
|
|
version: self.version,
|
|
|
|
env: env
|
|
|
|
});
|
2017-02-25 03:49:34 +00:00
|
|
|
dashboard.start(function() {
|
|
|
|
self.events.on('abi-vanila', function(abi) {
|
|
|
|
dashboard.console.runCode(abi);
|
|
|
|
});
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
2016-09-22 22:24:01 +00:00
|
|
|
},
|
2017-02-25 03:49:34 +00:00
|
|
|
function (callback) {
|
|
|
|
Embark.startEmbark(options, callback);
|
|
|
|
}
|
|
|
|
], function(err, result) {
|
|
|
|
if (err) {
|
|
|
|
self.logger.error(err.message);
|
|
|
|
} else {
|
|
|
|
self.logger.setStatus("Ready".green);
|
|
|
|
self.logger.info("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
|
|
|
|
self.logger.info("Ready".underline);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
startEmbark: function(options, done) {
|
|
|
|
var self = this;
|
|
|
|
var env = options.env;
|
|
|
|
async.waterfall([
|
2017-02-16 01:56:18 +00:00
|
|
|
function displayLoadedPlugins(callback) {
|
|
|
|
var pluginList = self.plugins.listPlugins();
|
|
|
|
if (pluginList.length > 0) {
|
|
|
|
self.logger.info("loaded plugins: " + pluginList.join(", "));
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
},
|
2017-02-25 20:47:35 +00:00
|
|
|
|
2017-02-25 03:49:34 +00:00
|
|
|
// can be done in paralell
|
2016-09-22 22:24:01 +00:00
|
|
|
function monitorServices(callback) {
|
2016-10-30 02:30:41 +00:00
|
|
|
if (!options.useDashboard) {
|
|
|
|
return callback();
|
|
|
|
}
|
2017-02-25 03:49:34 +00:00
|
|
|
var servicesMonitor = new ServicesMonitor({
|
2016-09-22 22:24:01 +00:00
|
|
|
logger: Embark.logger,
|
2016-10-25 23:33:24 +00:00
|
|
|
config: Embark.config,
|
2016-10-30 01:41:50 +00:00
|
|
|
serverHost: options.serverHost,
|
2016-10-30 02:00:54 +00:00
|
|
|
serverPort: options.serverPort,
|
2016-10-31 02:37:06 +00:00
|
|
|
runWebserver: options.runWebserver,
|
|
|
|
version: Embark.version
|
2016-09-22 22:24:01 +00:00
|
|
|
});
|
2017-02-25 03:49:34 +00:00
|
|
|
servicesMonitor.startMonitor();
|
2016-09-17 03:56:25 +00:00
|
|
|
callback();
|
|
|
|
},
|
2017-02-25 03:49:34 +00:00
|
|
|
|
|
|
|
function buildPipeline(callback) {
|
2017-02-20 22:12:13 +00:00
|
|
|
self.logger.setStatus("Building Assets");
|
|
|
|
var pipeline = new Pipeline({
|
|
|
|
buildDir: self.config.buildDir,
|
|
|
|
contractsFiles: self.config.contractsFiles,
|
|
|
|
assetFiles: self.config.assetFiles,
|
|
|
|
logger: self.logger,
|
|
|
|
plugins: self.plugins
|
|
|
|
});
|
2017-02-25 03:49:34 +00:00
|
|
|
self.events.on('abi', function(abi) {
|
2017-03-03 01:23:03 +00:00
|
|
|
Embark.currentAbi = abi;
|
2017-02-25 03:49:34 +00:00
|
|
|
pipeline.build(abi);
|
|
|
|
});
|
2017-03-03 01:23:03 +00:00
|
|
|
self.events.on('file-event', function(fileType, path) {
|
|
|
|
if (fileType === 'asset') {
|
|
|
|
self.config.reloadConfig();
|
2017-03-03 02:31:07 +00:00
|
|
|
pipeline.build(Embark.abi, path);
|
2017-03-03 01:23:03 +00:00
|
|
|
}
|
|
|
|
});
|
2017-02-20 22:12:13 +00:00
|
|
|
callback();
|
|
|
|
},
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-03-01 04:29:16 +00:00
|
|
|
function generateABI(callback) {
|
|
|
|
var generateABICode = function(contractsManager) {
|
|
|
|
var abiGenerator = new ABIGenerator({
|
|
|
|
blockchainConfig: self.config.blockchainConfig,
|
|
|
|
contractsManager: contractsManager,
|
|
|
|
plugins: self.plugins,
|
|
|
|
storageConfig: self.config.storageConfig,
|
|
|
|
communicationConfig: self.config.communicationConfig
|
|
|
|
});
|
|
|
|
var embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
|
|
|
|
var vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
|
|
|
|
|
|
|
|
self.events.emit('abi-vanila', vanillaABI);
|
|
|
|
self.events.emit('abi', embarkJSABI);
|
|
|
|
};
|
|
|
|
self.events.on('contractsDeployed', generateABICode);
|
|
|
|
self.events.on('blockchainDisabled', generateABICode);
|
|
|
|
callback();
|
|
|
|
},
|
|
|
|
|
2017-02-25 20:47:35 +00:00
|
|
|
function deploy(callback) {
|
|
|
|
var deployManager = new DeployManager({
|
|
|
|
config: Embark.config,
|
|
|
|
logger: Embark.logger,
|
|
|
|
plugins: self.plugins,
|
|
|
|
events: self.events
|
|
|
|
});
|
|
|
|
deployManager.deployContracts(function() {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
2017-02-24 11:18:57 +00:00
|
|
|
self.events.on('file-event', function(fileType, path) {
|
|
|
|
if (fileType === 'contract' || fileType === 'config') {
|
2017-02-25 20:47:35 +00:00
|
|
|
self.config.reloadConfig();
|
|
|
|
deployManager.deployContracts(function() {});
|
2017-02-24 11:18:57 +00:00
|
|
|
}
|
2016-09-23 08:37:15 +00:00
|
|
|
});
|
2016-12-07 02:33:31 +00:00
|
|
|
},
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-02-25 20:47:35 +00:00
|
|
|
function watchFilesForChanges(callback) {
|
|
|
|
self.logger.setStatus("Watching for changes");
|
|
|
|
var watch = new Watch({logger: self.logger, events: self.events});
|
|
|
|
watch.start();
|
|
|
|
callback();
|
|
|
|
},
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-02-16 01:56:18 +00:00
|
|
|
function startAssetServer(callback) {
|
|
|
|
if (!options.runWebserver) {
|
|
|
|
return callback();
|
2016-12-07 02:33:31 +00:00
|
|
|
}
|
2017-02-16 01:56:18 +00:00
|
|
|
self.logger.setStatus("Starting Server");
|
|
|
|
var server = new Server({
|
|
|
|
logger: self.logger,
|
|
|
|
host: options.serverHost,
|
|
|
|
port: options.serverPort
|
|
|
|
});
|
|
|
|
server.start(callback);
|
2016-08-21 16:02:02 +00:00
|
|
|
}
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2016-08-21 16:02:02 +00:00
|
|
|
], function(err, result) {
|
2016-10-31 02:04:25 +00:00
|
|
|
if (err) {
|
|
|
|
self.logger.error(err.message);
|
|
|
|
}
|
2017-02-25 03:49:34 +00:00
|
|
|
done();
|
2016-08-21 15:02:50 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
build: function(env) {
|
2016-10-31 02:04:25 +00:00
|
|
|
var self = this;
|
2016-08-21 16:02:02 +00:00
|
|
|
async.waterfall([
|
2017-02-26 01:45:40 +00:00
|
|
|
function displayLoadedPlugins(callback) {
|
|
|
|
var pluginList = self.plugins.listPlugins();
|
|
|
|
if (pluginList.length > 0) {
|
|
|
|
self.logger.info("loaded plugins: " + pluginList.join(", "));
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
},
|
|
|
|
|
2016-08-21 16:02:02 +00:00
|
|
|
function deployAndGenerateABI(callback) {
|
2017-02-26 01:45:40 +00:00
|
|
|
var deployManager = new DeployManager({
|
|
|
|
config: Embark.config,
|
|
|
|
logger: Embark.logger,
|
|
|
|
plugins: self.plugins,
|
|
|
|
events: self.events
|
|
|
|
});
|
|
|
|
deployManager.deployContracts(function(error, abi) {
|
2016-08-21 16:02:02 +00:00
|
|
|
callback(null, abi);
|
|
|
|
});
|
|
|
|
},
|
2017-02-26 01:45:40 +00:00
|
|
|
|
2016-08-21 16:02:02 +00:00
|
|
|
function buildPipeline(abi, callback) {
|
2016-11-28 20:14:39 +00:00
|
|
|
self.logger.trace("Building Assets");
|
|
|
|
var pipeline = new Pipeline({
|
|
|
|
buildDir: self.config.buildDir,
|
|
|
|
contractsFiles: self.config.contractsFiles,
|
|
|
|
assetFiles: self.config.assetFiles,
|
2016-12-10 15:20:04 +00:00
|
|
|
logger: self.logger,
|
|
|
|
plugins: self.plugins
|
2016-11-28 20:14:39 +00:00
|
|
|
});
|
2017-02-26 01:45:40 +00:00
|
|
|
pipeline.build(abi);
|
2016-08-21 16:02:02 +00:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
], function(err, result) {
|
2016-10-31 02:04:25 +00:00
|
|
|
if (err) {
|
|
|
|
self.logger.error(err.message);
|
|
|
|
} else {
|
2017-02-26 03:39:40 +00:00
|
|
|
self.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
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-08-21 22:05:35 +00:00
|
|
|
initTests: function(options) {
|
|
|
|
return new Test(options);
|
2016-10-02 21:26:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// TODO: should deploy if it hasn't already
|
2017-01-08 01:37:48 +00:00
|
|
|
upload: function(platform) {
|
|
|
|
if (platform === 'ipfs') {
|
2017-02-10 12:44:06 +00:00
|
|
|
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') {
|
2017-02-10 12:44:06 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-02-18 13:01:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
};
|
2016-08-14 12:04:34 +00:00
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
module.exports = Embark;
|
2016-08-14 15:10:34 +00:00
|
|
|
|