Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

bin.ts

91 lines3.1 KB

1import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import { Argument, Command } from "effect/unstable/cli";
6import * as CliError from "effect/unstable/cli/CliError";
7​
8import * as NetService from "@t3tools/shared/Net";
9import packageJson from "../package.json" with { type: "json" };
10import { authCommand } from "./cli/auth.ts";
11import { appCommand } from "./cli/app.ts";
12import { connectCommand } from "./cli/connect.ts";
13import { pairCommand } from "./cli/pair.ts";
14import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
15import { sharedServerCommandFlags } from "./cli/config.ts";
16import { isEntrypoint } from "./entrypoint.ts";
17import { projectCommand } from "./cli/project.ts";
18import { runServerCommand, serveCommand, startCommand } from "./cli/server.ts";
19import { serviceCommand } from "./cli/service.ts";
20import { updateCommand } from "./cli/update.ts";
21import { claudeHistoryCommand } from "./cli/claudeHistory.ts";
22import { serviceLauncherCommand } from "./cli/serviceLauncher.ts";
23import { servicePreflightCommand } from "./cli/servicePreflight.ts";
24import { sshHelperCommand } from "./cli/sshHelper.ts";
25import { themeCommand } from "./cli/theme.ts";
26import { triageCommand } from "./cli/triage.ts";
27​
28const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
29​
30const connectPublicConfigMissingMessage =
31 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
32​
33class ConnectPublicConfigMissingError extends CliError.UserError {
34 override get message() {
35 return connectPublicConfigMissingMessage;
36 }
38​
39const connectUnavailableCommand = Command.make("connect", {
40 command: Argument.string("command").pipe(Argument.variadic),
41}).pipe(
42 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
43 Command.unlisted,
44 Command.withHandler(() =>
45 Effect.fail(
46 new CliError.ShowHelp({
47 commandPath: ["t3", "connect"],
48 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
49 }),
50 ),
51 ),
52);
53​
54export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
55 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
56 Command.withDescription("Run the T3 Code server."),
57 Command.withHandler((flags) => runServerCommand(flags)),
58 Command.withSubcommands([
59 startCommand,
60 serveCommand,
61 appCommand,
62 pairCommand,
63 authCommand,
64 projectCommand,
65 serviceCommand,
66 updateCommand,
67 serviceLauncherCommand,
68 claudeHistoryCommand,
69 servicePreflightCommand,
70 sshHelperCommand,
71 themeCommand,
72 triageCommand,
73 cloudEnabled ? connectCommand : connectUnavailableCommand,
74 ]),
75 );
76​
77export const cli = makeCli();
78​
79if (
80 isEntrypoint({
81 moduleUrl: import.meta.url,
82 entryPath: process.argv[1],
83 runtimeMain: import.meta.main,
84 })
85) {
86 Command.run(cli, { version: packageJson.version }).pipe(
87 Effect.scoped,
88 Effect.provide(CliRuntimeLayer),
89 NodeRuntime.runMain,
90 );