| 12 | * @category loaders |
| 13 | */ |
| 14 | export const fromFileSystem = (directory: string): Loader<FileSystem> => |
| 15 | FileSystem.pipe( |
| 16 | Effect.flatMap((FS) => FS.readDirectory(directory)), |
| 17 | Effect.mapError((error) => new MigrationError({ reason: "failed", message: error.message })), |
| 18 | Effect.map((files): ReadonlyArray<ResolvedMigration> => |
| 19 | files |
| 20 | .map((file) => Option.fromNullable(file.match(/^(?:.*\/)?(\d+)_([^.]+)\.(js|ts)$/))) |
| 21 | .flatMap( |
| 22 | Option.match({ |
| 23 | onNone: () => [], |
| 24 | onSome: ([basename, id, name]): ReadonlyArray<ResolvedMigration> => |
| 25 | [ |
| 26 | [ |
| 27 | Number(id), |
| 28 | name, |
| 29 | Effect.promise( |
| 30 | () => |
| 31 | import( |
| 32 | /* @vite-ignore */ |
| 33 | /* webpackIgnore: true */ |
| 34 | `${directory}/${basename}` |
| 35 | ) |
| 36 | ) |
| 37 | ] |
| 38 | ] as const |
| 39 | }) |
| 40 | ) |
| 41 | .sort(([a], [b]) => a - b) |
| 42 | ) |
| 43 | ) |