@nx/react 0.0.0-pr-22179-271588f
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 +22 -0
- package/README.md +68 -0
- package/ast-utils.d.ts +1 -0
- package/ast-utils.js +11 -0
- package/babel.d.ts +20 -0
- package/babel.js +50 -0
- package/executors.json +14 -0
- package/generators.json +112 -0
- package/index.d.ts +22 -0
- package/index.js +47 -0
- package/mf/dynamic-federation.d.ts +4 -0
- package/mf/dynamic-federation.js +75 -0
- package/mf/index.d.ts +1 -0
- package/mf/index.js +7 -0
- package/migrations.json +310 -0
- package/module-federation.d.ts +4 -0
- package/module-federation.js +12 -0
- package/package.json +49 -0
- package/plugins/bundle-rollup.d.ts +1 -0
- package/plugins/bundle-rollup.js +47 -0
- package/plugins/component-testing/index.d.ts +37 -0
- package/plugins/component-testing/index.js +222 -0
- package/plugins/component-testing/webpack-fallback.d.ts +5 -0
- package/plugins/component-testing/webpack-fallback.js +125 -0
- package/plugins/jest.d.ts +1 -0
- package/plugins/jest.js +59 -0
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.d.ts +4 -0
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +60 -0
- package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.d.ts +8 -0
- package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.js +13 -0
- package/plugins/storybook/index.d.ts +3 -0
- package/plugins/storybook/index.js +174 -0
- package/plugins/storybook/merge-plugins.d.ts +3 -0
- package/plugins/storybook/merge-plugins.js +17 -0
- package/plugins/webpack.d.ts +1 -0
- package/plugins/webpack.js +6 -0
- package/plugins/with-react.d.ts +10 -0
- package/plugins/with-react.js +22 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +25 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +211 -0
- package/src/executors/module-federation-dev-server/schema.json +114 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +9 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +106 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +48 -0
- package/src/generators/application/application.d.ts +5 -0
- package/src/generators/application/application.js +232 -0
- package/src/generators/application/files/base-rspack/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-rspack/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-rspack/src/favicon.ico +0 -0
- package/src/generators/application/files/base-rspack/src/index.html +14 -0
- package/src/generators/application/files/base-rspack/src/main.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +14 -0
- package/src/generators/application/files/base-vite/index.html__tmpl__ +16 -0
- package/src/generators/application/files/base-vite/public/favicon.ico +0 -0
- package/src/generators/application/files/base-vite/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-vite/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-vite/src/environments/environment.prod.ts__tmpl__ +3 -0
- package/src/generators/application/files/base-vite/src/environments/environment.ts__tmpl__ +6 -0
- package/src/generators/application/files/base-vite/src/main.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +14 -0
- package/src/generators/application/files/base-webpack/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-webpack/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-webpack/src/favicon.ico +0 -0
- package/src/generators/application/files/base-webpack/src/index.html +12 -0
- package/src/generators/application/files/base-webpack/src/main.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +14 -0
- package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +50 -0
- package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +886 -0
- package/src/generators/application/files/style-css-module/src/app/__fileName__.module.__style__ +1 -0
- package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +36 -0
- package/src/generators/application/files/style-css-module/src/styles.__style__ +1 -0
- package/src/generators/application/files/style-global-css/src/app/__fileName__.__style__ +1 -0
- package/src/generators/application/files/style-global-css/src/app/__fileName__.tsx__tmpl__ +35 -0
- package/src/generators/application/files/style-global-css/src/styles.__style__ +1 -0
- package/src/generators/application/files/style-none/src/app/__fileName__.tsx__tmpl__ +34 -0
- package/src/generators/application/files/style-styled-jsx/src/app/__fileName__.tsx__tmpl__ +37 -0
- package/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ +40 -0
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +33 -0
- package/src/generators/application/files/style-tailwind/src/styles.css +1 -0
- package/src/generators/application/lib/add-e2e.d.ts +3 -0
- package/src/generators/application/lib/add-e2e.js +79 -0
- package/src/generators/application/lib/add-jest.d.ts +3 -0
- package/src/generators/application/lib/add-jest.js +21 -0
- package/src/generators/application/lib/add-project.d.ts +3 -0
- package/src/generators/application/lib/add-project.js +96 -0
- package/src/generators/application/lib/add-routing.d.ts +3 -0
- package/src/generators/application/lib/add-routing.js +27 -0
- package/src/generators/application/lib/create-application-files.d.ts +3 -0
- package/src/generators/application/lib/create-application-files.js +143 -0
- package/src/generators/application/lib/find-free-port.d.ts +2 -0
- package/src/generators/application/lib/find-free-port.js +16 -0
- package/src/generators/application/lib/get-app-tests.d.ts +2 -0
- package/src/generators/application/lib/get-app-tests.js +21 -0
- package/src/generators/application/lib/install-common-dependencies.d.ts +3 -0
- package/src/generators/application/lib/install-common-dependencies.js +47 -0
- package/src/generators/application/lib/normalize-options.d.ts +5 -0
- package/src/generators/application/lib/normalize-options.js +72 -0
- package/src/generators/application/lib/set-defaults.d.ts +3 -0
- package/src/generators/application/lib/set-defaults.js +43 -0
- package/src/generators/application/lib/show-possible-warnings.d.ts +3 -0
- package/src/generators/application/lib/show-possible-warnings.js +11 -0
- package/src/generators/application/lib/update-jest-config.d.ts +3 -0
- package/src/generators/application/lib/update-jest-config.js +30 -0
- package/src/generators/application/schema.d.ts +45 -0
- package/src/generators/application/schema.json +201 -0
- package/src/generators/component/component.d.ts +5 -0
- package/src/generators/component/component.js +93 -0
- package/src/generators/component/files/__fileName__.__style__ +0 -0
- package/src/generators/component/files/__fileName__.module.__style__ +7 -0
- package/src/generators/component/files/__fileName__.spec.tsx__tmpl__ +7 -0
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +88 -0
- package/src/generators/component/lib/get-component-tests.d.ts +2 -0
- package/src/generators/component/lib/get-component-tests.js +12 -0
- package/src/generators/component/lib/normalize-options.d.ts +3 -0
- package/src/generators/component/lib/normalize-options.js +50 -0
- package/src/generators/component/schema.d.ts +48 -0
- package/src/generators/component/schema.json +150 -0
- package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +13 -0
- package/src/generators/component-cypress-spec/component-cypress-spec.js +100 -0
- package/src/generators/component-cypress-spec/files/__componentName__.__fileExt__ +13 -0
- package/src/generators/component-cypress-spec/schema.json +44 -0
- package/src/generators/component-story/component-story.d.ts +12 -0
- package/src/generators/component-story/component-story.js +72 -0
- package/src/generators/component-story/files/jsx/__componentFileName__.stories.jsx__tmpl__ +29 -0
- package/src/generators/component-story/files/tsx/__componentFileName__.stories.tsx__tmpl__ +36 -0
- package/src/generators/component-story/schema.json +42 -0
- package/src/generators/component-test/component-test.d.ts +4 -0
- package/src/generators/component-test/component-test.js +76 -0
- package/src/generators/component-test/files/__fileName__.cy__ext__ +21 -0
- package/src/generators/component-test/schema.d.ts +4 -0
- package/src/generators/component-test/schema.js +2 -0
- package/src/generators/component-test/schema.json +31 -0
- package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +10 -0
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +51 -0
- package/src/generators/cypress-component-configuration/lib/add-files.d.ts +4 -0
- package/src/generators/cypress-component-configuration/lib/add-files.js +45 -0
- package/src/generators/cypress-component-configuration/schema.d.ts +8 -0
- package/src/generators/cypress-component-configuration/schema.json +54 -0
- package/src/generators/federate-module/federate-module.d.ts +4 -0
- package/src/generators/federate-module/federate-module.js +70 -0
- package/src/generators/federate-module/lib/utils.d.ts +23 -0
- package/src/generators/federate-module/lib/utils.js +100 -0
- package/src/generators/federate-module/schema.d.ts +13 -0
- package/src/generators/federate-module/schema.json +83 -0
- package/src/generators/hook/files/__fileName__.spec.tsx__tmpl__ +18 -0
- package/src/generators/hook/files/__fileName__.ts__tmpl__ +15 -0
- package/src/generators/hook/hook.d.ts +5 -0
- package/src/generators/hook/hook.js +131 -0
- package/src/generators/hook/schema.d.ts +24 -0
- package/src/generators/hook/schema.json +84 -0
- package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +33 -0
- package/src/generators/host/files/common/src/main.js__tmpl__ +10 -0
- package/src/generators/host/files/common/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +41 -0
- package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +10 -0
- package/src/generators/host/files/module-federation/module-federation.config.js__tmpl__ +21 -0
- package/src/generators/host/files/module-federation/webpack.config.js__tmpl__ +12 -0
- package/src/generators/host/files/module-federation/webpack.config.prod.js__tmpl__ +32 -0
- package/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +16 -0
- package/src/generators/host/files/module-federation-ssr/server.ts__tmpl__ +28 -0
- package/src/generators/host/files/module-federation-ssr/tsconfig.server.json__tmpl__ +17 -0
- package/src/generators/host/files/module-federation-ssr/webpack.server.config.js__tmpl__ +12 -0
- package/src/generators/host/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +13 -0
- package/src/generators/host/files/module-federation-ssr-ts/server.ts__tmpl__ +28 -0
- package/src/generators/host/files/module-federation-ssr-ts/tsconfig.server.json__tmpl__ +17 -0
- package/src/generators/host/files/module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +12 -0
- package/src/generators/host/files/module-federation-ts/module-federation.config.ts__tmpl__ +25 -0
- package/src/generators/host/files/module-federation-ts/webpack.config.prod.ts__tmpl__ +33 -0
- package/src/generators/host/files/module-federation-ts/webpack.config.ts__tmpl__ +12 -0
- package/src/generators/host/host.d.ts +5 -0
- package/src/generators/host/host.js +95 -0
- package/src/generators/host/lib/add-module-federation-files.d.ts +6 -0
- package/src/generators/host/lib/add-module-federation-files.js +52 -0
- package/src/generators/host/lib/normalize-remote.d.ts +4 -0
- package/src/generators/host/lib/normalize-remote.js +28 -0
- package/src/generators/host/lib/setup-ssr-for-host.d.ts +6 -0
- package/src/generators/host/lib/setup-ssr-for-host.js +33 -0
- package/src/generators/host/lib/update-module-federation-e2e-project.d.ts +3 -0
- package/src/generators/host/lib/update-module-federation-e2e-project.js +20 -0
- package/src/generators/host/schema.d.ts +37 -0
- package/src/generators/host/schema.json +184 -0
- package/src/generators/init/init.d.ts +4 -0
- package/src/generators/init/init.js +23 -0
- package/src/generators/init/schema.d.ts +5 -0
- package/src/generators/init/schema.json +27 -0
- package/src/generators/library/files/common/README.md +7 -0
- package/src/generators/library/files/common/package.json__tmpl__ +4 -0
- package/src/generators/library/files/common/src/index.ts__tmpl__ +0 -0
- package/src/generators/library/files/common/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/files/vite/README.md +7 -0
- package/src/generators/library/files/vite/package.json__tmpl__ +12 -0
- package/src/generators/library/files/vite/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/lib/add-linting.d.ts +3 -0
- package/src/generators/library/lib/add-linting.js +36 -0
- package/src/generators/library/lib/add-rollup-build-target.d.ts +4 -0
- package/src/generators/library/lib/add-rollup-build-target.js +59 -0
- package/src/generators/library/lib/create-files.d.ts +3 -0
- package/src/generators/library/lib/create-files.js +53 -0
- package/src/generators/library/lib/install-common-dependencies.d.ts +3 -0
- package/src/generators/library/lib/install-common-dependencies.js +47 -0
- package/src/generators/library/lib/normalize-options.d.ts +3 -0
- package/src/generators/library/lib/normalize-options.js +92 -0
- package/src/generators/library/lib/set-defaults.d.ts +3 -0
- package/src/generators/library/lib/set-defaults.js +23 -0
- package/src/generators/library/lib/update-app-routes.d.ts +3 -0
- package/src/generators/library/lib/update-app-routes.js +62 -0
- package/src/generators/library/library.d.ts +5 -0
- package/src/generators/library/library.js +193 -0
- package/src/generators/library/schema.d.ts +45 -0
- package/src/generators/library/schema.json +198 -0
- package/src/generators/redux/files/__fileName__.slice.spec.ts__tmpl__ +56 -0
- package/src/generators/redux/files/__fileName__.slice.ts__tmpl__ +129 -0
- package/src/generators/redux/redux.d.ts +5 -0
- package/src/generators/redux/redux.js +143 -0
- package/src/generators/redux/schema.d.ts +23 -0
- package/src/generators/redux/schema.json +51 -0
- package/src/generators/remote/files/common/src/main.js__tmpl__ +1 -0
- package/src/generators/remote/files/common/src/remote-entry.js__tmpl__ +1 -0
- package/src/generators/remote/files/common-ts/src/main.ts__tmpl__ +1 -0
- package/src/generators/remote/files/common-ts/src/remote-entry.ts__tmpl__ +1 -0
- package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +9 -0
- package/src/generators/remote/files/module-federation/webpack.config.js__tmpl__ +12 -0
- package/src/generators/remote/files/module-federation/webpack.config.prod.js__tmpl__ +1 -0
- package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
- package/src/generators/remote/files/module-federation-ssr/server.ts__tmpl__ +45 -0
- package/src/generators/remote/files/module-federation-ssr/webpack.server.config.js__tmpl__ +12 -0
- package/src/generators/remote/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +10 -0
- package/src/generators/remote/files/module-federation-ssr-ts/server.ts__tmpl__ +45 -0
- package/src/generators/remote/files/module-federation-ssr-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/files/module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +12 -0
- package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__ +13 -0
- package/src/generators/remote/files/module-federation-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/files/module-federation-ts/webpack.config.prod.ts__tmpl__ +1 -0
- package/src/generators/remote/files/module-federation-ts/webpack.config.ts__tmpl__ +12 -0
- package/src/generators/remote/lib/add-remote-to-dynamic-host.d.ts +2 -0
- package/src/generators/remote/lib/add-remote-to-dynamic-host.js +11 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +4 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.js +40 -0
- package/src/generators/remote/lib/setup-tspath-for-remote.d.ts +3 -0
- package/src/generators/remote/lib/setup-tspath-for-remote.js +15 -0
- package/src/generators/remote/lib/update-host-with-remote.d.ts +2 -0
- package/src/generators/remote/lib/update-host-with-remote.js +64 -0
- package/src/generators/remote/remote.d.ts +7 -0
- package/src/generators/remote/remote.js +104 -0
- package/src/generators/remote/schema.d.ts +34 -0
- package/src/generators/remote/schema.json +183 -0
- package/src/generators/setup-ssr/files/server.ts__tmpl__ +28 -0
- package/src/generators/setup-ssr/files/src/main.server.tsx__tmpl__ +47 -0
- package/src/generators/setup-ssr/files/tsconfig.server.json__tmpl__ +17 -0
- package/src/generators/setup-ssr/schema.d.ts +7 -0
- package/src/generators/setup-ssr/schema.json +48 -0
- package/src/generators/setup-ssr/setup-ssr.d.ts +4 -0
- package/src/generators/setup-ssr/setup-ssr.js +183 -0
- package/src/generators/setup-tailwind/files/postcss.config.js__tmpl__ +15 -0
- package/src/generators/setup-tailwind/files/tailwind.config.js__tmpl__ +17 -0
- package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.d.ts +3 -0
- package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.js +36 -0
- package/src/generators/setup-tailwind/lib/update-project.d.ts +3 -0
- package/src/generators/setup-tailwind/lib/update-project.js +13 -0
- package/src/generators/setup-tailwind/schema.d.ts +6 -0
- package/src/generators/setup-tailwind/schema.js +2 -0
- package/src/generators/setup-tailwind/schema.json +47 -0
- package/src/generators/setup-tailwind/setup-tailwind.d.ts +4 -0
- package/src/generators/setup-tailwind/setup-tailwind.js +35 -0
- package/src/generators/stories/schema.json +67 -0
- package/src/generators/stories/stories.d.ts +15 -0
- package/src/generators/stories/stories.js +130 -0
- package/src/generators/storybook-configuration/configuration.d.ts +6 -0
- package/src/generators/storybook-configuration/configuration.js +74 -0
- package/src/generators/storybook-configuration/schema.d.ts +16 -0
- package/src/generators/storybook-configuration/schema.json +95 -0
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.d.ts +3 -0
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +37 -0
- package/src/migrations/update-15-3-0/update-rollup-executor.d.ts +3 -0
- package/src/migrations/update-15-3-0/update-rollup-executor.js +15 -0
- package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +2 -0
- package/src/migrations/update-15-6-3/webpack-config-setup.js +103 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.d.ts +2 -0
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +8 -0
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.d.ts +2 -0
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +8 -0
- package/src/migrations/update-16-7-0/add-babel-core.d.ts +2 -0
- package/src/migrations/update-16-7-0/add-babel-core.js +14 -0
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.d.ts +2 -0
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +57 -0
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.d.ts +2 -0
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +26 -0
- package/src/module-federation/ast-utils.d.ts +8 -0
- package/src/module-federation/ast-utils.js +102 -0
- package/src/module-federation/load-config.d.ts +3 -0
- package/src/module-federation/load-config.js +16 -0
- package/src/module-federation/models.d.ts +24 -0
- package/src/module-federation/models.js +2 -0
- package/src/module-federation/package-json.d.ts +8 -0
- package/src/module-federation/package-json.js +13 -0
- package/src/module-federation/utils.d.ts +12 -0
- package/src/module-federation/utils.js +76 -0
- package/src/module-federation/with-module-federation-ssr.d.ts +2 -0
- package/src/module-federation/with-module-federation-ssr.js +34 -0
- package/src/module-federation/with-module-federation.d.ts +7 -0
- package/src/module-federation/with-module-federation.js +50 -0
- package/src/rules/add-styled-dependencies.d.ts +5 -0
- package/src/rules/add-styled-dependencies.js +17 -0
- package/src/rules/update-module-federation-project.d.ts +9 -0
- package/src/rules/update-module-federation-project.js +50 -0
- package/src/utils/add-mf-env-to-inputs.d.ts +2 -0
- package/src/utils/add-mf-env-to-inputs.js +24 -0
- package/src/utils/assertion.d.ts +1 -0
- package/src/utils/assertion.js +19 -0
- package/src/utils/ast-utils.d.ts +29 -0
- package/src/utils/ast-utils.js +522 -0
- package/src/utils/component-props.d.ts +15 -0
- package/src/utils/component-props.js +60 -0
- package/src/utils/create-ts-config.d.ts +9 -0
- package/src/utils/create-ts-config.js +65 -0
- package/src/utils/ct-utils.d.ts +14 -0
- package/src/utils/ct-utils.js +94 -0
- package/src/utils/dependencies.d.ts +7 -0
- package/src/utils/dependencies.js +2 -0
- package/src/utils/format-file.d.ts +1 -0
- package/src/utils/format-file.js +12 -0
- package/src/utils/get-in-source-vitest-tests-template.d.ts +1 -0
- package/src/utils/get-in-source-vitest-tests-template.js +21 -0
- package/src/utils/has-vite-plugin.d.ts +2 -0
- package/src/utils/has-vite-plugin.js +11 -0
- package/src/utils/has-webpack-plugin.d.ts +2 -0
- package/src/utils/has-webpack-plugin.js +11 -0
- package/src/utils/jest-utils.d.ts +1 -0
- package/src/utils/jest-utils.js +9 -0
- package/src/utils/lint.d.ts +36 -0
- package/src/utils/lint.js +24 -0
- package/src/utils/maybe-js.d.ts +3 -0
- package/src/utils/maybe-js.js +9 -0
- package/src/utils/styled.d.ts +3 -0
- package/src/utils/styled.js +62 -0
- package/src/utils/testing-generators.d.ts +3 -0
- package/src/utils/testing-generators.js +30 -0
- package/src/utils/versions.d.ts +46 -0
- package/src/utils/versions.js +54 -0
- package/tailwind.d.ts +6 -0
- package/tailwind.js +29 -0
- package/typings/cssmodule.d.ts +19 -0
- package/typings/image.d.ts +48 -0
- package/typings/style.d.ts +9 -0
- package/typings/styled-jsx.d.ts +8 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<% if (classComponent) { %>
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
<% } %>
|
|
4
|
+
|
|
5
|
+
<% if (routing) { %>
|
|
6
|
+
import { Route, Link } from 'react-router-dom';
|
|
7
|
+
<% } %>
|
|
8
|
+
|
|
9
|
+
<% if (hasStyles) {
|
|
10
|
+
if (styledModule && styledModule !== 'styled-jsx') {
|
|
11
|
+
var wrapper = 'Styled' + className;
|
|
12
|
+
var extras = '';
|
|
13
|
+
%>
|
|
14
|
+
import styled from '<%= styledModule %>';
|
|
15
|
+
<% } else {
|
|
16
|
+
var wrapper = 'div';
|
|
17
|
+
var extras = globalCss || styledModule === 'styled-jsx' ? '' : " className={styles['container']}";
|
|
18
|
+
%>
|
|
19
|
+
<%- style !== 'styled-jsx' ? globalCss ? `import './${fileName}.${style}';` : `import styles from './${fileName}.module.${style}';`: '' %>
|
|
20
|
+
<% }
|
|
21
|
+
} else {
|
|
22
|
+
var wrapper = 'div';
|
|
23
|
+
var extras = '';
|
|
24
|
+
} %>
|
|
25
|
+
|
|
26
|
+
/* eslint-disable-next-line */
|
|
27
|
+
export interface <%= className %>Props {
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
<% if (styledModule && styledModule !== 'styled-jsx') { %>
|
|
31
|
+
const Styled<%= className %> = styled.div`
|
|
32
|
+
color: pink;
|
|
33
|
+
`;
|
|
34
|
+
<% }%>
|
|
35
|
+
<% if(!isNextPage) { %>
|
|
36
|
+
<% if (classComponent) { %>
|
|
37
|
+
export class <%= className %> extends Component<<%= className %>Props> {
|
|
38
|
+
override render() {
|
|
39
|
+
return (
|
|
40
|
+
<<%= wrapper %><%- extras %>>
|
|
41
|
+
<%= styledModule === 'styled-jsx' ? `<style jsx>{\`div { color: pink; }\`}</style>` : `` %>
|
|
42
|
+
<p>Welcome to <%= className %>!</p>
|
|
43
|
+
<% if (routing) { %>
|
|
44
|
+
<ul>
|
|
45
|
+
<li><Link to="/"><%= name %> root</Link></li>
|
|
46
|
+
</ul>
|
|
47
|
+
<Route path="/" element={<div>This is the <%= name %> root route.</div>} />
|
|
48
|
+
<% } %>
|
|
49
|
+
</<%= wrapper %>>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
<% } else { %>
|
|
54
|
+
export function <%= className %>(props: <%= className %>Props) {
|
|
55
|
+
return (
|
|
56
|
+
<<%= wrapper %><%- extras %>>
|
|
57
|
+
<% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
|
|
58
|
+
<h1>Welcome to <%= className %>!</h1>
|
|
59
|
+
<% if (routing) { %>
|
|
60
|
+
<ul>
|
|
61
|
+
<li><Link to="/"><%= name %> root</Link></li>
|
|
62
|
+
</ul>
|
|
63
|
+
<Route path="/" element={<div>This is the <%= name %> root route.</div>} />
|
|
64
|
+
<% } %>
|
|
65
|
+
</<%= wrapper %>>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
<% } %>
|
|
69
|
+
|
|
70
|
+
export default <%= className %>;
|
|
71
|
+
<% } else { %>
|
|
72
|
+
export default function <%= className %>(props: <%= className %>Props) {
|
|
73
|
+
return (
|
|
74
|
+
<<%= wrapper %><%- extras %>>
|
|
75
|
+
<% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
|
|
76
|
+
<h1>Welcome to <%= className %>!</h1>
|
|
77
|
+
<% if (routing) { %>
|
|
78
|
+
<ul>
|
|
79
|
+
<li><Link to="/"><%= name %> root</Link></li>
|
|
80
|
+
</ul>
|
|
81
|
+
<Route path="/" element={<div>This is the <%= name %> root route.</div>} />
|
|
82
|
+
<% } %>
|
|
83
|
+
</<%= wrapper %>>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
<% } %>
|
|
87
|
+
|
|
88
|
+
<% if (inSourceTests === true) { %> <%- inSourceVitestTests %> <% } %>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentTests = void 0;
|
|
4
|
+
function getComponentTests(schema) {
|
|
5
|
+
return `
|
|
6
|
+
it('should render successfully', () => {
|
|
7
|
+
const { baseElement } = render(<${schema.className} />);
|
|
8
|
+
expect(baseElement).toBeTruthy();
|
|
9
|
+
});
|
|
10
|
+
`;
|
|
11
|
+
}
|
|
12
|
+
exports.getComponentTests = getComponentTests;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
6
|
+
const assertion_1 = require("../../../utils/assertion");
|
|
7
|
+
async function normalizeOptions(tree, options) {
|
|
8
|
+
(0, assertion_1.assertValidStyle)(options.style);
|
|
9
|
+
const { artifactName: name, directory, fileName, filePath, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
10
|
+
artifactType: 'component',
|
|
11
|
+
callingGenerator: '@nx/react:component',
|
|
12
|
+
name: options.name,
|
|
13
|
+
directory: options.directory,
|
|
14
|
+
derivedDirectory: options.derivedDirectory ?? options.directory,
|
|
15
|
+
flat: options.flat,
|
|
16
|
+
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
|
17
|
+
project: options.project,
|
|
18
|
+
fileExtension: 'tsx',
|
|
19
|
+
fileName: options.fileName,
|
|
20
|
+
pascalCaseFile: options.pascalCaseFiles,
|
|
21
|
+
pascalCaseDirectory: options.pascalCaseDirectory,
|
|
22
|
+
});
|
|
23
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
24
|
+
const { className } = (0, devkit_1.names)(name);
|
|
25
|
+
const { sourceRoot: projectSourceRoot, root: projectRoot, projectType, } = project;
|
|
26
|
+
const styledModule = /^(css|scss|less|none)$/.test(options.style)
|
|
27
|
+
? null
|
|
28
|
+
: options.style;
|
|
29
|
+
if (options.export && projectType === 'application') {
|
|
30
|
+
devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
|
|
31
|
+
}
|
|
32
|
+
options.classComponent = options.classComponent ?? false;
|
|
33
|
+
options.routing = options.routing ?? false;
|
|
34
|
+
options.globalCss = options.globalCss ?? false;
|
|
35
|
+
options.inSourceTests = options.inSourceTests ?? false;
|
|
36
|
+
//TODO (nicholas): Remove when Next page generator is removed
|
|
37
|
+
options.isNextPage = options.isNextPage ?? false;
|
|
38
|
+
return {
|
|
39
|
+
...options,
|
|
40
|
+
projectName,
|
|
41
|
+
directory,
|
|
42
|
+
styledModule,
|
|
43
|
+
hasStyles: options.style !== 'none',
|
|
44
|
+
className,
|
|
45
|
+
fileName,
|
|
46
|
+
filePath,
|
|
47
|
+
projectSourceRoot: projectSourceRoot ?? projectRoot,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.normalizeOptions = normalizeOptions;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SupportedStyles } from '../../../typings/style';
|
|
2
|
+
|
|
3
|
+
export interface Schema {
|
|
4
|
+
name: string;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19.
|
|
7
|
+
*/
|
|
8
|
+
project?: string;
|
|
9
|
+
style: SupportedStyles;
|
|
10
|
+
skipTests?: boolean;
|
|
11
|
+
directory?: string;
|
|
12
|
+
export?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
|
|
15
|
+
*/
|
|
16
|
+
pascalCaseFiles?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
|
|
19
|
+
*/
|
|
20
|
+
pascalCaseDirectory?: boolean;
|
|
21
|
+
classComponent?: boolean;
|
|
22
|
+
routing?: boolean;
|
|
23
|
+
js?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
26
|
+
*/
|
|
27
|
+
flat?: boolean;
|
|
28
|
+
globalCss?: boolean;
|
|
29
|
+
fileName?: string;
|
|
30
|
+
inSourceTests?: boolean;
|
|
31
|
+
skipFormat?: boolean;
|
|
32
|
+
nameAndDirectoryFormat?: 'as-provided' | 'derived';
|
|
33
|
+
// Used by other wrapping generators to preserve previous behavior
|
|
34
|
+
// e.g. @nx/next:component
|
|
35
|
+
derivedDirectory?: string;
|
|
36
|
+
// Used by Next.js to determine how React should generate the page
|
|
37
|
+
isNextPage?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface NormalizedSchema extends Schema {
|
|
41
|
+
projectSourceRoot: string;
|
|
42
|
+
projectName: string;
|
|
43
|
+
fileName: string;
|
|
44
|
+
filePath: string;
|
|
45
|
+
className: string;
|
|
46
|
+
styledModule: null | string;
|
|
47
|
+
hasStyles: boolean;
|
|
48
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxReactComponent",
|
|
5
|
+
"title": "Create a React Component",
|
|
6
|
+
"description": "Create a React Component for Nx.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The name of the project.",
|
|
12
|
+
"alias": "p",
|
|
13
|
+
"$default": {
|
|
14
|
+
"$source": "projectName"
|
|
15
|
+
},
|
|
16
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19."
|
|
17
|
+
},
|
|
18
|
+
"name": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The name of the component.",
|
|
21
|
+
"$default": {
|
|
22
|
+
"$source": "argv",
|
|
23
|
+
"index": 0
|
|
24
|
+
},
|
|
25
|
+
"x-prompt": "What name would you like to use for the component?",
|
|
26
|
+
"x-priority": "important"
|
|
27
|
+
},
|
|
28
|
+
"style": {
|
|
29
|
+
"description": "The file extension to be used for style files.",
|
|
30
|
+
"type": "string",
|
|
31
|
+
"alias": "s",
|
|
32
|
+
"default": "css",
|
|
33
|
+
"x-prompt": {
|
|
34
|
+
"message": "Which stylesheet format would you like to use?",
|
|
35
|
+
"type": "list",
|
|
36
|
+
"items": [
|
|
37
|
+
{
|
|
38
|
+
"value": "css",
|
|
39
|
+
"label": "CSS"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"value": "scss",
|
|
43
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"value": "less",
|
|
47
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"value": "styled-components",
|
|
51
|
+
"label": "styled-components [ https://styled-components.com ]"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"value": "@emotion/styled",
|
|
55
|
+
"label": "emotion [ https://emotion.sh ]"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"value": "styled-jsx",
|
|
59
|
+
"label": "styled-jsx [ https://www.npmjs.com/package/styled-jsx ]"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"value": "none",
|
|
63
|
+
"label": "None"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"js": {
|
|
69
|
+
"type": "boolean",
|
|
70
|
+
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
71
|
+
"default": false
|
|
72
|
+
},
|
|
73
|
+
"skipTests": {
|
|
74
|
+
"type": "boolean",
|
|
75
|
+
"description": "When true, does not create `spec.ts` test files for the new component.",
|
|
76
|
+
"default": false,
|
|
77
|
+
"x-priority": "internal"
|
|
78
|
+
},
|
|
79
|
+
"directory": {
|
|
80
|
+
"type": "string",
|
|
81
|
+
"description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
|
|
82
|
+
"alias": "dir",
|
|
83
|
+
"x-priority": "important"
|
|
84
|
+
},
|
|
85
|
+
"nameAndDirectoryFormat": {
|
|
86
|
+
"description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
|
|
87
|
+
"type": "string",
|
|
88
|
+
"enum": ["as-provided", "derived"]
|
|
89
|
+
},
|
|
90
|
+
"flat": {
|
|
91
|
+
"type": "boolean",
|
|
92
|
+
"description": "Create component at the source root rather than its own directory.",
|
|
93
|
+
"default": false,
|
|
94
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
|
|
95
|
+
},
|
|
96
|
+
"export": {
|
|
97
|
+
"type": "boolean",
|
|
98
|
+
"description": "When true, the component is exported from the project `index.ts` (if it exists).",
|
|
99
|
+
"alias": "e",
|
|
100
|
+
"default": false,
|
|
101
|
+
"x-prompt": "Should this component be exported in the project?"
|
|
102
|
+
},
|
|
103
|
+
"pascalCaseFiles": {
|
|
104
|
+
"type": "boolean",
|
|
105
|
+
"description": "Use pascal case component file name (e.g. `App.tsx`).",
|
|
106
|
+
"alias": "P",
|
|
107
|
+
"default": false,
|
|
108
|
+
"x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
109
|
+
},
|
|
110
|
+
"pascalCaseDirectory": {
|
|
111
|
+
"type": "boolean",
|
|
112
|
+
"description": "Use pascal case directory name (e.g. `App/App.tsx`).",
|
|
113
|
+
"alias": "R",
|
|
114
|
+
"default": false,
|
|
115
|
+
"x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
116
|
+
},
|
|
117
|
+
"classComponent": {
|
|
118
|
+
"type": "boolean",
|
|
119
|
+
"alias": "C",
|
|
120
|
+
"description": "Use class components instead of functional component.",
|
|
121
|
+
"default": false
|
|
122
|
+
},
|
|
123
|
+
"routing": {
|
|
124
|
+
"type": "boolean",
|
|
125
|
+
"description": "Generate a library with routes."
|
|
126
|
+
},
|
|
127
|
+
"globalCss": {
|
|
128
|
+
"type": "boolean",
|
|
129
|
+
"description": "Default is `false`. When `true`, the component is generated with `*.css`/`*.scss` instead of `*.module.css`/`*.module.scss`.",
|
|
130
|
+
"default": false
|
|
131
|
+
},
|
|
132
|
+
"fileName": {
|
|
133
|
+
"type": "string",
|
|
134
|
+
"description": "Create a component with this file name."
|
|
135
|
+
},
|
|
136
|
+
"inSourceTests": {
|
|
137
|
+
"type": "boolean",
|
|
138
|
+
"default": false,
|
|
139
|
+
"description": "When using Vitest, separate spec files will not be generated and instead will be included within the source files. Read more on the Vitest docs site: https://vitest.dev/guide/in-source.html"
|
|
140
|
+
},
|
|
141
|
+
"skipFormat": {
|
|
142
|
+
"description": "Skip formatting files.",
|
|
143
|
+
"type": "boolean",
|
|
144
|
+
"default": false,
|
|
145
|
+
"x-priority": "internal"
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"required": ["name"],
|
|
149
|
+
"examplesFile": "../../../docs/component-examples.md"
|
|
150
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export interface CreateComponentSpecFileSchema {
|
|
4
|
+
project: string;
|
|
5
|
+
componentPath: string;
|
|
6
|
+
js?: boolean;
|
|
7
|
+
cypressProject?: string;
|
|
8
|
+
skipFormat?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function componentCypressGenerator(host: Tree, schema: CreateComponentSpecFileSchema): Promise<void>;
|
|
11
|
+
export declare function getArgsDefaultValue(property: ts.SyntaxKind): string;
|
|
12
|
+
export declare function createComponentSpecFile(tree: Tree, { project, componentPath, js, cypressProject }: CreateComponentSpecFileSchema): void;
|
|
13
|
+
export default componentCypressGenerator;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createComponentSpecFile = exports.getArgsDefaultValue = exports.componentCypressGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const ast_utils_1 = require("../../utils/ast-utils");
|
|
7
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
8
|
+
let tsModule;
|
|
9
|
+
async function componentCypressGenerator(host, schema) {
|
|
10
|
+
createComponentSpecFile(host, schema);
|
|
11
|
+
if (!schema.skipFormat) {
|
|
12
|
+
await (0, devkit_1.formatFiles)(host);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.componentCypressGenerator = componentCypressGenerator;
|
|
16
|
+
// TODO: candidate to refactor with the angular component story
|
|
17
|
+
function getArgsDefaultValue(property) {
|
|
18
|
+
if (!tsModule) {
|
|
19
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
20
|
+
}
|
|
21
|
+
const typeNameToDefault = {
|
|
22
|
+
[tsModule.SyntaxKind.StringKeyword]: '',
|
|
23
|
+
[tsModule.SyntaxKind.NumberKeyword]: 0,
|
|
24
|
+
[tsModule.SyntaxKind.BooleanKeyword]: false,
|
|
25
|
+
};
|
|
26
|
+
const resolvedValue = typeNameToDefault[property];
|
|
27
|
+
if (typeof resolvedValue === undefined) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
else if (typeof resolvedValue === 'string') {
|
|
31
|
+
return resolvedValue.replace(/\s/g, '+');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return resolvedValue;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.getArgsDefaultValue = getArgsDefaultValue;
|
|
38
|
+
function createComponentSpecFile(tree, { project, componentPath, js, cypressProject }) {
|
|
39
|
+
if (!tsModule) {
|
|
40
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
41
|
+
}
|
|
42
|
+
const e2eProjectName = cypressProject || `${project}-e2e`;
|
|
43
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
44
|
+
const e2eProject = projects.get(e2eProjectName);
|
|
45
|
+
// cypress >= v10 will have a cypress.config.ts < v10 will have a cypress.json
|
|
46
|
+
const isCypressV10 = tree.exists((0, path_1.join)(e2eProject.root, 'cypress.config.ts'));
|
|
47
|
+
const e2eLibIntegrationFolderPath = (0, path_1.join)(e2eProject.sourceRoot, isCypressV10 ? 'e2e' : 'integration');
|
|
48
|
+
const proj = projects.get(project);
|
|
49
|
+
const componentFilePath = (0, devkit_1.joinPathFragments)(proj.sourceRoot, componentPath);
|
|
50
|
+
const componentName = componentFilePath
|
|
51
|
+
.slice(componentFilePath.lastIndexOf('/') + 1)
|
|
52
|
+
.replace('.tsx', '')
|
|
53
|
+
.replace('.jsx', '')
|
|
54
|
+
.replace('.js', '');
|
|
55
|
+
const contents = tree.read(componentFilePath, 'utf-8');
|
|
56
|
+
if (contents === null) {
|
|
57
|
+
throw new Error(`Failed to read ${componentFilePath}`);
|
|
58
|
+
}
|
|
59
|
+
const sourceFile = tsModule.createSourceFile(componentFilePath, contents, tsModule.ScriptTarget.Latest, true);
|
|
60
|
+
const cmpDeclaration = (0, ast_utils_1.getComponentNode)(sourceFile);
|
|
61
|
+
if (!cmpDeclaration) {
|
|
62
|
+
const componentNodes = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile);
|
|
63
|
+
if (componentNodes?.length) {
|
|
64
|
+
componentNodes.forEach((declaration) => {
|
|
65
|
+
findPropsAndGenerateFileForCypress(tree, sourceFile, declaration, e2eLibIntegrationFolderPath, componentName, project, js, true);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error(`Could not find any React component in file ${componentFilePath}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
findPropsAndGenerateFileForCypress(tree, sourceFile, cmpDeclaration, e2eLibIntegrationFolderPath, componentName, project, js);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.createComponentSpecFile = createComponentSpecFile;
|
|
77
|
+
function findPropsAndGenerateFileForCypress(tree, sourceFile, cmpDeclaration, e2eLibIntegrationFolderPath, componentName, project, js, fromNodeArray) {
|
|
78
|
+
const propsInterface = (0, ast_utils_1.getComponentPropsInterface)(sourceFile, cmpDeclaration);
|
|
79
|
+
let props = [];
|
|
80
|
+
if (propsInterface) {
|
|
81
|
+
props = propsInterface.members.map((member) => {
|
|
82
|
+
return {
|
|
83
|
+
name: member.name.text,
|
|
84
|
+
defaultValue: getArgsDefaultValue(member.type.kind),
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const isCypressV10 = (0, path_1.basename)(e2eLibIntegrationFolderPath) === 'e2e';
|
|
89
|
+
const cyFilePrefix = isCypressV10 ? 'cy' : 'spec';
|
|
90
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, './files'), `${e2eLibIntegrationFolderPath}/${fromNodeArray
|
|
91
|
+
? componentName + '--' + cmpDeclaration.name.text
|
|
92
|
+
: componentName}`, {
|
|
93
|
+
projectName: project,
|
|
94
|
+
componentName,
|
|
95
|
+
componentSelector: cmpDeclaration.name.text,
|
|
96
|
+
props,
|
|
97
|
+
fileExt: js ? `${cyFilePrefix}.js` : `${cyFilePrefix}.ts`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.default = componentCypressGenerator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
describe('<%=projectName%>: <%= componentSelector %> component', () => {
|
|
2
|
+
beforeEach(() => cy.visit('/iframe.html?id=<%= componentSelector.toLowerCase() %>--primary<% if ( props && props.length > 0 ) { %>&args=<% } %><%
|
|
3
|
+
for(let prop of props) {
|
|
4
|
+
%><%=prop.name%><%
|
|
5
|
+
if(prop.defaultValue !== undefined && (prop.defaultValue || prop.defaultValue === false)) {
|
|
6
|
+
%>:<%=prop.defaultValue%><%
|
|
7
|
+
} %>;<%
|
|
8
|
+
}%>'));
|
|
9
|
+
|
|
10
|
+
it('should render the component', () => {
|
|
11
|
+
cy.get('h1').should('contain', 'Welcome to <%=componentSelector%>!');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxReactComponentCypressSpec",
|
|
5
|
+
"title": "Create component Cypress spec",
|
|
6
|
+
"description": "Create a Cypress spec for a UI component that has a story.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The project name for which to generate tests.",
|
|
12
|
+
"examples": ["shared-ui-component"],
|
|
13
|
+
"$default": {
|
|
14
|
+
"$source": "projectName",
|
|
15
|
+
"index": 0
|
|
16
|
+
},
|
|
17
|
+
"x-prompt": "What's name of the project for which to generate tests?",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"componentPath": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Relative path to the component file from the library root?",
|
|
23
|
+
"examples": ["lib/components"],
|
|
24
|
+
"x-prompt": "What's path of the component relative to the project's lib root for which to generate a test?",
|
|
25
|
+
"x-priority": "important"
|
|
26
|
+
},
|
|
27
|
+
"js": {
|
|
28
|
+
"type": "boolean",
|
|
29
|
+
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
30
|
+
"default": false
|
|
31
|
+
},
|
|
32
|
+
"cypressProject": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "The Cypress project to generate the stories under. By default, inferred from `project`."
|
|
35
|
+
},
|
|
36
|
+
"skipFormat": {
|
|
37
|
+
"description": "Skip formatting files.",
|
|
38
|
+
"type": "boolean",
|
|
39
|
+
"default": false,
|
|
40
|
+
"x-priority": "internal"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"required": ["project", "componentPath"]
|
|
44
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export interface CreateComponentStoriesFileSchema {
|
|
4
|
+
project: string;
|
|
5
|
+
componentPath: string;
|
|
6
|
+
interactionTests?: boolean;
|
|
7
|
+
skipFormat?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function createComponentStoriesFile(host: Tree, { project, componentPath, interactionTests }: CreateComponentStoriesFileSchema): void;
|
|
10
|
+
export declare function findPropsAndGenerateFile(host: Tree, sourceFile: ts.SourceFile, cmpDeclaration: ts.Node, componentDirectory: string, name: string, interactionTests: boolean, isPlainJs: boolean, fromNodeArray?: boolean): void;
|
|
11
|
+
export declare function componentStoryGenerator(host: Tree, schema: CreateComponentStoriesFileSchema): Promise<void>;
|
|
12
|
+
export default componentStoryGenerator;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentStoryGenerator = exports.findPropsAndGenerateFile = exports.createComponentStoriesFile = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const ast_utils_1 = require("../../utils/ast-utils");
|
|
6
|
+
const component_props_1 = require("../../utils/component-props");
|
|
7
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
8
|
+
let tsModule;
|
|
9
|
+
function createComponentStoriesFile(host, { project, componentPath, interactionTests }) {
|
|
10
|
+
if (!tsModule) {
|
|
11
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
12
|
+
}
|
|
13
|
+
const proj = (0, devkit_1.getProjects)(host).get(project);
|
|
14
|
+
const sourceRoot = proj.sourceRoot;
|
|
15
|
+
const componentFilePath = (0, devkit_1.joinPathFragments)(sourceRoot, componentPath);
|
|
16
|
+
const componentDirectory = componentFilePath.replace(componentFilePath.slice(componentFilePath.lastIndexOf('/')), '');
|
|
17
|
+
const isPlainJs = componentFilePath.endsWith('.jsx') || componentFilePath.endsWith('.js');
|
|
18
|
+
const componentFileName = componentFilePath
|
|
19
|
+
.slice(componentFilePath.lastIndexOf('/') + 1)
|
|
20
|
+
.replace('.tsx', '')
|
|
21
|
+
.replace('.jsx', '')
|
|
22
|
+
.replace('.js', '');
|
|
23
|
+
const name = componentFileName;
|
|
24
|
+
const contents = host.read(componentFilePath, 'utf-8');
|
|
25
|
+
if (contents === null) {
|
|
26
|
+
throw new Error(`Failed to read ${componentFilePath}`);
|
|
27
|
+
}
|
|
28
|
+
const sourceFile = tsModule.createSourceFile(componentFilePath, contents, tsModule.ScriptTarget.Latest, true);
|
|
29
|
+
const cmpDeclaration = (0, ast_utils_1.getComponentNode)(sourceFile);
|
|
30
|
+
if (!cmpDeclaration) {
|
|
31
|
+
const componentNodes = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile);
|
|
32
|
+
if (componentNodes?.length) {
|
|
33
|
+
componentNodes.forEach((declaration) => {
|
|
34
|
+
findPropsAndGenerateFile(host, sourceFile, declaration, componentDirectory, name, interactionTests, isPlainJs, componentNodes.length > 1);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error(`Could not find any React component in file ${componentFilePath}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
findPropsAndGenerateFile(host, sourceFile, cmpDeclaration, componentDirectory, name, interactionTests, isPlainJs);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.createComponentStoriesFile = createComponentStoriesFile;
|
|
46
|
+
function findPropsAndGenerateFile(host, sourceFile, cmpDeclaration, componentDirectory, name, interactionTests, isPlainJs, fromNodeArray) {
|
|
47
|
+
const { propsTypeName, props, argTypes } = (0, component_props_1.getDefaultsForComponent)(sourceFile, cmpDeclaration);
|
|
48
|
+
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `./files${isPlainJs ? '/jsx' : '/tsx'}`), (0, devkit_1.normalizePath)(componentDirectory), {
|
|
49
|
+
tmpl: '',
|
|
50
|
+
componentFileName: fromNodeArray
|
|
51
|
+
? `${name}--${cmpDeclaration.name.text}`
|
|
52
|
+
: name,
|
|
53
|
+
componentImportFileName: name,
|
|
54
|
+
propsTypeName,
|
|
55
|
+
props,
|
|
56
|
+
argTypes,
|
|
57
|
+
componentName: cmpDeclaration.name.text,
|
|
58
|
+
interactionTests,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.findPropsAndGenerateFile = findPropsAndGenerateFile;
|
|
62
|
+
async function componentStoryGenerator(host, schema) {
|
|
63
|
+
createComponentStoriesFile(host, {
|
|
64
|
+
...schema,
|
|
65
|
+
interactionTests: schema.interactionTests ?? true,
|
|
66
|
+
});
|
|
67
|
+
if (!schema.skipFormat) {
|
|
68
|
+
await (0, devkit_1.formatFiles)(host);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.componentStoryGenerator = componentStoryGenerator;
|
|
72
|
+
exports.default = componentStoryGenerator;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import componentName from './<%= componentImportFileName %>';
|
|
2
|
+
<% if ( interactionTests ) { %>
|
|
3
|
+
import { within } from '@storybook/testing-library';
|
|
4
|
+
import { expect } from '@storybook/jest';
|
|
5
|
+
<% } %>
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
component: <%= componentName %>,
|
|
9
|
+
title: '<%= componentName %>',<% if ( argTypes && argTypes.length > 0 ) { %>
|
|
10
|
+
argTypes: {<% for (let argType of argTypes) { %>
|
|
11
|
+
<%= argType.name %>: { <%- argType.type %> : "<%- argType.actionText %>" },<% } %>
|
|
12
|
+
}
|
|
13
|
+
<% } %>
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const Primary = {
|
|
17
|
+
args: {<% for (let prop of props) { %>
|
|
18
|
+
<%= prop.name %>: <%- prop.defaultValue %>,<% } %>
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
<% if ( interactionTests ) { %>
|
|
23
|
+
export const Heading: Story = {
|
|
24
|
+
play: async ({ canvasElement }) => {
|
|
25
|
+
const canvas = within(canvasElement);
|
|
26
|
+
expect(canvas.getByText(/Welcome to <%=componentName%>!/gi)).toBeTruthy();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
<% } %>
|