@cedarjs/cli 5.0.0-canary.2482 → 5.0.0-canary.2486

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.
@@ -14,7 +14,11 @@ const createYargsForComponentDestroy = ({
14
14
  };
15
15
  function createHandler(componentName) {
16
16
  return async (argv) => {
17
- 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);
18
22
  const fn = importedHandler.default ?? importedHandler.handler ?? importedHandler;
19
23
  return typeof fn === "function" ? fn(argv) : fn;
20
24
  };
@@ -2,7 +2,7 @@ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
2
  import { getEpilogue } from "./util.js";
3
3
  const command = "setup-inngest";
4
4
  const description = "Setup Inngest for background, scheduled, delayed, multi-step, and fan-out jobs";
5
- const EXPERIMENTAL_TOPIC_ID = 4866;
5
+ const EXPERIMENTAL_TOPIC_ID = "4866";
6
6
  const builder = (yargs) => {
7
7
  yargs.option("force", {
8
8
  alias: "f",
@@ -36,9 +36,11 @@ const handler = async ({ force }) => {
36
36
  try {
37
37
  await tasks.run();
38
38
  } catch (e) {
39
- errorTelemetry(process.argv, e.message);
40
- console.error(c.error(e.message));
41
- process.exit(e?.exitCode || 1);
39
+ const message = e instanceof Error ? e.message : String(e);
40
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
41
+ errorTelemetry(process.argv, message);
42
+ console.error(c.error(message));
43
+ process.exit(exitCode);
42
44
  }
43
45
  };
44
46
  export {
@@ -2,7 +2,7 @@ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
2
  import { getEpilogue } from "./util.js";
3
3
  const command = "setup-opentelemetry";
4
4
  const description = "Setup OpenTelemetry within the API side";
5
- const EXPERIMENTAL_TOPIC_ID = 4772;
5
+ const EXPERIMENTAL_TOPIC_ID = "4772";
6
6
  const builder = (yargs) => {
7
7
  yargs.option("force", {
8
8
  alias: "f",
@@ -2,7 +2,7 @@ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
2
  import { getEpilogue } from "./util.js";
3
3
  const command = "setup-react-compiler";
4
4
  const description = "Enable the experimental React Compiler";
5
- const EXPERIMENTAL_TOPIC_ID = 7128;
5
+ const EXPERIMENTAL_TOPIC_ID = "7128";
6
6
  const builder = (yargs) => {
7
7
  yargs.option("force", {
8
8
  alias: "f",
@@ -2,7 +2,7 @@ import pascalcase from "pascalcase";
2
2
  import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
3
3
  import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
4
4
  import { isPlural, singularize } from "@cedarjs/utils/cedarPluralize";
5
- import { nameVariants, transformTSToJS } from "../../../lib/index.js";
5
+ import { nameVariants, transformTSToJSMap } from "../../../lib/index.js";
6
6
  import { isWordPluralizable } from "../../../lib/pluralHelpers.js";
7
7
  import { addFunctionToRollback } from "../../../lib/rollback.js";
8
8
  import { getSchema } from "../../../lib/schemaHelpers.js";
@@ -19,8 +19,12 @@ import {
19
19
  uniqueOperationName
20
20
  } from "./utils/utils.js";
21
21
  const COMPONENT_SUFFIX = "Cell";
22
- const REDWOOD_WEB_PATH_NAME = "components";
23
- const files = async ({ name, typescript, ...argv }) => {
22
+ const CEDAR_WEB_PATH_NAME = "components";
23
+ const files = async ({
24
+ name,
25
+ typescript = false,
26
+ ...argv
27
+ }) => {
24
28
  let cellName = removeGeneratorName(name, "cell");
25
29
  let idName = "id";
26
30
  let idType;
@@ -58,7 +62,7 @@ const files = async ({ name, typescript, ...argv }) => {
58
62
  name: cellName,
59
63
  suffix: COMPONENT_SUFFIX,
60
64
  extension,
61
- webPathSection: REDWOOD_WEB_PATH_NAME,
65
+ webPathSection: CEDAR_WEB_PATH_NAME,
62
66
  generator: "cell",
63
67
  templatePath: `cell${templateNameSuffix}.tsx.template`,
64
68
  templateVars: {
@@ -71,7 +75,7 @@ const files = async ({ name, typescript, ...argv }) => {
71
75
  name: cellName,
72
76
  suffix: COMPONENT_SUFFIX,
73
77
  extension: `.test${extension}`,
74
- webPathSection: REDWOOD_WEB_PATH_NAME,
78
+ webPathSection: CEDAR_WEB_PATH_NAME,
75
79
  generator: "cell",
76
80
  templatePath: "test.js.template",
77
81
  templateVars: {
@@ -83,7 +87,7 @@ const files = async ({ name, typescript, ...argv }) => {
83
87
  name: cellName,
84
88
  suffix: COMPONENT_SUFFIX,
85
89
  extension: `.stories${extension}`,
86
- webPathSection: REDWOOD_WEB_PATH_NAME,
90
+ webPathSection: CEDAR_WEB_PATH_NAME,
87
91
  generator: "cell",
88
92
  templatePath: "stories.tsx.template"
89
93
  });
@@ -91,7 +95,7 @@ const files = async ({ name, typescript, ...argv }) => {
91
95
  name: cellName,
92
96
  suffix: COMPONENT_SUFFIX,
93
97
  extension: typescript ? ".mock.ts" : ".mock.js",
94
- webPathSection: REDWOOD_WEB_PATH_NAME,
98
+ webPathSection: CEDAR_WEB_PATH_NAME,
95
99
  generator: "cell",
96
100
  templatePath: `mock${templateNameSuffix}.ts.template`,
97
101
  templateVars: {
@@ -110,14 +114,7 @@ const files = async ({ name, typescript, ...argv }) => {
110
114
  if (argv.stories || argv.tests) {
111
115
  files2.push(mockFile);
112
116
  }
113
- return files2.reduce(async (accP, [outputPath, content]) => {
114
- const acc = await accP;
115
- const template = typescript ? content : await transformTSToJS(outputPath, content);
116
- return {
117
- [outputPath]: template,
118
- ...acc
119
- };
120
- }, Promise.resolve({}));
117
+ return transformTSToJSMap(files2, typescript);
121
118
  };
122
119
  const handler = createHandler({
123
120
  componentName: "cell",
@@ -4,14 +4,19 @@ import prompts from "prompts";
4
4
  import { recordTelemetryAttributes, colors as c } from "@cedarjs/cli-helpers";
5
5
  import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
6
6
  import { getConfig } from "@cedarjs/project-config";
7
- import { writeFilesTask, transformTSToJS } from "../../../lib/index.js";
7
+ import { writeFilesTask, transformTSToJSMap } from "../../../lib/index.js";
8
8
  import {
9
9
  prepareForRollback,
10
10
  addFunctionToRollback
11
11
  } from "../../../lib/rollback.js";
12
12
  import { validateName } from "../helpers.js";
13
13
  import { templateForComponentFile } from "../yargsHandlerHelpers.js";
14
- const files = async ({ name, typescript = false, type, tests }) => {
14
+ const files = async ({
15
+ name,
16
+ typescript = false,
17
+ type,
18
+ tests
19
+ }) => {
15
20
  if (tests === void 0) {
16
21
  tests = getConfig().generate.tests;
17
22
  }
@@ -40,14 +45,7 @@ const files = async ({ name, typescript = false, type, tests }) => {
40
45
  });
41
46
  files2.push(testFile);
42
47
  }
43
- return files2.reduce(async (accP, [outputPath, content]) => {
44
- const acc = await accP;
45
- const template = typescript ? content : await transformTSToJS(outputPath, content);
46
- return {
47
- [outputPath]: template,
48
- ...acc
49
- };
50
- }, Promise.resolve({}));
48
+ return transformTSToJSMap(files2, typescript);
51
49
  };
52
50
  const handler = async (args) => {
53
51
  recordTelemetryAttributes({
@@ -132,7 +130,7 @@ const handler = async (args) => {
132
130
  console.log(notes);
133
131
  }
134
132
  } catch (e) {
135
- console.log(c.error(e.message));
133
+ console.log(c.error(e instanceof Error ? e.message : String(e)));
136
134
  process.exit(1);
137
135
  }
138
136
  };
@@ -1,18 +1,22 @@
1
- import { transformTSToJS } from "../../../lib/index.js";
1
+ import { transformTSToJSMap } from "../../../lib/index.js";
2
2
  import { removeGeneratorName } from "../helpers.js";
3
3
  import {
4
- templateForComponentFile,
5
- createHandler
4
+ createHandler,
5
+ templateForComponentFile
6
6
  } from "../yargsHandlerHelpers.js";
7
7
  const COMPONENT_SUFFIX = "Layout";
8
- const REDWOOD_WEB_PATH_NAME = "layouts";
9
- const files = async ({ name, typescript = false, ...options }) => {
8
+ const CEDAR_WEB_PATH_NAME = "layouts";
9
+ const files = async ({
10
+ name,
11
+ typescript = false,
12
+ ...options
13
+ }) => {
10
14
  const layoutName = removeGeneratorName(name, "layout");
11
15
  const extension = typescript ? ".tsx" : ".jsx";
12
16
  const layoutFile = await templateForComponentFile({
13
17
  name: layoutName,
14
18
  suffix: COMPONENT_SUFFIX,
15
- webPathSection: REDWOOD_WEB_PATH_NAME,
19
+ webPathSection: CEDAR_WEB_PATH_NAME,
16
20
  extension,
17
21
  generator: "layout",
18
22
  templatePath: options.skipLink ? "layout.tsx.a11y.template" : "layout.tsx.template"
@@ -21,7 +25,7 @@ const files = async ({ name, typescript = false, ...options }) => {
21
25
  name: layoutName,
22
26
  suffix: COMPONENT_SUFFIX,
23
27
  extension: `.test${extension}`,
24
- webPathSection: REDWOOD_WEB_PATH_NAME,
28
+ webPathSection: CEDAR_WEB_PATH_NAME,
25
29
  generator: "layout",
26
30
  templatePath: "test.tsx.template"
27
31
  });
@@ -29,7 +33,7 @@ const files = async ({ name, typescript = false, ...options }) => {
29
33
  name: layoutName,
30
34
  suffix: COMPONENT_SUFFIX,
31
35
  extension: `.stories${extension}`,
32
- webPathSection: REDWOOD_WEB_PATH_NAME,
36
+ webPathSection: CEDAR_WEB_PATH_NAME,
33
37
  generator: "layout",
34
38
  templatePath: "stories.tsx.template"
35
39
  });
@@ -40,14 +44,7 @@ const files = async ({ name, typescript = false, ...options }) => {
40
44
  if (options.tests) {
41
45
  files2.push(testFile);
42
46
  }
43
- return files2.reduce(async (accP, [outputPath, content]) => {
44
- const acc = await accP;
45
- const template = typescript ? content : await transformTSToJS(outputPath, content);
46
- return {
47
- [outputPath]: template,
48
- ...acc
49
- };
50
- }, Promise.resolve({}));
47
+ return transformTSToJSMap(files2, typescript);
51
48
  };
52
49
  const handler = createHandler({
53
50
  componentName: "layout",
@@ -14,14 +14,20 @@ const TEMPLATE_PATH = path.resolve(
14
14
  "templates",
15
15
  "model.js.template"
16
16
  );
17
- const files = async ({ name, typescript = false }) => {
17
+ const files = async ({
18
+ name,
19
+ typescript = false
20
+ }) => {
18
21
  const outputFilename = `${name}.${typescript ? "ts" : "js"}`;
19
22
  const outputPath = path.join(getPaths().api.models, outputFilename);
20
23
  return {
21
24
  [outputPath]: await generateTemplate(TEMPLATE_PATH, { name })
22
25
  };
23
26
  };
24
- const handler = async ({ force, ...args }) => {
27
+ const handler = async ({
28
+ force,
29
+ ...args
30
+ }) => {
25
31
  recordTelemetryAttributes({
26
32
  command: "generate model",
27
33
  force,
@@ -53,7 +59,7 @@ const handler = async ({ force, ...args }) => {
53
59
  }
54
60
  await tasks.run();
55
61
  } catch (e) {
56
- console.log(c.error(e.message));
62
+ console.log(c.error(e instanceof Error ? e.message : String(e)));
57
63
  process.exit(1);
58
64
  }
59
65
  };
@@ -8,7 +8,7 @@ import { getConfig } from "@cedarjs/project-config";
8
8
  import { errorTelemetry } from "@cedarjs/telemetry";
9
9
  import {
10
10
  addRoutesToRouterTask,
11
- transformTSToJS,
11
+ transformTSToJSMap,
12
12
  writeFilesTask
13
13
  } from "../../../lib/index.js";
14
14
  import {
@@ -21,10 +21,12 @@ import {
21
21
  removeGeneratorName,
22
22
  validateName
23
23
  } from "../helpers.js";
24
- import { templateForComponentFile } from "../yargsHandlerHelpers.js";
24
+ import {
25
+ templateForComponentFile
26
+ } from "../yargsHandlerHelpers.js";
25
27
  const COMPONENT_SUFFIX = "Page";
26
- const REDWOOD_WEB_PATH_NAME = "pages";
27
- const mapRouteParamTypeToDefaultValue = (paramType) => {
28
+ const CEDAR_WEB_PATH_NAME = "pages";
29
+ function mapRouteParamTypeToDefaultValue(paramType) {
28
30
  switch (paramType) {
29
31
  case "Int":
30
32
  return 42;
@@ -35,7 +37,7 @@ const mapRouteParamTypeToDefaultValue = (paramType) => {
35
37
  default:
36
38
  return "42";
37
39
  }
38
- };
40
+ }
39
41
  const paramVariants = (path) => {
40
42
  const param = path?.match(/(\{[\w:]+\})/)?.[1];
41
43
  const paramName = param?.replace(/:[^}]+/, "").slice(1, -1);
@@ -62,13 +64,19 @@ const paramVariants = (path) => {
62
64
  paramType: mapRouteParamTypeToTsType(routeParamType)
63
65
  };
64
66
  };
65
- const files = async ({ name, tests, stories, typescript, ...rest }) => {
67
+ const files = async ({
68
+ name,
69
+ tests,
70
+ stories,
71
+ typescript = false,
72
+ ...rest
73
+ }) => {
66
74
  const extension = typescript ? ".tsx" : ".jsx";
67
75
  const pageFile = await templateForComponentFile({
68
76
  name,
69
77
  suffix: COMPONENT_SUFFIX,
70
78
  extension,
71
- webPathSection: REDWOOD_WEB_PATH_NAME,
79
+ webPathSection: CEDAR_WEB_PATH_NAME,
72
80
  generator: "page",
73
81
  templatePath: "page.tsx.template",
74
82
  templateVars: {
@@ -80,7 +88,7 @@ const files = async ({ name, tests, stories, typescript, ...rest }) => {
80
88
  name,
81
89
  suffix: COMPONENT_SUFFIX,
82
90
  extension: `.test${extension}`,
83
- webPathSection: REDWOOD_WEB_PATH_NAME,
91
+ webPathSection: CEDAR_WEB_PATH_NAME,
84
92
  generator: "page",
85
93
  templatePath: "test.tsx.template",
86
94
  templateVars: rest
@@ -89,7 +97,7 @@ const files = async ({ name, tests, stories, typescript, ...rest }) => {
89
97
  name,
90
98
  suffix: COMPONENT_SUFFIX,
91
99
  extension: `.stories${extension}`,
92
- webPathSection: REDWOOD_WEB_PATH_NAME,
100
+ webPathSection: CEDAR_WEB_PATH_NAME,
93
101
  generator: "page",
94
102
  templatePath: rest.paramName !== "" ? "stories.tsx.parameters.template" : "stories.tsx.template",
95
103
  templateVars: rest
@@ -101,16 +109,12 @@ const files = async ({ name, tests, stories, typescript, ...rest }) => {
101
109
  if (stories) {
102
110
  files2.push(storiesFile);
103
111
  }
104
- return files2.reduce(async (accP, [outputPath, content]) => {
105
- const acc = await accP;
106
- const template = typescript ? content : await transformTSToJS(outputPath, content);
107
- return {
108
- [outputPath]: template,
109
- ...acc
110
- };
111
- }, Promise.resolve({}));
112
+ return transformTSToJSMap(files2, typescript);
112
113
  };
113
- const routes = ({ name, path }) => {
114
+ const routes = ({
115
+ name,
116
+ path
117
+ }) => {
114
118
  return [
115
119
  `<Route path="${path}" page={${pascalcase(name)}Page} name="${camelcase(
116
120
  name
@@ -191,7 +195,7 @@ const handler = async ({
191
195
  },
192
196
  {
193
197
  title: "One more thing...",
194
- task: (ctx, task) => {
198
+ task: (_ctx, task) => {
195
199
  task.title = `One more thing...
196
200
 
197
201
  ${c.warning("Page created! A note about <Metadata>:")}
@@ -213,9 +217,11 @@ const handler = async ({
213
217
  }
214
218
  await tasks.run();
215
219
  } catch (e) {
216
- errorTelemetry(process.argv, e.message);
217
- console.error(c.error(e.message));
218
- process.exit(e?.exitCode || 1);
220
+ const message = e instanceof Error ? e.message : String(e);
221
+ const exitCode = e instanceof Error && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
222
+ errorTelemetry(process.argv, message);
223
+ console.error(c.error(message));
224
+ process.exit(exitCode);
219
225
  }
220
226
  };
221
227
  export {
@@ -74,7 +74,11 @@ function createBuilder({
74
74
  }
75
75
  function createHandler(componentName) {
76
76
  return async function handler(argv) {
77
- const { handler: importedHandler } = await import(`./${componentName}/${componentName}Handler.js`);
77
+ const { existsSync } = await import("node:fs");
78
+ const tsPath = `./${componentName}/${componentName}Handler.ts`;
79
+ const jsPath = `./${componentName}/${componentName}Handler.js`;
80
+ const resolvedPath = existsSync(new URL(tsPath, import.meta.url)) ? tsPath : jsPath;
81
+ const { handler: importedHandler } = await import(resolvedPath);
78
82
  return importedHandler(argv);
79
83
  };
80
84
  }
@@ -45,8 +45,8 @@ const templateForFile = async ({
45
45
  templatePath,
46
46
  templateVars
47
47
  }) => {
48
- const sideBase = getPaths()[side];
49
- const basePath = sidePathSection ? sideBase[sidePathSection] : sideBase;
48
+ const paths = getPaths();
49
+ const basePath = side === "scripts" ? paths.scripts : side === "web" ? sidePathSection ? paths.web[sidePathSection] : paths.web.base : side === "packages" ? paths.packages : sidePathSection ? paths.api[sidePathSection] : paths.api.base;
50
50
  if (typeof basePath !== "string") {
51
51
  throw new Error(`Invalid path section: "${sidePathSection}"`);
52
52
  }
@@ -1,6 +1,10 @@
1
1
  function createHandler(componentName) {
2
2
  return async function handler(argv) {
3
- const { handler: importedHandler } = await import(`../providers/${componentName}Handler.js`);
3
+ const { existsSync } = await import("node:fs");
4
+ const tsPath = `../providers/${componentName}Handler.ts`;
5
+ const jsPath = `../providers/${componentName}Handler.js`;
6
+ const resolvedPath = existsSync(new URL(tsPath, import.meta.url)) ? tsPath : jsPath;
7
+ const { handler: importedHandler } = await import(resolvedPath);
4
8
  return importedHandler(argv);
5
9
  };
6
10
  }
@@ -1,6 +1,10 @@
1
1
  function createHandler(componentName) {
2
2
  return async function handler(argv) {
3
- const { handler: importedHandler } = await import(`../libraries/${componentName}Handler.js`);
3
+ const { existsSync } = await import("node:fs");
4
+ const tsPath = `../libraries/${componentName}Handler.ts`;
5
+ const jsPath = `../libraries/${componentName}Handler.js`;
6
+ const resolvedPath = existsSync(new URL(tsPath, import.meta.url)) ? tsPath : jsPath;
7
+ const { handler: importedHandler } = await import(resolvedPath);
4
8
  return importedHandler(argv);
5
9
  };
6
10
  }
package/dist/lib/index.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  } from "@cedarjs/project-config";
26
26
  import { pluralize, singularize } from "@cedarjs/utils/cedarPluralize";
27
27
  import { addFileToRollback } from "./rollback.js";
28
- const nameVariants = (name) => {
28
+ function nameVariants(name) {
29
29
  const normalizedName = pascalcase(paramCase(singularize(name)));
30
30
  return {
31
31
  pascalName: pascalcase(paramCase(name)),
@@ -39,8 +39,8 @@ const nameVariants = (name) => {
39
39
  singularConstantName: decamelize(normalizedName).toUpperCase(),
40
40
  pluralConstantName: decamelize(pluralize(normalizedName)).toUpperCase()
41
41
  };
42
- };
43
- const generateTemplate = (templateFilename, { name, ...rest }) => {
42
+ }
43
+ function generateTemplate(templateFilename, { name, ...rest }) {
44
44
  try {
45
45
  const templateFn = template(readFile(templateFilename).toString());
46
46
  const renderedTemplate = templateFn({
@@ -50,19 +50,22 @@ const generateTemplate = (templateFilename, { name, ...rest }) => {
50
50
  });
51
51
  return prettify(templateFilename, renderedTemplate);
52
52
  } catch (error) {
53
- ;
54
- error.message = `Error applying template at ${templateFilename} for ${name}: ${error.message}`;
55
- throw error;
53
+ const originalMessage = error instanceof Error ? error.message : String(error);
54
+ const wrappedError = new Error(
55
+ `Error applying template at ${templateFilename} for ${name}: ` + originalMessage
56
+ );
57
+ throw wrappedError;
56
58
  }
57
- };
59
+ }
58
60
  const prettify = async (templateFilename, renderedTemplate) => {
59
- const parser = {
61
+ const parserMap = {
60
62
  ".css": "css",
61
63
  ".js": "babel",
62
64
  ".jsx": "babel",
63
65
  ".ts": "babel-ts",
64
66
  ".tsx": "babel-ts"
65
- }[path.extname(templateFilename.replace(".template", ""))];
67
+ };
68
+ const parser = parserMap[path.extname(templateFilename.replace(".template", ""))];
66
69
  if (typeof parser === "undefined") {
67
70
  return renderedTemplate;
68
71
  }
@@ -132,8 +135,10 @@ async function getInstalledCedarVersion() {
132
135
  try {
133
136
  const packageJson = await import("../../package.json", { with: { type: "json" } });
134
137
  return packageJson.default.version;
135
- } catch {
138
+ } catch (e) {
139
+ const message = e instanceof Error ? e.message : String(e);
136
140
  console.error(c.error("Could not find installed Cedar version"));
141
+ console.error(c.error(message));
137
142
  process.exit(1);
138
143
  }
139
144
  }
@@ -148,10 +153,19 @@ const _getPaths = () => {
148
153
  };
149
154
  const getPaths = memoize(_getPaths);
150
155
  const resolveFile = internalResolveFile;
151
- const getGraphqlPath = () => resolveFile(path.join(getPaths().api.functions, "graphql"));
156
+ const getGraphqlPath = () => {
157
+ const functionsDir = getPaths().api.functions;
158
+ if (!functionsDir) {
159
+ throw new Error("Could not resolve the API functions directory");
160
+ }
161
+ return resolveFile(path.join(functionsDir, "graphql"));
162
+ };
152
163
  const graphFunctionDoesExist = () => {
153
164
  const graphqlPath = getGraphqlPath();
154
- return graphqlPath ? fs.existsSync(graphqlPath) : false;
165
+ if (!graphqlPath) {
166
+ return false;
167
+ }
168
+ return fs.existsSync(graphqlPath);
155
169
  };
156
170
  const getConfig = () => {
157
171
  try {
@@ -209,10 +223,27 @@ const transformTSToJS = async (filename, content) => {
209
223
  ],
210
224
  retainLines: true
211
225
  });
212
- const code = result?.code ?? "";
213
- return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), code);
226
+ if (result?.code == null) {
227
+ throw new Error(
228
+ `Could not transform ${filename} from TypeScript to JavaScript`
229
+ );
230
+ }
231
+ return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), result.code);
214
232
  };
215
- const writeFilesTask = (files, options) => {
233
+ const transformTSToJSMap = async (files, typescript) => {
234
+ return files.reduce(
235
+ async (accP, [outputPath, content]) => {
236
+ const acc = await accP;
237
+ const template2 = typescript ? content : await transformTSToJS(outputPath, content);
238
+ return {
239
+ [outputPath]: template2,
240
+ ...acc
241
+ };
242
+ },
243
+ Promise.resolve({})
244
+ );
245
+ };
246
+ const writeFilesTask = (files, options = {}) => {
216
247
  const { base } = getPaths();
217
248
  return new Listr(
218
249
  Object.keys(files).map((file) => {
@@ -274,7 +305,7 @@ const cleanupEmptyDirsTask = (files) => {
274
305
  })
275
306
  );
276
307
  };
277
- const wrapWithSet = (routesContent, layout, routes, newLineAndIndent, props = {}) => {
308
+ function wrapWithSet(routesContent, layout, routes, newLineAndIndent, props = {}) {
278
309
  const [_, indentOne, indentTwo] = routesContent.match(
279
310
  /([ \t]*)<Router.*?>[^<]*[\r\n]+([ \t]+)/
280
311
  ) || ["", "", ""];
@@ -286,15 +317,17 @@ const wrapWithSet = (routesContent, layout, routes, newLineAndIndent, props = {}
286
317
  ...newRoutesWithExtraIndent,
287
318
  `</Set>`
288
319
  ].join(newLineAndIndent);
289
- };
320
+ }
290
321
  function addRoutesToRouterTask(routes, layout, setProps = {}) {
291
322
  const cedarPaths = getPaths();
292
323
  const routesContent = readFile(cedarPaths.web.routes).toString();
293
324
  let newRoutes = routes.filter((route) => !routesContent.match(route));
294
325
  if (newRoutes.length) {
295
- const [routerStart, routerParams, newLineAndIndent] = routesContent.match(
296
- /\s*<Router(.*?)>(\s*)/s
297
- );
326
+ const routerMatch = routesContent.match(/\s*<Router(.*?)>(\s*)/s);
327
+ if (!routerMatch) {
328
+ throw new Error("Could not find a <Router> element in the routes file");
329
+ }
330
+ const [routerStart, routerParams, newLineAndIndent] = routerMatch;
298
331
  if (/trailingSlashes={?(["'])always\1}?/.test(routerParams)) {
299
332
  newRoutes = newRoutes.map((route) => {
300
333
  if (route.length > 2e3) {
@@ -337,7 +370,9 @@ function removeEmtpySet(routesContent, layout) {
337
370
  const setWithLayoutReg = new RegExp(
338
371
  `\\s*<Set[^>]*wrap={${layout}}[^<]*>([^<]*)</Set>`
339
372
  );
340
- const [matchedSet, childContent] = routesContent.match(setWithLayoutReg) || [];
373
+ const match = routesContent.match(setWithLayoutReg);
374
+ const matchedSet = match?.[0] ?? "";
375
+ const childContent = match?.[1] ?? "";
341
376
  if (!matchedSet) {
342
377
  return routesContent;
343
378
  }
@@ -387,20 +422,22 @@ const addPackagesTask = async ({
387
422
  }
388
423
  };
389
424
  };
390
- const runCommandTask = async (commands, { verbose, silent }) => {
425
+ const runCommandTask = async (commands, { verbose, silent } = {}) => {
391
426
  const tasks = new Listr(
392
- commands.map(({ title, cmd, args, opts = {}, cwd = getPaths().base }) => ({
393
- title,
394
- task: async () => {
395
- return execa(cmd, args, {
396
- cwd,
397
- stdio: verbose && !silent ? "inherit" : "pipe",
398
- extendEnv: true,
399
- cleanup: true,
400
- ...opts
401
- });
402
- }
403
- })),
427
+ commands.map(
428
+ ({ title, cmd, args = [], opts = {}, cwd = getPaths().base }) => ({
429
+ title,
430
+ task: async () => {
431
+ return execa(cmd, args, {
432
+ cwd,
433
+ stdio: verbose && !silent ? "inherit" : "pipe",
434
+ extendEnv: true,
435
+ cleanup: true,
436
+ ...opts
437
+ });
438
+ }
439
+ })
440
+ ),
404
441
  {
405
442
  renderer: silent ? "silent" : verbose ? "verbose" : "default",
406
443
  rendererOptions: { collapseSubtasks: false }
@@ -410,7 +447,8 @@ const runCommandTask = async (commands, { verbose, silent }) => {
410
447
  await tasks.run();
411
448
  return true;
412
449
  } catch (e) {
413
- console.log(c.error(e.message));
450
+ const message = e instanceof Error ? e.message : String(e);
451
+ console.log(c.error(message));
414
452
  return false;
415
453
  }
416
454
  };
@@ -470,6 +508,7 @@ export {
470
508
  runCommandTask,
471
509
  saveRemoteFileToDisk,
472
510
  transformTSToJS,
511
+ transformTSToJSMap,
473
512
  usingVSCode,
474
513
  writeFile,
475
514
  writeFilesTask
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "5.0.0-canary.2482",
3
+ "version": "5.0.0-canary.2486",
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.2482",
37
- "@cedarjs/cli-helpers": "5.0.0-canary.2482",
38
- "@cedarjs/fastify-web": "5.0.0-canary.2482",
39
- "@cedarjs/internal": "5.0.0-canary.2482",
40
- "@cedarjs/prerender": "5.0.0-canary.2482",
41
- "@cedarjs/project-config": "5.0.0-canary.2482",
42
- "@cedarjs/structure": "5.0.0-canary.2482",
43
- "@cedarjs/telemetry": "5.0.0-canary.2482",
44
- "@cedarjs/utils": "5.0.0-canary.2482",
45
- "@cedarjs/vite": "5.0.0-canary.2482",
46
- "@cedarjs/web-server": "5.0.0-canary.2482",
36
+ "@cedarjs/api-server": "5.0.0-canary.2486",
37
+ "@cedarjs/cli-helpers": "5.0.0-canary.2486",
38
+ "@cedarjs/fastify-web": "5.0.0-canary.2486",
39
+ "@cedarjs/internal": "5.0.0-canary.2486",
40
+ "@cedarjs/prerender": "5.0.0-canary.2486",
41
+ "@cedarjs/project-config": "5.0.0-canary.2486",
42
+ "@cedarjs/structure": "5.0.0-canary.2486",
43
+ "@cedarjs/telemetry": "5.0.0-canary.2486",
44
+ "@cedarjs/utils": "5.0.0-canary.2486",
45
+ "@cedarjs/vite": "5.0.0-canary.2486",
46
+ "@cedarjs/web-server": "5.0.0-canary.2486",
47
47
  "@listr2/prompt-adapter-enquirer": "4.2.1",
48
48
  "@opentelemetry/api": "1.9.1",
49
49
  "@opentelemetry/core": "1.30.1",
@@ -101,7 +101,7 @@
101
101
  "ts-dedent": "2.2.0",
102
102
  "tsx": "4.21.0",
103
103
  "typescript": "5.9.3",
104
- "vitest": "3.2.4"
104
+ "vitest": "3.2.6"
105
105
  },
106
106
  "engines": {
107
107
  "node": ">=24"