MCPcopy Create free account
hub / github.com/Maccoder3/MAC-MD / filesInit

Function filesInit

lib/plugins.js:19–44  ·  view source on GitHub ↗
(pluginFolder = pluginFolder, pluginFilter = pluginFilter, conn)

Source from the content-addressed store, hash-verified

17watcher = plugins = {}
18
19async 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
46function deletePluginFolder(folder, isAlreadyClosed = false) {
47 const resolved = resolve(folder)

Callers

nothing calls this directly

Calls 1

deletePluginFolderFunction · 0.85

Tested by

no test coverage detected