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