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