@cedarjs/cli 1.1.1-next.21 → 1.1.1-rc.3

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.
@@ -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.prismaConfig);
32
+ const prismaSchemaExists = fs.existsSync(rwjsPaths.api.dbSchema);
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: async () => {
39
- const { cmd, args } = await generatePrismaCommand();
38
+ task: () => {
39
+ const { cmd, args } = generatePrismaCommand(rwjsPaths.api.dbSchema);
40
40
  return execa(cmd, args, {
41
41
  stdio: verbose ? "inherit" : "pipe",
42
42
  shell: true,
@@ -19,8 +19,7 @@ const DEFAULT_SERVER_CONFIG = {
19
19
  packageManagerCommand: "yarn",
20
20
  monitorCommand: "pm2",
21
21
  sides: ["api", "web"],
22
- keepReleases: 5,
23
- freeSpaceRequired: 2048
22
+ keepReleases: 5
24
23
  };
25
24
  const pathJoin = path.posix.join;
26
25
  const throwMissingConfig = (name) => {
@@ -49,7 +48,7 @@ const verifyServerConfig = (config) => {
49
48
  if (!config.repo) {
50
49
  throwMissingConfig("repo");
51
50
  }
52
- if (!/^\d+$/.test(config.freeSpaceRequired)) {
51
+ if (config.freeSpaceRequired && !/^\d+$/.test(config.freeSpaceRequired)) {
53
52
  throw new Error('"freeSpaceRequired" must be an integer >= 0');
54
53
  }
55
54
  return true;
@@ -233,8 +232,15 @@ const deployTasks = (yargs, ssh, serverConfig, serverLifecycle) => {
233
232
  10
234
233
  );
235
234
  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
+ }
236
242
  throw new Error(
237
- `Not enough disk space. You need at least ${freeSpaceRequired}MB free space to continue. (Currently ${Math.round(dfMb)}MB available)`
243
+ `Not enough disk space. You need at least ${freeSpaceRequired}MB free space to continue.`
238
244
  );
239
245
  }
240
246
  }
@@ -26,7 +26,6 @@ const builder = (yargs) => {
26
26
  "https://cedarjs.com/docs/cli-commands#deploy"
27
27
  )}`
28
28
  );
29
- return yargs;
30
29
  };
31
30
  async function handler(yargs) {
32
31
  const { handler: importedHandler } = await import("./flightcontrolHandler.js");
@@ -3,12 +3,7 @@ import execa from "execa";
3
3
  import fs from "fs-extra";
4
4
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
5
5
  import { getPaths } from "@cedarjs/project-config";
6
- const handler = async ({
7
- side,
8
- serve,
9
- prisma,
10
- dm: dataMigrate
11
- }) => {
6
+ const handler = async ({ side, serve, prisma, dm: dataMigrate }) => {
12
7
  recordTelemetryAttributes({
13
8
  command: "deploy flightcontrol",
14
9
  side,
@@ -22,26 +17,20 @@ const handler = async ({
22
17
  shell: true,
23
18
  stdio: "inherit"
24
19
  };
25
- async function runExecaCommand(command) {
26
- const result = await execa.command(command, execaConfig);
27
- if (result.failed) {
28
- throw new Error(`Command (${command}) failed`);
29
- }
30
- return result;
31
- }
32
20
  async function runApiCommands() {
33
21
  if (!serve) {
34
22
  console.log("Building api...");
35
- await runExecaCommand("yarn rw build api --verbose");
23
+ execa.commandSync("yarn rw build api --verbose", execaConfig);
36
24
  if (prisma) {
37
25
  console.log("Running database migrations...");
38
- await runExecaCommand(
39
- `node_modules/.bin/prisma migrate deploy --config "${rwjsPaths.api.prismaConfig}"`
26
+ execa.commandSync(
27
+ `node_modules/.bin/prisma migrate deploy --schema "${rwjsPaths.api.dbSchema}"`,
28
+ execaConfig
40
29
  );
41
30
  }
42
31
  if (dataMigrate) {
43
32
  console.log("Running data migrations...");
44
- await runExecaCommand("yarn rw dataMigrate up");
33
+ execa.commandSync("yarn rw dataMigrate up", execaConfig);
45
34
  }
46
35
  return;
47
36
  }
@@ -56,12 +45,12 @@ const handler = async ({
56
45
  }
57
46
  async function runWebCommands() {
58
47
  console.log("Building web...");
59
- await runExecaCommand("yarn rw build web --verbose");
48
+ execa.commandSync("yarn rw build web --verbose", execaConfig);
60
49
  }
61
50
  if (side === "api") {
62
- await runApiCommands();
51
+ runApiCommands();
63
52
  } else if (side === "web") {
64
- await runWebCommands();
53
+ runWebCommands();
65
54
  }
66
55
  };
67
56
  export {
@@ -10,9 +10,9 @@ const handler = async ({ side, prisma, dataMigrate }) => {
10
10
  prisma,
11
11
  dataMigrate
12
12
  });
13
- const cedarPaths = getPaths();
13
+ const rwjsPaths = getPaths();
14
14
  const execaConfig = {
15
- cwd: cedarPaths.base,
15
+ cwd: rwjsPaths.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 --config "${cedarPaths.api.prismaConfig}"`,
23
+ `node_modules/.bin/prisma migrate deploy --schema "${rwjsPaths.api.dbSchema}"`,
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(cedarPaths.base, "package.json")
30
+ path.join(rwjsPaths.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 cedar dataMigrate up", execaConfig);
46
+ execa.commandSync("yarn rw dataMigrate up", execaConfig);
47
47
  }
48
48
  }
49
- const serverFilePath = path.join(cedarPaths.api.dist, "server.js");
49
+ const serverFilePath = path.join(rwjsPaths.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 cedar build web --verbose", execaConfig);
60
+ execa.commandSync("yarn rw build web --verbose", execaConfig);
61
61
  }
62
62
  if (side === "api") {
63
63
  runApiCommands();
@@ -81,7 +81,8 @@ const handler = async ({
81
81
  try {
82
82
  await generatePrismaClient({
83
83
  verbose: false,
84
- force: false
84
+ force: false,
85
+ schema: rwjsPaths.api.dbSchema
85
86
  });
86
87
  } catch (e) {
87
88
  errorTelemetry(
@@ -4,11 +4,7 @@ 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 {
8
- getConfigPath,
9
- resolveFile,
10
- getSchemaPath
11
- } from "@cedarjs/project-config";
7
+ import { getConfigPath, resolveFile } from "@cedarjs/project-config";
12
8
  import { errorTelemetry } from "@cedarjs/telemetry";
13
9
  import c from "../../lib/colors.js";
14
10
  import { getPaths, transformTSToJS, writeFile } from "../../lib/index.js";
@@ -130,8 +126,8 @@ const handler = async ({ force, verbose }) => {
130
126
  const prismaTasks = [
131
127
  {
132
128
  title: "Setup Prisma OpenTelemetry...",
133
- task: async (_ctx, task) => {
134
- const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
129
+ task: (_ctx, task) => {
130
+ const schemaPath = path.join(getPaths().api.db, "schema.prisma");
135
131
  const schemaContent = fs.readFileSync(schemaPath, {
136
132
  encoding: "utf-8",
137
133
  flag: "r"
@@ -4,7 +4,6 @@ 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";
8
7
  import c from "../../../lib/colors.js";
9
8
  import { getPaths, writeFilesTask } from "../../../lib/index.js";
10
9
  import { prepareForRollback } from "../../../lib/rollback.js";
@@ -30,16 +29,13 @@ const TEMPLATE_PATHS = {
30
29
  "dataMigration.ts.template"
31
30
  )
32
31
  };
33
- const files = async ({ name, typescript }) => {
32
+ const files = ({ name, typescript }) => {
34
33
  const now = (/* @__PURE__ */ new Date()).toISOString();
35
34
  const timestamp = now.split(".")[0].replace(/\D/g, "");
36
35
  const basename = `${timestamp}-${paramCase(name)}`;
37
36
  const extension = typescript ? "ts" : "js";
38
37
  const outputFilename = basename + "." + extension;
39
- const dataMigrationsPath = await getDataMigrationsPath(
40
- getPaths().api.prismaConfig
41
- );
42
- const outputPath = path.join(dataMigrationsPath, outputFilename);
38
+ const outputPath = path.join(getPaths().api.dataMigrations, outputFilename);
43
39
  return {
44
40
  [outputPath]: fs.readFileSync(TEMPLATE_PATHS[extension]).toString()
45
41
  };
@@ -76,8 +72,8 @@ const handler = async (args) => {
76
72
  [
77
73
  {
78
74
  title: "Generating data migration file...",
79
- task: async () => {
80
- return writeFilesTask(await files(args));
75
+ task: () => {
76
+ return writeFilesTask(files(args));
81
77
  }
82
78
  },
83
79
  {
@@ -55,7 +55,7 @@ const mapPrismaScalarToPagePropTsType = (scalarType) => {
55
55
  Float: "number",
56
56
  Decimal: "number",
57
57
  DateTime: "string",
58
- Bytes: "Uint8Array"
58
+ Bytes: "Buffer"
59
59
  };
60
60
  return prismaScalarToTsType[scalarType] || "unknown";
61
61
  };
@@ -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 `new Uint8Array([${randIntArray}])`;
55
+ return `Buffer.from([${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,10 +118,7 @@ const buildStringifiedScenario = async (model) => {
118
118
  }
119
119
  return value;
120
120
  });
121
- return jsonString.replace(
122
- /"new Uint8Array\(([^)]+)\)"/g,
123
- "new Uint8Array($1)"
124
- );
121
+ return jsonString.replace(/"Buffer\.from\(([^)]+)\)"/g, "Buffer.from($1)");
125
122
  };
126
123
  const fieldTypes = async (model) => {
127
124
  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(/"new Uint8Array\(([^)]+)\)"/g, 'new Uint8Array($1)')
32
+ return jsonString.replace(/"Buffer\.from\(([^)]+)\)"/g, 'Buffer.from($1)')
33
33
  } %>
34
34
  <% if (prismaImport) { %>import { Prisma, ${prismaModel} } from '@prisma/client'<% } else { %>import type { ${prismaModel} } from '@prisma/client'<% } %>
35
35
 
@@ -18,14 +18,22 @@ const handler = async ({ _, $0, commands = [], ...options }) => {
18
18
  }
19
19
  const hasHelpOption = options.help || options.h;
20
20
  if (!hasHelpOption) {
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);
21
+ if (["generate", "introspect", "db", "migrate", "studio", "format"].includes(
22
+ commands[0]
23
+ )) {
24
+ const schemaDir = path.dirname(rwjsPaths.api.dbSchema);
25
+ if (!fs.existsSync(rwjsPaths.api.dbSchema) && !fs.existsSync(schemaDir)) {
26
+ console.error();
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
+ }
27
36
  }
28
- options.config = `${rwjsPaths.api.prismaConfig}`;
29
37
  }
30
38
  const args = commands;
31
39
  for (const [name, value] of Object.entries(options)) {
@@ -57,10 +65,10 @@ const handler = async ({ _, $0, commands = [], ...options }) => {
57
65
  };
58
66
  const printWrapInfo = () => {
59
67
  const message = [
60
- c.bold("Cedar CLI wraps Prisma CLI"),
68
+ c.bold("Redwood CLI wraps Prisma CLI"),
61
69
  "",
62
- "Use `yarn cedar prisma` to automatically pass `--config` and `--preview-feature` options.",
63
- "Use `yarn prisma` to skip Cedar's automatic CLI options.",
70
+ "Use `yarn rw prisma` to automatically pass `--schema` and `--preview-feature` options.",
71
+ "Use `yarn prisma` to skip Redwood CLI automatic options.",
64
72
  "",
65
73
  "Find more information in our docs:",
66
74
  c.underline("https://cedarjs.com/docs/cli-commands#prisma")
@@ -4,7 +4,7 @@ const handler = async () => {
4
4
  command: "record"
5
5
  });
6
6
  const { parseDatamodel } = await import("@cedarjs/record");
7
- await parseDatamodel();
7
+ parseDatamodel();
8
8
  };
9
9
  export {
10
10
  handler
@@ -33,7 +33,12 @@ const builder = async (yargs) => {
33
33
  const { bothSsrRscServerHandler } = await import("./serveBothHandler.js");
34
34
  await bothSsrRscServerHandler(argv, rscEnabled);
35
35
  } else {
36
- await bothServerCLIConfig.handler(argv);
36
+ if (!projectIsEsm()) {
37
+ const { handler } = await import("@cedarjs/api-server/cjs/bothCliConfigHandler");
38
+ await handler(argv);
39
+ } else {
40
+ await bothServerCLIConfig.handler(argv);
41
+ }
37
42
  }
38
43
  }
39
44
  }).command({
@@ -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 { getSchemaWithPath, getConfig } = prismaInternals;
15
+ const { getSchema, 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 result = await getSchemaWithPath(redwoodProjectPaths.api.dbSchema);
61
- const prismaConfig = await getConfig({ datamodel: result.schemas });
60
+ const prismaSchema = await getSchema(redwoodProjectPaths.api.dbSchema);
61
+ const prismaConfig = await getConfig({ datamodel: prismaSchema });
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 { getSchemaWithPath, getConfig } = prismaInternals;
21
+ const { getSchema, 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 result = await getSchemaWithPath(
32
+ const schema = await getSchema(
33
33
  path.join(getPaths().base, "api/db/schema.prisma")
34
34
  );
35
- const config = await getConfig({ datamodel: result.schemas });
35
+ const config = await getConfig({ datamodel: schema });
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 { getSchemaWithPath, getConfig } = prismaInternals;
20
+ const { getSchema, 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 { schemas } = await getSchemaWithPath("api/db/schema.prisma");
32
- const config = await getConfig({ datamodel: schemas });
31
+ const schema = await getSchema("api/db/schema.prisma");
32
+ const config = await getConfig({ datamodel: schema });
33
33
  const detectedDatabase = config.datasources[0].activeProvider;
34
34
  if (detectedDatabase === database) {
35
35
  switch (database) {
@@ -2,7 +2,6 @@ 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";
6
5
  import { errorTelemetry } from "@cedarjs/telemetry";
7
6
  import c from "../../../../lib/colors.js";
8
7
  import {
@@ -57,16 +56,15 @@ const files = [
57
56
  content: SERVERLESS_WEB_YML
58
57
  }
59
58
  ];
60
- const prismaBinaryTargetAdditions = async () => {
61
- const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
62
- const content = fs.readFileSync(schemaPath).toString();
59
+ const prismaBinaryTargetAdditions = () => {
60
+ const content = fs.readFileSync(getPaths().api.dbSchema).toString();
63
61
  if (!content.includes("rhel-openssl-1.0.x")) {
64
62
  const result = content.replace(
65
63
  /binaryTargets =.*\n/,
66
64
  `binaryTargets = ["native", "rhel-openssl-1.0.x"]
67
65
  `
68
66
  );
69
- fs.writeFileSync(schemaPath, result);
67
+ fs.writeFileSync(getPaths().api.dbSchema, result);
70
68
  }
71
69
  };
72
70
  const updateRedwoodTomlTask = () => {
@@ -121,7 +119,7 @@ const handler = async ({ force }) => {
121
119
  }),
122
120
  {
123
121
  title: "Adding necessary Prisma binaries...",
124
- task: async () => await prismaBinaryTargetAdditions()
122
+ task: () => prismaBinaryTargetAdditions()
125
123
  },
126
124
  printSetupNotes(notes)
127
125
  ],
@@ -3,11 +3,9 @@ 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";
7
6
  import c from "../../../lib/colors.js";
8
7
  import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
9
8
  import { isTypeScriptProject } from "../../../lib/project.js";
10
- const { getDMMF, getSchemaWithPath } = prismaInternals;
11
9
  const MODEL_SCHEMA = `
12
10
  model BackgroundJob {
13
11
  id Int @id @default(autoincrement())
@@ -26,16 +24,15 @@ model BackgroundJob {
26
24
  }
27
25
  `;
28
26
  const getModelNames = async () => {
29
- const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
30
- const { schemas } = await getSchemaWithPath(schemaPath);
31
- const schema = await getDMMF({ datamodel: schemas });
27
+ const schema = await prismaInternals.getDMMF({
28
+ datamodelPath: getPaths().api.dbSchema
29
+ });
32
30
  return schema.datamodel.models.map((model) => model.name);
33
31
  };
34
- const addDatabaseModel = async () => {
35
- const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
36
- const schema = fs.readFileSync(schemaPath, "utf-8");
32
+ const addDatabaseModel = () => {
33
+ const schema = fs.readFileSync(getPaths().api.dbSchema, "utf-8");
37
34
  const schemaWithUser = schema + MODEL_SCHEMA;
38
- fs.writeFileSync(schemaPath, schemaWithUser);
35
+ fs.writeFileSync(getPaths().api.dbSchema, schemaWithUser);
39
36
  };
40
37
  const tasks = async ({ force }) => {
41
38
  const modelExists = (await getModelNames()).includes("BackgroundJob");
@@ -47,8 +44,8 @@ const tasks = async ({ force }) => {
47
44
  [
48
45
  {
49
46
  title: "Creating job database model...",
50
- task: async () => {
51
- await addDatabaseModel();
47
+ task: () => {
48
+ addDatabaseModel();
52
49
  },
53
50
  skip: () => {
54
51
  if (modelExists) {
@@ -38,7 +38,8 @@ const handler = async ({ sides, verbose, prisma, generate }) => {
38
38
  };
39
39
  if (generate && prisma) {
40
40
  await generatePrismaClient({
41
- verbose
41
+ verbose,
42
+ schema: getPaths().api.dbSchema
42
43
  });
43
44
  }
44
45
  if (generate) {
@@ -35,11 +35,6 @@ const builder = (yargs) => {
35
35
  description: "Skip dedupe check with --no-dedupe",
36
36
  type: "boolean",
37
37
  default: true
38
- }).option("yes", {
39
- alias: "y",
40
- describe: "Skip prompts and use defaults",
41
- default: false,
42
- type: "boolean"
43
38
  }).epilogue(
44
39
  `Also see the ${terminalLink(
45
40
  "CedarJS CLI Reference for the upgrade command",
@@ -69,42 +64,16 @@ const validateTag = (tag) => {
69
64
  }
70
65
  return tag;
71
66
  };
72
- const handler = async ({ dryRun, tag, verbose, dedupe, yes }) => {
67
+ const handler = async ({ dryRun, tag, verbose, dedupe }) => {
73
68
  recordTelemetryAttributes({
74
69
  command: "upgrade",
75
70
  dryRun,
76
71
  tag,
77
72
  verbose,
78
- dedupe,
79
- yes
73
+ dedupe
80
74
  });
81
75
  const tasks = new Listr(
82
76
  [
83
- {
84
- title: "Confirm upgrade",
85
- task: async (ctx, task) => {
86
- if (yes) {
87
- task.skip("Skipping confirmation prompt because of --yes flag.");
88
- return;
89
- }
90
- const proceed = await task.prompt({
91
- type: "Confirm",
92
- message: "This will upgrade your RedwoodJS project to the latest version. Do you want to proceed?",
93
- initial: "Y",
94
- default: "(Yes/no)",
95
- format: function(value) {
96
- if (this.state.submitted) {
97
- return this.isTrue(value) ? "yes" : "no";
98
- }
99
- return "Yes";
100
- }
101
- });
102
- if (!proceed) {
103
- task.skip("Upgrade cancelled by user.");
104
- process.exit(0);
105
- }
106
- }
107
- },
108
77
  {
109
78
  title: "Checking latest version",
110
79
  task: async (ctx) => setLatestVersionToContext(ctx, tag)
@@ -195,7 +164,7 @@ const handler = async ({ dryRun, tag, verbose, dedupe, yes }) => {
195
164
  }
196
165
  ],
197
166
  {
198
- renderer: verbose ? "verbose" : "default",
167
+ renderer: verbose && "verbose",
199
168
  rendererOptions: { collapseSubtasks: false }
200
169
  }
201
170
  );
@@ -415,7 +384,8 @@ async function refreshPrismaClient(task, { verbose }) {
415
384
  try {
416
385
  await generatePrismaClient({
417
386
  verbose,
418
- force: false
387
+ force: false,
388
+ schema: getPaths().api.dbSchema
419
389
  });
420
390
  } catch (e) {
421
391
  task.skip("Refreshing the Prisma client caused an Error.");
@@ -2,19 +2,35 @@ 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 generatePrismaCommand = async () => {
5
+ const skipTask = (schema = getPaths().api.dbSchema) => {
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
+ }
6
18
  const createdRequire = createRequire(import.meta.url);
7
19
  const prismaIndexPath = createdRequire.resolve("prisma/build/index.js");
8
20
  return {
9
21
  cmd: `node "${prismaIndexPath}"`,
10
- args: ["generate", `--config="${getPaths().api.prismaConfig}"`]
22
+ args: ["generate", schema && `--schema="${schema}"`]
11
23
  };
12
24
  };
13
25
  const generatePrismaClient = async ({
14
26
  verbose = true,
15
27
  force = true,
16
- silent = false
28
+ silent = false,
29
+ schema = getPaths().api.dbSchema
17
30
  }) => {
31
+ if (skipTask(schema)) {
32
+ return;
33
+ }
18
34
  if (!force) {
19
35
  const prismaClientPath = path.join(
20
36
  getPaths().base,
@@ -29,7 +45,7 @@ const generatePrismaClient = async ({
29
45
  [
30
46
  {
31
47
  title: "Generating the Prisma client...",
32
- ...await generatePrismaCommand()
48
+ ...generatePrismaCommand(schema)
33
49
  }
34
50
  ],
35
51
  {
@@ -1,9 +1,8 @@
1
1
  import prismaInternals from "@prisma/internals";
2
- import { getSchemaPath } from "@cedarjs/project-config";
3
2
  import { ensureUniquePlural } from "./pluralHelpers.js";
4
3
  import { singularize, isPlural } from "./rwPluralize.js";
5
4
  import { getPaths } from "./index.js";
6
- const { getConfig, getDMMF, getSchemaWithPath } = prismaInternals;
5
+ const { getConfig, getDMMF, getSchema: getSchemaPrisma } = prismaInternals;
7
6
  const schemaMemo = {};
8
7
  const getExistingModelName = async (name) => {
9
8
  if (!name) {
@@ -63,20 +62,15 @@ const getEnum = async (name) => {
63
62
  }
64
63
  return model;
65
64
  };
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;
65
+ const getDataModel = (path = getPaths().api.dbSchema) => {
66
+ return getSchemaPrisma(path);
71
67
  };
72
- const getSchemaDefinitions = async () => {
73
- return getDMMF({ datamodel: await getDataModel() });
74
- };
75
- const getSchemaConfig = async () => {
76
- return getConfig({
77
- datamodel: await getDataModel()
78
- });
68
+ const getSchemaDefinitions = () => {
69
+ return getDMMF({ datamodel: getDataModel() });
79
70
  };
71
+ const getSchemaConfig = () => getConfig({
72
+ datamodel: getDataModel()
73
+ });
80
74
  async function verifyModelName(options) {
81
75
  const modelName = await getExistingModelName(options.name) || await getExistingModelName(singularize(options.name));
82
76
  if (modelName === void 0) {
package/dist/lib/test.js CHANGED
@@ -10,6 +10,7 @@ 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");
13
14
  const originalProjectConfig = await importOriginal();
14
15
  return {
15
16
  ...originalProjectConfig,
@@ -18,48 +19,44 @@ vi.mock("@cedarjs/project-config", async (importOriginal) => {
18
19
  return {
19
20
  base: BASE_PATH,
20
21
  api: {
21
- prismaConfig: path.join(
22
- // Current test folder
22
+ dataMigrations: path2.join(BASE_PATH, "./api/prisma/dataMigrations"),
23
+ db: path2.join(globalThis.__dirname, "fixtures"),
24
+ // this folder
25
+ dbSchema: path2.join(
23
26
  globalThis.__dirname,
24
27
  "fixtures",
25
- "prisma.config.cjs"
28
+ "schema.prisma"
26
29
  ),
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")
30
+ // this folder
31
+ generators: path2.join(BASE_PATH, "./api/generators"),
32
+ src: path2.join(BASE_PATH, "./api/src"),
33
+ jobs: path2.join(BASE_PATH, "./api/src/jobs"),
34
+ services: path2.join(BASE_PATH, "./api/src/services"),
35
+ directives: path2.join(BASE_PATH, "./api/src/directives"),
36
+ graphql: path2.join(BASE_PATH, "./api/src/graphql"),
37
+ functions: path2.join(BASE_PATH, "./api/src/functions")
35
38
  },
36
39
  web: {
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")
40
+ base: path2.join(BASE_PATH, "./web"),
41
+ config: path2.join(BASE_PATH, "./web/config"),
42
+ src: path2.join(BASE_PATH, "./web/src"),
43
+ generators: path2.join(BASE_PATH, "./web/generators"),
44
+ routes: path2.join(BASE_PATH, "web/src/Routes.js"),
45
+ components: path2.join(BASE_PATH, "/web/src/components"),
46
+ layouts: path2.join(BASE_PATH, "/web/src/layouts"),
47
+ pages: path2.join(BASE_PATH, "/web/src/pages"),
48
+ app: path2.join(BASE_PATH, "/web/src/App.js")
46
49
  },
47
- scripts: path.join(BASE_PATH, "scripts"),
50
+ scripts: path2.join(BASE_PATH, "scripts"),
48
51
  generated: {
49
- base: path.join(BASE_PATH, ".redwood"),
50
- schema: path.join(BASE_PATH, ".redwood/schema.graphql"),
52
+ base: path2.join(BASE_PATH, ".redwood"),
53
+ schema: path2.join(BASE_PATH, ".redwood/schema.graphql"),
51
54
  types: {
52
- includes: path.join(BASE_PATH, ".redwood/types/includes"),
53
- mirror: path.join(BASE_PATH, ".redwood/types/mirror")
55
+ includes: path2.join(BASE_PATH, ".redwood/types/includes"),
56
+ mirror: path2.join(BASE_PATH, ".redwood/types/mirror")
54
57
  }
55
58
  }
56
59
  };
57
- },
58
- getSchemaPath: () => {
59
- return path.join(globalThis.__dirname, "fixtures", "schema.prisma");
60
- },
61
- getDataMigrationsPath: () => {
62
- return path.join(globalThis.__dirname, "fixtures", "migrations");
63
60
  }
64
61
  };
65
62
  });
@@ -4,8 +4,9 @@ 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 = "v24.0.0";
8
- if (semver.gte(pVersionC, LOWER_BOUND)) {
7
+ const LOWER_BOUND = "v20.0.0";
8
+ const LOWER_BOUND_C = semver.clean(LOWER_BOUND);
9
+ if (semver.gt(pVersionC, LOWER_BOUND_C)) {
9
10
  return checks;
10
11
  }
11
12
  checks.ok = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "1.1.1-next.21+77cfbaa90",
3
+ "version": "1.1.1-rc.3",
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.21+77cfbaa90",
35
- "@cedarjs/cli-helpers": "1.1.1-next.21+77cfbaa90",
36
- "@cedarjs/fastify-web": "1.1.1-next.21+77cfbaa90",
37
- "@cedarjs/internal": "1.1.1-next.21+77cfbaa90",
38
- "@cedarjs/prerender": "1.1.1-next.21+77cfbaa90",
39
- "@cedarjs/project-config": "1.1.1-next.21+77cfbaa90",
40
- "@cedarjs/structure": "1.1.1-next.21+77cfbaa90",
41
- "@cedarjs/telemetry": "1.1.1-next.21+77cfbaa90",
42
- "@cedarjs/web-server": "1.1.1-next.21+77cfbaa90",
34
+ "@cedarjs/api-server": "1.1.1-rc.3",
35
+ "@cedarjs/cli-helpers": "1.1.1-rc.3",
36
+ "@cedarjs/fastify-web": "1.1.1-rc.3",
37
+ "@cedarjs/internal": "1.1.1-rc.3",
38
+ "@cedarjs/prerender": "1.1.1-rc.3",
39
+ "@cedarjs/project-config": "1.1.1-rc.3",
40
+ "@cedarjs/structure": "1.1.1-rc.3",
41
+ "@cedarjs/telemetry": "1.1.1-rc.3",
42
+ "@cedarjs/web-server": "1.1.1-rc.3",
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": "6.19.0",
50
+ "@prisma/internals": "5.20.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": "6.19.0",
77
+ "prisma": "5.20.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": "77cfbaa90a726923a763fb33b836638d94b2d431"
104
+ "gitHead": "1332c50070b0ab7f2cfc0d7bc802c60cd8a664a9"
105
105
  }