mirror of https://github.com/embarklabs/embark.git
refactor deployment
This commit is contained in:
parent
4b119fffde
commit
d73eb802ea
|
@ -15,13 +15,14 @@ async.eachObject = asyncEachObject;
|
|||
|
||||
var Compiler = function(options) {
|
||||
this.plugins = options.plugins;
|
||||
this.logger = options.logger;
|
||||
};
|
||||
|
||||
Compiler.prototype.compile_contracts = function(contractFiles, cb) {
|
||||
|
||||
var available_compilers = {
|
||||
//".se": this.compile_serpent
|
||||
".sol": this.compile_solidity
|
||||
".sol": this.compile_solidity.bind(this)
|
||||
};
|
||||
|
||||
if (this.plugins) {
|
||||
|
@ -56,41 +57,56 @@ Compiler.prototype.compile_contracts = function(contractFiles, cb) {
|
|||
};
|
||||
|
||||
Compiler.prototype.compile_solidity = function(contractFiles, cb) {
|
||||
var self = this;
|
||||
var input = {};
|
||||
var solcW;
|
||||
async.waterfall([
|
||||
function prepareInput(callback) {
|
||||
for (var i = 0; i < contractFiles.length; i++){
|
||||
// TODO: this depends on the config
|
||||
var filename = contractFiles[i].filename.replace('app/contracts/','');
|
||||
input[filename] = contractFiles[i].content.toString();
|
||||
}
|
||||
callback();
|
||||
},
|
||||
function loadCompiler(callback) {
|
||||
// TODO: there ino need to load this twice
|
||||
self.logger.info("loading solc compiler..");
|
||||
solcW = new SolcW();
|
||||
solcW.load_compiler(function(){
|
||||
callback();
|
||||
});
|
||||
},
|
||||
function compileContracts(callback) {
|
||||
self.logger.info("compiling contracts...");
|
||||
solcW.compile({sources: input}, 1, function(output) {
|
||||
// TODO: check error is handled properly
|
||||
//if (output.errors) {
|
||||
// throw new Error ("Solidity errors: " + output.errors);
|
||||
//}
|
||||
callback(null, output);
|
||||
});
|
||||
},
|
||||
function createCompiledObject(output, callback) {
|
||||
var json = output.contracts;
|
||||
|
||||
for (var i = 0; i < contractFiles.length; i++){
|
||||
// TODO: this depends on the config
|
||||
var filename = contractFiles[i].filename.replace('app/contracts/','');
|
||||
input[filename] = contractFiles[i].content.toString();
|
||||
}
|
||||
compiled_object = {};
|
||||
|
||||
var solcW = new SolcW();
|
||||
console.log("loading solc..");
|
||||
var solc = solcW.load_compiler(function(){
|
||||
console.log("loaded solc");
|
||||
for (var className in json) {
|
||||
var contract = json[className];
|
||||
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.bytecode;
|
||||
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
|
||||
compiled_object[className].gasEstimates = contract.gasEstimates;
|
||||
compiled_object[className].functionHashes = contract.functionHashes;
|
||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||
}
|
||||
callback(null, compiled_object);
|
||||
}
|
||||
], function(err, result) {
|
||||
cb(result);
|
||||
});
|
||||
var output = solc.compile({sources: input}, 1);
|
||||
|
||||
if (output.errors) {
|
||||
throw new Error ("Solidity errors: " + output.errors);
|
||||
}
|
||||
|
||||
var json = output.contracts;
|
||||
|
||||
compiled_object = {};
|
||||
|
||||
for (var className in json) {
|
||||
var contract = json[className];
|
||||
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.bytecode;
|
||||
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
|
||||
compiled_object[className].gasEstimates = contract.gasEstimates;
|
||||
compiled_object[className].functionHashes = contract.functionHashes;
|
||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||
}
|
||||
|
||||
cb(compiled_object);
|
||||
};
|
||||
|
||||
module.exports = Compiler;
|
||||
|
|
|
@ -39,7 +39,7 @@ ContractsManager.prototype.build = function(done) {
|
|||
var self = this;
|
||||
async.waterfall([
|
||||
function compileContracts(callback) {
|
||||
var compiler = new Compiler({plugins: self.plugins});
|
||||
var compiler = new Compiler({plugins: self.plugins, logger: self.logger});
|
||||
// TODO: check if try is still needed
|
||||
//try {
|
||||
compiler.compile_contracts(self.contractFiles, function(compiledObject) {
|
||||
|
|
|
@ -15,7 +15,7 @@ var DeployManager = function(options) {
|
|||
DeployManager.prototype.deployContracts = function(done) {
|
||||
var self = this;
|
||||
async.waterfall([
|
||||
function buildContracts(callback) {
|
||||
function buildContracts(callback) {
|
||||
var contractsManager = new ContractsManager({
|
||||
contractFiles: self.config.contractsFiles,
|
||||
contractsConfig: self.config.contractsConfig,
|
||||
|
@ -57,6 +57,7 @@ DeployManager.prototype.deployContracts = function(done) {
|
|||
});
|
||||
deploy.deployAll(function() {
|
||||
callback(null, contractsManager);
|
||||
self.events.emit('contractsDeployed');
|
||||
});
|
||||
});
|
||||
},
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
var solc;
|
||||
|
||||
process.on('message', function(msg) {
|
||||
if (msg.action === 'loadCompiler') {
|
||||
solc = require('solc');
|
||||
process.send({result: "loadedCompiler"});
|
||||
}
|
||||
|
||||
if (msg.action === 'compile') {
|
||||
var output = solc.compile(msg.obj, msg.optimize);
|
||||
process.send({result: "compilation", output: output});
|
||||
}
|
||||
});
|
||||
|
|
@ -1,11 +1,26 @@
|
|||
var solcProcess = require('child_process').fork(__dirname + '/solcP.js');
|
||||
|
||||
var SolcW = function() {
|
||||
};
|
||||
|
||||
SolcW.prototype.load_compiler = function(done) {
|
||||
var solc = require('solc');
|
||||
done();
|
||||
return solc;
|
||||
solcProcess.on('message', function(msg) {
|
||||
if (msg.result !== 'loadedCompiler') {
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
solcProcess.send({action: 'loadCompiler'});
|
||||
};
|
||||
|
||||
SolcW.prototype.compile = function(obj, optimize, done) {
|
||||
solcProcess.on('message', function(msg) {
|
||||
if (msg.result !== 'compilation') {
|
||||
return;
|
||||
}
|
||||
done(msg.output);
|
||||
});
|
||||
solcProcess.send({action: 'compile', obj, optimize});
|
||||
};
|
||||
|
||||
module.exports = SolcW;
|
||||
|
|
144
lib/index.js
144
lib/index.js
|
@ -60,60 +60,54 @@ var Embark = {
|
|||
templateGenerator.generate(destinationFolder, name);
|
||||
},
|
||||
|
||||
redeploy: function(env) {
|
||||
var self = this;
|
||||
async.waterfall([
|
||||
function reloadFiles(callback) {
|
||||
self.config.reloadConfig();
|
||||
callback();
|
||||
},
|
||||
self.buildDeployGenerate.bind(self),
|
||||
function buildPipeline(abi, callback) {
|
||||
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
|
||||
});
|
||||
pipeline.build(abi);
|
||||
callback();
|
||||
}
|
||||
], function(err, result) {
|
||||
if (err) {
|
||||
self.logger.error(err.message);
|
||||
} else {
|
||||
self.logger.trace("finished".underline);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
run: function(options) {
|
||||
var self = this;
|
||||
var env = options.env;
|
||||
async.waterfall([
|
||||
function welcome(callback) {
|
||||
if (!options.useDashboard) {
|
||||
console.log('========================'.bold.green);
|
||||
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
|
||||
console.log('========================'.bold.green);
|
||||
}
|
||||
callback();
|
||||
},
|
||||
|
||||
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) {
|
||||
if (!options.useDashboard) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
Embark.dashboard = new Dashboard({
|
||||
var dashboard = new Dashboard({
|
||||
logger: Embark.logger,
|
||||
plugins: self.plugins,
|
||||
version: self.version,
|
||||
env: env
|
||||
});
|
||||
Embark.dashboard.start(callback);
|
||||
dashboard.start(function() {
|
||||
self.events.on('abi-vanila', function(abi) {
|
||||
dashboard.console.runCode(abi);
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
},
|
||||
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([
|
||||
function displayLoadedPlugins(callback) {
|
||||
var pluginList = self.plugins.listPlugins();
|
||||
if (pluginList.length > 0) {
|
||||
|
@ -121,11 +115,12 @@ var Embark = {
|
|||
}
|
||||
callback();
|
||||
},
|
||||
// can be done in paralell
|
||||
function monitorServices(callback) {
|
||||
if (!options.useDashboard) {
|
||||
return callback();
|
||||
}
|
||||
Embark.servicesMonitor = new ServicesMonitor({
|
||||
var servicesMonitor = new ServicesMonitor({
|
||||
logger: Embark.logger,
|
||||
config: Embark.config,
|
||||
serverHost: options.serverHost,
|
||||
|
@ -133,9 +128,10 @@ var Embark = {
|
|||
runWebserver: options.runWebserver,
|
||||
version: Embark.version
|
||||
});
|
||||
Embark.servicesMonitor.startMonitor();
|
||||
servicesMonitor.startMonitor();
|
||||
callback();
|
||||
},
|
||||
|
||||
function deploy(callback) {
|
||||
var deployManager = new DeployManager({
|
||||
config: Embark.config,
|
||||
|
@ -143,14 +139,13 @@ var Embark = {
|
|||
plugins: self.plugins,
|
||||
events: self.events
|
||||
});
|
||||
deployManager.deployContracts(function(abi) {
|
||||
callback(null, abi);
|
||||
deployManager.deployContracts(function() {
|
||||
callback();
|
||||
});
|
||||
//if (Embark.dashboard) {
|
||||
// Embark.dashboard.console.runCode(consoleABI);
|
||||
//}
|
||||
},
|
||||
function buildPipeline(abi, callback) {
|
||||
|
||||
|
||||
function buildPipeline(callback) {
|
||||
self.logger.setStatus("Building Assets");
|
||||
var pipeline = new Pipeline({
|
||||
buildDir: self.config.buildDir,
|
||||
|
@ -159,10 +154,12 @@ var Embark = {
|
|||
logger: self.logger,
|
||||
plugins: self.plugins
|
||||
});
|
||||
// TODO: do this with event instead
|
||||
pipeline.build(abi);
|
||||
self.events.on('abi', function(abi) {
|
||||
pipeline.build(abi);
|
||||
});
|
||||
callback();
|
||||
},
|
||||
|
||||
function watchFilesForChanges(callback) {
|
||||
self.logger.setStatus("Watching for changes");
|
||||
var watch = new Watch({logger: self.logger, events: self.events});
|
||||
|
@ -183,6 +180,9 @@ var Embark = {
|
|||
});
|
||||
callback();
|
||||
},
|
||||
|
||||
|
||||
|
||||
function startAssetServer(callback) {
|
||||
if (!options.runWebserver) {
|
||||
return callback();
|
||||
|
@ -195,6 +195,8 @@ var Embark = {
|
|||
});
|
||||
server.start(callback);
|
||||
}
|
||||
|
||||
|
||||
], function(err, result) {
|
||||
if (err) {
|
||||
self.logger.error(err.message);
|
||||
|
@ -203,6 +205,7 @@ var Embark = {
|
|||
self.logger.info("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
|
||||
self.logger.info("Ready".underline);
|
||||
}
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -237,47 +240,6 @@ var Embark = {
|
|||
});
|
||||
},
|
||||
|
||||
deploy: function(done) {
|
||||
var self = this;
|
||||
async.waterfall([
|
||||
function buildAndDeploy(callback) {
|
||||
Embark.buildAndDeploy(function(err, contractsManager) {
|
||||
callback(err, contractsManager);
|
||||
});
|
||||
},
|
||||
function generateABI(contractsManager, callback) {
|
||||
}
|
||||
], function(err, result) {
|
||||
if (err) {
|
||||
self.logger.error(err.message);
|
||||
}
|
||||
done(result);
|
||||
});
|
||||
},
|
||||
|
||||
buildDeployGenerate: function(done) {
|
||||
var self = this;
|
||||
|
||||
self.logger.setStatus("Deploying...".magenta.underline);
|
||||
async.waterfall([
|
||||
function generateConsoleABI(contractsManager, callback) {
|
||||
// through a listener
|
||||
callback(null, contractsManager);
|
||||
},
|
||||
function generateABI(contractsManager, callback) {
|
||||
}
|
||||
], function(err, result) {
|
||||
if (err) {
|
||||
self.logger.error("error deploying");
|
||||
self.logger.error(err.message);
|
||||
self.logger.setStatus("Deployment Error".red);
|
||||
} else {
|
||||
self.logger.setStatus("Ready".green);
|
||||
}
|
||||
done(null, result);
|
||||
});
|
||||
},
|
||||
|
||||
initTests: function(options) {
|
||||
return new Test(options);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue