The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as FileSystem from "effect/FileSystem"; |
| 3 | import * as Path from "effect/Path"; |
| 4 | import type { ExtraFile } from "../Util/extraFiles.ts"; |
| 5 | |
| 6 | const nextConfigFiles = [ |
| 7 | "next.config.js", |
| 8 | "next.config.mjs", |
| 9 | "next.config.cjs", |
| 10 | "next.config.ts", |
| 11 | ] as const; |
| 12 | |
| 13 | const exists = (target: string) => |
| 14 | Effect.gen(function* () { |
| 15 | const fs = yield* FileSystem.FileSystem; |
| 16 | return yield* fs.exists(target).pipe(Effect.orElseSucceed(() => false)); |
| 17 | }); |
| 18 | |
| 19 | /** |
| 20 | * Extra files baked into a container/unit next to the Node serve entry. |
| 21 | * |
| 22 | * - `"client"`: the build's dist directory at the image/unit root. |
| 23 | * - `"next"`: `.next`, `public/`, and `next.config.*` from `from` (the |
| 24 | * Next.js app root — for the node target that is also `distDirectory`). |
| 25 | */ |
| 26 | export const packSiteExtraFiles = ( |
| 27 | from: string, |
| 28 | mode: "client" | "next", |
| 29 | ): Effect.Effect<ExtraFile[] | undefined, never, FileSystem.FileSystem | Path.Path> => |
| 30 | Effect.gen(function* () { |
| 31 | if (mode === "client") { |
| 32 | return [{ source: from, dest: "." }]; |
| 33 | } |
| 34 | const path = yield* Path.Path; |
| 35 | const nextDir = path.join(from, ".next"); |
| 36 | const publicDir = path.join(from, "public"); |
| 37 | const configPaths = nextConfigFiles.map((name) => ({ |
| 38 | name, |
| 39 | target: path.join(from, name), |
| 40 | })); |
| 41 | const [hasNext, hasPublic, ...configHits] = yield* Effect.all( |
| 42 | [exists(nextDir), exists(publicDir), ...configPaths.map((file) => exists(file.target))], |
| 43 | { concurrency: "unbounded" }, |
| 44 | ); |
| 45 | const files: ExtraFile[] = []; |
| 46 | if (hasNext) files.push({ source: nextDir, dest: ".next" }); |
| 47 | if (hasPublic) files.push({ source: publicDir, dest: "public" }); |
| 48 | configPaths.forEach((file, i) => { |
| 49 | if (configHits[i] === true) { |
| 50 | files.push({ source: file.target, dest: file.name }); |
| 51 | } |
| 52 | }); |
| 53 | return files.length > 0 ? files : undefined; |
| 54 | }); |