(fs: FSUtil.Interface, directory: string)
| 50 | }) |
| 51 | |
| 52 | function loadDirectory(fs: FSUtil.Interface, directory: string) { |
| 53 | return Effect.gen(function* () { |
| 54 | const files = yield* fs |
| 55 | .glob("{command,commands}/**/*.md", { cwd: directory, absolute: true, dot: true, symlink: true }) |
| 56 | .pipe(Effect.catch(() => Effect.succeed([] as string[]))) |
| 57 | return yield* Effect.forEach(files.toSorted(), (filepath) => |
| 58 | fs.readFileStringSafe(filepath).pipe( |
| 59 | Effect.map((content) => (content === undefined ? undefined : decode(directory, filepath, content))), |
| 60 | Effect.catch(() => Effect.succeed(undefined)), |
| 61 | ), |
| 62 | ).pipe( |
| 63 | Effect.map((commands) => |
| 64 | commands.filter((command): command is { name: string; info: ConfigCommand.Info } => command !== undefined), |
| 65 | ), |
| 66 | ) |
| 67 | }) |
| 68 | } |
| 69 | |
| 70 | function decode(directory: string, filepath: string, content: string) { |
| 71 | const markdown = ConfigMarkdown.parseOption(content) |
no test coverage detected