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