@cedarjs/cli 1.1.1-next.0 → 1.1.1-next.18
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/commands/buildHandler.js +3 -3
- package/dist/commands/deploy/baremetal/baremetalHandler.js +4 -10
- package/dist/commands/deploy/flightcontrolHandler.js +1 -1
- package/dist/commands/deploy/renderHandler.js +7 -7
- package/dist/commands/devHandler.js +1 -2
- package/dist/commands/experimental/setupOpentelemetryHandler.js +7 -3
- package/dist/commands/generate/dataMigration/dataMigration.js +8 -4
- package/dist/commands/generate/helpers.js +1 -1
- package/dist/commands/generate/service/serviceHandler.js +5 -2
- package/dist/commands/generate/service/templates/test.ts.template +1 -1
- package/dist/commands/prismaHandler.js +10 -18
- package/dist/commands/record/init.js +1 -1
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +3 -3
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +3 -3
- package/dist/commands/setup/deploy/providers/renderHandler.js +3 -3
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +6 -4
- package/dist/commands/setup/jobs/jobsHandler.js +11 -8
- package/dist/commands/type-checkHandler.js +1 -2
- package/dist/commands/upgrade.js +1 -2
- package/dist/lib/generatePrismaClient.js +4 -20
- package/dist/lib/schemaHelpers.js +14 -8
- package/dist/lib/test.js +31 -28
- package/dist/middleware/checkNodeVersion.js +2 -3
- package/package.json +13 -13
|
@@ -29,14 +29,14 @@ const handler = async ({
|
|
|
29
29
|
const rwjsConfig = getConfig();
|
|
30
30
|
const useFragments = rwjsConfig.graphql?.fragments;
|
|
31
31
|
const useTrustedDocuments = rwjsConfig.graphql?.trustedDocuments;
|
|
32
|
-
const prismaSchemaExists = fs.existsSync(rwjsPaths.api.
|
|
32
|
+
const prismaSchemaExists = fs.existsSync(rwjsPaths.api.prismaConfig);
|
|
33
33
|
const prerenderRoutes = prerender && side.includes("web") ? detectPrerenderRoutes() : [];
|
|
34
34
|
const shouldGeneratePrismaClient = prisma && prismaSchemaExists && (side.includes("api") || prerenderRoutes.length > 0);
|
|
35
35
|
const tasks = [
|
|
36
36
|
shouldGeneratePrismaClient && {
|
|
37
37
|
title: "Generating Prisma Client...",
|
|
38
|
-
task: () => {
|
|
39
|
-
const { cmd, args } = generatePrismaCommand(
|
|
38
|
+
task: async () => {
|
|
39
|
+
const { cmd, args } = await generatePrismaCommand();
|
|
40
40
|
return execa(cmd, args, {
|
|
41
41
|
stdio: verbose ? "inherit" : "pipe",
|
|
42
42
|
shell: true,
|
|
@@ -19,7 +19,8 @@ const DEFAULT_SERVER_CONFIG = {
|
|
|
19
19
|
packageManagerCommand: "yarn",
|
|
20
20
|
monitorCommand: "pm2",
|
|
21
21
|
sides: ["api", "web"],
|
|
22
|
-
keepReleases: 5
|
|
22
|
+
keepReleases: 5,
|
|
23
|
+
freeSpaceRequired: 2048
|
|
23
24
|
};
|
|
24
25
|
const pathJoin = path.posix.join;
|
|
25
26
|
const throwMissingConfig = (name) => {
|
|
@@ -48,7 +49,7 @@ const verifyServerConfig = (config) => {
|
|
|
48
49
|
if (!config.repo) {
|
|
49
50
|
throwMissingConfig("repo");
|
|
50
51
|
}
|
|
51
|
-
if (
|
|
52
|
+
if (!/^\d+$/.test(config.freeSpaceRequired)) {
|
|
52
53
|
throw new Error('"freeSpaceRequired" must be an integer >= 0');
|
|
53
54
|
}
|
|
54
55
|
return true;
|
|
@@ -232,15 +233,8 @@ const deployTasks = (yargs, ssh, serverConfig, serverLifecycle) => {
|
|
|
232
233
|
10
|
|
233
234
|
);
|
|
234
235
|
if (dfMb < freeSpaceRequired) {
|
|
235
|
-
if (typeof serverConfig.freeSpaceRequired === "undefined") {
|
|
236
|
-
return task.skip(
|
|
237
|
-
c.warning(
|
|
238
|
-
`Warning: Your server is running low on disk space. (${Math.round(dfMb)}MB available)`
|
|
239
|
-
)
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
236
|
throw new Error(
|
|
243
|
-
`Not enough disk space. You need at least ${freeSpaceRequired}MB free space to continue
|
|
237
|
+
`Not enough disk space. You need at least ${freeSpaceRequired}MB free space to continue. (Currently ${Math.round(dfMb)}MB available)`
|
|
244
238
|
);
|
|
245
239
|
}
|
|
246
240
|
}
|
|
@@ -24,7 +24,7 @@ const handler = async ({ side, serve, prisma, dm: dataMigrate }) => {
|
|
|
24
24
|
if (prisma) {
|
|
25
25
|
console.log("Running database migrations...");
|
|
26
26
|
execa.commandSync(
|
|
27
|
-
`node_modules/.bin/prisma migrate deploy --
|
|
27
|
+
`node_modules/.bin/prisma migrate deploy --config "${rwjsPaths.api.prismaConfig}"`,
|
|
28
28
|
execaConfig
|
|
29
29
|
);
|
|
30
30
|
}
|
|
@@ -10,9 +10,9 @@ const handler = async ({ side, prisma, dataMigrate }) => {
|
|
|
10
10
|
prisma,
|
|
11
11
|
dataMigrate
|
|
12
12
|
});
|
|
13
|
-
const
|
|
13
|
+
const cedarPaths = getPaths();
|
|
14
14
|
const execaConfig = {
|
|
15
|
-
cwd:
|
|
15
|
+
cwd: cedarPaths.base,
|
|
16
16
|
shell: true,
|
|
17
17
|
stdio: "inherit"
|
|
18
18
|
};
|
|
@@ -20,14 +20,14 @@ const handler = async ({ side, prisma, dataMigrate }) => {
|
|
|
20
20
|
if (prisma) {
|
|
21
21
|
console.log("Running database migrations...");
|
|
22
22
|
execa.commandSync(
|
|
23
|
-
`node_modules/.bin/prisma migrate deploy --
|
|
23
|
+
`node_modules/.bin/prisma migrate deploy --config "${cedarPaths.api.prismaConfig}"`,
|
|
24
24
|
execaConfig
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
if (dataMigrate) {
|
|
28
28
|
console.log("Running data migrations...");
|
|
29
29
|
const packageJson = fs.readJsonSync(
|
|
30
|
-
path.join(
|
|
30
|
+
path.join(cedarPaths.base, "package.json")
|
|
31
31
|
);
|
|
32
32
|
const hasDataMigratePackage = !!packageJson.devDependencies["@cedarjs/cli-data-migrate"];
|
|
33
33
|
if (!hasDataMigratePackage) {
|
|
@@ -43,10 +43,10 @@ const handler = async ({ side, prisma, dataMigrate }) => {
|
|
|
43
43
|
].join("\n")
|
|
44
44
|
);
|
|
45
45
|
} else {
|
|
46
|
-
execa.commandSync("yarn
|
|
46
|
+
execa.commandSync("yarn cedar dataMigrate up", execaConfig);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
const serverFilePath = path.join(
|
|
49
|
+
const serverFilePath = path.join(cedarPaths.api.dist, "server.js");
|
|
50
50
|
const hasServerFile = fs.pathExistsSync(serverFilePath);
|
|
51
51
|
if (hasServerFile) {
|
|
52
52
|
execa(`yarn node ${serverFilePath}`, execaConfig);
|
|
@@ -57,7 +57,7 @@ const handler = async ({ side, prisma, dataMigrate }) => {
|
|
|
57
57
|
}
|
|
58
58
|
async function runWebCommands() {
|
|
59
59
|
execa.commandSync("yarn install", execaConfig);
|
|
60
|
-
execa.commandSync("yarn
|
|
60
|
+
execa.commandSync("yarn cedar build web --verbose", execaConfig);
|
|
61
61
|
}
|
|
62
62
|
if (side === "api") {
|
|
63
63
|
runApiCommands();
|
|
@@ -4,7 +4,11 @@ import execa from "execa";
|
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
import { Listr } from "listr2";
|
|
6
6
|
import { addApiPackages } from "@cedarjs/cli-helpers";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
getConfigPath,
|
|
9
|
+
resolveFile,
|
|
10
|
+
getSchemaPath
|
|
11
|
+
} from "@cedarjs/project-config";
|
|
8
12
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
9
13
|
import c from "../../lib/colors.js";
|
|
10
14
|
import { getPaths, transformTSToJS, writeFile } from "../../lib/index.js";
|
|
@@ -126,8 +130,8 @@ const handler = async ({ force, verbose }) => {
|
|
|
126
130
|
const prismaTasks = [
|
|
127
131
|
{
|
|
128
132
|
title: "Setup Prisma OpenTelemetry...",
|
|
129
|
-
task: (_ctx, task) => {
|
|
130
|
-
const schemaPath =
|
|
133
|
+
task: async (_ctx, task) => {
|
|
134
|
+
const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
|
|
131
135
|
const schemaContent = fs.readFileSync(schemaPath, {
|
|
132
136
|
encoding: "utf-8",
|
|
133
137
|
flag: "r"
|
|
@@ -4,6 +4,7 @@ import fs from "fs-extra";
|
|
|
4
4
|
import { Listr } from "listr2";
|
|
5
5
|
import { terminalLink } from "termi-link";
|
|
6
6
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
7
|
+
import { getDataMigrationsPath } from "@cedarjs/project-config";
|
|
7
8
|
import c from "../../../lib/colors.js";
|
|
8
9
|
import { getPaths, writeFilesTask } from "../../../lib/index.js";
|
|
9
10
|
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
@@ -29,13 +30,16 @@ const TEMPLATE_PATHS = {
|
|
|
29
30
|
"dataMigration.ts.template"
|
|
30
31
|
)
|
|
31
32
|
};
|
|
32
|
-
const files = ({ name, typescript }) => {
|
|
33
|
+
const files = async ({ name, typescript }) => {
|
|
33
34
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
34
35
|
const timestamp = now.split(".")[0].replace(/\D/g, "");
|
|
35
36
|
const basename = `${timestamp}-${paramCase(name)}`;
|
|
36
37
|
const extension = typescript ? "ts" : "js";
|
|
37
38
|
const outputFilename = basename + "." + extension;
|
|
38
|
-
const
|
|
39
|
+
const dataMigrationsPath = await getDataMigrationsPath(
|
|
40
|
+
getPaths().api.prismaConfig
|
|
41
|
+
);
|
|
42
|
+
const outputPath = path.join(dataMigrationsPath, outputFilename);
|
|
39
43
|
return {
|
|
40
44
|
[outputPath]: fs.readFileSync(TEMPLATE_PATHS[extension]).toString()
|
|
41
45
|
};
|
|
@@ -72,8 +76,8 @@ const handler = async (args) => {
|
|
|
72
76
|
[
|
|
73
77
|
{
|
|
74
78
|
title: "Generating data migration file...",
|
|
75
|
-
task: () => {
|
|
76
|
-
return writeFilesTask(files(args));
|
|
79
|
+
task: async () => {
|
|
80
|
+
return writeFilesTask(await files(args));
|
|
77
81
|
}
|
|
78
82
|
},
|
|
79
83
|
{
|
|
@@ -52,7 +52,7 @@ const scenarioFieldValue = (field) => {
|
|
|
52
52
|
case "String":
|
|
53
53
|
return field.isUnique ? `String${randInt}` : "String";
|
|
54
54
|
case "Bytes":
|
|
55
|
-
return `
|
|
55
|
+
return `new Uint8Array([${randIntArray}])`;
|
|
56
56
|
default: {
|
|
57
57
|
if (field.kind === "enum" && field.enumValues[0]) {
|
|
58
58
|
return field.enumValues[0].dbName || field.enumValues[0].name;
|
|
@@ -118,7 +118,10 @@ const buildStringifiedScenario = async (model) => {
|
|
|
118
118
|
}
|
|
119
119
|
return value;
|
|
120
120
|
});
|
|
121
|
-
return jsonString.replace(
|
|
121
|
+
return jsonString.replace(
|
|
122
|
+
/"new Uint8Array\(([^)]+)\)"/g,
|
|
123
|
+
"new Uint8Array($1)"
|
|
124
|
+
);
|
|
122
125
|
};
|
|
123
126
|
const fieldTypes = async (model) => {
|
|
124
127
|
const { scalarFields } = await parseSchema(model);
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
// Not all values can be represented as JSON, like function invocations
|
|
32
|
-
return jsonString.replace(/"
|
|
32
|
+
return jsonString.replace(/"new Uint8Array\(([^)]+)\)"/g, 'new Uint8Array($1)')
|
|
33
33
|
} %>
|
|
34
34
|
<% if (prismaImport) { %>import { Prisma, ${prismaModel} } from '@prisma/client'<% } else { %>import type { ${prismaModel} } from '@prisma/client'<% } %>
|
|
35
35
|
|
|
@@ -18,22 +18,14 @@ const handler = async ({ _, $0, commands = [], ...options }) => {
|
|
|
18
18
|
}
|
|
19
19
|
const hasHelpOption = options.help || options.h;
|
|
20
20
|
if (!hasHelpOption) {
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.error(c.error("No Prisma Schema found."));
|
|
28
|
-
console.error(`Redwood searched here '${rwjsPaths.api.dbSchema}'`);
|
|
29
|
-
console.error();
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
options.schema = `${rwjsPaths.api.dbSchema}`;
|
|
33
|
-
if (["seed", "diff"].includes(commands[1])) {
|
|
34
|
-
delete options.schema;
|
|
35
|
-
}
|
|
21
|
+
if (!fs.existsSync(rwjsPaths.api.prismaConfig)) {
|
|
22
|
+
console.error();
|
|
23
|
+
console.error(c.error("No Prisma config file found."));
|
|
24
|
+
console.error(`Cedar searched here '${rwjsPaths.api.prismaConfig}'`);
|
|
25
|
+
console.error();
|
|
26
|
+
process.exit(1);
|
|
36
27
|
}
|
|
28
|
+
options.config = `${rwjsPaths.api.prismaConfig}`;
|
|
37
29
|
}
|
|
38
30
|
const args = commands;
|
|
39
31
|
for (const [name, value] of Object.entries(options)) {
|
|
@@ -65,10 +57,10 @@ const handler = async ({ _, $0, commands = [], ...options }) => {
|
|
|
65
57
|
};
|
|
66
58
|
const printWrapInfo = () => {
|
|
67
59
|
const message = [
|
|
68
|
-
c.bold("
|
|
60
|
+
c.bold("Cedar CLI wraps Prisma CLI"),
|
|
69
61
|
"",
|
|
70
|
-
"Use `yarn
|
|
71
|
-
"Use `yarn prisma` to skip
|
|
62
|
+
"Use `yarn cedar prisma` to automatically pass `--config` and `--preview-feature` options.",
|
|
63
|
+
"Use `yarn prisma` to skip Cedar's automatic CLI options.",
|
|
72
64
|
"",
|
|
73
65
|
"Find more information in our docs:",
|
|
74
66
|
c.underline("https://cedarjs.com/docs/cli-commands#prisma")
|
|
@@ -12,7 +12,7 @@ import { errorTelemetry } from "@cedarjs/telemetry";
|
|
|
12
12
|
import { printSetupNotes } from "../../../../lib/index.js";
|
|
13
13
|
import { serverFileExists } from "../../../../lib/project.js";
|
|
14
14
|
import { addFilesTask } from "../helpers/index.js";
|
|
15
|
-
const {
|
|
15
|
+
const { getSchemaWithPath, getConfig } = prismaInternals;
|
|
16
16
|
const redwoodProjectPaths = getPaths();
|
|
17
17
|
const EXTENSION = isTypeScriptProject ? "ts" : "js";
|
|
18
18
|
async function handler({ force }) {
|
|
@@ -57,8 +57,8 @@ async function getAddCoherenceFilesTask(force) {
|
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
async function getCoherenceConfigFileContent() {
|
|
60
|
-
const
|
|
61
|
-
const prismaConfig = await getConfig({ datamodel:
|
|
60
|
+
const result = await getSchemaWithPath(redwoodProjectPaths.api.dbSchema);
|
|
61
|
+
const prismaConfig = await getConfig({ datamodel: result.schemas });
|
|
62
62
|
let db = prismaConfig.datasources[0].activeProvider;
|
|
63
63
|
if (!SUPPORTED_DATABASES.includes(db)) {
|
|
64
64
|
throw new Error(
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
postgresDatabaseService,
|
|
19
19
|
mysqlDatabaseService
|
|
20
20
|
} from "../templates/flightcontrol.js";
|
|
21
|
-
const {
|
|
21
|
+
const { getSchemaWithPath, getConfig } = prismaInternals;
|
|
22
22
|
const getFlightcontrolJson = async (database) => {
|
|
23
23
|
if (database === "none") {
|
|
24
24
|
return {
|
|
@@ -29,10 +29,10 @@ const getFlightcontrolJson = async (database) => {
|
|
|
29
29
|
if (!fs.existsSync(path.join(getPaths().base, "api/db/schema.prisma"))) {
|
|
30
30
|
throw new Error("Could not find prisma schema at 'api/db/schema.prisma'");
|
|
31
31
|
}
|
|
32
|
-
const
|
|
32
|
+
const result = await getSchemaWithPath(
|
|
33
33
|
path.join(getPaths().base, "api/db/schema.prisma")
|
|
34
34
|
);
|
|
35
|
-
const config = await getConfig({ datamodel:
|
|
35
|
+
const config = await getConfig({ datamodel: result.schemas });
|
|
36
36
|
const detectedDatabase = config.datasources[0].activeProvider;
|
|
37
37
|
if (detectedDatabase === database) {
|
|
38
38
|
let dbService;
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
RENDER_YAML,
|
|
18
18
|
SQLITE_YAML
|
|
19
19
|
} from "../templates/render.js";
|
|
20
|
-
const {
|
|
20
|
+
const { getSchemaWithPath, getConfig } = prismaInternals;
|
|
21
21
|
const getRenderYamlContent = async (database) => {
|
|
22
22
|
if (database === "none") {
|
|
23
23
|
return {
|
|
@@ -28,8 +28,8 @@ const getRenderYamlContent = async (database) => {
|
|
|
28
28
|
if (!fs.existsSync("api/db/schema.prisma")) {
|
|
29
29
|
throw new Error("Could not find prisma schema at 'api/db/schema.prisma'");
|
|
30
30
|
}
|
|
31
|
-
const
|
|
32
|
-
const config = await getConfig({ datamodel:
|
|
31
|
+
const { schemas } = await getSchemaWithPath("api/db/schema.prisma");
|
|
32
|
+
const config = await getConfig({ datamodel: schemas });
|
|
33
33
|
const detectedDatabase = config.datasources[0].activeProvider;
|
|
34
34
|
if (detectedDatabase === database) {
|
|
35
35
|
switch (database) {
|
|
@@ -2,6 +2,7 @@ import path from "path";
|
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
5
|
+
import { getSchemaPath } from "@cedarjs/project-config";
|
|
5
6
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
6
7
|
import c from "../../../../lib/colors.js";
|
|
7
8
|
import {
|
|
@@ -56,15 +57,16 @@ const files = [
|
|
|
56
57
|
content: SERVERLESS_WEB_YML
|
|
57
58
|
}
|
|
58
59
|
];
|
|
59
|
-
const prismaBinaryTargetAdditions = () => {
|
|
60
|
-
const
|
|
60
|
+
const prismaBinaryTargetAdditions = async () => {
|
|
61
|
+
const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
|
|
62
|
+
const content = fs.readFileSync(schemaPath).toString();
|
|
61
63
|
if (!content.includes("rhel-openssl-1.0.x")) {
|
|
62
64
|
const result = content.replace(
|
|
63
65
|
/binaryTargets =.*\n/,
|
|
64
66
|
`binaryTargets = ["native", "rhel-openssl-1.0.x"]
|
|
65
67
|
`
|
|
66
68
|
);
|
|
67
|
-
fs.writeFileSync(
|
|
69
|
+
fs.writeFileSync(schemaPath, result);
|
|
68
70
|
}
|
|
69
71
|
};
|
|
70
72
|
const updateRedwoodTomlTask = () => {
|
|
@@ -119,7 +121,7 @@ const handler = async ({ force }) => {
|
|
|
119
121
|
}),
|
|
120
122
|
{
|
|
121
123
|
title: "Adding necessary Prisma binaries...",
|
|
122
|
-
task: () => prismaBinaryTargetAdditions()
|
|
124
|
+
task: async () => await prismaBinaryTargetAdditions()
|
|
123
125
|
},
|
|
124
126
|
printSetupNotes(notes)
|
|
125
127
|
],
|
|
@@ -3,9 +3,11 @@ import * as path from "node:path";
|
|
|
3
3
|
import prismaInternals from "@prisma/internals";
|
|
4
4
|
import { Listr } from "listr2";
|
|
5
5
|
import { addApiPackages } from "@cedarjs/cli-helpers";
|
|
6
|
+
import { getSchemaPath } from "@cedarjs/project-config";
|
|
6
7
|
import c from "../../../lib/colors.js";
|
|
7
8
|
import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
|
|
8
9
|
import { isTypeScriptProject } from "../../../lib/project.js";
|
|
10
|
+
const { getDMMF, getSchemaWithPath } = prismaInternals;
|
|
9
11
|
const MODEL_SCHEMA = `
|
|
10
12
|
model BackgroundJob {
|
|
11
13
|
id Int @id @default(autoincrement())
|
|
@@ -24,15 +26,16 @@ model BackgroundJob {
|
|
|
24
26
|
}
|
|
25
27
|
`;
|
|
26
28
|
const getModelNames = async () => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
});
|
|
29
|
+
const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
|
|
30
|
+
const { schemas } = await getSchemaWithPath(schemaPath);
|
|
31
|
+
const schema = await getDMMF({ datamodel: schemas });
|
|
30
32
|
return schema.datamodel.models.map((model) => model.name);
|
|
31
33
|
};
|
|
32
|
-
const addDatabaseModel = () => {
|
|
33
|
-
const
|
|
34
|
+
const addDatabaseModel = async () => {
|
|
35
|
+
const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
|
|
36
|
+
const schema = fs.readFileSync(schemaPath, "utf-8");
|
|
34
37
|
const schemaWithUser = schema + MODEL_SCHEMA;
|
|
35
|
-
fs.writeFileSync(
|
|
38
|
+
fs.writeFileSync(schemaPath, schemaWithUser);
|
|
36
39
|
};
|
|
37
40
|
const tasks = async ({ force }) => {
|
|
38
41
|
const modelExists = (await getModelNames()).includes("BackgroundJob");
|
|
@@ -44,8 +47,8 @@ const tasks = async ({ force }) => {
|
|
|
44
47
|
[
|
|
45
48
|
{
|
|
46
49
|
title: "Creating job database model...",
|
|
47
|
-
task: () => {
|
|
48
|
-
addDatabaseModel();
|
|
50
|
+
task: async () => {
|
|
51
|
+
await addDatabaseModel();
|
|
49
52
|
},
|
|
50
53
|
skip: () => {
|
|
51
54
|
if (modelExists) {
|
package/dist/commands/upgrade.js
CHANGED
|
@@ -384,8 +384,7 @@ async function refreshPrismaClient(task, { verbose }) {
|
|
|
384
384
|
try {
|
|
385
385
|
await generatePrismaClient({
|
|
386
386
|
verbose,
|
|
387
|
-
force: false
|
|
388
|
-
schema: getPaths().api.dbSchema
|
|
387
|
+
force: false
|
|
389
388
|
});
|
|
390
389
|
} catch (e) {
|
|
391
390
|
task.skip("Refreshing the Prisma client caused an Error.");
|
|
@@ -2,35 +2,19 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import { runCommandTask, getPaths } from "../lib/index.js";
|
|
5
|
-
const
|
|
6
|
-
if (!fs.existsSync(schema)) {
|
|
7
|
-
console.log(
|
|
8
|
-
`Skipping database and Prisma client generation, no \`schema.prisma\` file found: \`${schema}\``
|
|
9
|
-
);
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
};
|
|
14
|
-
const generatePrismaCommand = (schema) => {
|
|
15
|
-
if (skipTask(schema)) {
|
|
16
|
-
return {};
|
|
17
|
-
}
|
|
5
|
+
const generatePrismaCommand = async () => {
|
|
18
6
|
const createdRequire = createRequire(import.meta.url);
|
|
19
7
|
const prismaIndexPath = createdRequire.resolve("prisma/build/index.js");
|
|
20
8
|
return {
|
|
21
9
|
cmd: `node "${prismaIndexPath}"`,
|
|
22
|
-
args: ["generate",
|
|
10
|
+
args: ["generate", `--config="${getPaths().api.prismaConfig}"`]
|
|
23
11
|
};
|
|
24
12
|
};
|
|
25
13
|
const generatePrismaClient = async ({
|
|
26
14
|
verbose = true,
|
|
27
15
|
force = true,
|
|
28
|
-
silent = false
|
|
29
|
-
schema = getPaths().api.dbSchema
|
|
16
|
+
silent = false
|
|
30
17
|
}) => {
|
|
31
|
-
if (skipTask(schema)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
18
|
if (!force) {
|
|
35
19
|
const prismaClientPath = path.join(
|
|
36
20
|
getPaths().base,
|
|
@@ -45,7 +29,7 @@ const generatePrismaClient = async ({
|
|
|
45
29
|
[
|
|
46
30
|
{
|
|
47
31
|
title: "Generating the Prisma client...",
|
|
48
|
-
...generatePrismaCommand(
|
|
32
|
+
...await generatePrismaCommand()
|
|
49
33
|
}
|
|
50
34
|
],
|
|
51
35
|
{
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import prismaInternals from "@prisma/internals";
|
|
2
|
+
import { getSchemaPath } from "@cedarjs/project-config";
|
|
2
3
|
import { ensureUniquePlural } from "./pluralHelpers.js";
|
|
3
4
|
import { singularize, isPlural } from "./rwPluralize.js";
|
|
4
5
|
import { getPaths } from "./index.js";
|
|
5
|
-
const { getConfig, getDMMF,
|
|
6
|
+
const { getConfig, getDMMF, getSchemaWithPath } = prismaInternals;
|
|
6
7
|
const schemaMemo = {};
|
|
7
8
|
const getExistingModelName = async (name) => {
|
|
8
9
|
if (!name) {
|
|
@@ -62,15 +63,20 @@ const getEnum = async (name) => {
|
|
|
62
63
|
}
|
|
63
64
|
return model;
|
|
64
65
|
};
|
|
65
|
-
const getDataModel =
|
|
66
|
-
|
|
66
|
+
const getDataModel = async () => {
|
|
67
|
+
const prismaConfigPath = getPaths().api.prismaConfig;
|
|
68
|
+
const schemaPath = await getSchemaPath(prismaConfigPath);
|
|
69
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
70
|
+
return result.schemas;
|
|
67
71
|
};
|
|
68
|
-
const getSchemaDefinitions = () => {
|
|
69
|
-
return getDMMF({ datamodel: getDataModel() });
|
|
72
|
+
const getSchemaDefinitions = async () => {
|
|
73
|
+
return getDMMF({ datamodel: await getDataModel() });
|
|
74
|
+
};
|
|
75
|
+
const getSchemaConfig = async () => {
|
|
76
|
+
return getConfig({
|
|
77
|
+
datamodel: await getDataModel()
|
|
78
|
+
});
|
|
70
79
|
};
|
|
71
|
-
const getSchemaConfig = () => getConfig({
|
|
72
|
-
datamodel: getDataModel()
|
|
73
|
-
});
|
|
74
80
|
async function verifyModelName(options) {
|
|
75
81
|
const modelName = await getExistingModelName(options.name) || await getExistingModelName(singularize(options.name));
|
|
76
82
|
if (modelName === void 0) {
|
package/dist/lib/test.js
CHANGED
|
@@ -10,7 +10,6 @@ vi.mock("@cedarjs/internal/dist/generate/generate", () => {
|
|
|
10
10
|
};
|
|
11
11
|
});
|
|
12
12
|
vi.mock("@cedarjs/project-config", async (importOriginal) => {
|
|
13
|
-
const path2 = await import("path");
|
|
14
13
|
const originalProjectConfig = await importOriginal();
|
|
15
14
|
return {
|
|
16
15
|
...originalProjectConfig,
|
|
@@ -19,44 +18,48 @@ vi.mock("@cedarjs/project-config", async (importOriginal) => {
|
|
|
19
18
|
return {
|
|
20
19
|
base: BASE_PATH,
|
|
21
20
|
api: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// this folder
|
|
25
|
-
dbSchema: path2.join(
|
|
21
|
+
prismaConfig: path.join(
|
|
22
|
+
// Current test folder
|
|
26
23
|
globalThis.__dirname,
|
|
27
24
|
"fixtures",
|
|
28
|
-
"
|
|
25
|
+
"prisma.config.cjs"
|
|
29
26
|
),
|
|
30
|
-
|
|
31
|
-
generators:
|
|
32
|
-
src:
|
|
33
|
-
jobs:
|
|
34
|
-
services:
|
|
35
|
-
directives:
|
|
36
|
-
graphql:
|
|
37
|
-
functions:
|
|
27
|
+
dataMigrations: path.join(BASE_PATH, "./api/dataMigrations"),
|
|
28
|
+
generators: path.join(BASE_PATH, "./api/generators"),
|
|
29
|
+
src: path.join(BASE_PATH, "./api/src"),
|
|
30
|
+
jobs: path.join(BASE_PATH, "./api/src/jobs"),
|
|
31
|
+
services: path.join(BASE_PATH, "./api/src/services"),
|
|
32
|
+
directives: path.join(BASE_PATH, "./api/src/directives"),
|
|
33
|
+
graphql: path.join(BASE_PATH, "./api/src/graphql"),
|
|
34
|
+
functions: path.join(BASE_PATH, "./api/src/functions")
|
|
38
35
|
},
|
|
39
36
|
web: {
|
|
40
|
-
base:
|
|
41
|
-
config:
|
|
42
|
-
src:
|
|
43
|
-
generators:
|
|
44
|
-
routes:
|
|
45
|
-
components:
|
|
46
|
-
layouts:
|
|
47
|
-
pages:
|
|
48
|
-
app:
|
|
37
|
+
base: path.join(BASE_PATH, "./web"),
|
|
38
|
+
config: path.join(BASE_PATH, "./web/config"),
|
|
39
|
+
src: path.join(BASE_PATH, "./web/src"),
|
|
40
|
+
generators: path.join(BASE_PATH, "./web/generators"),
|
|
41
|
+
routes: path.join(BASE_PATH, "web/src/Routes.js"),
|
|
42
|
+
components: path.join(BASE_PATH, "/web/src/components"),
|
|
43
|
+
layouts: path.join(BASE_PATH, "/web/src/layouts"),
|
|
44
|
+
pages: path.join(BASE_PATH, "/web/src/pages"),
|
|
45
|
+
app: path.join(BASE_PATH, "/web/src/App.js")
|
|
49
46
|
},
|
|
50
|
-
scripts:
|
|
47
|
+
scripts: path.join(BASE_PATH, "scripts"),
|
|
51
48
|
generated: {
|
|
52
|
-
base:
|
|
53
|
-
schema:
|
|
49
|
+
base: path.join(BASE_PATH, ".redwood"),
|
|
50
|
+
schema: path.join(BASE_PATH, ".redwood/schema.graphql"),
|
|
54
51
|
types: {
|
|
55
|
-
includes:
|
|
56
|
-
mirror:
|
|
52
|
+
includes: path.join(BASE_PATH, ".redwood/types/includes"),
|
|
53
|
+
mirror: path.join(BASE_PATH, ".redwood/types/mirror")
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
};
|
|
57
|
+
},
|
|
58
|
+
getSchemaPath: () => {
|
|
59
|
+
return path.join(globalThis.__dirname, "fixtures", "schema.prisma");
|
|
60
|
+
},
|
|
61
|
+
getDataMigrationsPath: () => {
|
|
62
|
+
return path.join(globalThis.__dirname, "fixtures", "migrations");
|
|
60
63
|
}
|
|
61
64
|
};
|
|
62
65
|
});
|
|
@@ -4,9 +4,8 @@ function checkNodeVersion() {
|
|
|
4
4
|
const checks = { ok: true };
|
|
5
5
|
const pVersion = process.version;
|
|
6
6
|
const pVersionC = semver.clean(pVersion);
|
|
7
|
-
const LOWER_BOUND = "
|
|
8
|
-
|
|
9
|
-
if (semver.gt(pVersionC, LOWER_BOUND_C)) {
|
|
7
|
+
const LOWER_BOUND = "v24.0.0";
|
|
8
|
+
if (semver.gte(pVersionC, LOWER_BOUND)) {
|
|
10
9
|
return checks;
|
|
11
10
|
}
|
|
12
11
|
checks.ok = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli",
|
|
3
|
-
"version": "1.1.1-next.
|
|
3
|
+
"version": "1.1.1-next.18+5ffd3124d",
|
|
4
4
|
"description": "The CedarJS Command Line",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/preset-typescript": "7.27.1",
|
|
33
33
|
"@babel/runtime-corejs3": "7.27.6",
|
|
34
|
-
"@cedarjs/api-server": "1.1.1-next.
|
|
35
|
-
"@cedarjs/cli-helpers": "1.1.1-next.
|
|
36
|
-
"@cedarjs/fastify-web": "1.1.1-next.
|
|
37
|
-
"@cedarjs/internal": "1.1.1-next.
|
|
38
|
-
"@cedarjs/prerender": "1.1.1-next.
|
|
39
|
-
"@cedarjs/project-config": "1.1.1-next.
|
|
40
|
-
"@cedarjs/structure": "1.1.1-next.
|
|
41
|
-
"@cedarjs/telemetry": "1.1.1-next.
|
|
42
|
-
"@cedarjs/web-server": "1.1.1-next.
|
|
34
|
+
"@cedarjs/api-server": "1.1.1-next.18+5ffd3124d",
|
|
35
|
+
"@cedarjs/cli-helpers": "1.1.1-next.18+5ffd3124d",
|
|
36
|
+
"@cedarjs/fastify-web": "1.1.1-next.18+5ffd3124d",
|
|
37
|
+
"@cedarjs/internal": "1.1.1-next.18+5ffd3124d",
|
|
38
|
+
"@cedarjs/prerender": "1.1.1-next.18+5ffd3124d",
|
|
39
|
+
"@cedarjs/project-config": "1.1.1-next.18+5ffd3124d",
|
|
40
|
+
"@cedarjs/structure": "1.1.1-next.18+5ffd3124d",
|
|
41
|
+
"@cedarjs/telemetry": "1.1.1-next.18+5ffd3124d",
|
|
42
|
+
"@cedarjs/web-server": "1.1.1-next.18+5ffd3124d",
|
|
43
43
|
"@listr2/prompt-adapter-enquirer": "2.0.16",
|
|
44
44
|
"@opentelemetry/api": "1.8.0",
|
|
45
45
|
"@opentelemetry/core": "1.22.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@opentelemetry/resources": "1.22.0",
|
|
48
48
|
"@opentelemetry/sdk-trace-node": "1.22.0",
|
|
49
49
|
"@opentelemetry/semantic-conventions": "1.22.0",
|
|
50
|
-
"@prisma/internals": "
|
|
50
|
+
"@prisma/internals": "6.19.0",
|
|
51
51
|
"ansis": "4.1.0",
|
|
52
52
|
"archiver": "7.0.1",
|
|
53
53
|
"boxen": "5.1.2",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"pluralize": "8.0.0",
|
|
75
75
|
"portfinder": "1.0.37",
|
|
76
76
|
"prettier": "3.6.2",
|
|
77
|
-
"prisma": "
|
|
77
|
+
"prisma": "6.19.0",
|
|
78
78
|
"prompts": "2.4.2",
|
|
79
79
|
"rimraf": "6.0.1",
|
|
80
80
|
"semver": "7.6.3",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"publishConfig": {
|
|
102
102
|
"access": "public"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "5ffd3124d3d4ceb7843408264c96ecceff8542f5"
|
|
105
105
|
}
|