-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 4.2.0 load multiple directories &
handleModuleErrors
(#378)
* error-handling-draft * feat: array based module loading (#379) Co-authored-by: Jacob Nguyen <[email protected]> * Update utility.ts * Update sern.ts * describesemanticsbetter --------- Co-authored-by: Duro <[email protected]>
- Loading branch information
Showing
6 changed files
with
115 additions
and
50 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
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
f9e7eaf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any chance we could rename commands to modules so that new developers can understand it a little better?