@prisma/cli 3.0.0-alpha.2 → 3.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/adapters/git.js +49 -0
  2. package/dist/adapters/local-state.js +38 -0
  3. package/dist/cli2.js +3 -1
  4. package/dist/commands/app/index.js +31 -20
  5. package/dist/commands/auth/index.js +1 -1
  6. package/dist/commands/env.js +87 -0
  7. package/dist/commands/git/index.js +36 -0
  8. package/dist/commands/project/index.js +10 -13
  9. package/dist/controllers/app-env.js +223 -0
  10. package/dist/controllers/app.js +260 -86
  11. package/dist/controllers/auth.js +2 -2
  12. package/dist/controllers/branch.js +1 -1
  13. package/dist/controllers/project.js +451 -161
  14. package/dist/lib/app/env-config.js +57 -0
  15. package/dist/lib/app/preview-provider.js +15 -2
  16. package/dist/lib/auth/auth-ops.js +8 -10
  17. package/dist/lib/auth/client.js +1 -1
  18. package/dist/lib/project/resolution.js +148 -0
  19. package/dist/output/patterns.js +1 -2
  20. package/dist/presenters/app-env.js +129 -0
  21. package/dist/presenters/app.js +9 -1
  22. package/dist/presenters/auth.js +2 -2
  23. package/dist/presenters/branch.js +6 -6
  24. package/dist/presenters/project.js +84 -44
  25. package/dist/shell/command-meta.js +91 -9
  26. package/dist/shell/command-runner.js +32 -2
  27. package/dist/shell/errors.js +4 -1
  28. package/dist/shell/help.js +1 -1
  29. package/dist/shell/output.js +18 -12
  30. package/dist/shell/runtime.js +1 -1
  31. package/dist/shell/ui.js +19 -1
  32. package/dist/use-cases/auth.js +5 -8
  33. package/dist/use-cases/branch.js +20 -20
  34. package/dist/use-cases/create-cli-gateways.js +3 -13
  35. package/dist/use-cases/project.js +2 -48
  36. package/package.json +2 -2
  37. package/dist/adapters/config.js +0 -74
