(dir: string)
| 11 | const decodeInfo = Schema.decodeUnknownExit(ConfigCommandV1.Info) |
| 12 | |
| 13 | export async function load(dir: string) { |
| 14 | const result: Record<string, ConfigCommandV1.Info> = {} |
| 15 | for (const item of await Glob.scan("{command,commands}/**/*.md", { |
| 16 | cwd: dir, |
| 17 | absolute: true, |
| 18 | dot: true, |
| 19 | symlink: true, |
| 20 | })) { |
| 21 | const md = await ConfigMarkdown.parse(item).catch(() => undefined) |
| 22 | if (!md) continue |
| 23 | |
| 24 | const name = configEntryNameFromPath(path.relative(dir, item), ["command/", "commands/"]) |
| 25 | |
| 26 | const config = { |
| 27 | name, |
| 28 | ...md.data, |
| 29 | template: md.content.trim(), |
| 30 | } |
| 31 | const parsed = decodeInfo(config, { errors: "all", propertyOrder: "original" }) |
| 32 | if (Exit.isSuccess(parsed)) { |
| 33 | result[config.name] = parsed.value |
| 34 | continue |
| 35 | } |
| 36 | throw new InvalidError({ path: item, message: Cause.pretty(parsed.cause) }, { cause: Cause.squash(parsed.cause) }) |
| 37 | } |
| 38 | return result |
| 39 | } |
nothing calls this directly
no test coverage detected