@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,71 @@
1
+ import path from "path";
2
+ import concurrently from "concurrently";
3
+ import execa from "execa";
4
+ import { Listr } from "listr2";
5
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
6
+ import { getCmdMajorVersion } from "../commands/upgrade.js";
7
+ import { generatePrismaClient } from "../lib/generatePrismaClient.js";
8
+ import { getPaths } from "../lib/index.js";
9
+ const handler = async ({ sides, verbose, prisma, generate }) => {
10
+ recordTelemetryAttributes({
11
+ command: "type-check",
12
+ sides: JSON.stringify(sides),
13
+ verbose,
14
+ prisma,
15
+ generate
16
+ });
17
+ const typeCheck = async () => {
18
+ let conclusiveExitCode = 0;
19
+ const yarnVersion = await getCmdMajorVersion("yarn");
20
+ const tscForAllSides = sides.map((side) => {
21
+ const projectDir = path.join(getPaths().base, side);
22
+ return {
23
+ cwd: projectDir,
24
+ command: `yarn ${yarnVersion > 1 ? "" : "-s"} tsc --noEmit --skipLibCheck`
25
+ };
26
+ });
27
+ const { result } = concurrently(tscForAllSides, {
28
+ group: true,
29
+ raw: true
30
+ });
31
+ try {
32
+ await result;
33
+ } catch (err) {
34
+ if (err.length) {
35
+ const exitCodes = err.map((e) => e?.exitCode).filter(Boolean);
36
+ conclusiveExitCode = Math.max(...exitCodes);
37
+ }
38
+ }
39
+ return conclusiveExitCode;
40
+ };
41
+ if (generate && prisma) {
42
+ await generatePrismaClient({
43
+ verbose,
44
+ schema: getPaths().api.dbSchema
45
+ });
46
+ }
47
+ if (generate) {
48
+ await new Listr(
49
+ [
50
+ {
51
+ title: "Generating types",
52
+ task: () => execa("yarn rw-gen", {
53
+ shell: true,
54
+ stdio: verbose ? "inherit" : "ignore"
55
+ })
56
+ }
57
+ ],
58
+ {
59
+ renderer: verbose && "verbose",
60
+ rendererOptions: { collapseSubtasks: false }
61
+ }
62
+ ).run();
63
+ }
64
+ const exitCode = await typeCheck();
65
+ if (exitCode > 0) {
66
+ process.exitCode = exitCode;
67
+ }
68
+ };
69
+ export {
70
+ handler
71
+ };
@@ -0,0 +1,441 @@
1
+ import path from "path";
2
+ import execa from "execa";
3
+ import fs from "fs-extra";
4
+ import latestVersion from "latest-version";
5
+ import { Listr } from "listr2";
6
+ import terminalLink from "terminal-link";
7
+ import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
8
+ import { getConfig } from "@cedarjs/project-config";
9
+ import c from "../lib/colors.js";
10
+ import { generatePrismaClient } from "../lib/generatePrismaClient.js";
11
+ import { getPaths } from "../lib/index.js";
12
+ import { PLUGIN_CACHE_FILENAME } from "../lib/plugin.js";
13
+ const command = "upgrade";
14
+ const description = "Upgrade all @cedarjs packages via interactive CLI";
15
+ const builder = (yargs) => {
16
+ yargs.example(
17
+ "rw upgrade -t 0.20.1-canary.5",
18
+ "Specify a version. URL for Version History:\nhttps://www.npmjs.com/package/@cedarjs/core"
19
+ ).option("dry-run", {
20
+ alias: "d",
21
+ description: "Check for outdated packages without upgrading",
22
+ type: "boolean"
23
+ }).option("tag", {
24
+ alias: "t",
25
+ description: '[choices: "latest", "rc", "next", "canary", "experimental", or a specific-version (see example below)] WARNING: "canary", "rc" and "experimental" are unstable releases! And "canary" releases include breaking changes often requiring codemods if upgrading a project.',
26
+ requiresArg: true,
27
+ type: "string",
28
+ coerce: validateTag
29
+ }).option("verbose", {
30
+ alias: "v",
31
+ description: "Print verbose logs",
32
+ type: "boolean",
33
+ default: false
34
+ }).option("dedupe", {
35
+ description: "Skip dedupe check with --no-dedupe",
36
+ type: "boolean",
37
+ default: true
38
+ }).epilogue(
39
+ `Also see the ${terminalLink(
40
+ "Cedar CLI Reference for the upgrade command",
41
+ "https://redwoodjs.com/docs/cli-commands#upgrade"
42
+ )}.
43
+ And the ${terminalLink(
44
+ "GitHub releases page",
45
+ "https://github.com/cedarjs/cedar/releases"
46
+ )} for more information on the current release.`
47
+ );
48
+ };
49
+ const SEMVER_REGEX = /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/i;
50
+ const isValidSemver = (string) => {
51
+ return SEMVER_REGEX.test(string);
52
+ };
53
+ const isValidCedarTag = (tag) => {
54
+ return ["rc", "canary", "latest", "next", "experimental"].includes(tag);
55
+ };
56
+ const validateTag = (tag) => {
57
+ const isTagValid = isValidSemver(tag) || isValidCedarTag(tag);
58
+ if (!isTagValid) {
59
+ throw new Error(
60
+ c.error(
61
+ "Invalid tag supplied. Supported values: 'rc', 'canary', 'latest', 'next', 'experimental', or a valid semver version\n"
62
+ )
63
+ );
64
+ }
65
+ return tag;
66
+ };
67
+ const handler = async ({ dryRun, tag, verbose, dedupe }) => {
68
+ recordTelemetryAttributes({
69
+ command: "upgrade",
70
+ dryRun,
71
+ tag,
72
+ verbose,
73
+ dedupe
74
+ });
75
+ const tasks = new Listr(
76
+ [
77
+ {
78
+ title: "Checking latest version",
79
+ task: async (ctx) => setLatestVersionToContext(ctx, tag)
80
+ },
81
+ {
82
+ title: "Updating your Cedar version",
83
+ task: (ctx) => updateCedarDepsForAllSides(ctx, { dryRun, verbose }),
84
+ enabled: (ctx) => !!ctx.versionToUpgradeTo
85
+ },
86
+ {
87
+ title: "Updating other packages in your package.json(s)",
88
+ task: (ctx) => updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }),
89
+ enabled: (ctx) => ctx.versionToUpgradeTo?.includes("canary")
90
+ },
91
+ {
92
+ title: "Downloading yarn patches",
93
+ task: (ctx) => downloadYarnPatches(ctx, { dryRun, verbose }),
94
+ enabled: (ctx) => ctx.versionToUpgradeTo?.includes("canary")
95
+ },
96
+ {
97
+ title: "Removing CLI cache",
98
+ task: (ctx) => removeCliCache(ctx, { dryRun, verbose })
99
+ },
100
+ {
101
+ title: "Running yarn install",
102
+ task: (ctx) => yarnInstall(ctx, { dryRun, verbose }),
103
+ skip: () => dryRun
104
+ },
105
+ {
106
+ title: "Refreshing the Prisma client",
107
+ task: (_ctx, task) => refreshPrismaClient(task, { verbose }),
108
+ skip: () => dryRun
109
+ },
110
+ {
111
+ title: "De-duplicating dependencies",
112
+ skip: () => dryRun || !dedupe,
113
+ task: (_ctx, task) => dedupeDeps(task, { verbose })
114
+ },
115
+ {
116
+ title: "One more thing..",
117
+ task: (ctx, task) => {
118
+ const version = ctx.versionToUpgradeTo;
119
+ const messageSections = [
120
+ `One more thing...
121
+
122
+ ${c.warning(
123
+ `\u{1F389} Your project has been upgraded to Cedar ${version}!`
124
+ )}
125
+
126
+ `
127
+ ];
128
+ if ([void 0, "latest", "rc"].includes(tag)) {
129
+ messageSections.push(
130
+ ` Please review the release notes for any manual steps:
131
+ \u2756 ${terminalLink(
132
+ `Redwood community discussion`,
133
+ `https://community.redwoodjs.com/c/announcements/releases-and-upgrade-guides/`
134
+ )}
135
+ \u2756 ${terminalLink(
136
+ `GitHub Release notes`,
137
+ `https://github.com/cedarjs/cedar/releases`
138
+ // intentionally not linking to specific version
139
+ )}
140
+
141
+ `
142
+ );
143
+ }
144
+ if (tag) {
145
+ const additionalMessages = [];
146
+ if (!getConfig().notifications.versionUpdates.includes(tag) && isValidCedarTag(tag)) {
147
+ additionalMessages.push(
148
+ ` \u2756 You may want to update your redwood.toml config so that \`notifications.versionUpdates\` includes "${tag}"
149
+ `
150
+ );
151
+ }
152
+ if (additionalMessages.length > 0) {
153
+ messageSections.push(
154
+ ` \u{1F4E2} ${c.warning(`We'd also like to remind you that:`)}
155
+ `,
156
+ ...additionalMessages
157
+ );
158
+ }
159
+ }
160
+ task.title = messageSections.join("").trimEnd();
161
+ }
162
+ }
163
+ ],
164
+ {
165
+ renderer: verbose && "verbose",
166
+ rendererOptions: { collapseSubtasks: false }
167
+ }
168
+ );
169
+ await tasks.run();
170
+ };
171
+ async function yarnInstall({ verbose }) {
172
+ const yarnVersion = await getCmdMajorVersion("yarn");
173
+ try {
174
+ await execa(
175
+ "yarn install",
176
+ yarnVersion > 1 ? [] : ["--force", "--non-interactive"],
177
+ {
178
+ shell: true,
179
+ stdio: verbose ? "inherit" : "pipe",
180
+ cwd: getPaths().base
181
+ }
182
+ );
183
+ } catch (e) {
184
+ throw new Error(
185
+ "Could not finish installation. Please run `yarn install` and then `yarn dedupe`, before continuing"
186
+ );
187
+ }
188
+ }
189
+ async function removeCliCache(ctx, { dryRun, verbose }) {
190
+ const cliCacheDir = path.join(
191
+ getPaths().generated.base,
192
+ PLUGIN_CACHE_FILENAME
193
+ );
194
+ if (verbose) {
195
+ console.log("Removing CLI cache at: ", cliCacheDir);
196
+ }
197
+ if (!dryRun) {
198
+ fs.removeSync(cliCacheDir);
199
+ }
200
+ }
201
+ async function setLatestVersionToContext(ctx, tag) {
202
+ try {
203
+ const foundVersion = await latestVersion(
204
+ "@cedarjs/core",
205
+ tag ? { version: tag } : {}
206
+ );
207
+ ctx.versionToUpgradeTo = foundVersion;
208
+ return foundVersion;
209
+ } catch (e) {
210
+ if (tag) {
211
+ throw new Error("Could not find the latest `" + tag + "` version");
212
+ }
213
+ throw new Error("Could not find the latest version");
214
+ }
215
+ }
216
+ function updatePackageJsonVersion(pkgPath, version, { dryRun, verbose }) {
217
+ const pkg = JSON.parse(
218
+ fs.readFileSync(path.join(pkgPath, "package.json"), "utf-8")
219
+ );
220
+ if (pkg.dependencies) {
221
+ for (const depName of Object.keys(pkg.dependencies).filter(
222
+ (x) => x.startsWith("@cedarjs/") && x !== "@cedarjs/studio"
223
+ )) {
224
+ if (verbose || dryRun) {
225
+ console.log(` - ${depName}: ${pkg.dependencies[depName]} => ${version}`);
226
+ }
227
+ pkg.dependencies[depName] = `${version}`;
228
+ }
229
+ }
230
+ if (pkg.devDependencies) {
231
+ for (const depName of Object.keys(pkg.devDependencies).filter(
232
+ (x) => x.startsWith("@cedarjs/") && x !== "@cedarjs/studio"
233
+ )) {
234
+ if (verbose || dryRun) {
235
+ console.log(
236
+ ` - ${depName}: ${pkg.devDependencies[depName]} => ${version}`
237
+ );
238
+ }
239
+ pkg.devDependencies[depName] = `${version}`;
240
+ }
241
+ }
242
+ if (!dryRun) {
243
+ fs.writeFileSync(
244
+ path.join(pkgPath, "package.json"),
245
+ JSON.stringify(pkg, void 0, 2)
246
+ );
247
+ }
248
+ }
249
+ function updateCedarDepsForAllSides(ctx, options) {
250
+ if (!ctx.versionToUpgradeTo) {
251
+ throw new Error("Failed to upgrade");
252
+ }
253
+ const updatePaths = [
254
+ getPaths().base,
255
+ getPaths().api.base,
256
+ getPaths().web.base
257
+ ];
258
+ return new Listr(
259
+ updatePaths.map((basePath) => {
260
+ const pkgJsonPath = path.join(basePath, "package.json");
261
+ return {
262
+ title: `Updating ${pkgJsonPath}`,
263
+ task: () => updatePackageJsonVersion(basePath, ctx.versionToUpgradeTo, options),
264
+ skip: () => !fs.existsSync(pkgJsonPath)
265
+ };
266
+ })
267
+ );
268
+ }
269
+ async function updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }) {
270
+ if (!ctx.versionToUpgradeTo) {
271
+ throw new Error("Failed to upgrade");
272
+ }
273
+ const packageJsons = [
274
+ {
275
+ basePath: getPaths().base,
276
+ url: "https://raw.githubusercontent.com/cedarjs/cedar/main/packages/create-cedar-app/templates/ts/package.json"
277
+ },
278
+ {
279
+ basePath: getPaths().api.base,
280
+ url: "https://raw.githubusercontent.com/cedarjs/cedar/main/packages/create-cedar-app/templates/ts/api/package.json"
281
+ },
282
+ {
283
+ basePath: getPaths().web.base,
284
+ url: "https://raw.githubusercontent.com/cedarjs/cedar/main/packages/create-cedar-app/templates/ts/web/package.json"
285
+ }
286
+ ];
287
+ return new Listr(
288
+ packageJsons.map(({ basePath, url }) => {
289
+ const pkgJsonPath = path.join(basePath, "package.json");
290
+ return {
291
+ title: `Updating ${pkgJsonPath}`,
292
+ task: async () => {
293
+ const res = await fetch(url);
294
+ const text = await res.text();
295
+ const templatePackageJson = JSON.parse(text);
296
+ const localPackageJsonText = fs.readFileSync(pkgJsonPath, "utf-8");
297
+ const localPackageJson = JSON.parse(localPackageJsonText);
298
+ Object.entries(templatePackageJson.dependencies || {}).forEach(
299
+ ([depName, depVersion]) => {
300
+ if (!depName.startsWith("@cedarjs/")) {
301
+ if (verbose || dryRun) {
302
+ console.log(
303
+ ` - ${depName}: ${localPackageJson.dependencies[depName]} => ${depVersion}`
304
+ );
305
+ }
306
+ localPackageJson.dependencies[depName] = depVersion;
307
+ }
308
+ }
309
+ );
310
+ Object.entries(templatePackageJson.devDependencies || {}).forEach(
311
+ ([depName, depVersion]) => {
312
+ if (!depName.startsWith("@cedarjs/")) {
313
+ if (verbose || dryRun) {
314
+ console.log(
315
+ ` - ${depName}: ${localPackageJson.devDependencies[depName]} => ${depVersion}`
316
+ );
317
+ }
318
+ localPackageJson.devDependencies[depName] = depVersion;
319
+ }
320
+ }
321
+ );
322
+ if (!dryRun) {
323
+ fs.writeFileSync(
324
+ pkgJsonPath,
325
+ JSON.stringify(localPackageJson, null, 2)
326
+ );
327
+ }
328
+ },
329
+ skip: () => !fs.existsSync(pkgJsonPath)
330
+ };
331
+ })
332
+ );
333
+ }
334
+ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
335
+ if (!ctx.versionToUpgradeTo) {
336
+ throw new Error("Failed to upgrade");
337
+ }
338
+ const githubToken = process.env.GH_TOKEN || process.env.GITHUB_TOKEN || process.env.REDWOOD_GITHUB_TOKEN;
339
+ const res = await fetch(
340
+ "https://api.github.com/repos/cedarjs/cedar/git/trees/main?recursive=1",
341
+ {
342
+ headers: {
343
+ Authorization: githubToken ? `Bearer ${githubToken}` : void 0,
344
+ ["X-GitHub-Api-Version"]: "2022-11-28",
345
+ Accept: "application/vnd.github+json"
346
+ }
347
+ }
348
+ );
349
+ const json = await res.json();
350
+ const patches = json.tree?.filter(
351
+ (patchInfo) => patchInfo.path.startsWith(
352
+ "packages/create-cedar-app/templates/ts/.yarn/patches/"
353
+ )
354
+ );
355
+ const patchDir = path.join(getPaths().base, ".yarn", "patches");
356
+ if (verbose) {
357
+ console.log("Creating patch directory", patchDir);
358
+ }
359
+ if (!dryRun) {
360
+ fs.mkdirSync(patchDir, { recursive: true });
361
+ }
362
+ return new Listr(
363
+ (patches || []).map((patch) => {
364
+ return {
365
+ title: `Downloading ${patch.path}`,
366
+ task: async () => {
367
+ const res2 = await fetch(patch.url);
368
+ const patchMeta = await res2.json();
369
+ const patchPath = path.join(
370
+ getPaths().base,
371
+ ".yarn",
372
+ "patches",
373
+ path.basename(patch.path)
374
+ );
375
+ if (verbose) {
376
+ console.log("Writing patch", patchPath);
377
+ }
378
+ if (!dryRun) {
379
+ await fs.writeFile(patchPath, patchMeta.content, "base64");
380
+ }
381
+ }
382
+ };
383
+ })
384
+ );
385
+ }
386
+ async function refreshPrismaClient(task, { verbose }) {
387
+ try {
388
+ await generatePrismaClient({
389
+ verbose,
390
+ force: false,
391
+ schema: getPaths().api.dbSchema
392
+ });
393
+ } catch (e) {
394
+ task.skip("Refreshing the Prisma client caused an Error.");
395
+ console.log(
396
+ "You may need to update your prisma client manually: $ yarn rw prisma generate"
397
+ );
398
+ console.log(c.error(e.message));
399
+ }
400
+ }
401
+ const getCmdMajorVersion = async (command2) => {
402
+ const { stdout } = await execa(command2, ["--version"], {
403
+ cwd: getPaths().base
404
+ });
405
+ if (!SEMVER_REGEX.test(stdout)) {
406
+ throw new Error(`Unable to verify ${command2} version.`);
407
+ }
408
+ const version = stdout.match(SEMVER_REGEX)[0];
409
+ return parseInt(version.split(".")[0]);
410
+ };
411
+ const dedupeDeps = async (task, { verbose }) => {
412
+ try {
413
+ const yarnVersion = await getCmdMajorVersion("yarn");
414
+ const baseExecaArgsForDedupe = {
415
+ shell: true,
416
+ stdio: verbose ? "inherit" : "pipe",
417
+ cwd: getPaths().base
418
+ };
419
+ if (yarnVersion > 1) {
420
+ await execa("yarn", ["dedupe"], baseExecaArgsForDedupe);
421
+ } else {
422
+ task.skip(
423
+ "Yarn 1.x doesn't support dedupe directly. Please upgrade yarn or use npx with `npx yarn-deduplicate` manually."
424
+ );
425
+ }
426
+ } catch (e) {
427
+ console.log(c.error(e.message));
428
+ throw new Error(
429
+ "Could not finish de-duplication. For yarn 1.x, please run `npx yarn-deduplicate`, or for yarn >= 3 run `yarn dedupe` before continuing"
430
+ );
431
+ }
432
+ await yarnInstall({ verbose });
433
+ };
434
+ export {
435
+ builder,
436
+ command,
437
+ description,
438
+ getCmdMajorVersion,
439
+ handler,
440
+ validateTag
441
+ };
File without changes
package/dist/index.js ADDED
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env node
2
+ import path from "path";
3
+ import { trace, SpanStatusCode } from "@opentelemetry/api";
4
+ import fs from "fs-extra";
5
+ import { hideBin, Parser } from "yargs/helpers";
6
+ import yargs from "yargs/yargs";
7
+ import { loadEnvFiles, recordTelemetryAttributes } from "@cedarjs/cli-helpers";
8
+ import { telemetryMiddleware } from "@cedarjs/telemetry";
9
+ import * as buildCommand from "./commands/build.js";
10
+ import * as checkCommand from "./commands/check.js";
11
+ import * as consoleCommand from "./commands/console.js";
12
+ import * as deployCommand from "./commands/deploy.js";
13
+ import * as destroyCommand from "./commands/destroy.js";
14
+ import * as devCommand from "./commands/dev.js";
15
+ import * as execCommand from "./commands/exec.js";
16
+ import * as experimentalCommand from "./commands/experimental.js";
17
+ import * as generateCommand from "./commands/generate.js";
18
+ import * as infoCommand from "./commands/info.js";
19
+ import * as jobsCommand from "./commands/jobs.js";
20
+ import * as lintCommand from "./commands/lint.js";
21
+ import * as prerenderCommand from "./commands/prerender.js";
22
+ import * as prismaCommand from "./commands/prisma.js";
23
+ import * as recordCommand from "./commands/record.js";
24
+ import * as serveCommand from "./commands/serve.js";
25
+ import * as setupCommand from "./commands/setup.js";
26
+ import * as studioCommand from "./commands/studio.js";
27
+ import * as testCommand from "./commands/test.js";
28
+ import * as tstojsCommand from "./commands/ts-to-js.js";
29
+ import * as typeCheckCommand from "./commands/type-check.js";
30
+ import * as upgradeCommand from "./commands/upgrade.js";
31
+ import { exitWithError } from "./lib/exit.js";
32
+ import { findUp } from "./lib/index.js";
33
+ import * as updateCheck from "./lib/updateCheck.js";
34
+ import { loadPlugins } from "./plugin.js";
35
+ import { startTelemetry, shutdownTelemetry } from "./telemetry/index.js";
36
+ let { cwd, telemetry, help, version } = Parser(hideBin(process.argv), {
37
+ // Telemetry is enabled by default, but can be disabled in two ways
38
+ // - by passing a `--telemetry false` option
39
+ // - by setting a `REDWOOD_DISABLE_TELEMETRY` env var
40
+ boolean: ["telemetry"],
41
+ default: {
42
+ telemetry: process.env.REDWOOD_DISABLE_TELEMETRY === void 0 || process.env.REDWOOD_DISABLE_TELEMETRY === ""
43
+ }
44
+ });
45
+ cwd ??= process.env.RWJS_CWD;
46
+ try {
47
+ if (cwd) {
48
+ if (!fs.existsSync(path.join(cwd, "redwood.toml"))) {
49
+ throw new Error(`Couldn't find a "redwood.toml" file in ${cwd}`);
50
+ }
51
+ } else {
52
+ const redwoodTOMLPath = findUp("redwood.toml");
53
+ if (!redwoodTOMLPath) {
54
+ throw new Error(
55
+ `Couldn't find up a "redwood.toml" file from ${process.cwd()}`
56
+ );
57
+ }
58
+ cwd = path.dirname(redwoodTOMLPath);
59
+ }
60
+ } catch (error) {
61
+ console.error(error.message);
62
+ process.exit(1);
63
+ }
64
+ process.env.RWJS_CWD = cwd;
65
+ if (process.cwd() !== cwd) {
66
+ process.chdir(cwd);
67
+ }
68
+ loadEnvFiles();
69
+ async function main() {
70
+ if (telemetry) {
71
+ startTelemetry();
72
+ }
73
+ const tracer = trace.getTracer("redwoodjs");
74
+ await tracer.startActiveSpan("cli", async (span) => {
75
+ const telemetryTimeoutTimer = setTimeout(() => {
76
+ shutdownTelemetry();
77
+ }, 5 * 6e4);
78
+ if (version) {
79
+ recordTelemetryAttributes({ command: "--version" });
80
+ }
81
+ if (help) {
82
+ recordTelemetryAttributes({ command: "--help" });
83
+ }
84
+ try {
85
+ await runYargs();
86
+ } catch (error) {
87
+ exitWithError(error);
88
+ }
89
+ if (span?.isRecording()) {
90
+ span?.setStatus({ code: SpanStatusCode.OK });
91
+ span?.end();
92
+ }
93
+ clearTimeout(telemetryTimeoutTimer);
94
+ });
95
+ if (telemetry) {
96
+ shutdownTelemetry();
97
+ }
98
+ }
99
+ async function runYargs() {
100
+ const yarg = yargs(hideBin(process.argv)).scriptName("rw").middleware(
101
+ [
102
+ // We've already handled `cwd` above, but it may still be in `argv`.
103
+ // We don't need it anymore so let's get rid of it.
104
+ // Likewise for `telemetry`.
105
+ (argv) => {
106
+ delete argv.cwd;
107
+ delete argv.addEnvFiles;
108
+ delete argv["load-env-files"];
109
+ delete argv.telemetry;
110
+ },
111
+ telemetry && telemetryMiddleware,
112
+ updateCheck.isEnabled() && updateCheck.updateCheckMiddleware
113
+ ].filter(Boolean)
114
+ ).option("cwd", {
115
+ describe: "Working directory to use (where `redwood.toml` is located)"
116
+ }).option("load-env-files", {
117
+ describe: "Load additional .env files. Values defined in files specified later override earlier ones.",
118
+ array: true
119
+ }).example(
120
+ "yarn rw exec migrateUsers --load-env-files stripe nakama",
121
+ "Run a script, also loading env vars from '.env.stripe' and '.env.nakama'"
122
+ ).option("telemetry", {
123
+ describe: "Whether to send anonymous usage telemetry to RedwoodJS",
124
+ boolean: true
125
+ // hidden: true,
126
+ }).example(
127
+ "yarn rw g page home /",
128
+ "Create a page component named 'Home' at path '/'"
129
+ ).demandCommand().strict().exitProcess(false).alias("h", "help").command(buildCommand).command(checkCommand).command(consoleCommand).command(deployCommand).command(destroyCommand).command(devCommand).command(execCommand).command(experimentalCommand).command(generateCommand).command(infoCommand).command(jobsCommand).command(lintCommand).command(prerenderCommand).command(prismaCommand).command(recordCommand).command(serveCommand).command(setupCommand).command(studioCommand).command(testCommand).command(tstojsCommand).command(typeCheckCommand).command(upgradeCommand);
130
+ await loadPlugins(yarg);
131
+ const pkgJson = await import("../package.json", { with: { type: "json" } });
132
+ yarg.version(pkgJson.default["version"]);
133
+ await yarg.parse(process.argv.slice(2), {}, (err, _argv, output) => {
134
+ if (err) {
135
+ process.exitCode = 1;
136
+ }
137
+ if (output) {
138
+ if (err) {
139
+ console.error(output);
140
+ } else {
141
+ console.log(output);
142
+ }
143
+ }
144
+ });
145
+ }
146
+ main();
@@ -0,0 +1,45 @@
1
+ import { spawn } from "child_process";
2
+ import os from "os";
3
+ import path from "path";
4
+ import fs from "fs-extra";
5
+ import { getPaths } from "@cedarjs/project-config";
6
+ function spawnBackgroundProcess(name, cmd, args) {
7
+ const logDirectory = path.join(getPaths().generated.base, "logs");
8
+ fs.ensureDirSync(logDirectory);
9
+ const safeName = name.replace(/[^a-z0-9]/gi, "_").toLowerCase();
10
+ const logHeader = [
11
+ `Starting log:`,
12
+ ` - Time: ${(/* @__PURE__ */ new Date()).toISOString()}`,
13
+ ` - Name: ${name} (${safeName})`,
14
+ ` - Command: ${cmd}`,
15
+ ` - Arguments: ${args.join(" ")}`,
16
+ "",
17
+ ""
18
+ ].join("\n");
19
+ const stdout = fs.openSync(
20
+ path.join(logDirectory, `${safeName}.out.log`),
21
+ "w"
22
+ );
23
+ fs.writeSync(stdout, logHeader);
24
+ const stderr = fs.openSync(
25
+ path.join(logDirectory, `${safeName}.err.log`),
26
+ "w"
27
+ );
28
+ fs.writeSync(stderr, logHeader);
29
+ const spawnOptions = os.type() === "Windows_NT" ? {
30
+ // The following options run the process in the background without a console window, even though they don't look like they would.
31
+ // See https://github.com/nodejs/node/issues/21825#issuecomment-503766781 for information
32
+ detached: false,
33
+ windowsHide: false,
34
+ shell: true,
35
+ stdio: ["ignore", stdout, stderr]
36
+ } : {
37
+ detached: true,
38
+ stdio: ["ignore", stdout, stderr]
39
+ };
40
+ const child = spawn(cmd, args, spawnOptions);
41
+ child.unref();
42
+ }
43
+ export {
44
+ spawnBackgroundProcess
45
+ };