fix(@embark/deployment): ensure logger is available in all hooks

This commit is contained in:
Pascal Precht 2019-04-16 15:19:49 +02:00 committed by Pascal Precht
parent 72fc80df53
commit 42aebb92fd
1 changed files with 17 additions and 6 deletions

View File

@ -100,7 +100,8 @@ class SpecialConfigs {
return cb(); return cb();
} }
try { try {
await beforeDeployFn(); const logger = this.createLoggerWithPrefix('beforeDeploy >');
await beforeDeployFn({ logger });
cb(); cb();
} catch (err) { } catch (err) {
cb(new Error(`Error running beforeDeploy hook: ${err.message}`)); cb(new Error(`Error running beforeDeploy hook: ${err.message}`));
@ -163,7 +164,10 @@ class SpecialConfigs {
return cb(); return cb();
} }
try { try {
const dependencies = await this.getOnDeployLifecycleHookDependencies(contract); const dependencies = await this.getOnDeployLifecycleHookDependencies({
contractConfig: contract,
logPrefix: `${contract.className} > beforeDeploy >`
});
await beforeDeployFn(dependencies); await beforeDeployFn(dependencies);
cb(); cb();
} catch (e) { } catch (e) {
@ -186,7 +190,10 @@ class SpecialConfigs {
if (typeof contract.onDeploy === 'function') { if (typeof contract.onDeploy === 'function') {
try { try {
const dependencies = await this.getOnDeployLifecycleHookDependencies(contract); const dependencies = await this.getOnDeployLifecycleHookDependencies({
contractConfig: contract,
logPrefix: `${contract.className} > onDeploy >`
});
await contract.onDeploy(dependencies); await contract.onDeploy(dependencies);
cb(); cb();
} catch (err) { } catch (err) {
@ -228,7 +235,10 @@ class SpecialConfigs {
if (typeof cmd === 'function') { if (typeof cmd === 'function') {
try { try {
const dependencies = await this.getOnDeployLifecycleHookDependencies(contract); const dependencies = await this.getOnDeployLifecycleHookDependencies({
contractConfig: contract,
logPrefix: `${contract.className} > deployIf >`
});
params.shouldDeploy = await contract.deployIf(dependencies); params.shouldDeploy = await contract.deployIf(dependencies);
cb(null, params); cb(null, params);
} catch (err) { } catch (err) {
@ -252,7 +262,8 @@ class SpecialConfigs {
}); });
} }
getOnDeployLifecycleHookDependencies(contractConfig) { getOnDeployLifecycleHookDependencies(options) {
let contractConfig = options.contractConfig;
let dependencyNames = contractConfig.deps || []; let dependencyNames = contractConfig.deps || [];
dependencyNames.push(contractConfig.className); dependencyNames.push(contractConfig.className);
dependencyNames = [...new Set(dependencyNames)]; dependencyNames = [...new Set(dependencyNames)];
@ -275,7 +286,7 @@ class SpecialConfigs {
reject(err); reject(err);
} }
this.events.request('blockchain:get', web3 => { this.events.request('blockchain:get', web3 => {
const logger = this.createLoggerWithPrefix(`${contractConfig.className} > onDeploy >`); const logger = this.createLoggerWithPrefix(options.logPrefix);
resolve(this.assembleLifecycleHookDependencies(contractInstances, web3, logger)); resolve(this.assembleLifecycleHookDependencies(contractInstances, web3, logger));
}); });
}); });