@cedarjs/cli 5.0.7-next.338 → 5.0.7
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 +10 -7
- package/dist/cfw.js +1 -3
- package/dist/commands/build/buildHandler.js +6 -14
- package/dist/commands/console.js +3 -5
- package/dist/commands/consoleHandler.js +75 -0
- package/dist/commands/dev/devHandler.js +4 -71
- package/dist/commands/dev.js +4 -7
- package/dist/commands/execHandler.js +0 -12
- package/dist/commands/experimental/setupOpentelemetryHandler.js +1 -1
- package/dist/commands/generate/helpers.js +0 -16
- package/dist/commands/generate/job/jobHandler.js +7 -5
- package/dist/commands/generate/package/filesTask.js +0 -12
- package/dist/commands/generate/package/packageHandler.js +11 -18
- package/dist/commands/generate/package/templates/test.ts.template +2 -2
- package/dist/commands/generate/scaffold/scaffoldHandler.js +19 -138
- package/dist/commands/generate/script/templates/script.ts.template +4 -9
- package/dist/commands/generate/sdl/sdlHandler.js +44 -113
- package/dist/commands/generate/sdl/templates/sdl.js.template +1 -2
- package/dist/commands/generate/sdl/templates/sdl.ts.template +1 -2
- package/dist/commands/generate/service/serviceHandler.js +6 -17
- package/dist/commands/generate/yargsHandlerHelpers.js +6 -0
- package/dist/commands/lint.js +61 -1
- package/dist/commands/prismaHandler.js +7 -4
- package/dist/commands/serve.js +24 -23
- package/dist/commands/serveBothHandler.js +4 -4
- package/dist/commands/setup/auth/auth.js +1 -1
- package/dist/commands/setup/deploy/helpers/index.js +39 -9
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +5 -17
- package/dist/commands/setup/deploy/providers/renderHandler.js +21 -27
- package/dist/commands/setup/deploy/templates/render.js +16 -29
- package/dist/commands/setup/docker/templates/Dockerfile.yarn +5 -2
- package/dist/commands/setup/docker/templates/docker-compose.dev.yml +1 -1
- package/dist/commands/setup/docker/templates/docker-compose.prod.yml +5 -2
- package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +3 -6
- package/dist/commands/setup/monitoring/sentry/sentryHandler.js +4 -9
- package/dist/commands/setup/neon/neon.js +3 -13
- package/dist/commands/setup/neon/neonHandler.js +258 -141
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +1 -3
- package/dist/commands/setup/ui/libraries/mantineHandler.js +1 -3
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +1 -0
- package/dist/commands/setup/uploads/uploadsHandler.js +5 -6
- package/dist/commands/setup.js +1 -2
- package/dist/commands/test/testHandlerEsm.js +1 -1
- package/dist/commands/upgrade/preUpgradeScripts.js +9 -9
- package/dist/commands/upgrade/upgradeHandler.js +32 -42
- package/dist/lib/background.js +1 -20
- package/dist/lib/exec.js +8 -5
- package/dist/lib/extendFile.js +1 -1
- package/dist/lib/index.js +6 -22
- package/dist/lib/updateCheck.js +6 -34
- package/dist/telemetry/resource.js +8 -3
- package/package.json +27 -26
- package/dist/commands/generate/package/templates/vitest.config.ts.template +0 -9
- package/dist/commands/generate/sdl/stubFiles.js +0 -132
- package/dist/commands/setup/database/database.js +0 -15
- package/dist/commands/setup/database/postgres.js +0 -19
- package/dist/commands/setup/database/postgresHandler.js +0 -194
- /package/dist/commands/setup/{database → neon}/templates/db.ts.template +0 -0
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import execa from "execa";
|
|
4
|
-
import { Listr } from "listr2";
|
|
5
|
-
import { colors, getPaths, installPackages } from "@cedarjs/cli-helpers";
|
|
6
|
-
import { prettyPrintCedarCommand } from "@cedarjs/cli-helpers/packageManager";
|
|
7
|
-
import { addWorkspacePackages } from "@cedarjs/cli-helpers/packageManager/packages";
|
|
8
|
-
import { resolveFile } from "@cedarjs/project-config";
|
|
9
|
-
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
10
|
-
function checkProjectShape(cedarPaths) {
|
|
11
|
-
const schemaPath = path.join(cedarPaths.api.base, "db", "schema.prisma");
|
|
12
|
-
const dbPath = resolveFile(path.join(cedarPaths.api.lib, "db"));
|
|
13
|
-
if (!fs.existsSync(schemaPath)) {
|
|
14
|
-
return blocked(`Could not find ${schemaPath}.`);
|
|
15
|
-
}
|
|
16
|
-
if (!dbPath) {
|
|
17
|
-
return blocked(`No ${path.join(cedarPaths.api.lib, "db")} file found`);
|
|
18
|
-
}
|
|
19
|
-
const schemaContent = fs.readFileSync(schemaPath, "utf-8");
|
|
20
|
-
const hasPgAdapter = fs.readFileSync(dbPath, "utf-8").includes("PrismaPg");
|
|
21
|
-
if (schemaContent.includes('provider = "postgresql"') && hasPgAdapter) {
|
|
22
|
-
return {
|
|
23
|
-
ok: false,
|
|
24
|
-
alreadyConverted: true,
|
|
25
|
-
message: "This project is already configured for PostgreSQL."
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if (!schemaContent.includes('provider = "sqlite"') || hasPgAdapter) {
|
|
29
|
-
return blocked(
|
|
30
|
-
"This command only converts a project that is still on SQLite, with the default adapter in api/src/lib/db.ts (or db.js) untouched. This project doesn't match that shape (a different provider, or a partial previous conversion). Please switch it over to PostgreSQL manually."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
return { ok: true, dbPath };
|
|
34
|
-
}
|
|
35
|
-
function blocked(message) {
|
|
36
|
-
return { ok: false, alreadyConverted: false, message };
|
|
37
|
-
}
|
|
38
|
-
function getSqliteToPostgresTasks({
|
|
39
|
-
dbPath
|
|
40
|
-
}) {
|
|
41
|
-
const cedarPaths = getPaths();
|
|
42
|
-
const schemaPath = path.join(cedarPaths.api.base, "db", "schema.prisma");
|
|
43
|
-
const rootPkgPath = path.join(cedarPaths.base, "package.json");
|
|
44
|
-
const apiPkgPath = path.join(cedarPaths.api.base, "package.json");
|
|
45
|
-
const dbTsTemplatePath = path.join(
|
|
46
|
-
import.meta.dirname,
|
|
47
|
-
"templates",
|
|
48
|
-
"db.ts.template"
|
|
49
|
-
);
|
|
50
|
-
return [
|
|
51
|
-
{
|
|
52
|
-
title: "Removing SQLite dependencies from api/package.json",
|
|
53
|
-
task: () => {
|
|
54
|
-
const pkg = JSON.parse(fs.readFileSync(apiPkgPath, "utf-8"));
|
|
55
|
-
if (pkg.dependencies) {
|
|
56
|
-
delete pkg.dependencies["better-sqlite3"];
|
|
57
|
-
delete pkg.dependencies["@prisma/adapter-better-sqlite3"];
|
|
58
|
-
}
|
|
59
|
-
fs.writeFileSync(apiPkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
title: "Removing better-sqlite3 dependenciesMeta",
|
|
64
|
-
task: () => {
|
|
65
|
-
if (!fs.existsSync(rootPkgPath)) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const pkg = JSON.parse(fs.readFileSync(rootPkgPath, "utf-8"));
|
|
69
|
-
if (pkg.dependenciesMeta?.["better-sqlite3"]) {
|
|
70
|
-
delete pkg.dependenciesMeta["better-sqlite3"];
|
|
71
|
-
if (Object.keys(pkg.dependenciesMeta).length === 0) {
|
|
72
|
-
delete pkg.dependenciesMeta;
|
|
73
|
-
}
|
|
74
|
-
fs.writeFileSync(rootPkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
title: "Switching Prisma schema to PostgreSQL",
|
|
80
|
-
task: () => {
|
|
81
|
-
const schemaContent = fs.readFileSync(schemaPath, "utf-8");
|
|
82
|
-
fs.writeFileSync(
|
|
83
|
-
schemaPath,
|
|
84
|
-
schemaContent.replace(
|
|
85
|
-
'provider = "sqlite"',
|
|
86
|
-
'provider = "postgresql"'
|
|
87
|
-
)
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
title: "Updating database adapter",
|
|
93
|
-
task: () => {
|
|
94
|
-
const pgDbTs = fs.readFileSync(dbTsTemplatePath, "utf-8");
|
|
95
|
-
fs.writeFileSync(dbPath, pgDbTs);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
title: "Adding required api packages...",
|
|
100
|
-
task: async () => {
|
|
101
|
-
await addWorkspacePackages("api", ["@prisma/adapter-pg@7.8.0"], {
|
|
102
|
-
cwd: cedarPaths.api.base
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
function readEnvVar(envContent, name) {
|
|
109
|
-
return envContent.match(new RegExp(`^${name}=(.*)$`, "m"))?.[1] || void 0;
|
|
110
|
-
}
|
|
111
|
-
async function handler() {
|
|
112
|
-
const cedarPaths = getPaths();
|
|
113
|
-
const shape = checkProjectShape(cedarPaths);
|
|
114
|
-
if (!shape.ok) {
|
|
115
|
-
if (shape.alreadyConverted) {
|
|
116
|
-
console.log(colors.note(shape.message));
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
console.error(colors.error(shape.message));
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
const envPath = path.join(cedarPaths.base, ".env");
|
|
123
|
-
const envContent = fs.existsSync(envPath) ? fs.readFileSync(envPath, "utf-8") : "";
|
|
124
|
-
const databaseUrl = readEnvVar(envContent, "DATABASE_URL");
|
|
125
|
-
const tasks = new Listr(
|
|
126
|
-
[
|
|
127
|
-
...getSqliteToPostgresTasks({ dbPath: shape.dbPath }),
|
|
128
|
-
installPackages,
|
|
129
|
-
{
|
|
130
|
-
title: "Running Prisma migrations",
|
|
131
|
-
skip: () => {
|
|
132
|
-
if (!databaseUrl) {
|
|
133
|
-
return `No DATABASE_URL found in \`.env\`. Set it to your PostgreSQL connection string, then run \`${prettyPrintCedarCommand(["prisma", "migrate", "dev"])}\``;
|
|
134
|
-
}
|
|
135
|
-
return false;
|
|
136
|
-
},
|
|
137
|
-
task: () => {
|
|
138
|
-
const result = execa.commandSync(
|
|
139
|
-
"yarn cedar prisma migrate dev --name init-postgres",
|
|
140
|
-
{
|
|
141
|
-
cwd: cedarPaths.base,
|
|
142
|
-
stdio: ["inherit", "inherit", "pipe"],
|
|
143
|
-
reject: false
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
if (result.exitCode !== 0) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
"Prisma migration failed:\n\n" + result.stderr + `
|
|
149
|
-
|
|
150
|
-
You can try running it manually:
|
|
151
|
-
${prettyPrintCedarCommand(["prisma", "migrate", "dev", "--name", "init-postgres"])}`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
],
|
|
157
|
-
{
|
|
158
|
-
exitOnError: false,
|
|
159
|
-
collectErrors: "minimal"
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
try {
|
|
163
|
-
await tasks.run();
|
|
164
|
-
if (tasks.errors.length > 0) {
|
|
165
|
-
for (const error of tasks.errors) {
|
|
166
|
-
if (isErrorWithMessage(error)) {
|
|
167
|
-
errorTelemetry(process.argv, error.message);
|
|
168
|
-
console.error(colors.error(error.message));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
process.exit(1);
|
|
172
|
-
}
|
|
173
|
-
} catch (e) {
|
|
174
|
-
if (isErrorWithMessage(e)) {
|
|
175
|
-
errorTelemetry(process.argv, e.message);
|
|
176
|
-
console.error(colors.error(e.message));
|
|
177
|
-
}
|
|
178
|
-
if (isErrorWithExitCode(e)) {
|
|
179
|
-
process.exit(e.exitCode);
|
|
180
|
-
}
|
|
181
|
-
process.exit(1);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
function isErrorWithMessage(e) {
|
|
185
|
-
return !!e && typeof e === "object" && "message" in e;
|
|
186
|
-
}
|
|
187
|
-
function isErrorWithExitCode(e) {
|
|
188
|
-
return !!e && typeof e === "object" && "exitCode" in e && typeof e.exitCode === "number";
|
|
189
|
-
}
|
|
190
|
-
export {
|
|
191
|
-
checkProjectShape,
|
|
192
|
-
getSqliteToPostgresTasks,
|
|
193
|
-
handler
|
|
194
|
-
};
|
|
File without changes
|