@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,117 @@
|
|
|
1
|
+
function isJsxExpressionContainer(node) {
|
|
2
|
+
return node.type === "JSXExpressionContainer";
|
|
3
|
+
}
|
|
4
|
+
function isObjectExpression(node) {
|
|
5
|
+
return node.type === "ObjectExpression";
|
|
6
|
+
}
|
|
7
|
+
function isObjectProperty(node) {
|
|
8
|
+
return node.type === "ObjectProperty";
|
|
9
|
+
}
|
|
10
|
+
function isIdentifier(node) {
|
|
11
|
+
return node.type === "Identifier";
|
|
12
|
+
}
|
|
13
|
+
function isPropertyWithName(node, name) {
|
|
14
|
+
return isObjectProperty(node) && node.key.type === "Identifier" && node.key.name === name;
|
|
15
|
+
}
|
|
16
|
+
function transform(file, api) {
|
|
17
|
+
const j = api.jscodeshift;
|
|
18
|
+
const root = j(file.source);
|
|
19
|
+
const redwoodApolloProvider = root.findJSXElements("RedwoodApolloProvider");
|
|
20
|
+
const graphQLClientConfigCollection = redwoodApolloProvider.find(
|
|
21
|
+
j.JSXAttribute,
|
|
22
|
+
{
|
|
23
|
+
name: { name: "graphQLClientConfig" }
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
let graphQLClientConfig;
|
|
27
|
+
if (graphQLClientConfigCollection.length === 0) {
|
|
28
|
+
graphQLClientConfig = j.jsxAttribute(
|
|
29
|
+
j.jsxIdentifier("graphQLClientConfig"),
|
|
30
|
+
j.jsxExpressionContainer(j.objectExpression([]))
|
|
31
|
+
);
|
|
32
|
+
} else {
|
|
33
|
+
graphQLClientConfig = graphQLClientConfigCollection.get(0).node;
|
|
34
|
+
}
|
|
35
|
+
const graphQLClientConfigExpression = isJsxExpressionContainer(
|
|
36
|
+
graphQLClientConfig.value
|
|
37
|
+
) ? graphQLClientConfig.value.expression : j.jsxEmptyExpression();
|
|
38
|
+
let graphQLClientConfigVariableName = "";
|
|
39
|
+
if (isIdentifier(graphQLClientConfigExpression)) {
|
|
40
|
+
graphQLClientConfigVariableName = graphQLClientConfigExpression.name;
|
|
41
|
+
}
|
|
42
|
+
if (!graphQLClientConfigVariableName && !isObjectExpression(graphQLClientConfigExpression)) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Error configuring possibleTypes. You'll have to do it manually. (Could not find a graphQLClientConfigExpression of the correct type, it's a " + graphQLClientConfigExpression.type + ")"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (isObjectExpression(graphQLClientConfigExpression)) {
|
|
48
|
+
graphQLClientConfigVariableName = "graphQLClientConfig";
|
|
49
|
+
root.find(j.VariableDeclaration, {
|
|
50
|
+
declarations: [
|
|
51
|
+
{
|
|
52
|
+
type: "VariableDeclarator",
|
|
53
|
+
id: { type: "Identifier", name: "App" }
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}).insertBefore(
|
|
57
|
+
j.variableDeclaration("const", [
|
|
58
|
+
j.variableDeclarator(
|
|
59
|
+
j.identifier(graphQLClientConfigVariableName),
|
|
60
|
+
graphQLClientConfigExpression
|
|
61
|
+
)
|
|
62
|
+
])
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const configVariableDeclarators = root.findVariableDeclarators(
|
|
66
|
+
graphQLClientConfigVariableName
|
|
67
|
+
);
|
|
68
|
+
const configExpression = configVariableDeclarators.get(0)?.node.init;
|
|
69
|
+
if (!isObjectExpression(configExpression)) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"Error configuring possibleTypes. You'll have to do it manually. (Could not find a graphQLClientConfig variable ObjectExpression)"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
let cacheConfig = configExpression.properties.find(
|
|
75
|
+
(prop) => isPropertyWithName(prop, "cacheConfig")
|
|
76
|
+
);
|
|
77
|
+
if (!cacheConfig) {
|
|
78
|
+
cacheConfig = j.objectProperty(
|
|
79
|
+
j.identifier("cacheConfig"),
|
|
80
|
+
j.objectExpression([])
|
|
81
|
+
);
|
|
82
|
+
configExpression.properties.push(cacheConfig);
|
|
83
|
+
}
|
|
84
|
+
if (!isObjectProperty(cacheConfig)) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
"Error configuring possibleTypes. You'll have to do it manually. (cacheConfig is not an ObjectProperty)"
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const cacheConfigValue = cacheConfig.value;
|
|
90
|
+
if (!isObjectExpression(cacheConfigValue)) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"Error configuring possibleTypes. You'll have to do it manually. (cacheConfigValue is not an ObjectExpression)"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const possibleTypes = cacheConfigValue.properties.find(
|
|
96
|
+
(prop) => isPropertyWithName(prop, "possibleTypes")
|
|
97
|
+
);
|
|
98
|
+
if (!possibleTypes) {
|
|
99
|
+
const property = j.property(
|
|
100
|
+
"init",
|
|
101
|
+
j.identifier("possibleTypes"),
|
|
102
|
+
j.identifier("possibleTypes.possibleTypes")
|
|
103
|
+
);
|
|
104
|
+
cacheConfigValue.properties.push(property);
|
|
105
|
+
}
|
|
106
|
+
graphQLClientConfigCollection.remove();
|
|
107
|
+
redwoodApolloProvider.get(0).node.openingElement.attributes.push(
|
|
108
|
+
j.jsxAttribute(
|
|
109
|
+
j.jsxIdentifier("graphQLClientConfig"),
|
|
110
|
+
j.jsxExpressionContainer(j.identifier(graphQLClientConfigVariableName))
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
return root.toSource();
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
transform as default
|
|
117
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function transform(file, api) {
|
|
2
|
+
const j = api.jscodeshift;
|
|
3
|
+
const root = j(file.source);
|
|
4
|
+
const possibleTypesImports = root.find(j.ImportDeclaration);
|
|
5
|
+
const hasPossibleTypesImport = possibleTypesImports.some((i) => {
|
|
6
|
+
return i.get("source").value.value === "src/graphql/possibleTypes" || i.get("source").value.value === "./graphql/possibleTypes";
|
|
7
|
+
});
|
|
8
|
+
if (!hasPossibleTypesImport) {
|
|
9
|
+
possibleTypesImports.at(1).insertAfter(
|
|
10
|
+
j.importDeclaration(
|
|
11
|
+
[j.importDefaultSpecifier(j.identifier("possibleTypes"))],
|
|
12
|
+
j.literal("src/graphql/possibleTypes")
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return root.toSource();
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
transform as default
|
|
20
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
2
|
+
const command = "fragments";
|
|
3
|
+
const description = "Set up Fragments for GraphQL";
|
|
4
|
+
function builder(yargs) {
|
|
5
|
+
return yargs.option("force", {
|
|
6
|
+
alias: "f",
|
|
7
|
+
default: false,
|
|
8
|
+
description: "Overwrite existing configuration",
|
|
9
|
+
type: "boolean"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async function handler({ force }) {
|
|
13
|
+
recordTelemetryAttributes({
|
|
14
|
+
command: "setup graphql fragments",
|
|
15
|
+
force
|
|
16
|
+
});
|
|
17
|
+
const { handler: handler2 } = await import("./fragmentsHandler.js");
|
|
18
|
+
return handler2({ force });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
builder,
|
|
22
|
+
command,
|
|
23
|
+
description,
|
|
24
|
+
handler
|
|
25
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import execa from "execa";
|
|
4
|
+
import { Listr } from "listr2";
|
|
5
|
+
import { format } from "prettier";
|
|
6
|
+
import {
|
|
7
|
+
colors,
|
|
8
|
+
getPrettierOptions,
|
|
9
|
+
setTomlSetting
|
|
10
|
+
} from "@cedarjs/cli-helpers";
|
|
11
|
+
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
12
|
+
import { runTransform } from "../../../../../lib/runTransform.js";
|
|
13
|
+
const command = "fragments";
|
|
14
|
+
const description = "Set up Fragments for GraphQL";
|
|
15
|
+
async function handler({ force }) {
|
|
16
|
+
const tasks = new Listr(
|
|
17
|
+
[
|
|
18
|
+
{
|
|
19
|
+
title: "Update Redwood Project Configuration to enable GraphQL Fragments",
|
|
20
|
+
skip: () => {
|
|
21
|
+
if (force) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const config = getConfig();
|
|
25
|
+
if (config.graphql.fragments) {
|
|
26
|
+
return "GraphQL Fragments are already enabled.";
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
},
|
|
30
|
+
task: () => {
|
|
31
|
+
setTomlSetting("graphql", "fragments", true);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
title: "Generate possibleTypes.ts",
|
|
36
|
+
task: () => {
|
|
37
|
+
execa.commandSync("yarn redwood generate types", { stdio: "ignore" });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: "Import possibleTypes in App.tsx",
|
|
42
|
+
task: () => {
|
|
43
|
+
return runTransform({
|
|
44
|
+
transformPath: path.join(
|
|
45
|
+
import.meta.dirname,
|
|
46
|
+
"appImportTransform.js"
|
|
47
|
+
),
|
|
48
|
+
targetPaths: [getPaths().web.app]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
title: "Add possibleTypes to the GraphQL cache config",
|
|
54
|
+
task: async () => {
|
|
55
|
+
const transformResult = await runTransform({
|
|
56
|
+
transformPath: path.join(
|
|
57
|
+
import.meta.dirname,
|
|
58
|
+
"appGqlConfigTransform.js"
|
|
59
|
+
),
|
|
60
|
+
targetPaths: [getPaths().web.app]
|
|
61
|
+
});
|
|
62
|
+
if (transformResult.error) {
|
|
63
|
+
throw new Error(transformResult.error);
|
|
64
|
+
}
|
|
65
|
+
const appPath = getPaths().web.app;
|
|
66
|
+
const source = fs.readFileSync(appPath, "utf-8");
|
|
67
|
+
const prettierOptions = await getPrettierOptions();
|
|
68
|
+
const prettifiedApp = await format(source, {
|
|
69
|
+
...prettierOptions,
|
|
70
|
+
parser: "babel-ts"
|
|
71
|
+
});
|
|
72
|
+
fs.writeFileSync(getPaths().web.app, prettifiedApp, "utf-8");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
{ rendererOptions: { collapseSubtasks: false } }
|
|
77
|
+
);
|
|
78
|
+
try {
|
|
79
|
+
await tasks.run();
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error(colors.error(e.message));
|
|
82
|
+
process.exit(e?.exitCode || 1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
command,
|
|
87
|
+
description,
|
|
88
|
+
handler
|
|
89
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function transform(file, api) {
|
|
2
|
+
const j = api.jscodeshift;
|
|
3
|
+
const root = j(file.source);
|
|
4
|
+
const allImports = root.find(j.ImportDeclaration);
|
|
5
|
+
const hasStoreImport = allImports.some((i) => {
|
|
6
|
+
return i.get("source").value.value === "src/lib/trustedDocumentsStore";
|
|
7
|
+
});
|
|
8
|
+
if (!hasStoreImport) {
|
|
9
|
+
allImports.at(-1).insertAfter(
|
|
10
|
+
j.importDeclaration(
|
|
11
|
+
[j.importSpecifier(j.identifier("store"))],
|
|
12
|
+
j.literal("src/lib/trustedDocumentsStore")
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const createGraphQLHandlerCalls = root.find(j.CallExpression, {
|
|
17
|
+
callee: {
|
|
18
|
+
name: "createGraphQLHandler"
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (createGraphQLHandlerCalls.length === 0) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"Error updating your graphql handler function. You'll have to do it manually. (Couldn't find a call to `createGraphQLHandler`)"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const existingTrustedDocumentsProperty = createGraphQLHandlerCalls.find(
|
|
27
|
+
j.ObjectProperty,
|
|
28
|
+
{
|
|
29
|
+
key: {
|
|
30
|
+
name: "trustedDocuments"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
if (existingTrustedDocumentsProperty.length === 0) {
|
|
35
|
+
const storeProperty = j.objectProperty(
|
|
36
|
+
j.identifier("store"),
|
|
37
|
+
j.identifier("store")
|
|
38
|
+
);
|
|
39
|
+
storeProperty.shorthand = true;
|
|
40
|
+
createGraphQLHandlerCalls.get(0).node.arguments[0].properties.push(
|
|
41
|
+
j.objectProperty(
|
|
42
|
+
j.identifier("trustedDocuments"),
|
|
43
|
+
j.objectExpression([storeProperty])
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return root.toSource();
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
transform as default
|
|
51
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
2
|
+
const command = "trusted-documents";
|
|
3
|
+
const description = "Set up Trusted Documents for GraphQL";
|
|
4
|
+
function builder(yargs) {
|
|
5
|
+
return yargs.option("force", {
|
|
6
|
+
alias: "f",
|
|
7
|
+
default: false,
|
|
8
|
+
description: "Overwrite existing configuration",
|
|
9
|
+
type: "boolean"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async function handler({ force }) {
|
|
13
|
+
recordTelemetryAttributes({
|
|
14
|
+
command: "setup graphql trusted-documents",
|
|
15
|
+
force
|
|
16
|
+
});
|
|
17
|
+
const { handler: handler2 } = await import("./trustedDocumentsHandler.js");
|
|
18
|
+
return handler2({ force });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
builder,
|
|
22
|
+
command,
|
|
23
|
+
description,
|
|
24
|
+
handler
|
|
25
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import execa from "execa";
|
|
4
|
+
import { Listr } from "listr2";
|
|
5
|
+
import { format } from "prettier";
|
|
6
|
+
import { getPrettierOptions, setTomlSetting } from "@cedarjs/cli-helpers";
|
|
7
|
+
import { getConfig, getPaths, resolveFile } from "@cedarjs/project-config";
|
|
8
|
+
import { runTransform } from "../../../../../lib/runTransform.js";
|
|
9
|
+
async function handler({ force }) {
|
|
10
|
+
const tasks = new Listr(
|
|
11
|
+
[
|
|
12
|
+
{
|
|
13
|
+
title: "Update Redwood Project Configuration to enable GraphQL Trusted Documents ...",
|
|
14
|
+
skip: () => {
|
|
15
|
+
if (force) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const config = getConfig();
|
|
19
|
+
if (config.graphql.trustedDocuments) {
|
|
20
|
+
return "GraphQL Trusted Documents are already enabled in your Redwood project.";
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
},
|
|
24
|
+
task: () => {
|
|
25
|
+
setTomlSetting("graphql", "trustedDocuments", true);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: "Generating Trusted Documents store ...",
|
|
30
|
+
task: () => {
|
|
31
|
+
execa.commandSync("yarn redwood generate types", { stdio: "ignore" });
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
title: "Configuring the GraphQL Handler to use a Trusted Documents store ...",
|
|
36
|
+
task: async () => {
|
|
37
|
+
const graphqlPath = resolveFile(
|
|
38
|
+
path.join(getPaths().api.functions, "graphql")
|
|
39
|
+
);
|
|
40
|
+
if (!graphqlPath) {
|
|
41
|
+
throw new Error("Could not find a GraphQL handler in your project.");
|
|
42
|
+
}
|
|
43
|
+
const transformResult = await runTransform({
|
|
44
|
+
transformPath: path.join(
|
|
45
|
+
import.meta.dirname,
|
|
46
|
+
"graphqlTransform.js"
|
|
47
|
+
),
|
|
48
|
+
targetPaths: [graphqlPath]
|
|
49
|
+
});
|
|
50
|
+
if (transformResult.error) {
|
|
51
|
+
throw new Error(transformResult.error);
|
|
52
|
+
}
|
|
53
|
+
const source = fs.readFileSync(graphqlPath, "utf-8");
|
|
54
|
+
const prettierOptions = await getPrettierOptions();
|
|
55
|
+
const prettifiedApp = await format(source, {
|
|
56
|
+
...prettierOptions,
|
|
57
|
+
parser: "babel-ts"
|
|
58
|
+
});
|
|
59
|
+
fs.writeFileSync(graphqlPath, prettifiedApp, "utf-8");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
{ rendererOptions: { collapseSubtasks: false } }
|
|
64
|
+
);
|
|
65
|
+
try {
|
|
66
|
+
await tasks.run();
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error(e.message);
|
|
69
|
+
process.exit(e?.exitCode || 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
handler
|
|
74
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import terminalLink from "terminal-link";
|
|
2
|
+
import * as fragmentsCommand from "./features/fragments/fragments.js";
|
|
3
|
+
import * as trustedDocumentsCommand from "./features/trustedDocuments/trustedDocuments.js";
|
|
4
|
+
const command = "graphql <feature>";
|
|
5
|
+
const description = "Set up GraphQL feature support";
|
|
6
|
+
function builder(yargs) {
|
|
7
|
+
return yargs.command(fragmentsCommand).command(trustedDocumentsCommand).epilogue(
|
|
8
|
+
`Also see the ${terminalLink(
|
|
9
|
+
"Redwood CLI Reference",
|
|
10
|
+
"https://redwoodjs.com/docs/cli-commands#setup-graphql"
|
|
11
|
+
)}`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
builder,
|
|
16
|
+
command,
|
|
17
|
+
description
|
|
18
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
2
|
+
const command = "i18n";
|
|
3
|
+
const description = "Set up i18n";
|
|
4
|
+
const builder = (yargs) => {
|
|
5
|
+
yargs.option("force", {
|
|
6
|
+
alias: "f",
|
|
7
|
+
default: false,
|
|
8
|
+
description: "Overwrite existing configuration",
|
|
9
|
+
type: "boolean"
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const handler = async (options) => {
|
|
13
|
+
recordTelemetryAttributes({
|
|
14
|
+
command: "setup i18n",
|
|
15
|
+
force: options.force
|
|
16
|
+
});
|
|
17
|
+
const { handler: handler2 } = await import("./i18nHandler.js");
|
|
18
|
+
return handler2(options);
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
builder,
|
|
22
|
+
command,
|
|
23
|
+
description,
|
|
24
|
+
handler
|
|
25
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import execa from "execa";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import { Listr } from "listr2";
|
|
5
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
6
|
+
import c from "../../../lib/colors.js";
|
|
7
|
+
import extendStorybookConfiguration from "../../../lib/configureStorybook.js";
|
|
8
|
+
import { fileIncludes } from "../../../lib/extendFile.js";
|
|
9
|
+
import { getPaths, writeFile } from "../../../lib/index.js";
|
|
10
|
+
const APP_JS_PATH = getPaths().web.app;
|
|
11
|
+
const i18nImportExist = (appJS) => {
|
|
12
|
+
let content = appJS.toString();
|
|
13
|
+
const hasBaseImport = () => /import '.\/i18n'/.test(content);
|
|
14
|
+
return hasBaseImport();
|
|
15
|
+
};
|
|
16
|
+
const addI18nImport = (appJS) => {
|
|
17
|
+
var content = appJS.toString().split("\n").reverse();
|
|
18
|
+
const index = content.findIndex((value) => /import/.test(value));
|
|
19
|
+
content.splice(index, 0, "import './i18n'");
|
|
20
|
+
return content.reverse().join(`
|
|
21
|
+
`);
|
|
22
|
+
};
|
|
23
|
+
const i18nConfigExists = () => {
|
|
24
|
+
return fs.existsSync(path.join(getPaths().web.src, "i18n.js"));
|
|
25
|
+
};
|
|
26
|
+
const localesExists = (lng) => {
|
|
27
|
+
return fs.existsSync(path.join(getPaths().web.src, "locales", lng + ".json"));
|
|
28
|
+
};
|
|
29
|
+
const handler = async ({ force }) => {
|
|
30
|
+
const rwPaths = getPaths();
|
|
31
|
+
const tasks = new Listr(
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
title: "Installing packages...",
|
|
35
|
+
task: async () => {
|
|
36
|
+
return new Listr(
|
|
37
|
+
[
|
|
38
|
+
{
|
|
39
|
+
title: "Install i18next, react-i18next and i18next-browser-languagedetector",
|
|
40
|
+
task: async () => {
|
|
41
|
+
await execa("yarn", [
|
|
42
|
+
"workspace",
|
|
43
|
+
"web",
|
|
44
|
+
"add",
|
|
45
|
+
"i18next",
|
|
46
|
+
"react-i18next",
|
|
47
|
+
"i18next-browser-languagedetector"
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
{ rendererOptions: { collapseSubtasks: false } }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: "Configure i18n...",
|
|
58
|
+
task: () => {
|
|
59
|
+
if (!force && i18nConfigExists()) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"i18n config already exists.\nUse --force to override existing config."
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
return writeFile(
|
|
65
|
+
path.join(getPaths().web.src, "i18n.js"),
|
|
66
|
+
fs.readFileSync(
|
|
67
|
+
path.resolve(
|
|
68
|
+
import.meta.dirname,
|
|
69
|
+
"templates",
|
|
70
|
+
"i18n.js.template"
|
|
71
|
+
)
|
|
72
|
+
).toString(),
|
|
73
|
+
{ overwriteExisting: force }
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
title: "Adding locale file for French...",
|
|
80
|
+
task: () => {
|
|
81
|
+
if (!force && localesExists("fr")) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
"fr.json config already exists.\nUse --force to override existing config."
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
return writeFile(
|
|
87
|
+
path.join(getPaths().web.src, "/locales/fr.json"),
|
|
88
|
+
fs.readFileSync(
|
|
89
|
+
path.resolve(
|
|
90
|
+
import.meta.dirname,
|
|
91
|
+
"templates",
|
|
92
|
+
"fr.json.template"
|
|
93
|
+
)
|
|
94
|
+
).toString(),
|
|
95
|
+
{ overwriteExisting: force }
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
title: "Adding locale file for English...",
|
|
102
|
+
task: () => {
|
|
103
|
+
if (!force && localesExists("en")) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
"en.json already exists.\nUse --force to override existing config."
|
|
106
|
+
);
|
|
107
|
+
} else {
|
|
108
|
+
return writeFile(
|
|
109
|
+
path.join(getPaths().web.src, "/locales/en.json"),
|
|
110
|
+
fs.readFileSync(
|
|
111
|
+
path.resolve(
|
|
112
|
+
import.meta.dirname,
|
|
113
|
+
"templates",
|
|
114
|
+
"en.json.template"
|
|
115
|
+
)
|
|
116
|
+
).toString(),
|
|
117
|
+
{ overwriteExisting: force }
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
title: "Adding import to App.{jsx,tsx}...",
|
|
124
|
+
task: (_ctx, task) => {
|
|
125
|
+
let appJS = fs.readFileSync(APP_JS_PATH);
|
|
126
|
+
if (i18nImportExist(appJS)) {
|
|
127
|
+
task.skip("Import already exists in App.js");
|
|
128
|
+
} else {
|
|
129
|
+
fs.writeFileSync(APP_JS_PATH, addI18nImport(appJS));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
title: "Configuring Storybook...",
|
|
135
|
+
// skip this task if the user's storybook config already includes "withI18n"
|
|
136
|
+
skip: () => fileIncludes(rwPaths.web.storybookConfig, "withI18n"),
|
|
137
|
+
task: async () => extendStorybookConfiguration(
|
|
138
|
+
path.join(
|
|
139
|
+
import.meta.dirname,
|
|
140
|
+
"templates",
|
|
141
|
+
"storybook.preview.tsx.template"
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
title: "One more thing...",
|
|
147
|
+
task: (_ctx, task) => {
|
|
148
|
+
task.title = `One more thing...
|
|
149
|
+
|
|
150
|
+
${c.tip("Quick link to the docs:")}
|
|
151
|
+
|
|
152
|
+
${c.link("https://react.i18next.com/guides/quick-start/")}
|
|
153
|
+
`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
{ rendererOptions: { collapseSubtasks: false } }
|
|
158
|
+
);
|
|
159
|
+
try {
|
|
160
|
+
await tasks.run();
|
|
161
|
+
} catch (e) {
|
|
162
|
+
errorTelemetry(process.argv, e.message);
|
|
163
|
+
console.error(c.error(e.message));
|
|
164
|
+
process.exit(e?.exitCode || 1);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
export {
|
|
168
|
+
handler
|
|
169
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Welcome to Cedar": "Welcome to Cedar",
|
|
3
|
+
"info": "This is your English translation file",
|
|
4
|
+
"see": "https://www.i18next.com/translation-function/essentials",
|
|
5
|
+
"HomePage": {
|
|
6
|
+
"title": "Home Page",
|
|
7
|
+
"info": "Find me in",
|
|
8
|
+
"route": "My default route is named",
|
|
9
|
+
"link": "link to me with"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Welcome to Cedar": "Bienvenu sur Cedar",
|
|
3
|
+
"info": "Ceci est votre fichier de traduction",
|
|
4
|
+
"see": "https://www.i18next.com/translation-function/essentials",
|
|
5
|
+
"HomePage": {
|
|
6
|
+
"title": "Page d'accueil",
|
|
7
|
+
"info": "Trouve moi dans",
|
|
8
|
+
"route": "Ma route par default se nomme",
|
|
9
|
+
"link": "le lien vers moi avec"
|
|
10
|
+
}
|
|
11
|
+
}
|