diff --git a/packages/cli/src/ExternalHooks.ts b/packages/cli/src/ExternalHooks.ts index acdae264ab..89dbc54045 100644 --- a/packages/cli/src/ExternalHooks.ts +++ b/packages/cli/src/ExternalHooks.ts @@ -20,6 +20,19 @@ class ExternalHooksClass implements IExternalHooksClass { return; } + await this.loadHooksFiles(); + + this.initDidRun = true; + } + + + async reload() { + this.externalHooks = {}; + await this.loadHooksFiles(true); + } + + + async loadHooksFiles(reload = false) { const externalHookFiles = config.get('externalHookFiles').split(':'); // Load all the provided hook-files @@ -27,6 +40,11 @@ class ExternalHooksClass implements IExternalHooksClass { hookFilePath = hookFilePath.trim(); if (hookFilePath !== '') { try { + + if (reload === true) { + delete require.cache[require.resolve(hookFilePath)]; + } + const hookFile = require(hookFilePath); for (const resource of Object.keys(hookFile)) { @@ -46,10 +64,9 @@ class ExternalHooksClass implements IExternalHooksClass { } } } - - this.initDidRun = true; } + async run(hookName: string, hookParameters?: any[]): Promise { // tslint:disable-line:no-any const externalHookFunctions: IExternalHooksFunctions = { dbCollections: Db.collections, @@ -64,6 +81,7 @@ class ExternalHooksClass implements IExternalHooksClass { } } + exists(hookName: string): boolean { return !!this.externalHooks[hookName]; }