-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: array based module loading (#379)
Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
48 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
import * as Files from '../core/module-loading' | ||
import { UnpackedDependencies } from "../types/utility"; | ||
import { UnpackedDependencies, Wrapper } from "../types/utility"; | ||
import type { ScheduledTask } from "../types/core-modules"; | ||
import { relative } from "path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
export const registerTasks = async (tasksPath: string, deps: UnpackedDependencies) => { | ||
export const registerTasks = async (tasksDirs: string | string[], deps: UnpackedDependencies) => { | ||
const taskManager = deps['@sern/scheduler'] | ||
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 | ||
const uuid = module.name+"/"+relative(tasksPath,fileURLToPath(f)) | ||
taskManager.schedule(uuid, module, deps) | ||
|
||
const directories = Array.isArray(tasksDirs) ? tasksDirs : [tasksDirs]; | ||
|
||
for (const dir of directories) { | ||
for await (const path of Files.readRecursive(dir)) { | ||
let { module } = await Files.importModule<ScheduledTask>(path); | ||
//module.name is assigned by Files.importModule<> | ||
// the id created for the task is unique | ||
const uuid = module.name+"/"+relative(dir,fileURLToPath(path)) | ||
taskManager.schedule(uuid, module, deps) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters