@cedarjs/cli 0.0.4

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 (360) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +706 -0
  3. package/dist/commands/build.js +54 -0
  4. package/dist/commands/buildHandler.js +134 -0
  5. package/dist/commands/check.js +28 -0
  6. package/dist/commands/console.js +13 -0
  7. package/dist/commands/consoleHandler.js +68 -0
  8. package/dist/commands/deploy/baremetal/SshExecutor.js +41 -0
  9. package/dist/commands/deploy/baremetal/baremetalHandler.js +558 -0
  10. package/dist/commands/deploy/baremetal.js +89 -0
  11. package/dist/commands/deploy/flightcontrol.js +40 -0
  12. package/dist/commands/deploy/flightcontrolHandler.js +58 -0
  13. package/dist/commands/deploy/helpers/deployBuilder.js +25 -0
  14. package/dist/commands/deploy/helpers/deployHandler.js +31 -0
  15. package/dist/commands/deploy/netlify.js +21 -0
  16. package/dist/commands/deploy/packing/nft.js +61 -0
  17. package/dist/commands/deploy/render.js +37 -0
  18. package/dist/commands/deploy/renderHandler.js +70 -0
  19. package/dist/commands/deploy/serverless.js +51 -0
  20. package/dist/commands/deploy/serverlessHandler.js +211 -0
  21. package/dist/commands/deploy/vercel.js +21 -0
  22. package/dist/commands/deploy.js +21 -0
  23. package/dist/commands/destroy/cell/cell.js +12 -0
  24. package/dist/commands/destroy/cell/cellHandler.js +10 -0
  25. package/dist/commands/destroy/component/component.js +15 -0
  26. package/dist/commands/destroy/component/componentHandler.js +10 -0
  27. package/dist/commands/destroy/directive/directive.js +14 -0
  28. package/dist/commands/destroy/directive/directiveHandler.js +12 -0
  29. package/dist/commands/destroy/function/function.js +20 -0
  30. package/dist/commands/destroy/function/functionHandler.js +10 -0
  31. package/dist/commands/destroy/handlerHelpers.js +34 -0
  32. package/dist/commands/destroy/helpers.js +22 -0
  33. package/dist/commands/destroy/layout/layout.js +12 -0
  34. package/dist/commands/destroy/layout/layoutHandler.js +10 -0
  35. package/dist/commands/destroy/page/page.js +20 -0
  36. package/dist/commands/destroy/page/pageHandler.js +51 -0
  37. package/dist/commands/destroy/scaffold/scaffold.js +16 -0
  38. package/dist/commands/destroy/scaffold/scaffoldHandler.js +105 -0
  39. package/dist/commands/destroy/sdl/sdl.js +16 -0
  40. package/dist/commands/destroy/sdl/sdlHandler.js +33 -0
  41. package/dist/commands/destroy/service/service.js +10 -0
  42. package/dist/commands/destroy/service/serviceHandler.js +17 -0
  43. package/dist/commands/destroy.js +25 -0
  44. package/dist/commands/dev.js +47 -0
  45. package/dist/commands/devHandler.js +202 -0
  46. package/dist/commands/exec.js +38 -0
  47. package/dist/commands/execHandler.js +180 -0
  48. package/dist/commands/experimental/setupInngest.js +28 -0
  49. package/dist/commands/experimental/setupInngestHandler.js +46 -0
  50. package/dist/commands/experimental/setupOpentelemetry.js +34 -0
  51. package/dist/commands/experimental/setupOpentelemetryHandler.js +215 -0
  52. package/dist/commands/experimental/setupReactCompiler.js +28 -0
  53. package/dist/commands/experimental/setupReactCompilerHandler.js +124 -0
  54. package/dist/commands/experimental/setupRsc.js +28 -0
  55. package/dist/commands/experimental/setupRscHandler.js +408 -0
  56. package/dist/commands/experimental/setupStreamingSsr.js +28 -0
  57. package/dist/commands/experimental/setupStreamingSsrHandler.js +208 -0
  58. package/dist/commands/experimental/templates/opentelemetry.ts.template +55 -0
  59. package/dist/commands/experimental/templates/rsc/AboutCounter.tsx.template +20 -0
  60. package/dist/commands/experimental/templates/rsc/AboutPage.css.template +2 -0
  61. package/dist/commands/experimental/templates/rsc/AboutPage.tsx.template +17 -0
  62. package/dist/commands/experimental/templates/rsc/Counter.css.template +7 -0
  63. package/dist/commands/experimental/templates/rsc/Counter.module.css.template +3 -0
  64. package/dist/commands/experimental/templates/rsc/Counter.tsx.template +18 -0
  65. package/dist/commands/experimental/templates/rsc/Document.tsx.template +27 -0
  66. package/dist/commands/experimental/templates/rsc/HomePage.css.template +2 -0
  67. package/dist/commands/experimental/templates/rsc/HomePage.module.css.template +3 -0
  68. package/dist/commands/experimental/templates/rsc/HomePage.tsx.template +19 -0
  69. package/dist/commands/experimental/templates/rsc/NavigationLayout.css.template +32 -0
  70. package/dist/commands/experimental/templates/rsc/NavigationLayout.tsx.template +31 -0
  71. package/dist/commands/experimental/templates/rsc/Routes.tsx.template +29 -0
  72. package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +35 -0
  73. package/dist/commands/experimental/templates/rsc/entry.server.tsx.template +20 -0
  74. package/dist/commands/experimental/templates/rsc/index.css.template +4 -0
  75. package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +27 -0
  76. package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +40 -0
  77. package/dist/commands/experimental/templates/streamingSsr/entry.server.tsx.template +20 -0
  78. package/dist/commands/experimental/templates/streamingSsr/tsconfig.json.template +54 -0
  79. package/dist/commands/experimental/util.js +69 -0
  80. package/dist/commands/experimental.js +22 -0
  81. package/dist/commands/generate/cell/cell.js +35 -0
  82. package/dist/commands/generate/cell/cellHandler.js +153 -0
  83. package/dist/commands/generate/cell/templates/cell.tsx.template +34 -0
  84. package/dist/commands/generate/cell/templates/cellList.tsx.template +40 -0
  85. package/dist/commands/generate/cell/templates/mock.ts.template +7 -0
  86. package/dist/commands/generate/cell/templates/mockList.ts.template +14 -0
  87. package/dist/commands/generate/cell/templates/stories.tsx.template +35 -0
  88. package/dist/commands/generate/cell/templates/test.js.template +42 -0
  89. package/dist/commands/generate/cell/utils/utils.js +43 -0
  90. package/dist/commands/generate/component/component.js +15 -0
  91. package/dist/commands/generate/component/componentHandler.js +55 -0
  92. package/dist/commands/generate/component/templates/component.tsx.template +10 -0
  93. package/dist/commands/generate/component/templates/stories.jsx.template +17 -0
  94. package/dist/commands/generate/component/templates/stories.tsx.template +26 -0
  95. package/dist/commands/generate/component/templates/test.tsx.template +14 -0
  96. package/dist/commands/generate/dataMigration/dataMigration.js +105 -0
  97. package/dist/commands/generate/dataMigration/templates/dataMigration.js.template +7 -0
  98. package/dist/commands/generate/dataMigration/templates/dataMigration.ts.template +5 -0
  99. package/dist/commands/generate/dbAuth/dbAuth.js +55 -0
  100. package/dist/commands/generate/dbAuth/dbAuthHandler.js +375 -0
  101. package/dist/commands/generate/dbAuth/templates/forgotPassword.tsx.template +94 -0
  102. package/dist/commands/generate/dbAuth/templates/login.tsx.template +130 -0
  103. package/dist/commands/generate/dbAuth/templates/login.webAuthn.tsx.template +264 -0
  104. package/dist/commands/generate/dbAuth/templates/resetPassword.tsx.template +121 -0
  105. package/dist/commands/generate/dbAuth/templates/signup.tsx.template +123 -0
  106. package/dist/commands/generate/directive/directive.js +15 -0
  107. package/dist/commands/generate/directive/directiveHandler.js +159 -0
  108. package/dist/commands/generate/directive/templates/transformer.directive.test.ts.template +18 -0
  109. package/dist/commands/generate/directive/templates/transformer.directive.ts.template +38 -0
  110. package/dist/commands/generate/directive/templates/validator.directive.test.ts.template +17 -0
  111. package/dist/commands/generate/directive/templates/validator.directive.ts.template +39 -0
  112. package/dist/commands/generate/function/function.js +29 -0
  113. package/dist/commands/generate/function/functionHandler.js +131 -0
  114. package/dist/commands/generate/function/templates/function.ts.template +33 -0
  115. package/dist/commands/generate/function/templates/scenarios.ts.template +8 -0
  116. package/dist/commands/generate/function/templates/test.ts.template +30 -0
  117. package/dist/commands/generate/helpers.js +71 -0
  118. package/dist/commands/generate/job/job.js +39 -0
  119. package/dist/commands/generate/job/jobHandler.js +138 -0
  120. package/dist/commands/generate/job/templates/job.ts.template +8 -0
  121. package/dist/commands/generate/job/templates/scenarios.ts.template +8 -0
  122. package/dist/commands/generate/job/templates/test.ts.template +7 -0
  123. package/dist/commands/generate/layout/layout.js +25 -0
  124. package/dist/commands/generate/layout/layoutHandler.js +59 -0
  125. package/dist/commands/generate/layout/templates/layout.tsx.a11y.template +27 -0
  126. package/dist/commands/generate/layout/templates/layout.tsx.template +9 -0
  127. package/dist/commands/generate/layout/templates/stories.tsx.template +13 -0
  128. package/dist/commands/generate/layout/templates/test.tsx.template +14 -0
  129. package/dist/commands/generate/model/model.js +29 -0
  130. package/dist/commands/generate/model/modelHandler.js +63 -0
  131. package/dist/commands/generate/model/templates/model.js.template +3 -0
  132. package/dist/commands/generate/ogImage/ogImage.js +43 -0
  133. package/dist/commands/generate/ogImage/ogImageHandler.js +111 -0
  134. package/dist/commands/generate/ogImage/templates/ogImage.og.tsx.template +13 -0
  135. package/dist/commands/generate/page/page.js +22 -0
  136. package/dist/commands/generate/page/pageHandler.js +227 -0
  137. package/dist/commands/generate/page/templates/page.tsx.template +35 -0
  138. package/dist/commands/generate/page/templates/stories.tsx.parameters.template +13 -0
  139. package/dist/commands/generate/page/templates/stories.tsx.template +13 -0
  140. package/dist/commands/generate/page/templates/test.tsx.template +14 -0
  141. package/dist/commands/generate/realtime/realtime.js +41 -0
  142. package/dist/commands/generate/realtime/realtimeHandler.js +215 -0
  143. package/dist/commands/generate/realtime/templates/liveQueries/blank/blank.sdl.ts.template +27 -0
  144. package/dist/commands/generate/realtime/templates/liveQueries/blank/blank.service.ts.template +73 -0
  145. package/dist/commands/generate/realtime/templates/realtime.ts.template +42 -0
  146. package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.sdl.ts.template +20 -0
  147. package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.service.ts.template +19 -0
  148. package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +58 -0
  149. package/dist/commands/generate/scaffold/scaffold.js +38 -0
  150. package/dist/commands/generate/scaffold/scaffoldHandler.js +663 -0
  151. package/dist/commands/generate/scaffold/templates/assets/scaffold.css.template +398 -0
  152. package/dist/commands/generate/scaffold/templates/assets/scaffold.tailwind.css.template +243 -0
  153. package/dist/commands/generate/scaffold/templates/components/EditNameCell.tsx.template +74 -0
  154. package/dist/commands/generate/scaffold/templates/components/Name.tsx.template +79 -0
  155. package/dist/commands/generate/scaffold/templates/components/NameCell.tsx.template +32 -0
  156. package/dist/commands/generate/scaffold/templates/components/NameForm.tsx.template +123 -0
  157. package/dist/commands/generate/scaffold/templates/components/Names.tsx.template +88 -0
  158. package/dist/commands/generate/scaffold/templates/components/NamesCell.tsx.template +45 -0
  159. package/dist/commands/generate/scaffold/templates/components/NewName.tsx.template +55 -0
  160. package/dist/commands/generate/scaffold/templates/layouts/ScaffoldLayout.tsx.template +37 -0
  161. package/dist/commands/generate/scaffold/templates/lib/formatters.test.tsx.template +192 -0
  162. package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +58 -0
  163. package/dist/commands/generate/scaffold/templates/pages/EditNamePage.tsx.template +11 -0
  164. package/dist/commands/generate/scaffold/templates/pages/NamePage.tsx.template +11 -0
  165. package/dist/commands/generate/scaffold/templates/pages/NamesPage.tsx.template +7 -0
  166. package/dist/commands/generate/scaffold/templates/pages/NewNamePage.tsx.template +7 -0
  167. package/dist/commands/generate/script/script.js +29 -0
  168. package/dist/commands/generate/script/scriptHandler.js +85 -0
  169. package/dist/commands/generate/script/templates/script.ts.template +15 -0
  170. package/dist/commands/generate/script/templates/tsconfig.json.template +33 -0
  171. package/dist/commands/generate/sdl/sdl.js +48 -0
  172. package/dist/commands/generate/sdl/sdlHandler.js +282 -0
  173. package/dist/commands/generate/sdl/templates/sdl.js.template +70 -0
  174. package/dist/commands/generate/sdl/templates/sdl.ts.template +70 -0
  175. package/dist/commands/generate/secret/secret.js +52 -0
  176. package/dist/commands/generate/service/service.js +50 -0
  177. package/dist/commands/generate/service/serviceHandler.js +301 -0
  178. package/dist/commands/generate/service/templates/scenarios.ts.template +7 -0
  179. package/dist/commands/generate/service/templates/service.ts.template +38 -0
  180. package/dist/commands/generate/service/templates/test.ts.template +84 -0
  181. package/dist/commands/generate/yargsCommandHelpers.js +77 -0
  182. package/dist/commands/generate/yargsHandlerHelpers.js +155 -0
  183. package/dist/commands/generate.js +44 -0
  184. package/dist/commands/info.js +36 -0
  185. package/dist/commands/jobs.js +17 -0
  186. package/dist/commands/jobsHandler.js +30 -0
  187. package/dist/commands/lint.js +57 -0
  188. package/dist/commands/prerender.js +34 -0
  189. package/dist/commands/prerenderHandler.js +282 -0
  190. package/dist/commands/prisma.js +17 -0
  191. package/dist/commands/prismaHandler.js +90 -0
  192. package/dist/commands/record/init.js +11 -0
  193. package/dist/commands/record.js +19 -0
  194. package/dist/commands/serve.js +139 -0
  195. package/dist/commands/serveApiHandler.js +15 -0
  196. package/dist/commands/serveBothHandler.js +95 -0
  197. package/dist/commands/serveWebHandler.js +17 -0
  198. package/dist/commands/setup/auth/auth.js +265 -0
  199. package/dist/commands/setup/cache/cache.js +37 -0
  200. package/dist/commands/setup/cache/cacheHandler.js +69 -0
  201. package/dist/commands/setup/cache/templates/memcached.ts.template +30 -0
  202. package/dist/commands/setup/cache/templates/redis.ts.template +24 -0
  203. package/dist/commands/setup/deploy/deploy.js +26 -0
  204. package/dist/commands/setup/deploy/helpers/helpers.js +9 -0
  205. package/dist/commands/setup/deploy/helpers/index.js +110 -0
  206. package/dist/commands/setup/deploy/providers/baremetal.js +9 -0
  207. package/dist/commands/setup/deploy/providers/baremetalHandler.js +64 -0
  208. package/dist/commands/setup/deploy/providers/coherence.js +24 -0
  209. package/dist/commands/setup/deploy/providers/coherenceHandler.js +203 -0
  210. package/dist/commands/setup/deploy/providers/flightcontrol.js +19 -0
  211. package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +294 -0
  212. package/dist/commands/setup/deploy/providers/netlify.js +9 -0
  213. package/dist/commands/setup/deploy/providers/netlifyHandler.js +42 -0
  214. package/dist/commands/setup/deploy/providers/render.js +17 -0
  215. package/dist/commands/setup/deploy/providers/renderHandler.js +111 -0
  216. package/dist/commands/setup/deploy/providers/serverless.js +11 -0
  217. package/dist/commands/setup/deploy/providers/serverlessHandler.js +141 -0
  218. package/dist/commands/setup/deploy/providers/vercel.js +9 -0
  219. package/dist/commands/setup/deploy/providers/vercelHandler.js +56 -0
  220. package/dist/commands/setup/deploy/templates/baremetal.js +128 -0
  221. package/dist/commands/setup/deploy/templates/flightcontrol.js +85 -0
  222. package/dist/commands/setup/deploy/templates/netlify.js +32 -0
  223. package/dist/commands/setup/deploy/templates/render.js +72 -0
  224. package/dist/commands/setup/deploy/templates/serverless/api.js +78 -0
  225. package/dist/commands/setup/deploy/templates/serverless/web.js +32 -0
  226. package/dist/commands/setup/docker/docker.js +26 -0
  227. package/dist/commands/setup/docker/dockerHandler.js +265 -0
  228. package/dist/commands/setup/docker/templates/Dockerfile +154 -0
  229. package/dist/commands/setup/docker/templates/docker-compose.dev.yml +58 -0
  230. package/dist/commands/setup/docker/templates/docker-compose.prod.yml +63 -0
  231. package/dist/commands/setup/docker/templates/dockerignore +18 -0
  232. package/dist/commands/setup/generator/generator.js +49 -0
  233. package/dist/commands/setup/generator/generatorHandler.js +55 -0
  234. package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +117 -0
  235. package/dist/commands/setup/graphql/features/fragments/appImportTransform.js +20 -0
  236. package/dist/commands/setup/graphql/features/fragments/fragments.js +25 -0
  237. package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +89 -0
  238. package/dist/commands/setup/graphql/features/trustedDocuments/graphqlTransform.js +51 -0
  239. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +25 -0
  240. package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +74 -0
  241. package/dist/commands/setup/graphql/graphql.js +18 -0
  242. package/dist/commands/setup/i18n/i18n.js +25 -0
  243. package/dist/commands/setup/i18n/i18nHandler.js +169 -0
  244. package/dist/commands/setup/i18n/templates/en.json.template +11 -0
  245. package/dist/commands/setup/i18n/templates/fr.json.template +11 -0
  246. package/dist/commands/setup/i18n/templates/i18n.js.template +52 -0
  247. package/dist/commands/setup/i18n/templates/storybook.preview.tsx.template +43 -0
  248. package/dist/commands/setup/jobs/jobs.js +31 -0
  249. package/dist/commands/setup/jobs/jobsHandler.js +122 -0
  250. package/dist/commands/setup/jobs/templates/jobs.ts.template +32 -0
  251. package/dist/commands/setup/mailer/mailer.js +30 -0
  252. package/dist/commands/setup/mailer/mailerHandler.js +106 -0
  253. package/dist/commands/setup/mailer/templates/mailer.ts.template +30 -0
  254. package/dist/commands/setup/mailer/templates/re-example.tsx.template +40 -0
  255. package/dist/commands/setup/middleware/middleware.js +17 -0
  256. package/dist/commands/setup/middleware/ogImage/__codemod_tests__/middleware.js +15 -0
  257. package/dist/commands/setup/middleware/ogImage/__codemod_tests__/vitePlugin.js +6 -0
  258. package/dist/commands/setup/middleware/ogImage/codemodMiddleware.js +97 -0
  259. package/dist/commands/setup/middleware/ogImage/codemodVitePlugin.js +65 -0
  260. package/dist/commands/setup/middleware/ogImage/ogImage.js +27 -0
  261. package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +121 -0
  262. package/dist/commands/setup/monitoring/monitoring.js +17 -0
  263. package/dist/commands/setup/monitoring/sentry/sentry.js +25 -0
  264. package/dist/commands/setup/monitoring/sentry/sentryHandler.js +163 -0
  265. package/dist/commands/setup/monitoring/sentry/templates/sentryApi.ts.template +15 -0
  266. package/dist/commands/setup/monitoring/sentry/templates/sentryWeb.ts.template +31 -0
  267. package/dist/commands/setup/package/package.js +33 -0
  268. package/dist/commands/setup/package/packageHandler.js +134 -0
  269. package/dist/commands/setup/realtime/realtime.js +37 -0
  270. package/dist/commands/setup/realtime/realtimeHandler.js +309 -0
  271. package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.sdl.template +14 -0
  272. package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.ts.template +14 -0
  273. package/dist/commands/setup/realtime/templates/liveQueries/auctions/auctions.sdl.ts.template +27 -0
  274. package/dist/commands/setup/realtime/templates/liveQueries/auctions/auctions.ts.template +73 -0
  275. package/dist/commands/setup/realtime/templates/realtime.ts.template +46 -0
  276. package/dist/commands/setup/realtime/templates/stream/alphabet/alphabet.sdl.template +9 -0
  277. package/dist/commands/setup/realtime/templates/stream/alphabet/alphabet.ts.template +31 -0
  278. package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +58 -0
  279. package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +57 -0
  280. package/dist/commands/setup/realtime/templates/subscriptions/newMessage/rooms.sdl.ts.template +20 -0
  281. package/dist/commands/setup/realtime/templates/subscriptions/newMessage/rooms.ts.template +20 -0
  282. package/dist/commands/setup/server-file/serverFile.js +31 -0
  283. package/dist/commands/setup/server-file/serverFileHandler.js +56 -0
  284. package/dist/commands/setup/server-file/templates/server.ts.template +13 -0
  285. package/dist/commands/setup/tsconfig/tsconfig.js +25 -0
  286. package/dist/commands/setup/tsconfig/tsconfigHandler.js +59 -0
  287. package/dist/commands/setup/ui/helpers/helpers.js +9 -0
  288. package/dist/commands/setup/ui/libraries/chakra-ui.js +24 -0
  289. package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +98 -0
  290. package/dist/commands/setup/ui/libraries/mantine.js +32 -0
  291. package/dist/commands/setup/ui/libraries/mantineHandler.js +138 -0
  292. package/dist/commands/setup/ui/libraries/tailwindcss.js +26 -0
  293. package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +386 -0
  294. package/dist/commands/setup/ui/templates/chakra.storybook.preview.tsx.template +20 -0
  295. package/dist/commands/setup/ui/templates/mantine-postcss.config.js.template +35 -0
  296. package/dist/commands/setup/ui/templates/mantine.storybook.preview.tsx.template +18 -0
  297. package/dist/commands/setup/ui/templates/postcss.config.js.template +9 -0
  298. package/dist/commands/setup/ui/ui.js +17 -0
  299. package/dist/commands/setup/uploads/dbCodemod.js +28 -0
  300. package/dist/commands/setup/uploads/templates/signedUrl.ts.template +21 -0
  301. package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +25 -0
  302. package/dist/commands/setup/uploads/uploads.js +26 -0
  303. package/dist/commands/setup/uploads/uploadsHandler.js +147 -0
  304. package/dist/commands/setup/vite/templates/vite.config.ts.template +19 -0
  305. package/dist/commands/setup/vite/vite.js +38 -0
  306. package/dist/commands/setup/vite/viteHandler.js +83 -0
  307. package/dist/commands/setup.js +33 -0
  308. package/dist/commands/studio.js +23 -0
  309. package/dist/commands/studioHandler.js +61 -0
  310. package/dist/commands/test.js +44 -0
  311. package/dist/commands/testHandler.js +138 -0
  312. package/dist/commands/ts-to-js.js +20 -0
  313. package/dist/commands/type-check.js +41 -0
  314. package/dist/commands/type-checkHandler.js +71 -0
  315. package/dist/commands/upgrade.js +441 -0
  316. package/dist/index.d.js +0 -0
  317. package/dist/index.js +146 -0
  318. package/dist/lib/background.js +45 -0
  319. package/dist/lib/colors.js +18 -0
  320. package/dist/lib/configureStorybook.js +50 -0
  321. package/dist/lib/exec.js +85 -0
  322. package/dist/lib/exit.js +44 -0
  323. package/dist/lib/extendFile.js +114 -0
  324. package/dist/lib/generatePrismaClient.js +60 -0
  325. package/dist/lib/index.js +485 -0
  326. package/dist/lib/loadEnvFiles.js +12 -0
  327. package/dist/lib/locking.js +60 -0
  328. package/dist/lib/merge/algorithms.js +30 -0
  329. package/dist/lib/merge/index.js +163 -0
  330. package/dist/lib/merge/semanticIdentity.js +18 -0
  331. package/dist/lib/merge/strategy.js +136 -0
  332. package/dist/lib/mockTelemetry.js +7 -0
  333. package/dist/lib/packages.js +77 -0
  334. package/dist/lib/plugin.js +206 -0
  335. package/dist/lib/pluralHelpers.js +50 -0
  336. package/dist/lib/ports.js +17 -0
  337. package/dist/lib/project.js +30 -0
  338. package/dist/lib/rollback.js +72 -0
  339. package/dist/lib/runTransform.js +66 -0
  340. package/dist/lib/rwPluralize.js +56 -0
  341. package/dist/lib/schemaHelpers.js +95 -0
  342. package/dist/lib/templates/storybook.preview.tsx.template +19 -0
  343. package/dist/lib/test.js +106 -0
  344. package/dist/lib/updateCheck.js +202 -0
  345. package/dist/lib/updateCheckExecute.js +2 -0
  346. package/dist/middleware/checkNodeVersion.js +23 -0
  347. package/dist/middleware/detectProjectRxVersion.js +12 -0
  348. package/dist/plugin.js +223 -0
  349. package/dist/rwfw.js +47 -0
  350. package/dist/telemetry/exporter.js +63 -0
  351. package/dist/telemetry/index.js +84 -0
  352. package/dist/telemetry/resource.js +98 -0
  353. package/dist/telemetry/send.js +80 -0
  354. package/dist/testLib/cells.js +188 -0
  355. package/dist/testLib/fetchFileFromTemplate.js +9 -0
  356. package/dist/testLib/getFilesWithPattern.js +21 -0
  357. package/dist/testLib/getRootPackageJSON.js +14 -0
  358. package/dist/testLib/isTSProject.js +9 -0
  359. package/dist/testLib/runTransform.js +42 -0
  360. package/package.json +102 -0
