fix up some bugs and debugging

This commit is contained in:
Jacob Nguyen
2024-08-11 01:48:24 -05:00
parent 3e668090d8
commit 8ec59a3443
3 changed files with 6 additions and 5 deletions

View File

@@ -55,15 +55,16 @@ export async function importModule<T>(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];
}
}
}

View File

@@ -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<Module>(path);
const validType = module.type >= CommandType.Text && module.type <= CommandType.ChannelSelect;
if(!validType) {

View File

@@ -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<ScheduledTask>(f);
//module.name is assigned by Files.importModule<>
// the id created for the task is unique