From 8ec59a344367f40e0570f5417196246e2df4cb0d Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 11 Aug 2024 01:48:24 -0500 Subject: [PATCH] fix up some bugs and debugging --- src/core/module-loading.ts | 7 ++++--- src/handlers/ready.ts | 2 +- src/handlers/tasks.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index 2f389db..736b09d 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -55,15 +55,16 @@ export async function importModule(absPath: string) { export async function* readRecursive(dir: string, directoryPlugins: string[] = []): AsyncGenerator<[string, string[]]> { const files = await readdir(dir, { withFileTypes: true }); - const plugins = files.find(file => file.isFile() && file.name.startsWith('!plugins')) as Dirent; + const pluginFile = files.find(file => file.isFile() && file.name.startsWith('!plugins')) as Dirent; for (const file of files) { const fullPath = path.posix.join(dir, file.name); + const plugins = pluginFile ? [...directoryPlugins, path.posix.join(dir, pluginFile.name) ] : directoryPlugins if (file.isDirectory()) { if (!file.name.startsWith('!')) { - yield* readRecursive(fullPath, [path.posix.join(dir, plugins?.name!), ...directoryPlugins]); + yield* readRecursive(fullPath, plugins); } } else if (!file.name.startsWith('!')) { - yield ["file:///"+path.resolve(fullPath), directoryPlugins]; + yield ["file:///"+path.resolve(fullPath), plugins]; } } } diff --git a/src/handlers/ready.ts b/src/handlers/ready.ts index 4f1a370..e7af5e4 100644 --- a/src/handlers/ready.ts +++ b/src/handlers/ready.ts @@ -18,7 +18,7 @@ export default async function(dir: string, deps : UnpackedDependencies) { // https://observablehq.com/@ehouais/multiple-promises-as-an-async-generator // possibly optimize to concurrently import modules for await (const [path, directoryPlugins] of Files.readRecursive(dir)) { - console.log(directoryPlugins) + console.log(path, directoryPlugins) let { module } = await Files.importModule(path); const validType = module.type >= CommandType.Text && module.type <= CommandType.ChannelSelect; if(!validType) { diff --git a/src/handlers/tasks.ts b/src/handlers/tasks.ts index a204fc5..7545635 100644 --- a/src/handlers/tasks.ts +++ b/src/handlers/tasks.ts @@ -6,7 +6,7 @@ import { fileURLToPath } from "url"; export const registerTasks = async (tasksPath: string, deps: UnpackedDependencies) => { const taskManager = deps['@sern/scheduler'] - for await (const f of Files.readRecursive(tasksPath)) { + for await (const [f, _] of Files.readRecursive(tasksPath)) { let { module } = await Files.importModule(f); //module.name is assigned by Files.importModule<> // the id created for the task is unique