Open History to see the last commit
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 { connectCommand } from "./cli/connect.ts";
12import { pairCommand } from "./cli/pair.ts";
13import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
14import { sharedServerCommandFlags } from "./cli/config.ts";
15import { projectCommand } from "./cli/project.ts";
16import { runServerCommand, serveCommand, startCommand } from "./cli/server.ts";
17import { serviceCommand } from "./cli/service.ts";
18import { servicePreflightCommand } from "./cli/servicePreflight.ts";
19import { triageCommand } from "./cli/triage.ts";
20
21const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
22
23const connectPublicConfigMissingMessage =
24 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
25
26class ConnectPublicConfigMissingError extends CliError.UserError {
27 override get message() {
28 return connectPublicConfigMissingMessage;
29 }
30}
31
32const connectUnavailableCommand = Command.make("connect", {
33 command: Argument.string("command").pipe(Argument.variadic),
34}).pipe(
35 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
36 Command.withHidden,
37 Command.withHandler(() =>
38 Effect.fail(
39 new CliError.ShowHelp({
40 commandPath: ["t3", "connect"],
41 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
42 }),
43 ),
44 ),
45);
46
47export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
48 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
49 Command.withDescription("Run the T3 Code server."),
50 Command.withHandler((flags) => runServerCommand(flags)),
51 Command.withSubcommands([
52 startCommand,
53 serveCommand,
54 pairCommand,
55 authCommand,
56 projectCommand,
57 serviceCommand,
58 servicePreflightCommand,
59 triageCommand,
60 cloudEnabled ? connectCommand : connectUnavailableCommand,
61 ]),
62 );
63
64export const cli = makeCli();
65
66if (import.meta.main) {
67 Command.run(cli, { version: packageJson.version }).pipe(
68 Effect.scoped,
69 Effect.provide(CliRuntimeLayer),
70 NodeRuntime.runMain,
71 );
72}