mirror of https://github.com/embarklabs/embark.git
feat(@embark/embark-specialconfigs): introduce new beforeDeploy hooks
This commit enables new `beforeDeploy` deployment hooks. With this change it's possible to add `beforeDeploy` to either `contracts: {}` within the contracts configuration, or an individual contract. For example: ``` contracts: { SimpleStorage: { beforeDeploy: async (context) => { } } } ``` Runs the hook before `SimpleStorage` will be deployed. Whereas ``` contracts: { ... beforeDeploy: async () => { } } will be executed before *all* Smart Contracts will be deployed.
This commit is contained in:
parent
f0aed55319
commit
1aeb6fd83b
|
@ -13,7 +13,9 @@ class SpecialConfigs {
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
this.config = embark.config;
|
this.config = embark.config;
|
||||||
|
|
||||||
|
this.registerBeforeAllDeployAction();
|
||||||
this.registerAfterDeployAction();
|
this.registerAfterDeployAction();
|
||||||
|
this.registerBeforeDeployAction();
|
||||||
this.registerOnDeployAction();
|
this.registerOnDeployAction();
|
||||||
this.registerDeployIfAction();
|
this.registerDeployIfAction();
|
||||||
}
|
}
|
||||||
|
@ -91,6 +93,21 @@ class SpecialConfigs {
|
||||||
return replaceWithAddresses(cmd);
|
return replaceWithAddresses(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerBeforeAllDeployAction() {
|
||||||
|
this.embark.registerActionForEvent('deploy:beforeAll', async (cb) => {
|
||||||
|
const beforeDeployFn = this.config.contractsConfig.beforeDeploy;
|
||||||
|
if (!beforeDeployFn || typeof beforeDeployFn !== 'function') {
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await beforeDeployFn();
|
||||||
|
cb();
|
||||||
|
} catch (err) {
|
||||||
|
cb(new Error(`Error running beforeDeploy hook: ${err.message}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerAfterDeployAction() {
|
registerAfterDeployAction() {
|
||||||
this.embark.registerActionForEvent("contracts:deploy:afterAll", async (cb) => {
|
this.embark.registerActionForEvent("contracts:deploy:afterAll", async (cb) => {
|
||||||
if (typeof this.config.contractsConfig.afterDeploy === 'function') {
|
if (typeof this.config.contractsConfig.afterDeploy === 'function') {
|
||||||
|
@ -138,6 +155,23 @@ class SpecialConfigs {
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerBeforeDeployAction() {
|
||||||
|
this.embark.registerActionForEvent('deploy:contract:beforeDeploy', async (params, cb) => {
|
||||||
|
const contract = params.contract;
|
||||||
|
const beforeDeployFn = params.contract.beforeDeploy;
|
||||||
|
if (!beforeDeployFn || typeof beforeDeployFn !== 'function') {
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const dependencies = await this.getOnDeployLifecycleHookDependencies(contract);
|
||||||
|
await beforeDeployFn(dependencies);
|
||||||
|
cb();
|
||||||
|
} catch (e) {
|
||||||
|
cb(new Error(`Error running beforeDeploy hook for ${contract.className}: ${e.message || e}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerOnDeployAction() {
|
registerOnDeployAction() {
|
||||||
this.embark.registerActionForEvent("deploy:contract:deployed", async (params, cb) => {
|
this.embark.registerActionForEvent("deploy:contract:deployed", async (params, cb) => {
|
||||||
let contract = params.contract;
|
let contract = params.contract;
|
||||||
|
|
Loading…
Reference in New Issue