@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,58 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import humanize from 'humanize-string'
|
|
4
|
+
|
|
5
|
+
const MAX_STRING_LENGTH = 150
|
|
6
|
+
|
|
7
|
+
export const formatEnum = (values: string | string[] | null | undefined) => {
|
|
8
|
+
let output = ''
|
|
9
|
+
|
|
10
|
+
if (Array.isArray(values)) {
|
|
11
|
+
const humanizedValues = values.map((value) => humanize(value))
|
|
12
|
+
output = humanizedValues.join(', ')
|
|
13
|
+
} else if (typeof values === 'string') {
|
|
14
|
+
output = humanize(values)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return output
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const jsonDisplay = (obj: unknown) => {
|
|
21
|
+
return (
|
|
22
|
+
<pre>
|
|
23
|
+
<code>{JSON.stringify(obj, null, 2)}</code>
|
|
24
|
+
</pre>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const truncate = (value: string | number) => {
|
|
29
|
+
let output = value?.toString() ?? ''
|
|
30
|
+
|
|
31
|
+
if (output.length > MAX_STRING_LENGTH) {
|
|
32
|
+
output = output.substring(0, MAX_STRING_LENGTH) + '...'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return output
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const jsonTruncate = (obj: unknown) => {
|
|
39
|
+
return truncate(JSON.stringify(obj, null, 2))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const timeTag = (dateTime?: string) => {
|
|
43
|
+
let output: string | JSX.Element = ''
|
|
44
|
+
|
|
45
|
+
if (dateTime) {
|
|
46
|
+
output = (
|
|
47
|
+
<time dateTime={dateTime} title={dateTime}>
|
|
48
|
+
{new Date(dateTime).toUTCString()}
|
|
49
|
+
</time>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return output
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const checkboxInputTag = (checked: boolean) => {
|
|
57
|
+
return <input type="checkbox" checked={checked} disabled />
|
|
58
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Edit${singularPascalName}Cell from '${importComponentEditNameCell}'
|
|
2
|
+
|
|
3
|
+
type ${pascalName}PageProps = {
|
|
4
|
+
${idName}: ${idTsType}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const Edit${singularPascalName}Page = ({ ${idName} }: ${pascalName}PageProps) => {
|
|
8
|
+
return <Edit${singularPascalName}Cell ${idName}={${idName}} />
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default Edit${singularPascalName}Page
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ${singularPascalName}Cell from '${importComponentNameCell}'
|
|
2
|
+
|
|
3
|
+
type ${pascalName}PageProps = {
|
|
4
|
+
${idName}: ${idTsType}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const ${singularPascalName}Page = ({ ${idName} }: ${pascalName}PageProps) => {
|
|
8
|
+
return <${singularPascalName}Cell ${idName}={${idName}} />
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default ${singularPascalName}Page
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import terminalLink from "terminal-link";
|
|
2
|
+
import { createHandler, getYargsDefaults } from "../yargsCommandHelpers.js";
|
|
3
|
+
const command = "script <name>";
|
|
4
|
+
const description = "Generate a command line script";
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs.positional("name", {
|
|
7
|
+
description: "A descriptor of what this script does",
|
|
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-script"
|
|
17
|
+
)}`
|
|
18
|
+
);
|
|
19
|
+
Object.entries(getYargsDefaults()).forEach(([option, config]) => {
|
|
20
|
+
yargs.option(option, config);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const handler = createHandler("script");
|
|
24
|
+
export {
|
|
25
|
+
builder,
|
|
26
|
+
command,
|
|
27
|
+
description,
|
|
28
|
+
handler
|
|
29
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { Listr } from "listr2";
|
|
4
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
5
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
6
|
+
import c from "../../../lib/colors.js";
|
|
7
|
+
import {
|
|
8
|
+
getPaths,
|
|
9
|
+
writeFilesTask,
|
|
10
|
+
transformTSToJS
|
|
11
|
+
} from "../../../lib/index.js";
|
|
12
|
+
import { prepareForRollback } from "../../../lib/rollback.js";
|
|
13
|
+
import { validateName } from "../helpers.js";
|
|
14
|
+
const TEMPLATE_PATH = path.resolve(
|
|
15
|
+
import.meta.dirname,
|
|
16
|
+
"templates",
|
|
17
|
+
"script.ts.template"
|
|
18
|
+
);
|
|
19
|
+
const TSCONFIG_TEMPLATE = path.resolve(
|
|
20
|
+
import.meta.dirname,
|
|
21
|
+
"templates",
|
|
22
|
+
"tsconfig.json.template"
|
|
23
|
+
);
|
|
24
|
+
const files = async ({ name, typescript = false }) => {
|
|
25
|
+
const outputFilename = `${name}.${typescript ? "ts" : "js"}`;
|
|
26
|
+
const outputPath = path.join(getPaths().scripts, outputFilename);
|
|
27
|
+
const scriptTsConfigPath = path.join(getPaths().scripts, "tsconfig.json");
|
|
28
|
+
const template = fs.readFileSync(TEMPLATE_PATH, "utf-8");
|
|
29
|
+
return {
|
|
30
|
+
[outputPath]: typescript ? template : await transformTSToJS(outputPath, template),
|
|
31
|
+
// Add tsconfig for type and cmd+click support if project is TS
|
|
32
|
+
...typescript && !fs.existsSync(scriptTsConfigPath) && {
|
|
33
|
+
[scriptTsConfigPath]: fs.readFileSync(TSCONFIG_TEMPLATE, "utf-8")
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const handler = async ({ force, ...args }) => {
|
|
38
|
+
recordTelemetryAttributes({
|
|
39
|
+
command: "generate script",
|
|
40
|
+
force,
|
|
41
|
+
rollback: args.rollback
|
|
42
|
+
});
|
|
43
|
+
const POST_RUN_INSTRUCTIONS = `Next steps...
|
|
44
|
+
|
|
45
|
+
${c.warning(
|
|
46
|
+
"After modifying your script, you can invoke it like:"
|
|
47
|
+
)}
|
|
48
|
+
|
|
49
|
+
yarn rw exec ${args.name}
|
|
50
|
+
|
|
51
|
+
yarn rw exec ${args.name} --param1 true
|
|
52
|
+
`;
|
|
53
|
+
validateName(args.name);
|
|
54
|
+
const tasks = new Listr(
|
|
55
|
+
[
|
|
56
|
+
{
|
|
57
|
+
title: "Generating script file...",
|
|
58
|
+
task: async () => {
|
|
59
|
+
return writeFilesTask(await files(args), { overwriteExisting: force });
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title: "Next steps...",
|
|
64
|
+
task: (_ctx, task) => {
|
|
65
|
+
task.title = POST_RUN_INSTRUCTIONS;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
].filter(Boolean),
|
|
69
|
+
{ rendererOptions: { collapseSubtasks: false } }
|
|
70
|
+
);
|
|
71
|
+
try {
|
|
72
|
+
if (args.rollback && !force) {
|
|
73
|
+
prepareForRollback(tasks);
|
|
74
|
+
}
|
|
75
|
+
await tasks.run();
|
|
76
|
+
} catch (e) {
|
|
77
|
+
errorTelemetry(process.argv, e.message);
|
|
78
|
+
console.log(c.error(e.message));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
export {
|
|
83
|
+
files,
|
|
84
|
+
handler
|
|
85
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Append api/* to import from api and web/* to import from web
|
|
2
|
+
|
|
3
|
+
// To access your database uncomment the line below
|
|
4
|
+
// import { db } from 'api/src/lib/db'
|
|
5
|
+
|
|
6
|
+
interface Args {
|
|
7
|
+
_: string[]
|
|
8
|
+
[key: string]: unknown
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default async ({ args }: Args) => {
|
|
12
|
+
// Your script here...
|
|
13
|
+
console.log(':: Executing script with args ::')
|
|
14
|
+
console.log(args)
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"noEmit": true,
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"baseUrl": "./",
|
|
7
|
+
"paths": {
|
|
8
|
+
"$api/*": [
|
|
9
|
+
"../api/*",
|
|
10
|
+
],
|
|
11
|
+
"api/*": [
|
|
12
|
+
"../api/*",
|
|
13
|
+
],
|
|
14
|
+
"$web/*": [
|
|
15
|
+
"../web/*",
|
|
16
|
+
],
|
|
17
|
+
"web/*": [
|
|
18
|
+
"../web/*",
|
|
19
|
+
],
|
|
20
|
+
"$web/src/*": [
|
|
21
|
+
"../web/src/*",
|
|
22
|
+
"../.redwood/types/mirror/web/src/*"
|
|
23
|
+
],
|
|
24
|
+
"web/src/*": [
|
|
25
|
+
"../web/src/*",
|
|
26
|
+
"../.redwood/types/mirror/web/src/*"
|
|
27
|
+
],
|
|
28
|
+
"types/*": ["../types/*", "../web/types/*", "../api/types/*"],
|
|
29
|
+
},
|
|
30
|
+
"typeRoots": ["../node_modules/@types"],
|
|
31
|
+
"jsx": "preserve",
|
|
32
|
+
},
|
|
33
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import terminalLink from "terminal-link";
|
|
2
|
+
import { createHandler, getYargsDefaults } from "../yargsCommandHelpers.js";
|
|
3
|
+
const getDefaults = () => {
|
|
4
|
+
return {
|
|
5
|
+
...getYargsDefaults(),
|
|
6
|
+
crud: {
|
|
7
|
+
default: true,
|
|
8
|
+
description: "Also generate mutations",
|
|
9
|
+
type: "boolean"
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const command = "sdl <model>";
|
|
14
|
+
const description = "Generate a GraphQL schema and service component based on a given DB schema Model";
|
|
15
|
+
const builder = (yargs) => {
|
|
16
|
+
yargs.positional("model", {
|
|
17
|
+
description: "Model to generate the sdl for",
|
|
18
|
+
type: "string"
|
|
19
|
+
}).option("tests", {
|
|
20
|
+
description: "Generate test files",
|
|
21
|
+
type: "boolean"
|
|
22
|
+
// don't give it a default value, it gets overwritten in first few lines
|
|
23
|
+
// of the handler
|
|
24
|
+
}).option("docs", {
|
|
25
|
+
description: "Generate SDL and GraphQL comments to use in documentation",
|
|
26
|
+
type: "boolean"
|
|
27
|
+
}).option("rollback", {
|
|
28
|
+
description: "Revert all generator actions if an error occurs",
|
|
29
|
+
type: "boolean",
|
|
30
|
+
default: true
|
|
31
|
+
}).epilogue(
|
|
32
|
+
`Also see the ${terminalLink(
|
|
33
|
+
"Redwood CLI Reference",
|
|
34
|
+
"https://redwoodjs.com/docs/cli-commands#generate-sdl"
|
|
35
|
+
)}`
|
|
36
|
+
);
|
|
37
|
+
Object.entries(getDefaults()).forEach(([option, config]) => {
|
|
38
|
+
yargs.option(option, config);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const handler = createHandler("sdl");
|
|
42
|
+
export {
|
|
43
|
+
builder,
|
|
44
|
+
command,
|
|
45
|
+
description,
|
|
46
|
+
getDefaults,
|
|
47
|
+
handler
|
|
48
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import boxen from "boxen";
|
|
3
|
+
import camelcase from "camelcase";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { Listr } from "listr2";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
7
|
+
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
8
|
+
import { getConfig } from "@cedarjs/project-config";
|
|
9
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
10
|
+
import c from "../../../lib/colors.js";
|
|
11
|
+
import {
|
|
12
|
+
generateTemplate,
|
|
13
|
+
transformTSToJS,
|
|
14
|
+
getPaths,
|
|
15
|
+
writeFilesTask
|
|
16
|
+
} from "../../../lib/index.js";
|
|
17
|
+
import {
|
|
18
|
+
prepareForRollback,
|
|
19
|
+
addFunctionToRollback
|
|
20
|
+
} from "../../../lib/rollback.js";
|
|
21
|
+
import { pluralize } from "../../../lib/rwPluralize.js";
|
|
22
|
+
import {
|
|
23
|
+
getSchema,
|
|
24
|
+
getEnum,
|
|
25
|
+
verifyModelName
|
|
26
|
+
} from "../../../lib/schemaHelpers.js";
|
|
27
|
+
import { relationsForModel } from "../helpers.js";
|
|
28
|
+
import { files as serviceFiles } from "../service/serviceHandler.js";
|
|
29
|
+
import { customOrDefaultTemplatePath } from "../yargsHandlerHelpers.js";
|
|
30
|
+
const DEFAULT_IGNORE_FIELDS_FOR_INPUT = ["createdAt", "updatedAt"];
|
|
31
|
+
const missingIdConsoleMessage = () => {
|
|
32
|
+
const line1 = chalk.bold.yellow("WARNING") + ": Cannot generate CRUD SDL without an `@id` database column.";
|
|
33
|
+
const line2 = "If you are trying to generate for a many-to-many join table ";
|
|
34
|
+
const line3 = "you'll need to update your schema definition to include";
|
|
35
|
+
const line4 = "an `@id` column. Read more here: ";
|
|
36
|
+
const line5 = chalk.underline.blue(
|
|
37
|
+
"https://redwoodjs.com/docs/schema-relations"
|
|
38
|
+
);
|
|
39
|
+
console.error(
|
|
40
|
+
boxen(line1 + "\n\n" + line2 + "\n" + line3 + "\n" + line4 + "\n" + line5, {
|
|
41
|
+
padding: 1,
|
|
42
|
+
margin: { top: 1, bottom: 3, right: 1, left: 2 },
|
|
43
|
+
borderStyle: "single"
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const addFieldGraphQLComment = (field, str) => {
|
|
48
|
+
const description = field.documentation || `Description for ${field.name}.`;
|
|
49
|
+
return `
|
|
50
|
+
"${description}"
|
|
51
|
+
${str}`;
|
|
52
|
+
};
|
|
53
|
+
const modelFieldToSDL = ({
|
|
54
|
+
field,
|
|
55
|
+
required = true,
|
|
56
|
+
types = {},
|
|
57
|
+
docs = false
|
|
58
|
+
}) => {
|
|
59
|
+
if (Object.entries(types).length) {
|
|
60
|
+
field.type = field.kind === "object" ? idType(types[field.type]) : field.type;
|
|
61
|
+
}
|
|
62
|
+
const prismaTypeToGraphqlType = {
|
|
63
|
+
Json: "JSON",
|
|
64
|
+
Decimal: "Float",
|
|
65
|
+
Bytes: "Byte"
|
|
66
|
+
};
|
|
67
|
+
const gqlType = prismaTypeToGraphqlType[field.type] || field.type;
|
|
68
|
+
const type = field.isList ? `[${gqlType}]` : gqlType;
|
|
69
|
+
const isRequired = field.isRequired && required || field.isList || field.isId;
|
|
70
|
+
const fieldContent = `${field.name}: ${type}${isRequired ? "!" : ""}`;
|
|
71
|
+
if (docs) {
|
|
72
|
+
return addFieldGraphQLComment(field, fieldContent);
|
|
73
|
+
} else {
|
|
74
|
+
return fieldContent;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const querySDL = (model, docs = false) => {
|
|
78
|
+
return model.fields.map((field) => modelFieldToSDL({ field, docs }));
|
|
79
|
+
};
|
|
80
|
+
const inputSDL = (model, required, types = {}, docs = false) => {
|
|
81
|
+
const ignoredFields = DEFAULT_IGNORE_FIELDS_FOR_INPUT;
|
|
82
|
+
return model.fields.filter((field) => {
|
|
83
|
+
const idField = model.fields.find((field2) => field2.isId);
|
|
84
|
+
if (idField && idField.default) {
|
|
85
|
+
ignoredFields.push(idField.name);
|
|
86
|
+
}
|
|
87
|
+
return ignoredFields.indexOf(field.name) === -1 && field.kind !== "object";
|
|
88
|
+
}).map((field) => modelFieldToSDL({ field, required, types, docs }));
|
|
89
|
+
};
|
|
90
|
+
const idInputSDL = (idType2, docs) => {
|
|
91
|
+
if (!Array.isArray(idType2)) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
return idType2.map(
|
|
95
|
+
(field) => modelFieldToSDL({ field, required: true, types: {}, docs })
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
const createInputSDL = (model, types = {}, docs = false) => {
|
|
99
|
+
return inputSDL(model, true, types, docs);
|
|
100
|
+
};
|
|
101
|
+
const updateInputSDL = (model, types = {}, docs = false) => {
|
|
102
|
+
return inputSDL(model, false, types, docs);
|
|
103
|
+
};
|
|
104
|
+
const idType = (model, crud) => {
|
|
105
|
+
if (!crud) {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
if (model.primaryKey?.fields.length) {
|
|
109
|
+
const { fields: fieldNames } = model.primaryKey;
|
|
110
|
+
return fieldNames.map((name) => model.fields.find((f) => f.name === name));
|
|
111
|
+
}
|
|
112
|
+
const idField = model.fields.find((field) => field.isId);
|
|
113
|
+
if (!idField) {
|
|
114
|
+
missingIdConsoleMessage();
|
|
115
|
+
throw new Error("Failed: Could not generate SDL");
|
|
116
|
+
}
|
|
117
|
+
return idField.type;
|
|
118
|
+
};
|
|
119
|
+
const idName = (model, crud) => {
|
|
120
|
+
if (!crud) {
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
const idField = model.fields.find((field) => field.isId);
|
|
124
|
+
if (!idField) {
|
|
125
|
+
missingIdConsoleMessage();
|
|
126
|
+
throw new Error("Failed: Could not generate SDL");
|
|
127
|
+
}
|
|
128
|
+
return idField.name;
|
|
129
|
+
};
|
|
130
|
+
const sdlFromSchemaModel = async (name, crud, docs = false) => {
|
|
131
|
+
const model = await getSchema(name);
|
|
132
|
+
const types = (await Promise.all(
|
|
133
|
+
model.fields.filter((field) => field.kind === "object").map(async (field) => {
|
|
134
|
+
const model2 = await getSchema(field.type);
|
|
135
|
+
return model2;
|
|
136
|
+
})
|
|
137
|
+
)).reduce((acc, cur) => ({ ...acc, [cur.name]: cur }), {});
|
|
138
|
+
const enums = (await Promise.all(
|
|
139
|
+
model.fields.filter((field) => field.kind === "enum").map(async (field) => {
|
|
140
|
+
const enumDef = await getEnum(field.type);
|
|
141
|
+
return enumDef;
|
|
142
|
+
})
|
|
143
|
+
)).reduce((acc, curr) => acc.concat(curr), []);
|
|
144
|
+
const modelName = model.name;
|
|
145
|
+
const modelDescription = model.documentation || `Representation of ${modelName}.`;
|
|
146
|
+
const idTypeRes = idType(model, crud);
|
|
147
|
+
return {
|
|
148
|
+
modelName,
|
|
149
|
+
modelDescription,
|
|
150
|
+
query: querySDL(model, docs).join("\n "),
|
|
151
|
+
createInput: createInputSDL(model, types, docs).join("\n "),
|
|
152
|
+
updateInput: updateInputSDL(model, types, docs).join("\n "),
|
|
153
|
+
idInput: idInputSDL(idTypeRes, docs).join("\n "),
|
|
154
|
+
idType: idType(model, crud),
|
|
155
|
+
idName: idName(model, crud),
|
|
156
|
+
relations: relationsForModel(model),
|
|
157
|
+
enums
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
const files = async ({
|
|
161
|
+
name,
|
|
162
|
+
crud = true,
|
|
163
|
+
docs = false,
|
|
164
|
+
tests,
|
|
165
|
+
typescript
|
|
166
|
+
}) => {
|
|
167
|
+
const {
|
|
168
|
+
modelName,
|
|
169
|
+
modelDescription,
|
|
170
|
+
query,
|
|
171
|
+
createInput,
|
|
172
|
+
updateInput,
|
|
173
|
+
idInput,
|
|
174
|
+
idType: idType2,
|
|
175
|
+
idName: idName2,
|
|
176
|
+
relations,
|
|
177
|
+
enums
|
|
178
|
+
} = await sdlFromSchemaModel(name, crud, docs);
|
|
179
|
+
const templatePath = customOrDefaultTemplatePath({
|
|
180
|
+
side: "api",
|
|
181
|
+
generator: "sdl",
|
|
182
|
+
templatePath: "sdl.ts.template"
|
|
183
|
+
});
|
|
184
|
+
let template = await generateTemplate(templatePath, {
|
|
185
|
+
docs,
|
|
186
|
+
modelName,
|
|
187
|
+
modelDescription,
|
|
188
|
+
name,
|
|
189
|
+
crud,
|
|
190
|
+
query,
|
|
191
|
+
createInput,
|
|
192
|
+
updateInput,
|
|
193
|
+
idInput,
|
|
194
|
+
idType: idType2,
|
|
195
|
+
idName: idName2,
|
|
196
|
+
enums
|
|
197
|
+
});
|
|
198
|
+
const extension = typescript ? "ts" : "js";
|
|
199
|
+
let outputPath = path.join(
|
|
200
|
+
getPaths().api.graphql,
|
|
201
|
+
`${camelcase(pluralize(name))}.sdl.${extension}`
|
|
202
|
+
);
|
|
203
|
+
if (typescript) {
|
|
204
|
+
template = await transformTSToJS(outputPath, template);
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
[outputPath]: template,
|
|
208
|
+
...await serviceFiles({
|
|
209
|
+
name,
|
|
210
|
+
crud,
|
|
211
|
+
tests,
|
|
212
|
+
relations,
|
|
213
|
+
typescript
|
|
214
|
+
})
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
const handler = async ({
|
|
218
|
+
model,
|
|
219
|
+
crud,
|
|
220
|
+
force,
|
|
221
|
+
tests,
|
|
222
|
+
typescript,
|
|
223
|
+
docs,
|
|
224
|
+
rollback
|
|
225
|
+
}) => {
|
|
226
|
+
if (tests === void 0) {
|
|
227
|
+
tests = getConfig().generate.tests;
|
|
228
|
+
}
|
|
229
|
+
recordTelemetryAttributes({
|
|
230
|
+
command: "generate sdl",
|
|
231
|
+
crud,
|
|
232
|
+
force,
|
|
233
|
+
tests,
|
|
234
|
+
typescript,
|
|
235
|
+
docs,
|
|
236
|
+
rollback
|
|
237
|
+
});
|
|
238
|
+
try {
|
|
239
|
+
const { name } = await verifyModelName({ name: model });
|
|
240
|
+
const tasks = new Listr(
|
|
241
|
+
[
|
|
242
|
+
{
|
|
243
|
+
title: "Generating SDL files...",
|
|
244
|
+
task: async () => {
|
|
245
|
+
const f = await files({ name, tests, crud, typescript, docs });
|
|
246
|
+
return writeFilesTask(f, { overwriteExisting: force });
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
title: `Generating types ...`,
|
|
251
|
+
task: async () => {
|
|
252
|
+
const { errors } = await generateTypes();
|
|
253
|
+
for (const { message, error } of errors) {
|
|
254
|
+
console.error(message);
|
|
255
|
+
console.log();
|
|
256
|
+
console.error(error);
|
|
257
|
+
console.log();
|
|
258
|
+
}
|
|
259
|
+
addFunctionToRollback(generateTypes, true);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
].filter(Boolean),
|
|
263
|
+
{
|
|
264
|
+
rendererOptions: { collapseSubtasks: false },
|
|
265
|
+
exitOnError: true,
|
|
266
|
+
silentRendererCondition: process.env.NODE_ENV === "test"
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
if (rollback && !force) {
|
|
270
|
+
prepareForRollback(tasks);
|
|
271
|
+
}
|
|
272
|
+
await tasks.run();
|
|
273
|
+
} catch (e) {
|
|
274
|
+
errorTelemetry(process.argv, e.message);
|
|
275
|
+
console.error(c.error(e.message));
|
|
276
|
+
process.exit(e?.exitCode || 1);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
export {
|
|
280
|
+
files,
|
|
281
|
+
handler
|
|
282
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export const schema = gql`
|
|
2
|
+
<% if (docs) { %>
|
|
3
|
+
"""${modelDescription}"""
|
|
4
|
+
<% } %>
|
|
5
|
+
type ${singularPascalName} {
|
|
6
|
+
${query}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
<% if (enums.length > 0) {%>
|
|
10
|
+
<% enums.forEach((enumDef, idx)=> {
|
|
11
|
+
const enumName = enums[idx].name
|
|
12
|
+
const enumDescription = enums[idx].documentation || `Possible values for ${enums[idx].name}`
|
|
13
|
+
%>
|
|
14
|
+
<% if (docs) { %>
|
|
15
|
+
"""${enumDescription}"""
|
|
16
|
+
<% } %>
|
|
17
|
+
enum ${enums[idx].name} {<% enums[idx].values.forEach((enumDefValue, idk)=> { %>
|
|
18
|
+
${enums[idx].values[idk].name}<% }) %>
|
|
19
|
+
}
|
|
20
|
+
<%}) %><% } %>
|
|
21
|
+
<% if (docs) { %>
|
|
22
|
+
"""About queries"""
|
|
23
|
+
<% } %>
|
|
24
|
+
type Query {
|
|
25
|
+
<% if (docs) { %>
|
|
26
|
+
"Fetch ${pluralPascalName}."
|
|
27
|
+
<% } %>${pluralCamelName}: [${singularPascalName}!]! @requireAuth<% if (crud) { %>
|
|
28
|
+
<% if (docs) { %>
|
|
29
|
+
"Fetch a ${singularPascalName} by id."
|
|
30
|
+
<% } %>${singularCamelName}(${idName}: ${idType}!): ${singularPascalName} @requireAuth<% } %>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
<% if (docs) { %>
|
|
34
|
+
"""Autogenerated input type of Input${singularPascalName}."""
|
|
35
|
+
<% } %>
|
|
36
|
+
input Create${singularPascalName}Input {
|
|
37
|
+
${createInput}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
<% if (idInput) { %>
|
|
41
|
+
<% if (docs) { %>
|
|
42
|
+
"""Autogenerated ID input type of ${singularPascalName}Id."""
|
|
43
|
+
<% } %>
|
|
44
|
+
input ${singularPascalName}IdInput {
|
|
45
|
+
${idInput}
|
|
46
|
+
}
|
|
47
|
+
<% } %>
|
|
48
|
+
|
|
49
|
+
<% if (docs) { %>
|
|
50
|
+
"""Autogenerated input type of Update${singularPascalName}."""
|
|
51
|
+
<% } %>
|
|
52
|
+
input Update${singularPascalName}Input {
|
|
53
|
+
${updateInput}
|
|
54
|
+
}<% if (crud) { %>
|
|
55
|
+
|
|
56
|
+
<% if (docs) { %>
|
|
57
|
+
"""About mutations"""
|
|
58
|
+
<% } %>
|
|
59
|
+
type Mutation {
|
|
60
|
+
<% if (docs) { %>
|
|
61
|
+
"Creates a new ${singularPascalName}."
|
|
62
|
+
<% } %>create${singularPascalName}(input: Create${singularPascalName}Input!): ${singularPascalName}! @requireAuth
|
|
63
|
+
<% if (docs) { %>
|
|
64
|
+
"Updates an existing ${singularPascalName}."
|
|
65
|
+
<% } %>update${singularPascalName}(${idName}: ${idType}!, input: Update${singularPascalName}Input!): ${singularPascalName}! @requireAuth
|
|
66
|
+
<% if (docs) { %>
|
|
67
|
+
"Deletes an existing ${singularPascalName}."
|
|
68
|
+
<% } %>delete${singularPascalName}(${idName}: ${idType}!): ${singularPascalName}! @requireAuth
|
|
69
|
+
}<% } %>
|
|
70
|
+
`
|