Merge pull request #415 from embark-framework/features/cargo

Add a cargo to not run file write for each file
This commit is contained in:
Iuri Matias 2018-05-15 18:01:25 -04:00 committed by GitHub
commit 256276c884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 24 deletions

View File

@ -146,16 +146,9 @@ class Engine {
plugins: this.plugins
});
const queue = async.queue((task, callback) => {
pipeline.build(task.abi, task.contractsJSON, task.path, callback);
}, 1);
this.events.on('code-generator-ready', function () {
self.events.request('code', function (abi, contractsJSON) {
self.currentAbi = abi;
self.contractsJSON = contractsJSON;
queue.push({abi, contractsJSON, path: null}, () => {
pipeline.build(abi, contractsJSON, null, () => {
if (self.watch) {
self.watch.restart(); // Necessary because changing a file while it is writing can stop it from being watched
}
@ -168,7 +161,7 @@ class Engine {
codeGeneratorService(_options) {
let self = this;
let generateCode = function (contractsManager) {
const generateCode = function (contractsManager) {
let codeGenerator = new CodeGenerator({
blockchainConfig: self.config.blockchainConfig,
contractsConfig: self.config.contractsConfig,
@ -183,9 +176,17 @@ class Engine {
self.events.emit('code-generator-ready');
});
};
this.events.on('contractsDeployed', generateCode);
this.events.on('blockchainDisabled', generateCode);
this.events.on('asset-changed', generateCode);
const cargo = async.cargo((tasks, callback) => {
generateCode(tasks[tasks.length - 1].contractsManager);
self.events.once('outputDone', callback);
});
const addToCargo = function (contractsManager) {
cargo.push({contractsManager});
};
this.events.on('contractsDeployed', addToCargo);
this.events.on('blockchainDisabled', addToCargo);
this.events.on('asset-changed', addToCargo);
}
deploymentService(options) {
@ -223,18 +224,22 @@ class Engine {
});
this.events.on('file-event', function (fileType) {
// TODO: still need to redeploy contracts because the original contracts
// config is being corrupted
if (fileType === 'asset') {
self.events.emit('asset-changed', self.contractsManager);
}
// TODO: for now need to deploy on asset chanes as well
// because the contractsManager config is corrupted after a deploy
if (fileType === 'contract' || fileType === 'config') {
self.config.reloadConfig();
self.deployManager.deployContracts(function () {
});
}
clearTimeout(self.fileTimeout);
self.fileTimeout = setTimeout(() => {
// TODO: still need to redeploy contracts because the original contracts
// config is being corrupted
if (fileType === 'asset') {
// Throttle file changes so we re-write only once for all files
self.events.emit('asset-changed', self.contractsManager);
}
// TODO: for now need to deploy on asset changes as well
// because the contractsManager config is corrupted after a deploy
if (fileType === 'contract' || fileType === 'config') {
self.config.reloadConfig();
self.deployManager.deployContracts(function () {
});
}
}, 50);
});
}