mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
fix up some bugs and debugging
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user