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 { 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", {
30 command: Argument.string("command").pipe(Argument.variadic),
31}).pipe(
32 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
33 Command.withHidden,
34 Command.withHandler(() =>
35 Effect.fail(
36 new CliError.ShowHelp({
37 commandPath: ["t3", "connect"],
38 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
39 }),
40 ),
41 ),
42);
43
44export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
45 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
46 Command.withDescription("Run the T3 Code server."),
47 Command.withHandler((flags) => runServerCommand(flags)),
48 Command.withSubcommands([
49 startCommand,
50 serveCommand,
51 authCommand,
52 projectCommand,
53 serviceCommand,
54 cloudEnabled ? connectCommand : connectUnavailableCommand,
55 ]),
56 );
57
58export const cli = makeCli();
59
60if (import.meta.main) {
61 Command.run(cli, { version: packageJson.version }).pipe(
62 Effect.scoped,
63 Effect.provide(CliRuntimeLayer),
64 NodeRuntime.runMain,
65 );
66}