@prisma/cli-init 0.0.0-dev.202505142350 → 0.0.1
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/index.d.ts +1 -3
- package/dist/index.js +2 -591
- package/package.json +1 -48
- package/dist/_-EJEMZX3O.js +0 -34
- package/dist/chunk-4Z3GF35Q.js +0 -1487
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,595 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
credentialsFile,
|
|
3
|
-
poll,
|
|
4
|
-
printPpgInitOutput,
|
|
5
|
-
requestOrThrow,
|
|
6
|
-
successMessage
|
|
7
|
-
} from "./chunk-4Z3GF35Q.js";
|
|
8
|
-
|
|
9
|
-
// src/Init.ts
|
|
10
|
-
import { confirm, input, select } from "@inquirer/prompts";
|
|
11
|
-
import internals from "@prisma/internals";
|
|
12
|
-
import dotenv from "dotenv";
|
|
13
|
-
import { Schema as Shape } from "effect";
|
|
14
|
-
import fs2 from "fs";
|
|
15
|
-
import { bold as bold2, dim, green, red as red2, yellow } from "kleur/colors";
|
|
16
|
-
import ora from "ora";
|
|
17
|
-
import path2 from "path";
|
|
18
|
-
import { match, P } from "ts-pattern";
|
|
19
|
-
|
|
20
|
-
// src/utils/client-output-path.ts
|
|
21
|
-
import fs from "fs";
|
|
22
|
-
import path from "path";
|
|
23
|
-
import { getTsconfig } from "get-tsconfig";
|
|
24
|
-
function determineClientOutputPath(schemaDir) {
|
|
25
|
-
const sourceDir = getSourceDir();
|
|
26
|
-
const outputPath = path.join(sourceDir, "generated", "prisma");
|
|
27
|
-
const relativeOutputPath = path.relative(schemaDir, outputPath);
|
|
28
|
-
return relativeOutputPath.replaceAll(path.sep, "/");
|
|
29
|
-
}
|
|
30
|
-
function getSourceDir() {
|
|
31
|
-
const projectDir = process.cwd();
|
|
32
|
-
const sourceRootFromTsConfig = getSourceDirFromTypeScriptConfig();
|
|
33
|
-
if (sourceRootFromTsConfig) {
|
|
34
|
-
return path.join(projectDir, sourceRootFromTsConfig);
|
|
35
|
-
}
|
|
36
|
-
for (const dir of ["src", "lib", "app"]) {
|
|
37
|
-
const absoluteSourceDir = path.join(projectDir, dir);
|
|
38
|
-
if (fs.existsSync(absoluteSourceDir)) {
|
|
39
|
-
return absoluteSourceDir;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return projectDir;
|
|
43
|
-
}
|
|
44
|
-
function getSourceDirFromTypeScriptConfig() {
|
|
45
|
-
const tsconfig = getTsconfig();
|
|
46
|
-
if (!tsconfig) {
|
|
47
|
-
return void 0;
|
|
48
|
-
}
|
|
49
|
-
const { config } = tsconfig;
|
|
50
|
-
return config.compilerOptions?.rootDir ?? config.compilerOptions?.baseUrl ?? config.compilerOptions?.rootDirs?.[0];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/platform/accelerate/regions.ts
|
|
54
|
-
var getRegionsOrThrow = async (input2) => {
|
|
55
|
-
const { token } = input2;
|
|
56
|
-
const { system } = await requestOrThrow({
|
|
57
|
-
token,
|
|
58
|
-
body: {
|
|
59
|
-
query: (
|
|
60
|
-
/* GraphQL */
|
|
61
|
-
`
|
|
62
|
-
query {
|
|
63
|
-
system {
|
|
64
|
-
accelerate {
|
|
65
|
-
regions {
|
|
66
|
-
id
|
|
67
|
-
displayName
|
|
68
|
-
ppgStatus
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
`
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
return system.accelerate.regions;
|
|
78
|
-
};
|
|
79
|
-
var getPrismaPostgresRegionsOrThrow = async (input2) => {
|
|
80
|
-
const regions = await getRegionsOrThrow(input2);
|
|
81
|
-
const ppgRegions = regions.filter((_) => _.ppgStatus !== "unsupported").sort((a, b) => b.displayName.localeCompare(a.displayName));
|
|
82
|
-
return ppgRegions;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// src/utils/print.ts
|
|
86
|
-
import { bgRed, bold, red } from "kleur/colors";
|
|
87
|
-
function printError(text) {
|
|
88
|
-
return bold(bgRed(" ERROR ")) + " " + red(text);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/Init.ts
|
|
92
|
-
var defaultSchema = (props) => {
|
|
93
|
-
const {
|
|
94
|
-
datasourceProvider = "postgresql",
|
|
95
|
-
generatorProvider = defaultGeneratorProvider,
|
|
96
|
-
previewFeatures = defaultPreviewFeatures,
|
|
97
|
-
output = "../generated/prisma",
|
|
98
|
-
withModel = false
|
|
99
|
-
} = props ?? {};
|
|
100
|
-
const aboutAccelerate = `
|
|
101
|
-
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
|
102
|
-
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
|
103
|
-
`;
|
|
104
|
-
const isProviderCompatibleWithAccelerate = datasourceProvider !== "sqlite";
|
|
105
|
-
let schema = `// This is your Prisma schema file,
|
|
106
|
-
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
107
|
-
${isProviderCompatibleWithAccelerate ? aboutAccelerate : ""}
|
|
108
|
-
generator client {
|
|
109
|
-
provider = "${generatorProvider}"
|
|
110
|
-
${previewFeatures.length > 0 ? ` previewFeatures = [${previewFeatures.map((feature) => `"${feature}"`).join(", ")}]
|
|
111
|
-
` : ""} output = "${output}"
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
datasource db {
|
|
115
|
-
provider = "${datasourceProvider}"
|
|
116
|
-
url = env("DATABASE_URL")
|
|
117
|
-
}
|
|
118
|
-
`;
|
|
119
|
-
if (withModel) {
|
|
120
|
-
const defaultAttributes = `email String @unique
|
|
121
|
-
name String?`;
|
|
122
|
-
switch (datasourceProvider) {
|
|
123
|
-
case "mongodb":
|
|
124
|
-
schema += `
|
|
125
|
-
model User {
|
|
126
|
-
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
127
|
-
${defaultAttributes}
|
|
128
|
-
}
|
|
129
|
-
`;
|
|
130
|
-
break;
|
|
131
|
-
case "cockroachdb":
|
|
132
|
-
schema += `
|
|
133
|
-
model User {
|
|
134
|
-
id BigInt @id @default(sequence())
|
|
135
|
-
${defaultAttributes}
|
|
136
|
-
}
|
|
137
|
-
`;
|
|
138
|
-
break;
|
|
139
|
-
default:
|
|
140
|
-
schema += `
|
|
141
|
-
model User {
|
|
142
|
-
id Int @id @default(autoincrement())
|
|
143
|
-
${defaultAttributes}
|
|
144
|
-
}
|
|
145
|
-
`;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return schema;
|
|
149
|
-
};
|
|
150
|
-
var defaultEnv = (url = "postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public", comments = true) => {
|
|
151
|
-
let env = comments ? `# Environment variables declared in this file are automatically made available to Prisma.
|
|
152
|
-
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
|
153
|
-
|
|
154
|
-
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
|
155
|
-
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
|
156
|
-
|
|
157
|
-
` : "";
|
|
158
|
-
env += `DATABASE_URL="${url}"`;
|
|
159
|
-
return env;
|
|
160
|
-
};
|
|
161
|
-
var defaultPort = (datasourceProvider) => {
|
|
162
|
-
switch (datasourceProvider) {
|
|
163
|
-
case "mysql":
|
|
164
|
-
return 3306;
|
|
165
|
-
case "sqlserver":
|
|
166
|
-
return 1433;
|
|
167
|
-
case "mongodb":
|
|
168
|
-
return 27017;
|
|
169
|
-
case "postgresql":
|
|
170
|
-
return 5432;
|
|
171
|
-
case "cockroachdb":
|
|
172
|
-
return 26257;
|
|
173
|
-
case internals.PRISMA_POSTGRES_PROVIDER:
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
return void 0;
|
|
177
|
-
};
|
|
178
|
-
var defaultURL = (datasourceProvider, port = defaultPort(datasourceProvider), schema = "public") => {
|
|
179
|
-
switch (datasourceProvider) {
|
|
180
|
-
case "postgresql":
|
|
181
|
-
return `postgresql://johndoe:randompassword@localhost:${port}/mydb?schema=${schema}`;
|
|
182
|
-
case "cockroachdb":
|
|
183
|
-
return `postgresql://johndoe:randompassword@localhost:${port}/mydb?schema=${schema}`;
|
|
184
|
-
case "mysql":
|
|
185
|
-
return `mysql://johndoe:randompassword@localhost:${port}/mydb`;
|
|
186
|
-
case "sqlserver":
|
|
187
|
-
return `sqlserver://localhost:${port};database=mydb;user=SA;password=randompassword;`;
|
|
188
|
-
case "mongodb":
|
|
189
|
-
return `mongodb+srv://root:randompassword@cluster0.ab1cd.mongodb.net/mydb?retryWrites=true&w=majority`;
|
|
190
|
-
case "sqlite":
|
|
191
|
-
return "file:./dev.db";
|
|
192
|
-
default:
|
|
193
|
-
return void 0;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
var defaultGitIgnore = () => {
|
|
197
|
-
return `node_modules
|
|
198
|
-
# Keep environment variables out of version control
|
|
199
|
-
.env
|
|
200
|
-
`;
|
|
201
|
-
};
|
|
202
|
-
var defaultGeneratorProvider = "prisma-client-js";
|
|
203
|
-
var defaultPreviewFeatures = [];
|
|
204
|
-
var Init = class _Init {
|
|
205
|
-
static new() {
|
|
206
|
-
return new _Init();
|
|
207
|
-
}
|
|
208
|
-
static help = internals.format(`
|
|
209
|
-
Set up a new Prisma project
|
|
210
|
-
|
|
211
|
-
${bold2("Usage")}
|
|
212
|
-
|
|
213
|
-
${dim("$")} prisma init [options]
|
|
214
|
-
|
|
215
|
-
${bold2("Options")}
|
|
216
|
-
|
|
217
|
-
-h, --help Display this help message
|
|
218
|
-
--db Provisions a fully managed Prisma Postgres database on the Prisma Data Platform.
|
|
219
|
-
--datasource-provider Define the datasource provider to use: postgresql, mysql, sqlite, sqlserver, mongodb or cockroachdb
|
|
220
|
-
--generator-provider Define the generator provider to use. Default: \`prisma-client-js\`
|
|
221
|
-
--preview-feature Define a preview feature to use.
|
|
222
|
-
--output Define Prisma Client generator output path to use.
|
|
223
|
-
--url Define a custom datasource url
|
|
224
|
-
|
|
225
|
-
${bold2("Flags")}
|
|
226
|
-
|
|
227
|
-
--with-model Add example model to created schema file
|
|
228
|
-
|
|
229
|
-
${bold2("Examples")}
|
|
230
|
-
|
|
231
|
-
Set up a new Prisma project with PostgreSQL (default)
|
|
232
|
-
${dim("$")} prisma init
|
|
233
|
-
|
|
234
|
-
Set up a new Prisma project and specify MySQL as the datasource provider to use
|
|
235
|
-
${dim("$")} prisma init --datasource-provider mysql
|
|
236
|
-
|
|
237
|
-
Set up a new Prisma project and specify \`prisma-client-go\` as the generator provider to use
|
|
238
|
-
${dim("$")} prisma init --generator-provider prisma-client-go
|
|
239
|
-
|
|
240
|
-
Set up a new Prisma project and specify \`x\` and \`y\` as the preview features to use
|
|
241
|
-
${dim("$")} prisma init --preview-feature x --preview-feature y
|
|
242
|
-
|
|
243
|
-
Set up a new Prisma project and specify \`./generated-client\` as the output path to use
|
|
244
|
-
${dim("$")} prisma init --output ./generated-client
|
|
245
|
-
|
|
246
|
-
Set up a new Prisma project and specify the url that will be used
|
|
247
|
-
${dim("$")} prisma init --url mysql://user:password@localhost:3306/mydb
|
|
248
|
-
|
|
249
|
-
Set up a new Prisma project with an example model
|
|
250
|
-
${dim("$")} prisma init --with-model
|
|
251
|
-
`);
|
|
252
|
-
async parse(argv, _config) {
|
|
253
|
-
const args = internals.arg(argv, {
|
|
254
|
-
"--help": Boolean,
|
|
255
|
-
"-h": "--help",
|
|
256
|
-
"--url": String,
|
|
257
|
-
"--datasource-provider": String,
|
|
258
|
-
"--generator-provider": String,
|
|
259
|
-
"--preview-feature": [String],
|
|
260
|
-
"--output": String,
|
|
261
|
-
"--with-model": Boolean,
|
|
262
|
-
"--db": Boolean,
|
|
263
|
-
"--region": String,
|
|
264
|
-
"--name": String,
|
|
265
|
-
"--non-interactive": Boolean,
|
|
266
|
-
"--prompt": String,
|
|
267
|
-
"--vibe": String
|
|
268
|
-
});
|
|
269
|
-
if (internals.isError(args) || args["--help"]) {
|
|
270
|
-
return this.help();
|
|
271
|
-
}
|
|
272
|
-
internals.checkUnsupportedDataProxy({ cmd: "init", urls: [args["--url"]] });
|
|
273
|
-
const outputDirName = args._[0];
|
|
274
|
-
if (outputDirName) {
|
|
275
|
-
throw Error("The init command does not take any argument.");
|
|
276
|
-
}
|
|
277
|
-
const { datasourceProvider, url } = await match(args).with(
|
|
278
|
-
{
|
|
279
|
-
"--datasource-provider": P.when(
|
|
280
|
-
(datasourceProvider2) => Boolean(datasourceProvider2)
|
|
281
|
-
)
|
|
282
|
-
},
|
|
283
|
-
(input2) => {
|
|
284
|
-
const datasourceProviderLowercase = input2["--datasource-provider"].toLowerCase();
|
|
285
|
-
if (![
|
|
286
|
-
"postgresql",
|
|
287
|
-
"mysql",
|
|
288
|
-
"sqlserver",
|
|
289
|
-
"sqlite",
|
|
290
|
-
"mongodb",
|
|
291
|
-
"cockroachdb",
|
|
292
|
-
"prismapostgres",
|
|
293
|
-
"prisma+postgres"
|
|
294
|
-
].includes(datasourceProviderLowercase)) {
|
|
295
|
-
throw new Error(
|
|
296
|
-
`Provider "${args["--datasource-provider"]}" is invalid or not supported. Try again with "postgresql", "mysql", "sqlite", "sqlserver", "mongodb" or "cockroachdb".`
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
const datasourceProvider2 = datasourceProviderLowercase;
|
|
300
|
-
const url2 = defaultURL(datasourceProvider2);
|
|
301
|
-
return Promise.resolve({
|
|
302
|
-
datasourceProvider: datasourceProvider2,
|
|
303
|
-
url: url2
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
).with(
|
|
307
|
-
{
|
|
308
|
-
"--url": P.when((url2) => Boolean(url2))
|
|
309
|
-
},
|
|
310
|
-
async (input2) => {
|
|
311
|
-
const url2 = input2["--url"];
|
|
312
|
-
const canConnect = await internals.canConnectToDatabase(url2);
|
|
313
|
-
if (canConnect !== true) {
|
|
314
|
-
const { code, message } = canConnect;
|
|
315
|
-
if (code !== "P1003") {
|
|
316
|
-
if (code) {
|
|
317
|
-
throw new Error(`${code}: ${message}`);
|
|
318
|
-
} else {
|
|
319
|
-
throw new Error(message);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
const datasourceProvider2 = internals.protocolToConnectorType(`${url2.split(":")[0]}:`);
|
|
324
|
-
return { datasourceProvider: datasourceProvider2, url: url2 };
|
|
325
|
-
}
|
|
326
|
-
).otherwise(() => {
|
|
327
|
-
return Promise.resolve({
|
|
328
|
-
datasourceProvider: "postgresql",
|
|
329
|
-
url: void 0
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
const generatorProvider = args["--generator-provider"];
|
|
333
|
-
const previewFeatures = args["--preview-feature"];
|
|
334
|
-
const output = args["--output"];
|
|
335
|
-
const isPpgCommand = args["--db"] || datasourceProvider === internals.PRISMA_POSTGRES_PROVIDER || args["--prompt"] || args["--vibe"];
|
|
336
|
-
let prismaPostgresDatabaseUrl;
|
|
337
|
-
let workspaceId = ``;
|
|
338
|
-
let projectId = ``;
|
|
339
|
-
let environmentId = ``;
|
|
340
|
-
const outputDir = process.cwd();
|
|
341
|
-
const prismaFolder = path2.join(outputDir, "prisma");
|
|
342
|
-
let generatedSchema;
|
|
343
|
-
let generatedName;
|
|
344
|
-
if (isPpgCommand) {
|
|
345
|
-
const PlatformCommands = await import("./_-EJEMZX3O.js");
|
|
346
|
-
const credentials = await credentialsFile.load();
|
|
347
|
-
if (internals.isError(credentials))
|
|
348
|
-
throw credentials;
|
|
349
|
-
if (!credentials) {
|
|
350
|
-
if (args["--non-interactive"]) {
|
|
351
|
-
return "Please authenticate before creating a Prisma Postgres project.";
|
|
352
|
-
}
|
|
353
|
-
console.log("This will create a project for you on console.prisma.io and requires you to be authenticated.");
|
|
354
|
-
const authAnswer = await confirm({
|
|
355
|
-
message: "Would you like to authenticate?"
|
|
356
|
-
});
|
|
357
|
-
if (!authAnswer) {
|
|
358
|
-
return "Project creation aborted. You need to authenticate to use Prisma Postgres";
|
|
359
|
-
}
|
|
360
|
-
const authenticationResult = await PlatformCommands.loginOrSignup();
|
|
361
|
-
console.log(`Successfully authenticated as ${bold2(authenticationResult.email)}.`);
|
|
362
|
-
}
|
|
363
|
-
if (args["--prompt"] || args["--vibe"]) {
|
|
364
|
-
const prompt = args["--prompt"] || args["--vibe"] || "";
|
|
365
|
-
const spinner2 = ora(`Generating a Prisma Schema based on your description ${bold2(prompt)} ...`).start();
|
|
366
|
-
try {
|
|
367
|
-
const serverResponseShape = Shape.Struct({
|
|
368
|
-
generatedSchema: Shape.String,
|
|
369
|
-
generatedName: Shape.String
|
|
370
|
-
});
|
|
371
|
-
({ generatedSchema, generatedName } = Shape.decodeUnknownSync(serverResponseShape)(
|
|
372
|
-
await (await fetch(`https://prisma-generate-server.prisma.workers.dev/`, {
|
|
373
|
-
method: "POST",
|
|
374
|
-
headers: {
|
|
375
|
-
"Content-Type": "application/json"
|
|
376
|
-
},
|
|
377
|
-
body: JSON.stringify({
|
|
378
|
-
description: prompt
|
|
379
|
-
})
|
|
380
|
-
})).json()
|
|
381
|
-
));
|
|
382
|
-
} catch (e) {
|
|
383
|
-
spinner2.fail();
|
|
384
|
-
throw e;
|
|
385
|
-
}
|
|
386
|
-
spinner2.succeed("Schema is ready");
|
|
387
|
-
}
|
|
388
|
-
console.log("Let's set up your Prisma Postgres database!");
|
|
389
|
-
const platformToken = await PlatformCommands.getTokenOrThrow(args);
|
|
390
|
-
const defaultWorkspace = await PlatformCommands.Workspace.getDefaultWorkspaceOrThrow({ token: platformToken });
|
|
391
|
-
const regions = await getPrismaPostgresRegionsOrThrow({ token: platformToken });
|
|
392
|
-
const ppgRegionSelection = args["--region"] || await select({
|
|
393
|
-
message: "Select your region:",
|
|
394
|
-
default: "us-east-1",
|
|
395
|
-
choices: regions.map((region) => ({
|
|
396
|
-
name: `${region.id} - ${region.displayName}`,
|
|
397
|
-
value: region.id,
|
|
398
|
-
disabled: region.ppgStatus === "unavailable"
|
|
399
|
-
})),
|
|
400
|
-
loop: true
|
|
401
|
-
});
|
|
402
|
-
const projectDisplayNameAnswer = args["--name"] || await input({
|
|
403
|
-
message: "Enter a project name:",
|
|
404
|
-
default: generatedName || "My Prisma Project"
|
|
405
|
-
});
|
|
406
|
-
const spinner = ora(
|
|
407
|
-
`Creating project ${bold2(projectDisplayNameAnswer)} (this may take a few seconds)...`
|
|
408
|
-
).start();
|
|
409
|
-
try {
|
|
410
|
-
const project = await PlatformCommands.Project.createProjectOrThrow({
|
|
411
|
-
token: platformToken,
|
|
412
|
-
displayName: projectDisplayNameAnswer,
|
|
413
|
-
workspaceId: defaultWorkspace.id,
|
|
414
|
-
allowRemoteDatabases: false,
|
|
415
|
-
ppgRegion: ppgRegionSelection
|
|
416
|
-
});
|
|
417
|
-
spinner.text = `Waiting for your Prisma Postgres database to be ready...`;
|
|
418
|
-
workspaceId = defaultWorkspace.id;
|
|
419
|
-
projectId = project.id;
|
|
420
|
-
environmentId = project.defaultEnvironment.id;
|
|
421
|
-
await poll(
|
|
422
|
-
() => PlatformCommands.Environment.getEnvironmentOrThrow({
|
|
423
|
-
environmentId: project.defaultEnvironment.id,
|
|
424
|
-
token: platformToken
|
|
425
|
-
}),
|
|
426
|
-
(environment) => environment.ppg.status === "healthy" && environment.accelerate.status.enabled,
|
|
427
|
-
5e3,
|
|
428
|
-
// Poll every 5 seconds
|
|
429
|
-
12e4
|
|
430
|
-
// if it takes more than two minutes, bail with an error
|
|
431
|
-
);
|
|
432
|
-
const serviceToken = await PlatformCommands.ServiceToken.createOrThrow({
|
|
433
|
-
token: platformToken,
|
|
434
|
-
environmentId: project.defaultEnvironment.id,
|
|
435
|
-
displayName: `database-setup-prismaPostgres-api-key`
|
|
436
|
-
});
|
|
437
|
-
prismaPostgresDatabaseUrl = `${internals.PRISMA_POSTGRES_PROTOCOL}//accelerate.prisma-data.net/?api_key=${serviceToken.value}`;
|
|
438
|
-
spinner.succeed(successMessage("Your Prisma Postgres database is ready \u2705"));
|
|
439
|
-
} catch (error) {
|
|
440
|
-
spinner.fail(error instanceof Error ? error.message : "Something went wrong");
|
|
441
|
-
throw error;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
if (fs2.existsSync(path2.join(outputDir, "schema.prisma")) || fs2.existsSync(prismaFolder) || fs2.existsSync(path2.join(prismaFolder, "schema.prisma"))) {
|
|
445
|
-
if (isPpgCommand) {
|
|
446
|
-
return printPpgInitOutput({
|
|
447
|
-
databaseUrl: prismaPostgresDatabaseUrl,
|
|
448
|
-
workspaceId,
|
|
449
|
-
projectId,
|
|
450
|
-
environmentId,
|
|
451
|
-
isExistingPrismaProject: true
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
if (fs2.existsSync(path2.join(outputDir, "schema.prisma"))) {
|
|
456
|
-
console.log(
|
|
457
|
-
printError(`File ${bold2("schema.prisma")} already exists in your project.
|
|
458
|
-
Please try again in a project that is not yet using Prisma.
|
|
459
|
-
`)
|
|
460
|
-
);
|
|
461
|
-
process.exit(1);
|
|
462
|
-
}
|
|
463
|
-
if (fs2.existsSync(prismaFolder)) {
|
|
464
|
-
console.log(
|
|
465
|
-
printError(`A folder called ${bold2("prisma")} already exists in your project.
|
|
466
|
-
Please try again in a project that is not yet using Prisma.
|
|
467
|
-
`)
|
|
468
|
-
);
|
|
469
|
-
process.exit(1);
|
|
470
|
-
}
|
|
471
|
-
if (fs2.existsSync(path2.join(prismaFolder, "schema.prisma"))) {
|
|
472
|
-
console.log(
|
|
473
|
-
printError(`File ${bold2("prisma/schema.prisma")} already exists in your project.
|
|
474
|
-
Please try again in a project that is not yet using Prisma.
|
|
475
|
-
`)
|
|
476
|
-
);
|
|
477
|
-
process.exit(1);
|
|
478
|
-
}
|
|
479
|
-
if (!fs2.existsSync(outputDir)) {
|
|
480
|
-
fs2.mkdirSync(outputDir);
|
|
481
|
-
}
|
|
482
|
-
if (!fs2.existsSync(prismaFolder)) {
|
|
483
|
-
fs2.mkdirSync(prismaFolder);
|
|
484
|
-
}
|
|
485
|
-
const clientOutput = output ?? determineClientOutputPath(prismaFolder);
|
|
486
|
-
fs2.writeFileSync(
|
|
487
|
-
path2.join(prismaFolder, "schema.prisma"),
|
|
488
|
-
generatedSchema || defaultSchema({
|
|
489
|
-
datasourceProvider,
|
|
490
|
-
generatorProvider,
|
|
491
|
-
previewFeatures,
|
|
492
|
-
output: clientOutput,
|
|
493
|
-
withModel: args["--with-model"]
|
|
494
|
-
})
|
|
495
|
-
);
|
|
496
|
-
const databaseUrl = prismaPostgresDatabaseUrl || url;
|
|
497
|
-
const warnings = [];
|
|
498
|
-
const envPath = path2.join(outputDir, ".env");
|
|
499
|
-
if (!fs2.existsSync(envPath)) {
|
|
500
|
-
fs2.writeFileSync(envPath, defaultEnv(databaseUrl));
|
|
501
|
-
} else {
|
|
502
|
-
const envFile = fs2.readFileSync(envPath, { encoding: "utf8" });
|
|
503
|
-
const config = dotenv.parse(envFile);
|
|
504
|
-
if (Object.keys(config).includes("DATABASE_URL")) {
|
|
505
|
-
warnings.push(
|
|
506
|
-
`${yellow("warn")} Prisma would have added DATABASE_URL but it already exists in ${bold2(
|
|
507
|
-
path2.relative(outputDir, envPath)
|
|
508
|
-
)}`
|
|
509
|
-
);
|
|
510
|
-
} else {
|
|
511
|
-
fs2.appendFileSync(envPath, `
|
|
512
|
-
|
|
513
|
-
# This was inserted by \`prisma init\`:
|
|
514
|
-
` + defaultEnv(databaseUrl));
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
const gitignorePath = path2.join(outputDir, ".gitignore");
|
|
518
|
-
try {
|
|
519
|
-
fs2.writeFileSync(gitignorePath, defaultGitIgnore(), { flag: "wx" });
|
|
520
|
-
} catch (e) {
|
|
521
|
-
if (e.code === "EEXIST") {
|
|
522
|
-
warnings.push(
|
|
523
|
-
`${yellow(
|
|
524
|
-
"warn"
|
|
525
|
-
)} You already have a .gitignore file. Don't forget to add \`.env\` in it to not commit any private information.`
|
|
526
|
-
);
|
|
527
|
-
} else {
|
|
528
|
-
console.error("Failed to write .gitignore file, reason: ", e);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
const steps = [];
|
|
532
|
-
if (datasourceProvider === "mongodb") {
|
|
533
|
-
steps.push(`Define models in the schema.prisma file.`);
|
|
534
|
-
} else {
|
|
535
|
-
steps.push(
|
|
536
|
-
`Run ${green(internals.getCommandWithExecutor("prisma db pull"))} to turn your database schema into a Prisma schema.`
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
steps.push(
|
|
540
|
-
`Run ${green(
|
|
541
|
-
internals.getCommandWithExecutor("prisma generate")
|
|
542
|
-
)} to generate the Prisma Client. You can then start querying your database.`
|
|
543
|
-
);
|
|
544
|
-
steps.push(
|
|
545
|
-
`Tip: Explore how you can extend the ${green(
|
|
546
|
-
"ORM"
|
|
547
|
-
)} with scalable connection pooling, global caching, and real-time database events. Read: https://pris.ly/cli/beyond-orm`
|
|
548
|
-
);
|
|
549
|
-
if (!url && !args["--datasource-provider"]) {
|
|
550
|
-
steps.unshift(
|
|
551
|
-
`Set the ${green("provider")} of the ${green("datasource")} block in ${green(
|
|
552
|
-
"schema.prisma"
|
|
553
|
-
)} to match your database: ${green("postgresql")}, ${green("mysql")}, ${green("sqlite")}, ${green(
|
|
554
|
-
"sqlserver"
|
|
555
|
-
)}, ${green("mongodb")} or ${green("cockroachdb")}.`
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
if (!args["--url"]) {
|
|
559
|
-
steps.unshift(
|
|
560
|
-
`Set the ${green("DATABASE_URL")} in the ${green(
|
|
561
|
-
".env"
|
|
562
|
-
)} file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started`
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
const defaultOutput = `
|
|
566
|
-
\u2714 Your Prisma schema was created at ${green("prisma/schema.prisma")}
|
|
567
|
-
You can now open it in your favorite editor.
|
|
568
|
-
${warnings.length > 0 && internals.logger.should.warn() ? `
|
|
569
|
-
${warnings.join("\n")}
|
|
570
|
-
` : ""}
|
|
571
|
-
Next steps:
|
|
572
|
-
${steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
573
|
-
|
|
574
|
-
More information in our documentation:
|
|
575
|
-
${internals.link("https://pris.ly/d/getting-started")}
|
|
576
|
-
`;
|
|
577
|
-
return isPpgCommand ? printPpgInitOutput({ databaseUrl: prismaPostgresDatabaseUrl, workspaceId, projectId, environmentId }) : defaultOutput;
|
|
578
|
-
}
|
|
579
|
-
// help message
|
|
580
|
-
help(error) {
|
|
581
|
-
if (error) {
|
|
582
|
-
return new internals.HelpError(`
|
|
583
|
-
${bold2(red2(`!`))} ${error}
|
|
584
|
-
${_Init.help}`);
|
|
585
|
-
}
|
|
586
|
-
return _Init.help;
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
// src/index.ts
|
|
1
|
+
// index.ts
|
|
591
2
|
function run(args, config) {
|
|
592
|
-
|
|
3
|
+
console.log("Hello world from @primsa/cli-init");
|
|
593
4
|
}
|
|
594
5
|
export {
|
|
595
6
|
run
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/cli-init",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"description": "Init CLI for Prisma",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -16,52 +16,5 @@
|
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
18
|
}
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"cli",
|
|
22
|
-
"prisma",
|
|
23
|
-
"init",
|
|
24
|
-
"development",
|
|
25
|
-
"server",
|
|
26
|
-
"ppg",
|
|
27
|
-
"postgres"
|
|
28
|
-
],
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@arethetypeswrong/cli": "0.17.4",
|
|
31
|
-
"@prisma/get-platform": "6.7.0",
|
|
32
|
-
"@types/fs-extra": "11.0.4",
|
|
33
|
-
"@types/node": "22.3.0",
|
|
34
|
-
"strip-ansi": "7.1.0",
|
|
35
|
-
"tsup": "8.0.2",
|
|
36
|
-
"typescript": "5.8.3",
|
|
37
|
-
"vitest": "3.1.3"
|
|
38
|
-
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@inquirer/prompts": "7.3.3",
|
|
41
|
-
"@prisma/config": "6.7.0",
|
|
42
|
-
"@prisma/debug": "6.7.0",
|
|
43
|
-
"@prisma/generator": "6.7.0",
|
|
44
|
-
"@prisma/internals": "6.7.0",
|
|
45
|
-
"arg": "5.0.2",
|
|
46
|
-
"async-listen": "3.1.0",
|
|
47
|
-
"checkpoint-client": "1.1.33",
|
|
48
|
-
"dotenv": "16.5.0",
|
|
49
|
-
"effect": "3.12.10",
|
|
50
|
-
"fs-extra": "11.3.0",
|
|
51
|
-
"get-tsconfig": "4.10.0",
|
|
52
|
-
"kleur": "4.1.5",
|
|
53
|
-
"node-fetch": "3.3.2",
|
|
54
|
-
"open": "7.4.2",
|
|
55
|
-
"ora": "8.2.0",
|
|
56
|
-
"ts-pattern": "5.6.2",
|
|
57
|
-
"xdg-app-paths": "8.3.0"
|
|
58
|
-
},
|
|
59
|
-
"scripts": {
|
|
60
|
-
"build": "tsup",
|
|
61
|
-
"check:exports": "attw . --pack --profile esm-only",
|
|
62
|
-
"dev": "tsup --watch",
|
|
63
|
-
"lint": "eslint --fix .",
|
|
64
|
-
"test": "vitest",
|
|
65
|
-
"typecheck": "tsc --noEmit"
|
|
66
19
|
}
|
|
67
20
|
}
|
package/dist/_-EJEMZX3O.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ErrorPlatformUnauthorized,
|
|
3
|
-
Login,
|
|
4
|
-
Logout,
|
|
5
|
-
__exports,
|
|
6
|
-
__exports2,
|
|
7
|
-
__exports3,
|
|
8
|
-
__exports4,
|
|
9
|
-
__exports5,
|
|
10
|
-
__exports6,
|
|
11
|
-
generateConnectionString,
|
|
12
|
-
getTokenOrThrow,
|
|
13
|
-
loginOrSignup,
|
|
14
|
-
platformParameters,
|
|
15
|
-
poll,
|
|
16
|
-
printPpgInitOutput
|
|
17
|
-
} from "./chunk-4Z3GF35Q.js";
|
|
18
|
-
export {
|
|
19
|
-
__exports as Accelerate,
|
|
20
|
-
__exports2 as Auth,
|
|
21
|
-
__exports3 as Environment,
|
|
22
|
-
ErrorPlatformUnauthorized,
|
|
23
|
-
Login,
|
|
24
|
-
Logout,
|
|
25
|
-
__exports4 as Project,
|
|
26
|
-
__exports5 as ServiceToken,
|
|
27
|
-
__exports6 as Workspace,
|
|
28
|
-
generateConnectionString,
|
|
29
|
-
getTokenOrThrow,
|
|
30
|
-
loginOrSignup,
|
|
31
|
-
platformParameters,
|
|
32
|
-
poll,
|
|
33
|
-
printPpgInitOutput
|
|
34
|
-
};
|