@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,4 +1,5 @@
1
1
  import { terminalLink } from "termi-link";
2
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
3
  import { getPackageManager } from "@cedarjs/project-config/packageManager";
3
4
  const command = "baremetal [environment]";
4
5
  const description = "Deploy to baremetal server(s)";
@@ -70,17 +71,37 @@ const builder = (yargs) => {
70
71
  default: false,
71
72
  type: "boolean"
72
73
  });
74
+ yargs.option("git-check", {
75
+ describe: "Check for unpushed commits before deploying",
76
+ default: true,
77
+ type: "boolean"
78
+ });
73
79
  yargs.epilogue(
74
80
  `Also see the ${terminalLink(
75
- "Redwood Baremetal Deploy Reference",
81
+ "Cedar Baremetal Deploy Reference",
76
82
  "https://cedarjs.com/docs/cli-commands#deploy"
77
83
  )}
78
84
  `
79
85
  );
80
86
  };
81
87
  async function handler(yargs) {
82
- const { handler: importedHandler } = await import("./baremetal/baremetalHandler.js");
83
- return importedHandler(yargs);
88
+ recordTelemetryAttributes({
89
+ command: "deploy baremetal",
90
+ firstRun: yargs.firstRun,
91
+ df: yargs.df,
92
+ update: yargs.update,
93
+ install: yargs.install,
94
+ migrate: yargs.migrate,
95
+ build: yargs.build,
96
+ restart: yargs.restart,
97
+ cleanup: yargs.cleanup,
98
+ maintenance: yargs.maintenance,
99
+ rollback: yargs.rollback,
100
+ verbose: yargs.verbose,
101
+ gitCheck: yargs.gitCheck
102
+ });
103
+ const { handler: baremetalHandler } = await import("./baremetal/baremetalHandler.js");
104
+ return baremetalHandler(yargs);
84
105
  }
