mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
⚡ Make it possible to reload hook-files
This commit is contained in:
parent
dfd054f036
commit
e428ccffba
|
@ -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<void> { // 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];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue