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