create-prisma 0.4.2-pr.53.196.1 → 0.4.2-pr.53.198.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/cli.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as DatabaseProviderSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as PackageManagerSchema, r as CreateCommandInputSchema, t as runCreateCommand } from "./create-
|
|
2
|
+
import { a as DatabaseProviderSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as PackageManagerSchema, r as CreateCommandInputSchema, t as runCreateCommand } from "./create-BHcAcUH1.mjs";
|
|
3
3
|
import { os } from "@orpc/server";
|
|
4
4
|
import { createCli } from "trpc-cli";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
|
|
7
7
|
//#region src/index.ts
|
|
8
|
-
const CLI_VERSION = "0.4.2-pr.53.
|
|
8
|
+
const CLI_VERSION = "0.4.2-pr.53.198.1";
|
|
9
9
|
const CreateCliInputSchema = z.tuple([z.string().trim().min(1, "Please enter a valid project name").optional().describe("Project name / directory"), CreateCommandInputSchema]);
|
|
10
10
|
function normalizeCreateCliInput(input) {
|
|
11
11
|
const [projectName, options] = input;
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ This builds the app and starts it with Composer. PostgreSQL projects get a local
|
|
|
18
18
|
|
|
19
19
|
The deploy script builds the framework output, provisions Prisma Postgres when selected, applies migrations, and deploys the app to Prisma Compute.
|
|
20
20
|
|
|
21
|
-
The starter users are inserted idempotently on the first database query. `{{runScriptCommand packageManager "db:seed"}}`
|
|
21
|
+
The starter users are inserted idempotently on the first database query through the Composer service binding. `{{runScriptCommand packageManager "db:seed"}}` starts the app with Composer, seeds through its database route, and stops it again. If `DATABASE_URL` is set explicitly, the command seeds that database directly instead.
|
|
22
22
|
|
|
23
23
|
{{#if (eq provider "mongo")}}
|
|
24
24
|
MongoDB is not provisioned by Composer. Set `MONGODB_URL` before running Composer locally or deploying.
|
|
@@ -1,38 +1,97 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
-
{
|
|
3
|
-
|
|
2
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
const seedPath = {{#if (eq template "astro")}}"/api/users"{{else if (eq template "nuxt")}}"/api/users"{{else if (eq template "hono")}}"/users"{{else if (eq template "elysia")}}"/users"{{else if (eq template "nest")}}"/users"{{else}}"/"{{/if}};
|
|
5
|
+
|
|
6
|
+
async function seedExplicitDatabase(): Promise<void> {
|
|
7
|
+
const [{ db }, { seedStarterData }] = await Promise.all([
|
|
8
|
+
import("./db.ts"),
|
|
9
|
+
import("./starter-data.ts"),
|
|
10
|
+
]);
|
|
4
11
|
|
|
5
|
-
async function loadComposerDevDatabaseUrl(): Promise<string | undefined> {
|
|
6
12
|
try {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
);
|
|
11
|
-
const env = JSON.parse(contents) as Record<string, unknown>;
|
|
12
|
-
const value = env.COMPOSER_APP_DATABASE_URL;
|
|
13
|
-
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
14
|
-
} catch {
|
|
15
|
-
return undefined;
|
|
13
|
+
await seedStarterData();
|
|
14
|
+
} finally {
|
|
15
|
+
await db.close();
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
function stopComposer(child: ChildProcess): void {
|
|
20
|
+
if (child.exitCode !== null || child.pid === undefined) return;
|
|
21
|
+
try {
|
|
22
|
+
if (process.platform === "win32") child.kill("SIGINT");
|
|
23
|
+
else process.kill(-child.pid, "SIGINT");
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (!(error instanceof Error && "code" in error && error.code === "ESRCH")) throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
async function requestStarterUsers(origin: string): Promise<void> {
|
|
30
|
+
let lastStatus = 0;
|
|
31
|
+
for (let attempt = 0; attempt < 30; attempt += 1) {
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(new URL(seedPath, origin));
|
|
34
|
+
const body = await response.text();
|
|
35
|
+
lastStatus = response.status;
|
|
36
|
+
if (response.ok && ["Alice", "Bob", "Carol"].every((name) => body.includes(name))) return;
|
|
37
|
+
} catch {
|
|
38
|
+
// The service may still be accepting its first connection after Composer reports ready.
|
|
39
|
+
}
|
|
40
|
+
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`The app's database route did not return the starter users (HTTP ${lastStatus}).`);
|
|
26
43
|
}
|
|
27
44
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
async function seedThroughComposer(): Promise<void> {
|
|
46
|
+
const child = spawn("{{packageManager}}", ["run", "dev:composer"], {
|
|
47
|
+
cwd: new URL("../..", import.meta.url),
|
|
48
|
+
detached: process.platform !== "win32",
|
|
49
|
+
env: process.env,
|
|
50
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
51
|
+
});
|
|
32
52
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
53
|
+
let output = "";
|
|
54
|
+
let settled = false;
|
|
55
|
+
const ready = new Promise<string>((resolve, reject) => {
|
|
56
|
+
const timeout = setTimeout(() => reject(new Error("Timed out waiting for composer dev.")), 120_000);
|
|
57
|
+
const consume = (chunk: Buffer) => {
|
|
58
|
+
const text = chunk.toString();
|
|
59
|
+
output = `${output}${text}`.slice(-20_000);
|
|
60
|
+
if (!settled) process.stderr.write(text);
|
|
61
|
+
const url = output.match(/\bapp(?::|\s+)\s+(http:\/\/(?:127\.0\.0\.1|localhost):\d+)/)?.[1];
|
|
62
|
+
if (url && !settled) {
|
|
63
|
+
settled = true;
|
|
64
|
+
clearTimeout(timeout);
|
|
65
|
+
resolve(url);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
child.stdout?.on("data", consume);
|
|
69
|
+
child.stderr?.on("data", consume);
|
|
70
|
+
child.once("error", (error) => {
|
|
71
|
+
clearTimeout(timeout);
|
|
72
|
+
reject(error);
|
|
73
|
+
});
|
|
74
|
+
child.once("exit", (code) => {
|
|
75
|
+
if (settled) return;
|
|
76
|
+
clearTimeout(timeout);
|
|
77
|
+
reject(new Error(`composer dev exited before the app was ready (code ${String(code)}).`));
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const stopOnSignal = () => stopComposer(child);
|
|
82
|
+
process.once("SIGINT", stopOnSignal);
|
|
83
|
+
process.once("SIGTERM", stopOnSignal);
|
|
84
|
+
try {
|
|
85
|
+
const origin = await ready;
|
|
86
|
+
await requestStarterUsers(origin);
|
|
87
|
+
} finally {
|
|
88
|
+
process.removeListener("SIGINT", stopOnSignal);
|
|
89
|
+
process.removeListener("SIGTERM", stopOnSignal);
|
|
90
|
+
stopComposer(child);
|
|
91
|
+
}
|
|
38
92
|
}
|
|
93
|
+
|
|
94
|
+
if (process.env.DATABASE_URL) await seedExplicitDatabase();
|
|
95
|
+
else await seedThroughComposer();
|
|
96
|
+
|
|
97
|
+
console.log("Starter users are ready.");
|