mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-17 01:37:26 +00:00
refactor deployment
This commit is contained in:
parent
4b119fffde
commit
d73eb802ea
@ -15,13 +15,14 @@ async.eachObject = asyncEachObject;
|
|||||||
|
|
||||||
var Compiler = function(options) {
|
var Compiler = function(options) {
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
|
this.logger = options.logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.prototype.compile_contracts = function(contractFiles, cb) {
|
Compiler.prototype.compile_contracts = function(contractFiles, cb) {
|
||||||
|
|
||||||
var available_compilers = {
|
var available_compilers = {
|
||||||
//".se": this.compile_serpent
|
//".se": this.compile_serpent
|
||||||
".sol": this.compile_solidity
|
".sol": this.compile_solidity.bind(this)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.plugins) {
|
if (this.plugins) {
|
||||||
@ -56,25 +57,37 @@ Compiler.prototype.compile_contracts = function(contractFiles, cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Compiler.prototype.compile_solidity = function(contractFiles, cb) {
|
Compiler.prototype.compile_solidity = function(contractFiles, cb) {
|
||||||
|
var self = this;
|
||||||
var input = {};
|
var input = {};
|
||||||
|
var solcW;
|
||||||
|
async.waterfall([
|
||||||
|
function prepareInput(callback) {
|
||||||
for (var i = 0; i < contractFiles.length; i++){
|
for (var i = 0; i < contractFiles.length; i++){
|
||||||
// TODO: this depends on the config
|
// TODO: this depends on the config
|
||||||
var filename = contractFiles[i].filename.replace('app/contracts/','');
|
var filename = contractFiles[i].filename.replace('app/contracts/','');
|
||||||
input[filename] = contractFiles[i].content.toString();
|
input[filename] = contractFiles[i].content.toString();
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
var solcW = new SolcW();
|
},
|
||||||
console.log("loading solc..");
|
function loadCompiler(callback) {
|
||||||
var solc = solcW.load_compiler(function(){
|
// TODO: there ino need to load this twice
|
||||||
console.log("loaded solc");
|
self.logger.info("loading solc compiler..");
|
||||||
|
solcW = new SolcW();
|
||||||
|
solcW.load_compiler(function(){
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
var output = solc.compile({sources: input}, 1);
|
},
|
||||||
|
function compileContracts(callback) {
|
||||||
if (output.errors) {
|
self.logger.info("compiling contracts...");
|
||||||
throw new Error ("Solidity errors: " + output.errors);
|
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;
|
var json = output.contracts;
|
||||||
|
|
||||||
compiled_object = {};
|
compiled_object = {};
|
||||||
@ -89,8 +102,11 @@ Compiler.prototype.compile_solidity = function(contractFiles, cb) {
|
|||||||
compiled_object[className].functionHashes = contract.functionHashes;
|
compiled_object[className].functionHashes = contract.functionHashes;
|
||||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||||
}
|
}
|
||||||
|
callback(null, compiled_object);
|
||||||
cb(compiled_object);
|
}
|
||||||
|
], function(err, result) {
|
||||||
|
cb(result);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Compiler;
|
module.exports = Compiler;
|
||||||
|
@ -39,7 +39,7 @@ ContractsManager.prototype.build = function(done) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function compileContracts(callback) {
|
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
|
// TODO: check if try is still needed
|
||||||
//try {
|
//try {
|
||||||
compiler.compile_contracts(self.contractFiles, function(compiledObject) {
|
compiler.compile_contracts(self.contractFiles, function(compiledObject) {
|
||||||
|
@ -57,6 +57,7 @@ DeployManager.prototype.deployContracts = function(done) {
|
|||||||
});
|
});
|
||||||
deploy.deployAll(function() {
|
deploy.deployAll(function() {
|
||||||
callback(null, contractsManager);
|
callback(null, contractsManager);
|
||||||
|
self.events.emit('contractsDeployed');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
14
lib/contracts/solcP.js
Normal file
14
lib/contracts/solcP.js
Normal file
@ -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() {
|
var SolcW = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
SolcW.prototype.load_compiler = function(done) {
|
SolcW.prototype.load_compiler = function(done) {
|
||||||
var solc = require('solc');
|
solcProcess.on('message', function(msg) {
|
||||||
|
if (msg.result !== 'loadedCompiler') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
return solc;
|
});
|
||||||
|
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;
|
module.exports = SolcW;
|
||||||
|
132
lib/index.js
132
lib/index.js
@ -60,60 +60,54 @@ var Embark = {
|
|||||||
templateGenerator.generate(destinationFolder, name);
|
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) {
|
run: function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var env = options.env;
|
var env = options.env;
|
||||||
async.waterfall([
|
|
||||||
function welcome(callback) {
|
|
||||||
if (!options.useDashboard) {
|
if (!options.useDashboard) {
|
||||||
console.log('========================'.bold.green);
|
console.log('========================'.bold.green);
|
||||||
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
|
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
|
||||||
console.log('========================'.bold.green);
|
console.log('========================'.bold.green);
|
||||||
}
|
}
|
||||||
callback();
|
|
||||||
},
|
async.parallel([
|
||||||
function startDashboard(callback) {
|
function startDashboard(callback) {
|
||||||
if (!options.useDashboard) {
|
if (!options.useDashboard) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
Embark.dashboard = new Dashboard({
|
var dashboard = new Dashboard({
|
||||||
logger: Embark.logger,
|
logger: Embark.logger,
|
||||||
plugins: self.plugins,
|
plugins: self.plugins,
|
||||||
version: self.version,
|
version: self.version,
|
||||||
env: env
|
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) {
|
function displayLoadedPlugins(callback) {
|
||||||
var pluginList = self.plugins.listPlugins();
|
var pluginList = self.plugins.listPlugins();
|
||||||
if (pluginList.length > 0) {
|
if (pluginList.length > 0) {
|
||||||
@ -121,11 +115,12 @@ var Embark = {
|
|||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
|
// can be done in paralell
|
||||||
function monitorServices(callback) {
|
function monitorServices(callback) {
|
||||||
if (!options.useDashboard) {
|
if (!options.useDashboard) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
Embark.servicesMonitor = new ServicesMonitor({
|
var servicesMonitor = new ServicesMonitor({
|
||||||
logger: Embark.logger,
|
logger: Embark.logger,
|
||||||
config: Embark.config,
|
config: Embark.config,
|
||||||
serverHost: options.serverHost,
|
serverHost: options.serverHost,
|
||||||
@ -133,9 +128,10 @@ var Embark = {
|
|||||||
runWebserver: options.runWebserver,
|
runWebserver: options.runWebserver,
|
||||||
version: Embark.version
|
version: Embark.version
|
||||||
});
|
});
|
||||||
Embark.servicesMonitor.startMonitor();
|
servicesMonitor.startMonitor();
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
|
|
||||||
function deploy(callback) {
|
function deploy(callback) {
|
||||||
var deployManager = new DeployManager({
|
var deployManager = new DeployManager({
|
||||||
config: Embark.config,
|
config: Embark.config,
|
||||||
@ -143,14 +139,13 @@ var Embark = {
|
|||||||
plugins: self.plugins,
|
plugins: self.plugins,
|
||||||
events: self.events
|
events: self.events
|
||||||
});
|
});
|
||||||
deployManager.deployContracts(function(abi) {
|
deployManager.deployContracts(function() {
|
||||||
callback(null, abi);
|
callback();
|
||||||
});
|
});
|
||||||
//if (Embark.dashboard) {
|
|
||||||
// Embark.dashboard.console.runCode(consoleABI);
|
|
||||||
//}
|
|
||||||
},
|
},
|
||||||
function buildPipeline(abi, callback) {
|
|
||||||
|
|
||||||
|
function buildPipeline(callback) {
|
||||||
self.logger.setStatus("Building Assets");
|
self.logger.setStatus("Building Assets");
|
||||||
var pipeline = new Pipeline({
|
var pipeline = new Pipeline({
|
||||||
buildDir: self.config.buildDir,
|
buildDir: self.config.buildDir,
|
||||||
@ -159,10 +154,12 @@ var Embark = {
|
|||||||
logger: self.logger,
|
logger: self.logger,
|
||||||
plugins: self.plugins
|
plugins: self.plugins
|
||||||
});
|
});
|
||||||
// TODO: do this with event instead
|
self.events.on('abi', function(abi) {
|
||||||
pipeline.build(abi);
|
pipeline.build(abi);
|
||||||
|
});
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
|
|
||||||
function watchFilesForChanges(callback) {
|
function watchFilesForChanges(callback) {
|
||||||
self.logger.setStatus("Watching for changes");
|
self.logger.setStatus("Watching for changes");
|
||||||
var watch = new Watch({logger: self.logger, events: self.events});
|
var watch = new Watch({logger: self.logger, events: self.events});
|
||||||
@ -183,6 +180,9 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function startAssetServer(callback) {
|
function startAssetServer(callback) {
|
||||||
if (!options.runWebserver) {
|
if (!options.runWebserver) {
|
||||||
return callback();
|
return callback();
|
||||||
@ -195,6 +195,8 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
server.start(callback);
|
server.start(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.error(err.message);
|
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("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
|
||||||
self.logger.info("Ready".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) {
|
initTests: function(options) {
|
||||||
return new Test(options);
|
return new Test(options);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user