@cedarjs/cli 9.0.0-canary.1784 → 9.0.0-canary.3124

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 (277) hide show
  1. package/README.md +7 -10
  2. package/dist/cfw.js +10 -6
  3. package/dist/commands/build/buildHandler.js +220 -45
  4. package/dist/commands/build/buildPackagesTask.js +21 -20
  5. package/dist/commands/build.js +13 -2
  6. package/dist/commands/check.js +4 -6
  7. package/dist/commands/console.js +6 -4
  8. package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
  9. package/dist/commands/deploy/baremetal/baremetalHandler.js +116 -50
  10. package/dist/commands/deploy/baremetal.js +11 -4
  11. package/dist/commands/deploy/flightcontrolHandler.js +28 -15
  12. package/dist/commands/deploy/helpers/deployHandler.js +11 -6
  13. package/dist/commands/deploy/netlify.js +1 -1
  14. package/dist/commands/deploy/packing/nft.js +1 -2
  15. package/dist/commands/deploy/render.js +1 -1
  16. package/dist/commands/deploy/renderHandler.js +24 -13
  17. package/dist/commands/deploy/serverlessHandler.js +69 -27
  18. package/dist/commands/deploy/vercel.js +1 -1
  19. package/dist/commands/destroy/component/component.js +2 -3
  20. package/dist/commands/destroy/directive/directive.js +1 -3
  21. package/dist/commands/destroy/directive/directiveHandler.js +2 -4
  22. package/dist/commands/destroy/function/function.js +1 -3
  23. package/dist/commands/destroy/handlerHelpers.js +17 -17
  24. package/dist/commands/destroy/helpers.js +8 -2
  25. package/dist/commands/destroy/layout/layout.js +1 -2
  26. package/dist/commands/destroy/page/pageHandler.js +3 -3
  27. package/dist/commands/destroy/scaffold/scaffoldHandler.js +31 -12
  28. package/dist/commands/destroy/sdl/sdlHandler.js +3 -3
  29. package/dist/commands/dev/apiDebugFlag.js +5 -4
  30. package/dist/commands/dev/devHandler.js +219 -68
  31. package/dist/commands/dev/packageWatchCommands.js +8 -3
  32. package/dist/commands/dev.js +16 -6
  33. package/dist/commands/execHandler.js +49 -29
  34. package/dist/commands/experimental/live-queries/liveQueries.js +32 -0
  35. package/dist/commands/experimental/live-queries/liveQueriesHandler.js +448 -0
  36. package/dist/commands/experimental/live-queries/templates/liveQueriesListener.ts.template +153 -0
  37. package/dist/commands/experimental/live-queries/templates/migration.sql.template +100 -0
  38. package/dist/commands/experimental/setupInngest.js +2 -2
  39. package/dist/commands/experimental/setupInngestHandler.js +13 -12
  40. package/dist/commands/experimental/setupOpentelemetry.js +2 -2
  41. package/dist/commands/experimental/setupOpentelemetryHandler.js +14 -10
  42. package/dist/commands/experimental/setupReactCompiler.js +2 -2
  43. package/dist/commands/experimental/setupReactCompilerHandler.js +48 -33
  44. package/dist/commands/experimental/setupRsc.js +1 -1
  45. package/dist/commands/experimental/setupRscHandler.js +20 -16
  46. package/dist/commands/experimental/setupStreamingSsr.js +2 -2
  47. package/dist/commands/experimental/setupStreamingSsrHandler.js +49 -34
  48. package/dist/commands/experimental/templates/opentelemetry.ts.template +2 -1
  49. package/dist/commands/experimental/templates/rsc/Document.tsx.template +1 -1
  50. package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +8 -8
  51. package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +1 -1
  52. package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +6 -6
  53. package/dist/commands/experimental/templates/streamingSsr/tsconfig.json.template +6 -6
  54. package/dist/commands/experimental/util.js +27 -25
  55. package/dist/commands/experimental.js +3 -2
  56. package/dist/commands/generate/cell/cell.js +20 -0
  57. package/dist/commands/generate/cell/cellHandler.js +89 -40
  58. package/dist/commands/generate/cell/templates/cell.tsx.template +21 -2
  59. package/dist/commands/generate/cell/templates/cellFragment.tsx.template +43 -0
  60. package/dist/commands/generate/cell/templates/cellList.tsx.template +21 -2
  61. package/dist/commands/generate/cell/templates/storiesFragment.tsx.template +23 -0
  62. package/dist/commands/generate/cell/templates/test.js.template +1 -1
  63. package/dist/commands/generate/cell/templates/testFragment.js.template +30 -0
  64. package/dist/commands/generate/component/componentHandler.js +14 -16
  65. package/dist/commands/generate/dataMigration/dataMigration.js +36 -18
  66. package/dist/commands/generate/dataMigration/templates/dataMigration.js.template +1 -1
  67. package/dist/commands/generate/dataMigration/templates/dataMigration.ts.template +1 -1
  68. package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
  69. package/dist/commands/generate/dbAuth/dbAuthHandler.js +63 -34
  70. package/dist/commands/generate/dbAuth/templates/login.oauth.tsx.template +164 -0
  71. package/dist/commands/generate/dbAuth/templates/signup.oauth.tsx.template +147 -0
  72. package/dist/commands/generate/directive/directiveHandler.js +14 -16
  73. package/dist/commands/generate/function/function.js +1 -0
  74. package/dist/commands/generate/function/functionHandler.js +14 -19
  75. package/dist/commands/generate/helpers.js +34 -18
  76. package/dist/commands/generate/job/job.js +1 -0
  77. package/dist/commands/generate/job/jobHandler.js +20 -24
  78. package/dist/commands/generate/layout/layoutHandler.js +13 -16
  79. package/dist/commands/generate/model/model.js +1 -0
  80. package/dist/commands/generate/model/modelHandler.js +11 -5
  81. package/dist/commands/generate/ogImage/ogImage.js +1 -0
  82. package/dist/commands/generate/ogImage/ogImageHandler.js +18 -11
  83. package/dist/commands/generate/package/filesTask.js +9 -0
  84. package/dist/commands/generate/package/packageHandler.js +50 -61
  85. package/dist/commands/generate/package/templates/test.ts.template +2 -2
  86. package/dist/commands/generate/package/templates/vitest.config.ts.template +9 -0
  87. package/dist/commands/generate/page/pageHandler.js +27 -24
  88. package/dist/commands/generate/realtime/realtime.js +2 -2
  89. package/dist/commands/generate/realtime/realtimeHandler.js +51 -32
  90. package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +1 -1
  91. package/dist/commands/generate/scaffold/scaffold.js +1 -0
  92. package/dist/commands/generate/scaffold/scaffoldHandler.js +176 -49
  93. package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +1 -1
  94. package/dist/commands/generate/script/script.js +1 -0
  95. package/dist/commands/generate/script/scriptHandler.js +10 -6
  96. package/dist/commands/generate/script/templates/script.ts.template +9 -4
  97. package/dist/commands/generate/script/templates/tsconfig.json.template +16 -2
  98. package/dist/commands/generate/sdl/sdl.js +4 -3
  99. package/dist/commands/generate/sdl/sdlHandler.js +135 -46
  100. package/dist/commands/generate/sdl/stubFiles.js +132 -0
  101. package/dist/commands/generate/sdl/templates/sdl.js.template +2 -1
  102. package/dist/commands/generate/sdl/templates/sdl.ts.template +2 -1
  103. package/dist/commands/generate/secret/secret.js +20 -20
  104. package/dist/commands/generate/service/service.js +5 -5
  105. package/dist/commands/generate/service/serviceHandler.js +126 -61
  106. package/dist/commands/generate/service/templates/scenarios.ts.template +4 -2
  107. package/dist/commands/generate/service/templates/service.ts.template +22 -8
  108. package/dist/commands/generate/service/templates/test.ts.template +2 -2
  109. package/dist/commands/generate/yargsCommandHelpers.js +7 -2
  110. package/dist/commands/generate/yargsHandlerHelpers.js +20 -18
  111. package/dist/commands/generate.js +4 -4
  112. package/dist/commands/info.js +2 -2
  113. package/dist/commands/jobsHandler.js +7 -4
  114. package/dist/commands/lint.js +26 -69
  115. package/dist/commands/prerenderHandler.js +95 -58
  116. package/dist/commands/prismaHandler.js +51 -26
  117. package/dist/commands/record/init.js +2 -2
  118. package/dist/commands/record.js +4 -3
  119. package/dist/commands/serve.js +245 -31
  120. package/dist/commands/serveApiHandler.js +7 -6
  121. package/dist/commands/serveBothHandler.js +22 -13
  122. package/dist/commands/serveWebHandler.js +3 -2
  123. package/dist/commands/setup/auth/auth.js +15 -11
  124. package/dist/commands/setup/cache/cache.js +1 -1
  125. package/dist/commands/setup/cache/cacheHandler.js +15 -9
  126. package/dist/commands/setup/database/database.js +15 -0
  127. package/dist/commands/setup/database/postgres.js +19 -0
  128. package/dist/commands/setup/database/postgresHandler.js +196 -0
  129. package/dist/commands/setup/database/templates/db.ts.template +32 -0
  130. package/dist/commands/setup/deploy/deploy.js +4 -3
  131. package/dist/commands/setup/deploy/helpers/helpers.js +5 -1
  132. package/dist/commands/setup/deploy/helpers/index.js +132 -6
  133. package/dist/commands/setup/deploy/providers/baremetalHandler.js +28 -6
  134. package/dist/commands/setup/deploy/providers/coherence.js +1 -1
  135. package/dist/commands/setup/deploy/providers/coherenceHandler.js +60 -31
  136. package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +69 -51
  137. package/dist/commands/setup/deploy/providers/netlify.js +6 -0
  138. package/dist/commands/setup/deploy/providers/netlifyHandler.js +114 -13
  139. package/dist/commands/setup/deploy/providers/renderHandler.js +44 -41
  140. package/dist/commands/setup/deploy/providers/serverlessHandler.js +7 -5
  141. package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
  142. package/dist/commands/setup/deploy/providers/universalDeployHandler.js +186 -0
  143. package/dist/commands/setup/deploy/providers/vercel.js +6 -0
  144. package/dist/commands/setup/deploy/providers/vercelHandler.js +115 -14
  145. package/dist/commands/setup/deploy/templates/baremetal.js +3 -2
  146. package/dist/commands/setup/deploy/templates/flightcontrol.js +60 -49
  147. package/dist/commands/setup/deploy/templates/netlify.js +2 -1
  148. package/dist/commands/setup/deploy/templates/netlifyUD.js +31 -0
  149. package/dist/commands/setup/deploy/templates/render.js +32 -17
  150. package/dist/commands/setup/docker/docker.js +2 -2
  151. package/dist/commands/setup/docker/dockerHandler.js +74 -39
  152. package/dist/commands/setup/docker/templates/Dockerfile.npm +119 -0
  153. package/dist/commands/setup/docker/templates/Dockerfile.pnpm +112 -0
  154. package/dist/commands/setup/docker/templates/{Dockerfile → Dockerfile.yarn} +4 -7
  155. package/dist/commands/setup/docker/templates/docker-compose.dev.yml +3 -3
  156. package/dist/commands/setup/docker/templates/docker-compose.prod.yml +2 -5
  157. package/dist/commands/setup/docker/templates/dockerignore +1 -0
  158. package/dist/commands/setup/generator/generator.js +1 -1
  159. package/dist/commands/setup/generator/generatorHandler.js +5 -4
  160. package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +6 -3
  161. package/dist/commands/setup/graphql/features/fragments/fragments.js +1 -1
  162. package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +5 -7
  163. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +1 -1
  164. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +4 -3
  165. package/dist/commands/setup/i18n/i18n.js +1 -1
  166. package/dist/commands/setup/i18n/i18nHandler.js +21 -17
  167. package/dist/commands/setup/jobs/jobs.js +1 -1
  168. package/dist/commands/setup/jobs/jobsHandler.js +17 -12
  169. package/dist/commands/setup/mailer/mailer.js +1 -1
  170. package/dist/commands/setup/mailer/mailerHandler.js +13 -11
  171. package/dist/commands/setup/middleware/ogImage/ogImage.js +1 -1
  172. package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +2 -1
  173. package/dist/commands/setup/monitoring/sentry/sentry.js +1 -1
  174. package/dist/commands/setup/monitoring/sentry/sentryHandler.js +18 -12
  175. package/dist/commands/setup/neon/neon.js +35 -0
  176. package/dist/commands/setup/neon/neonHandler.js +264 -0
  177. package/dist/commands/setup/package/package.js +1 -1
  178. package/dist/commands/setup/package/packageHandler.js +18 -14
  179. package/dist/commands/setup/realtime/addRealtimeToGraphql.js +1 -1
  180. package/dist/commands/setup/realtime/realtime.js +1 -1
  181. package/dist/commands/setup/realtime/realtimeHandler.js +26 -37
  182. package/dist/commands/setup/realtime/templates/realtime.ts.template +1 -1
  183. package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +1 -1
  184. package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +1 -1
  185. package/dist/commands/setup/server-file/serverFile.js +1 -1
  186. package/dist/commands/setup/server-file/serverFileHandler.js +18 -10
  187. package/dist/commands/setup/tenancy/authCodemod.js +66 -0
  188. package/dist/commands/setup/tenancy/dbCodemod.js +64 -0
  189. package/dist/commands/setup/tenancy/graphqlCodemod.js +88 -0
  190. package/dist/commands/setup/tenancy/preflight.js +49 -0
  191. package/dist/commands/setup/tenancy/schemaPrisma.js +81 -0
  192. package/dist/commands/setup/tenancy/signupCodemod.js +153 -0
  193. package/dist/commands/setup/tenancy/templates/InvitePage.tsx.template +63 -0
  194. package/dist/commands/setup/tenancy/templates/OrgScope.tsx.template +40 -0
  195. package/dist/commands/setup/tenancy/templates/ensureDefaultOrganizations.dataMigration.ts.template +39 -0
  196. package/dist/commands/setup/tenancy/templates/organizations.scenarios.ts.template +59 -0
  197. package/dist/commands/setup/tenancy/templates/organizations.sdl.ts.template +89 -0
  198. package/dist/commands/setup/tenancy/templates/organizations.test.ts.template +389 -0
  199. package/dist/commands/setup/tenancy/templates/organizations.ts.template +394 -0
  200. package/dist/commands/setup/tenancy/templates/requireMembership.test.ts.template +35 -0
  201. package/dist/commands/setup/tenancy/templates/requireMembership.ts.template +25 -0
  202. package/dist/commands/setup/tenancy/tenancy.js +30 -0
  203. package/dist/commands/setup/tenancy/tenancyHandler.js +425 -0
  204. package/dist/commands/setup/ui/helpers/helpers.js +5 -1
  205. package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +16 -8
  206. package/dist/commands/setup/ui/libraries/mantineHandler.js +26 -16
  207. package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +40 -29
  208. package/dist/commands/setup/uploads/schemaPrisma.js +41 -0
  209. package/dist/commands/setup/uploads/serverFile.js +151 -0
  210. package/dist/commands/setup/uploads/templates/requireUploadToken.ts.template +15 -0
  211. package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +23 -24
  212. package/dist/commands/setup/uploads/templates/uploads.sdl.ts.template +79 -0
  213. package/dist/commands/setup/uploads/templates/uploads.ts.template +89 -0
  214. package/dist/commands/setup/uploads/templates/withDataUri.ts.template +14 -0
  215. package/dist/commands/setup/uploads/templates/withSignedUrl.ts.template +16 -0
  216. package/dist/commands/setup/uploads/uploads.js +49 -7
  217. package/dist/commands/setup/uploads/uploadsHandler.js +266 -72
  218. package/dist/commands/setup.js +5 -4
  219. package/dist/commands/studio.js +1 -1
  220. package/dist/commands/studioHandler.js +2 -2
  221. package/dist/commands/test/datasourceWarning.js +42 -0
  222. package/dist/commands/test/testHandler.js +104 -0
  223. package/dist/commands/test/viteVersionCheck.js +75 -0
  224. package/dist/commands/test.js +16 -19
  225. package/dist/commands/type-check.js +2 -1
  226. package/dist/commands/type-checkHandler.js +25 -18
  227. package/dist/commands/upgrade/preUpgradeScripts.js +11 -11
  228. package/dist/commands/upgrade/upgrade.js +4 -2
  229. package/dist/commands/upgrade/upgradeHandler.js +97 -73
  230. package/dist/index.js +15 -11
  231. package/dist/lib/background.js +22 -1
  232. package/dist/lib/configureStorybook.js +2 -2
  233. package/dist/lib/exec.js +68 -63
  234. package/dist/lib/exit.js +20 -5
  235. package/dist/lib/extendFile.js +23 -13
  236. package/dist/lib/generatePrismaClient.js +48 -12
  237. package/dist/lib/index.js +137 -106
  238. package/dist/lib/loadEnvFiles.js +1 -1
  239. package/dist/lib/locking.js +8 -4
  240. package/dist/lib/merge/algorithms.js +4 -1
  241. package/dist/lib/merge/index.js +78 -41
  242. package/dist/lib/merge/semanticIdentity.js +18 -6
  243. package/dist/lib/merge/strategy.js +86 -36
  244. package/dist/lib/packages.js +23 -13
  245. package/dist/lib/plugin.js +13 -7
  246. package/dist/lib/pluralHelpers.js +6 -2
  247. package/dist/lib/project.js +3 -1
  248. package/dist/lib/rollback.js +7 -7
  249. package/dist/lib/schemaHelpers.js +16 -19
  250. package/dist/lib/test.js +20 -5
  251. package/dist/lib/updateCheck.js +47 -18
  252. package/dist/middleware/checkNodeVersion.js +9 -4
  253. package/dist/middleware/{detectProjectRxVersion.js → detectProjectCedarVersion.js} +2 -2
  254. package/dist/plugin.js +18 -12
  255. package/dist/telemetry/exporter.js +12 -5
  256. package/dist/telemetry/index.js +4 -3
  257. package/dist/telemetry/resource.js +9 -12
  258. package/dist/telemetry/send.js +14 -10
  259. package/dist/testLib/cells.js +5 -3
  260. package/package.json +44 -41
  261. package/LICENSE +0 -21
  262. package/dist/commands/consoleHandler.js +0 -68
  263. package/dist/commands/setup/tsconfig/tsconfig.js +0 -25
  264. package/dist/commands/setup/tsconfig/tsconfigHandler.js +0 -59
  265. package/dist/commands/setup/uploads/dbCodemod.js +0 -28
  266. package/dist/commands/setup/uploads/templates/signedUrl.ts.template +0 -21
  267. package/dist/commands/setup/vite/templates/vite.config.ts.template +0 -19
  268. package/dist/commands/setup/vite/vite.js +0 -38
  269. package/dist/commands/setup/vite/viteHandler.js +0 -83
  270. package/dist/commands/testEsm.js +0 -36
  271. package/dist/commands/testHandler.js +0 -137
  272. package/dist/commands/testHandlerEsm.js +0 -85
  273. package/dist/commands/ts-to-js.js +0 -20
  274. package/dist/lib/cedarPluralize.js +0 -56
  275. package/dist/lib/colors.js +0 -18
  276. package/dist/testLib/getFilesWithPattern.js +0 -21
  277. /package/dist/{index.d.js → global.d.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  import fs from "node:fs";
2
- function fileIncludes(path, str) {
3
- return fs.existsSync(path) && fs.readFileSync(path).toString().includes(str);
2
+ function fileIncludes(filePath, str) {
3
+ return fs.existsSync(filePath) && fs.readFileSync(filePath).toString().includes(str);
4
4
  }
5
- function extendJSXFile(path, {
5
+ function extendJSXFile(filePath, {
6
6
  insertComponent: {
7
7
  name = void 0,
8
8
  props = void 0,
@@ -14,7 +14,7 @@ function extendJSXFile(path, {
14
14
  imports = [],
15
15
  moduleScopeLines = []
16
16
  }) {
17
- const content = fs.readFileSync(path).toString().split("\n");
17
+ const content = fs.readFileSync(filePath).toString().split("\n");
18
18
  if (moduleScopeLines?.length) {
19
19
  content.splice(
20
20
  content.findLastIndex((l) => l.trimStart().startsWith("import")) + 1,
@@ -41,15 +41,22 @@ function extendJSXFile(path, {
41
41
  insertAfter
42
42
  });
43
43
  }
44
- fs.writeFileSync(path, content.filter((e) => e !== void 0).join("\n"));
44
+ fs.writeFileSync(filePath, content.join("\n"));
45
45
  }
46
- function insertComponent(content, { component, props, around, within, insertBefore, insertAfter }) {
46
+ function insertComponent(content, {
47
+ component,
48
+ props,
49
+ around,
50
+ within,
51
+ insertBefore,
52
+ insertAfter
53
+ }) {
47
54
  if (around && within || !(around || within)) {
48
55
  throw new Error(
49
56
  "Exactly one of (around | within) must be defined. Choose one."
50
57
  );
51
58
  }
52
- const target = around ?? within;
59
+ const target = `(?:${around ?? within})`;
53
60
  const findTagIndex = (regex) => content.findIndex((line) => regex.test(line));
54
61
  let open = findTagIndex(new RegExp(`([^\\S\r
55
62
  ]*)<${target}\\s*(.*)\\s*>`));
@@ -62,16 +69,16 @@ function insertComponent(content, { component, props, around, within, insertBefo
62
69
  open++;
63
70
  close--;
64
71
  }
65
- const [, componentDepth] = content[open].match(/([^\S\r\n]*).*/);
72
+ const depthMatch = content[open].match(/([^\S\r\n]*).*/);
73
+ const componentDepth = depthMatch?.[1] ?? "";
66
74
  content.splice(
67
75
  open,
68
76
  close - open,
69
- // "Delete" the wrapped component contents. We put it back below.
70
- insertBefore && componentDepth + insertBefore,
77
+ ...insertBefore ? [componentDepth + insertBefore] : [],
71
78
  componentDepth + buildOpeningTag(component, props),
72
79
  ...content.slice(open, close).map((line) => " " + line),
73
80
  componentDepth + `</${component}>`,
74
- insertAfter && componentDepth + insertAfter
81
+ ...insertAfter ? [componentDepth + insertAfter] : []
75
82
  );
76
83
  }
77
84
  function buildOpeningTag(componentName, props) {
@@ -92,11 +99,14 @@ function buildOpeningTag(componentName, props) {
92
99
  const possibleSpace = propsString.length ? " " : "";
93
100
  return `<${componentName}${possibleSpace}${propsString}>`;
94
101
  }
95
- function objectToComponentProps(obj, options = { exclude: [], raw: false }) {
102
+ function objectToComponentProps(obj, options = {
103
+ exclude: [],
104
+ raw: false
105
+ }) {
96
106
  const props = [];
97
107
  const doRaw = (key) => options.raw === true || Array.isArray(options.raw) && options.raw.includes(key);
98
108
  for (const [key, value] of Object.entries(obj)) {
99
- if (options.exclude && options.exclude.includes(key)) {
109
+ if (options.exclude?.includes(key)) {
100
110
  continue;
101
111
  }
102
112
  if (doRaw(key)) {
@@ -1,8 +1,11 @@
1
+ import { createHash } from "node:crypto";
1
2
  import fs from "node:fs";
2
3
  import { createRequire } from "node:module";
3
4
  import path from "node:path";
4
- import { runCommandTask, getPaths } from "../lib/index.js";
5
+ import { getConfig, getPrismaSchemas } from "@cedarjs/project-config";
6
+ import { runCommandTask, getPaths } from "./index.js";
5
7
  const generatePrismaCommand = async () => {
8
+ const config = getConfig();
6
9
  const createdRequire = createRequire(import.meta.url);
7
10
  const prismaIndexPath = createdRequire.resolve("prisma/build/index.js");
8
11
  return {
@@ -10,22 +13,52 @@ const generatePrismaCommand = async () => {
10
13
  args: [
11
14
  prismaIndexPath,
12
15
  "generate",
13
- `--config=${getPaths().api.prismaConfig}`
16
+ `--config=${getPaths().api.prismaConfig}`,
17
+ ...config.api.prismaGenerateArgs
14
18
  ]
15
19
  };
16
20
  };
17
- const generatePrismaClient = async ({
21
+ async function computePrismaSchemaHash() {
22
+ try {
23
+ const hash = createHash("sha256");
24
+ const configPath = getPaths().api.prismaConfig;
25
+ if (fs.existsSync(configPath)) {
26
+ hash.update(fs.readFileSync(configPath));
27
+ }
28
+ const { schemas } = await getPrismaSchemas();
29
+ for (const schema of schemas) {
30
+ hash.update(schema[1]);
31
+ }
32
+ return hash.digest("hex");
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+ function getHashFilePath() {
38
+ const generatedBase = getPaths().generated.base;
39
+ return path.join(generatedBase, "prisma-schema-hash");
40
+ }
41
+ function getStoredSchemaHash() {
42
+ const hashFile = getHashFilePath();
43
+ if (fs.existsSync(hashFile)) {
44
+ return fs.readFileSync(hashFile, "utf-8").trim();
45
+ }
46
+ return null;
47
+ }
48
+ function storeSchemaHash(hash) {
49
+ const hashFile = getHashFilePath();
50
+ fs.mkdirSync(path.dirname(hashFile), { recursive: true });
51
+ fs.writeFileSync(hashFile, hash);
52
+ }
53
+ async function generatePrismaClient({
18
54
  verbose = true,
19
- force = true,
55
+ force = false,
20
56
  silent = false
21
- }) => {
57
+ } = {}) {
58
+ const hash = await computePrismaSchemaHash();
22
59
  if (!force) {
23
- const prismaClientPath = path.join(
24
- getPaths().base,
25
- "node_modules/.prisma/client/index.js"
26
- );
27
- const prismaClientFile = fs.readFileSync(prismaClientPath, "utf8");
28
- if (!prismaClientFile.includes("@prisma/client did not initialize yet.") && prismaClientFile.includes("exports.Prisma.")) {
60
+ const storedHash = hash ? getStoredSchemaHash() : null;
61
+ if (hash !== null && hash === storedHash) {
29
62
  return;
30
63
  }
31
64
  }
@@ -41,7 +74,10 @@ const generatePrismaClient = async ({
41
74
  silent
42
75
  }
43
76
  );
44
- };
77
+ if (hash !== null) {
78
+ storeSchemaHash(hash);
79
+ }
80
+ }
45
81
  export {
46
82
  generatePrismaClient,
47
83
  generatePrismaCommand
package/dist/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
- import https from "https";
2
1
  import fs from "node:fs";
3
- import path from "path";
4
- import * as babel from "@babel/core";
2
+ import https from "node:https";
3
+ import path from "node:path";
5
4
  import boxen from "boxen";
6
5
  import camelcase from "camelcase";
7
6
  import { paramCase } from "change-case";
@@ -12,16 +11,21 @@ import memoize from "lodash/memoize.js";
12
11
  import template from "lodash/template.js";
13
12
  import pascalcase from "pascalcase";
14
13
  import { format } from "prettier";
14
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
15
15
  import {
16
- getConfig as getRedwoodConfig,
17
- getPaths as getRedwoodPaths,
16
+ addRootPackages,
17
+ addWorkspacePackages
18
+ } from "@cedarjs/cli-helpers/packageManager/packages";
19
+ import { transpileTSToJS } from "@cedarjs/cli-helpers/transpileTSToJS";
20
+ import {
21
+ getConfig as getCedarConfig,
22
+ getPaths as getCedarPaths,
18
23
  resolveFile as internalResolveFile,
19
24
  findUp
20
25
  } from "@cedarjs/project-config";
21
- import { pluralize, singularize } from "./cedarPluralize.js";
22
- import c from "./colors.js";
26
+ import { pluralize, singularize } from "@cedarjs/utils/cedarPluralize";
23
27
  import { addFileToRollback } from "./rollback.js";
24
- const nameVariants = (name) => {
28
+ function nameVariants(name) {
25
29
  const normalizedName = pascalcase(paramCase(singularize(name)));
26
30
  return {
27
31
  pascalName: pascalcase(paramCase(name)),
@@ -35,8 +39,8 @@ const nameVariants = (name) => {
35
39
  singularConstantName: decamelize(normalizedName).toUpperCase(),
36
40
  pluralConstantName: decamelize(pluralize(normalizedName)).toUpperCase()
37
41
  };
38
- };
39
- const generateTemplate = (templateFilename, { name, ...rest }) => {
42
+ }
43
+ function generateTemplate(templateFilename, { name, ...rest }) {
40
44
  try {
41
45
  const templateFn = template(readFile(templateFilename).toString());
42
46
  const renderedTemplate = templateFn({
@@ -46,18 +50,22 @@ const generateTemplate = (templateFilename, { name, ...rest }) => {
46
50
  });
47
51
  return prettify(templateFilename, renderedTemplate);
48
52
  } catch (error) {
49
- error.message = `Error applying template at ${templateFilename} for ${name}: ${error.message}`;
50
- 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;
51
58
  }
52
- };
59
+ }
53
60
  const prettify = async (templateFilename, renderedTemplate) => {
54
- const parser = {
61
+ const parserMap = {
55
62
  ".css": "css",
56
63
  ".js": "babel",
57
64
  ".jsx": "babel",
58
65
  ".ts": "babel-ts",
59
66
  ".tsx": "babel-ts"
60
- }[path.extname(templateFilename.replace(".template", ""))];
67
+ };
68
+ const parser = parserMap[path.extname(templateFilename.replace(".template", ""))];
61
69
  if (typeof parser === "undefined") {
62
70
  return renderedTemplate;
63
71
  }
@@ -128,30 +136,43 @@ async function getInstalledCedarVersion() {
128
136
  const packageJson = await import("../../package.json", { with: { type: "json" } });
129
137
  return packageJson.default.version;
130
138
  } catch (e) {
139
+ const message = e instanceof Error ? e.message : String(e);
131
140
  console.error(c.error("Could not find installed Cedar version"));
141
+ console.error(c.error(message));
132
142
  process.exit(1);
133
143
  }
134
144
  }
135
- const bytes = (contents) => Buffer.byteLength(contents, "utf8");
136
145
  const _getPaths = () => {
137
146
  try {
138
- return getRedwoodPaths();
147
+ return getCedarPaths();
139
148
  } catch (e) {
140
- console.error(c.error(e.message));
149
+ const message = e instanceof Error ? e.message : String(e);
150
+ console.error(c.error(message));
141
151
  process.exit(1);
142
152
  }
143
153
  };
144
154
  const getPaths = memoize(_getPaths);
145
155
  const resolveFile = internalResolveFile;
146
- 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
+ };
147
163
  const graphFunctionDoesExist = () => {
148
- return fs.existsSync(getGraphqlPath());
164
+ const graphqlPath = getGraphqlPath();
165
+ if (!graphqlPath) {
166
+ return false;
167
+ }
168
+ return fs.existsSync(graphqlPath);
149
169
  };
150
170
  const getConfig = () => {
151
171
  try {
152
- return getRedwoodConfig();
172
+ return getCedarConfig();
153
173
  } catch (e) {
154
- console.error(c.error(e.message));
174
+ const message = e instanceof Error ? e.message : String(e);
175
+ console.error(c.error(message));
155
176
  process.exit(1);
156
177
  }
157
178
  };
@@ -162,7 +183,7 @@ const getPrettierOptions = async () => {
162
183
  const prettierConfigPath = fs.existsSync(cjsPath) ? cjsPath : mjsPath;
163
184
  const { default: prettierOptions } = await import(`file://${prettierConfigPath}`);
164
185
  return prettierOptions;
165
- } catch (e) {
186
+ } catch {
166
187
  if (process.env.VITEST_POOL_ID !== void 0) {
167
188
  return {
168
189
  trailingComma: "es5",
@@ -185,33 +206,32 @@ const getPrettierOptions = async () => {
185
206
  }
186
207
  };
187
208
  const transformTSToJS = async (filename, content) => {
188
- const { code } = babel.transform(content, {
189
- filename,
190
- // If you ran `yarn cedar generate` in `./web` transformSync would import the `.babelrc.js` file,
191
- // in `./web`? despite us setting `configFile: false`.
192
- cwd: process.env.NODE_ENV === "test" ? void 0 : getPaths().base,
193
- configFile: false,
194
- plugins: [
195
- [
196
- "@babel/plugin-transform-typescript",
197
- {
198
- isTSX: true,
199
- allExtensions: true
200
- }
201
- ]
202
- ],
203
- retainLines: true
204
- });
205
- return prettify(filename.replace(/\.ts(x)?$/, ".js$1"), code);
209
+ return prettify(
210
+ filename.replace(/\.ts(x)?$/, ".js$1"),
211
+ transpileTSToJS(filename, content)
212
+ );
213
+ };
214
+ const transformTSToJSMap = async (files, typescript) => {
215
+ return files.reduce(
216
+ async (accP, [outputPath, content]) => {
217
+ const acc = await accP;
218
+ const template2 = typescript ? content : await transformTSToJS(outputPath, content);
219
+ return {
220
+ [outputPath]: template2,
221
+ ...acc
222
+ };
223
+ },
224
+ Promise.resolve({})
225
+ );
206
226
  };
207
- const writeFilesTask = (files, options) => {
227
+ const writeFilesTask = (files, options = {}) => {
208
228
  const { base } = getPaths();
209
229
  return new Listr(
210
230
  Object.keys(files).map((file) => {
211
231
  const contents = files[file];
212
232
  return {
213
233
  title: `...waiting to write file \`./${path.relative(base, file)}\`...`,
214
- task: (ctx, task) => writeFile(file, contents, options, task)
234
+ task: (_ctx, task) => writeFile(file, contents, options, task)
215
235
  };
216
236
  })
217
237
  );
@@ -266,27 +286,44 @@ const cleanupEmptyDirsTask = (files) => {
266
286
  })
267
287
  );
268
288
  };
269
- const wrapWithSet = (routesContent, layout, routes, newLineAndIndent, props = {}) => {
289
+ function wrapWithSet(routesContent, layout, routes, newLineAndIndent, props = {}, privateSetProps) {
270
290
  const [_, indentOne, indentTwo] = routesContent.match(
271
291
  /([ \t]*)<Router.*?>[^<]*[\r\n]+([ \t]+)/
272
- ) || ["", 0, 2];
292
+ ) || ["", "", ""];
273
293
  const oneLevelIndent = indentTwo.slice(0, indentTwo.length - indentOne.length);
274
- const newRoutesWithExtraIndent = routes.map((route) => oneLevelIndent + route);
275
294
  const propsString = Object.entries(props).map((values) => `${values[0]}="${values[1]}"`).join(" ");
295
+ if (!privateSetProps) {
296
+ const newRoutesWithExtraIndent2 = routes.map(
297
+ (route) => oneLevelIndent + route
298
+ );
299
+ return [
300
+ `<Set wrap={${layout}}${propsString && " " + propsString}>`,
301
+ ...newRoutesWithExtraIndent2,
302
+ `</Set>`
303
+ ].join(newLineAndIndent);
304
+ }
305
+ const privateSetPropsString = Object.entries(privateSetProps).map((values) => `${values[0]}="${values[1]}"`).join(" ");
306
+ const newRoutesWithExtraIndent = routes.map(
307
+ (route) => oneLevelIndent + oneLevelIndent + route
308
+ );
276
309
  return [
277
- `<Set wrap={${layout}}${propsString && " " + propsString}>`,
310
+ `<PrivateSet${privateSetPropsString && " " + privateSetPropsString}>`,
311
+ `${oneLevelIndent}<Set wrap={${layout}}${propsString && " " + propsString}>`,
278
312
  ...newRoutesWithExtraIndent,
279
- `</Set>`
313
+ `${oneLevelIndent}</Set>`,
314
+ `</PrivateSet>`
280
315
  ].join(newLineAndIndent);
281
- };
282
- const addRoutesToRouterTask = (routes, layout, setProps = {}) => {
283
- const redwoodPaths = getPaths();
284
- const routesContent = readFile(redwoodPaths.web.routes).toString();
316
+ }
317
+ function addRoutesToRouterTask(routes, layout, setProps = {}, privateSetProps) {
318
+ const cedarPaths = getPaths();
319
+ const routesContent = readFile(cedarPaths.web.routes).toString();
285
320
  let newRoutes = routes.filter((route) => !routesContent.match(route));
286
321
  if (newRoutes.length) {
287
- const [routerStart, routerParams, newLineAndIndent] = routesContent.match(
288
- /\s*<Router(.*?)>(\s*)/s
289
- );
322
+ const routerMatch = routesContent.match(/\s*<Router(.*?)>(\s*)/s);
323
+ if (!routerMatch) {
324
+ throw new Error("Could not find a <Router> element in the routes file");
325
+ }
326
+ const [routerStart, routerParams, newLineAndIndent] = routerMatch;
290
327
  if (/trailingSlashes={?(["'])always\1}?/.test(routerParams)) {
291
328
  newRoutes = newRoutes.map((route) => {
292
329
  if (route.length > 2e3) {
@@ -301,17 +338,18 @@ ${route}`);
301
338
  layout,
302
339
  newRoutes,
303
340
  newLineAndIndent,
304
- setProps
341
+ setProps,
342
+ privateSetProps
305
343
  ) : newRoutes.join(newLineAndIndent);
306
344
  const newRoutesContent = routesContent.replace(
307
345
  routerStart,
308
346
  `${routerStart + routesBatch + newLineAndIndent}`
309
347
  );
310
- writeFile(redwoodPaths.web.routes, newRoutesContent, {
348
+ writeFile(cedarPaths.web.routes, newRoutesContent, {
311
349
  overwriteExisting: true
312
350
  });
313
351
  }
314
- };
352
+ }
315
353
  const addScaffoldImport = () => {
316
354
  const appJsPath = getPaths().web.app;
317
355
  let appJsContents = readFile(appJsPath).toString();
@@ -325,11 +363,13 @@ const addScaffoldImport = () => {
325
363
  writeFile(appJsPath, appJsContents, { overwriteExisting: true });
326
364
  return "Added scaffold import to App.{jsx,tsx}";
327
365
  };
328
- const removeEmtpySet = (routesContent, layout) => {
366
+ function removeEmtpySet(routesContent, layout) {
329
367
  const setWithLayoutReg = new RegExp(
330
368
  `\\s*<Set[^>]*wrap={${layout}}[^<]*>([^<]*)</Set>`
331
369
  );
332
- const [matchedSet, childContent] = routesContent.match(setWithLayoutReg) || [];
370
+ const match = routesContent.match(setWithLayoutReg);
371
+ const matchedSet = match?.[0] ?? "";
372
+ const childContent = match?.[1] ?? "";
333
373
  if (!matchedSet) {
334
374
  return routesContent;
335
375
  }
@@ -338,19 +378,19 @@ const removeEmtpySet = (routesContent, layout) => {
338
378
  return routesContent;
339
379
  }
340
380
  return routesContent.replace(setWithLayoutReg, "");
341
- };
342
- const removeRoutesFromRouterTask = (routes, layout) => {
343
- const redwoodPaths = getPaths();
344
- const routesContent = readFile(redwoodPaths.web.routes).toString();
381
+ }
382
+ function removeRoutesFromRouterTask(routes, layout) {
383
+ const cedarPaths = getPaths();
384
+ const routesContent = readFile(cedarPaths.web.routes).toString();
345
385
  const newRoutesContent = routes.reduce((content, route) => {
346
386
  const matchRouteByName = new RegExp(`\\s*<Route[^>]*name="${route}"[^>]*/>`);
347
387
  return content.replace(matchRouteByName, "");
348
388
  }, routesContent);
349
389
  const routesWithoutEmptySet = layout ? removeEmtpySet(newRoutesContent, layout) : newRoutesContent;
350
- writeFile(redwoodPaths.web.routes, routesWithoutEmptySet, {
390
+ writeFile(cedarPaths.web.routes, routesWithoutEmptySet, {
351
391
  overwriteExisting: true
352
392
  });
353
- };
393
+ }
354
394
  const addPackagesTask = async ({
355
395
  packages,
356
396
  side = "project",
@@ -364,57 +404,48 @@ const addPackagesTask = async ({
364
404
  return pkg;
365
405
  }
366
406
  });
367
- let installCommand;
368
- if (side !== "project") {
369
- installCommand = [
370
- "yarn",
371
- [
372
- "workspace",
373
- side,
374
- "add",
375
- devDependency && "--dev",
376
- ...packagesWithSameRWVersion
377
- ].filter(Boolean)
378
- ];
379
- } else {
380
- installCommand = [
381
- "yarn",
382
- ["add", devDependency && "--dev", ...packagesWithSameRWVersion].filter(
383
- Boolean
384
- )
385
- ];
386
- }
387
407
  return {
388
408
  title: `Adding dependencies to ${side}`,
389
409
  task: async () => {
390
- await execa(...installCommand);
410
+ if (side !== "project") {
411
+ await addWorkspacePackages(side, packagesWithSameRWVersion, {
412
+ dev: devDependency
413
+ });
414
+ } else {
415
+ await addRootPackages(packagesWithSameRWVersion, {
416
+ dev: devDependency
417
+ });
418
+ }
391
419
  }
392
420
  };
393
421
  };
394
- const runCommandTask = async (commands, { verbose, silent }) => {
422
+ const runCommandTask = async (commands, { verbose, silent } = {}) => {
395
423
  const tasks = new Listr(
396
- commands.map(({ title, cmd, args, opts = {}, cwd = getPaths().base }) => ({
397
- title,
398
- task: async () => {
399
- return execa(cmd, args, {
400
- cwd,
401
- stdio: verbose && !silent ? "inherit" : "pipe",
402
- extendEnv: true,
403
- cleanup: true,
404
- ...opts
405
- });
406
- }
407
- })),
424
+ commands.map(
425
+ ({ title, cmd, args = [], opts = {}, cwd = getPaths().base }) => ({
426
+ title,
427
+ task: async () => {
428
+ return execa(cmd, args, {
429
+ cwd,
430
+ stdio: verbose && !silent ? "inherit" : "pipe",
431
+ extendEnv: true,
432
+ cleanup: true,
433
+ ...opts
434
+ });
435
+ }
436
+ })
437
+ ),
408
438
  {
409
439
  renderer: silent ? "silent" : verbose ? "verbose" : "default",
410
- rendererOptions: { collapseSubtasks: false, dateFormat: false }
440
+ rendererOptions: { collapseSubtasks: false }
411
441
  }
412
442
  );
413
443
  try {
414
444
  await tasks.run();
415
445
  return true;
416
446
  } catch (e) {
417
- console.log(c.error(e.message));
447
+ const message = e instanceof Error ? e.message : String(e);
448
+ console.log(c.error(message));
418
449
  return false;
419
450
  }
420
451
  };
@@ -428,8 +459,8 @@ const getDefaultArgs = (builder) => {
428
459
  );
429
460
  };
430
461
  const usingVSCode = () => {
431
- const redwoodPaths = getPaths();
432
- const VS_CODE_PATH = path.join(redwoodPaths.base, ".vscode");
462
+ const cedarPaths = getPaths();
463
+ const VS_CODE_PATH = path.join(cedarPaths.base, ".vscode");
433
464
  return fs.existsSync(VS_CODE_PATH);
434
465
  };
435
466
  const printSetupNotes = (notes) => {
@@ -441,7 +472,7 @@ const printSetupNotes = (notes) => {
441
472
  ${boxen(notes.join("\n"), {
442
473
  padding: { top: 1, bottom: 1, right: 1, left: 1 },
443
474
  margin: 1,
444
- borderColour: "gray"
475
+ borderColor: "gray"
445
476
  })}
446
477
  `;
447
478
  }
@@ -452,7 +483,6 @@ export {
452
483
  addPackagesTask,
453
484
  addRoutesToRouterTask,
454
485
  addScaffoldImport,
455
- bytes,
456
486
  cleanupEmptyDirsTask,
457
487
  deleteFile,
458
488
  deleteFilesTask,
@@ -475,6 +505,7 @@ export {
475
505
  runCommandTask,
476
506
  saveRemoteFileToDisk,
477
507
  transformTSToJS,
508
+ transformTSToJSMap,
478
509
  usingVSCode,
479
510
  writeFile,
480
511
  writeFilesTask
@@ -3,7 +3,7 @@ import {
3
3
  loadDefaultEnvFiles,
4
4
  loadNodeEnvDerivedEnvFile,
5
5
  loadUserSpecifiedEnvFiles
6
- } from "@cedarjs/cli-helpers";
6
+ } from "@cedarjs/cli-helpers/loadEnvFiles";
7
7
  export {
8
8
  loadDefaultEnvFiles,
9
9
  loadEnvFiles,
@@ -32,11 +32,15 @@ function unsetLock(identifier) {
32
32
  }
33
33
  function isLockSet(identifier) {
34
34
  const lockfilePath = path.join(getPaths().generated.base, "locks", identifier);
35
- const exists = fs.existsSync(lockfilePath);
36
- if (!exists) {
37
- return false;
35
+ let createdAt;
36
+ try {
37
+ createdAt = fs.statSync(lockfilePath).birthtimeMs;
38
+ } catch (error) {
39
+ if (isErrorWithCode(error, "ENOENT")) {
40
+ return false;
41
+ }
42
+ throw error;
38
43
  }
39
- const createdAt = fs.statSync(lockfilePath).birthtimeMs;
40
44
  if (Date.now() - createdAt > 36e5) {
41
45
  unsetLock(identifier);
42
46
  return false;
@@ -16,9 +16,12 @@ function sieve(...listRulePairs) {
16
16
  }
17
17
  return result;
18
18
  }
19
+ function isAnyFn(value) {
20
+ return typeof value === "function";
21
+ }
19
22
  function forEachFunctionOn(object, callback) {
20
23
  forOwn(object, (value, key) => {
21
- if (typeof value === "function") {
24
+ if (isAnyFn(value)) {
22
25
  callback(key, value);
23
26
  }
24
27
  });