mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -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;
|
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(':');
|
const externalHookFiles = config.get('externalHookFiles').split(':');
|
||||||
|
|
||||||
// Load all the provided hook-files
|
// Load all the provided hook-files
|
||||||
|
@ -27,6 +40,11 @@ class ExternalHooksClass implements IExternalHooksClass {
|
||||||
hookFilePath = hookFilePath.trim();
|
hookFilePath = hookFilePath.trim();
|
||||||
if (hookFilePath !== '') {
|
if (hookFilePath !== '') {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (reload === true) {
|
||||||
|
delete require.cache[require.resolve(hookFilePath)];
|
||||||
|
}
|
||||||
|
|
||||||
const hookFile = require(hookFilePath);
|
const hookFile = require(hookFilePath);
|
||||||
|
|
||||||
for (const resource of Object.keys(hookFile)) {
|
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
|
async run(hookName: string, hookParameters?: any[]): Promise<void> { // tslint:disable-line:no-any
|
||||||
const externalHookFunctions: IExternalHooksFunctions = {
|
const externalHookFunctions: IExternalHooksFunctions = {
|
||||||
dbCollections: Db.collections,
|
dbCollections: Db.collections,
|
||||||
|
@ -64,6 +81,7 @@ class ExternalHooksClass implements IExternalHooksClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exists(hookName: string): boolean {
|
exists(hookName: string): boolean {
|
||||||
return !!this.externalHooks[hookName];
|
return !!this.externalHooks[hookName];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue