@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 04:45 UTC

main
ts 116 lines 3.71 KB
Raw
1 #!/usr/bin/env node
2 import { PlatformServices, runMain } from "alchemy/Util/PlatformServices";
3 import { CliConfig, CliError, Command, Flag, GlobalFlag } from "effect/cli";
4 import * as Config from "effect/Config";
5 import * as Effect from "effect/Effect";
6 import * as FetchHttpClient from "effect/http/FetchHttpClient";
7 import * as Layer from "effect/Layer";
8 import * as Option from "effect/Option";
9 import pkg from "../../package.json" with { type: "json" };
10 import { Group, pack } from "./pack.ts";
11 import { publish } from "./publish.ts";
12
13 const groupFlag = Flag.String("group").pipe(
14 Flag.withDescription(
15 "Display group and directory glob, as NAME=GLOB or NAME[Collapsed]=GLOB (repeatable), e.g. --group Alchemy=./packages/*",
16 ),
17 Flag.withSchema(Group),
18 Flag.atLeast(1),
19 );
20
21 const registryFlag = Flag.String("registry").pipe(
22 Flag.withDescription(
23 "Registry origin used for install URLs. Falls back to PKG_REGISTRY, then https://pkg.alchemy.run",
24 ),
25 Flag.withFallbackConfig(Config.String("PKG_REGISTRY")),
26 Flag.withDefault("https://pkg.alchemy.run"),
27 );
28
29 const outFlag = Flag.String("out").pipe(
30 Flag.withDescription("Directory to write tarballs and the manifest into"),
31 Flag.withDefault(".pkg"),
32 );
33
34 export const packCommand = Command.make(
35 "pack",
36 {
37 group: groupFlag,
38 registry: registryFlag,
39 out: outFlag,
40 since: Flag.String("since").pipe(
41 Flag.withDescription("Compare HEAD with this Git ref; defaults to the PR base in Actions"),
42 Flag.optional,
43 ),
44 all: Flag.Boolean("all").pipe(
45 Flag.withDefault(false),
46 Flag.withDescription("Pack every configured package regardless of changes"),
47 ),
48 rebuildAllPaths: Flag.String("rebuild-all-path").pipe(
49 Flag.withDescription(
50 "Additional exact path or directory/** forcing all packages (repeatable)",
51 ),
52 Flag.atLeast(0),
53 ),
54 },
55 ({ group, registry, out, since, all, rebuildAllPaths }) =>
56 Effect.gen(function* () {
57 const cwd = yield* Effect.sync(() => process.cwd());
58 yield* pack({
59 cwd,
60 groups: group,
61 registry,
62 out,
63 since: Option.getOrUndefined(since),
64 all,
65 rebuildAllPaths,
66 });
67 }),
68 ).pipe(
69 Command.withDescription(
70 "Pack workspace packages into reproducible tarballs with dependencies rewritten to registry URLs",
71 ),
72 Command.withExamples([
73 {
74 command:
75 "pkg pack --group 'alchemy=./packages/alchemy' --group '@alchemy.run[Collapsed]=./packages/{better-auth,pkg}' --group '@distilled.cloud[Collapsed]=./submodules/distilled/packages/*'",
76 },
77 ]),
78 );
79
80 const dirFlag = Flag.String("dir").pipe(
81 Flag.withDescription("Directory written by pkg pack"),
82 Flag.withDefault(".pkg"),
83 );
84
85 export const publishCommand = Command.make(
86 "publish",
87 { registry: registryFlag, dir: dirFlag },
88 ({ registry, dir }) =>
89 Effect.gen(function* () {
90 const cwd = yield* Effect.sync(() => process.cwd());
91 yield* publish({ cwd, dir, registry });
92 }),
93 ).pipe(
94 Command.withDescription(
95 "Publish a pkg pack directory from the current GitHub Actions job, after its manifest artifact has been uploaded",
96 ),
97 Command.withExamples([{ command: "pkg publish --registry https://pkg.alchemy.run" }]),
98 );
99
100 export const root = Command.make("pkg", {}, () =>
101 Effect.fail(CliError.ShowHelp.make({ commandPath: ["pkg"], errors: [] })),
102 ).pipe(
103 Command.withDescription("Pack and publish preview packages for pull requests."),
104 Command.withSubcommands([packCommand, publishCommand]),
105 );
106
107 Command.run(root, { version: pkg.version }).pipe(
108 Effect.provide(
109 Layer.mergeAll(
110 PlatformServices,
111 FetchHttpClient.layer,
112 CliConfig.layer({ builtIns: [GlobalFlag.Help, GlobalFlag.Version] }),
113 ),
114 ),
115 runMain,
116 );