85
106
  export {
86
107
  builder,
@@ -1,8 +1,15 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import execa from "execa";
4
3
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
4
+ import { runBin, runWithNode } from "@cedarjs/cli-helpers/packageManager/exec";
5
5
  import { getPaths } from "@cedarjs/project-config";
6
+ async function runBinWithThrow(bin, args, options) {
7
+ const result = await runBin(bin, args, options);
8
+ if (result.failed) {
9
+ throw new Error(`Command (${bin} ${args.join(" ")}) failed`);
10
+ }
11
+ return result;
12
+ }
6
13
  const handler = async ({
7
14
  side,
8
15
  serve,
@@ -22,33 +29,28 @@ const handler = async ({
22
29
  shell: true,
23
30
  stdio: "inherit"
24
31
  };
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
32
  async function runApiCommands() {
33
33
  if (!serve) {
34
34
  console.log("Building api...");
35
- await runExecaCommand("yarn rw build api --verbose");
35
+ await runBinWithThrow("cedar", ["build", "api", "--verbose"], execaConfig);
36
36
  if (prisma) {
37
37
  console.log("Running database migrations...");
38
- await runExecaCommand(
39
- `node_modules/.bin/prisma migrate deploy --config "${cedarPaths.api.prismaConfig}"`
38
+ await runBinWithThrow(
39
+ "prisma",
40
+ ["migrate", "deploy", "--config", cedarPaths.api.prismaConfig],
41
+ execaConfig
40
42
  );
41
43
  }
42
44
  if (dataMigrate) {
43
45
  console.log("Running data migrations...");
44
- await runExecaCommand("yarn rw dataMigrate up");
46
+ await runBinWithThrow("cedar", ["dataMigrate", "up"], execaConfig);
45
47
  }
46
48
  return;
47
49
  }
48
50
  const serverFilePath = path.join(cedarPaths.api.dist, "server.js");
49
51
  const hasServerFile = fs.existsSync(serverFilePath);
50
52
  if (hasServerFile) {
51
- execa(`yarn node ${serverFilePath}`, execaConfig);
53
+ runWithNode(serverFilePath, execaConfig);
52
54
  } else {
53
55
  const { handler: handler2 } = await import("@cedarjs/api-server/apiCliConfigHandler");
54
56
  handler2();
@@ -56,7 +58,7 @@ const handler = async ({
56
58
  }
57
59
  async function runWebCommands() {
58
60
  console.log("Building web...");
59
- await runExecaCommand("yarn rw build web --verbose");
61
+ await runBinWithThrow("cedar", ["build", "web", "--verbose"], execaConfig);
60
62
  }
61
63
  if (side === "api") {
62
64
  await runApiCommands();
@@ -1,17 +1,22 @@
1
1
  import execa from "execa";
2
2
  import { colors as c } from "@cedarjs/cli-helpers";
3
+ import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
3
4
  import { getPaths } from "@cedarjs/project-config";
4
- const deployHandler = ({ build, prisma, dm: dataMigrate }) => {
5
+ const deployHandler = ({
6
+ build,
7
+ prisma,
8
+ dm: dataMigrate
9
+ }) => {
5
10
  const paths = getPaths();
6
- let commandSet = [];
11
+ const commandSet = [];
7
12
  if (build) {
8
- commandSet.push("yarn cedar build --verbose");
13
+ commandSet.push(formatCedarCommand(["build", "--verbose"]));
9
14
  }
10
15
  if (prisma) {
11
- commandSet.push("yarn cedar prisma migrate deploy");
16
+ commandSet.push(formatCedarCommand(["prisma", "migrate", "deploy"]));
12
17
  }
13
18
  if (dataMigrate) {
14
- commandSet.push("yarn cedar data-migrate up");
19
+ commandSet.push(formatCedarCommand(["data-migrate", "up"]));
15
20
  }
16
21
  const joinedCommands = commandSet.join(" && ");
17
22
  console.log(c.note("\nRunning:\n") + `${joinedCommands}
@@ -52,10 +52,9 @@ async function packageSingleFunction(functionFile) {
52
52
  recursive: true,
53
53
  force: true
54
54
  });
55
- return;
56
55
  }
57
56
  function nftPack() {
58
- const filesToBePacked = findApiDistFunctions();
57
+ const filesToBePacked = findApiDistFunctions({ cwd: getPaths().api.base });
59
58
  return Promise.all(filesToBePacked.map(nftPacker.packageSingleFunction));
60
59
  }
61
60
  export {
@@ -1,6 +1,6 @@
1
1
  import { terminalLink } from "termi-link";
2
2
  if (process.argv.slice(2).includes("api")) {
3
- process.env.REDWOOD_DISABLE_TELEMETRY = "1";
3
+ process.env.CEDAR_DISABLE_TELEMETRY = "1";
4
4
  }
5
5
  const command = "render <side>";
6
6
  const description = "Build, migrate, and serve command for Render deploy";
@@ -1,9 +1,18 @@
1
1
  import fs from "node:fs";
2
2
  import path from "path";
3
- import execa from "execa";
4
3
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
4
+ import { formatAddRootPackagesCommand } from "@cedarjs/cli-helpers/packageManager/display";
5
+ import {
6
+ runBinSync,
7
+ runWithNode
8
+ } from "@cedarjs/cli-helpers/packageManager/exec";
9
+ import { installPackages } from "@cedarjs/cli-helpers/packageManager/packages";
5
10
  import { getPaths } from "@cedarjs/project-config";
6
- const handler = async ({ side, prisma, dataMigrate }) => {
11
+ const handler = async ({
12
+ side,
13
+ prisma,
14
+ dataMigrate
15
+ }) => {
7
16
  recordTelemetryAttributes({
8
17
  command: "deploy render",
9
18
  side,
@@ -19,8 +28,9 @@ const handler = async ({ side, prisma, dataMigrate }) => {
19
28
  async function runApiCommands() {
20
29
  if (prisma) {
21
30
  console.log("Running database migrations...");
22
- execa.commandSync(
23
- `node_modules/.bin/prisma migrate deploy --config "${cedarPaths.api.prismaConfig}"`,
31
+ runBinSync(
32
+ "prisma",
33
+ ["migrate", "deploy", "--config", cedarPaths.api.prismaConfig],
24
34
  execaConfig
25
35
  );
26
36
  }
@@ -29,7 +39,7 @@ const handler = async ({ side, prisma, dataMigrate }) => {
29
39
  const packageJson = JSON.parse(
30
40
  fs.readFileSync(path.join(cedarPaths.base, "package.json"), "utf-8")
31
41
  );
32
- const hasDataMigratePackage = !!packageJson.devDependencies["@cedarjs/cli-data-migrate"];
42
+ const hasDataMigratePackage = !!packageJson.devDependencies?.["@cedarjs/cli-data-migrate"];
33
43
  if (!hasDataMigratePackage) {
34
44
  console.error(
35
45
  [
@@ -38,26 +48,26 @@ const handler = async ({ side, prisma, dataMigrate }) => {
38
48
  "If you want to run data migrations, add the package to your project's root package.json and deploy again:",
39
49
  "",
40
50
  "```",
41
- "yarn add -D @cedarjs/cli-data-migrate",
51
+ formatAddRootPackagesCommand(["@cedarjs/cli-data-migrate"], true),
42
52
  "```"
43
53
  ].join("\n")
44
54
  );
45
55
  } else {
46
- execa.commandSync("yarn cedar dataMigrate up", execaConfig);
56
+ runBinSync("cedar", ["dataMigrate", "up"], execaConfig);
47
57
  }
48
58
  }
49
59
  const serverFilePath = path.join(cedarPaths.api.dist, "server.js");
50
60
  const hasServerFile = fs.existsSync(serverFilePath);
51
61
  if (hasServerFile) {
52
- execa(`yarn node ${serverFilePath}`, execaConfig);
62
+ runWithNode(serverFilePath, execaConfig);
53
63
  } else {
54
- const { handler: handler2 } = await import("@cedarjs/api-server/apiCliConfigHandler");
55
- handler2();
64
+ const { handler: apiHandler } = await import("@cedarjs/api-server/apiCliConfigHandler");
65
+ apiHandler();
56
66
  }
57
67
  }
58
68
  async function runWebCommands() {
59
- execa.commandSync("yarn install", execaConfig);
60
- execa.commandSync("yarn cedar build web --verbose", execaConfig);
69
+ await installPackages(execaConfig);
70
+ runBinSync("cedar", ["build", "web", "--verbose"], execaConfig);
61
71
  }
62
72
  if (side === "api") {
63
73
  runApiCommands();
@@ -7,22 +7,38 @@ import execa from "execa";
7
7
  import { Listr } from "listr2";
8
8
  import prompts from "prompts";
9
9
  import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
10
+ import {
11
+ formatAddRootPackagesCommand,
12
+ formatRunBinCommand
13
+ } from "@cedarjs/cli-helpers/packageManager/display";
14
+ import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
10
15
  import { getPaths } from "../../lib/index.js";
11
16
  const preRequisites = () => [
12
17
  {
13
18
  title: "Checking if Serverless framework is installed...",
14
- command: ["yarn serverless", ["--version"]],
15
- errorMessage: [
16
- "Looks like Serverless is not installed.",
17
- "Please run yarn add -W --dev serverless."
18
- ]
19
+ task: async () => {
20
+ try {
21
+ await runBin("serverless", ["--version"], { shell: true });
22
+ } catch (error) {
23
+ const msg = error instanceof Error ? error.message : String(error);
24
+ throw new Error(
25
+ `${msg}
26
+ Looks like Serverless is not installed.
27
+ Please run ${formatAddRootPackagesCommand(["serverless"], true)}.`
28
+ );
29
+ }
30
+ }
19
31
  }
20
32
  ];
21
- const buildCommands = ({ sides }) => {
33
+ const buildCommands = ({
34
+ sides
35
+ }) => {
22
36
  return [
23
37
  {
24
38
  title: `Building ${sides.join(" & ")}...`,
25
- command: ["yarn", ["cedar", "build", ...sides]]
39
+ task: async () => {
40
+ await runBin("cedar", ["build", ...sides], { shell: true });
41
+ }
26
42
  },
27
43
  {
28
44
  title: "Packing Functions...",
@@ -34,13 +50,18 @@ const buildCommands = ({ sides }) => {
34
50
  }
35
51
  ];
36
52
  };
37
- const deployCommands = ({ stage, sides, firstRun, packOnly }) => {
53
+ const deployCommands = ({
54
+ stage,
55
+ sides,
56
+ firstRun,
57
+ packOnly
58
+ }) => {
38
59
  const slsStage = stage ? ["--stage", stage] : [];
39
60
  return sides.map((side) => {
40
61
  return {
41
62
  title: `Deploying ${side}....`,
42
63
  task: async () => {
43
- await execa("yarn", ["serverless", "deploy", ...slsStage], {
64
+ await runBin("serverless", ["deploy", ...slsStage], {
44
65
  cwd: path.join(getPaths().base, side),
45
66
  shell: true,
46
67
  stdio: "inherit",
@@ -54,6 +75,7 @@ const deployCommands = ({ stage, sides, firstRun, packOnly }) => {
54
75
  if (packOnly) {
55
76
  return "Finishing early due to --pack-only flag. Your Redwood project is packaged and ready to deploy";
56
77
  }
78
+ return false;
57
79
  }
58
80
  };
59
81
  });
@@ -78,13 +100,13 @@ const handler = async (yargs) => {
78
100
  loadDotEnvForStage(dotEnvPath);
79
101
  const tasks = new Listr(
80
102
  [
81
- ...preRequisites(yargs).map(mapCommandsToListr),
103
+ ...preRequisites().map(mapCommandsToListr),
82
104
  ...buildCommands(yargs).map(mapCommandsToListr),
83
105
  ...deployCommands(yargs).map(mapCommandsToListr)
84
106
  ],
85
107
  {
86
108
  exitOnError: true,
87
- renderer: yargs.verbose && "verbose"
109
+ renderer: yargs.verbose ? "verbose" : void 0
88
110
  }
89
111
  );
90
112
  try {
@@ -93,14 +115,21 @@ const handler = async (yargs) => {
93
115
  const SETUP_MARKER = ansis.bgBlue.black("First Setup ");
94
116
  console.log();
95
117
  console.log(SETUP_MARKER, c.success("Starting first setup wizard..."));
96
- const { stdout: slsInfo } = await execa(
97
- `yarn serverless info --verbose --stage=${yargs.stage}`,
118
+ const { stdout: slsInfo } = await runBin(
119
+ "serverless",
120
+ ["info", "--verbose", `--stage=${yargs.stage}`],
98
121
  {
99
122
  shell: true,
100
123
  cwd: getPaths().api.base
101
124
  }
102
125
  );
103
- const deployedApiUrl = slsInfo.match(/HttpApiUrl: (https:\/\/.*)/)[1];
126
+ const apiMatch = slsInfo.match(/HttpApiUrl: (https:\/\/.*)/);
127
+ if (!apiMatch) {
128
+ throw new Error(
129
+ "Could not find HttpApiUrl in serverless info output. Deploy may have failed."
130
+ );
131
+ }
132
+ const deployedApiUrl = apiMatch[1];
104
133
  console.log();
105
134
  console.log(SETUP_MARKER, `Found ${c.success(deployedApiUrl)}`);
106
135
  console.log();
@@ -124,7 +153,7 @@ const handler = async (yargs) => {
124
153
  const webDeployTasks = new Listr(
125
154
  [
126
155
  // Rebuild web with the new API_URL
127
- ...buildCommands({ ...yargs, sides: ["web"], firstRun: false }).map(
156
+ ...buildCommands({ ...yargs, sides: ["web"] }).map(
128
157
  mapCommandsToListr
129
158
  ),
130
159
  ...deployCommands({
@@ -135,25 +164,32 @@ const handler = async (yargs) => {
135
164
  ],
136
165
  {
137
166
  exitOnError: true,
138
- renderer: yargs.verbose && "verbose"
167
+ renderer: yargs.verbose ? "verbose" : void 0
139
168
  }
140
169
  );
141
170
  await webDeployTasks.run();
142
- const { stdout: slsInfo2 } = await execa(
143
- `yarn serverless info --verbose --stage=${yargs.stage}`,
171
+ const { stdout: webSlsInfo } = await runBin(
172
+ "serverless",
173
+ ["info", "--verbose", `--stage=${yargs.stage}`],
144
174
  {
145
175
  shell: true,
146
176
  cwd: getPaths().web.base
147
177
  }
148
178
  );
149
- const deployedWebUrl = slsInfo2.match(/url: (https:\/\/.*)/)[1];
179
+ const webMatch = webSlsInfo.match(/url: (https:\/\/.*)/);
180
+ if (!webMatch) {
181
+ throw new Error(
182
+ "Could not find url in serverless info output. Deploy may have failed."
183
+ );
184
+ }
185
+ const deployedWebUrl = webMatch[1];
150
186
  const message = [
151
187
  c.bold("Successful first deploy!"),
152
188
  "",
153
189
  `View your deployed site at: ${c.success(deployedWebUrl)}`,
154
190
  "",
155
191
  "You can use serverless.com CI/CD by connecting/creating an app",
156
- "To do this run `yarn serverless` on each of the sides, and connect your account",
192
+ `To do this run \`${formatRunBinCommand("serverless")}\` on each of the sides, and connect your account`,
157
193
  "",
158
194
  "Find more information in our docs:",
159
195
  c.underline("https://cedarjs.com/docs/deploy#serverless")
@@ -168,8 +204,9 @@ const handler = async (yargs) => {
168
204
  }
169
205
  }
170
206
  } catch (e) {
171
- console.error(c.error(e.message));
172
- process.exit(e?.exitCode || 1);
207
+ console.error(c.error(e instanceof Error ? e.message : String(e)));
208
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
209
+ process.exit(exitCode);
173
210
  }
174
211
  };
175
212
  const mapCommandsToListr = ({
@@ -185,14 +222,19 @@ const mapCommandsToListr = ({
185
222
  title,
186
223
  task: task ? task : async () => {
187
224
  try {
188
- const executingCommand = execa(...command, {
225
+ if (!command) {
226
+ throw new Error(
227
+ "No command or task provided to mapCommandsToListr"
228
+ );
229
+ }
230
+ const executingCommand = execa(command[0], command[1], {
189
231
  cwd: cwd || getPaths().base,
190
232
  shell: true
191
233
  });
192
- executingCommand.stdout.pipe(process.stdout);
234
+ executingCommand.stdout?.pipe(process.stdout);
193
235
  await executingCommand;
194
236
  } catch (error) {
195
- if (errorMessage) {
237
+ if (errorMessage && error instanceof Error) {
196
238
  error.message = error.message + "\n" + errorMessage.join(" ");
197
239
  }
198
240
  throw error;
@@ -1,6 +1,6 @@
1
1
  import { createHandler, createYargsForComponentDestroy } from "../helpers.js";
2
2
  const description = "Destroy a component";
3
- const { command, builder, tasks } = createYargsForComponentDestroy({
3
+ const { command, builder } = createYargsForComponentDestroy({
4
4
  componentName: "component"
5
5
  });
6
6
  const handler = createHandler("component");
@@ -8,6 +8,5 @@ export {
8
8
  builder,
9
9
  command,
10
10
  description,
11
- handler,
12
- tasks
11
+ handler
13
12
  };
@@ -1,9 +1,7 @@
1
- import { files as directiveFiles } from "../../generate/directive/directiveHandler.js";
2
1
  import { createYargsForComponentDestroy, createHandler } from "../helpers.js";
3
2
  const description = "Destroy a directive";
4
3
  const { command, builder } = createYargsForComponentDestroy({
5
- componentName: "directive",
6
- filesFn: (args) => directiveFiles({ ...args, type: "validator" })
4
+ componentName: "directive"
7
5
  });
8
6
  const handler = createHandler("directive");
9
7
  export {
@@ -1,12 +1,10 @@
1
1
  import { files as directiveFiles } from "../../generate/directive/directiveHandler.js";
2
2
  import { createHandler } from "../handlerHelpers.js";
3
- const description = "Destroy a directive";
4
- const { builder, tasks } = createHandler({
3
+ const { handler, tasks } = createHandler({
5
4
  componentName: "directive",
6
5
  filesFn: (args) => directiveFiles({ ...args, type: "validator" })
7
6
  });
8
7
  export {
9
- builder,
10
- description,
8
+ handler,
11
9
  tasks
12
10
  };
@@ -1,4 +1,3 @@
1
- import { files as functionFiles } from "../../generate/function/functionHandler.js";
2
1
  import { createYargsForComponentDestroy, createHandler } from "../helpers.js";
3
2
  const description = "Destroy a Function";
4
3
  const builder = (yargs) => {
@@ -8,8 +7,7 @@ const builder = (yargs) => {
8
7
  });
9
8
  };
10
9
  const { command } = createYargsForComponentDestroy({
11
- componentName: "function",
12
- filesFn: functionFiles
10
+ componentName: "function"
13
11
  });
14
12
  const handler = createHandler("function");
15
13
  export {
@@ -1,18 +1,20 @@
1
1
  import { Listr } from "listr2";
2
2
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
3
3
  import { deleteFilesTask } from "../../lib/index.js";
4
- const tasks = ({ componentName, filesFn, name }) => new Listr(
5
- [
6
- {
7
- title: `Destroying ${componentName} files...`,
8
- task: async () => {
9
- const f = await filesFn({ name, stories: true, tests: true });
10
- return deleteFilesTask(f);
4
+ function tasks({ componentName, filesFn, name }) {
5
+ return new Listr(
6
+ [
7
+ {
8
+ title: `Destroying ${componentName} files...`,
9
+ task: async () => {
10
+ const f = await filesFn({ name, stories: true, tests: true });
11
+ return deleteFilesTask(f);
12
+ }
11
13
  }
12
- }
13
- ],
14
- { rendererOptions: { collapseSubtasks: false }, exitOnError: true }
15
- );
14
+ ],
15
+ { rendererOptions: { collapseSubtasks: false }, exitOnError: true }
16
+ );
17
+ }
16
18
  function createHandler({
17
19
  componentName,
18
20
  preTasksFn = (options) => options,
@@ -20,11 +22,9 @@ function createHandler({
20
22
  }) {
21
23
  return {
22
24
  handler: async (options) => {
23
- recordTelemetryAttributes({
24
- command: `destroy ${componentName}`
25
- });
26
- options = await preTasksFn({ ...options, isDestroyer: true });
27
- await tasks({ componentName, filesFn, name: options.name }).run();
25
+ recordTelemetryAttributes({ command: `destroy ${componentName}` });
26
+ const { name } = await preTasksFn({ ...options, isDestroyer: true });
27
+ await tasks({ componentName, filesFn, name }).run();
28
28
  },
29
29
  tasks
30
30
  };
@@ -1,4 +1,6 @@
1
- const createYargsForComponentDestroy = ({ componentName }) => {
1
+ const createYargsForComponentDestroy = ({
2
+ componentName
3
+ }) => {
2
4
  return {
3
5
  command: `${componentName} <name>`,
4
6
  description: `Destroy a ${componentName} component`,
@@ -12,7 +14,11 @@ const createYargsForComponentDestroy = ({ componentName }) => {
12
14
  };
13
15
  function createHandler(componentName) {
14
16
  return async (argv) => {
15
- const importedHandler = await import(`./${componentName}/${componentName}Handler.js`);
17
+ const { existsSync } = await import("node:fs");
18
+ const tsPath = `./${componentName}/${componentName}Handler.ts`;
19
+ const jsPath = `./${componentName}/${componentName}Handler.js`;
20
+ const resolvedPath = existsSync(new URL(tsPath, import.meta.url)) ? tsPath : jsPath;
21
+ const importedHandler = await import(resolvedPath);
16
22
  const fn = importedHandler.default ?? importedHandler.handler ?? importedHandler;
17
23
  return typeof fn === "function" ? fn(argv) : fn;
18
24
  };
@@ -1,7 +1,6 @@
1
- import { files as layoutFiles } from "../../generate/layout/layoutHandler.js";
2
1
  import { createYargsForComponentDestroy, createHandler } from "../helpers.js";
3
2
  const { command, description, builder } = createYargsForComponentDestroy(
4
- { componentName: "layout", filesFn: layoutFiles }
3
+ { componentName: "layout" }
5
4
  );
6
5
  const handler = createHandler("layout");
7
6
  export {
@@ -41,7 +41,7 @@ const handler = async ({ name, path }) => {
41
41
  try {
42
42
  await t.run();
43
43
  } catch (e) {
44
- console.log(c.error(e.message));
44
+ console.log(c.error(e instanceof Error ? e.message : String(e)));
45
45
  }
46
46
  };
47
47
  export {
@@ -15,7 +15,11 @@ import {
15
15
  routes as scaffoldRoutes,
16
16
  splitPathAndModel
17
17
  } from "../../generate/scaffold/scaffoldHandler.js";
18
- const removeRoutesWithSet = async ({ model, path, nestScaffoldByModel }) => {
18
+ const removeRoutesWithSet = async ({
19
+ model,
20
+ path,
21
+ nestScaffoldByModel
22
+ }) => {
19
23
  const routes = await scaffoldRoutes({ model, path, nestScaffoldByModel });
20
24
  const routeNames = routes.map(extractRouteName);
21
25
  const pluralPascalName = pascalcase(pluralize(model));
@@ -28,18 +32,25 @@ const removeSetImport = () => {
28
32
  if (routesContent.match("<Set")) {
29
33
  return "Skipping removal of Set import in Routes.{jsx,tsx}";
30
34
  }
31
- const [redwoodRouterImport] = routesContent.match(
35
+ const cedarRouterImportMatch = routesContent.match(
32
36
  /import {[^]*} from '@cedarjs\/router'/
33
37
  );
34
- const removedSetImport = redwoodRouterImport.replace(/,*\s*Set,*/, "");
38
+ if (!cedarRouterImportMatch) {
39
+ return "No @cedarjs/router import found in Routes.{jsx,tsx}";
40
+ }
41
+ const [cedarRouterImport] = cedarRouterImportMatch;
42
+ const removedSetImport = cedarRouterImport.replace(/,*\s*Set,*/, "");
35
43
  const newRoutesContent = routesContent.replace(
36
- redwoodRouterImport,
44
+ cedarRouterImport,
37
45
  removedSetImport
38
46
  );
39
47
  writeFile(routesPath, newRoutesContent, { overwriteExisting: true });
40
48
  return "Removed Set import in Routes.{jsx,tsx}";
41
49
  };
42
- const removeLayoutImport = ({ model: name, path: scaffoldPath = "" }) => {
50
+ const removeLayoutImport = ({
51
+ model: name,
52
+ path: scaffoldPath = ""
53
+ }) => {
43
54
  const pluralPascalName = pascalcase(pluralize(name));
44
55
  const pascalScaffoldPath = scaffoldPath === "" ? scaffoldPath : scaffoldPath.split("/").map(pascalcase).join("/") + "/";
45
56
  const layoutName = `${pluralPascalName}Layout`;
@@ -53,7 +64,12 @@ const removeLayoutImport = ({ model: name, path: scaffoldPath = "" }) => {
53
64
  writeFile(routesPath, newRoutesContent, { overwriteExisting: true });
54
65
  return "Removed layout import from Routes.{jsx,tsx}";
55
66
  };
56
- const tasks = ({ model, path, tests, nestScaffoldByModel }) => new Listr(
67
+ const tasks = ({
68
+ model,
69
+ path,
70
+ tests,
71
+ nestScaffoldByModel
72
+ }) => new Listr(
57
73
  [
58
74
  {
59
75
  title: "Destroying scaffold files...",
@@ -91,12 +107,15 @@ const handler = async ({ model: modelArg }) => {
91
107
  const { name } = await verifyModelName({ name: model, isDestroyer: true });
92
108
  await tasks({ model: name, path }).run();
93
109
  } catch (e) {
94
- console.log(c.error(e.message));
110
+ console.log(c.error(e instanceof Error ? e.message : String(e)));
95
111
  }
96
112
  };
97
113
  const extractRouteName = (route) => {
98
- const { groups } = route.match(/.*name="?(?<routeName>\w+)"?/);
99
- return groups.routeName;
114
+ const match = route.match(/.*name="?(?<routeName>\w+)"?/);
115
+ if (!match?.groups?.routeName) {
116
+ throw new Error(`Could not extract route name from route: ${route}`);
117
+ }
118
+ return match.groups.routeName;
100
119
  };
101
120
  export {
102
121
  handler,