@@ -0,0 +1,52 @@
1
+ import i18n from 'i18next'
2
+ import { initReactI18next } from 'react-i18next'
3
+ import LanguageDetector from 'i18next-browser-languagedetector'
4
+ import fr from './locales/fr.json'
5
+ import en from './locales/en.json'
6
+
7
+ // This is a simple i18n configuration with English and French translations.
8
+ // You can find the translations in web/src/locales/{language}.json
9
+ // see: https://react.i18next.com
10
+ // Here's an example of how to use it in your components, pages or layouts:
11
+ /*
12
+ import { Link, routes } from '@cedarjs/router'
13
+ import { useTranslation } from 'react-i18next'
14
+
15
+ const HomePage = () => {
16
+ const { t, i18n } = useTranslation()
17
+ return (
18
+ <>
19
+ <h1>{t('HomePage.title')}</h1>
20
+ <button onClick={() => i18n.changeLanguage('fr')}>fr</button>
21
+ <button onClick={() => i18n.changeLanguage('en')}>en</button>
22
+ <p>
23
+ {t('HomePage.info')} <code>./web/src/pages/HomePage/HomePage.js</code>
24
+ </p>
25
+ <p>
26
+ {t('HomePage.route')} <code>home</code>, {t('HomePage.link')}`
27
+ <Link to={routes.home()}>Home</Link>`
28
+ </p>
29
+ </>
30
+ )
31
+ }
32
+
33
+ export default HomePage
34
+ */
35
+
36
+ i18n
37
+ // learn more: https://github.com/i18next/i18next-browser-languageDetector
38
+ .use(LanguageDetector)
39
+ .use(initReactI18next)
40
+ .init({
41
+ interpolation: { escapeValue: false }, // React already does escaping
42
+ fallbackLng: 'en',
43
+ resources: {
44
+ en: {
45
+ translation: en,
46
+ },
47
+ fr: {
48
+ translation: fr,
49
+ },
50
+ },
51
+ })
52
+ export default i18n
@@ -0,0 +1,43 @@
1
+ import * as React from 'react'
2
+
3
+ import type { GlobalTypes } from '@storybook/csf'
4
+ import type { Preview, StoryContext, StoryFn } from '@storybook/react'
5
+ import { I18nextProvider } from 'react-i18next'
6
+ import i18n from 'web/src/i18n'
7
+
8
+ /** @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#global-types-and-the-toolbar-annotation | Global types and the toolbar annotation} */
9
+ export const globalTypes: GlobalTypes = {
10
+ locale: {
11
+ name: 'Locale',
12
+ description: 'Internationalization locale',
13
+ defaultValue: 'en',
14
+ toolbar: {
15
+ icon: 'globe',
16
+ items: [
17
+ { value: 'en', right: '🇺🇸', title: 'English' },
18
+ { value: 'fr', right: '🇫🇷', title: 'Français' },
19
+ ],
20
+ },
21
+ },
22
+ }
23
+
24
+ /**
25
+ * @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#create-a-decorator | Create a decorator}
26
+ */
27
+ const withI18n = function WithI18n(Story: StoryFn, context: StoryContext) {
28
+ React.useEffect(() => {
29
+ i18n.changeLanguage(context.globals.locale)
30
+ }, [context.globals.locale])
31
+
32
+ return (
33
+ <I18nextProvider i18n={i18n}>
34
+ <Story />
35
+ </I18nextProvider>
36
+ )
37
+ }
38
+
39
+ const preview: Preview = {
40
+ decorators: [withI18n],
41
+ }
42
+
43
+ export default preview
@@ -0,0 +1,31 @@
1
+ import terminalLink from "terminal-link";
2
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
3
+ const command = "jobs";
4
+ const description = "Sets up the config file and parent directory for background jobs";
5
+ const builder = (yargs) => {
6
+ yargs.option("force", {
7
+ alias: "f",
8
+ default: false,
9
+ description: "Overwrite existing files",
10
+ type: "boolean"
11
+ }).epilogue(
12
+ `Also see the ${terminalLink(
13
+ "Redwood CLI Reference",
14
+ "https://redwoodjs.com/docs/cli-commands#setup-jobs"
15
+ )}`
16
+ );
17
+ };
18
+ const handler = async (options) => {
19
+ recordTelemetryAttributes({
20
+ command: "setup jobs",
21
+ force: options.force
22
+ });
23
+ const { handler: handler2 } = await import("./jobsHandler.js");
24
+ return handler2(options);
25
+ };
26
+ export {
27
+ builder,
28
+ command,
29
+ description,
30
+ handler
31
+ };
@@ -0,0 +1,122 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import prismaInternals from "@prisma/internals";
4
+ import { Listr } from "listr2";
5
+ import { addApiPackages } from "@cedarjs/cli-helpers";
6
+ import c from "../../../lib/colors.js";
7
+ import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
8
+ import { isTypeScriptProject } from "../../../lib/project.js";
9
+ const MODEL_SCHEMA = `
10
+ model BackgroundJob {
11
+ id Int @id @default(autoincrement())
12
+ attempts Int @default(0)
13
+ handler String
14
+ queue String
15
+ priority Int
16
+ runAt DateTime?
17
+ lockedAt DateTime?
18
+ lockedBy String?
19
+ lastError String?
20
+ failedAt DateTime?
21
+ createdAt DateTime @default(now())
22
+ updatedAt DateTime @updatedAt
23
+ }
24
+ `;
25
+ const getModelNames = async () => {
26
+ const schema = await prismaInternals.getDMMF({
27
+ datamodelPath: getPaths().api.dbSchema
28
+ });
29
+ return schema.datamodel.models.map((model) => model.name);
30
+ };
31
+ const addDatabaseModel = () => {
32
+ const schema = fs.readFileSync(getPaths().api.dbSchema, "utf-8");
33
+ const schemaWithUser = schema + MODEL_SCHEMA;
34
+ fs.writeFileSync(getPaths().api.dbSchema, schemaWithUser);
35
+ };
36
+ const tasks = async ({ force }) => {
37
+ const modelExists = (await getModelNames()).includes("BackgroundJob");
38
+ const packageJsonPath = path.join(getPaths().base, "package.json");
39
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
40
+ const redwoodVersion = packageJson.devDependencies?.["@cedarjs/core"] ?? "latest";
41
+ const jobsPackage = `@cedarjs/jobs@${redwoodVersion}`;
42
+ return new Listr(
43
+ [
44
+ {
45
+ title: "Creating job database model...",
46
+ task: () => {
47
+ addDatabaseModel();
48
+ },
49
+ skip: () => {
50
+ if (modelExists) {
51
+ return "BackgroundJob model exists, skipping";
52
+ }
53
+ }
54
+ },
55
+ {
56
+ title: "Creating config file in api/src/lib...",
57
+ task: async () => {
58
+ const isTs = isTypeScriptProject();
59
+ const outputExtension = isTs ? "ts" : "js";
60
+ const outputPath = path.join(
61
+ getPaths().api.lib,
62
+ `jobs.${outputExtension}`
63
+ );
64
+ let template = fs.readFileSync(
65
+ path.resolve(
66
+ import.meta.dirname,
67
+ "templates",
68
+ "jobs.ts.template"
69
+ )
70
+ ).toString();
71
+ if (!isTs) {
72
+ template = await transformTSToJS(outputPath, template);
73
+ }
74
+ writeFile(outputPath, template, {
75
+ overwriteExisting: force
76
+ });
77
+ }
78
+ },
79
+ {
80
+ title: "Creating jobs dir at api/src/jobs...",
81
+ task: () => {
82
+ fs.mkdirSync(getPaths().api.jobs, { recursive: true });
83
+ writeFile(path.join(getPaths().api.jobs, ".keep"), "", {
84
+ overwriteExisting: force
85
+ });
86
+ }
87
+ },
88
+ addApiPackages([jobsPackage]),
89
+ {
90
+ title: "One more thing...",
91
+ task: (_ctx, task) => {
92
+ task.title = `One more thing...
93
+
94
+ ${c.success("\nBackground jobs configured!\n")}
95
+
96
+ ${!modelExists ? "Migrate your database to finish setting up jobs:\n" : ""}
97
+ ${!modelExists ? c.highlight("\n\xA0\xA0yarn rw prisma migrate dev\n") : ""}
98
+
99
+ Generate jobs with: ${c.highlight("yarn rw g job <name>")}
100
+ Execute jobs with: ${c.highlight("yarn rw jobs work\n")}
101
+
102
+ Check out the docs for more info:
103
+ ${c.link("https://docs.redwoodjs.com/docs/background-jobs")}
104
+
105
+ `;
106
+ }
107
+ }
108
+ ],
109
+ { rendererOptions: { collapseSubtasks: false }, errorOnExist: true }
110
+ );
111
+ };
112
+ const handler = async ({ force }) => {
113
+ const t = await tasks({ force });
114
+ try {
115
+ await t.run();
116
+ } catch (e) {
117
+ console.error(c.error(e.message));
118
+ }
119
+ };
120
+ export {
121
+ handler
122
+ };
@@ -0,0 +1,32 @@
1
+ // Setup for background jobs. Jobs themselves live in api/src/jobs
2
+ // Execute jobs in dev with `yarn rw jobs work`
3
+ // See https://docs.redwoodjs.com/docs/background-jobs
4
+
5
+ import { PrismaAdapter, JobManager } from '@cedarjs/jobs'
6
+
7
+ import { db } from 'src/lib/db'
8
+ import { logger } from 'src/lib/logger'
9
+
10
+ export const jobs = new JobManager({
11
+ adapters: {
12
+ prisma: new PrismaAdapter({ db, logger }),
13
+ },
14
+ queues: ['default'] as const,
15
+ logger,
16
+ workers: [
17
+ {
18
+ adapter: 'prisma',
19
+ logger,
20
+ queue: '*', // watch all queues
21
+ count: 1,
22
+ maxAttempts: 24,
23
+ maxRuntime: 14_400,
24
+ deleteFailedJobs: false,
25
+ sleepDelay: 5,
26
+ },
27
+ ],
28
+ })
29
+
30
+ export const later = jobs.createScheduler({
31
+ adapter: 'prisma',
32
+ })
@@ -0,0 +1,30 @@
1
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
2
+ const command = "mailer";
3
+ const description = "Setup the redwood mailer. This will install the required packages and add the required initial configuration to your redwood app.";
4
+ const builder = (yargs) => {
5
+ yargs.option("force", {
6
+ alias: "f",
7
+ default: false,
8
+ description: "Overwrite existing configuration",
9
+ type: "boolean"
10
+ }).option("skip-examples", {
11
+ default: false,
12
+ description: "Only include required files and exclude any examples",
13
+ type: "boolean"
14
+ });
15
+ };
16
+ const handler = async (options) => {
17
+ recordTelemetryAttributes({
18
+ command: "setup mailer",
19
+ force: options.force,
20
+ skipExamples: options.skipExamples
21
+ });
22
+ const { handler: handler2 } = await import("./mailerHandler.js");
23
+ return handler2(options);
24
+ };
25
+ export {
26
+ builder,
27
+ command,
28
+ description,
29
+ handler
30
+ };
@@ -0,0 +1,106 @@
1
+ import path from "node:path";
2
+ import fs from "fs-extra";
3
+ import { Listr } from "listr2";
4
+ import { addApiPackages } from "@cedarjs/cli-helpers";
5
+ import { errorTelemetry } from "@cedarjs/telemetry";
6
+ import c from "../../../lib/colors.js";
7
+ import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
8
+ import { isTypeScriptProject } from "../../../lib/project.js";
9
+ const handler = async ({ force, skipExamples }) => {
10
+ const projectIsTypescript = isTypeScriptProject();
11
+ const redwoodVersion = await import(path.join(getPaths().base, "package.json"), {
12
+ with: { type: "json " }
13
+ }).default.devDependencies["@cedarjs/core"] ?? "latest";
14
+ const tasks = new Listr(
15
+ [
16
+ {
17
+ title: `Adding api/src/lib/mailer.${projectIsTypescript ? "ts" : "js"}...`,
18
+ task: async () => {
19
+ const templatePath = path.resolve(
20
+ import.meta.dirname,
21
+ "templates",
22
+ "mailer.ts.template"
23
+ );
24
+ const templateContent = fs.readFileSync(templatePath, {
25
+ encoding: "utf8",
26
+ flag: "r"
27
+ });
28
+ const mailerPath = path.join(
29
+ getPaths().api.lib,
30
+ `mailer.${projectIsTypescript ? "ts" : "js"}`
31
+ );
32
+ const mailerContent = projectIsTypescript ? templateContent : await transformTSToJS(mailerPath, templateContent);
33
+ return writeFile(mailerPath, mailerContent, {
34
+ overwriteExisting: force
35
+ });
36
+ }
37
+ },
38
+ {
39
+ title: "Adding api/src/mail directory...",
40
+ task: () => {
41
+ const mailDir = path.join(getPaths().api.mail);
42
+ if (!fs.existsSync(mailDir)) {
43
+ fs.mkdirSync(mailDir);
44
+ }
45
+ }
46
+ },
47
+ {
48
+ title: `Adding example ReactEmail mail template`,
49
+ skip: () => skipExamples,
50
+ task: async () => {
51
+ const templatePath = path.resolve(
52
+ import.meta.dirname,
53
+ "templates",
54
+ "re-example.tsx.template"
55
+ );
56
+ const templateContent = fs.readFileSync(templatePath, {
57
+ encoding: "utf8",
58
+ flag: "r"
59
+ });
60
+ const exampleTemplatePath = path.join(
61
+ getPaths().api.mail,
62
+ "Example",
63
+ `Example.${projectIsTypescript ? "tsx" : "jsx"}`
64
+ );
65
+ const exampleTemplateContent = projectIsTypescript ? templateContent : await transformTSToJS(exampleTemplatePath, templateContent);
66
+ return writeFile(exampleTemplatePath, exampleTemplateContent, {
67
+ overwriteExisting: force
68
+ });
69
+ }
70
+ },
71
+ {
72
+ // Add production dependencies
73
+ ...addApiPackages([
74
+ `@cedarjs/mailer-core@${redwoodVersion}`,
75
+ `@cedarjs/mailer-handler-nodemailer@${redwoodVersion}`,
76
+ `@cedarjs/mailer-renderer-react-email@${redwoodVersion}`,
77
+ `@react-email/components`
78
+ // NOTE: Unpinned dependency here
79
+ ]),
80
+ title: "Adding production dependencies to your api side..."
81
+ },
82
+ {
83
+ // Add development dependencies
84
+ ...addApiPackages([
85
+ "-D",
86
+ `@cedarjs/mailer-handler-in-memory@${redwoodVersion}`,
87
+ `@cedarjs/mailer-handler-studio@${redwoodVersion}`
88
+ ]),
89
+ title: "Adding development dependencies to your api side..."
90
+ }
91
+ ],
92
+ {
93
+ rendererOptions: { collapseSubtasks: false }
94
+ }
95
+ );
96
+ try {
97
+ await tasks.run();
98
+ } catch (e) {
99
+ errorTelemetry(process.argv, e.message);
100
+ console.error(c.error(e.message));
101
+ process.exit(e?.exitCode || 1);
102
+ }
103
+ };
104
+ export {
105
+ handler
106
+ };
@@ -0,0 +1,30 @@
1
+ import { Mailer } from '@cedarjs/mailer-core'
2
+ import { NodemailerMailHandler } from '@cedarjs/mailer-handler-nodemailer'
3
+ import { ReactEmailRenderer } from '@cedarjs/mailer-renderer-react-email'
4
+
5
+ import { logger } from 'src/lib/logger'
6
+
7
+ export const mailer = new Mailer({
8
+ handling: {
9
+ handlers: {
10
+ // TODO: Update this handler config or switch it out for a different handler completely
11
+ nodemailer: new NodemailerMailHandler({
12
+ transport: {
13
+ host: 'localhost',
14
+ port: 4319,
15
+ secure: false,
16
+ },
17
+ }),
18
+ },
19
+ default: 'nodemailer',
20
+ },
21
+
22
+ rendering: {
23
+ renderers: {
24
+ reactEmail: new ReactEmailRenderer(),
25
+ },
26
+ default: 'reactEmail',
27
+ },
28
+
29
+ logger,
30
+ })
@@ -0,0 +1,40 @@
1
+ import React from 'react'
2
+
3
+ import {
4
+ Html,
5
+ Text,
6
+ Hr,
7
+ Body,
8
+ Head,
9
+ Tailwind,
10
+ Preview,
11
+ Container,
12
+ Heading,
13
+ } from '@react-email/components'
14
+
15
+ export function ExampleEmail(
16
+ { when }: { when: string } = { when: new Date().toLocaleString() }
17
+ ) {
18
+ return (
19
+ <Html lang="en">
20
+ <Head />
21
+ <Preview>An example email</Preview>
22
+ <Tailwind>
23
+ <Body className="mx-auto my-auto bg-white font-sans">
24
+ <Container className="mx-auto my-[40px] rounded border border-solid border-gray-200 p-[20px]">
25
+ <Heading className="mx-0 my-[30px] p-0 text-center text-[24px] font-normal text-black">
26
+ Example Email
27
+ </Heading>
28
+ <Text className="text-[14px] leading-[24px] text-black">
29
+ This is an example email which you can customise to your needs.
30
+ </Text>
31
+ <Hr className="mx-0 my-[26px] w-full border border-solid border-[#eaeaea]" />
32
+ <Text className="text-[12px] leading-[24px] text-[#666666]">
33
+ Message was sent on {when}
34
+ </Text>
35
+ </Container>
36
+ </Body>
37
+ </Tailwind>
38
+ </Html>
39
+ )
40
+ }
@@ -0,0 +1,17 @@
1
+ import terminalLink from "terminal-link";
2
+ import * as ogImageCommand from "./ogImage/ogImage.js";
3
+ const command = "middleware <type>";
4
+ const description = "Set up a middleware";
5
+ function builder(yargs) {
6
+ return yargs.command(ogImageCommand).epilogue(
7
+ `Also see the ${terminalLink(
8
+ "Redwood CLI Reference",
9
+ "https://redwoodjs.com/docs/cli-commands"
10
+ )}`
11
+ );
12
+ }
13
+ export {
14
+ builder,
15
+ command,
16
+ description
17
+ };
@@ -0,0 +1,15 @@
1
+ import { describe, it } from "vitest";
2
+ describe("Middleware codemod", () => {
3
+ it("Handles the default TSX case", async () => {
4
+ await matchTransformSnapshot("codemodMiddleware", "defaultTsx");
5
+ });
6
+ it("Handles when OgImageMiddleware is already imported", async () => {
7
+ await matchTransformSnapshot("codemodMiddleware", "alreadyContainsImport");
8
+ });
9
+ it("Handles when registerMiddleware function is already defined", async () => {
10
+ await matchTransformSnapshot(
11
+ "codemodMiddleware",
12
+ "registerFunctionAlreadyDefined"
13
+ );
14
+ });
15
+ });
@@ -0,0 +1,6 @@
1
+ import { describe, it } from "vitest";
2
+ describe("Vite plugin codemod", () => {
3
+ it("Handles the default vite config case", async () => {
4
+ await matchTransformSnapshot("codemodVitePlugin", "defaultViteConfig");
5
+ });
6
+ });
@@ -0,0 +1,97 @@
1
+ function transform(file, api) {
2
+ const j = api.jscodeshift;
3
+ const ast = j(file.source);
4
+ const needsImport = ast.find(j.ImportDeclaration, {
5
+ specifiers: [
6
+ {
7
+ type: "ImportDefaultSpecifier",
8
+ local: {
9
+ name: "OgImageMiddleware"
10
+ }
11
+ }
12
+ ],
13
+ source: {
14
+ value: "@cedarjs/ogimage-gen/middleware",
15
+ type: "StringLiteral"
16
+ }
17
+ }).length === 0;
18
+ if (needsImport) {
19
+ ast.find(j.ImportDeclaration).at(0).insertBefore(
20
+ j.importDeclaration(
21
+ [j.importDefaultSpecifier(j.identifier("OgImageMiddleware"))],
22
+ j.stringLiteral("@cedarjs/ogimage-gen/middleware")
23
+ )
24
+ );
25
+ }
26
+ const registerMiddleware = ast.find(j.ExportNamedDeclaration, {
27
+ declaration(value) {
28
+ if (!value) {
29
+ return false;
30
+ }
31
+ if (value.type === "VariableDeclaration") {
32
+ return value.declarations[0].type === "VariableDeclarator" && value.declarations[0].id.type === "Identifier" && value.declarations[0].id.name === "registerMiddleware";
33
+ }
34
+ if (value.type === "FunctionDeclaration") {
35
+ return value.id?.type === "Identifier" && value.id?.name === "registerMiddleware";
36
+ }
37
+ return false;
38
+ }
39
+ });
40
+ const appObjectProperty = j.objectProperty(
41
+ j.identifier("App"),
42
+ j.identifier("App")
43
+ );
44
+ appObjectProperty.shorthand = true;
45
+ const documentObjectProperty = j.objectProperty(
46
+ j.identifier("Document"),
47
+ j.identifier("Document")
48
+ );
49
+ documentObjectProperty.shorthand = true;
50
+ const ogMwDeclaration = j.variableDeclaration("const", [
51
+ j.variableDeclarator(
52
+ j.identifier("ogMw"),
53
+ j.newExpression(j.identifier("OgImageMiddleware"), [
54
+ j.objectExpression([appObjectProperty, documentObjectProperty])
55
+ ])
56
+ )
57
+ ]);
58
+ const arrowFunc = j.arrowFunctionExpression(
59
+ [],
60
+ j.blockStatement([
61
+ ogMwDeclaration,
62
+ j.returnStatement(j.arrayExpression([j.identifier("ogMw")]))
63
+ ])
64
+ );
65
+ arrowFunc.async = true;
66
+ const needsCompleteRegisterMiddleware = registerMiddleware.length === 0;
67
+ if (needsCompleteRegisterMiddleware) {
68
+ ast.find(j.ExportNamedDeclaration).at(-1).insertAfter(
69
+ j.exportNamedDeclaration(
70
+ j.variableDeclaration("const", [
71
+ j.variableDeclarator(j.identifier("registerMiddleware"), arrowFunc)
72
+ ])
73
+ )
74
+ );
75
+ } else {
76
+ const returnStatement = registerMiddleware.find(j.ReturnStatement, {
77
+ argument: {
78
+ type: "ArrayExpression"
79
+ }
80
+ });
81
+ if (returnStatement.length === 0) {
82
+ throw new Error(
83
+ "Could not find the return statement in the existing registerMiddleware function"
84
+ );
85
+ }
86
+ returnStatement.insertBefore(ogMwDeclaration);
87
+ returnStatement.find(j.ArrayExpression).at(0).replaceWith((nodePath) => {
88
+ const elements = nodePath.value.elements;
89
+ elements.push(j.identifier("ogMw"));
90
+ return nodePath.value;
91
+ });
92
+ }
93
+ return ast.toSource();
94
+ }
95
+ export {
96
+ transform as default
97
+ };