embark/lib/index.js

139 lines
4.0 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');
2016-08-14 12:04:34 +00:00
var Web3 = require('web3');
2016-08-14 14:34:42 +00:00
var fs = require('fs');
var grunt = require('grunt');
var mkdirp = require('mkdirp');
2016-08-14 15:10:34 +00:00
var colors = require('colors');
2016-08-14 16:26:49 +00:00
var chokidar = require('chokidar');
2016-08-14 12:04:34 +00:00
2016-08-18 00:29:41 +00:00
var Cmd = require('./cmd.js');
2016-08-14 12:04:34 +00:00
var Deploy = require('./deploy.js');
var ContractsManager = require('./contracts.js');
var ABIGenerator = require('./abi.js');
var TemplateGenerator = require('./template_generator.js');
var Blockchain = require('./blockchain.js');
2016-08-21 15:24:57 +00:00
var Server = require('./server.js');
var Watch = require('./watch.js');
2016-08-21 16:02:02 +00:00
var Pipeline = require('./pipeline.js');
2016-08-21 22:05:35 +00:00
var Test = require('./test.js');
2016-08-22 03:40:05 +00:00
var Logger = require('./logger.js');
var Config = require('./config.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
process: function(args) {
var cmd = new Cmd(Embark);
cmd.process(args);
},
generateTemplate: function(templateName, destinationFolder, name) {
var templateGenerator = new TemplateGenerator(templateName);
templateGenerator.generate(destinationFolder, name);
},
2016-08-22 03:40:05 +00:00
initConfig: function(env, options) {
this.config = new Config(env);
this.config.loadConfigFiles(options);
//this.contractsManager = new ContractsManager(configDir, files, env);
//this.contractsManager.init();
//return this.contractsManager;
2016-08-14 12:04:34 +00:00
},
2016-08-14 14:34:42 +00:00
2016-08-21 15:02:50 +00:00
run: function(env) {
2016-08-22 03:40:05 +00:00
var self = this;
2016-08-21 16:02:02 +00:00
async.waterfall([
function deployAndGenerateABI(callback) {
Embark.deploy(function(abi) {
callback(null, abi);
});
},
function buildPipeline(abi, callback) {
2016-08-22 03:40:05 +00:00
var pipeline = new Pipeline({
buildDir: self.config.buildDir,
contractsFiles: self.config.contractsFiles,
assetFiles: self.config.assetFiles
});
2016-08-21 16:02:02 +00:00
pipeline.build(abi);
callback();
},
function startAssetServer(callback) {
var server = new Server({});
server.start(callback);
},
function watchFilesForChanges(callback) {
2016-08-21 15:24:57 +00:00
var watch = new Watch();
watch.start();
2016-08-21 16:02:02 +00:00
callback();
}
], function(err, result) {
console.log("finished".underline);
2016-08-21 15:02:50 +00:00
});
},
build: function(env) {
2016-08-21 16:02:02 +00:00
async.waterfall([
function deployAndGenerateABI(callback) {
Embark.deploy(function(abi) {
callback(null, abi);
});
},
function buildPipeline(abi, callback) {
var pipeline = new Pipeline({});
pipeline.build(abi);
callback();
}
], function(err, result) {
console.log("finished".underline);
2016-08-21 15:02:50 +00:00
});
},
blockchain: function(env, client) {
var blockchain = Blockchain(this.config.blockchainConfig, client);
2016-08-21 15:02:50 +00:00
blockchain.run({env: env});
},
2016-08-18 00:29:41 +00:00
deploy: function(done) {
2016-08-22 03:40:05 +00:00
var self = this;
2016-08-14 14:34:42 +00:00
async.waterfall([
2016-08-22 03:40:05 +00:00
function buildContracts(callback) {
var contractsManager = new ContractsManager({
contractFiles: self.config.contractsFiles,
contractsConfig: self.config.contractsConfig
});
contractsManager.init();
2016-08-21 16:02:02 +00:00
contractsManager.build();
2016-08-14 14:34:42 +00:00
callback(null, contractsManager);
2016-08-21 16:02:02 +00:00
},
function deployContracts(contractsManager, callback) {
//TODO: figure out where to put this since the web3 can be passed along if needed
// perhaps it should go into the deploy object itself
2016-08-21 16:02:02 +00:00
var web3 = new Web3();
var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort;
web3.setProvider(new web3.providers.HttpProvider(web3Endpoint));
2016-08-21 16:02:02 +00:00
var deploy = new Deploy(web3, contractsManager);
deploy.deployAll(function() {
callback(null, contractsManager);
});
},
function generateABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager);
2016-08-21 16:02:02 +00:00
callback(null, abiGenerator.generateABI());
},
2016-08-14 14:34:42 +00:00
], function(err, result) {
2016-08-18 00:29:41 +00:00
done(result);
2016-08-14 12:04:34 +00:00
});
2016-08-21 22:05:35 +00:00
},
initTests: function(options) {
return new Test(options);
2016-08-14 14:34:42 +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