@cedarjs/cli 4.2.1-next.0 → 4.2.1-next.258

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.
Files changed (153) hide show
  1. package/dist/cfw.js +8 -6
  2. package/dist/commands/build/buildHandler.js +43 -42
  3. package/dist/commands/build/buildPackagesTask.js +6 -6
  4. package/dist/commands/build.js +7 -1
  5. package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
  6. package/dist/commands/deploy/baremetal/baremetalHandler.js +117 -65
  7. package/dist/commands/deploy/baremetal.js +24 -3
  8. package/dist/commands/deploy/flightcontrolHandler.js +16 -14
  9. package/dist/commands/deploy/helpers/deployHandler.js +10 -5
  10. package/dist/commands/deploy/packing/nft.js +1 -2
  11. package/dist/commands/deploy/render.js +1 -1
  12. package/dist/commands/deploy/renderHandler.js +22 -12
  13. package/dist/commands/deploy/serverlessHandler.js +67 -25
  14. package/dist/commands/destroy/component/component.js +2 -3
  15. package/dist/commands/destroy/directive/directive.js +1 -3
  16. package/dist/commands/destroy/directive/directiveHandler.js +2 -4
  17. package/dist/commands/destroy/function/function.js +1 -3
  18. package/dist/commands/destroy/handlerHelpers.js +16 -16
  19. package/dist/commands/destroy/helpers.js +8 -2
  20. package/dist/commands/destroy/layout/layout.js +1 -2
  21. package/dist/commands/destroy/page/pageHandler.js +1 -1
  22. package/dist/commands/destroy/scaffold/scaffoldHandler.js +28 -9
  23. package/dist/commands/destroy/sdl/sdlHandler.js +1 -1
  24. package/dist/commands/dev/devHandler.js +25 -25
  25. package/dist/commands/dev.js +3 -0
  26. package/dist/commands/experimental/live-queries/liveQueriesHandler.js +110 -4
  27. package/dist/commands/experimental/setupInngest.js +1 -1
  28. package/dist/commands/experimental/setupInngestHandler.js +12 -11
  29. package/dist/commands/experimental/setupOpentelemetry.js +1 -1
  30. package/dist/commands/experimental/setupOpentelemetryHandler.js +11 -7
  31. package/dist/commands/experimental/setupReactCompiler.js +1 -1
  32. package/dist/commands/experimental/setupReactCompilerHandler.js +45 -30
  33. package/dist/commands/experimental/setupRscHandler.js +14 -11
  34. package/dist/commands/experimental/setupStreamingSsr.js +1 -1
  35. package/dist/commands/experimental/setupStreamingSsrHandler.js +46 -31
  36. package/dist/commands/experimental/templates/rsc/Document.tsx.template +1 -1
  37. package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +8 -8
  38. package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +1 -1
  39. package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +6 -6
  40. package/dist/commands/experimental/util.js +3 -2
  41. package/dist/commands/generate/cell/cellHandler.js +22 -21
  42. package/dist/commands/generate/component/componentHandler.js +14 -16
  43. package/dist/commands/generate/dataMigration/dataMigration.js +24 -13
  44. package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
  45. package/dist/commands/generate/dbAuth/dbAuthHandler.js +40 -30
  46. package/dist/commands/generate/directive/directiveHandler.js +12 -14
  47. package/dist/commands/generate/function/function.js +1 -0
  48. package/dist/commands/generate/function/functionHandler.js +12 -17
  49. package/dist/commands/generate/helpers.js +17 -17
  50. package/dist/commands/generate/job/job.js +1 -0
  51. package/dist/commands/generate/job/jobHandler.js +15 -17
  52. package/dist/commands/generate/layout/layoutHandler.js +13 -16
  53. package/dist/commands/generate/model/model.js +1 -0
  54. package/dist/commands/generate/model/modelHandler.js +9 -3
  55. package/dist/commands/generate/ogImage/ogImage.js +1 -0
  56. package/dist/commands/generate/ogImage/ogImageHandler.js +16 -9
  57. package/dist/commands/generate/package/packageHandler.js +32 -49
  58. package/dist/commands/generate/page/pageHandler.js +25 -22
  59. package/dist/commands/generate/realtime/realtime.js +1 -1
  60. package/dist/commands/generate/realtime/realtimeHandler.js +46 -20
  61. package/dist/commands/generate/scaffold/scaffold.js +1 -0
  62. package/dist/commands/generate/scaffold/scaffoldHandler.js +35 -27
  63. package/dist/commands/generate/script/script.js +1 -0
  64. package/dist/commands/generate/script/templates/tsconfig.json.template +14 -0
  65. package/dist/commands/generate/sdl/sdl.js +4 -3
  66. package/dist/commands/generate/sdl/sdlHandler.js +38 -18
  67. package/dist/commands/generate/secret/secret.js +19 -19
  68. package/dist/commands/generate/service/service.js +5 -5
  69. package/dist/commands/generate/service/serviceHandler.js +59 -22
  70. package/dist/commands/generate/yargsCommandHelpers.js +6 -1
  71. package/dist/commands/generate/yargsHandlerHelpers.js +18 -10
  72. package/dist/commands/generate.js +3 -10
  73. package/dist/commands/jobsHandler.js +3 -2
  74. package/dist/commands/prismaHandler.js +10 -9
  75. package/dist/commands/serve.js +84 -137
  76. package/dist/commands/serveApiHandler.js +5 -5
  77. package/dist/commands/serveBothHandler.js +10 -7
  78. package/dist/commands/serveWebHandler.js +2 -2
  79. package/dist/commands/setup/auth/auth.js +12 -6
  80. package/dist/commands/setup/cache/cacheHandler.js +11 -6
  81. package/dist/commands/setup/deploy/deploy.js +4 -3
  82. package/dist/commands/setup/deploy/helpers/helpers.js +5 -1
  83. package/dist/commands/setup/deploy/helpers/index.js +157 -5
  84. package/dist/commands/setup/deploy/providers/baremetalHandler.js +26 -4
  85. package/dist/commands/setup/deploy/providers/coherenceHandler.js +53 -25
  86. package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +33 -23
  87. package/dist/commands/setup/deploy/providers/netlify.js +6 -0
  88. package/dist/commands/setup/deploy/providers/netlifyHandler.js +112 -11
  89. package/dist/commands/setup/deploy/providers/renderHandler.js +10 -5
  90. package/dist/commands/setup/deploy/providers/serverlessHandler.js +5 -3
  91. package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
  92. package/dist/commands/setup/deploy/providers/universalDeployHandler.js +188 -0
  93. package/dist/commands/setup/deploy/providers/vercel.js +6 -0
  94. package/dist/commands/setup/deploy/providers/vercelHandler.js +113 -12
  95. package/dist/commands/setup/deploy/templates/baremetal.js +3 -2
  96. package/dist/commands/setup/deploy/templates/flightcontrol.js +60 -49
  97. package/dist/commands/setup/deploy/templates/netlify.js +2 -1
  98. package/dist/commands/setup/deploy/templates/netlifyUD.js +31 -0
  99. package/dist/commands/setup/docker/docker.js +1 -1
  100. package/dist/commands/setup/docker/dockerHandler.js +72 -37
  101. package/dist/commands/setup/docker/templates/Dockerfile.npm +119 -0
  102. package/dist/commands/setup/docker/templates/Dockerfile.pnpm +112 -0
  103. package/dist/commands/setup/docker/templates/{Dockerfile → Dockerfile.yarn} +1 -1
  104. package/dist/commands/setup/docker/templates/docker-compose.dev.yml +2 -2
  105. package/dist/commands/setup/generator/generatorHandler.js +4 -3
  106. package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +2 -2
  107. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +2 -2
  108. package/dist/commands/setup/i18n/i18nHandler.js +18 -15
  109. package/dist/commands/setup/jobs/jobsHandler.js +10 -5
  110. package/dist/commands/setup/mailer/mailerHandler.js +11 -9
  111. package/dist/commands/setup/package/packageHandler.js +14 -10
  112. package/dist/commands/setup/realtime/realtimeHandler.js +22 -20
  113. package/dist/commands/setup/server-file/serverFileHandler.js +16 -8
  114. package/dist/commands/setup/tsconfig/tsconfigHandler.js +5 -3
  115. package/dist/commands/setup/ui/helpers/helpers.js +5 -1
  116. package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +11 -5
  117. package/dist/commands/setup/ui/libraries/mantineHandler.js +21 -13
  118. package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +38 -26
  119. package/dist/commands/setup/uploads/uploadsHandler.js +7 -4
  120. package/dist/commands/setup.js +1 -2
  121. package/dist/commands/test/testHandler.js +2 -1
  122. package/dist/commands/test/testHandlerEsm.js +2 -2
  123. package/dist/commands/type-checkHandler.js +4 -6
  124. package/dist/commands/upgrade/upgradeHandler.js +2 -4
  125. package/dist/index.js +10 -4
  126. package/dist/lib/configureStorybook.js +2 -2
  127. package/dist/lib/exec.js +36 -24
  128. package/dist/lib/exit.js +19 -4
  129. package/dist/lib/extendFile.js +22 -12
  130. package/dist/lib/index.js +119 -85
  131. package/dist/lib/merge/algorithms.js +4 -1
  132. package/dist/lib/merge/index.js +76 -41
  133. package/dist/lib/merge/semanticIdentity.js +18 -6
  134. package/dist/lib/merge/strategy.js +86 -36
  135. package/dist/lib/packages.js +23 -13
  136. package/dist/lib/plugin.js +12 -5
  137. package/dist/lib/pluralHelpers.js +1 -1
  138. package/dist/lib/project.js +3 -1
  139. package/dist/lib/rollback.js +7 -7
  140. package/dist/lib/schemaHelpers.js +12 -12
  141. package/dist/lib/test.js +4 -0
  142. package/dist/lib/updateCheck.js +6 -4
  143. package/dist/middleware/checkNodeVersion.js +5 -0
  144. package/dist/plugin.js +18 -12
  145. package/dist/telemetry/exporter.js +12 -5
  146. package/dist/telemetry/index.js +4 -3
  147. package/dist/telemetry/resource.js +9 -5
  148. package/dist/telemetry/send.js +14 -10
  149. package/package.json +15 -12
  150. package/dist/commands/setup/vite/templates/vite.config.ts.template +0 -19
  151. package/dist/commands/setup/vite/vite.js +0 -38
  152. package/dist/commands/setup/vite/viteHandler.js +0 -82
  153. /package/dist/{index.d.js → global.d.js} +0 -0
