@prisma/compute-cli 0.1.0 → 0.4.0
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 +92 -72
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +8 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +8 -8
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/helpers.d.ts +5 -3
- package/dist/commands/helpers.d.ts.map +1 -1
- package/dist/commands/helpers.js +6 -5
- package/dist/commands/helpers.js.map +1 -1
- package/dist/commands/projects.d.ts.map +1 -1
- package/dist/commands/projects.js +67 -2
- package/dist/commands/projects.js.map +1 -1
- package/package.json +4 -3
- package/src/commands/deploy.ts +11 -13
- package/src/commands/env.ts +11 -10
- package/src/commands/helpers.ts +13 -8
- package/src/commands/projects.ts +84 -2
- package/dist/lib/compute-config.d.ts +0 -12
- package/dist/lib/compute-config.d.ts.map +0 -1
- package/dist/lib/compute-config.js +0 -69
- package/dist/lib/compute-config.js.map +0 -1
- package/src/lib/compute-config.ts +0 -95
package/README.md
CHANGED
|
@@ -1,118 +1,138 @@
|
|
|
1
1
|
# Compute CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command-line interface for deploying and managing [Prisma Compute](https://www.prisma.io/compute) services.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
Run directly with bunx (no install required):
|
|
4
8
|
|
|
5
9
|
```sh
|
|
6
|
-
|
|
7
|
-
bun run bin/compute deploy --path .
|
|
10
|
+
bunx @prisma/compute-cli --help
|
|
8
11
|
```
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
> Also works with `npx @prisma/compute-cli` if you don't have Bun installed.
|
|
14
|
+
|
|
15
|
+
## Authentication
|
|
16
|
+
|
|
17
|
+
### Interactive login (browser-based)
|
|
11
18
|
|
|
12
19
|
```sh
|
|
13
|
-
|
|
20
|
+
bunx @prisma/compute-cli login
|
|
14
21
|
```
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
This opens your browser for OAuth authentication with Prisma. Tokens are stored locally:
|
|
24
|
+
|
|
25
|
+
| Platform | Path |
|
|
26
|
+
| -------- | ---------------------------------------------------------------------------------------------- |
|
|
27
|
+
| macOS | `~/Library/Application Support/prisma-compute/auth.json` |
|
|
28
|
+
| Linux | `$XDG_CONFIG_HOME/prisma-compute/auth.json` (defaults to `~/.config/prisma-compute/auth.json`) |
|
|
29
|
+
| Windows | `%APPDATA%\prisma-compute\auth.json` |
|
|
30
|
+
|
|
31
|
+
To log out and clear stored credentials:
|
|
17
32
|
|
|
18
33
|
```sh
|
|
19
|
-
|
|
34
|
+
bunx @prisma/compute-cli logout
|
|
20
35
|
```
|
|
21
36
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
When linked with Bun, import directly from `compute`:
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
import {
|
|
28
|
-
ApiClient,
|
|
29
|
-
FileTokenStorage,
|
|
30
|
-
computeProcedures,
|
|
31
|
-
computeRouter,
|
|
32
|
-
deploy,
|
|
33
|
-
destroy,
|
|
34
|
-
deployCli,
|
|
35
|
-
destroyCli,
|
|
36
|
-
listServices,
|
|
37
|
-
listVersions,
|
|
38
|
-
listProjects,
|
|
39
|
-
login,
|
|
40
|
-
logout,
|
|
41
|
-
runCli,
|
|
42
|
-
} from "compute";
|
|
43
|
-
```
|
|
37
|
+
### Service token (CI / non-interactive)
|
|
44
38
|
|
|
45
|
-
|
|
39
|
+
Set the `PRISMA_API_TOKEN` environment variable. When present, the CLI skips the stored OAuth credentials and authenticates with this token directly.
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
- programmatic handlers: `deploy`, `destroy`, `listServices`, `listVersions`, `listProjects`, `login`, `logout`
|
|
52
|
-
- CLI wrappers (exit-code based): `deployCli`, `destroyCli`
|
|
41
|
+
```sh
|
|
42
|
+
export PRISMA_API_TOKEN="your-service-token"
|
|
43
|
+
bunx @prisma/compute-cli projects list
|
|
44
|
+
```
|
|
53
45
|
|
|
54
|
-
|
|
46
|
+
## Commands
|
|
55
47
|
|
|
56
|
-
|
|
57
|
-
import { ApiClient, deploy } from "compute";
|
|
48
|
+
All commands except `login` and `logout` support `--json` for machine-readable output.
|
|
58
49
|
|
|
59
|
-
|
|
50
|
+
### Deploy
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
path: "./app",
|
|
63
|
-
env: {
|
|
64
|
-
NODE_ENV: "production",
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
```
|
|
52
|
+
Build and deploy your application:
|
|
68
53
|
|
|
69
|
-
|
|
54
|
+
```sh
|
|
55
|
+
bunx @prisma/compute-cli deploy --path ./my-app
|
|
56
|
+
```
|
|
70
57
|
|
|
71
|
-
|
|
72
|
-
|
|
58
|
+
Key flags:
|
|
59
|
+
|
|
60
|
+
| Flag | Description |
|
|
61
|
+
| ----------------- | ------------------------------------------------------ |
|
|
62
|
+
| `--path` | App directory (default: `.`) |
|
|
63
|
+
| `--project` | Project ID (prompted interactively if omitted) |
|
|
64
|
+
| `--service` | Compute service ID (prompted interactively if omitted) |
|
|
65
|
+
| `--entrypoint` | Relative app entrypoint |
|
|
66
|
+
| `--serviceName` | Name for a new compute service |
|
|
67
|
+
| `--region` | Region for a new compute service |
|
|
68
|
+
| `--env KEY=VALUE` | Environment variable (repeatable) |
|
|
69
|
+
| `--httpPort` | HTTP port your application listens on |
|
|
70
|
+
| `--skipBuild` | Deploy a pre-built artifact (requires `--entrypoint`) |
|
|
71
|
+
| `--timeout` | Poll timeout in seconds (default: `120`) |
|
|
72
|
+
| `--pollInterval` | Poll interval in ms (default: `1000`) |
|
|
73
|
+
| `--json` | Output JSON instead of human-readable text |
|
|
74
|
+
|
|
75
|
+
Set `PRISMA_COMPUTE_SERVICE_ID` to skip the `--service` flag across all commands:
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
authBaseUrl: "https://auth.prisma.io",
|
|
78
|
-
});
|
|
77
|
+
```sh
|
|
78
|
+
export PRISMA_COMPUTE_SERVICE_ID="your-service-id"
|
|
79
|
+
bunx @prisma/compute-cli deploy --path ./my-app
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
### Environment variables
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
import { login } from "compute";
|
|
84
|
+
Update environment variables on a running service (creates a new version):
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
authBaseUrl: "https://auth.prisma.io",
|
|
89
|
-
});
|
|
86
|
+
```sh
|
|
87
|
+
bunx @prisma/compute-cli env update --env DATABASE_URL=postgres://... --env NODE_ENV=production
|
|
90
88
|
```
|
|
91
89
|
|
|
92
|
-
|
|
90
|
+
### Projects
|
|
93
91
|
|
|
94
|
-
|
|
92
|
+
```sh
|
|
93
|
+
bunx @prisma/compute-cli projects list
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Services
|
|
95
97
|
|
|
96
98
|
```sh
|
|
97
|
-
|
|
99
|
+
bunx @prisma/compute-cli services list --project <id>
|
|
100
|
+
bunx @prisma/compute-cli services create --project <id> --name my-service --region <region>
|
|
101
|
+
bunx @prisma/compute-cli services show <service-id>
|
|
102
|
+
bunx @prisma/compute-cli services delete <service-id>
|
|
103
|
+
bunx @prisma/compute-cli services destroy <service-id> # stops all versions, then deletes
|
|
98
104
|
```
|
|
99
105
|
|
|
100
|
-
|
|
106
|
+
### Versions
|
|
101
107
|
|
|
102
108
|
```sh
|
|
103
|
-
|
|
109
|
+
bunx @prisma/compute-cli versions list --service <id>
|
|
110
|
+
bunx @prisma/compute-cli versions show <version-id>
|
|
111
|
+
bunx @prisma/compute-cli versions start <version-id>
|
|
112
|
+
bunx @prisma/compute-cli versions stop <version-id>
|
|
113
|
+
bunx @prisma/compute-cli versions delete <version-id>
|
|
114
|
+
bunx @prisma/compute-cli versions destroy <version-id> # stops, then deletes
|
|
104
115
|
```
|
|
105
116
|
|
|
106
|
-
|
|
117
|
+
## JSON output
|
|
107
118
|
|
|
108
|
-
|
|
119
|
+
Pass `--json` to any command for structured output suitable for scripting:
|
|
109
120
|
|
|
110
121
|
```sh
|
|
111
|
-
|
|
122
|
+
bunx @prisma/compute-cli services list --project <id> --json | jq '.value[].id'
|
|
112
123
|
```
|
|
113
124
|
|
|
114
|
-
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
| Variable | Description |
|
|
128
|
+
| --------------------------- | -------------------------------------- |
|
|
129
|
+
| `PRISMA_API_TOKEN` | Service token for non-interactive auth |
|
|
130
|
+
| `PRISMA_COMPUTE_SERVICE_ID` | Default compute service ID |
|
|
131
|
+
| `PRISMA_MANAGEMENT_API_URL` | Override the management API base URL |
|
|
132
|
+
|
|
133
|
+
## Development
|
|
115
134
|
|
|
116
135
|
```sh
|
|
117
|
-
bun run
|
|
136
|
+
bun run bin/compute --help
|
|
137
|
+
bun run bin/compute deploy --path .
|
|
118
138
|
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0GxB,CAAC"}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { BunBuild, ComputeClient, PreBuilt } from "@prisma/compute-sdk";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
|
-
import { writeComputeConfig } from "../lib/compute-config.js";
|
|
5
4
|
import { createDeployInteraction } from "../lib/interaction.js";
|
|
6
5
|
import { printJsonResult } from "../lib/json-output.js";
|
|
7
6
|
import { createDeployProgress } from "../lib/progress.js";
|
|
8
|
-
import { endFlow,
|
|
7
|
+
import { endFlow, handleError, parseEnvFromArgs, parsePollOptions, parsePortMapping, printServiceIdHint, resolveServiceId, startFlow, withAuthAndSignal, } from "./helpers.js";
|
|
9
8
|
export const deployCommand = defineCommand({
|
|
10
9
|
meta: { name: "deploy", description: "Build and deploy your application" },
|
|
11
10
|
args: {
|
|
@@ -51,10 +50,7 @@ export const deployCommand = defineCommand({
|
|
|
51
50
|
const appPath = path.resolve(process.cwd(), args.path);
|
|
52
51
|
const envVars = parseEnvFromArgs(rawArgs);
|
|
53
52
|
const portMapping = parsePortMapping(args.httpPort);
|
|
54
|
-
const
|
|
55
|
-
const currentConfig = await readComputeConfig(configPath);
|
|
56
|
-
const projectId = args.project ?? currentConfig?.projectId;
|
|
57
|
-
const serviceId = args.service ?? currentConfig?.serviceId;
|
|
53
|
+
const inputServiceId = resolveServiceId(args);
|
|
58
54
|
let strategy;
|
|
59
55
|
if (args.skipBuild) {
|
|
60
56
|
if (!args.entrypoint) {
|
|
@@ -67,12 +63,12 @@ export const deployCommand = defineCommand({
|
|
|
67
63
|
}
|
|
68
64
|
const result = await sdk.deploy({
|
|
69
65
|
strategy,
|
|
70
|
-
projectId,
|
|
71
|
-
serviceId,
|
|
66
|
+
projectId: args.project,
|
|
67
|
+
serviceId: inputServiceId,
|
|
72
68
|
serviceName: args.serviceName,
|
|
73
69
|
region: args.region,
|
|
74
70
|
envVars,
|
|
75
|
-
portMapping
|
|
71
|
+
portMapping,
|
|
76
72
|
...parsePollOptions(args),
|
|
77
73
|
interaction: args.json ? undefined : createDeployInteraction(),
|
|
78
74
|
progress: args.json ? undefined : createDeployProgress(),
|
|
@@ -87,11 +83,13 @@ export const deployCommand = defineCommand({
|
|
|
87
83
|
console.error(result.error.message);
|
|
88
84
|
return 1;
|
|
89
85
|
}
|
|
90
|
-
await writeComputeConfig(configPath, result.value.resolvedConfig);
|
|
91
86
|
console.log(`Version: ${result.value.versionId}`);
|
|
92
87
|
console.log("");
|
|
93
88
|
console.log("Deployment URL:");
|
|
94
89
|
console.log(result.value.deploymentUrl);
|
|
90
|
+
if (!inputServiceId) {
|
|
91
|
+
printServiceIdHint(result.value.serviceId);
|
|
92
|
+
}
|
|
95
93
|
endFlow(flowStarted, "Deploy flow completed.");
|
|
96
94
|
return 0;
|
|
97
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;IACzC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mCAAmC,EAAE;IAC1E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3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/commands/env.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/commands/env.ts"],"names":[],"mappings":"AAqGA,eAAO,MAAM,QAAQ,qDAGnB,CAAC"}
|
package/dist/commands/env.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ComputeClient } from "@prisma/compute-sdk";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
|
-
import { writeComputeConfig } from "../lib/compute-config.js";
|
|
4
3
|
import { createDeployInteraction } from "../lib/interaction.js";
|
|
5
4
|
import { printJsonResult } from "../lib/json-output.js";
|
|
6
5
|
import { createUpdateEnvProgress } from "../lib/progress.js";
|
|
7
|
-
import { endFlow,
|
|
6
|
+
import { endFlow, handleError, parseEnvFromArgs, parsePollOptions, parsePortMapping, printServiceIdHint, resolveServiceId, startFlow, withAuthAndSignal, } from "./helpers.js";
|
|
8
7
|
const envUpdateCommand = defineCommand({
|
|
9
8
|
meta: {
|
|
10
9
|
name: "update",
|
|
@@ -41,13 +40,12 @@ const envUpdateCommand = defineCommand({
|
|
|
41
40
|
const sdk = new ComputeClient(managementClient);
|
|
42
41
|
const envVars = parseEnvFromArgs(rawArgs);
|
|
43
42
|
const portMapping = parsePortMapping(args.httpPort);
|
|
44
|
-
const
|
|
45
|
-
const currentConfig = await readComputeConfig(configPath);
|
|
43
|
+
const inputServiceId = resolveServiceId(args);
|
|
46
44
|
const result = await sdk.updateEnv({
|
|
47
|
-
projectId: args.project
|
|
48
|
-
serviceId:
|
|
45
|
+
projectId: args.project,
|
|
46
|
+
serviceId: inputServiceId,
|
|
49
47
|
envVars,
|
|
50
|
-
portMapping
|
|
48
|
+
portMapping,
|
|
51
49
|
...parsePollOptions(args),
|
|
52
50
|
interaction: args.json ? undefined : createDeployInteraction(),
|
|
53
51
|
progress: args.json ? undefined : createUpdateEnvProgress(),
|
|
@@ -61,11 +59,13 @@ const envUpdateCommand = defineCommand({
|
|
|
61
59
|
console.error(result.error.message);
|
|
62
60
|
return 1;
|
|
63
61
|
}
|
|
64
|
-
await writeComputeConfig(configPath, result.value.resolvedConfig);
|
|
65
62
|
console.log(`Version: ${result.value.versionId}`);
|
|
66
63
|
console.log("");
|
|
67
64
|
console.log("Deployment URL:");
|
|
68
65
|
console.log(result.value.deploymentUrl);
|
|
66
|
+
if (!inputServiceId) {
|
|
67
|
+
printServiceIdHint(result.value.serviceId);
|
|
68
|
+
}
|
|
69
69
|
endFlow(flowStarted, "Env update completed.");
|
|
70
70
|
return 0;
|
|
71
71
|
}
|
package/dist/commands/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/commands/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/commands/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,MAAM,gBAAgB,GAAG,aAAa,CAAC;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,sDAAsD;KACpE;IACD,IAAI,EAAE;QAC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QAAQ,KAAK,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,aAAa,CAAC;IACpC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,iCAAiC,EAAE;IACrE,WAAW,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;CAC1C,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ManagementApiClient } from "@prisma/management-api-sdk";
|
|
2
|
-
import { readComputeConfig } from "../lib/compute-config.ts";
|
|
3
2
|
import { isInteractiveSession } from "../lib/interaction.ts";
|
|
3
|
+
export declare const PRISMA_COMPUTE_SERVICE_ID_ENV = "PRISMA_COMPUTE_SERVICE_ID";
|
|
4
4
|
export declare function parseEnvAssignments(entries: string[]): Record<string, string>;
|
|
5
5
|
export declare function parseEnvFromArgs(rawArgs: string[]): Record<string, string>;
|
|
6
6
|
export declare function parsePortMapping(httpPort: string | undefined): {
|
|
@@ -13,8 +13,10 @@ export declare function parsePollOptions(args: {
|
|
|
13
13
|
timeoutSeconds: number;
|
|
14
14
|
pollIntervalMs: number;
|
|
15
15
|
};
|
|
16
|
-
export declare function
|
|
17
|
-
|
|
16
|
+
export declare function resolveServiceId(args: {
|
|
17
|
+
service?: string;
|
|
18
|
+
}): string | undefined;
|
|
19
|
+
export declare function printServiceIdHint(serviceId: string): void;
|
|
18
20
|
export declare function createCommandAbortSignal(): {
|
|
19
21
|
signal: AbortSignal;
|
|
20
22
|
cleanup(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/commands/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/commands/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE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EAAE,CAAC"}
|
package/dist/commands/helpers.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import { intro, outro } from "@clack/prompts";
|
|
3
2
|
import { requireAuth } from "../lib/auth/guard.js";
|
|
4
|
-
import { COMPUTE_CONFIG_FILENAME, readComputeConfig, } from "../lib/compute-config.js";
|
|
5
3
|
import { isInteractiveSession, isPromptCancelled } from "../lib/interaction.js";
|
|
4
|
+
export const PRISMA_COMPUTE_SERVICE_ID_ENV = "PRISMA_COMPUTE_SERVICE_ID";
|
|
6
5
|
export function parseEnvAssignments(entries) {
|
|
7
6
|
const envVars = {};
|
|
8
7
|
for (const value of entries) {
|
|
@@ -71,10 +70,12 @@ export function parsePollOptions(args) {
|
|
|
71
70
|
pollIntervalMs: parseIntOrThrow(args.pollInterval, "--poll-interval"),
|
|
72
71
|
};
|
|
73
72
|
}
|
|
74
|
-
export function
|
|
75
|
-
return
|
|
73
|
+
export function resolveServiceId(args) {
|
|
74
|
+
return (args.service || process.env[PRISMA_COMPUTE_SERVICE_ID_ENV] || undefined);
|
|
75
|
+
}
|
|
76
|
+
export function printServiceIdHint(serviceId) {
|
|
77
|
+
console.log(`\nTip: To skip the service prompt next time, set:\n export ${PRISMA_COMPUTE_SERVICE_ID_ENV}=${serviceId}\n`);
|
|
76
78
|
}
|
|
77
|
-
export { readComputeConfig };
|
|
78
79
|
export function createCommandAbortSignal() {
|
|
79
80
|
const controller = new AbortController();
|
|
80
81
|
let cleanedUp = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/commands/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/commands/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM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,CAAC,KAAK,UAAU,iBAAiB,CACrC,EAAyE;IAEzE,MAAM,MAAM,GAAG,MAAM,WAAW,EAAE,CAAC;IACnC,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,CAAC;IACtB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,wBAAwB,EAAE,CAAC;IACvD,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,iBAAiB,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,CAAC,oBAAoB,EAAE;QAAE,OAAO,KAAK,CAAC;IAC1C,KAAK,CAAC,KAAK,CAAC,CAAC;IACb,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,OAAgB,EAAE,OAAO,GAAG,OAAO;IACzD,IAAI,OAAO;QAAE,KAAK,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":"AAoIA,eAAO,MAAM,aAAa,qDAGxB,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { ComputeClient } from "@prisma/compute-sdk";
|
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
3
|
import { formatTable } from "../lib/format.js";
|
|
4
4
|
import { printJsonResult } from "../lib/json-output.js";
|
|
5
|
-
import { handleError, withAuthAndSignal } from "./helpers.js";
|
|
5
|
+
import { endFlow, handleError, startFlow, withAuthAndSignal, } from "./helpers.js";
|
|
6
6
|
const projectsListCommand = defineCommand({
|
|
7
7
|
meta: { name: "list", description: "List projects in your workspace" },
|
|
8
8
|
args: {
|
|
@@ -36,8 +36,73 @@ const projectsListCommand = defineCommand({
|
|
|
36
36
|
process.exit(exitCode);
|
|
37
37
|
},
|
|
38
38
|
});
|
|
39
|
+
const projectsCreateCommand = defineCommand({
|
|
40
|
+
meta: { name: "create", description: "Create a new project" },
|
|
41
|
+
args: {
|
|
42
|
+
name: { type: "string", description: "Project name" },
|
|
43
|
+
"create-database": {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
default: false,
|
|
46
|
+
description: "Also create a Prisma Postgres database",
|
|
47
|
+
},
|
|
48
|
+
region: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "Database region (only with --create-database)",
|
|
51
|
+
},
|
|
52
|
+
json: { type: "boolean", default: false, description: "Output JSON" },
|
|
53
|
+
},
|
|
54
|
+
run: async ({ args }) => {
|
|
55
|
+
const exitCode = await withAuthAndSignal(async (managementClient, signal) => {
|
|
56
|
+
const name = args.name;
|
|
57
|
+
if (!name) {
|
|
58
|
+
console.error("Missing required flag: --name <name>");
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
if (args.region && !args["create-database"]) {
|
|
62
|
+
console.error("--region requires --create-database");
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
const flowStarted = !args.json && startFlow("Prisma Compute · Projects");
|
|
66
|
+
try {
|
|
67
|
+
const sdk = new ComputeClient(managementClient);
|
|
68
|
+
const result = await sdk.createProject({
|
|
69
|
+
name,
|
|
70
|
+
createDatabase: args["create-database"],
|
|
71
|
+
region: args.region,
|
|
72
|
+
signal,
|
|
73
|
+
});
|
|
74
|
+
if (args.json) {
|
|
75
|
+
printJsonResult(result);
|
|
76
|
+
return result.isOk() ? 0 : 1;
|
|
77
|
+
}
|
|
78
|
+
if (result.isErr()) {
|
|
79
|
+
endFlow(flowStarted);
|
|
80
|
+
console.error(result.error.message);
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
const project = result.value;
|
|
84
|
+
console.log(`Created project ${project.name} (${project.id})`);
|
|
85
|
+
if (project.database) {
|
|
86
|
+
console.log(`Database: ${project.database.id}`);
|
|
87
|
+
console.log(`Region: ${project.database.region}`);
|
|
88
|
+
if (project.database.connectionString) {
|
|
89
|
+
console.log(`Connection: ${project.database.connectionString}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
endFlow(flowStarted);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
endFlow(flowStarted);
|
|
97
|
+
return handleError(error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (exitCode !== 0)
|
|
101
|
+
process.exit(exitCode);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
39
104
|
export const projectsGroup = defineCommand({
|
|
40
105
|
meta: { name: "projects", description: "Project management" },
|
|
41
|
-
subCommands: { list: projectsListCommand },
|
|
106
|
+
subCommands: { list: projectsListCommand, create: projectsCreateCommand },
|
|
42
107
|
});
|
|
43
108
|
//# sourceMappingURL=projects.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version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GAAG,CAAC,CAAC;gBAE/D,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;oBACrB,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;oBAClD,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;oBACtD,IAAI,OAAO,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;wBACtC,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC;oBAClE,CAAC;gBACH,CAAC;gBAED,OAAO,CAAC,WAAW,CAAC,CAAC;gBACrB,OAAO,CAAC,CAAC;YACX,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,WAAW,CAAC,CAAC;gBACrB,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CACF,CAAC;QAEF,IAAI,QAAQ,KAAK,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;IACzC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE;IAC7D,WAAW,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,qBAAqB,EAAE;CAC1E,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/compute-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"repository": "prisma/project-compute",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"bin": {
|
|
6
7
|
"compute": "./bin/compute"
|
|
@@ -23,14 +24,14 @@
|
|
|
23
24
|
],
|
|
24
25
|
"scripts": {
|
|
25
26
|
"build": "tsc --project tsconfig.build.json",
|
|
26
|
-
"
|
|
27
|
+
"prepack": "npm run build",
|
|
27
28
|
"dev": "bun run bin/compute",
|
|
28
29
|
"test": "bun test",
|
|
29
30
|
"check:types": "tsc --noEmit"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@clack/prompts": "^1.1.0",
|
|
33
|
-
"@prisma/compute-sdk": "0.
|
|
34
|
+
"@prisma/compute-sdk": "0.4.0",
|
|
34
35
|
"@prisma/credentials-store": "^7.5.0",
|
|
35
36
|
"@prisma/management-api-sdk": "^1.23.0",
|
|
36
37
|
"citty": "^0.2.1",
|
package/src/commands/deploy.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { BunBuild, ComputeClient, PreBuilt } from "@prisma/compute-sdk";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
|
-
import { writeComputeConfig } from "../lib/compute-config.ts";
|
|
5
4
|
import { createDeployInteraction } from "../lib/interaction.ts";
|
|
6
5
|
import { printJsonResult } from "../lib/json-output.ts";
|
|
7
6
|
import { createDeployProgress } from "../lib/progress.ts";
|
|
8
7
|
import {
|
|
9
8
|
endFlow,
|
|
10
|
-
getConfigPath,
|
|
11
9
|
handleError,
|
|
12
10
|
parseEnvFromArgs,
|
|
13
11
|
parsePollOptions,
|
|
14
12
|
parsePortMapping,
|
|
15
|
-
|
|
13
|
+
printServiceIdHint,
|
|
14
|
+
resolveServiceId,
|
|
16
15
|
startFlow,
|
|
17
16
|
withAuthAndSignal,
|
|
18
17
|
} from "./helpers.ts";
|
|
@@ -65,11 +64,7 @@ export const deployCommand = defineCommand({
|
|
|
65
64
|
const envVars = parseEnvFromArgs(rawArgs);
|
|
66
65
|
const portMapping = parsePortMapping(args.httpPort);
|
|
67
66
|
|
|
68
|
-
const
|
|
69
|
-
const currentConfig = await readComputeConfig(configPath);
|
|
70
|
-
|
|
71
|
-
const projectId = args.project ?? currentConfig?.projectId;
|
|
72
|
-
const serviceId = args.service ?? currentConfig?.serviceId;
|
|
67
|
+
const inputServiceId = resolveServiceId(args);
|
|
73
68
|
|
|
74
69
|
let strategy: PreBuilt | BunBuild;
|
|
75
70
|
if (args.skipBuild) {
|
|
@@ -85,12 +80,12 @@ export const deployCommand = defineCommand({
|
|
|
85
80
|
|
|
86
81
|
const result = await sdk.deploy({
|
|
87
82
|
strategy,
|
|
88
|
-
projectId,
|
|
89
|
-
serviceId,
|
|
83
|
+
projectId: args.project,
|
|
84
|
+
serviceId: inputServiceId,
|
|
90
85
|
serviceName: args.serviceName,
|
|
91
86
|
region: args.region,
|
|
92
87
|
envVars,
|
|
93
|
-
portMapping
|
|
88
|
+
portMapping,
|
|
94
89
|
...parsePollOptions(args),
|
|
95
90
|
interaction: args.json ? undefined : createDeployInteraction(),
|
|
96
91
|
progress: args.json ? undefined : createDeployProgress(),
|
|
@@ -108,12 +103,15 @@ export const deployCommand = defineCommand({
|
|
|
108
103
|
return 1;
|
|
109
104
|
}
|
|
110
105
|
|
|
111
|
-
await writeComputeConfig(configPath, result.value.resolvedConfig);
|
|
112
|
-
|
|
113
106
|
console.log(`Version: ${result.value.versionId}`);
|
|
114
107
|
console.log("");
|
|
115
108
|
console.log("Deployment URL:");
|
|
116
109
|
console.log(result.value.deploymentUrl);
|
|
110
|
+
|
|
111
|
+
if (!inputServiceId) {
|
|
112
|
+
printServiceIdHint(result.value.serviceId);
|
|
113
|
+
}
|
|
114
|
+
|
|
117
115
|
endFlow(flowStarted, "Deploy flow completed.");
|
|
118
116
|
return 0;
|
|
119
117
|
} catch (error) {
|
package/src/commands/env.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { ComputeClient } from "@prisma/compute-sdk";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
|
-
import { writeComputeConfig } from "../lib/compute-config.ts";
|
|
4
3
|
import { createDeployInteraction } from "../lib/interaction.ts";
|
|
5
4
|
import { printJsonResult } from "../lib/json-output.ts";
|
|
6
5
|
import { createUpdateEnvProgress } from "../lib/progress.ts";
|
|
7
6
|
import {
|
|
8
7
|
endFlow,
|
|
9
|
-
getConfigPath,
|
|
10
8
|
handleError,
|
|
11
9
|
parseEnvFromArgs,
|
|
12
10
|
parsePollOptions,
|
|
13
11
|
parsePortMapping,
|
|
14
|
-
|
|
12
|
+
printServiceIdHint,
|
|
13
|
+
resolveServiceId,
|
|
15
14
|
startFlow,
|
|
16
15
|
withAuthAndSignal,
|
|
17
16
|
} from "./helpers.ts";
|
|
@@ -56,14 +55,13 @@ const envUpdateCommand = defineCommand({
|
|
|
56
55
|
const envVars = parseEnvFromArgs(rawArgs);
|
|
57
56
|
const portMapping = parsePortMapping(args.httpPort);
|
|
58
57
|
|
|
59
|
-
const
|
|
60
|
-
const currentConfig = await readComputeConfig(configPath);
|
|
58
|
+
const inputServiceId = resolveServiceId(args);
|
|
61
59
|
|
|
62
60
|
const result = await sdk.updateEnv({
|
|
63
|
-
projectId: args.project
|
|
64
|
-
serviceId:
|
|
61
|
+
projectId: args.project,
|
|
62
|
+
serviceId: inputServiceId,
|
|
65
63
|
envVars,
|
|
66
|
-
portMapping
|
|
64
|
+
portMapping,
|
|
67
65
|
...parsePollOptions(args),
|
|
68
66
|
interaction: args.json ? undefined : createDeployInteraction(),
|
|
69
67
|
progress: args.json ? undefined : createUpdateEnvProgress(),
|
|
@@ -80,12 +78,15 @@ const envUpdateCommand = defineCommand({
|
|
|
80
78
|
return 1;
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
await writeComputeConfig(configPath, result.value.resolvedConfig);
|
|
84
|
-
|
|
85
81
|
console.log(`Version: ${result.value.versionId}`);
|
|
86
82
|
console.log("");
|
|
87
83
|
console.log("Deployment URL:");
|
|
88
84
|
console.log(result.value.deploymentUrl);
|
|
85
|
+
|
|
86
|
+
if (!inputServiceId) {
|
|
87
|
+
printServiceIdHint(result.value.serviceId);
|
|
88
|
+
}
|
|
89
|
+
|
|
89
90
|
endFlow(flowStarted, "Env update completed.");
|
|
90
91
|
return 0;
|
|
91
92
|
} catch (error) {
|
package/src/commands/helpers.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import { intro, outro } from "@clack/prompts";
|
|
3
2
|
import type { ManagementApiClient } from "@prisma/management-api-sdk";
|
|
4
3
|
import { requireAuth } from "../lib/auth/guard.ts";
|
|
5
|
-
import {
|
|
6
|
-
COMPUTE_CONFIG_FILENAME,
|
|
7
|
-
readComputeConfig,
|
|
8
|
-
} from "../lib/compute-config.ts";
|
|
9
4
|
import { isInteractiveSession, isPromptCancelled } from "../lib/interaction.ts";
|
|
10
5
|
|
|
6
|
+
export const PRISMA_COMPUTE_SERVICE_ID_ENV = "PRISMA_COMPUTE_SERVICE_ID";
|
|
7
|
+
|
|
11
8
|
export function parseEnvAssignments(entries: string[]): Record<string, string> {
|
|
12
9
|
const envVars: Record<string, string> = {};
|
|
13
10
|
for (const value of entries) {
|
|
@@ -87,11 +84,19 @@ export function parsePollOptions(args: {
|
|
|
87
84
|
};
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
export function
|
|
91
|
-
|
|
87
|
+
export function resolveServiceId(args: {
|
|
88
|
+
service?: string;
|
|
89
|
+
}): string | undefined {
|
|
90
|
+
return (
|
|
91
|
+
args.service || process.env[PRISMA_COMPUTE_SERVICE_ID_ENV] || undefined
|
|
92
|
+
);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
export
|
|
95
|
+
export function printServiceIdHint(serviceId: string): void {
|
|
96
|
+
console.log(
|
|
97
|
+
`\nTip: To skip the service prompt next time, set:\n export ${PRISMA_COMPUTE_SERVICE_ID_ENV}=${serviceId}\n`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
95
100
|
|
|
96
101
|
export function createCommandAbortSignal(): {
|
|
97
102
|
signal: AbortSignal;
|
package/src/commands/projects.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { ComputeClient } from "@prisma/compute-sdk";
|
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
3
|
import { formatTable } from "../lib/format.ts";
|
|
4
4
|
import { printJsonResult } from "../lib/json-output.ts";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
endFlow,
|
|
7
|
+
handleError,
|
|
8
|
+
startFlow,
|
|
9
|
+
withAuthAndSignal,
|
|
10
|
+
} from "./helpers.ts";
|
|
6
11
|
|
|
7
12
|
const projectsListCommand = defineCommand({
|
|
8
13
|
meta: { name: "list", description: "List projects in your workspace" },
|
|
@@ -48,7 +53,84 @@ const projectsListCommand = defineCommand({
|
|
|
48
53
|
},
|
|
49
54
|
});
|
|
50
55
|
|
|
56
|
+
const projectsCreateCommand = defineCommand({
|
|
57
|
+
meta: { name: "create", description: "Create a new project" },
|
|
58
|
+
args: {
|
|
59
|
+
name: { type: "string", description: "Project name" },
|
|
60
|
+
"create-database": {
|
|
61
|
+
type: "boolean",
|
|
62
|
+
default: false,
|
|
63
|
+
description: "Also create a Prisma Postgres database",
|
|
64
|
+
},
|
|
65
|
+
region: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Database region (only with --create-database)",
|
|
68
|
+
},
|
|
69
|
+
json: { type: "boolean", default: false, description: "Output JSON" },
|
|
70
|
+
},
|
|
71
|
+
run: async ({ args }) => {
|
|
72
|
+
const exitCode = await withAuthAndSignal(
|
|
73
|
+
async (managementClient, signal) => {
|
|
74
|
+
const name = args.name;
|
|
75
|
+
if (!name) {
|
|
76
|
+
console.error("Missing required flag: --name <name>");
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (args.region && !args["create-database"]) {
|
|
81
|
+
console.error("--region requires --create-database");
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const flowStarted =
|
|
86
|
+
!args.json && startFlow("Prisma Compute · Projects");
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const sdk = new ComputeClient(managementClient);
|
|
90
|
+
|
|
91
|
+
const result = await sdk.createProject({
|
|
92
|
+
name,
|
|
93
|
+
createDatabase: args["create-database"],
|
|
94
|
+
region: args.region,
|
|
95
|
+
signal,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (args.json) {
|
|
99
|
+
printJsonResult(result);
|
|
100
|
+
return result.isOk() ? 0 : 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (result.isErr()) {
|
|
104
|
+
endFlow(flowStarted);
|
|
105
|
+
console.error(result.error.message);
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const project = result.value;
|
|
110
|
+
console.log(`Created project ${project.name} (${project.id})`);
|
|
111
|
+
|
|
112
|
+
if (project.database) {
|
|
113
|
+
console.log(`Database: ${project.database.id}`);
|
|
114
|
+
console.log(`Region: ${project.database.region}`);
|
|
115
|
+
if (project.database.connectionString) {
|
|
116
|
+
console.log(`Connection: ${project.database.connectionString}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
endFlow(flowStarted);
|
|
121
|
+
return 0;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
endFlow(flowStarted);
|
|
124
|
+
return handleError(error);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (exitCode !== 0) process.exit(exitCode);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
51
133
|
export const projectsGroup = defineCommand({
|
|
52
134
|
meta: { name: "projects", description: "Project management" },
|
|
53
|
-
subCommands: { list: projectsListCommand },
|
|
135
|
+
subCommands: { list: projectsListCommand, create: projectsCreateCommand },
|
|
54
136
|
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { PortMapping } from "@prisma/compute-sdk";
|
|
2
|
-
export declare const COMPUTE_CONFIG_FILENAME = "compute.config.json";
|
|
3
|
-
export type ComputeConfig = {
|
|
4
|
-
projectId: string;
|
|
5
|
-
serviceId: string;
|
|
6
|
-
serviceName?: string;
|
|
7
|
-
region?: string;
|
|
8
|
-
portMapping?: PortMapping;
|
|
9
|
-
};
|
|
10
|
-
export declare function readComputeConfig(filePath: string): Promise<ComputeConfig | null>;
|
|
11
|
-
export declare function writeComputeConfig(filePath: string, config: ComputeConfig): Promise<void>;
|
|
12
|
-
//# sourceMappingURL=compute-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute-config.d.ts","sourceRoot":"","sources":["../../src/lib/compute-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAgB7D,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,CAAC;AAEF,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAU/B;AAED,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,IAAI,CAAC,CAsBf"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
export const COMPUTE_CONFIG_FILENAME = "compute.config.json";
|
|
6
|
-
const computePortMappingSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
http: z.union([z.number().int().min(1).max(65_535), z.null()]).optional(),
|
|
9
|
-
})
|
|
10
|
-
.strict();
|
|
11
|
-
const computeConfigSchema = z.object({
|
|
12
|
-
projectId: z.string().min(1),
|
|
13
|
-
serviceId: z.string().min(1),
|
|
14
|
-
serviceName: z.string().min(1).optional(),
|
|
15
|
-
region: z.string().min(1).optional(),
|
|
16
|
-
portMapping: computePortMappingSchema.optional(),
|
|
17
|
-
});
|
|
18
|
-
export async function readComputeConfig(filePath) {
|
|
19
|
-
try {
|
|
20
|
-
const raw = await readFile(filePath, "utf8");
|
|
21
|
-
return parseComputeConfig(raw, filePath);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
if (isNotFoundError(error)) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export async function writeComputeConfig(filePath, config) {
|
|
31
|
-
const payload = {
|
|
32
|
-
projectId: config.projectId,
|
|
33
|
-
serviceId: config.serviceId,
|
|
34
|
-
serviceName: config.serviceName,
|
|
35
|
-
region: config.region,
|
|
36
|
-
portMapping: config.portMapping,
|
|
37
|
-
};
|
|
38
|
-
const serialized = `${JSON.stringify(payload, null, 2)}\n`;
|
|
39
|
-
const tempPath = path.join(path.dirname(filePath), `.compute.config.${randomUUID()}.tmp`);
|
|
40
|
-
try {
|
|
41
|
-
await writeFile(tempPath, serialized, "utf8");
|
|
42
|
-
await rename(tempPath, filePath);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
await rm(tempPath, { force: true }).catch(() => { });
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function parseComputeConfig(raw, filePath) {
|
|
50
|
-
let parsed;
|
|
51
|
-
try {
|
|
52
|
-
parsed = JSON.parse(raw);
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
throw new Error(`Invalid JSON in ${filePath}`);
|
|
56
|
-
}
|
|
57
|
-
const result = computeConfigSchema.safeParse(parsed);
|
|
58
|
-
if (!result.success) {
|
|
59
|
-
throw new Error(`Invalid config in ${filePath}: ${result.error.message}`);
|
|
60
|
-
}
|
|
61
|
-
return result.data;
|
|
62
|
-
}
|
|
63
|
-
function isNotFoundError(error) {
|
|
64
|
-
return (typeof error === "object" &&
|
|
65
|
-
error !== null &&
|
|
66
|
-
"code" in error &&
|
|
67
|
-
error.code === "ENOENT");
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=compute-config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute-config.js","sourceRoot":"","sources":["../../src/lib/compute-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,uBAAuB,GAAG,qBAAqB,CAAC;AAE7D,MAAM,wBAAwB,GAAG,CAAC;KAC/B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC1E,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACzC,MAAM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M,EAAE,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACpD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAW,EAAE,QAAgB;IACvD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACd,KAA4B,CAAC,IAAI,KAAK,QAAQ,CAChD,CAAC;AACJ,CAAC"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import type { PortMapping } from "@prisma/compute-sdk";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
export const COMPUTE_CONFIG_FILENAME = "compute.config.json";
|
|
8
|
-
|
|
9
|
-
const computePortMappingSchema = z
|
|
10
|
-
.object({
|
|
11
|
-
http: z.union([z.number().int().min(1).max(65_535), z.null()]).optional(),
|
|
12
|
-
})
|
|
13
|
-
.strict();
|
|
14
|
-
|
|
15
|
-
const computeConfigSchema = z.object({
|
|
16
|
-
projectId: z.string().min(1),
|
|
17
|
-
serviceId: z.string().min(1),
|
|
18
|
-
serviceName: z.string().min(1).optional(),
|
|
19
|
-
region: z.string().min(1).optional(),
|
|
20
|
-
portMapping: computePortMappingSchema.optional(),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export type ComputeConfig = {
|
|
24
|
-
projectId: string;
|
|
25
|
-
serviceId: string;
|
|
26
|
-
serviceName?: string;
|
|
27
|
-
region?: string;
|
|
28
|
-
portMapping?: PortMapping;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export async function readComputeConfig(
|
|
32
|
-
filePath: string,
|
|
33
|
-
): Promise<ComputeConfig | null> {
|
|
34
|
-
try {
|
|
35
|
-
const raw = await readFile(filePath, "utf8");
|
|
36
|
-
return parseComputeConfig(raw, filePath);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
if (isNotFoundError(error)) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function writeComputeConfig(
|
|
46
|
-
filePath: string,
|
|
47
|
-
config: ComputeConfig,
|
|
48
|
-
): Promise<void> {
|
|
49
|
-
const payload: ComputeConfig = {
|
|
50
|
-
projectId: config.projectId,
|
|
51
|
-
serviceId: config.serviceId,
|
|
52
|
-
serviceName: config.serviceName,
|
|
53
|
-
region: config.region,
|
|
54
|
-
portMapping: config.portMapping,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const serialized = `${JSON.stringify(payload, null, 2)}\n`;
|
|
58
|
-
const tempPath = path.join(
|
|
59
|
-
path.dirname(filePath),
|
|
60
|
-
`.compute.config.${randomUUID()}.tmp`,
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
await writeFile(tempPath, serialized, "utf8");
|
|
65
|
-
await rename(tempPath, filePath);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
await rm(tempPath, { force: true }).catch(() => {});
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function parseComputeConfig(raw: string, filePath: string): ComputeConfig {
|
|
73
|
-
let parsed: unknown;
|
|
74
|
-
try {
|
|
75
|
-
parsed = JSON.parse(raw);
|
|
76
|
-
} catch {
|
|
77
|
-
throw new Error(`Invalid JSON in ${filePath}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const result = computeConfigSchema.safeParse(parsed);
|
|
81
|
-
if (!result.success) {
|
|
82
|
-
throw new Error(`Invalid config in ${filePath}: ${result.error.message}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return result.data;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function isNotFoundError(error: unknown): error is NodeJS.ErrnoException {
|
|
89
|
-
return (
|
|
90
|
-
typeof error === "object" &&
|
|
91
|
-
error !== null &&
|
|
92
|
-
"code" in error &&
|
|
93
|
-
(error as { code?: unknown }).code === "ENOENT"
|
|
94
|
-
);
|
|
95
|
-
}
|