@prisma/cli 3.0.0-beta.3 → 3.0.0-beta.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.
- package/README.md +3 -2
- package/dist/commands/app/index.js +4 -2
- package/dist/commands/branch/index.js +2 -27
- package/dist/controllers/app-env.js +152 -21
- package/dist/controllers/app.js +26 -50
- package/dist/controllers/branch.js +73 -47
- package/dist/lib/app/preview-provider.js +26 -6
- package/dist/lib/app/production-deploy-gate.js +160 -0
- package/dist/lib/git/local-branch.js +41 -0
- package/dist/presenters/app-env.js +14 -3
- package/dist/presenters/branch.js +29 -101
- package/dist/shell/command-meta.js +6 -24
- package/dist/shell/ui.js +4 -1
- package/dist/use-cases/branch.js +20 -68
- package/dist/use-cases/create-cli-gateways.js +2 -17
- package/package.json +1 -1
|
@@ -36,6 +36,18 @@ function createPreviewAppProvider(client, options) {
|
|
|
36
36
|
signal: options?.signal
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
|
+
async resolveBranch(projectId, options) {
|
|
40
|
+
const branch = await resolveOrCreateBranch(client, {
|
|
41
|
+
projectId,
|
|
42
|
+
gitName: options.branchName,
|
|
43
|
+
signal: options.signal
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
id: branch.id,
|
|
47
|
+
name: branch.gitName,
|
|
48
|
+
role: branch.role
|
|
49
|
+
};
|
|
50
|
+
},
|
|
39
51
|
async removeApp(appId, options) {
|
|
40
52
|
const appResult = await sdk.showService({
|
|
41
53
|
serviceId: appId,
|
|
@@ -316,17 +328,19 @@ async function listBranches(client, options) {
|
|
|
316
328
|
signal: options.signal
|
|
317
329
|
});
|
|
318
330
|
if (result.error || !result.data) throw apiCallError("Failed to list branches", result.response, result.error);
|
|
319
|
-
return result.data.data
|
|
331
|
+
return result.data.data.map((branch) => ({
|
|
332
|
+
id: branch.id,
|
|
333
|
+
gitName: branch.gitName,
|
|
334
|
+
isDefault: branch.isDefault,
|
|
335
|
+
role: branch.role
|
|
336
|
+
}));
|
|
320
337
|
}
|
|
321
338
|
async function resolveOrCreateBranch(client, options) {
|
|
322
339
|
const existing = (await listBranches(client, options))[0];
|
|
323
340
|
if (existing) return existing;
|
|
324
341
|
const result = await client.POST("/v1/projects/{projectId}/branches", {
|
|
325
342
|
params: { path: { projectId: options.projectId } },
|
|
326
|
-
body: {
|
|
327
|
-
gitName: options.gitName,
|
|
328
|
-
isDefault: options.gitName === "main"
|
|
329
|
-
},
|
|
343
|
+
body: { gitName: options.gitName },
|
|
330
344
|
signal: options.signal
|
|
331
345
|
});
|
|
332
346
|
if (result.error || !result.data) {
|
|
@@ -336,7 +350,13 @@ async function resolveOrCreateBranch(client, options) {
|
|
|
336
350
|
}
|
|
337
351
|
throw apiCallError(`Failed to create branch "${options.gitName}"`, result.response, result.error);
|
|
338
352
|
}
|
|
339
|
-
|
|
353
|
+
const branch = result.data.data;
|
|
354
|
+
return {
|
|
355
|
+
id: branch.id,
|
|
356
|
+
gitName: branch.gitName,
|
|
357
|
+
isDefault: branch.isDefault,
|
|
358
|
+
role: branch.role
|
|
359
|
+
};
|
|
340
360
|
}
|
|
341
361
|
async function listComputeServices(client, options) {
|
|
342
362
|
const services = [];
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { CliError } from "../../shell/errors.js";
|
|
2
|
+
import { canPrompt } from "../../shell/runtime.js";
|
|
3
|
+
import { confirmPrompt } from "../../shell/prompt.js";
|
|
4
|
+
//#region src/lib/app/production-deploy-gate.ts
|
|
5
|
+
async function enforceProductionDeployGate(context, provider, options) {
|
|
6
|
+
if (options.branchKind !== "production") return;
|
|
7
|
+
if (!options.appId) {
|
|
8
|
+
renderFirstProductionDeployLine(context, options.appName);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const currentLiveDeployment = resolveCurrentProductionDeployment(await provider.listDeployments(options.appId).catch((error) => {
|
|
12
|
+
throw productionDeployInspectionFailedError(error);
|
|
13
|
+
}));
|
|
14
|
+
if (!currentLiveDeployment) {
|
|
15
|
+
renderFirstProductionDeployLine(context, options.appName);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!options.prod) throw productionDeployRequiresFlagError();
|
|
19
|
+
if (context.flags.yes) {
|
|
20
|
+
renderProductionDeployYesLine(context);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!canPrompt(context)) throw productionDeployConfirmationRequiredError(options.appName);
|
|
24
|
+
renderProductionDeployConfirmation(context, currentLiveDeployment);
|
|
25
|
+
if (!await confirmPrompt({
|
|
26
|
+
input: context.runtime.stdin,
|
|
27
|
+
output: context.output.stderr,
|
|
28
|
+
message: "Deploy to production?",
|
|
29
|
+
initialValue: false
|
|
30
|
+
})) throw productionDeployCancelledError();
|
|
31
|
+
}
|
|
32
|
+
function resolveCurrentProductionDeployment(result) {
|
|
33
|
+
if (result.deployments.length === 0) return null;
|
|
34
|
+
if (result.app.liveDeploymentId) {
|
|
35
|
+
const live = result.deployments.find((deployment) => deployment.id === result.app.liveDeploymentId);
|
|
36
|
+
if (live) return live;
|
|
37
|
+
}
|
|
38
|
+
return result.deployments.find((deployment) => deployment.live === true) ?? result.deployments[0] ?? null;
|
|
39
|
+
}
|
|
40
|
+
function renderFirstProductionDeployLine(context, appName) {
|
|
41
|
+
if (context.flags.json || context.flags.quiet) return;
|
|
42
|
+
context.output.stderr.write(`First deploy of "${appName}" -- promoting to production.\n\n`);
|
|
43
|
+
}
|
|
44
|
+
function renderProductionDeployYesLine(context) {
|
|
45
|
+
if (context.flags.json || context.flags.quiet) return;
|
|
46
|
+
context.output.stderr.write("Deploying to production (--prod --yes).\n\n");
|
|
47
|
+
}
|
|
48
|
+
function renderProductionDeployConfirmation(context, currentLiveDeployment) {
|
|
49
|
+
if (context.flags.json || context.flags.quiet) return;
|
|
50
|
+
const lines = [
|
|
51
|
+
"This will deploy to production and replace the live deployment.",
|
|
52
|
+
"",
|
|
53
|
+
` Current live: ${currentLiveDeployment.id} deployed ${formatDeploymentAge(currentLiveDeployment.createdAt)}`,
|
|
54
|
+
" New deploy: will be built from your local code",
|
|
55
|
+
""
|
|
56
|
+
];
|
|
57
|
+
context.output.stderr.write(`${lines.join("\n")}\n`);
|
|
58
|
+
}
|
|
59
|
+
function formatDeploymentAge(createdAt) {
|
|
60
|
+
const createdAtMs = Date.parse(createdAt);
|
|
61
|
+
if (!Number.isFinite(createdAtMs)) return createdAt;
|
|
62
|
+
const elapsedMs = Math.max(0, Date.now() - createdAtMs);
|
|
63
|
+
for (const unit of [
|
|
64
|
+
{
|
|
65
|
+
label: "day",
|
|
66
|
+
ms: 1440 * 60 * 1e3
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
label: "hour",
|
|
70
|
+
ms: 3600 * 1e3
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
label: "minute",
|
|
74
|
+
ms: 60 * 1e3
|
|
75
|
+
}
|
|
76
|
+
]) if (elapsedMs >= unit.ms) {
|
|
77
|
+
const value = Math.floor(elapsedMs / unit.ms);
|
|
78
|
+
return `${value} ${unit.label}${value === 1 ? "" : "s"} ago`;
|
|
79
|
+
}
|
|
80
|
+
return "less than a minute ago";
|
|
81
|
+
}
|
|
82
|
+
function productionDeployRequiresFlagError() {
|
|
83
|
+
return new CliError({
|
|
84
|
+
code: "PROD_DEPLOY_REQUIRES_FLAG",
|
|
85
|
+
domain: "app",
|
|
86
|
+
summary: "Production deploy requires --prod",
|
|
87
|
+
why: "The resolved Branch is production and this App already has a production deployment.",
|
|
88
|
+
fix: "Re-run with --prod, or deploy from a preview Branch.",
|
|
89
|
+
exitCode: 2,
|
|
90
|
+
nextActions: [{
|
|
91
|
+
kind: "run-command",
|
|
92
|
+
journey: "deploy-app",
|
|
93
|
+
label: "Deploy to production",
|
|
94
|
+
command: "prisma-cli app deploy --prod"
|
|
95
|
+
}, {
|
|
96
|
+
kind: "run-command",
|
|
97
|
+
journey: "deploy-app",
|
|
98
|
+
label: "Create a preview branch",
|
|
99
|
+
commands: ["git checkout -b <branch-name>", "prisma-cli app deploy"]
|
|
100
|
+
}],
|
|
101
|
+
humanLines: [
|
|
102
|
+
"This would deploy to production.",
|
|
103
|
+
"",
|
|
104
|
+
"Production deploys require explicit intent. Re-run with:",
|
|
105
|
+
"",
|
|
106
|
+
" prisma app deploy --prod",
|
|
107
|
+
"",
|
|
108
|
+
"Or deploy a preview from a feature branch:",
|
|
109
|
+
"",
|
|
110
|
+
" git checkout -b <branch-name>",
|
|
111
|
+
" prisma app deploy"
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function productionDeployConfirmationRequiredError(appName) {
|
|
116
|
+
return new CliError({
|
|
117
|
+
code: "CONFIRMATION_REQUIRED",
|
|
118
|
+
domain: "app",
|
|
119
|
+
summary: "Production deploy requires confirmation in the current mode",
|
|
120
|
+
why: "This command cannot prompt for production deploy confirmation in the current mode.",
|
|
121
|
+
fix: `Pass --prod --yes to confirm deployment of "${appName}" to production.`,
|
|
122
|
+
exitCode: 1,
|
|
123
|
+
nextSteps: ["prisma-cli app deploy --prod --yes"],
|
|
124
|
+
nextActions: [{
|
|
125
|
+
kind: "run-command",
|
|
126
|
+
journey: "deploy-app",
|
|
127
|
+
label: "Deploy to production non-interactively",
|
|
128
|
+
command: "prisma-cli app deploy --prod --yes"
|
|
129
|
+
}]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function productionDeployCancelledError() {
|
|
133
|
+
return new CliError({
|
|
134
|
+
code: "CONFIRMATION_REQUIRED",
|
|
135
|
+
domain: "app",
|
|
136
|
+
summary: "Production deploy cancelled",
|
|
137
|
+
why: null,
|
|
138
|
+
fix: null,
|
|
139
|
+
exitCode: 0,
|
|
140
|
+
humanLines: ["Cancelled."]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function productionDeployInspectionFailedError(error) {
|
|
144
|
+
return new CliError({
|
|
145
|
+
code: "DEPLOY_FAILED",
|
|
146
|
+
domain: "app",
|
|
147
|
+
summary: "Failed to inspect production deployments",
|
|
148
|
+
why: error instanceof Error ? error.message : String(error),
|
|
149
|
+
fix: "Retry the command, or rerun with --trace for more detailed diagnostics.",
|
|
150
|
+
debug: formatDebugDetails(error),
|
|
151
|
+
exitCode: 1,
|
|
152
|
+
nextSteps: ["prisma-cli app list-deploys"]
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function formatDebugDetails(error) {
|
|
156
|
+
if (error instanceof Error) return error.stack ?? error.message;
|
|
157
|
+
return typeof error === "string" ? error : null;
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
export { enforceProductionDeployGate };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { access, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/lib/git/local-branch.ts
|
|
4
|
+
async function readLocalGitBranch(cwd, signal) {
|
|
5
|
+
const headPath = await resolveGitHeadPath(path.join(cwd, ".git"), signal);
|
|
6
|
+
if (!headPath) return null;
|
|
7
|
+
try {
|
|
8
|
+
const head = (await readFile(headPath, {
|
|
9
|
+
encoding: "utf8",
|
|
10
|
+
signal
|
|
11
|
+
})).trim();
|
|
12
|
+
if (head.startsWith("ref: refs/heads/")) return head.slice(16);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (signal.aborted) throw error;
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
async function resolveGitHeadPath(gitPath, signal) {
|
|
20
|
+
signal.throwIfAborted();
|
|
21
|
+
try {
|
|
22
|
+
const raw = await readFile(gitPath, {
|
|
23
|
+
encoding: "utf8",
|
|
24
|
+
signal
|
|
25
|
+
});
|
|
26
|
+
if (raw.startsWith("gitdir:")) return path.join(path.resolve(path.dirname(gitPath), raw.slice(7).trim()), "HEAD");
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (signal.aborted) throw error;
|
|
29
|
+
}
|
|
30
|
+
signal.throwIfAborted();
|
|
31
|
+
try {
|
|
32
|
+
await access(path.join(gitPath, "HEAD"));
|
|
33
|
+
signal.throwIfAborted();
|
|
34
|
+
return path.join(gitPath, "HEAD");
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (signal.aborted) throw error;
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { readLocalGitBranch };
|
|
@@ -2,8 +2,18 @@ import { renderList, renderShow, serializeList } from "../output/patterns.js";
|
|
|
2
2
|
//#region src/presenters/app-env.ts
|
|
3
3
|
function scopeLabel(scope) {
|
|
4
4
|
if (scope.kind === "role") return scope.role ?? "unknown";
|
|
5
|
+
if (scope.kind === "overview") return "overview";
|
|
5
6
|
return `branch:${scope.branchName ?? scope.branchId ?? "unknown"}`;
|
|
6
7
|
}
|
|
8
|
+
function listTargetLabel(result) {
|
|
9
|
+
const target = result.target;
|
|
10
|
+
if (target.source === "overview") return "overview";
|
|
11
|
+
if (target.branchName) {
|
|
12
|
+
const suffix = target.branchExists === false ? " (not created yet)" : "";
|
|
13
|
+
return `branch:${target.branchName} -> ${target.envMap}${suffix}`;
|
|
14
|
+
}
|
|
15
|
+
return scopeLabel(result.scope);
|
|
16
|
+
}
|
|
7
17
|
function renderEnvAdd(context, descriptor, result) {
|
|
8
18
|
return renderShow({
|
|
9
19
|
title: "Setting a new environment variable.",
|
|
@@ -75,8 +85,8 @@ function renderEnvList(context, descriptor, result) {
|
|
|
75
85
|
title: "Listing environment variables for the selected scope.",
|
|
76
86
|
descriptor,
|
|
77
87
|
parentContext: {
|
|
78
|
-
key: "
|
|
79
|
-
value:
|
|
88
|
+
key: "target",
|
|
89
|
+
value: listTargetLabel(result)
|
|
80
90
|
},
|
|
81
91
|
items: result.variables.map((variable) => ({
|
|
82
92
|
noun: "variable",
|
|
@@ -91,8 +101,9 @@ function serializeEnvList(result) {
|
|
|
91
101
|
return {
|
|
92
102
|
projectId: result.projectId,
|
|
93
103
|
scope: result.scope,
|
|
104
|
+
target: result.target,
|
|
94
105
|
...serializeList({
|
|
95
|
-
context: {
|
|
106
|
+
context: { target: listTargetLabel(result) },
|
|
96
107
|
items: result.variables.map((variable) => ({
|
|
97
108
|
noun: "variable",
|
|
98
109
|
label: `${variable.key} (${variable.source})`,
|
|
@@ -1,111 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { formatColumns } from "../shell/ui.js";
|
|
2
|
+
import { formatDescriptorLabel } from "../shell/command-meta.js";
|
|
2
3
|
//#region src/presenters/branch.ts
|
|
3
4
|
function renderBranchList(context, descriptor, result) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
5
|
+
const ui = context.ui;
|
|
6
|
+
const lines = [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing branches for the resolved project.")}`, ""];
|
|
7
|
+
const rail = ui.dim("│");
|
|
8
|
+
lines.push(`${rail} ${ui.accent("project:")} ${result.projectName}`);
|
|
9
|
+
lines.push(rail);
|
|
10
|
+
if (result.branches.length === 0) {
|
|
11
|
+
lines.push(`${rail} ${ui.dim("No branches found.")}`);
|
|
12
|
+
return lines;
|
|
13
|
+
}
|
|
14
|
+
const widths = [
|
|
15
|
+
Math.max(4, ...result.branches.map((branch) => branch.name.length)),
|
|
16
|
+
Math.max(4, ...result.branches.map((branch) => branch.role.length)),
|
|
17
|
+
Math.max(7, ...result.branches.map((branch) => branch.envMap.length))
|
|
18
|
+
];
|
|
19
|
+
lines.push(`${rail} ${ui.accent(formatColumns([
|
|
20
|
+
"Name",
|
|
21
|
+
"Role",
|
|
22
|
+
"Env map"
|
|
23
|
+
], widths))}`);
|
|
24
|
+
for (const branch of result.branches) lines.push(`${rail} ${formatColumns([
|
|
25
|
+
branch.name,
|
|
26
|
+
branch.role,
|
|
27
|
+
branch.envMap
|
|
28
|
+
], widths)}`);
|
|
29
|
+
return lines;
|
|
19
30
|
}
|
|
20
31
|
function serializeBranchList(result) {
|
|
21
|
-
return serializeList({
|
|
22
|
-
context: { project: result.projectName ?? "not resolved" },
|
|
23
|
-
items: result.branches.map((branch) => ({
|
|
24
|
-
noun: "branch",
|
|
25
|
-
label: branch.name,
|
|
26
|
-
id: branch.id,
|
|
27
|
-
status: branch.active ? "active" : null
|
|
28
|
-
}))
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function serializeBranchShow(result) {
|
|
32
32
|
return {
|
|
33
33
|
projectId: result.projectId,
|
|
34
34
|
projectName: result.projectName,
|
|
35
|
-
|
|
36
|
-
name: result.branch.name,
|
|
37
|
-
kind: result.branch.kind,
|
|
38
|
-
active: result.branch.active,
|
|
39
|
-
remoteState: result.branch.remoteState,
|
|
40
|
-
liveDeployment: result.branch.liveDeployment
|
|
41
|
-
}
|
|
35
|
+
branches: result.branches
|
|
42
36
|
};
|
|
43
37
|
}
|
|
44
|
-
function renderBranchShow(context, descriptor, result) {
|
|
45
|
-
const fields = [
|
|
46
|
-
{
|
|
47
|
-
key: "project",
|
|
48
|
-
value: result.projectName ?? "not resolved",
|
|
49
|
-
tone: result.projectName ? "default" : "dim"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
key: "branch",
|
|
53
|
-
value: result.branch.name,
|
|
54
|
-
tone: result.branch.active ? "success" : "default"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
key: "kind",
|
|
58
|
-
value: result.branch.kind
|
|
59
|
-
}
|
|
60
|
-
];
|
|
61
|
-
if (result.branch.liveDeployment) {
|
|
62
|
-
fields.push({
|
|
63
|
-
key: "status",
|
|
64
|
-
value: result.branch.liveDeployment.status,
|
|
65
|
-
tone: toneForDeploymentStatus(result.branch.liveDeployment.status)
|
|
66
|
-
});
|
|
67
|
-
if (result.branch.liveDeployment.url) fields.push({
|
|
68
|
-
key: "url",
|
|
69
|
-
value: result.branch.liveDeployment.url,
|
|
70
|
-
tone: "link"
|
|
71
|
-
});
|
|
72
|
-
} else if (!result.branch.remoteState) fields.push({
|
|
73
|
-
key: "remote state",
|
|
74
|
-
value: "not created yet",
|
|
75
|
-
tone: "dim"
|
|
76
|
-
});
|
|
77
|
-
return renderShow({
|
|
78
|
-
title: "Showing the current active branch context.",
|
|
79
|
-
descriptor,
|
|
80
|
-
fields
|
|
81
|
-
}, context.ui);
|
|
82
|
-
}
|
|
83
|
-
function toneForDeploymentStatus(status) {
|
|
84
|
-
if (status === "ready" || status === "active" || status === "healthy") return "success";
|
|
85
|
-
if (status === "pending" || status === "building" || status === "starting") return "warning";
|
|
86
|
-
if (status === "failed" || status === "error") return "error";
|
|
87
|
-
return "default";
|
|
88
|
-
}
|
|
89
|
-
function renderBranchUse(context, descriptor, result) {
|
|
90
|
-
return renderMutate({
|
|
91
|
-
title: "Changing the local default branch context.",
|
|
92
|
-
descriptor,
|
|
93
|
-
context: [{
|
|
94
|
-
key: "project",
|
|
95
|
-
value: result.projectName ?? "not resolved",
|
|
96
|
-
tone: result.projectName ? "default" : "dim"
|
|
97
|
-
}, {
|
|
98
|
-
key: "branch",
|
|
99
|
-
value: result.branch.name
|
|
100
|
-
}],
|
|
101
|
-
operationDescription: "Applying active branch change",
|
|
102
|
-
operationCount: 1,
|
|
103
|
-
details: ["Active branch updated in local CLI state for this repo."],
|
|
104
|
-
alerts: result.branch.kind === "production" ? [{
|
|
105
|
-
tone: "warning",
|
|
106
|
-
text: "Production is protected and durable. Use with care"
|
|
107
|
-
}] : void 0
|
|
108
|
-
}, context.ui);
|
|
109
|
-
}
|
|
110
38
|
//#endregion
|
|
111
|
-
export { renderBranchList,
|
|
39
|
+
export { renderBranchList, serializeBranchList };
|
|
@@ -69,8 +69,8 @@ const DESCRIPTORS = [
|
|
|
69
69
|
{
|
|
70
70
|
id: "branch",
|
|
71
71
|
path: ["prisma", "branch"],
|
|
72
|
-
description: "View your
|
|
73
|
-
examples: ["prisma-cli branch list"
|
|
72
|
+
description: "View your Platform branches",
|
|
73
|
+
examples: ["prisma-cli branch list"]
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
id: "git",
|
|
@@ -153,29 +153,9 @@ const DESCRIPTORS = [
|
|
|
153
153
|
"branch",
|
|
154
154
|
"list"
|
|
155
155
|
],
|
|
156
|
-
description: "List
|
|
156
|
+
description: "List Platform branches for the resolved project",
|
|
157
157
|
examples: ["prisma-cli branch list", "prisma-cli branch list --json"]
|
|
158
158
|
},
|
|
159
|
-
{
|
|
160
|
-
id: "branch.show",
|
|
161
|
-
path: [
|
|
162
|
-
"prisma",
|
|
163
|
-
"branch",
|
|
164
|
-
"show"
|
|
165
|
-
],
|
|
166
|
-
description: "Show the Platform branch matching your current Git branch",
|
|
167
|
-
examples: ["prisma-cli branch show", "prisma-cli branch show --json"]
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
id: "branch.use",
|
|
171
|
-
path: [
|
|
172
|
-
"prisma",
|
|
173
|
-
"branch",
|
|
174
|
-
"use"
|
|
175
|
-
],
|
|
176
|
-
description: "Change the local default branch context.",
|
|
177
|
-
examples: ["prisma-cli branch use", "prisma-cli branch use production"]
|
|
178
|
-
},
|
|
179
159
|
{
|
|
180
160
|
id: "app.build",
|
|
181
161
|
path: [
|
|
@@ -216,6 +196,7 @@ const DESCRIPTORS = [
|
|
|
216
196
|
"prisma-cli app deploy --app my-app --env DATABASE_URL=postgresql://example",
|
|
217
197
|
"prisma-cli app deploy --app my-app --framework nextjs --http-port 3000",
|
|
218
198
|
"prisma-cli app deploy --branch feat-login --framework hono",
|
|
199
|
+
"prisma-cli app deploy --prod --yes",
|
|
219
200
|
"pnpm dlx skills@latest add prisma/prisma-cli/skills#cli-v<cli-version> --all",
|
|
220
201
|
"prisma-cli app deploy --framework bun --entry src/server.ts"
|
|
221
202
|
]
|
|
@@ -378,7 +359,7 @@ const DESCRIPTORS = [
|
|
|
378
359
|
],
|
|
379
360
|
description: "Manage environment variables for the active project",
|
|
380
361
|
examples: [
|
|
381
|
-
"prisma-cli project env list
|
|
362
|
+
"prisma-cli project env list",
|
|
382
363
|
"prisma-cli project env add STRIPE_KEY=sk_test_xxx --role production",
|
|
383
364
|
"prisma-cli project env add DATABASE_URL=postgresql://branch --branch feature/foo",
|
|
384
365
|
"prisma-cli project env remove STRIPE_KEY --role preview"
|
|
@@ -425,6 +406,7 @@ const DESCRIPTORS = [
|
|
|
425
406
|
],
|
|
426
407
|
description: "List environment variable metadata for a scope (no values).",
|
|
427
408
|
examples: [
|
|
409
|
+
"prisma-cli project env list",
|
|
428
410
|
"prisma-cli project env list --role production",
|
|
429
411
|
"prisma-cli project env list --role preview",
|
|
430
412
|
"prisma-cli project env list --branch feature/foo"
|
package/dist/shell/ui.js
CHANGED
|
@@ -48,6 +48,9 @@ function renderNextSteps(steps) {
|
|
|
48
48
|
...steps.map((step) => `- ${step}`)
|
|
49
49
|
];
|
|
50
50
|
}
|
|
51
|
+
function formatColumns(columns, widths) {
|
|
52
|
+
return columns.map((value, index) => padDisplay(value, widths[index])).join(" ").trimEnd();
|
|
53
|
+
}
|
|
51
54
|
function wrapText(text, width, indent = "") {
|
|
52
55
|
return wrapAnsi(text, width, {
|
|
53
56
|
hard: false,
|
|
@@ -74,4 +77,4 @@ function formatHeaderValue(ui, row) {
|
|
|
74
77
|
return value;
|
|
75
78
|
}
|
|
76
79
|
//#endregion
|
|
77
|
-
export { createShellUi, maskValue, padDisplay, renderCommandHeader, renderNextSteps, renderSummaryLine, wrapText };
|
|
80
|
+
export { createShellUi, formatColumns, maskValue, padDisplay, renderCommandHeader, renderNextSteps, renderSummaryLine, wrapText };
|
package/dist/use-cases/branch.js
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
//#region src/use-cases/branch.ts
|
|
2
2
|
function createBranchUseCases(dependencies) {
|
|
3
|
-
return {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
projectId,
|
|
18
|
-
projectName: resolveProjectName(dependencies.projectGateway, projectId),
|
|
19
|
-
branch: buildBranchDetail(dependencies.branchGateway, projectId, activeBranch)
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
use: async (branchName) => {
|
|
23
|
-
await dependencies.branchStateGateway.writeActiveBranch(branchName);
|
|
24
|
-
const projectId = await dependencies.projectStateGateway.readRememberedProjectId();
|
|
25
|
-
return {
|
|
26
|
-
projectId,
|
|
27
|
-
projectName: resolveProjectName(dependencies.projectGateway, projectId),
|
|
28
|
-
branch: buildBranchDetail(dependencies.branchGateway, projectId, branchName)
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
};
|
|
3
|
+
return { list: async () => {
|
|
4
|
+
const projectId = await dependencies.projectStateGateway.readRememberedProjectId();
|
|
5
|
+
if (!projectId) return {
|
|
6
|
+
projectId: "",
|
|
7
|
+
projectName: "not resolved",
|
|
8
|
+
branches: []
|
|
9
|
+
};
|
|
10
|
+
const remoteBranches = await listRemoteBranches(dependencies.branchGateway, projectId);
|
|
11
|
+
return {
|
|
12
|
+
projectId,
|
|
13
|
+
projectName: resolveProjectName(dependencies.projectGateway, projectId) ?? "not resolved",
|
|
14
|
+
branches: buildBranchSummaries(remoteBranches)
|
|
15
|
+
};
|
|
16
|
+
} };
|
|
32
17
|
}
|
|
33
18
|
function resolveProjectName(projectGateway, projectId) {
|
|
34
19
|
if (!projectId) return null;
|
|
@@ -38,38 +23,13 @@ async function listRemoteBranches(branchGateway, projectId) {
|
|
|
38
23
|
if (!projectId) return [];
|
|
39
24
|
return branchGateway.listBranchesForProject(projectId);
|
|
40
25
|
}
|
|
41
|
-
function buildBranchSummaries(
|
|
42
|
-
|
|
43
|
-
for (const branch of remoteBranches) byName.set(branch.name, {
|
|
26
|
+
function buildBranchSummaries(remoteBranches) {
|
|
27
|
+
return sortBranches(remoteBranches.map((branch) => ({
|
|
44
28
|
id: branch.id,
|
|
45
29
|
name: branch.name,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
if (!byName.has(activeBranch)) byName.set(activeBranch, {
|
|
51
|
-
id: activeBranch,
|
|
52
|
-
name: activeBranch,
|
|
53
|
-
kind: toBranchKind(activeBranch),
|
|
54
|
-
active: true,
|
|
55
|
-
remoteState: false
|
|
56
|
-
});
|
|
57
|
-
return sortBranches([...byName.values()]);
|
|
58
|
-
}
|
|
59
|
-
function buildBranchDetail(branchGateway, projectId, branchName) {
|
|
60
|
-
const kind = toBranchKind(branchName);
|
|
61
|
-
const remoteBranch = projectId ? branchGateway.getBranchForProject(projectId, branchName) : void 0;
|
|
62
|
-
return {
|
|
63
|
-
name: branchName,
|
|
64
|
-
kind,
|
|
65
|
-
active: true,
|
|
66
|
-
remoteState: Boolean(remoteBranch),
|
|
67
|
-
liveDeployment: remoteBranch && remoteBranch.currentDeploymentId ? toLiveDeployment(branchGateway.getDeployment(remoteBranch.currentDeploymentId)) : null
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function toBranchKind(name) {
|
|
71
|
-
if (name === "production") return "production";
|
|
72
|
-
return "preview";
|
|
30
|
+
role: branch.role,
|
|
31
|
+
envMap: branch.role
|
|
32
|
+
})));
|
|
73
33
|
}
|
|
74
34
|
function sortBranches(branches) {
|
|
75
35
|
return branches.slice().sort((left, right) => {
|
|
@@ -80,16 +40,8 @@ function sortBranches(branches) {
|
|
|
80
40
|
});
|
|
81
41
|
}
|
|
82
42
|
function branchOrder(branch) {
|
|
83
|
-
if (branch.
|
|
43
|
+
if (branch.role === "production") return 0;
|
|
84
44
|
return 1;
|
|
85
45
|
}
|
|
86
|
-
function toLiveDeployment(deployment) {
|
|
87
|
-
if (!deployment) return null;
|
|
88
|
-
return {
|
|
89
|
-
id: deployment.id,
|
|
90
|
-
status: deployment.status,
|
|
91
|
-
url: deployment.url
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
46
|
//#endregion
|
|
95
47
|
export { createBranchUseCases };
|
|
@@ -29,16 +29,9 @@ function createCliUseCaseGateways(context) {
|
|
|
29
29
|
getProjectForWorkspace: (workspaceId, projectId) => context.api.getProjectForWorkspace(workspaceId, projectId)
|
|
30
30
|
},
|
|
31
31
|
branchGateway: {
|
|
32
|
-
listBranchesForProject: (projectId) => context.api.listBranchesForProject(projectId)
|
|
33
|
-
...branch,
|
|
34
|
-
kind: branch.name === "production" ? "production" : "preview"
|
|
35
|
-
})),
|
|
32
|
+
listBranchesForProject: (projectId) => context.api.listBranchesForProject(projectId),
|
|
36
33
|
getBranchForProject: (projectId, name) => {
|
|
37
|
-
|
|
38
|
-
return branch ? {
|
|
39
|
-
...branch,
|
|
40
|
-
kind: branch.name === "production" ? "production" : "preview"
|
|
41
|
-
} : void 0;
|
|
34
|
+
return context.api.getBranchForProject(projectId, name);
|
|
42
35
|
},
|
|
43
36
|
getDeployment: (deploymentId) => context.api.getDeployment(deploymentId)
|
|
44
37
|
},
|
|
@@ -55,14 +48,6 @@ function createCliUseCaseGateways(context) {
|
|
|
55
48
|
clearAuthSession: async () => {
|
|
56
49
|
await context.stateStore.clearAuthSession();
|
|
57
50
|
}
|
|
58
|
-
},
|
|
59
|
-
branchStateGateway: {
|
|
60
|
-
readActiveBranch: async () => {
|
|
61
|
-
return (await context.stateStore.read()).branch.active;
|
|
62
|
-
},
|
|
63
|
-
writeActiveBranch: async (branchName) => {
|
|
64
|
-
await context.stateStore.setActiveBranch(branchName);
|
|
65
|
-
}
|
|
66
51
|
}
|
|
67
52
|
};
|
|
68
53
|
}
|