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