diff --git a/lib/contracts/compiler.js b/lib/contracts/compiler.js index 5dfb6c6ee..4f9b1cc2c 100644 --- a/lib/contracts/compiler.js +++ b/lib/contracts/compiler.js @@ -71,11 +71,15 @@ Compiler.prototype.compile_solidity = function(contractFiles, cb) { }, function loadCompiler(callback) { // TODO: there ino need to load this twice - self.logger.info("loading solc compiler.."); solcW = new SolcW(); - solcW.load_compiler(function(){ + if (solcW.isCompilerLoaded()) { callback(); - }); + } else { + self.logger.info("loading solc compiler.."); + solcW.load_compiler(function(){ + callback(); + }); + } }, function compileContracts(callback) { self.logger.info("compiling contracts..."); diff --git a/lib/contracts/solcW.js b/lib/contracts/solcW.js index 62804094c..8c9b05233 100644 --- a/lib/contracts/solcW.js +++ b/lib/contracts/solcW.js @@ -1,20 +1,27 @@ var solcProcess = require('child_process').fork(__dirname + '/solcP.js'); +var compilerLoaded = false; var SolcW = function() { }; SolcW.prototype.load_compiler = function(done) { - solcProcess.on('message', function(msg) { + if (compilerLoaded) { done(); } + solcProcess.once('message', function(msg) { if (msg.result !== 'loadedCompiler') { return; } + compilerLoaded = true; done(); }); solcProcess.send({action: 'loadCompiler'}); }; +SolcW.prototype.isCompilerLoaded = function() { + return (compilerLoaded === true); +} + SolcW.prototype.compile = function(obj, optimize, done) { - solcProcess.on('message', function(msg) { + solcProcess.once('message', function(msg) { if (msg.result !== 'compilation') { return; } diff --git a/lib/core/core.js b/lib/core/core.js new file mode 100644 index 000000000..424eda08c --- /dev/null +++ b/lib/core/core.js @@ -0,0 +1,5 @@ + +var Core = function() {}; + +module.exports = Core; + diff --git a/lib/index.js b/lib/index.js index 439b8ee27..a7bb06d6d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -115,6 +115,7 @@ var Embark = { } callback(); }, + // can be done in paralell function monitorServices(callback) { if (!options.useDashboard) { @@ -132,18 +133,6 @@ var Embark = { callback(); }, - function deploy(callback) { - var deployManager = new DeployManager({ - config: Embark.config, - logger: Embark.logger, - plugins: self.plugins, - events: self.events - }); - deployManager.deployContracts(function() { - callback(); - }); - }, - function buildPipeline(callback) { self.logger.setStatus("Building Assets"); @@ -160,29 +149,41 @@ var Embark = { callback(); }, + function deploy(callback) { + var deployManager = new DeployManager({ + config: Embark.config, + logger: Embark.logger, + plugins: self.plugins, + events: self.events + }); + deployManager.deployContracts(function() { + callback(); + }); + + self.events.on('file-event', function(fileType, path) { + if (fileType === 'contract' || fileType === 'config') { + self.config.reloadConfig(); + deployManager.deployContracts(function() {}); + } + }); + self.events.on('file-event', function(fileType, path) { + if (fileType === 'asset') { + // TODO: can just rebuild pipeline, no need to deploy contracts + // again + self.config.reloadConfig(); + deployManager.deployContracts(function() {}); + } + }); + }, + function watchFilesForChanges(callback) { self.logger.setStatus("Watching for changes"); var watch = new Watch({logger: self.logger, events: self.events}); watch.start(); - self.events.on('file-event', function(fileType, path) { - if (fileType === 'contract' || fileType === 'config') { - self.logger.info("received redeploy event"); - //Embark.redeploy(); - } - }); - self.events.on('rebuildAssets', function(fileType, path) { - if (fileType === 'asset') { - self.logger.info("received rebuildAssets event"); - // TODO: can just rebuild pipeline, no need to deploy contracts - // again - //Embark.redeploy(); - } - }); callback(); }, - function startAssetServer(callback) { if (!options.runWebserver) { return callback(); diff --git a/test_app/app/contracts/token.sol b/test_app/app/contracts/token.sol index 9d5c34f8f..0eff9e71b 100644 --- a/test_app/app/contracts/token.sol +++ b/test_app/app/contracts/token.sol @@ -9,6 +9,7 @@ contract Token { mapping( address => uint ) _balances; mapping( address => mapping( address => uint ) ) _approvals; uint public _supply; + //uint public _supply2; function Token( uint initial_balance ) { _balances[msg.sender] = initial_balance; _supply = initial_balance;