The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Effect from "effect/Effect" |
| 2 | import * as Option from "effect/Option" |
| 3 | import type * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" |
| 4 | import * as Schema from "effect/Schema" |
| 5 | import type { ReleasePackage } from "./NpmPromote.ts" |
| 6 | import { NpmPromoteError } from "./NpmPromoteError.ts" |
| 7 | import * as Process from "./Process.ts" |
| 8 | |
| 9 | export interface WorkspacePackage extends ReleasePackage { |
| 10 | readonly directory: string |
| 11 | } |
| 12 | |
| 13 | const PnpmList = Schema.fromJsonString(Schema.Array(Schema.Struct({ |
| 14 | name: Schema.optional(Schema.NullOr(Schema.String)), |
| 15 | version: Schema.optional(Schema.NullOr(Schema.String)), |
| 16 | path: Schema.String, |
| 17 | private: Schema.optional(Schema.Boolean) |
| 18 | }))) |
| 19 | |
| 20 | /** |
| 21 | * Lists the non-private workspace packages with their versions at the |
| 22 | * checked-out revision. These are the packages `changeset publish` releases. |
| 23 | */ |
| 24 | export const releasePackages = ( |
| 25 | cwd: string |
| 26 | ): Effect.Effect<ReadonlyArray<WorkspacePackage>, NpmPromoteError, ChildProcessSpawner.ChildProcessSpawner> => |
| 27 | Process.run("pnpm", ["ls", "--recursive", "--depth", "-1", "--json"], { cwd }).pipe( |
| 28 | Effect.flatMap(Schema.decodeUnknownEffect(PnpmList)), |
| 29 | Effect.mapError((cause) => |
| 30 | Schema.is(NpmPromoteError)(cause) ? cause : new NpmPromoteError({ |
| 31 | message: "Could not read the pnpm workspace package list", |
| 32 | cause |
| 33 | }) |
| 34 | ), |
| 35 | Effect.map((packages) => |
| 36 | packages.flatMap((pkg) => |
| 37 | pkg.private !== true && typeof pkg.name === "string" && typeof pkg.version === "string" |
| 38 | ? [{ name: pkg.name, version: pkg.version, directory: pkg.path }] |
| 39 | : [] |
| 40 | ) |
| 41 | ) |
| 42 | ) |
| 43 | |
| 44 | export interface VersionBump { |
| 45 | readonly sha: string |
| 46 | readonly committedAt: Date |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Finds the newest commit that changed the `version` field of the package in |
| 51 | * `directory`. Fails in a shallow clone, which would report its boundary |
| 52 | * commit instead. |
| 53 | */ |
| 54 | export const versionBump = ( |
| 55 | directory: string |
| 56 | ): Effect.Effect<Option.Option<VersionBump>, NpmPromoteError, ChildProcessSpawner.ChildProcessSpawner> => |
| 57 | Effect.gen(function*() { |
| 58 | const shallow = yield* Process.run("git", ["rev-parse", "--is-shallow-repository"], { cwd: directory }) |
| 59 | if (shallow.trim() !== "false") { |
| 60 | return yield* new NpmPromoteError({ message: "Finding the version bump commit needs a full clone" }) |
| 61 | } |
| 62 | return yield* Process.run("git", ["log", "-1", "--format=%H %cI", "-G", "\"version\":", "--", "package.json"], { |
| 63 | cwd: directory |
| 64 | }) |
| 65 | }).pipe( |
| 66 | Effect.map((output) => { |
| 67 | const [sha, committedAt] = output.trim().split(" ") |
| 68 | return sha && committedAt ? Option.some({ sha, committedAt: new Date(committedAt) }) : Option.none() |
| 69 | }) |
| 70 | ) |