@prisma/cli 3.0.0-alpha.3 → 3.0.0-alpha.5
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/git.js +49 -0
- package/dist/adapters/local-state.js +38 -0
- package/dist/cli2.js +58 -4
- package/dist/commands/app/index.js +30 -19
- package/dist/commands/auth/index.js +1 -1
- package/dist/commands/env.js +25 -9
- package/dist/commands/git/index.js +36 -0
- package/dist/commands/project/index.js +8 -13
- package/dist/commands/version/index.js +18 -0
- package/dist/controllers/app-env.js +23 -21
- package/dist/controllers/app.js +159 -91
- package/dist/controllers/auth.js +2 -2
- package/dist/controllers/branch.js +1 -1
- package/dist/controllers/project.js +451 -161
- package/dist/controllers/version.js +12 -0
- package/dist/lib/app/env-config.js +13 -2
- package/dist/lib/auth/auth-ops.js +54 -9
- package/dist/lib/auth/client.js +2 -2
- package/dist/lib/auth/guard.js +1 -1
- package/dist/lib/project/resolution.js +151 -0
- package/dist/lib/version.js +55 -0
- package/dist/output/patterns.js +0 -1
- package/dist/presenters/app.js +9 -1
- package/dist/presenters/branch.js +6 -6
- package/dist/presenters/project.js +84 -44
- package/dist/presenters/version.js +29 -0
- package/dist/shell/command-meta.js +41 -11
- package/dist/shell/errors.js +4 -1
- package/dist/shell/global-flags.js +2 -1
- package/dist/use-cases/auth.js +4 -7
- package/dist/use-cases/branch.js +20 -20
- package/dist/use-cases/create-cli-gateways.js +3 -13
- package/dist/use-cases/project.js +2 -48
- package/package.json +1 -1
- package/dist/adapters/config.js +0 -74
|
@@ -20,10 +20,21 @@ function resolveEnvScope(flags, options) {
|
|
|
20
20
|
}
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
-
function parseKeyValuePositional(raw, command) {
|
|
23
|
+
function parseKeyValuePositional(raw, command, env = process.env) {
|
|
24
24
|
if (!raw) throw usageError(`prisma-cli project env ${command} requires KEY=VALUE`, "No KEY=VALUE positional argument was supplied.", "Pass the variable as KEY=VALUE, e.g. STRIPE_KEY=sk_test_xxx.", [`prisma-cli project env ${command} STRIPE_KEY=sk_test_xxx --role production`], "app");
|
|
25
25
|
const separatorIndex = raw.indexOf("=");
|
|
26
|
-
if (separatorIndex === -1)
|
|
26
|
+
if (separatorIndex === -1) {
|
|
27
|
+
if (KEY_SHAPE.test(raw)) {
|
|
28
|
+
validateKey(raw, command);
|
|
29
|
+
const value = env[raw];
|
|
30
|
+
if (typeof value === "string" && value.length > 0) return {
|
|
31
|
+
key: raw,
|
|
32
|
+
value
|
|
33
|
+
};
|
|
34
|
+
throw usageError(`Value for "${raw}" was not provided`, `No KEY=VALUE assignment was supplied, and ${raw} is not set in the current environment.`, "Pass KEY=VALUE or export the variable before running the command.", [`prisma-cli project env ${command} ${raw}=value --role production`, `${raw}=value prisma-cli project env ${command} ${raw} --role production`], "app");
|
|
35
|
+
}
|
|
36
|
+
throw usageError(`KEY=VALUE argument is missing the = separator`, `"${raw}" does not contain an = character.`, "Pass the variable as KEY=VALUE, e.g. STRIPE_KEY=sk_test_xxx.", [`prisma-cli project env ${command} STRIPE_KEY=sk_test_xxx --role production`], "app");
|
|
37
|
+
}
|
|
27
38
|
const key = raw.slice(0, separatorIndex);
|
|
28
39
|
const value = raw.slice(separatorIndex + 1);
|
|
29
40
|
validateKey(key, command);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { SERVICE_TOKEN_ENV_VAR } from "./client.js";
|
|
1
2
|
import { FileTokenStorage } from "../../adapters/token-storage.js";
|
|
2
3
|
import { requireComputeAuth } from "./guard.js";
|
|
3
4
|
import { login } from "./login.js";
|
|
4
5
|
//#region src/lib/auth/auth-ops.ts
|
|
6
|
+
const WORKSPACE_SUB_PREFIX = "workspace:";
|
|
5
7
|
function decodeJwtPayload(token) {
|
|
6
8
|
try {
|
|
7
9
|
const payload = token.split(".")[1];
|
|
@@ -15,6 +17,13 @@ function emailFromClaims(claims) {
|
|
|
15
17
|
const email = claims.email;
|
|
16
18
|
return typeof email === "string" && email.trim().length > 0 ? email.trim() : null;
|
|
17
19
|
}
|
|
20
|
+
function workspaceIdFromClaims(claims) {
|
|
21
|
+
const sub = claims.sub;
|
|
22
|
+
if (typeof sub !== "string") return null;
|
|
23
|
+
if (!sub.startsWith(WORKSPACE_SUB_PREFIX)) return null;
|
|
24
|
+
const id = sub.slice(10).trim();
|
|
25
|
+
return id.length > 0 ? id : null;
|
|
26
|
+
}
|
|
18
27
|
async function performLogin(env) {
|
|
19
28
|
await login({
|
|
20
29
|
tokenStorage: new FileTokenStorage(env),
|
|
@@ -22,23 +31,60 @@ async function performLogin(env) {
|
|
|
22
31
|
});
|
|
23
32
|
}
|
|
24
33
|
async function readAuthState(env) {
|
|
34
|
+
const rawServiceToken = env[SERVICE_TOKEN_ENV_VAR];
|
|
35
|
+
if (rawServiceToken !== void 0) {
|
|
36
|
+
const serviceToken = rawServiceToken.trim();
|
|
37
|
+
if (serviceToken.length === 0) throw new Error(`${SERVICE_TOKEN_ENV_VAR} is set but empty. Provide a valid token or unset the variable.`);
|
|
38
|
+
return readServiceTokenAuthState(serviceToken, env);
|
|
39
|
+
}
|
|
25
40
|
const tokens = await new FileTokenStorage(env).getTokens();
|
|
26
41
|
if (!tokens) return {
|
|
27
42
|
authenticated: false,
|
|
28
43
|
provider: null,
|
|
29
44
|
user: null,
|
|
30
|
-
workspace: null
|
|
31
|
-
|
|
45
|
+
workspace: null
|
|
46
|
+
};
|
|
47
|
+
const claims = decodeJwtPayload(tokens.accessToken);
|
|
48
|
+
return buildAuthState({
|
|
49
|
+
workspaceIdFromCredential: tokens.workspaceId,
|
|
50
|
+
claims,
|
|
51
|
+
env
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function readServiceTokenAuthState(token, env) {
|
|
55
|
+
const claims = decodeJwtPayload(token);
|
|
56
|
+
const workspaceId = workspaceIdFromClaims(claims);
|
|
57
|
+
if (!workspaceId) return {
|
|
58
|
+
authenticated: false,
|
|
59
|
+
provider: null,
|
|
60
|
+
user: null,
|
|
61
|
+
workspace: null
|
|
32
62
|
};
|
|
33
|
-
|
|
63
|
+
return buildAuthState({
|
|
64
|
+
workspaceIdFromCredential: workspaceId,
|
|
65
|
+
claims,
|
|
66
|
+
env
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function buildAuthState({ workspaceIdFromCredential, claims, env }) {
|
|
70
|
+
let workspaceId = workspaceIdFromCredential;
|
|
71
|
+
let workspaceName = workspaceIdFromCredential;
|
|
34
72
|
const client = await requireComputeAuth(env);
|
|
35
|
-
let workspaceId = tokens.workspaceId;
|
|
36
|
-
let workspaceName = tokens.workspaceId;
|
|
37
73
|
if (client) try {
|
|
38
|
-
const { data } = await client.GET("/v1/workspaces/{id}", { params: { path: { id:
|
|
39
|
-
if (
|
|
74
|
+
const { data, response } = await client.GET("/v1/workspaces/{id}", { params: { path: { id: workspaceIdFromCredential } } });
|
|
75
|
+
if (response?.status === 401) return {
|
|
76
|
+
authenticated: false,
|
|
77
|
+
provider: null,
|
|
78
|
+
user: null,
|
|
79
|
+
workspace: null
|
|
80
|
+
};
|
|
81
|
+
if (data?.data?.id) {
|
|
82
|
+
workspaceId = data.data.id;
|
|
83
|
+
workspaceName = data.data.id;
|
|
84
|
+
}
|
|
40
85
|
if (data?.data?.name) workspaceName = data.data.name;
|
|
41
86
|
} catch {}
|
|
87
|
+
const email = emailFromClaims(claims);
|
|
42
88
|
return {
|
|
43
89
|
authenticated: true,
|
|
44
90
|
provider: null,
|
|
@@ -46,8 +92,7 @@ async function readAuthState(env) {
|
|
|
46
92
|
workspace: {
|
|
47
93
|
id: workspaceId,
|
|
48
94
|
name: workspaceName
|
|
49
|
-
}
|
|
50
|
-
linkedProjectId: null
|
|
95
|
+
}
|
|
51
96
|
};
|
|
52
97
|
}
|
|
53
98
|
async function performLogout(env) {
|
package/dist/lib/auth/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
3
|
//#region src/lib/auth/client.ts
|
|
4
4
|
const CLIENT_ID = "cmm3lndn701oo0uefvxzo0ivw";
|
|
5
|
-
const SERVICE_TOKEN_ENV_VAR = "
|
|
5
|
+
const SERVICE_TOKEN_ENV_VAR = "PRISMA_SERVICE_TOKEN";
|
|
6
6
|
const AUTH_FILE_ENV_VAR = "PRISMA_COMPUTE_AUTH_FILE";
|
|
7
7
|
function getApiBaseUrl(env = process.env) {
|
|
8
8
|
return env.PRISMA_MANAGEMENT_API_URL?.trim() || "https://api.prisma.io";
|
package/dist/lib/auth/guard.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createManagementApiClient, createManagementApiSdk } from "@prisma/manag
|
|
|
6
6
|
* Resolve authentication and return a ManagementApiClient.
|
|
7
7
|
*
|
|
8
8
|
* Priority:
|
|
9
|
-
* 1.
|
|
9
|
+
* 1. PRISMA_SERVICE_TOKEN env var → service token (CI / headless)
|
|
10
10
|
* 2. Stored OAuth tokens → SDK with auto-refresh
|
|
11
11
|
*
|
|
12
12
|
* Returns null if not authenticated.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { CliError } from "../../shell/errors.js";
|
|
2
|
+
import { canPrompt } from "../../shell/runtime.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
//#region src/lib/project/resolution.ts
|
|
6
|
+
async function resolveProjectTarget(options) {
|
|
7
|
+
const projects = await options.listProjects();
|
|
8
|
+
if (options.explicitProject) return rememberIfRequested(options, resolveExplicitProject(options.explicitProject, projects, options.workspace), "explicit");
|
|
9
|
+
const platformMapping = await resolveDurablePlatformMapping();
|
|
10
|
+
if (platformMapping) return rememberIfRequested(options, platformMapping, "platform-mapping");
|
|
11
|
+
const remembered = await options.context.stateStore.readRememberedProject(options.workspace.id);
|
|
12
|
+
let staleRemembered = false;
|
|
13
|
+
if (remembered) {
|
|
14
|
+
const matched = projects.find((project) => project.id === remembered.id);
|
|
15
|
+
if (matched) return rememberIfRequested(options, matched, "remembered-local");
|
|
16
|
+
staleRemembered = true;
|
|
17
|
+
}
|
|
18
|
+
const packageName = await readPackageName(options.context.runtime.cwd);
|
|
19
|
+
if (packageName) {
|
|
20
|
+
const matches = projects.filter((project) => projectMatchesPackageName(project, packageName));
|
|
21
|
+
if (matches.length === 1) return rememberIfRequested(options, matches[0], "package-name");
|
|
22
|
+
if (matches.length > 1) return resolveAmbiguousProject(options, matches, "package-name");
|
|
23
|
+
}
|
|
24
|
+
if (options.allowCreate && options.createProject) {
|
|
25
|
+
const inferredName = packageName ?? path.basename(options.context.runtime.cwd);
|
|
26
|
+
if (inferredName) {
|
|
27
|
+
const existing = projects.filter((project) => projectMatchesPackageName(project, inferredName));
|
|
28
|
+
if (existing.length === 1) return rememberIfRequested(options, existing[0], "package-name");
|
|
29
|
+
if (existing.length > 1) return resolveAmbiguousProject(options, existing, "package-name");
|
|
30
|
+
return rememberIfRequested(options, await options.createProject(inferredName), "created");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (options.prompt && canPrompt(options.context) && projects.length > 0) return rememberIfRequested(options, await options.prompt.select({
|
|
34
|
+
message: "Select a project",
|
|
35
|
+
choices: sortProjects(projects).map((project) => ({
|
|
36
|
+
label: `${project.name} (${project.id})`,
|
|
37
|
+
value: project
|
|
38
|
+
}))
|
|
39
|
+
}), "prompt");
|
|
40
|
+
if (staleRemembered && projects.length > 1) throw localStateStaleError();
|
|
41
|
+
throw projectUnresolvedError();
|
|
42
|
+
}
|
|
43
|
+
function projectNotFoundError(projectRef, workspace) {
|
|
44
|
+
return new CliError({
|
|
45
|
+
code: "PROJECT_NOT_FOUND",
|
|
46
|
+
domain: "project",
|
|
47
|
+
summary: "Project not found",
|
|
48
|
+
why: `The project "${projectRef}" does not exist in workspace "${workspace.name}" or is not accessible.`,
|
|
49
|
+
fix: "Pass a project id or name from prisma-cli project list.",
|
|
50
|
+
exitCode: 1,
|
|
51
|
+
nextSteps: ["prisma-cli project list"]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function projectAmbiguousError(projectRef, matches) {
|
|
55
|
+
const firstMatch = matches[0];
|
|
56
|
+
const nextSteps = ["prisma-cli project list"];
|
|
57
|
+
if (firstMatch) nextSteps.push(`prisma-cli app deploy --project ${firstMatch.id}`);
|
|
58
|
+
return new CliError({
|
|
59
|
+
code: "PROJECT_AMBIGUOUS",
|
|
60
|
+
domain: "project",
|
|
61
|
+
summary: "Project resolution is ambiguous",
|
|
62
|
+
why: projectRef ? `Multiple projects matched "${projectRef}".` : "Multiple projects matched the current directory context.",
|
|
63
|
+
fix: "Pass --project <id-or-name> to choose the project explicitly.",
|
|
64
|
+
meta: { matches: matches.map((project) => ({
|
|
65
|
+
id: project.id,
|
|
66
|
+
name: project.name
|
|
67
|
+
})) },
|
|
68
|
+
exitCode: 1,
|
|
69
|
+
nextSteps
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function projectUnresolvedError() {
|
|
73
|
+
return new CliError({
|
|
74
|
+
code: "PROJECT_UNRESOLVED",
|
|
75
|
+
domain: "project",
|
|
76
|
+
summary: "No project is resolved for this directory",
|
|
77
|
+
why: "No project could be resolved from explicit input, platform mappings, remembered local context, or package metadata.",
|
|
78
|
+
fix: "Pass --project <id-or-name> on the command that needs a project, or add a package.json name that matches an accessible project.",
|
|
79
|
+
exitCode: 1,
|
|
80
|
+
nextSteps: ["prisma-cli project list", "prisma-cli project show --project <id-or-name>"]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function localStateStaleError() {
|
|
84
|
+
return new CliError({
|
|
85
|
+
code: "LOCAL_STATE_STALE",
|
|
86
|
+
domain: "project",
|
|
87
|
+
summary: "Remembered project context is stale",
|
|
88
|
+
why: "The remembered project is no longer available in the selected workspace, and automatic resolution would be ambiguous.",
|
|
89
|
+
fix: "Pass --project <id-or-name> to choose the project explicitly.",
|
|
90
|
+
exitCode: 1,
|
|
91
|
+
nextSteps: ["prisma-cli project list"]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function readPackageName(cwd) {
|
|
95
|
+
try {
|
|
96
|
+
const raw = await readFile(path.join(cwd, "package.json"), "utf8");
|
|
97
|
+
const parsed = JSON.parse(raw);
|
|
98
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
99
|
+
const packageName = "name" in parsed ? parsed.name : null;
|
|
100
|
+
return typeof packageName === "string" && packageName.trim().length > 0 ? packageName.trim() : null;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (error.code === "ENOENT") return null;
|
|
103
|
+
if (error instanceof SyntaxError) return null;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function sortProjects(projects) {
|
|
108
|
+
return projects.slice().sort((left, right) => left.name.localeCompare(right.name) || left.id.localeCompare(right.id));
|
|
109
|
+
}
|
|
110
|
+
function resolveExplicitProject(projectRef, projects, workspace) {
|
|
111
|
+
const matches = projects.filter((project) => project.id === projectRef || project.name === projectRef);
|
|
112
|
+
if (matches.length === 1) return matches[0];
|
|
113
|
+
if (matches.length > 1) throw projectAmbiguousError(projectRef, matches);
|
|
114
|
+
throw projectNotFoundError(projectRef, workspace);
|
|
115
|
+
}
|
|
116
|
+
function resolveAmbiguousProject(options, matches, projectRef) {
|
|
117
|
+
if (options.prompt && canPrompt(options.context)) return options.prompt.select({
|
|
118
|
+
message: "Select a project",
|
|
119
|
+
choices: sortProjects(matches).map((project) => ({
|
|
120
|
+
label: `${project.name} (${project.id})`,
|
|
121
|
+
value: project
|
|
122
|
+
}))
|
|
123
|
+
}).then((selected) => rememberIfRequested(options, selected, "prompt"));
|
|
124
|
+
throw projectAmbiguousError(projectRef, matches);
|
|
125
|
+
}
|
|
126
|
+
function projectMatchesPackageName(project, packageName) {
|
|
127
|
+
return project.id === packageName || project.name === packageName || project.slug === packageName;
|
|
128
|
+
}
|
|
129
|
+
async function resolveDurablePlatformMapping() {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
async function rememberIfRequested(options, project, projectSource) {
|
|
133
|
+
if (options.remember) await options.context.stateStore.setRememberedProject({
|
|
134
|
+
id: project.id,
|
|
135
|
+
name: project.name,
|
|
136
|
+
workspaceId: options.workspace.id
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
workspace: options.workspace,
|
|
140
|
+
project: toProjectSummary(project),
|
|
141
|
+
resolution: { projectSource }
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function toProjectSummary(project) {
|
|
145
|
+
return {
|
|
146
|
+
id: project.id,
|
|
147
|
+
name: project.name
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
export { resolveProjectTarget, sortProjects };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CliError } from "../shell/errors.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
//#region src/lib/version.ts
|
|
5
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
6
|
+
function readPackageMetadata() {
|
|
7
|
+
try {
|
|
8
|
+
return requireFromHere("../../package.json");
|
|
9
|
+
} catch {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function getCliVersion() {
|
|
14
|
+
const pkg = readPackageMetadata();
|
|
15
|
+
if (!pkg.version) throw new CliError({
|
|
16
|
+
code: "VERSION_UNAVAILABLE",
|
|
17
|
+
domain: "cli",
|
|
18
|
+
summary: "CLI version metadata is missing from the installed package",
|
|
19
|
+
why: "The bundled package.json could not be read or did not contain a version field.",
|
|
20
|
+
fix: "Reinstall the CLI from the npm registry, or check your install path is intact.",
|
|
21
|
+
exitCode: 1
|
|
22
|
+
});
|
|
23
|
+
return pkg.version;
|
|
24
|
+
}
|
|
25
|
+
function getCliName() {
|
|
26
|
+
return "prisma-cli";
|
|
27
|
+
}
|
|
28
|
+
function detectInvocation(env, argv) {
|
|
29
|
+
if (env.npm_config_user_agent?.startsWith("bun")) return "bunx";
|
|
30
|
+
const normalizedExecPath = env.npm_execpath?.replace(/\\/g, "/").toLowerCase();
|
|
31
|
+
const normalizedUserAgent = env.npm_config_user_agent?.toLowerCase();
|
|
32
|
+
if (env.npm_lifecycle_event === "npx" || normalizedExecPath?.includes("/_npx/") || normalizedUserAgent?.includes("npx")) return "npx";
|
|
33
|
+
const entry = (argv[1] ?? "").replace(/\\/g, "/").toLowerCase();
|
|
34
|
+
if (entry.endsWith(".ts") || entry.includes("/tsx/")) return "dev";
|
|
35
|
+
if (entry.includes("/_npx/")) return "npx";
|
|
36
|
+
if (entry.includes("/.bun/")) return "bunx";
|
|
37
|
+
if (entry.includes("/node_modules/.bin/") || /\/prisma-cli(\.cmd|\.exe)?$/.test(entry)) return "global";
|
|
38
|
+
return "unknown";
|
|
39
|
+
}
|
|
40
|
+
function buildVersionResult(env, argv) {
|
|
41
|
+
return {
|
|
42
|
+
cli: {
|
|
43
|
+
name: getCliName(),
|
|
44
|
+
version: getCliVersion()
|
|
45
|
+
},
|
|
46
|
+
node: { version: process.version },
|
|
47
|
+
os: {
|
|
48
|
+
platform: process.platform,
|
|
49
|
+
arch: process.arch
|
|
50
|
+
},
|
|
51
|
+
invocation: detectInvocation(env, argv)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { buildVersionResult, getCliName, getCliVersion };
|
package/dist/output/patterns.js
CHANGED
|
@@ -74,7 +74,6 @@ function formatListItemValue(ui, item) {
|
|
|
74
74
|
}
|
|
75
75
|
function renderAnnotation(ui, status) {
|
|
76
76
|
if (status === "active") return ui.success("(active)");
|
|
77
|
-
if (status === "linked") return ui.accent("(linked)");
|
|
78
77
|
if (status === "default") return ui.dim("(default)");
|
|
79
78
|
return "";
|
|
80
79
|
}
|
package/dist/presenters/app.js
CHANGED
|
@@ -29,9 +29,17 @@ function renderAppDeploy(context, descriptor, result) {
|
|
|
29
29
|
title: "Deploying the selected app.",
|
|
30
30
|
descriptor,
|
|
31
31
|
fields: [
|
|
32
|
+
{
|
|
33
|
+
key: "workspace",
|
|
34
|
+
value: result.workspace.name
|
|
35
|
+
},
|
|
32
36
|
{
|
|
33
37
|
key: "project",
|
|
34
|
-
value: result.
|
|
38
|
+
value: result.project.name
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "branch",
|
|
42
|
+
value: result.branch.name
|
|
35
43
|
},
|
|
36
44
|
{
|
|
37
45
|
key: "app",
|
|
@@ -2,11 +2,11 @@ import { renderList, renderMutate, renderShow, serializeList } from "../output/p
|
|
|
2
2
|
//#region src/presenters/branch.ts
|
|
3
3
|
function renderBranchList(context, descriptor, result) {
|
|
4
4
|
return renderList({
|
|
5
|
-
title: "Listing branches for the
|
|
5
|
+
title: "Listing branches for the resolved project.",
|
|
6
6
|
descriptor,
|
|
7
7
|
parentContext: {
|
|
8
8
|
key: "project",
|
|
9
|
-
value: result.projectName ?? "not
|
|
9
|
+
value: result.projectName ?? "not resolved"
|
|
10
10
|
},
|
|
11
11
|
items: result.branches.map((branch) => ({
|
|
12
12
|
noun: "branch",
|
|
@@ -19,7 +19,7 @@ function renderBranchList(context, descriptor, result) {
|
|
|
19
19
|
}
|
|
20
20
|
function serializeBranchList(result) {
|
|
21
21
|
return serializeList({
|
|
22
|
-
context: { project: result.projectName ?? "not
|
|
22
|
+
context: { project: result.projectName ?? "not resolved" },
|
|
23
23
|
items: result.branches.map((branch) => ({
|
|
24
24
|
noun: "branch",
|
|
25
25
|
label: branch.name,
|
|
@@ -30,7 +30,7 @@ function serializeBranchList(result) {
|
|
|
30
30
|
}
|
|
31
31
|
function serializeBranchShow(result) {
|
|
32
32
|
return {
|
|
33
|
-
|
|
33
|
+
projectId: result.projectId,
|
|
34
34
|
projectName: result.projectName,
|
|
35
35
|
branch: {
|
|
36
36
|
name: result.branch.name,
|
|
@@ -45,7 +45,7 @@ function renderBranchShow(context, descriptor, result) {
|
|
|
45
45
|
const fields = [
|
|
46
46
|
{
|
|
47
47
|
key: "project",
|
|
48
|
-
value: result.projectName ?? "not
|
|
48
|
+
value: result.projectName ?? "not resolved",
|
|
49
49
|
tone: result.projectName ? "default" : "dim"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -92,7 +92,7 @@ function renderBranchUse(context, descriptor, result) {
|
|
|
92
92
|
descriptor,
|
|
93
93
|
context: [{
|
|
94
94
|
key: "project",
|
|
95
|
-
value: result.projectName ?? "not
|
|
95
|
+
value: result.projectName ?? "not resolved",
|
|
96
96
|
tone: result.projectName ? "default" : "dim"
|
|
97
97
|
}, {
|
|
98
98
|
key: "branch",
|
|
@@ -12,7 +12,7 @@ function renderProjectList(context, descriptor, result) {
|
|
|
12
12
|
noun: "project",
|
|
13
13
|
label: project.name,
|
|
14
14
|
id: project.id,
|
|
15
|
-
status:
|
|
15
|
+
status: null
|
|
16
16
|
})),
|
|
17
17
|
emptyMessage: "No projects found."
|
|
18
18
|
}, context.ui);
|
|
@@ -24,61 +24,101 @@ function serializeProjectList(result) {
|
|
|
24
24
|
noun: "project",
|
|
25
25
|
label: project.name,
|
|
26
26
|
id: project.id,
|
|
27
|
-
status:
|
|
27
|
+
status: null
|
|
28
28
|
}))
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
function renderProjectShow(context, descriptor, result) {
|
|
32
|
-
|
|
33
|
-
title: "Showing the
|
|
34
|
-
descriptor,
|
|
35
|
-
fields: [{
|
|
36
|
-
key: "project",
|
|
37
|
-
value: "not linked",
|
|
38
|
-
tone: "dim"
|
|
39
|
-
}]
|
|
40
|
-
}, context.ui);
|
|
41
|
-
if (!result.project || !result.workspace) return renderShow({
|
|
42
|
-
title: "Showing the linked project for the current repo.",
|
|
32
|
+
return renderShow({
|
|
33
|
+
title: "Showing the project Prisma resolves for this directory.",
|
|
43
34
|
descriptor,
|
|
44
|
-
fields: [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
fields: [
|
|
36
|
+
{
|
|
37
|
+
key: "workspace",
|
|
38
|
+
value: result.workspace.name
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "project",
|
|
42
|
+
value: result.project.name
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "resolution",
|
|
46
|
+
value: formatProjectSource(result.resolution.projectSource)
|
|
47
|
+
}
|
|
48
|
+
]
|
|
53
49
|
}, context.ui);
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
}
|
|
51
|
+
function serializeProjectShow(result) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
function renderGitConnect(context, descriptor, result) {
|
|
55
|
+
const connection = result.repositoryConnection;
|
|
56
|
+
return renderMutate({
|
|
57
|
+
title: "Connecting Git to the resolved project.",
|
|
56
58
|
descriptor,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
context: [
|
|
60
|
+
{
|
|
61
|
+
key: "project",
|
|
62
|
+
value: result.project.name
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: "workspace",
|
|
66
|
+
value: result.workspace.name
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: "repository",
|
|
70
|
+
value: connection.repository.fullName
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "status",
|
|
74
|
+
value: connection.status
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
operationDescription: "Applying repository connection",
|
|
78
|
+
operationCount: 1,
|
|
79
|
+
details: [formatGitConnectionDetail(connection.status)]
|
|
64
80
|
}, context.ui);
|
|
65
81
|
}
|
|
66
|
-
function
|
|
67
|
-
if (!result.project || !result.workspace) throw new Error("Linked project result must be enriched for human output.");
|
|
82
|
+
function renderGitDisconnect(context, descriptor, result) {
|
|
68
83
|
return renderMutate({
|
|
69
|
-
title: "
|
|
84
|
+
title: "Disconnecting Git from the resolved project.",
|
|
70
85
|
descriptor,
|
|
71
|
-
context: [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
context: [
|
|
87
|
+
{
|
|
88
|
+
key: "project",
|
|
89
|
+
value: result.project.name
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
key: "workspace",
|
|
93
|
+
value: result.workspace.name
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
key: "repository",
|
|
97
|
+
value: result.repositoryConnection.repository.fullName
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
operationDescription: "Applying repository disconnection",
|
|
79
101
|
operationCount: 1,
|
|
80
|
-
details: ["
|
|
102
|
+
details: ["GitHub branch automation is no longer active for this project."]
|
|
81
103
|
}, context.ui);
|
|
82
104
|
}
|
|
105
|
+
function formatProjectSource(source) {
|
|
106
|
+
switch (source) {
|
|
107
|
+
case "explicit": return "explicit";
|
|
108
|
+
case "platform-mapping": return "platform mapping";
|
|
109
|
+
case "remembered-local": return "remembered local context";
|
|
110
|
+
case "package-name": return "package name";
|
|
111
|
+
case "created": return "created";
|
|
112
|
+
case "prompt": return "prompt";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function formatGitConnectionDetail(status) {
|
|
116
|
+
switch (status) {
|
|
117
|
+
case "active": return "GitHub branch automation is active for this project.";
|
|
118
|
+
case "pending": return "GitHub branch automation is pending GitHub App installation.";
|
|
119
|
+
case "archived": return "GitHub branch automation has been archived for this project.";
|
|
120
|
+
default: return "GitHub repository is connected, but branch automation is not active.";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
83
123
|
//#endregion
|
|
84
|
-
export {
|
|
124
|
+
export { renderGitConnect, renderGitDisconnect, renderProjectList, renderProjectShow, serializeProjectList, serializeProjectShow };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { renderShow } from "../output/patterns.js";
|
|
2
|
+
//#region src/presenters/version.ts
|
|
3
|
+
function renderVersionSuccess(context, descriptor, result) {
|
|
4
|
+
return renderShow({
|
|
5
|
+
title: "Showing CLI build and environment.",
|
|
6
|
+
descriptor,
|
|
7
|
+
fields: [
|
|
8
|
+
{
|
|
9
|
+
key: result.cli.name,
|
|
10
|
+
value: result.cli.version
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
key: "node",
|
|
14
|
+
value: result.node.version
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: "os",
|
|
18
|
+
value: `${result.os.platform} ${result.os.arch}`
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "invocation",
|
|
22
|
+
value: result.invocation,
|
|
23
|
+
tone: result.invocation === "unknown" ? "dim" : "default"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}, context.ui);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { renderVersionSuccess };
|