@prisma/cli 3.0.0-beta.21 → 3.0.0-beta.22
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.
- package/dist/adapters/mock-api.js +96 -0
- package/dist/adapters/token-storage.js +23 -0
- package/dist/cli2.js +2 -0
- package/dist/commands/database/index.js +92 -2
- package/dist/commands/init/index.js +32 -0
- package/dist/commands/project/index.js +51 -3
- package/dist/controllers/app.js +1 -1
- package/dist/controllers/database.js +249 -6
- package/dist/controllers/init.js +491 -0
- package/dist/controllers/project.js +326 -3
- package/dist/lib/agent/cli-command.js +4 -1
- package/dist/lib/agent/package-manager.js +1 -1
- package/dist/lib/auth/recipient.js +42 -0
- package/dist/lib/database/provider.js +148 -1
- package/dist/lib/project/interactive-setup.js +4 -4
- package/dist/lib/project/provider.js +92 -0
- package/dist/presenters/app.js +22 -7
- package/dist/presenters/database.js +175 -1
- package/dist/presenters/init.js +29 -0
- package/dist/presenters/project.js +90 -1
- package/dist/shell/command-meta.js +98 -0
- package/dist/shell/command-runner.js +7 -1
- package/dist/shell/errors.js +7 -1
- package/dist/shell/prompt.js +5 -2
- package/package.json +1 -1
|
@@ -32,6 +32,9 @@ var MockApi = class MockApi {
|
|
|
32
32
|
const workspaceIds = this.data.memberships.filter((membership) => membership.userId === userId).map((membership) => membership.workspaceId);
|
|
33
33
|
return this.data.workspaces.filter((workspace) => workspaceIds.includes(workspace.id));
|
|
34
34
|
}
|
|
35
|
+
listWorkspaces() {
|
|
36
|
+
return this.data.workspaces;
|
|
37
|
+
}
|
|
35
38
|
getWorkspace(workspaceId) {
|
|
36
39
|
return this.data.workspaces.find((workspace) => workspace.id === workspaceId);
|
|
37
40
|
}
|
|
@@ -47,6 +50,36 @@ var MockApi = class MockApi {
|
|
|
47
50
|
getProjectForWorkspace(workspaceId, projectId) {
|
|
48
51
|
return this.listProjectsForWorkspace(workspaceId).find((project) => project.id === projectId);
|
|
49
52
|
}
|
|
53
|
+
renameProject(projectId, name) {
|
|
54
|
+
const project = this.getProject(projectId);
|
|
55
|
+
if (!project) return;
|
|
56
|
+
project.name = name;
|
|
57
|
+
return project;
|
|
58
|
+
}
|
|
59
|
+
removeProject(projectId) {
|
|
60
|
+
const project = this.getProject(projectId);
|
|
61
|
+
if (!project) return { outcome: "not-found" };
|
|
62
|
+
if (this.data.deployments.some((deployment) => deployment.projectId === projectId)) return { outcome: "blocked" };
|
|
63
|
+
const removedDatabaseIds = new Set((this.data.databases ?? []).filter((database) => database.projectId === projectId).map((database) => database.id));
|
|
64
|
+
this.data.projects = this.data.projects.filter((candidate) => candidate.id !== projectId);
|
|
65
|
+
this.data.branches = this.data.branches.filter((branch) => branch.projectId !== projectId);
|
|
66
|
+
this.data.databases = (this.data.databases ?? []).filter((database) => database.projectId !== projectId);
|
|
67
|
+
this.data.databaseConnections = (this.data.databaseConnections ?? []).filter((connection) => !removedDatabaseIds.has(connection.databaseId));
|
|
68
|
+
return {
|
|
69
|
+
outcome: "removed",
|
|
70
|
+
project
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
transferProject(projectId, targetWorkspaceId) {
|
|
74
|
+
const project = this.getProject(projectId);
|
|
75
|
+
if (!project) return { outcome: "not-found" };
|
|
76
|
+
if (!this.getWorkspace(targetWorkspaceId)) return { outcome: "workspace-not-found" };
|
|
77
|
+
project.workspaceId = targetWorkspaceId;
|
|
78
|
+
return {
|
|
79
|
+
outcome: "transferred",
|
|
80
|
+
project
|
|
81
|
+
};
|
|
82
|
+
}
|
|
50
83
|
listBranchesForProject(projectId) {
|
|
51
84
|
return this.data.branches.filter((branch) => branch.projectId === projectId);
|
|
52
85
|
}
|
|
@@ -131,6 +164,69 @@ var MockApi = class MockApi {
|
|
|
131
164
|
this.data.databaseConnections = this.data.databaseConnections.filter((candidate) => candidate.id !== connectionId);
|
|
132
165
|
return connection;
|
|
133
166
|
}
|
|
167
|
+
getDatabaseUsage(databaseId, period) {
|
|
168
|
+
const defaults = (this.data.databaseUsage ?? []).find((record) => record.databaseId === databaseId) ?? {
|
|
169
|
+
databaseId,
|
|
170
|
+
period: {
|
|
171
|
+
start: "2026-06-01T00:00:00.000Z",
|
|
172
|
+
end: "2026-06-30T23:59:59.999Z"
|
|
173
|
+
},
|
|
174
|
+
metrics: {
|
|
175
|
+
operations: {
|
|
176
|
+
used: 0,
|
|
177
|
+
unit: "ops"
|
|
178
|
+
},
|
|
179
|
+
storage: {
|
|
180
|
+
used: 0,
|
|
181
|
+
unit: "GiB"
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
generatedAt: "2026-07-01T00:00:00.000Z"
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
period: {
|
|
188
|
+
start: period?.from ?? defaults.period.start,
|
|
189
|
+
end: period?.to ?? defaults.period.end
|
|
190
|
+
},
|
|
191
|
+
metrics: defaults.metrics,
|
|
192
|
+
generatedAt: defaults.generatedAt
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
listDatabaseBackups(databaseId, limit) {
|
|
196
|
+
const backups = (this.data.databaseBackups ?? []).filter((backup) => backup.databaseId === databaseId);
|
|
197
|
+
const limited = limit === void 0 ? backups : backups.slice(0, limit);
|
|
198
|
+
return {
|
|
199
|
+
backups: limited.map((backup) => ({
|
|
200
|
+
id: backup.id,
|
|
201
|
+
backupType: backup.backupType,
|
|
202
|
+
status: backup.status,
|
|
203
|
+
size: backup.size ?? null,
|
|
204
|
+
createdAt: backup.createdAt
|
|
205
|
+
})),
|
|
206
|
+
retentionDays: this.data.databaseBackupRetentionDays ?? null,
|
|
207
|
+
hasMore: limited.length < backups.length
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
restoreDatabase(input) {
|
|
211
|
+
const target = this.getDatabase(input.targetDatabaseId);
|
|
212
|
+
if (!target) return { outcome: "target-not-found" };
|
|
213
|
+
if (!(this.data.databaseBackups ?? []).find((candidate) => candidate.id === input.backupId && candidate.databaseId === input.sourceDatabaseId)) return { outcome: "backup-not-found" };
|
|
214
|
+
target.status = "recovering";
|
|
215
|
+
return {
|
|
216
|
+
outcome: "restored",
|
|
217
|
+
database: target
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
rotateDatabaseConnection(connectionId) {
|
|
221
|
+
const connection = this.getDatabaseConnection(connectionId);
|
|
222
|
+
if (!connection) return;
|
|
223
|
+
const connectionString = `postgresql://rotated-${connection.databaseId}-${connection.id}.example.prisma.io/postgres`;
|
|
224
|
+
connection.connectionString = connectionString;
|
|
225
|
+
return {
|
|
226
|
+
connection,
|
|
227
|
+
connectionString
|
|
228
|
+
};
|
|
229
|
+
}
|
|
134
230
|
};
|
|
135
231
|
//#endregion
|
|
136
232
|
export { MockApi };
|
|
@@ -77,6 +77,7 @@ var FileTokenStorage = class {
|
|
|
77
77
|
this.signal?.throwIfAborted();
|
|
78
78
|
try {
|
|
79
79
|
const credentials = await this.readCredentialsFromDisk();
|
|
80
|
+
if (this.options.pinnedWorkspaceId) return findTokensForWorkspace(credentials, this.options.pinnedWorkspaceId);
|
|
80
81
|
const context = await this.readAuthContext();
|
|
81
82
|
if (context.state.activeWorkspaceId) return findTokensForWorkspace(credentials, context.state.activeWorkspaceId);
|
|
82
83
|
const latest = findLatestValidTokens(credentials);
|
|
@@ -138,6 +139,9 @@ var FileTokenStorage = class {
|
|
|
138
139
|
this.signal?.throwIfAborted();
|
|
139
140
|
const credentials = await this.readCredentialsFromDisk();
|
|
140
141
|
const context = await this.ensureMigratedAuthContext(credentials);
|
|
142
|
+
return this.workspacesFromState(credentials, context);
|
|
143
|
+
}
|
|
144
|
+
workspacesFromState(credentials, context) {
|
|
141
145
|
return credentials.map((credential) => storedCredentialToTokens(credential)).filter((tokens) => tokens !== null).map((tokens) => {
|
|
142
146
|
const cached = context.state.workspaces[tokens.workspaceId];
|
|
143
147
|
const id = typeof cached?.id === "string" && cached.id.trim().length > 0 ? cached.id.trim() : tokens.workspaceId;
|
|
@@ -159,6 +163,24 @@ var FileTokenStorage = class {
|
|
|
159
163
|
async useWorkspace(workspaceRef) {
|
|
160
164
|
return this.withRefreshLock(() => this.useWorkspaceUnlocked(workspaceRef));
|
|
161
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Resolve a workspace ref (id, credential workspace id, or cached name)
|
|
168
|
+
* against the locally stored sessions without changing the active
|
|
169
|
+
* workspace. Read-only counterpart of useWorkspace: it reads the auth
|
|
170
|
+
* context as-is and never runs the legacy-state migration, so it writes
|
|
171
|
+
* nothing.
|
|
172
|
+
*/
|
|
173
|
+
async resolveWorkspace(workspaceRef) {
|
|
174
|
+
const ref = workspaceRef.trim();
|
|
175
|
+
if (!ref) throw new WorkspaceSelectionError("missing");
|
|
176
|
+
this.signal?.throwIfAborted();
|
|
177
|
+
const credentials = await this.readCredentialsFromDisk();
|
|
178
|
+
const context = await this.readAuthContext();
|
|
179
|
+
const matches = this.workspacesFromState(credentials, context).filter((workspace) => workspaceMatchesRef(workspace, ref));
|
|
180
|
+
if (matches.length === 0) throw new WorkspaceSelectionError("not-found", ref);
|
|
181
|
+
if (matches.length > 1) throw new WorkspaceSelectionError("ambiguous", ref, matches);
|
|
182
|
+
return matches[0];
|
|
183
|
+
}
|
|
162
184
|
async useWorkspaceUnlocked(workspaceRef) {
|
|
163
185
|
const ref = workspaceRef.trim();
|
|
164
186
|
if (!ref) throw new WorkspaceSelectionError("missing");
|
|
@@ -327,6 +349,7 @@ var FileTokenStorage = class {
|
|
|
327
349
|
await this.writeAuthContext(context.state);
|
|
328
350
|
}
|
|
329
351
|
async maybeActivateWorkspaceId(workspaceId) {
|
|
352
|
+
if (this.options.pinnedWorkspaceId) return;
|
|
330
353
|
const context = await this.readAuthContext();
|
|
331
354
|
if (this.options.activateOnSetTokens === false && context.exists && context.state.activeWorkspaceId && context.state.activeWorkspaceId !== workspaceId) return;
|
|
332
355
|
context.state.activeWorkspaceId = workspaceId;
|
package/dist/cli2.js
CHANGED
|
@@ -12,6 +12,7 @@ import { createBranchCommand } from "./commands/branch/index.js";
|
|
|
12
12
|
import { createBuildCommand } from "./commands/build/index.js";
|
|
13
13
|
import { createDatabaseCommand } from "./commands/database/index.js";
|
|
14
14
|
import { createGitCommand } from "./commands/git/index.js";
|
|
15
|
+
import { createInitCommand } from "./commands/init/index.js";
|
|
15
16
|
import { createProjectCommand } from "./commands/project/index.js";
|
|
16
17
|
import { getCliName, getCliVersion } from "./lib/version.js";
|
|
17
18
|
import { runVersion } from "./controllers/version.js";
|
|
@@ -48,6 +49,7 @@ function createProgram(runtime) {
|
|
|
48
49
|
program.addOption(new Option("--version", "Print the CLI version and exit."));
|
|
49
50
|
program.name("prisma").showSuggestionAfterError();
|
|
50
51
|
program.addCommand(createVersionCommand(runtime));
|
|
52
|
+
program.addCommand(createInitCommand(runtime));
|
|
51
53
|
program.addCommand(createAgentCommand(runtime));
|
|
52
54
|
program.addCommand(createAuthCommand(runtime));
|
|
53
55
|
program.addCommand(createProjectCommand(runtime));
|
|
@@ -2,8 +2,8 @@ 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
4
|
import { runCommand } from "../../shell/command-runner.js";
|
|
5
|
-
import { runDatabaseConnectionCreate, runDatabaseConnectionList, runDatabaseConnectionRemove, runDatabaseCreate, runDatabaseList, runDatabaseRemove, runDatabaseShow } from "../../controllers/database.js";
|
|
6
|
-
import { renderDatabaseConnectionCreate, renderDatabaseConnectionCreateStdout, renderDatabaseConnectionList, renderDatabaseConnectionRemove, renderDatabaseCreate, renderDatabaseCreateStdout, renderDatabaseList, renderDatabaseRemove, renderDatabaseShow, serializeDatabaseConnectionCreate, serializeDatabaseConnectionList, serializeDatabaseConnectionRemove, serializeDatabaseCreate, serializeDatabaseList, serializeDatabaseRemove, serializeDatabaseShow } from "../../presenters/database.js";
|
|
5
|
+
import { runDatabaseBackupList, runDatabaseConnectionCreate, runDatabaseConnectionList, runDatabaseConnectionRemove, runDatabaseConnectionRotate, runDatabaseCreate, runDatabaseList, runDatabaseRemove, runDatabaseRestore, runDatabaseShow, runDatabaseUsage } from "../../controllers/database.js";
|
|
6
|
+
import { renderDatabaseBackupList, renderDatabaseConnectionCreate, renderDatabaseConnectionCreateStdout, renderDatabaseConnectionList, renderDatabaseConnectionRemove, renderDatabaseConnectionRotate, renderDatabaseConnectionRotateStdout, renderDatabaseCreate, renderDatabaseCreateStdout, renderDatabaseList, renderDatabaseRemove, renderDatabaseRestore, renderDatabaseShow, renderDatabaseUsage, serializeDatabaseBackupList, serializeDatabaseConnectionCreate, serializeDatabaseConnectionList, serializeDatabaseConnectionRemove, serializeDatabaseConnectionRotate, serializeDatabaseCreate, serializeDatabaseList, serializeDatabaseRemove, serializeDatabaseRestore, serializeDatabaseShow, serializeDatabaseUsage } from "../../presenters/database.js";
|
|
7
7
|
import { Command, Option } from "commander";
|
|
8
8
|
//#region src/commands/database/index.ts
|
|
9
9
|
function createDatabaseCommand(runtime) {
|
|
@@ -12,7 +12,10 @@ function createDatabaseCommand(runtime) {
|
|
|
12
12
|
database.addCommand(createDatabaseListCommand(runtime));
|
|
13
13
|
database.addCommand(createDatabaseShowCommand(runtime));
|
|
14
14
|
database.addCommand(createDatabaseCreateCommand(runtime));
|
|
15
|
+
database.addCommand(createDatabaseUsageCommand(runtime));
|
|
16
|
+
database.addCommand(createDatabaseRestoreCommand(runtime));
|
|
15
17
|
database.addCommand(createDatabaseRemoveCommand(runtime));
|
|
18
|
+
database.addCommand(createDatabaseBackupCommand(runtime));
|
|
16
19
|
database.addCommand(createDatabaseConnectionCommand(runtime));
|
|
17
20
|
return database;
|
|
18
21
|
}
|
|
@@ -75,6 +78,78 @@ function createDatabaseCreateCommand(runtime) {
|
|
|
75
78
|
});
|
|
76
79
|
return command;
|
|
77
80
|
}
|
|
81
|
+
function createDatabaseUsageCommand(runtime) {
|
|
82
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("usage"), runtime), "database.usage");
|
|
83
|
+
command.argument("<database>", "Database id or name").addOption(new Option("--from <iso-date>", "Start of the usage period")).addOption(new Option("--to <iso-date>", "End of the usage period"));
|
|
84
|
+
addProjectAndBranchOptions(command);
|
|
85
|
+
addGlobalFlags(command);
|
|
86
|
+
command.action(async (databaseRef, options) => {
|
|
87
|
+
const projectRef = options.project;
|
|
88
|
+
const branchName = options.branch;
|
|
89
|
+
const from = options.from;
|
|
90
|
+
const to = options.to;
|
|
91
|
+
await runCommand(runtime, "database.usage", options, (context) => runDatabaseUsage(context, databaseRef, {
|
|
92
|
+
projectRef,
|
|
93
|
+
branchName,
|
|
94
|
+
from,
|
|
95
|
+
to
|
|
96
|
+
}), {
|
|
97
|
+
renderHuman: (context, descriptor, result) => renderDatabaseUsage(context, descriptor, result),
|
|
98
|
+
renderJson: (result) => serializeDatabaseUsage(result)
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
return command;
|
|
102
|
+
}
|
|
103
|
+
function createDatabaseRestoreCommand(runtime) {
|
|
104
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("restore"), runtime), "database.restore");
|
|
105
|
+
command.argument("<database>", "Target database id or name").addOption(new Option("--backup <backup-id>", "Backup to restore from")).addOption(new Option("--source-database <database>", "Database the backup belongs to (defaults to the target)")).addOption(new Option("--confirm <database-id>", "Exact target database id required to restore"));
|
|
106
|
+
addProjectAndBranchOptions(command);
|
|
107
|
+
addGlobalFlags(command);
|
|
108
|
+
command.action(async (databaseRef, options) => {
|
|
109
|
+
const projectRef = options.project;
|
|
110
|
+
const branchName = options.branch;
|
|
111
|
+
const backupId = options.backup;
|
|
112
|
+
const sourceDatabaseRef = options.sourceDatabase;
|
|
113
|
+
const confirm = options.confirm;
|
|
114
|
+
await runCommand(runtime, "database.restore", options, (context) => runDatabaseRestore(context, databaseRef, {
|
|
115
|
+
projectRef,
|
|
116
|
+
branchName,
|
|
117
|
+
backupId,
|
|
118
|
+
sourceDatabaseRef,
|
|
119
|
+
confirm
|
|
120
|
+
}), {
|
|
121
|
+
renderHuman: (context, descriptor, result) => renderDatabaseRestore(context, descriptor, result),
|
|
122
|
+
renderJson: (result) => serializeDatabaseRestore(result)
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return command;
|
|
126
|
+
}
|
|
127
|
+
function createDatabaseBackupCommand(runtime) {
|
|
128
|
+
const backup = attachCommandDescriptor(configureRuntimeCommand(new Command("backup"), runtime), "database.backup");
|
|
129
|
+
addCompactGlobalFlags(backup);
|
|
130
|
+
backup.addCommand(createDatabaseBackupListCommand(runtime));
|
|
131
|
+
return backup;
|
|
132
|
+
}
|
|
133
|
+
function createDatabaseBackupListCommand(runtime) {
|
|
134
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("list"), runtime), "database.backup.list");
|
|
135
|
+
command.argument("<database>", "Database id or name").addOption(new Option("--limit <n>", "Maximum number of backups to return"));
|
|
136
|
+
addProjectAndBranchOptions(command);
|
|
137
|
+
addGlobalFlags(command);
|
|
138
|
+
command.action(async (databaseRef, options) => {
|
|
139
|
+
const projectRef = options.project;
|
|
140
|
+
const branchName = options.branch;
|
|
141
|
+
const limit = options.limit;
|
|
142
|
+
await runCommand(runtime, "database.backup.list", options, (context) => runDatabaseBackupList(context, databaseRef, {
|
|
143
|
+
projectRef,
|
|
144
|
+
branchName,
|
|
145
|
+
limit
|
|
146
|
+
}), {
|
|
147
|
+
renderHuman: (context, descriptor, result) => renderDatabaseBackupList(context, descriptor, result),
|
|
148
|
+
renderJson: (result) => serializeDatabaseBackupList(result)
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
return command;
|
|
152
|
+
}
|
|
78
153
|
function createDatabaseRemoveCommand(runtime) {
|
|
79
154
|
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("remove"), runtime), "database.remove");
|
|
80
155
|
command.argument("<database>", "Database id or name").addOption(new Option("--confirm <database-id>", "Exact database id required to remove"));
|
|
@@ -100,9 +175,24 @@ function createDatabaseConnectionCommand(runtime) {
|
|
|
100
175
|
addCompactGlobalFlags(connection);
|
|
101
176
|
connection.addCommand(createDatabaseConnectionListCommand(runtime));
|
|
102
177
|
connection.addCommand(createDatabaseConnectionCreateCommand(runtime));
|
|
178
|
+
connection.addCommand(createDatabaseConnectionRotateCommand(runtime));
|
|
103
179
|
connection.addCommand(createDatabaseConnectionRemoveCommand(runtime));
|
|
104
180
|
return connection;
|
|
105
181
|
}
|
|
182
|
+
function createDatabaseConnectionRotateCommand(runtime) {
|
|
183
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("rotate"), runtime), "database.connection.rotate");
|
|
184
|
+
command.argument("<connection>", "Connection id").addOption(new Option("--confirm <connection-id>", "Exact connection id required to rotate"));
|
|
185
|
+
addGlobalFlags(command);
|
|
186
|
+
command.action(async (connectionRef, options) => {
|
|
187
|
+
const confirm = options.confirm;
|
|
188
|
+
await runCommand(runtime, "database.connection.rotate", options, (context) => runDatabaseConnectionRotate(context, connectionRef, { confirm }), {
|
|
189
|
+
renderStdout: (context, descriptor, result) => renderDatabaseConnectionRotateStdout(context, descriptor, result),
|
|
190
|
+
renderHuman: (context, descriptor, result) => renderDatabaseConnectionRotate(context, descriptor, result),
|
|
191
|
+
renderJson: (result) => serializeDatabaseConnectionRotate(result)
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
return command;
|
|
195
|
+
}
|
|
106
196
|
function createDatabaseConnectionListCommand(runtime) {
|
|
107
197
|
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("list"), runtime), "database.connection.list");
|
|
108
198
|
command.argument("<database>", "Database id or name");
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { runInit } from "../../controllers/init.js";
|
|
6
|
+
import { renderInit, serializeInit } from "../../presenters/init.js";
|
|
7
|
+
import { Command, Option } from "commander";
|
|
8
|
+
//#region src/commands/init/index.ts
|
|
9
|
+
function createInitCommand(runtime) {
|
|
10
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("init"), runtime), "init");
|
|
11
|
+
command.addOption(new Option("--framework <framework>", "Framework override; detected when omitted")).addOption(new Option("--entry <path>", "Source entrypoint for entrypoint frameworks (Bun, Hono)")).addOption(new Option("--http-port <port>", "HTTP port the app listens on")).addOption(new Option("--region <region>", "Region used when deploy creates the app")).addOption(new Option("--name <app-name>", "App name")).addOption(new Option("--link", "Link this directory to a Project")).addOption(new Option("--no-link", "Skip the Project link step")).addOption(new Option("--project <id-or-name>", "Project to link this directory to")).addOption(new Option("--install", "Install @prisma/compute-sdk for config types")).addOption(new Option("--no-install", "Skip the types install step"));
|
|
12
|
+
addGlobalFlags(command);
|
|
13
|
+
command.action(async (options) => {
|
|
14
|
+
const flags = options;
|
|
15
|
+
await runCommand(runtime, "init", options, (context) => runInit(context, {
|
|
16
|
+
framework: flags.framework,
|
|
17
|
+
entry: flags.entry,
|
|
18
|
+
httpPort: flags.httpPort,
|
|
19
|
+
region: flags.region,
|
|
20
|
+
name: flags.name,
|
|
21
|
+
link: flags.link,
|
|
22
|
+
project: flags.project,
|
|
23
|
+
install: flags.install
|
|
24
|
+
}), {
|
|
25
|
+
renderHuman: (context, descriptor, result) => renderInit(context, descriptor, result),
|
|
26
|
+
renderJson: (result) => serializeInit(result)
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
return command;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createInitCommand };
|
|
@@ -2,10 +2,10 @@ 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
4
|
import { runCommand } from "../../shell/command-runner.js";
|
|
5
|
-
import { runProjectCreate, runProjectLink, runProjectList, runProjectShow } from "../../controllers/project.js";
|
|
6
|
-
import { renderProjectList, renderProjectSetup, renderProjectShow, serializeProjectList, serializeProjectSetup, serializeProjectShow } from "../../presenters/project.js";
|
|
5
|
+
import { runProjectCreate, runProjectLink, runProjectList, runProjectRemove, runProjectRename, runProjectShow, runProjectTransfer } from "../../controllers/project.js";
|
|
6
|
+
import { renderProjectList, renderProjectRemove, renderProjectRename, renderProjectSetup, renderProjectShow, renderProjectTransfer, serializeProjectList, serializeProjectRemove, serializeProjectRename, serializeProjectSetup, serializeProjectShow, serializeProjectTransfer } from "../../presenters/project.js";
|
|
7
7
|
import { createEnvCommand } from "../env.js";
|
|
8
|
-
import { Command } from "commander";
|
|
8
|
+
import { Command, Option } from "commander";
|
|
9
9
|
//#region src/commands/project/index.ts
|
|
10
10
|
function createProjectCommand(runtime) {
|
|
11
11
|
const project = attachCommandDescriptor(configureRuntimeCommand(new Command("project"), runtime), "project");
|
|
@@ -14,9 +14,57 @@ function createProjectCommand(runtime) {
|
|
|
14
14
|
project.addCommand(createProjectShowCommand(runtime));
|
|
15
15
|
project.addCommand(createProjectCreateCommand(runtime));
|
|
16
16
|
project.addCommand(createProjectLinkCommand(runtime));
|
|
17
|
+
project.addCommand(createProjectRenameCommand(runtime));
|
|
18
|
+
project.addCommand(createProjectRemoveCommand(runtime));
|
|
19
|
+
project.addCommand(createProjectTransferCommand(runtime));
|
|
17
20
|
project.addCommand(createEnvCommand(runtime));
|
|
18
21
|
return project;
|
|
19
22
|
}
|
|
23
|
+
function createProjectRenameCommand(runtime) {
|
|
24
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("rename"), runtime), "project.rename");
|
|
25
|
+
command.argument("<name>", "New project name").addOption(new Option("--project <id-or-name>", "Project id or name"));
|
|
26
|
+
addGlobalFlags(command);
|
|
27
|
+
command.action(async (name, options) => {
|
|
28
|
+
const projectRef = options.project;
|
|
29
|
+
await runCommand(runtime, "project.rename", options, (context) => runProjectRename(context, name, { project: projectRef }), {
|
|
30
|
+
renderHuman: (context, descriptor, result) => renderProjectRename(context, descriptor, result),
|
|
31
|
+
renderJson: (result) => serializeProjectRename(result)
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return command;
|
|
35
|
+
}
|
|
36
|
+
function createProjectRemoveCommand(runtime) {
|
|
37
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("remove"), runtime), "project.remove");
|
|
38
|
+
command.argument("<project>", "Project id or name").addOption(new Option("--confirm <project-id>", "Exact project id required to remove"));
|
|
39
|
+
addGlobalFlags(command);
|
|
40
|
+
command.action(async (projectRef, options) => {
|
|
41
|
+
const confirm = options.confirm;
|
|
42
|
+
await runCommand(runtime, "project.remove", options, (context) => runProjectRemove(context, projectRef, { confirm }), {
|
|
43
|
+
renderHuman: (context, descriptor, result) => renderProjectRemove(context, descriptor, result),
|
|
44
|
+
renderJson: (result) => serializeProjectRemove(result)
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return command;
|
|
48
|
+
}
|
|
49
|
+
function createProjectTransferCommand(runtime) {
|
|
50
|
+
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("transfer"), runtime), "project.transfer");
|
|
51
|
+
command.argument("<project>", "Project id or name").addOption(new Option("--to-workspace <id-or-name>", "Locally authenticated workspace to receive the project")).addOption(new Option("--recipient-token <token>", "Access token for the receiving workspace")).addOption(new Option("--confirm <project-id>", "Exact project id required to transfer"));
|
|
52
|
+
addGlobalFlags(command);
|
|
53
|
+
command.action(async (projectRef, options) => {
|
|
54
|
+
const toWorkspace = options.toWorkspace;
|
|
55
|
+
const recipientToken = options.recipientToken;
|
|
56
|
+
const confirm = options.confirm;
|
|
57
|
+
await runCommand(runtime, "project.transfer", options, (context) => runProjectTransfer(context, projectRef, {
|
|
58
|
+
toWorkspace,
|
|
59
|
+
recipientToken,
|
|
60
|
+
confirm
|
|
61
|
+
}), {
|
|
62
|
+
renderHuman: (context, descriptor, result) => renderProjectTransfer(context, descriptor, result),
|
|
63
|
+
renderJson: (result) => serializeProjectTransfer(result)
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
return command;
|
|
67
|
+
}
|
|
20
68
|
function createProjectCreateCommand(runtime) {
|
|
21
69
|
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("create"), runtime), "project.create");
|
|
22
70
|
command.argument("<name>", "Project name");
|
package/dist/controllers/app.js
CHANGED
|
@@ -2528,4 +2528,4 @@ function toOptionalEnvVars(envVars) {
|
|
|
2528
2528
|
return Object.keys(envVars).length > 0 ? envVars : void 0;
|
|
2529
2529
|
}
|
|
2530
2530
|
//#endregion
|
|
2531
|
-
export { runAppBuild, runAppDeploy, runAppDomainAdd, runAppDomainRemove, runAppDomainRetry, runAppDomainShow, runAppDomainWait, runAppListDeploys, runAppLogs, runAppOpen, runAppPromote, runAppRemove, runAppRollback, runAppRun, runAppShow, runAppShowDeploy };
|
|
2531
|
+
export { detectDeployFramework, runAppBuild, runAppDeploy, runAppDomainAdd, runAppDomainRemove, runAppDomainRetry, runAppDomainShow, runAppDomainWait, runAppListDeploys, runAppLogs, runAppOpen, runAppPromote, runAppRemove, runAppRollback, runAppRun, runAppShow, runAppShowDeploy };
|