mirror of https://github.com/embarklabs/embark.git
refactor(@embark/cmd-controller): re add cargo for file watcher (#1855)
* refactor(@embark/cmd-controller): re add cargo for file watcher (cherry picked from commit 5c77b4000742a14f42a6dc5c145672b9cd0957a3) * use generate:all instea dof the event
This commit is contained in:
parent
8716373be2
commit
b260e81055
|
@ -1,4 +1,4 @@
|
|||
import {BlockchainClient, Simulator} from 'embark-blockchain-process';
|
||||
import {Simulator} from 'embark-blockchain-process';
|
||||
import {__} from 'embark-i18n';
|
||||
import {dappPath, embarkPath} from 'embark-utils';
|
||||
import findUp from 'find-up';
|
||||
|
@ -174,12 +174,6 @@ class EmbarkController {
|
|||
engine.registerModuleGroup("namesystem");
|
||||
engine.registerModulePackage('embark-deploy-tracker', {plugins: engine.plugins});
|
||||
|
||||
engine.events.on('deployment:deployContracts:afterAll', () => {
|
||||
engine.events.request('pipeline:generateAll', () => {
|
||||
engine.events.emit('outputDone');
|
||||
});
|
||||
});
|
||||
|
||||
const plugin = engine.plugins.createPlugin('cmdcontrollerplugin', {});
|
||||
plugin.registerActionForEvent("embark:engine:started", async (_params, cb) => {
|
||||
try {
|
||||
|
@ -196,8 +190,6 @@ class EmbarkController {
|
|||
cb();
|
||||
});
|
||||
|
||||
engine.events.request('watcher:start');
|
||||
|
||||
engine.events.on('check:backOnline:Ethereum', function () {
|
||||
engine.logger.info(__('Ethereum node detected') + '..');
|
||||
// TODO: deploy contracts, etc...
|
||||
|
@ -209,36 +201,14 @@ class EmbarkController {
|
|||
engine.events.emit("status", __("Ready").green);
|
||||
});
|
||||
|
||||
engine.events.on('file-event', async ({fileType, path}) => {
|
||||
// TODO: re-add async.cargo / or use rxjs to use latest request in the queue
|
||||
|
||||
if (fileType === 'contract' || fileType === 'config') {
|
||||
try {
|
||||
await compileAndDeploySmartContracts(engine);
|
||||
} catch (err) {
|
||||
engine.logger.error(err);
|
||||
}
|
||||
} else if (fileType === 'asset') {
|
||||
engine.events.request('pipeline:generateAll', () => {
|
||||
engine.events.emit('outputDone');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
engine.startEngine(async () => {
|
||||
callback();
|
||||
|
||||
engine.events.request("webserver:start")
|
||||
engine.events.request("webserver:start");
|
||||
|
||||
try {
|
||||
let contractsFiles = await engine.events.request2("config:contractsFiles");
|
||||
let compiledContracts = await engine.events.request2("compiler:contracts:compile", contractsFiles);
|
||||
let _contractsConfig = await engine.events.request2("config:contractsConfig");
|
||||
let contractsConfig = cloneDeep(_contractsConfig);
|
||||
let [contractsList, contractDependencies] = await engine.events.request2("contracts:build", contractsConfig, compiledContracts);
|
||||
await engine.events.request2("deployment:contracts:deploy", contractsList, contractDependencies);
|
||||
|
||||
await engine.events.request2("watcher:start");
|
||||
await compileAndDeploySmartContracts(engine);
|
||||
await setupCargoAndWatcher(engine);
|
||||
} catch (e) {
|
||||
engine.logger.error(__('Error building and deploying'), e);
|
||||
}
|
||||
|
@ -574,25 +544,14 @@ class EmbarkController {
|
|||
engine.events.emit("status", __("Ready").green);
|
||||
});
|
||||
|
||||
engine.events.on('file-event', async ({ fileType, path }) => {
|
||||
if (fileType === 'contract' || fileType === 'config') {
|
||||
try {
|
||||
await compileAndDeploySmartContracts(engine);
|
||||
} catch (e) {
|
||||
engine.logger.error(e);
|
||||
}
|
||||
} else if (fileType === 'asset') {
|
||||
engine.events.request('pipeline:generateAll', () => engine.events.emit('outputDone'));
|
||||
}
|
||||
});
|
||||
|
||||
engine.startEngine(async () => {
|
||||
try {
|
||||
await compileAndDeploySmartContracts(engine);
|
||||
await setupCargoAndWatcher(engine);
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
engine.events.request2("watcher:start")
|
||||
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
@ -959,5 +918,34 @@ async function compileAndDeploySmartContracts(engine) {
|
|||
let _contractsConfig = await engine.events.request2("config:contractsConfig");
|
||||
let contractsConfig = cloneDeep(_contractsConfig);
|
||||
let [contractsList, contractDependencies] = await engine.events.request2("contracts:build", contractsConfig, compiledContracts);
|
||||
return await engine.events.request2("deployment:contracts:deploy", contractsList, contractDependencies);
|
||||
await engine.events.request2("deployment:contracts:deploy", contractsList, contractDependencies);
|
||||
await engine.events.request2('pipeline:generateAll');
|
||||
engine.events.emit('outputDone');
|
||||
}
|
||||
|
||||
async function setupCargoAndWatcher(engine) {
|
||||
const cargo = async.cargo(async (tasks) => {
|
||||
if (tasks.includes('contract') || tasks.includes('config')) {
|
||||
try {
|
||||
return await compileAndDeploySmartContracts(engine);
|
||||
} catch (err) {
|
||||
engine.logger.error(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await engine.events.request2('pipeline:generateAll');
|
||||
engine.events.emit('outputDone');
|
||||
});
|
||||
|
||||
let fileTimeout;
|
||||
engine.events.on('file-event', ({fileType, _path}) => {
|
||||
clearTimeout(fileTimeout);
|
||||
// Throttle file changes so we re-write only once for all files
|
||||
fileTimeout = setTimeout(async () => {
|
||||
cargo.push(fileType);
|
||||
}, 50);
|
||||
});
|
||||
|
||||
await engine.events.request2("watcher:start");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue