@cedarjs/cli 5.0.0-canary.2457 → 5.0.0-canary.2459

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.
@@ -13,7 +13,10 @@ import {
13
13
  } from "../../../lib/index.js";
14
14
  import { prepareForRollback } from "../../../lib/rollback.js";
15
15
  import { customOrDefaultTemplatePath } from "../yargsHandlerHelpers.js";
16
- const files = async ({ pagePath, typescript = false }) => {
16
+ const files = async ({
17
+ pagePath,
18
+ typescript = false
19
+ }) => {
17
20
  const extension = typescript ? ".tsx" : ".jsx";
18
21
  const componentOutputPath = path.join(
19
22
  getPaths().web.pages,
@@ -73,6 +76,10 @@ const handler = async (options) => {
73
76
  const extension = options.typescript ? "tsx" : "jsx";
74
77
  try {
75
78
  await validatePath(normalizedPagePath, extension);
79
+ const listrOptions = {
80
+ exitOnError: true,
81
+ ...options.verbose ? { renderer: "verbose" } : { rendererOptions: { collapseSubtasks: false } }
82
+ };
76
83
  const tasks = new Listr(
77
84
  [
78
85
  {
@@ -86,22 +93,22 @@ const handler = async (options) => {
86
93
  }
87
94
  }
88
95
  ],
89
- {
90
- rendererOptions: { collapseSubtasks: false },
91
- exitOnError: true,
92
- renderer: options.verbose && "verbose"
93
- }
96
+ listrOptions
94
97
  );
95
98
  if (options.rollback && !options.force) {
96
99
  prepareForRollback(tasks);
97
100
  }
98
101
  await tasks.run();
99
102
  } catch (e) {
100
- errorTelemetry(process.argv, e.message);
101
- console.error(c.error(e.message));
102
- process.exit(e?.exitCode || 1);
103
+ const message = e instanceof Error ? e.message : String(e);
104
+ errorTelemetry(process.argv, message);
105
+ console.error(c.error(message));
106
+ process.exit(errorExitCode(e));
103
107
  }
104
108
  };
109
+ function errorExitCode(e) {
110
+ return typeof e === "object" && e !== null && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
111
+ }
105
112
  export {
106
113
  files,
107
114
  handler,
@@ -3,13 +3,13 @@ import { terminalLink } from "termi-link";
3
3
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
4
4
  const DEFAULT_LENGTH = 32;
5
5
  const generateSecret = (length = DEFAULT_LENGTH) => {
6
- return crypto.randomBytes(length).toString("base64");
6
+ return crypto.randomBytes(Math.trunc(length)).toString("base64");
7
7
  };
8
8
  const command = "secret";
9
9
  const description = "Generates a secret key using a cryptographically-secure source of entropy";
10
10
  const builder = (yargs) => yargs.option("length", {
11
11
  description: "Length of the generated secret",
12
- type: "integer",
12
+ type: "number",
13
13
  required: false,
14
14
  default: DEFAULT_LENGTH
15
15
  }).option("raw", {
@@ -51,7 +51,11 @@ const templateForFile = async ({
51
51
  templatePath,
52
52
  templateVars
53
53
  }) => {
54
- const basePath = sidePathSection ? getPaths()[side][sidePathSection] : getPaths()[side];
54
+ const sideBase = getPaths()[side];
55
+ const basePath = sidePathSection ? sideBase[sidePathSection] : sideBase;
56
+ if (typeof basePath !== "string") {
57
+ throw new Error(`Invalid path section: "${sidePathSection}"`);
58
+ }
55
59
  const fullOutputPath = path.join(basePath, outputPath);
56
60
  const fullTemplatePath = customOrDefaultTemplatePath({
57
61
  generator,
@@ -126,6 +130,10 @@ function createHandler({
126
130
  validateName(argv.name);
127
131
  try {
128
132
  argv = await preTasksFn(argv);
133
+ const listrOptions = {
134
+ exitOnError: true,
135
+ ...argv.verbose ? { renderer: "verbose" } : { rendererOptions: { collapseSubtasks: false } }
136
+ };
129
137
  const tasks = new Listr(
130
138
  [
131
139
  {
@@ -137,28 +145,28 @@ function createHandler({
137
145
  },
138
146
  ...includeAdditionalTasks(argv)
139
147
  ],
140
- {
141
- rendererOptions: { collapseSubtasks: false },
142
- exitOnError: true,
143
- renderer: argv.verbose && "verbose"
144
- }
148
+ listrOptions
145
149
  );
146
150
  if (argv.rollback && !argv.force) {
147
151
  prepareForRollback(tasks);
148
152
  }
149
153
  await tasks.run();
150
154
  } catch (e) {
151
- errorTelemetry(process.argv, e.message);
152
- console.error(c.error(e.message));
153
- process.exit(e?.exitCode || 1);
155
+ const message = e instanceof Error ? e.message : String(e);
156
+ errorTelemetry(process.argv, message);
157
+ console.error(c.error(message));
158
+ process.exit(errorExitCode(e));
154
159
  }
155
160
  };
156
161
  }
162
+ function errorExitCode(e) {
163
+ return typeof e === "object" && e !== null && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
164
+ }
157
165
  const createYargsForComponentGeneration = ({
158
166
  componentName,
159
167
  preTasksFn = (options) => options,
160
168
  /** filesFn is not used if generator implements its own `handler` */
161
- filesFn = () => ({}),
169
+ filesFn = async () => ({}),
162
170
  optionsObj,
163
171
  positionalsObj = {},
164
172
  /** function that takes the options object and returns an array of listr tasks */
@@ -21,7 +21,7 @@ function addFileToRollback(filePath, atEnd = false) {
21
21
  rollback.push(step);
22
22
  }
23
23
  }
24
- async function executeRollback(_ = null, task = null) {
24
+ const executeRollback = async (_, task) => {
25
25
  if (task) {
26
26
  task.title = "Reverting generator actions...";
27
27
  }
@@ -53,7 +53,7 @@ async function executeRollback(_ = null, task = null) {
53
53
  if (task) {
54
54
  task.title = `Reverted because: ${task.task.message?.error ?? "unknown error"}`;
55
55
  }
56
- }
56
+ };
57
57
  function resetRollback() {
58
58
  rollback.length = 0;
59
59
  }
@@ -5,6 +5,9 @@ function checkNodeVersion() {
5
5
  const pVersion = process.version;
6
6
  const pVersionC = semver.clean(pVersion);
7
7
  const LOWER_BOUND = "v24.0.0";
8
+ if (!pVersionC) {
9
+ return checks;
10
+ }
8
11
  if (semver.gte(pVersionC, LOWER_BOUND)) {
9
12
  return checks;
10
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "5.0.0-canary.2457",
3
+ "version": "5.0.0-canary.2459",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,17 +33,17 @@
33
33
  "dependencies": {
34
34
  "@babel/parser": "7.29.3",
35
35
  "@babel/preset-typescript": "7.28.5",
36
- "@cedarjs/api-server": "5.0.0-canary.2457",
37
- "@cedarjs/cli-helpers": "5.0.0-canary.2457",
38
- "@cedarjs/fastify-web": "5.0.0-canary.2457",
39
- "@cedarjs/internal": "5.0.0-canary.2457",
40
- "@cedarjs/prerender": "5.0.0-canary.2457",
41
- "@cedarjs/project-config": "5.0.0-canary.2457",
42
- "@cedarjs/structure": "5.0.0-canary.2457",
43
- "@cedarjs/telemetry": "5.0.0-canary.2457",
44
- "@cedarjs/utils": "5.0.0-canary.2457",
45
- "@cedarjs/vite": "5.0.0-canary.2457",
46
- "@cedarjs/web-server": "5.0.0-canary.2457",
36
+ "@cedarjs/api-server": "5.0.0-canary.2459",
37
+ "@cedarjs/cli-helpers": "5.0.0-canary.2459",
38
+ "@cedarjs/fastify-web": "5.0.0-canary.2459",
39
+ "@cedarjs/internal": "5.0.0-canary.2459",
40
+ "@cedarjs/prerender": "5.0.0-canary.2459",
41
+ "@cedarjs/project-config": "5.0.0-canary.2459",
42
+ "@cedarjs/structure": "5.0.0-canary.2459",
43
+ "@cedarjs/telemetry": "5.0.0-canary.2459",
44
+ "@cedarjs/utils": "5.0.0-canary.2459",
45
+ "@cedarjs/vite": "5.0.0-canary.2459",
46
+ "@cedarjs/web-server": "5.0.0-canary.2459",
47
47
  "@listr2/prompt-adapter-enquirer": "4.2.1",
48
48
  "@opentelemetry/api": "1.9.1",
49
49
  "@opentelemetry/core": "1.30.1",