(pluginFolder = pluginFolder, pluginFilter = pluginFilter, conn)
| 17 | watcher = plugins = {} |
| 18 | |
| 19 | async function filesInit(pluginFolder = pluginFolder, pluginFilter = pluginFilter, conn) { |
| 20 | const folder = resolve(pluginFolder) |
| 21 | if (folder in watcher) return |
| 22 | pluginFolders.push(folder) |
| 23 | |
| 24 | await Promise.all( |
| 25 | readdirSync(folder) |
| 26 | .filter(pluginFilter) |
| 27 | .map(async filename => { |
| 28 | try { |
| 29 | let file = global.__filename(join(folder, filename)) |
| 30 | const module = await import(file) |
| 31 | if (module) plugins[filename] = 'default' in module ? module.default : module |
| 32 | } catch (e) { |
| 33 | conn?.logger.error(e) |
| 34 | delete plugins[filename] |
| 35 | } |
| 36 | }) |
| 37 | ) |
| 38 | |
| 39 | const watching = watch(folder, reload.bind(null, conn, folder, pluginFilter)) |
| 40 | watching.on('close', () => deletePluginFolder(folder, true)) |
| 41 | watcher[folder] = watching |
| 42 | |
| 43 | return plugins |
| 44 | } |
| 45 | |
| 46 | function deletePluginFolder(folder, isAlreadyClosed = false) { |
| 47 | const resolved = resolve(folder) |
nothing calls this directly
no test coverage detected