@@ -1,7 +1,10 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import * as parser from "@babel/parser";
4
+ import * as t from "@babel/types";
3
5
  import execa from "execa";
4
6
  import { Listr } from "listr2";
7
+ import * as recast from "recast";
5
8
  import { getConfigPath, getConfig } from "@cedarjs/project-config";
6
9
  import { getPaths, writeFilesTask } from "../../../../lib/index.js";
7
10
  const updateApiURLTask = (apiUrl) => {
@@ -38,9 +41,10 @@ const preRequisiteCheckTask = (preRequisites) => {
38
41
  task: async () => {
39
42
  try {
40
43
  await execa(...preReq.command);
41
- } catch (error) {
42
- error.message = error.message + "\n" + preReq.errorMessage;
43
- throw error;
44
+ } catch (e) {
45
+ const baseMsg = e instanceof Error ? e.message : String(e);
46
+ const err = new Error(baseMsg + "\n" + preReq.errorMessage);
47
+ throw err;
44
48
  }
45
49
  }
46
50
  };
@@ -56,7 +60,7 @@ const addFilesTask = ({
56
60
  return {
57
61
  title: `${title}...`,
58
62
  task: () => {
59
- let fileNameToContentMap = {};
63
+ const fileNameToContentMap = {};
60
64
  files.forEach((fileData) => {
61
65
  fileNameToContentMap[fileData.path] = fileData.content;
62
66
  });
@@ -64,6 +68,150 @@ const addFilesTask = ({
64
68
  }
65
69
  };
66
70
  };
71
+ const verifyUDSetupTask = () => {
72
+ return {
73
+ title: "Checking if Universal Deploy is set up...",
74
+ task: () => {
75
+ const paths = getPaths();
76
+ const viteConfigTs = path.join(paths.web.base, "vite.config.ts");
77
+ const viteConfigJs = path.join(paths.web.base, "vite.config.js");
78
+ const viteConfigPath = fs.existsSync(viteConfigTs) ? viteConfigTs : viteConfigJs;
79
+ if (!fs.existsSync(viteConfigPath)) {
80
+ throw new Error("Vite config file not found");
81
+ }
82
+ const content = fs.readFileSync(viteConfigPath, "utf-8");
83
+ if (!content.includes("cedarUniversalDeployPlugin")) {
84
+ throw new Error(
85
+ "Universal Deploy is not set up. Please run `yarn cedar setup deploy universal-deploy` first."
86
+ );
87
+ }
88
+ }
89
+ };
90
+ };
91
+ function posToIndex(str, line, column) {
92
+ const lines = str.split("\n");
93
+ let index = 0;
94
+ for (let i = 0; i < line - 1; i++) {
95
+ index += lines[i].length + 1;
96
+ }
97
+ return index + column;
98
+ }
99
+ function resolveConfigObject(arg) {
100
+ if (t.isObjectExpression(arg)) {
101
+ return arg;
102
+ }
103
+ if (t.isArrowFunctionExpression(arg)) {
104
+ if (t.isObjectExpression(arg.body)) {
105
+ return arg.body;
106
+ }
107
+ if (t.isBlockStatement(arg.body)) {
108
+ const returnStmt = arg.body.body.find((s) => t.isReturnStatement(s));
109
+ if (t.isObjectExpression(returnStmt?.argument)) {
110
+ return returnStmt.argument;
111
+ }
112
+ }
113
+ return null;
114
+ }
115
+ if (t.isFunctionExpression(arg)) {
116
+ if (t.isBlockStatement(arg.body)) {
117
+ const returnStmt = arg.body.body.find(t.isReturnStatement);
118
+ if (t.isObjectExpression(returnStmt?.argument)) {
119
+ return returnStmt.argument;
120
+ }
121
+ }
122
+ return null;
123
+ }
124
+ return null;
125
+ }
126
+ function insertPluginsBeforeCedar({
127
+ content,
128
+ pluginCodes
129
+ }) {
130
+ const ast = recast.parse(content, {
131
+ parser: {
132
+ parse(source) {
133
+ return parser.parse(source, {
134
+ sourceType: "module",
135
+ plugins: ["typescript", "jsx"]
136
+ });
137
+ }
138
+ }
139
+ });
140
+ const defaultExport = ast.program.body.find(t.isExportDefaultDeclaration);
141
+ if (!defaultExport) {
142
+ return null;
143
+ }
144
+ const declaration = defaultExport.declaration;
145
+ const configArg = resolveConfigObject(declaration.arguments[0]);
146
+ if (!configArg) {
147
+ return null;
148
+ }
149
+ const pluginsProp = configArg.properties.find(t.isObjectProperty);
150
+ if (!t.isArrayExpression(pluginsProp?.value)) {
151
+ return null;
152
+ }
153
+ const arrayExpr = pluginsProp.value;
154
+ const elements = arrayExpr.elements;
155
+ const cedarIndex = elements.findIndex(
156
+ (el) => t.isCallExpression(el) && t.isIdentifier(el.callee) && el.callee.name === "cedar"
157
+ );
158
+ if (cedarIndex === -1) {
159
+ return null;
160
+ }
161
+ const cedarElement = elements[cedarIndex];
162
+ if (!cedarElement || !t.isCallExpression(cedarElement)) {
163
+ return null;
164
+ }
165
+ const cedarNode = cedarElement;
166
+ if (!cedarNode.loc || !arrayExpr.loc || !pluginsProp.loc) {
167
+ return null;
168
+ }
169
+ const isInline = cedarNode.loc.start.line === arrayExpr.loc.start.line;
170
+ if (isInline) {
171
+ const startPos = posToIndex(
172
+ content,
173
+ arrayExpr.loc.start.line,
174
+ arrayExpr.loc.start.column
175
+ );
176
+ const endPos = posToIndex(
177
+ content,
178
+ arrayExpr.loc.end.line,
179
+ arrayExpr.loc.end.column
180
+ );
181
+ const precedingText = content.slice(0, startPos);
182
+ const followingText = content.slice(endPos);
183
+ const existingCodes = elements.flatMap((el) => {
184
+ if (!el?.loc) {
185
+ return [];
186
+ }
187
+ return [
188
+ content.slice(
189
+ posToIndex(content, el.loc.start.line, el.loc.start.column),
190
+ posToIndex(content, el.loc.end.line, el.loc.end.column)
191
+ )
192
+ ];
193
+ });
194
+ const lines2 = content.split("\n");
195
+ const pluginsLine = pluginsProp.loc.start.line;
196
+ const pluginsIndent = (lines2[pluginsLine - 1].match(/^\s*/) ?? [""])[0];
197
+ const elemIndent = pluginsIndent + " ";
198
+ const allCodes = [...existingCodes];
199
+ allCodes.splice(cedarIndex, 0, ...pluginCodes);
200
+ const multiline = [
201
+ "[",
202
+ ...allCodes.map((code) => `${elemIndent}${code},`),
203
+ `${pluginsIndent}]`
204
+ ].join("\n");
205
+ return precedingText + multiline + followingText;
206
+ }
207
+ const cedarLine = cedarNode.loc.start.line;
208
+ const insertPos = posToIndex(content, cedarLine, 0);
209
+ const lines = content.split("\n");
210
+ const indent = (lines[cedarLine - 1].match(/^\s*/) ?? [""])[0];
211
+ const insertion = pluginCodes.map((code) => `${indent}${code},
212
+ `).join("");
213
+ return content.slice(0, insertPos) + insertion + content.slice(insertPos);
214
+ }
67
215
  const addToGitIgnoreTask = ({ paths }) => {
68
216
  return {
69
217
  title: "Updating .gitignore...",
@@ -71,6 +219,7 @@ const addToGitIgnoreTask = ({ paths }) => {
71
219
  if (!fs.existsSync(path.resolve(getPaths().base, ".gitignore"))) {
72
220
  return "No gitignore present, skipping.";
73
221
  }
222
+ return void 0;
74
223
  },
75
224
  task: async (_ctx, task) => {
76
225
  const gitIgnore = path.resolve(getPaths().base, ".gitignore");
@@ -89,6 +238,7 @@ const addToDotEnvTask = ({ lines }) => {
89
238
  if (!fs.existsSync(path.resolve(getPaths().base, ".env"))) {
90
239
  return "No .env present, skipping.";
91
240
  }
241
+ return void 0;
92
242
  },
93
243
  task: async (_ctx, task) => {
94
244
  const env = path.resolve(getPaths().base, ".env");
@@ -105,6 +255,8 @@ export {
105
255
  addToDotEnvTask,
106
256
  addToGitIgnoreTask,
107
257
  getUserApiUrl,
258
+ insertPluginsBeforeCedar,
108
259
  preRequisiteCheckTask,
109
- updateApiURLTask
260
+ updateApiURLTask,
261
+ verifyUDSetupTask
110
262
  };
@@ -1,5 +1,7 @@
1
- import path from "path";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
2
3
  import { Listr } from "listr2";
4
+ import prompts from "prompts";
3
5
  import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
4
6
  import { errorTelemetry } from "@cedarjs/telemetry";
5
7
  import {
@@ -35,6 +37,24 @@ const handler = async ({ force }) => {
35
37
  command: "setup deploy baremetal",
36
38
  force
37
39
  });
40
+ if (fs.existsSync(path.join(getPaths().base, ".pnp.cjs"))) {
41
+ console.warn(
42
+ c.warning(
43
+ "Your project uses Yarn PnP (Plug'n'Play), which is not officially supported for Baremetal deployments. The generated ecosystem.config.js file uses node_modules/.bin/cedar as the PM2 script path, which will most likely not work under PnP.\n\nYou will need to manually configure the server. See also the packageManagerCommand field in deploy.toml."
44
+ )
45
+ );
46
+ console.log();
47
+ const { confirmed } = await prompts({
48
+ type: "confirm",
49
+ name: "confirmed",
50
+ message: "Generate the default config anyway? (You can edit it later)"
51
+ });
52
+ if (!confirmed) {
53
+ console.log("Aborting baremetal setup.");
54
+ return;
55
+ }
56
+ console.log();
57
+ }
38
58
  const tasks = new Listr(
39
59
  [
40
60
  await addPackagesTask({
@@ -52,9 +72,11 @@ const handler = async ({ force }) => {
52
72
  try {
53
73
  await tasks.run();
54
74
  } catch (e) {
55
- errorTelemetry(process.argv, e.message);
56
- console.error(c.error(e.message));
57
- process.exit(e?.exitCode || 1);
75
+ const message = e instanceof Error ? e.message : String(e);
76
+ errorTelemetry(process.argv, message);
77
+ console.error(c.error(message));
78
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
79
+ process.exit(exitCode);
58
80
  }
59
81
  };
60
82
  export {
@@ -8,6 +8,10 @@ import {
8
8
  isTypeScriptProject,
9
9
  getConfigPath
10
10
  } from "@cedarjs/cli-helpers";
11
+ import {
12
+ formatCedarCommand,
13
+ formatRunBinCommand
14
+ } from "@cedarjs/cli-helpers/packageManager/display";
11
15
  import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
12
16
  import { errorTelemetry } from "@cedarjs/telemetry";
13
17
  import { printSetupNotes } from "../../../../lib/index.js";
@@ -34,9 +38,11 @@ async function handler({ force }) {
34
38
  );
35
39
  await tasks.run();
36
40
  } catch (e) {
37
- errorTelemetry(process.argv, e.message);
38
- console.error(c.error(e.message));
39
- process.exit(e?.exitCode || 1);
41
+ const message = e instanceof Error ? e.message : String(e);
42
+ errorTelemetry(process.argv, message);
43
+ console.error(c.error(message));
44
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
45
+ process.exit(exitCode);
40
46
  }
41
47
  }
42
48
  async function getAddCoherenceFilesTask(force) {
@@ -46,11 +52,11 @@ async function getAddCoherenceFilesTask(force) {
46
52
  content: coherenceFiles.healthCheck
47
53
  }
48
54
  ];
49
- const coherenceConfigFile = {
50
- path: path.join(cedarPaths.base, "coherence.yml")
51
- };
52
- coherenceConfigFile.content = await getCoherenceConfigFileContent();
53
- files.push(coherenceConfigFile);
55
+ const coherenceConfigContent = await getCoherenceConfigFileContent();
56
+ files.push({
57
+ path: path.join(cedarPaths.base, "coherence.yml"),
58
+ content: coherenceConfigContent
59
+ });
54
60
  return addFilesTask({
55
61
  title: `Adding coherence.yml and health.${EXTENSION}`,
56
62
  files,
@@ -74,20 +80,34 @@ async function getCoherenceConfigFileContent() {
74
80
  if (db === "postgresql") {
75
81
  db = "postgres";
76
82
  }
77
- const apiProdCommand = ["yarn", "cedar", "build", "api", "&&"];
83
+ const apiProdCommandSegments = [formatCedarCommand(["build", "api"]), "&&"];
78
84
  if (serverFileExists()) {
79
- apiProdCommand.push(
80
- "yarn",
81
- "node",
82
- "api/dist/server.js",
83
- "--apiRootPath=/api"
85
+ apiProdCommandSegments.push(
86
+ formatRunBinCommand("node", ["api/dist/server.js", "--apiRootPath=/api"])
84
87
  );
85
88
  } else {
86
- apiProdCommand.push("yarn", "cedar", "serve", "api", "--apiRootPath=/api");
89
+ apiProdCommandSegments.push(
90
+ formatCedarCommand(["serve", "api", "--apiRootPath=/api"])
91
+ );
87
92
  }
93
+ const apiDevCommandSegments = [
94
+ formatCedarCommand(["build", "api"]),
95
+ "&&",
96
+ formatCedarCommand(["dev", "api", "--apiRootPath=/api"])
97
+ ];
98
+ const migrationCommandSegments = [
99
+ formatCedarCommand(["prisma", "migrate", "deploy"]),
100
+ "&&",
101
+ formatCedarCommand(["data-migrate", "up"])
102
+ ];
88
103
  return coherenceFiles.yamlTemplate({
89
104
  db,
90
- apiProdCommand: `[${apiProdCommand.map((cmd) => `"${cmd}"`).join(", ")}]`
105
+ apiProdCommand: `[${apiProdCommandSegments.map((cmd) => `"${cmd}"`).join(", ")}]`,
106
+ apiDevCommand: `[${apiDevCommandSegments.map((cmd) => `"${cmd}"`).join(", ")}]`,
107
+ migrationCommand: `[${migrationCommandSegments.map((cmd) => `"${cmd}"`).join(", ")}]`,
108
+ webProdCommand: `["${formatCedarCommand(["serve", "web"])}"]`,
109
+ webDevCommand: `["${formatCedarCommand(["dev", "web", '--fwd=\\"--allowed-hosts all\\"'])}"]`,
110
+ webBuildCommand: `["${formatCedarCommand(["build", "web", "--no-prerender"])}"]`
91
111
  });
92
112
  }
93
113
  const SUPPORTED_DATABASES = ["mysql", "postgresql"];
@@ -117,13 +137,13 @@ function updateConfigTomlTask() {
117
137
  }
118
138
  configContent = configContent.replaceAll(
119
139
  HOST_REGEXP,
120
- (match, spaceBeforeAssign, spaceAfterAssign) => ["host", spaceBeforeAssign, "=", spaceAfterAssign, '"0.0.0.0"'].join(
140
+ (_match, spaceBeforeAssign, spaceAfterAssign) => ["host", spaceBeforeAssign, "=", spaceAfterAssign, '"0.0.0.0"'].join(
121
141
  ""
122
142
  )
123
143
  );
124
144
  configContent = configContent.replace(
125
145
  API_URL_REGEXP,
126
- (match, spaceBeforeAssign, spaceAfterAssign) => ["apiUrl", spaceBeforeAssign, "=", spaceAfterAssign, '"/api"'].join(
146
+ (_match, spaceBeforeAssign, spaceAfterAssign) => ["apiUrl", spaceBeforeAssign, "=", spaceAfterAssign, '"/api"'].join(
127
147
  ""
128
148
  )
129
149
  );
@@ -145,14 +165,22 @@ const HOST_REGEXP = /host(\s*)=(\s*)\".+\"/g;
145
165
  const API_URL_REGEXP = /apiUrl(\s*)=(\s*)\".+\"/;
146
166
  const PORT_REGEXP = /port(\s*)=(\s*)(?<port>\d{4})/g;
147
167
  const coherenceFiles = {
148
- yamlTemplate({ db, apiProdCommand }) {
168
+ yamlTemplate({
169
+ db,
170
+ apiProdCommand,
171
+ apiDevCommand,
172
+ migrationCommand,
173
+ webProdCommand,
174
+ webDevCommand,
175
+ webBuildCommand
176
+ }) {
149
177
  return `api:
150
178
  type: backend
151
179
  url_path: "/api"
152
180
  prod:
153
181
  command: ${apiProdCommand}
154
182
  dev:
155
- command: ["yarn", "cedar", "build", "api", "&&", "yarn", "cedar", "dev", "api", "--apiRootPath=/api"]
183
+ command: ${apiDevCommand}
156
184
  local_packages: ["node_modules"]
157
185
 
158
186
  system:
@@ -168,20 +196,20 @@ const coherenceFiles = {
168
196
  ${db === "postgres" ? "adapter: postgresql" : ""}
169
197
 
170
198
  # If you use data migrations, use the following instead:
171
- # migration: ["yarn", "cedar", "prisma", "migrate", "deploy", "&&", "yarn", "cedar", "data-migrate", "up"]
172
- migration: ["yarn", "cedar", "prisma", "migrate", "deploy"]
199
+ # migration: ["${formatCedarCommand(["prisma", "migrate", "deploy"])}", "&&", "${formatCedarCommand(["data-migrate", "up"])}"]
200
+ migration: ${migrationCommand}
173
201
 
174
202
  web:
175
203
  type: frontend
176
204
  assets_path: "web/dist"
177
205
  prod:
178
- command: ["yarn", "cedar", "serve", "web"]
206
+ command: ${webProdCommand}
179
207
  dev:
180
- command: ["yarn", "cedar", "dev", "web", "--fwd=\\"--allowed-hosts all\\""]
208
+ command: ${webDevCommand}
181
209
 
182
210
  # Heads up: Redwood's prerender doesn't work with Coherence yet.
183
211
  # For current status and updates, see https://github.com/redwoodjs/redwood/issues/8333.
184
- build: ["yarn", "cedar", "build", "web", "--no-prerender"]
212
+ build: ${webBuildCommand}
185
213
  local_packages: ["node_modules"]
186
214
 
187
215
  system:
@@ -4,18 +4,20 @@ import path from "path";
4
4
  import prismaInternals from "@prisma/internals";
5
5
  import { Listr } from "listr2";
6
6
  import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
7
+ import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
7
8
  import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
8
9
  import { errorTelemetry } from "@cedarjs/telemetry";
9
10
  import { writeFilesTask, printSetupNotes } from "../../../../lib/index.js";
10
11
  import { getUserApiUrl, updateApiURLTask } from "../helpers/index.js";
11
12
  import {
12
- flightcontrolConfig,
13
+ getFlightcontrolConfig,
13
14
  databaseEnvVariables,
14
15
  postgresDatabaseService,
15
16
  mysqlDatabaseService
16
17
  } from "../templates/flightcontrol.js";
17
18
  const { getConfig } = prismaInternals;
18
19
  const getFlightcontrolJson = async (database) => {
20
+ const flightcontrolConfig = getFlightcontrolConfig();
19
21
  if (database === "none") {
20
22
  return {
21
23
  path: path.join(getPaths().base, "flightcontrol.json"),
@@ -46,18 +48,20 @@ const getFlightcontrolJson = async (database) => {
46
48
  {
47
49
  ...flightcontrolConfig.environments[0],
48
50
  services: [
49
- ...flightcontrolConfig.environments[0].services.map((service) => {
50
- if (service.id === "cedar-api") {
51
- return {
52
- ...service,
53
- envVariables: {
54
- ...service.envVariables,
55
- ...databaseEnvVariables
56
- }
57
- };
51
+ ...flightcontrolConfig.environments[0].services.map(
52
+ (service) => {
53
+ if (service.id === "cedar-api") {
54
+ return {
55
+ ...service,
56
+ envVariables: {
57
+ ...service.envVariables,
58
+ ...databaseEnvVariables
59
+ }
60
+ };
61
+ }
62
+ return service;
58
63
  }
59
- return service;
60
- }),
64
+ ),
61
65
  dbService
62
66
  ]
63
67
  }
@@ -69,15 +73,15 @@ const getFlightcontrolJson = async (database) => {
69
73
  Prisma datasource provider is detected to be ${detectedDatabase}.
70
74
 
71
75
  Update your schema.prisma provider to be postgresql or mysql, then run
72
- yarn cedar prisma migrate dev
73
- yarn cedar setup deploy flightcontrol
76
+ ${formatCedarCommand(["prisma", "migrate", "dev"])}
77
+ ${formatCedarCommand(["setup", "deploy", "flightcontrol"])}
74
78
  `);
75
79
  }
76
80
  };
77
81
  const updateGraphQLFunction = () => {
78
82
  return {
79
83
  title: "Adding CORS config to createGraphQLHandler...",
80
- task: (_ctx) => {
84
+ task: () => {
81
85
  const graphqlTsPath = path.join(
82
86
  getPaths().base,
83
87
  "api/src/functions/graphql.ts"
@@ -125,7 +129,7 @@ const updateGraphQLFunction = () => {
125
129
  const updateDbAuth = () => {
126
130
  return {
127
131
  title: "Updating dbAuth cookie config (if used)...",
128
- task: (_ctx) => {
132
+ task: () => {
129
133
  const authTsPath = path.join(getPaths().base, "api/src/functions/auth.ts");
130
134
  const authJsPath = path.join(getPaths().base, "api/src/functions/auth.js");
131
135
  let authFnPath;
@@ -174,7 +178,7 @@ const updateDbAuth = () => {
174
178
  const updateApp = () => {
175
179
  return {
176
180
  title: "Updating App.jsx fetch config...",
177
- task: (_ctx) => {
181
+ task: () => {
178
182
  const appTsPath = path.join(getPaths().base, "web/src/App.tsx");
179
183
  const appJsPath = path.join(getPaths().base, "web/src/App.jsx");
180
184
  let appPath;
@@ -232,8 +236,9 @@ const addToDotEnvDefaultTask = () => {
232
236
  CEDAR_API_URL=${getUserApiUrl()}
233
237
  `;
234
238
  }
239
+ return void 0;
235
240
  },
236
- task: async (_ctx) => {
241
+ task: async () => {
237
242
  const env = path.resolve(getPaths().base, ".env.defaults");
238
243
  const apiUrl = getUserApiUrl();
239
244
  const line = `
@@ -250,7 +255,10 @@ const notes = [
250
255
  "Check out the deployment docs at https://app.flightcontrol.dev/docs for detailed instructions\n",
251
256
  "NOTE: If you are using yarn v1, remove the installCommand's from flightcontrol.json"
252
257
  ];
253
- const handler = async ({ force, database }) => {
258
+ const handler = async ({
259
+ force,
260
+ database
261
+ }) => {
254
262
  recordTelemetryAttributes({
255
263
  command: "setup deploy flightcontrol",
256
264
  force,
@@ -262,7 +270,7 @@ const handler = async ({ force, database }) => {
262
270
  title: "Adding flightcontrol.json",
263
271
  task: async () => {
264
272
  const fileData = await getFlightcontrolJson(database);
265
- let files = {};
273
+ const files = {};
266
274
  files[fileData.path] = JSON.stringify(fileData.content, null, 2);
267
275
  return writeFilesTask(files, { overwriteExisting: force });
268
276
  }
@@ -279,9 +287,11 @@ const handler = async ({ force, database }) => {
279
287
  try {
280
288
  await tasks.run();
281
289
  } catch (e) {
282
- errorTelemetry(process.argv, e.message);
283
- console.error(c.error(e.message));
284
- process.exit(e?.exitCode || 1);
290
+ const message = e instanceof Error ? e.message : String(e);
291
+ errorTelemetry(process.argv, message);
292
+ console.error(c.error(message));
293
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
294
+ process.exit(exitCode);
285
295
  }
286
296
  };
287
297
  export {
@@ -1,8 +1,14 @@
1
1
  import { createHandler } from "../helpers/helpers.js";
2
2
  const command = "netlify";
3
3
  const description = "Setup Netlify deploy";
4
+ const builder = (yargs) => yargs.option("ud", {
5
+ description: "Setup for use with Universal Deploy",
6
+ type: "boolean",
7
+ default: false
8
+ });
4
9
  const handler = createHandler("netlify");
5
10
  export {
11
+ builder,
6
12
  command,
7
13
  description,
8
14
  handler