@@ -0,0 +1,49 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ //#region src/adapters/git.ts
4
+ const execFileAsync = promisify(execFile);
5
+ async function readGitOriginRemote(cwd) {
6
+ try {
7
+ const { stdout } = await execFileAsync("git", [
8
+ "config",
9
+ "--get",
10
+ "remote.origin.url"
11
+ ], {
12
+ cwd,
13
+ timeout: 5e3
14
+ });
15
+ const remote = stdout.trim();
16
+ return remote.length > 0 ? remote : null;
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+ function parseGitHubRepositoryUrl(value) {
22
+ const input = value.trim();
23
+ const shorthand = input.match(/^git@github\.com:([^/\s]+)\/([^/\s]+?)(?:\.git)?$/);
24
+ if (shorthand) return toGitHubRepositoryReference(shorthand[1], shorthand[2]);
25
+ let parsed;
26
+ try {
27
+ parsed = new URL(input);
28
+ } catch {
29
+ return null;
30
+ }
31
+ if (parsed.hostname !== "github.com") return null;
32
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:" && parsed.protocol !== "ssh:") return null;
33
+ const parts = parsed.pathname.split("/").filter(Boolean);
34
+ if (parts.length !== 2) return null;
35
+ const [owner, rawName] = parts;
36
+ return toGitHubRepositoryReference(owner, rawName.endsWith(".git") ? rawName.slice(0, -4) : rawName);
37
+ }
38
+ function toGitHubRepositoryReference(owner, name) {
39
+ if (!owner || !name || owner.includes("/") || name.includes("/")) return null;
40
+ return {
41
+ provider: "github",
42
+ owner,
43
+ name,
44
+ fullName: `${owner}/${name}`,
45
+ url: `https://github.com/${owner}/${name}`
46
+ };
47
+ }
48
+ //#endregion
49
+ export { parseGitHubRepositoryUrl, readGitOriginRemote };
@@ -3,6 +3,11 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  //#region src/adapters/local-state.ts
4
4
  const DEFAULT_STATE = {
5
5
  auth: null,
6
+ project: {
7
+ rememberedByWorkspace: {},
8
+ lastResolved: null,
9
+ repositoryConnectionsByProject: {}
10
+ },
6
11
  branch: { active: "preview" },
7
12
  app: {
8
13
  selectedByProject: {},
@@ -24,6 +29,11 @@ var LocalStateStore = class {
24
29
  const parsed = JSON.parse(raw);
25
30
  return {
26
31
  auth: parsed.auth ?? structuredClone(DEFAULT_STATE.auth),
32
+ project: {
33
+ rememberedByWorkspace: parsed.project?.rememberedByWorkspace ?? {},
34
+ lastResolved: parsed.project?.lastResolved ?? null,
35
+ repositoryConnectionsByProject: parsed.project?.repositoryConnectionsByProject ?? {}
36
+ },
27
37
  branch: { active: parsed.branch?.active ?? DEFAULT_STATE.branch.active },
28
38
  app: {
29
39
  selectedByProject: parsed.app?.selectedByProject ?? {},
@@ -57,6 +67,34 @@ var LocalStateStore = class {
57
67
  await this.write(state);
58
68
  return state;
59
69
  }
70
+ async readRememberedProject(workspaceId) {
71
+ return (await this.read()).project.rememberedByWorkspace[workspaceId] ?? null;
72
+ }
73
+ async readLastResolvedProject() {
74
+ return (await this.read()).project.lastResolved;
75
+ }
76
+ async setRememberedProject(project) {
77
+ const state = await this.read();
78
+ state.project.rememberedByWorkspace[project.workspaceId] = project;
79
+ state.project.lastResolved = project;
80
+ await this.write(state);
81
+ return state;
82
+ }
83
+ async readRepositoryConnection(projectId) {
84
+ return (await this.read()).project.repositoryConnectionsByProject[projectId] ?? null;
85
+ }
86
+ async setRepositoryConnection(projectId, connection) {
87
+ const state = await this.read();
88
+ state.project.repositoryConnectionsByProject[projectId] = connection;
89
+ await this.write(state);
90
+ return state;
91
+ }
92
+ async clearRepositoryConnection(projectId) {
93
+ const state = await this.read();
94
+ delete state.project.repositoryConnectionsByProject[projectId];
95
+ await this.write(state);
96
+ return state;
97
+ }
60
98
  async readSelectedApp(projectId) {
61
99
  return (await this.read()).app.selectedByProject[projectId] ?? null;
62
100
  }
package/dist/cli2.js CHANGED
@@ -5,6 +5,7 @@ import "./shell/prompt.js";
5
5
  import { createAppCommand } from "./commands/app/index.js";
6
6
  import { createAuthCommand } from "./commands/auth/index.js";
7
7
  import { createBranchCommand } from "./commands/branch/index.js";
8
+ import { createGitCommand } from "./commands/git/index.js";
8
9
  import { createProjectCommand } from "./commands/project/index.js";
9
10
  import process from "node:process";
10
11
  import { Command, CommanderError } from "commander";
@@ -35,8 +36,9 @@ function createProgram(runtime) {
35
36
  addCompactGlobalFlags(program);
36
37
  program.name("prisma").showSuggestionAfterError();
37
38
  program.addCommand(createAuthCommand(runtime));
38
- program.addCommand(createBranchCommand(runtime));
39
39
  program.addCommand(createProjectCommand(runtime));
40
+ program.addCommand(createGitCommand(runtime));
41
+ program.addCommand(createBranchCommand(runtime));
40
42
  program.addCommand(createAppCommand(runtime));
41
43
  return program;
42
44
  }
@@ -4,7 +4,7 @@ import { configureRuntimeCommand } from "../../shell/runtime.js";
4
4
  import { PREVIEW_BUILD_TYPES } from "../../lib/app/preview-build.js";
5
5
  import { runAppBuild, runAppDeploy, runAppListDeploys, runAppListEnv, runAppLogs, runAppOpen, runAppPromote, runAppRemove, runAppRollback, runAppRun, runAppShow, runAppShowDeploy, runAppUpdateEnv } from "../../controllers/app.js";
6
6
  import { renderAppBuild, renderAppDeploy, renderAppListDeploys, renderAppListEnv, renderAppOpen, renderAppPromote, renderAppRemove, renderAppRollback, renderAppRun, renderAppShow, renderAppShowDeploy, renderAppUpdateEnv, serializeAppBuild, serializeAppDeploy, serializeAppListDeploys, serializeAppListEnv, serializeAppOpen, serializeAppPromote, serializeAppRemove, serializeAppRollback, serializeAppRun, serializeAppShow, serializeAppShowDeploy, serializeAppUpdateEnv } from "../../presenters/app.js";
7
- import { runCommand } from "../../shell/command-runner.js";
7
+ import { runCommand, runStreamingCommand } from "../../shell/command-runner.js";
8
8
  import { Command, Option } from "commander";
9
9
  //#region src/commands/app/index.ts
10
10
  function createAppCommand(runtime) {
@@ -60,7 +60,7 @@ function createRunCommand(runtime) {
60
60
  }
61
61
  function createDeployCommand(runtime) {
62
62
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("deploy"), runtime), "app.deploy");
63
- command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--entry <path>", "Entrypoint path for Bun or auto deploys")).addOption(new Option("--build-type <type>", "Deploy build type").choices([...PREVIEW_BUILD_TYPES]).default("auto")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues));
63
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name")).addOption(new Option("--entry <path>", "Entrypoint path for Bun or auto deploys")).addOption(new Option("--build-type <type>", "Deploy build type").choices([...PREVIEW_BUILD_TYPES]).default("auto")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues));
64
64
  addGlobalFlags(command);
65
65
  command.action(async (options) => {
66
66
  const appName = options.app;
@@ -68,7 +68,9 @@ function createDeployCommand(runtime) {
68
68
  const buildType = options.buildType;
69
69
  const httpPort = options.httpPort;
70
70
  const envAssignments = options.env;
71
+ const projectRef = options.project;
71
72
  await runCommand(runtime, "app.deploy", options, (context) => runAppDeploy(context, appName, {
73
+ projectRef,
72
74
  entrypoint: entry,
73
75
  buildType,
74
76
  httpPort,
@@ -82,12 +84,13 @@ function createDeployCommand(runtime) {
82
84
  }
83
85
  function createUpdateEnvCommand(runtime) {
84
86
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("update-env"), runtime), "app.update-env");
85
- command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues));
87
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues));
86
88
  addGlobalFlags(command);
87
89
  command.action(async (options) => {
88
90
  const appName = options.app;
89
91
  const envAssignments = options.env;
90
- await runCommand(runtime, "app.update-env", options, (context) => runAppUpdateEnv(context, appName, envAssignments), {
92
+ const projectRef = options.project;
93
+ await runCommand(runtime, "app.update-env", options, (context) => runAppUpdateEnv(context, appName, envAssignments, projectRef), {
91
94
  renderHuman: (context, descriptor, result) => renderAppUpdateEnv(context, descriptor, result),
92
95
  renderJson: (result) => serializeAppUpdateEnv(result)
93
96
  });
@@ -96,11 +99,12 @@ function createUpdateEnvCommand(runtime) {
96
99
  }
97
100
  function createListEnvCommand(runtime) {
98
101
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("list-env"), runtime), "app.list-env");
99
- command.addOption(new Option("--app <name>", "App name"));
102
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name"));
100
103
  addGlobalFlags(command);
101
104
  command.action(async (options) => {
102
105
  const appName = options.app;
103
- await runCommand(runtime, "app.list-env", options, (context) => runAppListEnv(context, appName), {
106
+ const projectRef = options.project;
107
+ await runCommand(runtime, "app.list-env", options, (context) => runAppListEnv(context, appName, projectRef), {
104
108
  renderHuman: (context, descriptor, result) => renderAppListEnv(context, descriptor, result),
105
109
  renderJson: (result) => serializeAppListEnv(result)
106
110
  });
@@ -109,11 +113,12 @@ function createListEnvCommand(runtime) {
109
113
  }
110
114
  function createShowCommand(runtime) {
111
115
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("show"), runtime), "app.show");
112
- command.addOption(new Option("--app <name>", "App name"));
116
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name"));
113
117
  addGlobalFlags(command);
114
118
  command.action(async (options) => {
115
119
  const appName = options.app;
116
- await runCommand(runtime, "app.show", options, (context) => runAppShow(context, appName), {
120
+ const projectRef = options.project;
121
+ await runCommand(runtime, "app.show", options, (context) => runAppShow(context, appName, projectRef), {
117
122
  renderHuman: (context, descriptor, result) => renderAppShow(context, descriptor, result),
118
123
  renderJson: (result) => serializeAppShow(result)
119
124
  });
@@ -122,11 +127,12 @@ function createShowCommand(runtime) {
122
127
  }
123
128
  function createOpenCommand(runtime) {
124
129
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("open"), runtime), "app.open");
125
- command.addOption(new Option("--app <name>", "App name"));
130
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name"));
126
131
  addGlobalFlags(command);
127
132
  command.action(async (options) => {
128
133
  const appName = options.app;
129
- await runCommand(runtime, "app.open", options, (context) => runAppOpen(context, appName), {
134
+ const projectRef = options.project;
135
+ await runCommand(runtime, "app.open", options, (context) => runAppOpen(context, appName, projectRef), {
130
136
  renderHuman: (context, descriptor, result) => renderAppOpen(context, descriptor, result),
131
137
  renderJson: (result) => serializeAppOpen(result)
132
138
  });
@@ -135,12 +141,13 @@ function createOpenCommand(runtime) {
135
141
  }
136
142
  function createLogsCommand(runtime) {
137
143
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("logs"), runtime), "app.logs");
138
- command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--deployment <id>", "Deployment id"));
144
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name")).addOption(new Option("--deployment <id>", "Deployment id"));
139
145
  addGlobalFlags(command);
140
146
  command.action(async (options) => {
141
147
  const appName = options.app;
142
148
  const deploymentId = options.deployment;
143
- await runCommand(runtime, "app.logs", options, (context) => runAppLogs(context, appName, deploymentId), { renderHuman: () => [] });
149
+ const projectRef = options.project;
150
+ await runStreamingCommand(runtime, "app.logs", options, (context) => runAppLogs(context, appName, deploymentId, projectRef));
144
151
  });
145
152
  return command;
146
153
  }
@@ -149,11 +156,12 @@ function collectRepeatableValues(value, previous) {
149
156
  }
150
157
  function createListDeploysCommand(runtime) {
151
158
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("list-deploys"), runtime), "app.list-deploys");
152
- command.addOption(new Option("--app <name>", "App name"));
159
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name"));
153
160
  addGlobalFlags(command);
154
161
  command.action(async (options) => {
155
162
  const appName = options.app;
156
- await runCommand(runtime, "app.list-deploys", options, (context) => runAppListDeploys(context, appName), {
163
+ const projectRef = options.project;
164
+ await runCommand(runtime, "app.list-deploys", options, (context) => runAppListDeploys(context, appName, projectRef), {
157
165
  renderHuman: (context, descriptor, result) => renderAppListDeploys(context, descriptor, result),
158
166
  renderJson: (result) => serializeAppListDeploys(result)
159
167
  });
@@ -175,11 +183,12 @@ function createShowDeployCommand(runtime) {
175
183
  function createPromoteCommand(runtime) {
176
184
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("promote"), runtime), "app.promote");
177
185
  command.argument("<deployment>", "Deployment id");
178
- command.addOption(new Option("--app <name>", "App name"));
186
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name"));
179
187
  addGlobalFlags(command);
180
188
  command.action(async (deploymentId, options) => {
181
189
  const appName = options.app;
182
- await runCommand(runtime, "app.promote", options, (context) => runAppPromote(context, deploymentId, appName), {
190
+ const projectRef = options.project;
191
+ await runCommand(runtime, "app.promote", options, (context) => runAppPromote(context, deploymentId, appName, projectRef), {
183
192
  renderHuman: (context, descriptor, result) => renderAppPromote(context, descriptor, result),
184
193
  renderJson: (result) => serializeAppPromote(result)
185
194
  });
@@ -188,12 +197,13 @@ function createPromoteCommand(runtime) {
188
197
  }
189
198
  function createRollbackCommand(runtime) {
190
199
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("rollback"), runtime), "app.rollback");
191
- command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--to <deployment>", "Deployment id"));
200
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name")).addOption(new Option("--to <deployment>", "Deployment id"));
192
201
  addGlobalFlags(command);
193
202
  command.action(async (options) => {
194
203
  const appName = options.app;
195
204
  const deploymentId = options.to;
196
- await runCommand(runtime, "app.rollback", options, (context) => runAppRollback(context, appName, deploymentId), {
205
+ const projectRef = options.project;
206
+ await runCommand(runtime, "app.rollback", options, (context) => runAppRollback(context, appName, deploymentId, projectRef), {
197
207
  renderHuman: (context, descriptor, result) => renderAppRollback(context, descriptor, result),
198
208
  renderJson: (result) => serializeAppRollback(result)
199
209
  });
@@ -202,11 +212,12 @@ function createRollbackCommand(runtime) {
202
212
  }
203
213
  function createRemoveCommand(runtime) {
204
214
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("remove"), runtime), "app.remove");
205
- command.addOption(new Option("--app <name>", "App name"));
215
+ command.addOption(new Option("--app <name>", "App name")).addOption(new Option("--project <id-or-name>", "Project id or name"));
206
216
  addGlobalFlags(command);
207
217
  command.action(async (options) => {
208
218
  const appName = options.app;
209
- await runCommand(runtime, "app.remove", options, (context) => runAppRemove(context, appName), {
219
+ const projectRef = options.project;
220
+ await runCommand(runtime, "app.remove", options, (context) => runAppRemove(context, appName, projectRef), {
210
221
  renderHuman: (context, descriptor, result) => renderAppRemove(context, descriptor, result),
211
222
  renderJson: (result) => serializeAppRemove(result)
212
223
  });
@@ -1,8 +1,8 @@
1
1
  import { attachCommandDescriptor } from "../../shell/command-meta.js";
2
2
  import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
3
3
  import { configureRuntimeCommand } from "../../shell/runtime.js";
4
- import { runCommand } from "../../shell/command-runner.js";
5
4
  import { runAuthLogin, runAuthLogout, runAuthWhoAmI } from "../../controllers/auth.js";
5
+ import { runCommand } from "../../shell/command-runner.js";
6
6
  import { renderAuthSuccess } from "../../presenters/auth.js";
7
7
  import { Command, Option } from "commander";
8
8
  //#region src/commands/auth/index.ts
@@ -0,0 +1,87 @@
1
+ import { attachCommandDescriptor } from "../shell/command-meta.js";
2
+ import { addGlobalFlags } from "../shell/global-flags.js";
3
+ import { configureRuntimeCommand } from "../shell/runtime.js";
4
+ import { runCommand } from "../shell/command-runner.js";
5
+ import { runEnvAdd, runEnvList, runEnvRm, runEnvUpdate } from "../controllers/app-env.js";
6
+ import { renderEnvAdd, renderEnvList, renderEnvRm, renderEnvUpdate, serializeEnvAdd, serializeEnvList, serializeEnvRm, serializeEnvUpdate } from "../presenters/app-env.js";
7
+ import { Command, Option } from "commander";
8
+ //#region src/commands/env.ts
9
+ function createEnvCommand(runtime) {
10
+ const env = attachCommandDescriptor(configureRuntimeCommand(new Command("env"), runtime), "project.env");
11
+ env.description("Manage environment variables for the active project");
12
+ env.addCommand(createEnvAddCommand(runtime));
13
+ env.addCommand(createEnvUpdateCommand(runtime));
14
+ env.addCommand(createEnvListCommand(runtime));
15
+ env.addCommand(createEnvRmCommand(runtime));
16
+ return env;
17
+ }
18
+ function createEnvAddCommand(runtime) {
19
+ const command = attachCommandDescriptor(configureRuntimeCommand(new Command("add"), runtime), "project.env.add");
20
+ command.argument("<assignment>", "Variable assignment as KEY=VALUE or KEY from the current environment").addOption(new Option("--role <role>", "Project template scope (production or preview)").choices(["production", "preview"])).addOption(new Option("--project <id-or-name>", "Project id or name"));
21
+ addGlobalFlags(command);
22
+ command.action(async (assignment, options) => {
23
+ const roleName = options.role;
24
+ const projectRef = options.project;
25
+ await runCommand(runtime, "project.env.add", options, (context) => runEnvAdd(context, assignment, {
26
+ roleName,
27
+ projectRef
28
+ }), {
29
+ renderHuman: (context, descriptor, result) => renderEnvAdd(context, descriptor, result),
30
+ renderJson: (result) => serializeEnvAdd(result)
31
+ });
32
+ });
33
+ return command;
34
+ }
35
+ function createEnvUpdateCommand(runtime) {
36
+ const command = attachCommandDescriptor(configureRuntimeCommand(new Command("update"), runtime), "project.env.update");
37
+ command.argument("<assignment>", "Variable assignment as KEY=VALUE or KEY from the current environment").addOption(new Option("--role <role>", "Project template scope (production or preview)").choices(["production", "preview"])).addOption(new Option("--project <id-or-name>", "Project id or name"));
38
+ addGlobalFlags(command);
39
+ command.action(async (assignment, options) => {
40
+ const roleName = options.role;
41
+ const projectRef = options.project;
42
+ await runCommand(runtime, "project.env.update", options, (context) => runEnvUpdate(context, assignment, {
43
+ roleName,
44
+ projectRef
45
+ }), {
46
+ renderHuman: (context, descriptor, result) => renderEnvUpdate(context, descriptor, result),
47
+ renderJson: (result) => serializeEnvUpdate(result)
48
+ });
49
+ });
50
+ return command;
51
+ }
52
+ function createEnvListCommand(runtime) {
53
+ const command = attachCommandDescriptor(configureRuntimeCommand(new Command("list"), runtime), "project.env.list");
54
+ command.addOption(new Option("--role <role>", "Project template scope").choices(["production", "preview"])).addOption(new Option("--project <id-or-name>", "Project id or name"));
55
+ addGlobalFlags(command);
56
+ command.action(async (options) => {
57
+ const roleName = options.role;
58
+ const projectRef = options.project;
59
+ await runCommand(runtime, "project.env.list", options, (context) => runEnvList(context, {
60
+ roleName,
61
+ projectRef
62
+ }), {
63
+ renderHuman: (context, descriptor, result) => renderEnvList(context, descriptor, result),
64
+ renderJson: (result) => serializeEnvList(result)
65
+ });
66
+ });
67
+ return command;
68
+ }
69
+ function createEnvRmCommand(runtime) {
70
+ const command = attachCommandDescriptor(configureRuntimeCommand(new Command("rm"), runtime), "project.env.rm");
71
+ command.argument("<key>", "Variable key to remove").addOption(new Option("--role <role>", "Project template scope (production or preview)").choices(["production", "preview"])).addOption(new Option("--project <id-or-name>", "Project id or name"));
72
+ addGlobalFlags(command);
73
+ command.action(async (key, options) => {
74
+ const roleName = options.role;
75
+ const projectRef = options.project;
76
+ await runCommand(runtime, "project.env.rm", options, (context) => runEnvRm(context, key, {
77
+ roleName,
78
+ projectRef
79
+ }), {
80
+ renderHuman: (context, descriptor, result) => renderEnvRm(context, descriptor, result),
81
+ renderJson: (result) => serializeEnvRm(result)
82
+ });
83
+ });
84
+ return command;
85
+ }
86
+ //#endregion
87
+ export { createEnvCommand };
@@ -0,0 +1,36 @@
1
+ import { attachCommandDescriptor } from "../../shell/command-meta.js";
2
+ import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
3
+ import { configureRuntimeCommand } from "../../shell/runtime.js";
4
+ import { runGitConnect, runGitDisconnect } from "../../controllers/project.js";
5
+ import { runCommand } from "../../shell/command-runner.js";
6
+ import { renderGitConnect, renderGitDisconnect } from "../../presenters/project.js";
7
+ import { Command } from "commander";
8
+ //#region src/commands/git/index.ts
9
+ function createGitCommand(runtime) {
10
+ const git = attachCommandDescriptor(configureRuntimeCommand(new Command("git"), runtime), "git");
11
+ addCompactGlobalFlags(git);
12
+ git.addCommand(createGitConnectCommand(runtime));
13
+ git.addCommand(createGitDisconnectCommand(runtime));
14
+ return git;
15
+ }
16
+ function createGitConnectCommand(runtime) {
17
+ const command = attachCommandDescriptor(configureRuntimeCommand(new Command("connect"), runtime), "git.connect");
18
+ command.argument("[git-url]", "GitHub repository URL");
19
+ command.option("--project <id-or-name>", "Project id or name");
20
+ addGlobalFlags(command);
21
+ command.action(async (gitUrl, options) => {
22
+ await runCommand(runtime, "git.connect", options, (context) => runGitConnect(context, gitUrl, { project: typeof options.project === "string" ? options.project : void 0 }), { renderHuman: (context, descriptor, result) => renderGitConnect(context, descriptor, result) });
23
+ });
24
+ return command;
25
+ }
26
+ function createGitDisconnectCommand(runtime) {
27
+ const command = attachCommandDescriptor(configureRuntimeCommand(new Command("disconnect"), runtime), "git.disconnect");
28
+ command.option("--project <id-or-name>", "Project id or name");
29
+ addGlobalFlags(command);
30
+ command.action(async (options) => {
31
+ await runCommand(runtime, "git.disconnect", options, (context) => runGitDisconnect(context, { project: typeof options.project === "string" ? options.project : void 0 }), { renderHuman: (context, descriptor, result) => renderGitDisconnect(context, descriptor, result) });
32
+ });
33
+ return command;
34
+ }
35
+ //#endregion
36
+ export { createGitCommand };
@@ -1,9 +1,10 @@
1
1
  import { attachCommandDescriptor } from "../../shell/command-meta.js";
2
2
  import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
3
3
  import { configureRuntimeCommand } from "../../shell/runtime.js";
4
+ import { runProjectList, runProjectShow } from "../../controllers/project.js";
4
5
  import { runCommand } from "../../shell/command-runner.js";
5
- import { runProjectLink, runProjectList, runProjectShow } from "../../controllers/project.js";
6
- import { renderProjectLink, renderProjectList, renderProjectShow, serializeProjectList } from "../../presenters/project.js";
6
+ import { renderProjectList, renderProjectShow, serializeProjectList, serializeProjectShow } from "../../presenters/project.js";
7
+ import { createEnvCommand } from "../env.js";
7
8
  import { Command } from "commander";
8
9
  //#region src/commands/project/index.ts
9
10
  function createProjectCommand(runtime) {
@@ -11,7 +12,7 @@ function createProjectCommand(runtime) {
11
12
  addCompactGlobalFlags(project);
12
13
  project.addCommand(createProjectListCommand(runtime));
13
14
  project.addCommand(createProjectShowCommand(runtime));
14
- project.addCommand(createProjectLinkCommand(runtime));
15
+ project.addCommand(createEnvCommand(runtime));
15
16
  return project;
16
17
  }
17
18
  function createProjectListCommand(runtime) {
@@ -27,18 +28,14 @@ function createProjectListCommand(runtime) {
27
28
  }
28
29
  function createProjectShowCommand(runtime) {
29
30
  const command = attachCommandDescriptor(configureRuntimeCommand(new Command("show"), runtime), "project.show");
31
+ command.option("--project <id-or-name>", "Project id or name");
30
32
  addGlobalFlags(command);
31
33
  command.action(async (options) => {
32
- await runCommand(runtime, "project.show", options, (context) => runProjectShow(context), { renderHuman: (context, descriptor, result) => renderProjectShow(context, descriptor, result) });
33
- });
34
- return command;
35
- }
36
- function createProjectLinkCommand(runtime) {
37
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("link"), runtime), "project.link");
38
- command.argument("[project]", "Project id");
39
- addGlobalFlags(command);
40
- command.action(async (projectId, options) => {
41
- await runCommand(runtime, "project.link", options, (context) => runProjectLink(context, projectId), { renderHuman: (context, descriptor, result) => renderProjectLink(context, descriptor, result) });
34
+ const projectRef = options.project;
35
+ await runCommand(runtime, "project.show", options, (context) => runProjectShow(context, projectRef), {
36
+ renderHuman: (context, descriptor, result) => renderProjectShow(context, descriptor, result),
37
+ renderJson: (result) => serializeProjectShow(result)
38
+ });
42
39
  });
43
40
  return command;
44
41
  }