@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.
- package/LICENSE +21 -0
- package/README.md +706 -0
- package/dist/commands/build.js +54 -0
- package/dist/commands/buildHandler.js +134 -0
- package/dist/commands/check.js +28 -0
- package/dist/commands/console.js +13 -0
- package/dist/commands/consoleHandler.js +68 -0
- package/dist/commands/deploy/baremetal/SshExecutor.js +41 -0
- package/dist/commands/deploy/baremetal/baremetalHandler.js +558 -0
- package/dist/commands/deploy/baremetal.js +89 -0
- package/dist/commands/deploy/flightcontrol.js +40 -0
- package/dist/commands/deploy/flightcontrolHandler.js +58 -0
- package/dist/commands/deploy/helpers/deployBuilder.js +25 -0
- package/dist/commands/deploy/helpers/deployHandler.js +31 -0
- package/dist/commands/deploy/netlify.js +21 -0
- package/dist/commands/deploy/packing/nft.js +61 -0
- package/dist/commands/deploy/render.js +37 -0
- package/dist/commands/deploy/renderHandler.js +70 -0
- package/dist/commands/deploy/serverless.js +51 -0
- package/dist/commands/deploy/serverlessHandler.js +211 -0
- package/dist/commands/deploy/vercel.js +21 -0
- package/dist/commands/deploy.js +21 -0
- package/dist/commands/destroy/cell/cell.js +12 -0
- package/dist/commands/destroy/cell/cellHandler.js +10 -0
- package/dist/commands/destroy/component/component.js +15 -0
- package/dist/commands/destroy/component/componentHandler.js +10 -0
- package/dist/commands/destroy/directive/directive.js +14 -0
- package/dist/commands/destroy/directive/directiveHandler.js +12 -0
- package/dist/commands/destroy/function/function.js +20 -0
- package/dist/commands/destroy/function/functionHandler.js +10 -0
- package/dist/commands/destroy/handlerHelpers.js +34 -0
- package/dist/commands/destroy/helpers.js +22 -0
- package/dist/commands/destroy/layout/layout.js +12 -0
- package/dist/commands/destroy/layout/layoutHandler.js +10 -0
- package/dist/commands/destroy/page/page.js +20 -0
- package/dist/commands/destroy/page/pageHandler.js +51 -0
- package/dist/commands/destroy/scaffold/scaffold.js +16 -0
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +105 -0
- package/dist/commands/destroy/sdl/sdl.js +16 -0
- package/dist/commands/destroy/sdl/sdlHandler.js +33 -0
- package/dist/commands/destroy/service/service.js +10 -0
- package/dist/commands/destroy/service/serviceHandler.js +17 -0
- package/dist/commands/destroy.js +25 -0
- package/dist/commands/dev.js +47 -0
- package/dist/commands/devHandler.js +202 -0
- package/dist/commands/exec.js +38 -0
- package/dist/commands/execHandler.js +180 -0
- package/dist/commands/experimental/setupInngest.js +28 -0
- package/dist/commands/experimental/setupInngestHandler.js +46 -0
- package/dist/commands/experimental/setupOpentelemetry.js +34 -0
- package/dist/commands/experimental/setupOpentelemetryHandler.js +215 -0
- package/dist/commands/experimental/setupReactCompiler.js +28 -0
- package/dist/commands/experimental/setupReactCompilerHandler.js +124 -0
- package/dist/commands/experimental/setupRsc.js +28 -0
- package/dist/commands/experimental/setupRscHandler.js +408 -0
- package/dist/commands/experimental/setupStreamingSsr.js +28 -0
- package/dist/commands/experimental/setupStreamingSsrHandler.js +208 -0
- package/dist/commands/experimental/templates/opentelemetry.ts.template +55 -0
- package/dist/commands/experimental/templates/rsc/AboutCounter.tsx.template +20 -0
- package/dist/commands/experimental/templates/rsc/AboutPage.css.template +2 -0
- package/dist/commands/experimental/templates/rsc/AboutPage.tsx.template +17 -0
- package/dist/commands/experimental/templates/rsc/Counter.css.template +7 -0
- package/dist/commands/experimental/templates/rsc/Counter.module.css.template +3 -0
- package/dist/commands/experimental/templates/rsc/Counter.tsx.template +18 -0
- package/dist/commands/experimental/templates/rsc/Document.tsx.template +27 -0
- package/dist/commands/experimental/templates/rsc/HomePage.css.template +2 -0
- package/dist/commands/experimental/templates/rsc/HomePage.module.css.template +3 -0
- package/dist/commands/experimental/templates/rsc/HomePage.tsx.template +19 -0
- package/dist/commands/experimental/templates/rsc/NavigationLayout.css.template +32 -0
- package/dist/commands/experimental/templates/rsc/NavigationLayout.tsx.template +31 -0
- package/dist/commands/experimental/templates/rsc/Routes.tsx.template +29 -0
- package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +35 -0
- package/dist/commands/experimental/templates/rsc/entry.server.tsx.template +20 -0
- package/dist/commands/experimental/templates/rsc/index.css.template +4 -0
- package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +27 -0
- package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +40 -0
- package/dist/commands/experimental/templates/streamingSsr/entry.server.tsx.template +20 -0
- package/dist/commands/experimental/templates/streamingSsr/tsconfig.json.template +54 -0
- package/dist/commands/experimental/util.js +69 -0
- package/dist/commands/experimental.js +22 -0
- package/dist/commands/generate/cell/cell.js +35 -0
- package/dist/commands/generate/cell/cellHandler.js +153 -0
- package/dist/commands/generate/cell/templates/cell.tsx.template +34 -0
- package/dist/commands/generate/cell/templates/cellList.tsx.template +40 -0
- package/dist/commands/generate/cell/templates/mock.ts.template +7 -0
- package/dist/commands/generate/cell/templates/mockList.ts.template +14 -0
- package/dist/commands/generate/cell/templates/stories.tsx.template +35 -0
- package/dist/commands/generate/cell/templates/test.js.template +42 -0
- package/dist/commands/generate/cell/utils/utils.js +43 -0
- package/dist/commands/generate/component/component.js +15 -0
- package/dist/commands/generate/component/componentHandler.js +55 -0
- package/dist/commands/generate/component/templates/component.tsx.template +10 -0
- package/dist/commands/generate/component/templates/stories.jsx.template +17 -0
- package/dist/commands/generate/component/templates/stories.tsx.template +26 -0
- package/dist/commands/generate/component/templates/test.tsx.template +14 -0
- package/dist/commands/generate/dataMigration/dataMigration.js +105 -0
- package/dist/commands/generate/dataMigration/templates/dataMigration.js.template +7 -0
- package/dist/commands/generate/dataMigration/templates/dataMigration.ts.template +5 -0
- package/dist/commands/generate/dbAuth/dbAuth.js +55 -0
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +375 -0
- package/dist/commands/generate/dbAuth/templates/forgotPassword.tsx.template +94 -0
- package/dist/commands/generate/dbAuth/templates/login.tsx.template +130 -0
- package/dist/commands/generate/dbAuth/templates/login.webAuthn.tsx.template +264 -0
- package/dist/commands/generate/dbAuth/templates/resetPassword.tsx.template +121 -0
- package/dist/commands/generate/dbAuth/templates/signup.tsx.template +123 -0
- package/dist/commands/generate/directive/directive.js +15 -0
- package/dist/commands/generate/directive/directiveHandler.js +159 -0
- package/dist/commands/generate/directive/templates/transformer.directive.test.ts.template +18 -0
- package/dist/commands/generate/directive/templates/transformer.directive.ts.template +38 -0
- package/dist/commands/generate/directive/templates/validator.directive.test.ts.template +17 -0
- package/dist/commands/generate/directive/templates/validator.directive.ts.template +39 -0
- package/dist/commands/generate/function/function.js +29 -0
- package/dist/commands/generate/function/functionHandler.js +131 -0
- package/dist/commands/generate/function/templates/function.ts.template +33 -0
- package/dist/commands/generate/function/templates/scenarios.ts.template +8 -0
- package/dist/commands/generate/function/templates/test.ts.template +30 -0
- package/dist/commands/generate/helpers.js +71 -0
- package/dist/commands/generate/job/job.js +39 -0
- package/dist/commands/generate/job/jobHandler.js +138 -0
- package/dist/commands/generate/job/templates/job.ts.template +8 -0
- package/dist/commands/generate/job/templates/scenarios.ts.template +8 -0
- package/dist/commands/generate/job/templates/test.ts.template +7 -0
- package/dist/commands/generate/layout/layout.js +25 -0
- package/dist/commands/generate/layout/layoutHandler.js +59 -0
- package/dist/commands/generate/layout/templates/layout.tsx.a11y.template +27 -0
- package/dist/commands/generate/layout/templates/layout.tsx.template +9 -0
- package/dist/commands/generate/layout/templates/stories.tsx.template +13 -0
- package/dist/commands/generate/layout/templates/test.tsx.template +14 -0
- package/dist/commands/generate/model/model.js +29 -0
- package/dist/commands/generate/model/modelHandler.js +63 -0
- package/dist/commands/generate/model/templates/model.js.template +3 -0
- package/dist/commands/generate/ogImage/ogImage.js +43 -0
- package/dist/commands/generate/ogImage/ogImageHandler.js +111 -0
- package/dist/commands/generate/ogImage/templates/ogImage.og.tsx.template +13 -0
- package/dist/commands/generate/page/page.js +22 -0
- package/dist/commands/generate/page/pageHandler.js +227 -0
- package/dist/commands/generate/page/templates/page.tsx.template +35 -0
- package/dist/commands/generate/page/templates/stories.tsx.parameters.template +13 -0
- package/dist/commands/generate/page/templates/stories.tsx.template +13 -0
- package/dist/commands/generate/page/templates/test.tsx.template +14 -0
- package/dist/commands/generate/realtime/realtime.js +41 -0
- package/dist/commands/generate/realtime/realtimeHandler.js +215 -0
- package/dist/commands/generate/realtime/templates/liveQueries/blank/blank.sdl.ts.template +27 -0
- package/dist/commands/generate/realtime/templates/liveQueries/blank/blank.service.ts.template +73 -0
- package/dist/commands/generate/realtime/templates/realtime.ts.template +42 -0
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.sdl.ts.template +20 -0
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.service.ts.template +19 -0
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +58 -0
- package/dist/commands/generate/scaffold/scaffold.js +38 -0
- package/dist/commands/generate/scaffold/scaffoldHandler.js +663 -0
- package/dist/commands/generate/scaffold/templates/assets/scaffold.css.template +398 -0
- package/dist/commands/generate/scaffold/templates/assets/scaffold.tailwind.css.template +243 -0
- package/dist/commands/generate/scaffold/templates/components/EditNameCell.tsx.template +74 -0
- package/dist/commands/generate/scaffold/templates/components/Name.tsx.template +79 -0
- package/dist/commands/generate/scaffold/templates/components/NameCell.tsx.template +32 -0
- package/dist/commands/generate/scaffold/templates/components/NameForm.tsx.template +123 -0
- package/dist/commands/generate/scaffold/templates/components/Names.tsx.template +88 -0
- package/dist/commands/generate/scaffold/templates/components/NamesCell.tsx.template +45 -0
- package/dist/commands/generate/scaffold/templates/components/NewName.tsx.template +55 -0
- package/dist/commands/generate/scaffold/templates/layouts/ScaffoldLayout.tsx.template +37 -0
- package/dist/commands/generate/scaffold/templates/lib/formatters.test.tsx.template +192 -0
- package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +58 -0
- package/dist/commands/generate/scaffold/templates/pages/EditNamePage.tsx.template +11 -0
- package/dist/commands/generate/scaffold/templates/pages/NamePage.tsx.template +11 -0
- package/dist/commands/generate/scaffold/templates/pages/NamesPage.tsx.template +7 -0
- package/dist/commands/generate/scaffold/templates/pages/NewNamePage.tsx.template +7 -0
- package/dist/commands/generate/script/script.js +29 -0
- package/dist/commands/generate/script/scriptHandler.js +85 -0
- package/dist/commands/generate/script/templates/script.ts.template +15 -0
- package/dist/commands/generate/script/templates/tsconfig.json.template +33 -0
- package/dist/commands/generate/sdl/sdl.js +48 -0
- package/dist/commands/generate/sdl/sdlHandler.js +282 -0
- package/dist/commands/generate/sdl/templates/sdl.js.template +70 -0
- package/dist/commands/generate/sdl/templates/sdl.ts.template +70 -0
- package/dist/commands/generate/secret/secret.js +52 -0
- package/dist/commands/generate/service/service.js +50 -0
- package/dist/commands/generate/service/serviceHandler.js +301 -0
- package/dist/commands/generate/service/templates/scenarios.ts.template +7 -0
- package/dist/commands/generate/service/templates/service.ts.template +38 -0
- package/dist/commands/generate/service/templates/test.ts.template +84 -0
- package/dist/commands/generate/yargsCommandHelpers.js +77 -0
- package/dist/commands/generate/yargsHandlerHelpers.js +155 -0
- package/dist/commands/generate.js +44 -0
- package/dist/commands/info.js +36 -0
- package/dist/commands/jobs.js +17 -0
- package/dist/commands/jobsHandler.js +30 -0
- package/dist/commands/lint.js +57 -0
- package/dist/commands/prerender.js +34 -0
- package/dist/commands/prerenderHandler.js +282 -0
- package/dist/commands/prisma.js +17 -0
- package/dist/commands/prismaHandler.js +90 -0
- package/dist/commands/record/init.js +11 -0
- package/dist/commands/record.js +19 -0
- package/dist/commands/serve.js +139 -0
- package/dist/commands/serveApiHandler.js +15 -0
- package/dist/commands/serveBothHandler.js +95 -0
- package/dist/commands/serveWebHandler.js +17 -0
- package/dist/commands/setup/auth/auth.js +265 -0
- package/dist/commands/setup/cache/cache.js +37 -0
- package/dist/commands/setup/cache/cacheHandler.js +69 -0
- package/dist/commands/setup/cache/templates/memcached.ts.template +30 -0
- package/dist/commands/setup/cache/templates/redis.ts.template +24 -0
- package/dist/commands/setup/deploy/deploy.js +26 -0
- package/dist/commands/setup/deploy/helpers/helpers.js +9 -0
- package/dist/commands/setup/deploy/helpers/index.js +110 -0
- package/dist/commands/setup/deploy/providers/baremetal.js +9 -0
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +64 -0
- package/dist/commands/setup/deploy/providers/coherence.js +24 -0
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +203 -0
- package/dist/commands/setup/deploy/providers/flightcontrol.js +19 -0
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +294 -0
- package/dist/commands/setup/deploy/providers/netlify.js +9 -0
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +42 -0
- package/dist/commands/setup/deploy/providers/render.js +17 -0
- package/dist/commands/setup/deploy/providers/renderHandler.js +111 -0
- package/dist/commands/setup/deploy/providers/serverless.js +11 -0
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +141 -0
- package/dist/commands/setup/deploy/providers/vercel.js +9 -0
- package/dist/commands/setup/deploy/providers/vercelHandler.js +56 -0
- package/dist/commands/setup/deploy/templates/baremetal.js +128 -0
- package/dist/commands/setup/deploy/templates/flightcontrol.js +85 -0
- package/dist/commands/setup/deploy/templates/netlify.js +32 -0
- package/dist/commands/setup/deploy/templates/render.js +72 -0
- package/dist/commands/setup/deploy/templates/serverless/api.js +78 -0
- package/dist/commands/setup/deploy/templates/serverless/web.js +32 -0
- package/dist/commands/setup/docker/docker.js +26 -0
- package/dist/commands/setup/docker/dockerHandler.js +265 -0
- package/dist/commands/setup/docker/templates/Dockerfile +154 -0
- package/dist/commands/setup/docker/templates/docker-compose.dev.yml +58 -0
- package/dist/commands/setup/docker/templates/docker-compose.prod.yml +63 -0
- package/dist/commands/setup/docker/templates/dockerignore +18 -0
- package/dist/commands/setup/generator/generator.js +49 -0
- package/dist/commands/setup/generator/generatorHandler.js +55 -0
- package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +117 -0
- package/dist/commands/setup/graphql/features/fragments/appImportTransform.js +20 -0
- package/dist/commands/setup/graphql/features/fragments/fragments.js +25 -0
- package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +89 -0
- package/dist/commands/setup/graphql/features/trustedDocuments/graphqlTransform.js +51 -0
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +25 -0
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +74 -0
- package/dist/commands/setup/graphql/graphql.js +18 -0
- package/dist/commands/setup/i18n/i18n.js +25 -0
- package/dist/commands/setup/i18n/i18nHandler.js +169 -0
- package/dist/commands/setup/i18n/templates/en.json.template +11 -0
- package/dist/commands/setup/i18n/templates/fr.json.template +11 -0
- package/dist/commands/setup/i18n/templates/i18n.js.template +52 -0
- package/dist/commands/setup/i18n/templates/storybook.preview.tsx.template +43 -0
- package/dist/commands/setup/jobs/jobs.js +31 -0
- package/dist/commands/setup/jobs/jobsHandler.js +122 -0
- package/dist/commands/setup/jobs/templates/jobs.ts.template +32 -0
- package/dist/commands/setup/mailer/mailer.js +30 -0
- package/dist/commands/setup/mailer/mailerHandler.js +106 -0
- package/dist/commands/setup/mailer/templates/mailer.ts.template +30 -0
- package/dist/commands/setup/mailer/templates/re-example.tsx.template +40 -0
- package/dist/commands/setup/middleware/middleware.js +17 -0
- package/dist/commands/setup/middleware/ogImage/__codemod_tests__/middleware.js +15 -0
- package/dist/commands/setup/middleware/ogImage/__codemod_tests__/vitePlugin.js +6 -0
- package/dist/commands/setup/middleware/ogImage/codemodMiddleware.js +97 -0
- package/dist/commands/setup/middleware/ogImage/codemodVitePlugin.js +65 -0
- package/dist/commands/setup/middleware/ogImage/ogImage.js +27 -0
- package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +121 -0
- package/dist/commands/setup/monitoring/monitoring.js +17 -0
- package/dist/commands/setup/monitoring/sentry/sentry.js +25 -0
- package/dist/commands/setup/monitoring/sentry/sentryHandler.js +163 -0
- package/dist/commands/setup/monitoring/sentry/templates/sentryApi.ts.template +15 -0
- package/dist/commands/setup/monitoring/sentry/templates/sentryWeb.ts.template +31 -0
- package/dist/commands/setup/package/package.js +33 -0
- package/dist/commands/setup/package/packageHandler.js +134 -0
- package/dist/commands/setup/realtime/realtime.js +37 -0
- package/dist/commands/setup/realtime/realtimeHandler.js +309 -0
- package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.sdl.template +14 -0
- package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.ts.template +14 -0
- package/dist/commands/setup/realtime/templates/liveQueries/auctions/auctions.sdl.ts.template +27 -0
- package/dist/commands/setup/realtime/templates/liveQueries/auctions/auctions.ts.template +73 -0
- package/dist/commands/setup/realtime/templates/realtime.ts.template +46 -0
- package/dist/commands/setup/realtime/templates/stream/alphabet/alphabet.sdl.template +9 -0
- package/dist/commands/setup/realtime/templates/stream/alphabet/alphabet.ts.template +31 -0
- package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +58 -0
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +57 -0
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/rooms.sdl.ts.template +20 -0
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/rooms.ts.template +20 -0
- package/dist/commands/setup/server-file/serverFile.js +31 -0
- package/dist/commands/setup/server-file/serverFileHandler.js +56 -0
- package/dist/commands/setup/server-file/templates/server.ts.template +13 -0
- package/dist/commands/setup/tsconfig/tsconfig.js +25 -0
- package/dist/commands/setup/tsconfig/tsconfigHandler.js +59 -0
- package/dist/commands/setup/ui/helpers/helpers.js +9 -0
- package/dist/commands/setup/ui/libraries/chakra-ui.js +24 -0
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +98 -0
- package/dist/commands/setup/ui/libraries/mantine.js +32 -0
- package/dist/commands/setup/ui/libraries/mantineHandler.js +138 -0
- package/dist/commands/setup/ui/libraries/tailwindcss.js +26 -0
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +386 -0
- package/dist/commands/setup/ui/templates/chakra.storybook.preview.tsx.template +20 -0
- package/dist/commands/setup/ui/templates/mantine-postcss.config.js.template +35 -0
- package/dist/commands/setup/ui/templates/mantine.storybook.preview.tsx.template +18 -0
- package/dist/commands/setup/ui/templates/postcss.config.js.template +9 -0
- package/dist/commands/setup/ui/ui.js +17 -0
- package/dist/commands/setup/uploads/dbCodemod.js +28 -0
- package/dist/commands/setup/uploads/templates/signedUrl.ts.template +21 -0
- package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +25 -0
- package/dist/commands/setup/uploads/uploads.js +26 -0
- package/dist/commands/setup/uploads/uploadsHandler.js +147 -0
- package/dist/commands/setup/vite/templates/vite.config.ts.template +19 -0
- package/dist/commands/setup/vite/vite.js +38 -0
- package/dist/commands/setup/vite/viteHandler.js +83 -0
- package/dist/commands/setup.js +33 -0
- package/dist/commands/studio.js +23 -0
- package/dist/commands/studioHandler.js +61 -0
- package/dist/commands/test.js +44 -0
- package/dist/commands/testHandler.js +138 -0
- package/dist/commands/ts-to-js.js +20 -0
- package/dist/commands/type-check.js +41 -0
- package/dist/commands/type-checkHandler.js +71 -0
- package/dist/commands/upgrade.js +441 -0
- package/dist/index.d.js +0 -0
- package/dist/index.js +146 -0
- package/dist/lib/background.js +45 -0
- package/dist/lib/colors.js +18 -0
- package/dist/lib/configureStorybook.js +50 -0
- package/dist/lib/exec.js +85 -0
- package/dist/lib/exit.js +44 -0
- package/dist/lib/extendFile.js +114 -0
- package/dist/lib/generatePrismaClient.js +60 -0
- package/dist/lib/index.js +485 -0
- package/dist/lib/loadEnvFiles.js +12 -0
- package/dist/lib/locking.js +60 -0
- package/dist/lib/merge/algorithms.js +30 -0
- package/dist/lib/merge/index.js +163 -0
- package/dist/lib/merge/semanticIdentity.js +18 -0
- package/dist/lib/merge/strategy.js +136 -0
- package/dist/lib/mockTelemetry.js +7 -0
- package/dist/lib/packages.js +77 -0
- package/dist/lib/plugin.js +206 -0
- package/dist/lib/pluralHelpers.js +50 -0
- package/dist/lib/ports.js +17 -0
- package/dist/lib/project.js +30 -0
- package/dist/lib/rollback.js +72 -0
- package/dist/lib/runTransform.js +66 -0
- package/dist/lib/rwPluralize.js +56 -0
- package/dist/lib/schemaHelpers.js +95 -0
- package/dist/lib/templates/storybook.preview.tsx.template +19 -0
- package/dist/lib/test.js +106 -0
- package/dist/lib/updateCheck.js +202 -0
- package/dist/lib/updateCheckExecute.js +2 -0
- package/dist/middleware/checkNodeVersion.js +23 -0
- package/dist/middleware/detectProjectRxVersion.js +12 -0
- package/dist/plugin.js +223 -0
- package/dist/rwfw.js +47 -0
- package/dist/telemetry/exporter.js +63 -0
- package/dist/telemetry/index.js +84 -0
- package/dist/telemetry/resource.js +98 -0
- package/dist/telemetry/send.js +80 -0
- package/dist/testLib/cells.js +188 -0
- package/dist/testLib/fetchFileFromTemplate.js +9 -0
- package/dist/testLib/getFilesWithPattern.js +21 -0
- package/dist/testLib/getRootPackageJSON.js +14 -0
- package/dist/testLib/isTSProject.js +9 -0
- package/dist/testLib/runTransform.js +42 -0
- package/package.json +102 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { getPaths } from "./index.js";
|
|
4
|
+
const isTypeScriptProject = () => {
|
|
5
|
+
const paths = getPaths();
|
|
6
|
+
return fs.existsSync(path.join(paths.web.base, "tsconfig.json")) || fs.existsSync(path.join(paths.api.base, "tsconfig.json"));
|
|
7
|
+
};
|
|
8
|
+
const sides = () => {
|
|
9
|
+
const paths = getPaths();
|
|
10
|
+
let sides2 = [];
|
|
11
|
+
if (fs.existsSync(path.join(paths.web.base, "package.json"))) {
|
|
12
|
+
sides2 = [...sides2, "web"];
|
|
13
|
+
}
|
|
14
|
+
if (fs.existsSync(path.join(paths.api.base, "package.json"))) {
|
|
15
|
+
sides2 = [...sides2, "api"];
|
|
16
|
+
}
|
|
17
|
+
return sides2;
|
|
18
|
+
};
|
|
19
|
+
const serverFileExists = () => {
|
|
20
|
+
const serverFilePath = path.join(
|
|
21
|
+
getPaths().api.src,
|
|
22
|
+
`server.${isTypeScriptProject() ? "ts" : "js"}`
|
|
23
|
+
);
|
|
24
|
+
return fs.existsSync(serverFilePath);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
isTypeScriptProject,
|
|
28
|
+
serverFileExists,
|
|
29
|
+
sides
|
|
30
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
let rollback = [];
|
|
4
|
+
function addFunctionToRollback(func, atEnd = false) {
|
|
5
|
+
const step = { type: "func", func };
|
|
6
|
+
if (atEnd) {
|
|
7
|
+
rollback.unshift(step);
|
|
8
|
+
} else {
|
|
9
|
+
rollback.push(step);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function addFileToRollback(path2, atEnd = false) {
|
|
13
|
+
const step = {
|
|
14
|
+
type: "file",
|
|
15
|
+
path: path2,
|
|
16
|
+
content: fs.existsSync(path2) ? fs.readFileSync(path2) : null
|
|
17
|
+
};
|
|
18
|
+
if (atEnd) {
|
|
19
|
+
rollback.unshift(step);
|
|
20
|
+
} else {
|
|
21
|
+
rollback.push(step);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function executeRollback(_ = null, task = null) {
|
|
25
|
+
if (task) {
|
|
26
|
+
task.title = "Reverting generator actions...";
|
|
27
|
+
}
|
|
28
|
+
while (rollback.length > 0) {
|
|
29
|
+
const step = rollback.pop();
|
|
30
|
+
switch (step.type) {
|
|
31
|
+
case "func":
|
|
32
|
+
await step.func();
|
|
33
|
+
break;
|
|
34
|
+
case "file":
|
|
35
|
+
if (step.content === null) {
|
|
36
|
+
fs.unlinkSync(step.path);
|
|
37
|
+
let parent = path.dirname(step.path);
|
|
38
|
+
if (parent !== "." && fs.readdirSync(parent).length === 0) {
|
|
39
|
+
fs.rmdirSync(parent);
|
|
40
|
+
}
|
|
41
|
+
parent = path.dirname(parent);
|
|
42
|
+
if (parent !== "." && fs.readdirSync(parent).length === 0) {
|
|
43
|
+
fs.rmdirSync(parent);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
fs.writeFileSync(step.path, step.content);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (task) {
|
|
54
|
+
task.title = `Reverted because: ${task.task.message.error}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function resetRollback() {
|
|
58
|
+
rollback.length = 0;
|
|
59
|
+
}
|
|
60
|
+
function prepareForRollback(tasks) {
|
|
61
|
+
resetRollback();
|
|
62
|
+
tasks.tasks?.forEach((task) => {
|
|
63
|
+
task.task.rollback = executeRollback;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
addFileToRollback,
|
|
68
|
+
addFunctionToRollback,
|
|
69
|
+
executeRollback,
|
|
70
|
+
prepareForRollback,
|
|
71
|
+
resetRollback
|
|
72
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as jscodeshift from "jscodeshift/src/Runner.js";
|
|
2
|
+
const defaultJscodeshiftOpts = {
|
|
3
|
+
// 0, 1 or 2
|
|
4
|
+
verbose: 0,
|
|
5
|
+
dry: false,
|
|
6
|
+
// Doesn't do anything when running programmatically
|
|
7
|
+
print: false,
|
|
8
|
+
babel: true,
|
|
9
|
+
extensions: "js,ts,jsx,tsx",
|
|
10
|
+
ignorePattern: "**/node_modules/**",
|
|
11
|
+
ignoreConfig: [],
|
|
12
|
+
runInBand: false,
|
|
13
|
+
silent: true,
|
|
14
|
+
parser: "babel",
|
|
15
|
+
parserConfig: {},
|
|
16
|
+
// `silent` has to be `false` for this option to do anything
|
|
17
|
+
failOnError: false,
|
|
18
|
+
stdin: false
|
|
19
|
+
};
|
|
20
|
+
const runTransform = async ({
|
|
21
|
+
transformPath,
|
|
22
|
+
targetPaths,
|
|
23
|
+
parser = "tsx",
|
|
24
|
+
options = {}
|
|
25
|
+
}) => {
|
|
26
|
+
if (process.env.NODE_ENV === "test" && process.env.RWJS_CWD) {
|
|
27
|
+
process.chdir(process.env.RWJS_CWD);
|
|
28
|
+
}
|
|
29
|
+
const { output, stdoutWrite } = patchStdoutWrite();
|
|
30
|
+
const result = await jscodeshift.run(transformPath, targetPaths, {
|
|
31
|
+
...defaultJscodeshiftOpts,
|
|
32
|
+
parser,
|
|
33
|
+
babel: process.env.NODE_ENV === "test",
|
|
34
|
+
...options
|
|
35
|
+
// Putting options here lets users override all the defaults.
|
|
36
|
+
});
|
|
37
|
+
restoreStdoutWrite(stdoutWrite);
|
|
38
|
+
let error;
|
|
39
|
+
if (result.error) {
|
|
40
|
+
error = output.value.split("\n").find((line) => line.startsWith("Error: "))?.slice("Error: ".length);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...result,
|
|
44
|
+
error,
|
|
45
|
+
output: output.value
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
function patchStdoutWrite() {
|
|
49
|
+
const stdoutWrite = process.stdout.write;
|
|
50
|
+
const output = {
|
|
51
|
+
value: ""
|
|
52
|
+
};
|
|
53
|
+
process.stdout.write = (chunk) => {
|
|
54
|
+
if (typeof chunk === "string") {
|
|
55
|
+
output.value += chunk;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
return { output, stdoutWrite };
|
|
60
|
+
}
|
|
61
|
+
function restoreStdoutWrite(stdoutWrite) {
|
|
62
|
+
process.stdout.write = stdoutWrite;
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
runTransform
|
|
66
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import plurals from "pluralize";
|
|
2
|
+
const mappings = {
|
|
3
|
+
toSingular: {},
|
|
4
|
+
toPlural: {}
|
|
5
|
+
};
|
|
6
|
+
function lastWord(str) {
|
|
7
|
+
const capitals = str.match(/[A-Z]/g);
|
|
8
|
+
const lastIndex = str.lastIndexOf(capitals?.slice(-1)[0]);
|
|
9
|
+
return lastIndex >= 0 ? str.slice(lastIndex) : str;
|
|
10
|
+
}
|
|
11
|
+
function pluralize(word) {
|
|
12
|
+
if (mappings.toPlural[word]) {
|
|
13
|
+
return mappings.toPlural[word];
|
|
14
|
+
}
|
|
15
|
+
const singular = lastWord(word);
|
|
16
|
+
const base = word.slice(0, word.length - singular.length);
|
|
17
|
+
if (mappings.toPlural[singular]) {
|
|
18
|
+
return base + mappings.toPlural[singular];
|
|
19
|
+
}
|
|
20
|
+
return base + plurals.plural(singular);
|
|
21
|
+
}
|
|
22
|
+
function singularize(word) {
|
|
23
|
+
if (mappings.toSingular[word]) {
|
|
24
|
+
return mappings.toSingular[word];
|
|
25
|
+
}
|
|
26
|
+
const plural = lastWord(word);
|
|
27
|
+
const base = word.slice(0, word.length - plural.length);
|
|
28
|
+
if (mappings.toSingular[plural]) {
|
|
29
|
+
return base + mappings.toSingular[plural];
|
|
30
|
+
}
|
|
31
|
+
return base + plurals.singular(plural);
|
|
32
|
+
}
|
|
33
|
+
function isPlural(word) {
|
|
34
|
+
return plurals.isPlural(lastWord(word));
|
|
35
|
+
}
|
|
36
|
+
function isSingular(word) {
|
|
37
|
+
return plurals.isSingular(lastWord(word));
|
|
38
|
+
}
|
|
39
|
+
function addSingularPlural(singular, plural) {
|
|
40
|
+
const existingPlural = Object.keys(mappings.toSingular).find(
|
|
41
|
+
(key) => mappings.toSingular[key] === singular
|
|
42
|
+
);
|
|
43
|
+
delete mappings.toSingular[existingPlural];
|
|
44
|
+
delete mappings.toPlural[existingPlural];
|
|
45
|
+
mappings.toPlural[singular] = plural;
|
|
46
|
+
mappings.toPlural[plural] = plural;
|
|
47
|
+
mappings.toSingular[plural] = singular;
|
|
48
|
+
mappings.toSingular[singular] = singular;
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
addSingularPlural,
|
|
52
|
+
isPlural,
|
|
53
|
+
isSingular,
|
|
54
|
+
pluralize,
|
|
55
|
+
singularize
|
|
56
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import prismaInternals from "@prisma/internals";
|
|
2
|
+
import { ensureUniquePlural } from "./pluralHelpers.js";
|
|
3
|
+
import { singularize, isPlural } from "./rwPluralize.js";
|
|
4
|
+
import { getPaths } from "./index.js";
|
|
5
|
+
const { getConfig, getDMMF, getSchema: getSchemaPrisma } = prismaInternals;
|
|
6
|
+
const schemaMemo = {};
|
|
7
|
+
const getExistingModelName = async (name) => {
|
|
8
|
+
if (!name) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
const modelName = name.replace(/[_-]/g, "").toLowerCase();
|
|
12
|
+
for (let model of Object.values(schemaMemo)) {
|
|
13
|
+
if (model.name.toLowerCase() === modelName) {
|
|
14
|
+
return model.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const schema = (await getSchemaDefinitions()).datamodel;
|
|
18
|
+
for (let model of schema.models) {
|
|
19
|
+
if (model.name.toLowerCase() === modelName) {
|
|
20
|
+
return model.name;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return void 0;
|
|
24
|
+
};
|
|
25
|
+
const getSchema = async (name) => {
|
|
26
|
+
const schema = (await getSchemaDefinitions()).datamodel;
|
|
27
|
+
if (!name) {
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
const modelName = await getExistingModelName(name);
|
|
31
|
+
if (!modelName) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`No schema definition found for \`${name}\` in schema.prisma file`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (schemaMemo[modelName]) {
|
|
37
|
+
return schemaMemo[modelName];
|
|
38
|
+
}
|
|
39
|
+
const model = schema.models.find((model2) => model2.name === modelName);
|
|
40
|
+
if (!model) {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
model.fields.forEach((field) => {
|
|
44
|
+
const fieldEnum = schema.enums.find((e) => field.type === e.name);
|
|
45
|
+
if (fieldEnum) {
|
|
46
|
+
field.enumValues = fieldEnum.values;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
schemaMemo[modelName] = model;
|
|
50
|
+
return model;
|
|
51
|
+
};
|
|
52
|
+
const getEnum = async (name) => {
|
|
53
|
+
const schema = await getSchemaDefinitions();
|
|
54
|
+
if (!name) {
|
|
55
|
+
return schema.metadata.datamodel.enums;
|
|
56
|
+
}
|
|
57
|
+
const model = schema.datamodel.enums.find((model2) => model2.name === name);
|
|
58
|
+
if (!model) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`No enum schema definition found for \`${name}\` in schema.prisma file`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return model;
|
|
64
|
+
};
|
|
65
|
+
const getDataModel = (path = getPaths().api.dbSchema) => {
|
|
66
|
+
return getSchemaPrisma(path);
|
|
67
|
+
};
|
|
68
|
+
const getSchemaDefinitions = () => {
|
|
69
|
+
return getDMMF({ datamodel: getDataModel() });
|
|
70
|
+
};
|
|
71
|
+
const getSchemaConfig = () => getConfig({
|
|
72
|
+
datamodel: getDataModel()
|
|
73
|
+
});
|
|
74
|
+
async function verifyModelName(options) {
|
|
75
|
+
const modelName = await getExistingModelName(options.name) || await getExistingModelName(singularize(options.name));
|
|
76
|
+
if (modelName === void 0) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`"${options.name}" model not found, check if it exists in "./api/db/schema.prisma"`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
await ensureUniquePlural({
|
|
82
|
+
model: modelName,
|
|
83
|
+
isDestroyer: options.isDestroyer,
|
|
84
|
+
forcePrompt: isPlural(modelName)
|
|
85
|
+
});
|
|
86
|
+
return { ...options, name: modelName };
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
getDataModel,
|
|
90
|
+
getEnum,
|
|
91
|
+
getSchema,
|
|
92
|
+
getSchemaConfig,
|
|
93
|
+
getSchemaDefinitions,
|
|
94
|
+
verifyModelName
|
|
95
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import type { GlobalTypes } from '@storybook/csf'
|
|
4
|
+
import type { Preview, StoryContext, StoryFn } from '@storybook/react'
|
|
5
|
+
|
|
6
|
+
/** @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#global-types-and-the-toolbar-annotation | Global types and the toolbar annotation} */
|
|
7
|
+
export const globalTypes: GlobalTypes = {}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An example, no-op storybook decorator. Use a function like this to create decorators.
|
|
11
|
+
* @see {@link https://storybook.js.org/docs/7/essentials/toolbars-and-globals#create-a-decorator | Create a decorator}
|
|
12
|
+
*/
|
|
13
|
+
const _exampleDecorator = (StoryFn: StoryFn, _context: StoryContext) => (
|
|
14
|
+
<StoryFn />
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const preview: Preview = {
|
|
18
|
+
decorators: [],
|
|
19
|
+
}
|
package/dist/lib/test.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
|
+
import "./mockTelemetry.js";
|
|
5
|
+
vi.mock("@cedarjs/internal/dist/generate/generate", () => {
|
|
6
|
+
return {
|
|
7
|
+
generate: () => {
|
|
8
|
+
return { errors: [] };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
vi.mock("@cedarjs/project-config", async (importOriginal) => {
|
|
13
|
+
const path2 = await import("path");
|
|
14
|
+
const originalProjectConfig = await importOriginal();
|
|
15
|
+
return {
|
|
16
|
+
...originalProjectConfig,
|
|
17
|
+
getPaths: () => {
|
|
18
|
+
const BASE_PATH = "/path/to/project";
|
|
19
|
+
return {
|
|
20
|
+
base: BASE_PATH,
|
|
21
|
+
api: {
|
|
22
|
+
dataMigrations: path2.join(BASE_PATH, "./api/prisma/dataMigrations"),
|
|
23
|
+
db: path2.join(globalThis.__dirname, "fixtures"),
|
|
24
|
+
// this folder
|
|
25
|
+
dbSchema: path2.join(
|
|
26
|
+
globalThis.__dirname,
|
|
27
|
+
"fixtures",
|
|
28
|
+
"schema.prisma"
|
|
29
|
+
),
|
|
30
|
+
// this folder
|
|
31
|
+
generators: path2.join(BASE_PATH, "./api/generators"),
|
|
32
|
+
src: path2.join(BASE_PATH, "./api/src"),
|
|
33
|
+
jobs: path2.join(BASE_PATH, "./api/src/jobs"),
|
|
34
|
+
services: path2.join(BASE_PATH, "./api/src/services"),
|
|
35
|
+
directives: path2.join(BASE_PATH, "./api/src/directives"),
|
|
36
|
+
graphql: path2.join(BASE_PATH, "./api/src/graphql"),
|
|
37
|
+
functions: path2.join(BASE_PATH, "./api/src/functions")
|
|
38
|
+
},
|
|
39
|
+
web: {
|
|
40
|
+
base: path2.join(BASE_PATH, "./web"),
|
|
41
|
+
config: path2.join(BASE_PATH, "./web/config"),
|
|
42
|
+
src: path2.join(BASE_PATH, "./web/src"),
|
|
43
|
+
generators: path2.join(BASE_PATH, "./web/generators"),
|
|
44
|
+
routes: path2.join(BASE_PATH, "web/src/Routes.js"),
|
|
45
|
+
components: path2.join(BASE_PATH, "/web/src/components"),
|
|
46
|
+
layouts: path2.join(BASE_PATH, "/web/src/layouts"),
|
|
47
|
+
pages: path2.join(BASE_PATH, "/web/src/pages"),
|
|
48
|
+
app: path2.join(BASE_PATH, "/web/src/App.js")
|
|
49
|
+
},
|
|
50
|
+
scripts: path2.join(BASE_PATH, "scripts"),
|
|
51
|
+
generated: {
|
|
52
|
+
base: path2.join(BASE_PATH, ".redwood"),
|
|
53
|
+
schema: path2.join(BASE_PATH, ".redwood/schema.graphql"),
|
|
54
|
+
types: {
|
|
55
|
+
includes: path2.join(BASE_PATH, ".redwood/types/includes"),
|
|
56
|
+
mirror: path2.join(BASE_PATH, ".redwood/types/mirror")
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
vi.mock("@cedarjs/cli-helpers", async (importOriginal) => {
|
|
64
|
+
const originalCliHelpers = await importOriginal();
|
|
65
|
+
return {
|
|
66
|
+
...originalCliHelpers,
|
|
67
|
+
isTypeScriptProject: () => false
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
vi.mock("./project", () => ({
|
|
71
|
+
isTypeScriptProject: () => false,
|
|
72
|
+
sides: () => ["web", "api"]
|
|
73
|
+
}));
|
|
74
|
+
globalThis.__prettierPath = path.resolve(
|
|
75
|
+
import.meta.dirname,
|
|
76
|
+
"./__tests__/fixtures/prettier.config.js"
|
|
77
|
+
);
|
|
78
|
+
vi.spyOn(Math, "random").mockReturnValue(0.123456789);
|
|
79
|
+
const generatorsRootPath = path.join(
|
|
80
|
+
import.meta.dirname,
|
|
81
|
+
"..",
|
|
82
|
+
"commands",
|
|
83
|
+
"generate"
|
|
84
|
+
);
|
|
85
|
+
const loadGeneratorFixture = (generator, name) => {
|
|
86
|
+
return loadFixture(
|
|
87
|
+
path.join(
|
|
88
|
+
import.meta.dirname,
|
|
89
|
+
"..",
|
|
90
|
+
"commands",
|
|
91
|
+
"generate",
|
|
92
|
+
generator,
|
|
93
|
+
"__tests__",
|
|
94
|
+
"fixtures",
|
|
95
|
+
name
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
const loadFixture = (filepath) => {
|
|
100
|
+
return fs.readFileSync(filepath).toString();
|
|
101
|
+
};
|
|
102
|
+
export {
|
|
103
|
+
generatorsRootPath,
|
|
104
|
+
loadFixture,
|
|
105
|
+
loadGeneratorFixture
|
|
106
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import boxen from "boxen";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import latestVersion from "latest-version";
|
|
6
|
+
import semver from "semver";
|
|
7
|
+
import { getConfig } from "@cedarjs/project-config";
|
|
8
|
+
import { spawnBackgroundProcess } from "./background.js";
|
|
9
|
+
import { isLockSet, setLock, unsetLock } from "./locking.js";
|
|
10
|
+
import { getPaths } from "./index.js";
|
|
11
|
+
const CHECK_PERIOD = 24 * 60 * 6e4;
|
|
12
|
+
const SHOW_PERIOD = 24 * 60 * 6e4;
|
|
13
|
+
const DEFAULT_DATETIME_MS = 9466848e5;
|
|
14
|
+
const CHECK_LOCK_IDENTIFIER = "UPDATE_CHECK";
|
|
15
|
+
const SHOW_LOCK_IDENTIFIER = "UPDATE_CHECK_SHOW";
|
|
16
|
+
const EXCLUDED_COMMANDS = ["upgrade", "ts-to-js"];
|
|
17
|
+
let persistenceDirectory;
|
|
18
|
+
function getPersistenceDirectory() {
|
|
19
|
+
if (persistenceDirectory) {
|
|
20
|
+
return persistenceDirectory;
|
|
21
|
+
}
|
|
22
|
+
persistenceDirectory = path.join(getPaths().generated.base, "updateCheck");
|
|
23
|
+
return persistenceDirectory;
|
|
24
|
+
}
|
|
25
|
+
async function check() {
|
|
26
|
+
try {
|
|
27
|
+
console.time("Update Check");
|
|
28
|
+
const packageJson = JSON.parse(
|
|
29
|
+
fs.readFileSync(path.join(getPaths().base, "package.json"))
|
|
30
|
+
);
|
|
31
|
+
let localVersion = packageJson.devDependencies["@cedarjs/core"];
|
|
32
|
+
while (!/\d/.test(localVersion.charAt(0))) {
|
|
33
|
+
localVersion = localVersion.substring(1);
|
|
34
|
+
}
|
|
35
|
+
console.log(`Detected the current version of Cedar: '${localVersion}'`);
|
|
36
|
+
const remoteVersions = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const tag of getConfig().notifications.versionUpdates) {
|
|
38
|
+
console.log(`Checking for new versions for npm tag: '${tag}'`);
|
|
39
|
+
try {
|
|
40
|
+
remoteVersions.set(
|
|
41
|
+
tag,
|
|
42
|
+
await latestVersion("@cedarjs/core", { version: tag })
|
|
43
|
+
);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(`Couldn't find a version for tag: '${tag}'`);
|
|
46
|
+
console.error(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
console.log(`Detected the latest versions of Cedar as:`);
|
|
50
|
+
console.log(JSON.stringify([...remoteVersions.entries()], void 0, 2));
|
|
51
|
+
console.log("Saving updated version information for future checks...");
|
|
52
|
+
updateUpdateDataFile({
|
|
53
|
+
localVersion,
|
|
54
|
+
remoteVersions,
|
|
55
|
+
checkedAt: (/* @__PURE__ */ new Date()).getTime()
|
|
56
|
+
});
|
|
57
|
+
} finally {
|
|
58
|
+
unsetLock(CHECK_LOCK_IDENTIFIER);
|
|
59
|
+
console.timeEnd("Update Check");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function isEnabled() {
|
|
63
|
+
return getConfig().notifications.versionUpdates.length > 0;
|
|
64
|
+
}
|
|
65
|
+
function shouldCheck() {
|
|
66
|
+
if (isLockSet(CHECK_LOCK_IDENTIFIER)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const data = readUpdateDataFile();
|
|
70
|
+
return data.checkedAt < (/* @__PURE__ */ new Date()).getTime() - CHECK_PERIOD;
|
|
71
|
+
}
|
|
72
|
+
function shouldShow() {
|
|
73
|
+
if (isLockSet(SHOW_LOCK_IDENTIFIER)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const data = readUpdateDataFile();
|
|
77
|
+
let newerVersion = false;
|
|
78
|
+
data.remoteVersions.forEach((version) => {
|
|
79
|
+
newerVersion ||= semver.gt(version, data.localVersion);
|
|
80
|
+
});
|
|
81
|
+
return data.shownAt < (/* @__PURE__ */ new Date()).getTime() - SHOW_PERIOD && newerVersion;
|
|
82
|
+
}
|
|
83
|
+
function showUpdateMessage() {
|
|
84
|
+
console.log(getUpdateMessage());
|
|
85
|
+
updateUpdateDataFile({ shownAt: (/* @__PURE__ */ new Date()).getTime() });
|
|
86
|
+
}
|
|
87
|
+
function getUpdateMessage() {
|
|
88
|
+
const data = readUpdateDataFile();
|
|
89
|
+
const localTag = extractTagFromVersion(data.localVersion) || "latest";
|
|
90
|
+
let updateCount = 0;
|
|
91
|
+
let message = " New updates to Cedar are available via `yarn rw upgrade#REPLACEME#` ";
|
|
92
|
+
data.remoteVersions.forEach((version, tag) => {
|
|
93
|
+
if (semver.gt(version, data.localVersion)) {
|
|
94
|
+
updateCount += 1;
|
|
95
|
+
if (tag === localTag) {
|
|
96
|
+
message += `
|
|
97
|
+
|
|
98
|
+
\u2756 ${chalk.underline(chalk.bold(tag))}:
|
|
99
|
+
v${data.localVersion} -> v${version} `;
|
|
100
|
+
} else {
|
|
101
|
+
message += `
|
|
102
|
+
|
|
103
|
+
\u2756 ${tag}:
|
|
104
|
+
v${version} `;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
message += "\n\n See release notes at: https://github.com/cedarjs/cedar/releases ";
|
|
109
|
+
message = message.replace("#REPLACEME#", updateCount > 1 ? " -t [tag]" : "");
|
|
110
|
+
return boxen(message, {
|
|
111
|
+
padding: 0,
|
|
112
|
+
margin: 1,
|
|
113
|
+
title: `Cedar Update${updateCount > 1 ? "s " : " "}available \u{1F389}`,
|
|
114
|
+
borderColor: "#0b8379",
|
|
115
|
+
// The RedwoodJS colour
|
|
116
|
+
borderStyle: "round"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function readUpdateDataFile() {
|
|
120
|
+
try {
|
|
121
|
+
if (!fs.existsSync(getPersistenceDirectory())) {
|
|
122
|
+
fs.mkdirSync(getPersistenceDirectory(), { recursive: true });
|
|
123
|
+
}
|
|
124
|
+
const persistedData = JSON.parse(
|
|
125
|
+
fs.readFileSync(path.join(getPersistenceDirectory(), "data.json"))
|
|
126
|
+
);
|
|
127
|
+
persistedData.remoteVersions = new Map(
|
|
128
|
+
Object.entries(persistedData.remoteVersions)
|
|
129
|
+
);
|
|
130
|
+
return persistedData;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error.code === "ENOENT") {
|
|
133
|
+
return {
|
|
134
|
+
localVersion: "0.0.0",
|
|
135
|
+
remoteVersions: /* @__PURE__ */ new Map(),
|
|
136
|
+
checkedAt: DEFAULT_DATETIME_MS,
|
|
137
|
+
shownAt: DEFAULT_DATETIME_MS
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function updateUpdateDataFile({
|
|
144
|
+
localVersion,
|
|
145
|
+
remoteVersions,
|
|
146
|
+
checkedAt,
|
|
147
|
+
shownAt
|
|
148
|
+
} = {}) {
|
|
149
|
+
const existingData = readUpdateDataFile();
|
|
150
|
+
const updatedData = {
|
|
151
|
+
localVersion: localVersion ?? existingData.localVersion,
|
|
152
|
+
remoteVersions: Object.fromEntries(
|
|
153
|
+
remoteVersions ?? existingData.remoteVersions
|
|
154
|
+
),
|
|
155
|
+
checkedAt: checkedAt ?? existingData.checkedAt,
|
|
156
|
+
shownAt: shownAt ?? existingData.shownAt
|
|
157
|
+
};
|
|
158
|
+
fs.writeFileSync(
|
|
159
|
+
path.join(getPersistenceDirectory(), "data.json"),
|
|
160
|
+
JSON.stringify(updatedData, null, 2)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
function extractTagFromVersion(version) {
|
|
164
|
+
const tagIndex = version.indexOf("-");
|
|
165
|
+
if (tagIndex === -1) {
|
|
166
|
+
return "";
|
|
167
|
+
}
|
|
168
|
+
const tag = version.substring(tagIndex + 1).trim();
|
|
169
|
+
return tag.includes(".") ? tag.split(".")[0] : tag;
|
|
170
|
+
}
|
|
171
|
+
function updateCheckMiddleware(argv) {
|
|
172
|
+
if (EXCLUDED_COMMANDS.includes(argv._[0])) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (shouldShow()) {
|
|
176
|
+
setLock(SHOW_LOCK_IDENTIFIER);
|
|
177
|
+
process.on("exit", () => {
|
|
178
|
+
showUpdateMessage();
|
|
179
|
+
unsetLock(SHOW_LOCK_IDENTIFIER);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (shouldCheck()) {
|
|
183
|
+
setLock(CHECK_LOCK_IDENTIFIER);
|
|
184
|
+
spawnBackgroundProcess("updateCheck", "yarn", [
|
|
185
|
+
"node",
|
|
186
|
+
path.join(import.meta.dirname, "updateCheckExecute.js")
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
CHECK_LOCK_IDENTIFIER,
|
|
192
|
+
DEFAULT_DATETIME_MS,
|
|
193
|
+
EXCLUDED_COMMANDS,
|
|
194
|
+
SHOW_LOCK_IDENTIFIER,
|
|
195
|
+
check,
|
|
196
|
+
isEnabled,
|
|
197
|
+
readUpdateDataFile,
|
|
198
|
+
shouldCheck,
|
|
199
|
+
shouldShow,
|
|
200
|
+
showUpdateMessage,
|
|
201
|
+
updateCheckMiddleware
|
|
202
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
import c from "../lib/colors.js";
|
|
3
|
+
function checkNodeVersion() {
|
|
4
|
+
const checks = { ok: true };
|
|
5
|
+
const pVersion = process.version;
|
|
6
|
+
const pVersionC = semver.clean(pVersion);
|
|
7
|
+
const LOWER_BOUND = "v20.0.0";
|
|
8
|
+
const LOWER_BOUND_C = semver.clean(LOWER_BOUND);
|
|
9
|
+
if (semver.gt(pVersionC, LOWER_BOUND_C)) {
|
|
10
|
+
return checks;
|
|
11
|
+
}
|
|
12
|
+
checks.ok = false;
|
|
13
|
+
checks.message = [
|
|
14
|
+
`Your Node.js version is ${c.warning(
|
|
15
|
+
pVersion
|
|
16
|
+
)}, but Redwood requires ${c.important(`>=${LOWER_BOUND}`)}.`,
|
|
17
|
+
"Upgrade your Node.js version using `nvm` or a similar tool. See https://redwoodjs.com/docs/how-to/using-nvm."
|
|
18
|
+
].join("\n");
|
|
19
|
+
return checks;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
checkNodeVersion
|
|
23
|
+
};
|