@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,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTransformerDirective,
|
|
3
|
+
TransformerDirectiveFunc,
|
|
4
|
+
} from '@cedarjs/graphql-server'
|
|
5
|
+
import { logger } from 'src/lib/logger'
|
|
6
|
+
|
|
7
|
+
export const schema = gql`
|
|
8
|
+
"""
|
|
9
|
+
Use @${camelName} to transform the resolved value to return a modified result.
|
|
10
|
+
"""
|
|
11
|
+
directive @${camelName} on FIELD_DEFINITION
|
|
12
|
+
`
|
|
13
|
+
|
|
14
|
+
const transform: TransformerDirectiveFunc = ({ context, resolvedValue }) => {
|
|
15
|
+
/**
|
|
16
|
+
* Write your transformation logic inside this function.
|
|
17
|
+
* Transformer directives run **after** resolving the value
|
|
18
|
+
*
|
|
19
|
+
* - You can also throw an error, if you want to stop executing, but note that the value has already been resolved
|
|
20
|
+
* - Transformer directives **must** be synchronous, and return a value
|
|
21
|
+
**/
|
|
22
|
+
|
|
23
|
+
// currentUser is only available when auth is setup.
|
|
24
|
+
logger.debug({ currentUser: context.currentUser }, 'currentUser in ${camelName} directive')
|
|
25
|
+
|
|
26
|
+
// ... you can modify the resolvedValue and return it
|
|
27
|
+
logger.debug(resolvedValue, 'resolvedValue in ${camelName} directive')
|
|
28
|
+
|
|
29
|
+
// You can also modify your directive to take arguments
|
|
30
|
+
// and use the directiveArgs object provided to this function to get values
|
|
31
|
+
// See documentation here: https://redwoodjs.com/docs/directives
|
|
32
|
+
|
|
33
|
+
return resolvedValue.replace('foo', 'bar')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ${camelName} = createTransformerDirective(schema, transform)
|
|
37
|
+
|
|
38
|
+
export default ${camelName}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { mockRedwoodDirective, getDirectiveName } from '@cedarjs/testing/api'
|
|
2
|
+
|
|
3
|
+
import ${camelName} from './${camelName}'
|
|
4
|
+
|
|
5
|
+
describe('${camelName} directive', () => {
|
|
6
|
+
it('declares the directive sdl as schema, with the correct name', () => {
|
|
7
|
+
expect(${camelName}.schema).toBeTruthy()
|
|
8
|
+
expect(getDirectiveName(${camelName}.schema)).toBe('${camelName}')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
it('has a ${camelName} throws an error if validation does not pass', () => {
|
|
13
|
+
const mockExecution = mockRedwoodDirective(${camelName}, {})
|
|
14
|
+
|
|
15
|
+
expect(mockExecution).toThrowError('Implementation missing for ${camelName}')
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createValidatorDirective,
|
|
3
|
+
ValidatorDirectiveFunc,
|
|
4
|
+
} from '@cedarjs/graphql-server'
|
|
5
|
+
|
|
6
|
+
import { logger } from 'src/lib/logger'
|
|
7
|
+
|
|
8
|
+
export const schema = gql`
|
|
9
|
+
"""
|
|
10
|
+
Use @${camelName} to validate access to a field, query or mutation.
|
|
11
|
+
"""
|
|
12
|
+
directive @${camelName} on FIELD_DEFINITION
|
|
13
|
+
`
|
|
14
|
+
|
|
15
|
+
const validate: ValidatorDirectiveFunc = ({ context, directiveArgs }) => {
|
|
16
|
+
/**
|
|
17
|
+
* Write your validation logic inside this function.
|
|
18
|
+
* Validator directives do not have access to the field value, i.e. they are called before resolving the value
|
|
19
|
+
*
|
|
20
|
+
* - Throw an error, if you want to stop executing e.g. not sufficient permissions
|
|
21
|
+
* - Validator directives can be async or sync
|
|
22
|
+
* - Returned value will be ignored
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// currentUser is only available when auth is setup.
|
|
26
|
+
logger.debug({ currentUser: context.currentUser }, 'currentUser in ${camelName} directive')
|
|
27
|
+
|
|
28
|
+
// You can also modify your directive to take arguments
|
|
29
|
+
// and use the directiveArgs object provided to this function to get values
|
|
30
|
+
// See documentation here: https://redwoodjs.com/docs/directives
|
|
31
|
+
logger.debug(directiveArgs, 'directiveArgs in ${camelName} directive')
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
throw new Error('Implementation missing for ${camelName}')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const ${camelName} = createValidatorDirective(schema, validate)
|
|
38
|
+
|
|
39
|
+
export default ${camelName}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import terminalLink from "terminal-link";
|
|
2
|
+
import { getYargsDefaults, createHandler } from "../yargsCommandHelpers.js";
|
|
3
|
+
const command = "function <name>";
|
|
4
|
+
const description = "Generate a Function";
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs.positional("name", {
|
|
7
|
+
description: "Name of the Function",
|
|
8
|
+
type: "string"
|
|
9
|
+
}).option("rollback", {
|
|
10
|
+
description: "Revert all generator actions if an error occurs",
|
|
11
|
+
type: "boolean",
|
|
12
|
+
default: true
|
|
13
|
+
}).epilogue(
|
|
14
|
+
`Also see the ${terminalLink(
|
|
15
|
+
"Redwood CLI Reference",
|
|
16
|
+
"https://redwoodjs.com/docs/cli-commands#generate-function"
|
|
17
|
+
)}`
|
|
18
|
+
);
|
|
19
|
+
Object.entries(getYargsDefaults()).forEach(([option, config]) => {
|
|
20
|
+
yargs.option(option, config);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const handler = createHandler("function");
|
|
24
|
+
export {
|
|
25
|
+
builder,
|
|
26
|
+
command,
|
|
27
|
+
description,
|
|
28
|
+
handler
|
|
29
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import camelcase from "camelcase";
|
|
3
|
+
import { Listr } from "listr2";
|
|
4
|
+
import terminalLink from "terminal-link";
|
|
5
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
6
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
|
+
import c from "../../../lib/colors.js";
|
|
8
|
+
import {
|
|
9
|
+
getPaths,
|
|
10
|
+
transformTSToJS,
|
|
11
|
+
writeFilesTask
|
|
12
|
+
} from "../../../lib/index.js";
|
|
13
|
+
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
14
|
+
import { validateName } from "../helpers.js";
|
|
15
|
+
import { templateForComponentFile } from "../yargsHandlerHelpers.js";
|
|
16
|
+
const files = async ({
|
|
17
|
+
name,
|
|
18
|
+
typescript: generateTypescript = false,
|
|
19
|
+
tests: generateTests = true,
|
|
20
|
+
...rest
|
|
21
|
+
}) => {
|
|
22
|
+
const extension = generateTypescript ? ".ts" : ".js";
|
|
23
|
+
const functionName = camelcase(name);
|
|
24
|
+
const outputFiles = [];
|
|
25
|
+
const functionFiles = await templateForComponentFile({
|
|
26
|
+
name: functionName,
|
|
27
|
+
componentName: functionName,
|
|
28
|
+
extension,
|
|
29
|
+
apiPathSection: "functions",
|
|
30
|
+
generator: "function",
|
|
31
|
+
templatePath: "function.ts.template",
|
|
32
|
+
templateVars: { ...rest, typescript: generateTypescript },
|
|
33
|
+
outputPath: path.join(
|
|
34
|
+
getPaths().api.functions,
|
|
35
|
+
functionName,
|
|
36
|
+
`${functionName}${extension}`
|
|
37
|
+
)
|
|
38
|
+
});
|
|
39
|
+
outputFiles.push(functionFiles);
|
|
40
|
+
if (generateTests) {
|
|
41
|
+
const testFile = await templateForComponentFile({
|
|
42
|
+
name: functionName,
|
|
43
|
+
componentName: functionName,
|
|
44
|
+
extension,
|
|
45
|
+
apiPathSection: "functions",
|
|
46
|
+
generator: "function",
|
|
47
|
+
templatePath: "test.ts.template",
|
|
48
|
+
templateVars: { ...rest },
|
|
49
|
+
outputPath: path.join(
|
|
50
|
+
getPaths().api.functions,
|
|
51
|
+
functionName,
|
|
52
|
+
`${functionName}.test${extension}`
|
|
53
|
+
)
|
|
54
|
+
});
|
|
55
|
+
const scenarioFile = await templateForComponentFile({
|
|
56
|
+
name: functionName,
|
|
57
|
+
componentName: functionName,
|
|
58
|
+
extension,
|
|
59
|
+
apiPathSection: "functions",
|
|
60
|
+
generator: "function",
|
|
61
|
+
templatePath: "scenarios.ts.template",
|
|
62
|
+
templateVars: { ...rest },
|
|
63
|
+
outputPath: path.join(
|
|
64
|
+
getPaths().api.functions,
|
|
65
|
+
functionName,
|
|
66
|
+
`${functionName}.scenarios${extension}`
|
|
67
|
+
)
|
|
68
|
+
});
|
|
69
|
+
outputFiles.push(testFile);
|
|
70
|
+
outputFiles.push(scenarioFile);
|
|
71
|
+
}
|
|
72
|
+
return outputFiles.reduce(async (accP, [outputPath, content]) => {
|
|
73
|
+
const acc = await accP;
|
|
74
|
+
const template = generateTypescript ? content : await transformTSToJS(outputPath, content);
|
|
75
|
+
return {
|
|
76
|
+
[outputPath]: template,
|
|
77
|
+
...acc
|
|
78
|
+
};
|
|
79
|
+
}, Promise.resolve({}));
|
|
80
|
+
};
|
|
81
|
+
const handler = async ({ name, force, ...rest }) => {
|
|
82
|
+
recordTelemetryAttributes({
|
|
83
|
+
command: "generate function",
|
|
84
|
+
force,
|
|
85
|
+
rollback: rest.rollback
|
|
86
|
+
});
|
|
87
|
+
validateName(name);
|
|
88
|
+
const tasks = new Listr(
|
|
89
|
+
[
|
|
90
|
+
{
|
|
91
|
+
title: "Generating function files...",
|
|
92
|
+
task: async () => {
|
|
93
|
+
return writeFilesTask(await files({ name, ...rest }), {
|
|
94
|
+
overwriteExisting: force
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
{ rendererOptions: { collapseSubtasks: false }, exitOnError: true }
|
|
100
|
+
);
|
|
101
|
+
try {
|
|
102
|
+
if (rest.rollback && !force) {
|
|
103
|
+
prepareForRollback(tasks);
|
|
104
|
+
}
|
|
105
|
+
await tasks.run();
|
|
106
|
+
console.info("");
|
|
107
|
+
console.info(c.warning("\u26A0 Important:"));
|
|
108
|
+
console.info("");
|
|
109
|
+
console.info(
|
|
110
|
+
c.bold(
|
|
111
|
+
"When deployed, a custom serverless function is an open API endpoint and is your responsibility to secure appropriately."
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
console.info("");
|
|
115
|
+
console.info(
|
|
116
|
+
`Please consult the ${terminalLink(
|
|
117
|
+
"Serverless Function Considerations",
|
|
118
|
+
"https://redwoodjs.com/docs/serverless-functions#security-considerations"
|
|
119
|
+
)} in the RedwoodJS documentation for more information.`
|
|
120
|
+
);
|
|
121
|
+
console.info("");
|
|
122
|
+
} catch (e) {
|
|
123
|
+
errorTelemetry(process.argv, e.message);
|
|
124
|
+
console.error(c.error(e.message));
|
|
125
|
+
process.exit(e?.exitCode || 1);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export {
|
|
129
|
+
files,
|
|
130
|
+
handler
|
|
131
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { APIGatewayEvent, Context } from 'aws-lambda'
|
|
2
|
+
|
|
3
|
+
import { logger } from 'src/lib/logger'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The handler function is your code that processes http request events.
|
|
7
|
+
* You can use return and throw to send a response or error, respectively.
|
|
8
|
+
*
|
|
9
|
+
* Important: When deployed, a custom serverless function is an open API endpoint and
|
|
10
|
+
* is your responsibility to secure appropriately.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://redwoodjs.com/docs/serverless-functions#security-considerations|Serverless Function Considerations}
|
|
13
|
+
* in the RedwoodJS documentation for more information.
|
|
14
|
+
*<% if (!typescript) { %>
|
|
15
|
+
* @typedef { import('aws-lambda').APIGatewayEvent } APIGatewayEvent
|
|
16
|
+
* @typedef { import('aws-lambda').Context } Context<% } %>
|
|
17
|
+
* @param { APIGatewayEvent } event - an object which contains information from the invoker.
|
|
18
|
+
* @param { Context } _context - contains information about the invocation,
|
|
19
|
+
* function, and execution environment.
|
|
20
|
+
*/
|
|
21
|
+
export const handler = async (event: APIGatewayEvent, _context: Context) => {
|
|
22
|
+
logger.info(`<%= '$' %>{event.httpMethod} <%= '$' %>{event.path}: <%= name %> function`)
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
statusCode: 200,
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
data: '${name} function',
|
|
31
|
+
}),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ScenarioData } from '@cedarjs/testing/api'
|
|
2
|
+
|
|
3
|
+
export const standard = defineScenario({
|
|
4
|
+
// Define the "fixture" to write into your test database here
|
|
5
|
+
// See guide: https://redwoodjs.com/docs/testing#scenarios
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
export type StandardScenario = ScenarioData<unknown>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { mockHttpEvent, mockContext } from '@cedarjs/testing/api'
|
|
2
|
+
|
|
3
|
+
import { handler } from './${name}'
|
|
4
|
+
|
|
5
|
+
// Improve this test with help from the Redwood Testing Doc:
|
|
6
|
+
// https://redwoodjs.com/docs/testing#testing-functions
|
|
7
|
+
|
|
8
|
+
describe('${name} function', () => {
|
|
9
|
+
|
|
10
|
+
it('Should respond with 200', async () => {
|
|
11
|
+
const httpEvent = mockHttpEvent({
|
|
12
|
+
queryStringParameters: {
|
|
13
|
+
id: '42', // Add parameters here
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const response = await handler(httpEvent, mockContext())
|
|
18
|
+
const { data } = JSON.parse(response.body)
|
|
19
|
+
|
|
20
|
+
expect(response.statusCode).toBe(200)
|
|
21
|
+
expect(data).toBe('${name} function')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// You can also use scenarios to test your api functions
|
|
25
|
+
// See guide here: https://redwoodjs.com/docs/testing#scenarios
|
|
26
|
+
//
|
|
27
|
+
// scenario('Scenario test', async () => {
|
|
28
|
+
//
|
|
29
|
+
// })
|
|
30
|
+
})
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { paramCase } from "change-case";
|
|
2
|
+
import pascalcase from "pascalcase";
|
|
3
|
+
import { pluralize, isPlural, isSingular } from "../../lib/rwPluralize.js";
|
|
4
|
+
const pathName = (path, name) => {
|
|
5
|
+
let routePath = path;
|
|
6
|
+
if (path && path.startsWith("{") && path.endsWith("}")) {
|
|
7
|
+
routePath = `/${paramCase(name)}/${path}`;
|
|
8
|
+
}
|
|
9
|
+
if (!routePath) {
|
|
10
|
+
routePath = `/${paramCase(name)}`;
|
|
11
|
+
}
|
|
12
|
+
return routePath;
|
|
13
|
+
};
|
|
14
|
+
function removeGeneratorName(name, generatorName) {
|
|
15
|
+
const pascalComponentName = pascalcase(generatorName);
|
|
16
|
+
const coercedName = name.replace(new RegExp(pascalComponentName + "$"), "");
|
|
17
|
+
return coercedName;
|
|
18
|
+
}
|
|
19
|
+
const validateName = (name) => {
|
|
20
|
+
if (name.match(/^\W/)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
"The <name> argument must start with a letter, number or underscore."
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const relationsForModel = (model) => {
|
|
27
|
+
return model.fields.filter((f) => f.relationName).map((field) => {
|
|
28
|
+
return field.name;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const intForeignKeysForModel = (model) => {
|
|
32
|
+
return model.fields.filter((f) => f.name.match(/Id$/) && f.type === "Int").map((f) => f.name);
|
|
33
|
+
};
|
|
34
|
+
const forcePluralizeWord = (word) => {
|
|
35
|
+
if (isPlural(word) && isSingular(word)) {
|
|
36
|
+
return pascalcase(`${word}_list`);
|
|
37
|
+
}
|
|
38
|
+
return pluralize(word);
|
|
39
|
+
};
|
|
40
|
+
const mapRouteParamTypeToTsType = (paramType) => {
|
|
41
|
+
const routeParamToTsType = {
|
|
42
|
+
Int: "number",
|
|
43
|
+
Float: "number",
|
|
44
|
+
Boolean: "boolean",
|
|
45
|
+
String: "string"
|
|
46
|
+
};
|
|
47
|
+
return routeParamToTsType[paramType] || "unknown";
|
|
48
|
+
};
|
|
49
|
+
const mapPrismaScalarToPagePropTsType = (scalarType) => {
|
|
50
|
+
const prismaScalarToTsType = {
|
|
51
|
+
String: "string",
|
|
52
|
+
Boolean: "boolean",
|
|
53
|
+
Int: "number",
|
|
54
|
+
BigInt: "number",
|
|
55
|
+
Float: "number",
|
|
56
|
+
Decimal: "number",
|
|
57
|
+
DateTime: "string",
|
|
58
|
+
Bytes: "Buffer"
|
|
59
|
+
};
|
|
60
|
+
return prismaScalarToTsType[scalarType] || "unknown";
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
forcePluralizeWord,
|
|
64
|
+
intForeignKeysForModel,
|
|
65
|
+
mapPrismaScalarToPagePropTsType,
|
|
66
|
+
mapRouteParamTypeToTsType,
|
|
67
|
+
pathName,
|
|
68
|
+
relationsForModel,
|
|
69
|
+
removeGeneratorName,
|
|
70
|
+
validateName
|
|
71
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import terminalLink from "terminal-link";
|
|
2
|
+
import { isTypeScriptProject } from "../../../lib/project.js";
|
|
3
|
+
import { getYargsDefaults, createHandler } from "../yargsCommandHelpers.js";
|
|
4
|
+
const command = "job <name>";
|
|
5
|
+
const description = "Generate a Background Job";
|
|
6
|
+
const builder = (yargs) => {
|
|
7
|
+
yargs.positional("name", {
|
|
8
|
+
description: "Name of the Job",
|
|
9
|
+
type: "string"
|
|
10
|
+
}).option("typescript", {
|
|
11
|
+
alias: "ts",
|
|
12
|
+
description: "Generate TypeScript files",
|
|
13
|
+
type: "boolean",
|
|
14
|
+
default: isTypeScriptProject()
|
|
15
|
+
}).option("tests", {
|
|
16
|
+
description: "Generate test files",
|
|
17
|
+
type: "boolean",
|
|
18
|
+
default: true
|
|
19
|
+
}).option("rollback", {
|
|
20
|
+
description: "Revert all generator actions if an error occurs",
|
|
21
|
+
type: "boolean",
|
|
22
|
+
default: true
|
|
23
|
+
}).epilogue(
|
|
24
|
+
`Also see the ${terminalLink(
|
|
25
|
+
"Redwood CLI Reference",
|
|
26
|
+
"https://redwoodjs.com/docs/cli-commands#generate-job"
|
|
27
|
+
)}`
|
|
28
|
+
);
|
|
29
|
+
Object.entries(getYargsDefaults()).forEach(([option, config]) => {
|
|
30
|
+
yargs.option(option, config);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const handler = createHandler("job");
|
|
34
|
+
export {
|
|
35
|
+
builder,
|
|
36
|
+
command,
|
|
37
|
+
description,
|
|
38
|
+
handler
|
|
39
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import * as changeCase from "change-case";
|
|
4
|
+
import execa from "execa";
|
|
5
|
+
import { Listr } from "listr2";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
7
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
8
|
+
import c from "../../../lib/colors.js";
|
|
9
|
+
import {
|
|
10
|
+
getPaths,
|
|
11
|
+
transformTSToJS,
|
|
12
|
+
writeFilesTask
|
|
13
|
+
} from "../../../lib/index.js";
|
|
14
|
+
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
15
|
+
import { validateName } from "../helpers.js";
|
|
16
|
+
import { templateForComponentFile } from "../yargsHandlerHelpers.js";
|
|
17
|
+
const normalizeName = (name) => {
|
|
18
|
+
return changeCase.pascalCase(name).replace(/Job$/, "");
|
|
19
|
+
};
|
|
20
|
+
const files = async ({
|
|
21
|
+
name,
|
|
22
|
+
queueName,
|
|
23
|
+
typescript: generateTypescript,
|
|
24
|
+
tests: generateTests = true,
|
|
25
|
+
...rest
|
|
26
|
+
}) => {
|
|
27
|
+
const extension = generateTypescript ? ".ts" : ".js";
|
|
28
|
+
const outputFiles = [];
|
|
29
|
+
const jobName = normalizeName(name);
|
|
30
|
+
const jobFiles = await templateForComponentFile({
|
|
31
|
+
name: jobName,
|
|
32
|
+
componentName: jobName,
|
|
33
|
+
extension,
|
|
34
|
+
apiPathSection: "jobs",
|
|
35
|
+
generator: "job",
|
|
36
|
+
templatePath: "job.ts.template",
|
|
37
|
+
templateVars: { name: jobName, queueName, ...rest },
|
|
38
|
+
outputPath: path.join(
|
|
39
|
+
getPaths().api.jobs,
|
|
40
|
+
`${jobName}Job`,
|
|
41
|
+
`${jobName}Job${extension}`
|
|
42
|
+
)
|
|
43
|
+
});
|
|
44
|
+
outputFiles.push(jobFiles);
|
|
45
|
+
if (generateTests) {
|
|
46
|
+
const testFile = await templateForComponentFile({
|
|
47
|
+
name: jobName,
|
|
48
|
+
componentName: jobName,
|
|
49
|
+
extension,
|
|
50
|
+
apiPathSection: "jobs",
|
|
51
|
+
generator: "job",
|
|
52
|
+
templatePath: "test.ts.template",
|
|
53
|
+
templateVars: { ...rest },
|
|
54
|
+
outputPath: path.join(
|
|
55
|
+
getPaths().api.jobs,
|
|
56
|
+
`${jobName}Job`,
|
|
57
|
+
`${jobName}Job.test${extension}`
|
|
58
|
+
)
|
|
59
|
+
});
|
|
60
|
+
const scenarioFile = await templateForComponentFile({
|
|
61
|
+
name: jobName,
|
|
62
|
+
componentName: jobName,
|
|
63
|
+
extension,
|
|
64
|
+
apiPathSection: "jobs",
|
|
65
|
+
generator: "job",
|
|
66
|
+
templatePath: "scenarios.ts.template",
|
|
67
|
+
templateVars: { ...rest },
|
|
68
|
+
outputPath: path.join(
|
|
69
|
+
getPaths().api.jobs,
|
|
70
|
+
`${jobName}Job`,
|
|
71
|
+
`${jobName}Job.scenarios${extension}`
|
|
72
|
+
)
|
|
73
|
+
});
|
|
74
|
+
outputFiles.push(testFile);
|
|
75
|
+
outputFiles.push(scenarioFile);
|
|
76
|
+
}
|
|
77
|
+
return outputFiles.reduce(async (accP, [outputPath, content]) => {
|
|
78
|
+
const acc = await accP;
|
|
79
|
+
const template = generateTypescript ? content : await transformTSToJS(outputPath, content);
|
|
80
|
+
return {
|
|
81
|
+
[outputPath]: template,
|
|
82
|
+
...acc
|
|
83
|
+
};
|
|
84
|
+
}, Promise.resolve({}));
|
|
85
|
+
};
|
|
86
|
+
const handler = async ({ name, force, ...rest }) => {
|
|
87
|
+
recordTelemetryAttributes({
|
|
88
|
+
command: "generate job",
|
|
89
|
+
force,
|
|
90
|
+
rollback: rest.rollback
|
|
91
|
+
});
|
|
92
|
+
validateName(name);
|
|
93
|
+
let queueName = "default";
|
|
94
|
+
try {
|
|
95
|
+
const jobsManagerFile = getPaths().api.distJobsConfig;
|
|
96
|
+
const jobManager = await import(pathToFileURL(jobsManagerFile).href);
|
|
97
|
+
queueName = jobManager.jobs?.queues[0] ?? "default";
|
|
98
|
+
} catch (_e) {
|
|
99
|
+
}
|
|
100
|
+
const tasks = new Listr(
|
|
101
|
+
[
|
|
102
|
+
{
|
|
103
|
+
title: "Generating job files...",
|
|
104
|
+
task: async () => {
|
|
105
|
+
const jobFiles = await files({ name, queueName, ...rest });
|
|
106
|
+
return writeFilesTask(jobFiles, { overwriteExisting: force });
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
title: "Cleaning up...",
|
|
111
|
+
task: () => {
|
|
112
|
+
execa.commandSync("yarn", [
|
|
113
|
+
"eslint",
|
|
114
|
+
"--fix",
|
|
115
|
+
"--config",
|
|
116
|
+
`${getPaths().base}/node_modules/@cedarjs/eslint-config/shared.js`,
|
|
117
|
+
`${getPaths().api.jobsConfig}`
|
|
118
|
+
]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
{ rendererOptions: { collapseSubtasks: false }, exitOnError: true }
|
|
123
|
+
);
|
|
124
|
+
try {
|
|
125
|
+
if (rest.rollback && !force) {
|
|
126
|
+
prepareForRollback(tasks);
|
|
127
|
+
}
|
|
128
|
+
await tasks.run();
|
|
129
|
+
} catch (e) {
|
|
130
|
+
errorTelemetry(process.argv, e.message);
|
|
131
|
+
console.error(c.error(e.message));
|
|
132
|
+
process.exit(e?.exitCode || 1);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
export {
|
|
136
|
+
files,
|
|
137
|
+
handler
|
|
138
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ScenarioData } from '@cedarjs/testing/api'
|
|
2
|
+
|
|
3
|
+
export const standard = defineScenario({
|
|
4
|
+
// Define the "fixture" to write into your test database here
|
|
5
|
+
// See guide: https://redwoodjs.com/docs/testing#scenarios
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
export type StandardScenario = ScenarioData<unknown>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCommand,
|
|
3
|
+
createDescription,
|
|
4
|
+
createBuilder,
|
|
5
|
+
createHandler,
|
|
6
|
+
getYargsDefaults
|
|
7
|
+
} from "../yargsCommandHelpers.js";
|
|
8
|
+
const optionsObj = () => ({
|
|
9
|
+
skipLink: {
|
|
10
|
+
default: false,
|
|
11
|
+
description: "Generate with skip link",
|
|
12
|
+
type: "boolean"
|
|
13
|
+
},
|
|
14
|
+
...getYargsDefaults()
|
|
15
|
+
});
|
|
16
|
+
const command = createCommand("layout");
|
|
17
|
+
const description = createDescription("layout");
|
|
18
|
+
const builder = createBuilder({ componentName: "layout", optionsObj });
|
|
19
|
+
const handler = createHandler("layout");
|
|
20
|
+
export {
|
|
21
|
+
builder,
|
|
22
|
+
command,
|
|
23
|
+
description,
|
|
24
|
+
handler
|
|
25
|
+
};
|