@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,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAppTests = void 0;
|
|
4
|
+
function getAppTests(options) {
|
|
5
|
+
return `
|
|
6
|
+
it('should render successfully', () => {
|
|
7
|
+
${options.routing
|
|
8
|
+
? 'const { baseElement } = render(<BrowserRouter><App /></BrowserRouter>);'
|
|
9
|
+
: 'const { baseElement } = render(<App />);'}
|
|
10
|
+
expect(baseElement).toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should have a greeting as the title', () => {
|
|
14
|
+
${options.routing
|
|
15
|
+
? 'const { getByText } = render(<BrowserRouter><App /></BrowserRouter>);'
|
|
16
|
+
: 'const { getByText } = render(<App />);'}
|
|
17
|
+
expect(getByText(/Welcome ${options.projectName}/gi)).toBeTruthy();
|
|
18
|
+
});
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
exports.getAppTests = getAppTests;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installCommonDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../../../utils/versions");
|
|
6
|
+
function installCommonDependencies(host, options) {
|
|
7
|
+
if (options.skipPackageJson) {
|
|
8
|
+
return () => { };
|
|
9
|
+
}
|
|
10
|
+
const dependencies = {};
|
|
11
|
+
const devDependencies = {
|
|
12
|
+
'@types/node': versions_1.typesNodeVersion,
|
|
13
|
+
'@types/react': versions_1.typesReactVersion,
|
|
14
|
+
'@types/react-dom': versions_1.typesReactDomVersion,
|
|
15
|
+
};
|
|
16
|
+
if (options.bundler !== 'vite') {
|
|
17
|
+
dependencies['tslib'] = versions_1.tsLibVersion;
|
|
18
|
+
}
|
|
19
|
+
// Vite requires style preprocessors to be installed manually.
|
|
20
|
+
// `@nx/webpack` installs them automatically for now.
|
|
21
|
+
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
22
|
+
switch (options.style) {
|
|
23
|
+
case 'scss':
|
|
24
|
+
devDependencies['sass'] = versions_1.sassVersion;
|
|
25
|
+
break;
|
|
26
|
+
case 'less':
|
|
27
|
+
devDependencies['less'] = versions_1.lessVersion;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (options.bundler === 'webpack') {
|
|
32
|
+
if (options.compiler === 'swc') {
|
|
33
|
+
devDependencies['swc-loader'] = versions_1.swcLoaderVersion;
|
|
34
|
+
}
|
|
35
|
+
else if (options.compiler === 'babel') {
|
|
36
|
+
// babel-loader is currently included in @nx/webpack
|
|
37
|
+
// TODO(jack): Install babel-loader and other babel packages only as needed
|
|
38
|
+
devDependencies['@babel/preset-react'] = versions_1.babelPresetReactVersion;
|
|
39
|
+
devDependencies['@babel/core'] = versions_1.babelCoreVersion;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (options.unitTestRunner && options.unitTestRunner !== 'none') {
|
|
43
|
+
devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
|
|
44
|
+
}
|
|
45
|
+
return (0, devkit_1.addDependenciesToPackageJson)(host, {}, devDependencies);
|
|
46
|
+
}
|
|
47
|
+
exports.installCommonDependencies = installCommonDependencies;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { NormalizedSchema, Schema } from '../schema';
|
|
3
|
+
export declare function normalizeDirectory(options: Schema): string;
|
|
4
|
+
export declare function normalizeProjectName(options: Schema): string;
|
|
5
|
+
export declare function normalizeOptions<T extends Schema = Schema>(host: Tree, options: Schema, callingGenerator?: string): Promise<NormalizedSchema<T>>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = exports.normalizeProjectName = exports.normalizeDirectory = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
|
+
const assertion_1 = require("../../../utils/assertion");
|
|
7
|
+
const find_free_port_1 = require("./find-free-port");
|
|
8
|
+
function normalizeDirectory(options) {
|
|
9
|
+
options.directory = options.directory?.replace(/\\{1,2}/g, '/');
|
|
10
|
+
const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
|
|
11
|
+
return projectDirectory
|
|
12
|
+
? `${(0, devkit_1.names)(projectDirectory).fileName}/${(0, devkit_1.names)(options.name).fileName}`
|
|
13
|
+
: (0, devkit_1.names)(options.name).fileName;
|
|
14
|
+
}
|
|
15
|
+
exports.normalizeDirectory = normalizeDirectory;
|
|
16
|
+
function normalizeProjectName(options) {
|
|
17
|
+
return normalizeDirectory(options).replace(new RegExp('/', 'g'), '-');
|
|
18
|
+
}
|
|
19
|
+
exports.normalizeProjectName = normalizeProjectName;
|
|
20
|
+
async function normalizeOptions(host, options, callingGenerator = '@nx/react:application') {
|
|
21
|
+
const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
22
|
+
name: options.name,
|
|
23
|
+
projectType: 'application',
|
|
24
|
+
directory: options.directory,
|
|
25
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
26
|
+
rootProject: options.rootProject,
|
|
27
|
+
callingGenerator,
|
|
28
|
+
});
|
|
29
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
30
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
31
|
+
nxJson.useInferencePlugins !== false;
|
|
32
|
+
options.addPlugin ??= addPlugin;
|
|
33
|
+
options.rootProject = appProjectRoot === '.';
|
|
34
|
+
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
35
|
+
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
|
36
|
+
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
|
37
|
+
const parsedTags = options.tags
|
|
38
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
39
|
+
: [];
|
|
40
|
+
const fileName = options.pascalCaseFiles ? 'App' : 'app';
|
|
41
|
+
const styledModule = /^(css|scss|less|tailwind|none)$/.test(options.style)
|
|
42
|
+
? null
|
|
43
|
+
: options.style;
|
|
44
|
+
(0, assertion_1.assertValidStyle)(options.style);
|
|
45
|
+
if (options.bundler === 'vite' && options.unitTestRunner !== 'none') {
|
|
46
|
+
options.unitTestRunner = 'vitest';
|
|
47
|
+
}
|
|
48
|
+
const normalized = {
|
|
49
|
+
...options,
|
|
50
|
+
name: (0, devkit_1.names)(options.name).fileName,
|
|
51
|
+
projectName: appProjectName,
|
|
52
|
+
appProjectRoot,
|
|
53
|
+
e2eProjectName,
|
|
54
|
+
e2eProjectRoot,
|
|
55
|
+
parsedTags,
|
|
56
|
+
fileName,
|
|
57
|
+
styledModule,
|
|
58
|
+
hasStyles: options.style !== 'none',
|
|
59
|
+
};
|
|
60
|
+
normalized.routing = normalized.routing ?? false;
|
|
61
|
+
normalized.strict = normalized.strict ?? true;
|
|
62
|
+
normalized.classComponent = normalized.classComponent ?? false;
|
|
63
|
+
normalized.compiler = normalized.compiler ?? 'babel';
|
|
64
|
+
normalized.bundler = normalized.bundler ?? 'webpack';
|
|
65
|
+
normalized.unitTestRunner = normalized.unitTestRunner ?? 'jest';
|
|
66
|
+
normalized.e2eTestRunner = normalized.e2eTestRunner ?? 'cypress';
|
|
67
|
+
normalized.inSourceTests = normalized.minimal || normalized.inSourceTests;
|
|
68
|
+
normalized.devServerPort ??= (0, find_free_port_1.findFreePort)(host);
|
|
69
|
+
normalized.minimal = normalized.minimal ?? false;
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
exports.normalizeOptions = normalizeOptions;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDefaults = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function setDefaults(host, options) {
|
|
6
|
+
if (options.skipNxJson) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
10
|
+
if (options.rootProject) {
|
|
11
|
+
nxJson.defaultProject = options.projectName;
|
|
12
|
+
}
|
|
13
|
+
nxJson.generators = nxJson.generators || {};
|
|
14
|
+
nxJson.generators['@nx/react'] = nxJson.generators['@nx/react'] || {};
|
|
15
|
+
const prev = { ...nxJson.generators['@nx/react'] };
|
|
16
|
+
const appDefaults = {
|
|
17
|
+
babel: true,
|
|
18
|
+
style: options.style,
|
|
19
|
+
linter: options.linter,
|
|
20
|
+
bundler: options.bundler,
|
|
21
|
+
...prev.application,
|
|
22
|
+
};
|
|
23
|
+
const componentDefaults = {
|
|
24
|
+
style: options.style,
|
|
25
|
+
...prev.component,
|
|
26
|
+
};
|
|
27
|
+
const libDefaults = {
|
|
28
|
+
style: options.style,
|
|
29
|
+
linter: options.linter,
|
|
30
|
+
...prev.library,
|
|
31
|
+
};
|
|
32
|
+
nxJson.generators = {
|
|
33
|
+
...nxJson.generators,
|
|
34
|
+
'@nx/react': {
|
|
35
|
+
...prev,
|
|
36
|
+
application: appDefaults,
|
|
37
|
+
component: componentDefaults,
|
|
38
|
+
library: libDefaults,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
(0, devkit_1.updateNxJson)(host, nxJson);
|
|
42
|
+
}
|
|
43
|
+
exports.setDefaults = setDefaults;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.showPossibleWarnings = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
function showPossibleWarnings(tree, options) {
|
|
7
|
+
if (options.style === 'styled-jsx' && options.compiler === 'swc') {
|
|
8
|
+
devkit_1.logger.warn(`styled-jsx may not work with SWC. Try using ${chalk.bold('nx g @nx/react:app --compiler=babel')} instead.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.showPossibleWarnings = showPossibleWarnings;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateSpecConfig = void 0;
|
|
4
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
5
|
+
const jest_utils_1 = require("../../../utils/jest-utils");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
function updateSpecConfig(host, options) {
|
|
8
|
+
if (options.unitTestRunner === 'none') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
(0, devkit_1.updateJson)(host, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => {
|
|
12
|
+
const compilerOptions = json.compilerOptions ?? {};
|
|
13
|
+
const types = compilerOptions.types ?? [];
|
|
14
|
+
if (options.style === 'styled-jsx') {
|
|
15
|
+
types.push('@nx/react/typings/styled-jsx.d.ts');
|
|
16
|
+
}
|
|
17
|
+
types.push('@nx/react/typings/cssmodule.d.ts', '@nx/react/typings/image.d.ts');
|
|
18
|
+
compilerOptions.types = types;
|
|
19
|
+
json.compilerOptions = compilerOptions;
|
|
20
|
+
return json;
|
|
21
|
+
});
|
|
22
|
+
if (options.unitTestRunner !== 'jest') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const configPath = (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/jest.config.ts`);
|
|
26
|
+
const originalContent = host.read(configPath, 'utf-8');
|
|
27
|
+
const content = (0, jest_utils_1.updateJestConfigContent)(originalContent);
|
|
28
|
+
host.write(configPath, content);
|
|
29
|
+
}
|
|
30
|
+
exports.updateSpecConfig = updateSpecConfig;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
|
+
import type { SupportedStyles } from '../../../typings/style';
|
|
4
|
+
|
|
5
|
+
export interface Schema {
|
|
6
|
+
name: string;
|
|
7
|
+
style: SupportedStyles;
|
|
8
|
+
skipFormat?: boolean;
|
|
9
|
+
directory?: string;
|
|
10
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
11
|
+
tags?: string;
|
|
12
|
+
unitTestRunner?: 'jest' | 'vitest' | 'none';
|
|
13
|
+
inSourceTests?: boolean;
|
|
14
|
+
e2eTestRunner: 'cypress' | 'playwright' | 'none';
|
|
15
|
+
linter: Linter;
|
|
16
|
+
pascalCaseFiles?: boolean;
|
|
17
|
+
classComponent?: boolean;
|
|
18
|
+
routing?: boolean;
|
|
19
|
+
skipNxJson?: boolean;
|
|
20
|
+
js?: boolean;
|
|
21
|
+
globalCss?: boolean;
|
|
22
|
+
strict?: boolean;
|
|
23
|
+
setParserOptionsProject?: boolean;
|
|
24
|
+
compiler?: 'babel' | 'swc';
|
|
25
|
+
remotes?: string[];
|
|
26
|
+
devServerPort?: number;
|
|
27
|
+
skipPackageJson?: boolean;
|
|
28
|
+
rootProject?: boolean;
|
|
29
|
+
bundler?: 'webpack' | 'vite' | 'rspack';
|
|
30
|
+
minimal?: boolean;
|
|
31
|
+
addPlugin?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface NormalizedSchema<T extends Schema = Schema> extends T {
|
|
35
|
+
projectName: string;
|
|
36
|
+
appProjectRoot: string;
|
|
37
|
+
e2eProjectName: string;
|
|
38
|
+
e2eProjectRoot: string;
|
|
39
|
+
parsedTags: string[];
|
|
40
|
+
fileName: string;
|
|
41
|
+
styledModule: null | SupportedStyles;
|
|
42
|
+
hasStyles: boolean;
|
|
43
|
+
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
44
|
+
addPlugin?: boolean;
|
|
45
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxReactApp",
|
|
5
|
+
"title": "Create a React Application",
|
|
6
|
+
"description": "Create a React application for Nx.",
|
|
7
|
+
"examples": [
|
|
8
|
+
{
|
|
9
|
+
"command": "nx g app myapp --directory=myorg",
|
|
10
|
+
"description": "Generate `apps/myorg/myapp` and `apps/myorg/myapp-e2e`"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"command": "nx g app myapp --classComponent",
|
|
14
|
+
"description": "Use class components instead of functional components"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"command": "nx g app myapp --routing",
|
|
18
|
+
"description": "Set up React Router"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"name": {
|
|
24
|
+
"description": "The name of the application.",
|
|
25
|
+
"type": "string",
|
|
26
|
+
"$default": {
|
|
27
|
+
"$source": "argv",
|
|
28
|
+
"index": 0
|
|
29
|
+
},
|
|
30
|
+
"x-prompt": "What name would you like to use for the application?",
|
|
31
|
+
"pattern": "^[a-zA-Z][^:]*$"
|
|
32
|
+
},
|
|
33
|
+
"directory": {
|
|
34
|
+
"description": "The directory of the new application.",
|
|
35
|
+
"type": "string",
|
|
36
|
+
"alias": "dir",
|
|
37
|
+
"x-priority": "important"
|
|
38
|
+
},
|
|
39
|
+
"projectNameAndRootFormat": {
|
|
40
|
+
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"enum": ["as-provided", "derived"]
|
|
43
|
+
},
|
|
44
|
+
"style": {
|
|
45
|
+
"description": "The file extension to be used for style files.",
|
|
46
|
+
"type": "string",
|
|
47
|
+
"default": "css",
|
|
48
|
+
"alias": "s",
|
|
49
|
+
"x-prompt": {
|
|
50
|
+
"message": "Which stylesheet format would you like to use?",
|
|
51
|
+
"type": "list",
|
|
52
|
+
"items": [
|
|
53
|
+
{
|
|
54
|
+
"value": "css",
|
|
55
|
+
"label": "CSS"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"value": "scss",
|
|
59
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"value": "less",
|
|
63
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"value": "tailwind",
|
|
67
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"value": "styled-components",
|
|
71
|
+
"label": "styled-components [ https://styled-components.com ]"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"value": "@emotion/styled",
|
|
75
|
+
"label": "emotion [ https://emotion.sh ]"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"value": "styled-jsx",
|
|
79
|
+
"label": "styled-jsx [ https://www.npmjs.com/package/styled-jsx ]"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"value": "none",
|
|
83
|
+
"label": "None"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"linter": {
|
|
89
|
+
"description": "The tool to use for running lint checks.",
|
|
90
|
+
"type": "string",
|
|
91
|
+
"enum": ["eslint", "none"],
|
|
92
|
+
"default": "eslint"
|
|
93
|
+
},
|
|
94
|
+
"routing": {
|
|
95
|
+
"type": "boolean",
|
|
96
|
+
"description": "Generate application with routes.",
|
|
97
|
+
"x-prompt": "Would you like to add React Router to this application?",
|
|
98
|
+
"default": false
|
|
99
|
+
},
|
|
100
|
+
"skipFormat": {
|
|
101
|
+
"description": "Skip formatting files.",
|
|
102
|
+
"type": "boolean",
|
|
103
|
+
"default": false,
|
|
104
|
+
"x-priority": "internal"
|
|
105
|
+
},
|
|
106
|
+
"skipNxJson": {
|
|
107
|
+
"description": "Skip updating `nx.json` with default options based on values provided to this app.",
|
|
108
|
+
"type": "boolean",
|
|
109
|
+
"default": false,
|
|
110
|
+
"x-priority": "internal"
|
|
111
|
+
},
|
|
112
|
+
"unitTestRunner": {
|
|
113
|
+
"type": "string",
|
|
114
|
+
"enum": ["jest", "vitest", "none"],
|
|
115
|
+
"description": "Test runner to use for unit tests.",
|
|
116
|
+
"default": "jest"
|
|
117
|
+
},
|
|
118
|
+
"inSourceTests": {
|
|
119
|
+
"type": "boolean",
|
|
120
|
+
"default": false,
|
|
121
|
+
"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"
|
|
122
|
+
},
|
|
123
|
+
"e2eTestRunner": {
|
|
124
|
+
"type": "string",
|
|
125
|
+
"enum": ["cypress", "playwright", "none"],
|
|
126
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
127
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
128
|
+
"default": "cypress"
|
|
129
|
+
},
|
|
130
|
+
"tags": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"description": "Add tags to the application (used for linting).",
|
|
133
|
+
"alias": "t"
|
|
134
|
+
},
|
|
135
|
+
"pascalCaseFiles": {
|
|
136
|
+
"type": "boolean",
|
|
137
|
+
"description": "Use pascal case component file name (e.g. `App.tsx`).",
|
|
138
|
+
"alias": "P",
|
|
139
|
+
"default": false
|
|
140
|
+
},
|
|
141
|
+
"classComponent": {
|
|
142
|
+
"type": "boolean",
|
|
143
|
+
"description": "Use class components instead of functional component.",
|
|
144
|
+
"alias": "C",
|
|
145
|
+
"default": false
|
|
146
|
+
},
|
|
147
|
+
"js": {
|
|
148
|
+
"type": "boolean",
|
|
149
|
+
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
150
|
+
"default": false
|
|
151
|
+
},
|
|
152
|
+
"globalCss": {
|
|
153
|
+
"type": "boolean",
|
|
154
|
+
"description": "Default is `false`. When `true`, the component is generated with `*.css`/`*.scss` instead of `*.module.css`/`*.module.scss`.",
|
|
155
|
+
"default": false
|
|
156
|
+
},
|
|
157
|
+
"strict": {
|
|
158
|
+
"type": "boolean",
|
|
159
|
+
"description": "Creates an application with strict mode and strict type checking.",
|
|
160
|
+
"default": true
|
|
161
|
+
},
|
|
162
|
+
"setParserOptionsProject": {
|
|
163
|
+
"type": "boolean",
|
|
164
|
+
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
|
165
|
+
"default": false
|
|
166
|
+
},
|
|
167
|
+
"compiler": {
|
|
168
|
+
"type": "string",
|
|
169
|
+
"description": "The compiler to use.",
|
|
170
|
+
"enum": ["babel", "swc"],
|
|
171
|
+
"default": "babel"
|
|
172
|
+
},
|
|
173
|
+
"skipPackageJson": {
|
|
174
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
175
|
+
"type": "boolean",
|
|
176
|
+
"default": false,
|
|
177
|
+
"x-priority": "internal"
|
|
178
|
+
},
|
|
179
|
+
"rootProject": {
|
|
180
|
+
"description": "Create a application at the root of the workspace",
|
|
181
|
+
"type": "boolean",
|
|
182
|
+
"default": false,
|
|
183
|
+
"hidden": true
|
|
184
|
+
},
|
|
185
|
+
"bundler": {
|
|
186
|
+
"description": "The bundler to use.",
|
|
187
|
+
"type": "string",
|
|
188
|
+
"enum": ["vite", "webpack", "rspack"],
|
|
189
|
+
"x-prompt": "Which bundler do you want to use to build the application?",
|
|
190
|
+
"default": "webpack",
|
|
191
|
+
"x-priority": "important"
|
|
192
|
+
},
|
|
193
|
+
"minimal": {
|
|
194
|
+
"description": "Generate a React app with a minimal setup, no separate test files.",
|
|
195
|
+
"type": "boolean",
|
|
196
|
+
"default": false
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"required": ["name"],
|
|
200
|
+
"examplesFile": "../../../docs/application-examples.md"
|
|
201
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export declare function componentGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function componentGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
5
|
+
export default componentGenerator;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentGeneratorInternal = exports.componentGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const add_styled_dependencies_1 = require("../../rules/add-styled-dependencies");
|
|
8
|
+
const ast_utils_1 = require("../../utils/ast-utils");
|
|
9
|
+
const get_in_source_vitest_tests_template_1 = require("../../utils/get-in-source-vitest-tests-template");
|
|
10
|
+
const versions_1 = require("../../utils/versions");
|
|
11
|
+
const get_component_tests_1 = require("./lib/get-component-tests");
|
|
12
|
+
const normalize_options_1 = require("./lib/normalize-options");
|
|
13
|
+
async function componentGenerator(host, schema) {
|
|
14
|
+
return componentGeneratorInternal(host, {
|
|
15
|
+
nameAndDirectoryFormat: 'derived',
|
|
16
|
+
...schema,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.componentGenerator = componentGenerator;
|
|
20
|
+
async function componentGeneratorInternal(host, schema) {
|
|
21
|
+
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
22
|
+
createComponentFiles(host, options);
|
|
23
|
+
const tasks = [];
|
|
24
|
+
const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(host, options);
|
|
25
|
+
tasks.push(styledTask);
|
|
26
|
+
addExportsToBarrel(host, options);
|
|
27
|
+
if (options.routing) {
|
|
28
|
+
const routingTask = (0, devkit_1.addDependenciesToPackageJson)(host, { 'react-router-dom': versions_1.reactRouterDomVersion }, {});
|
|
29
|
+
tasks.push(routingTask);
|
|
30
|
+
}
|
|
31
|
+
if (!options.skipFormat) {
|
|
32
|
+
await (0, devkit_1.formatFiles)(host);
|
|
33
|
+
}
|
|
34
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
35
|
+
}
|
|
36
|
+
exports.componentGeneratorInternal = componentGeneratorInternal;
|
|
37
|
+
function createComponentFiles(host, options) {
|
|
38
|
+
const componentTests = (0, get_component_tests_1.getComponentTests)(options);
|
|
39
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.directory, {
|
|
40
|
+
...options,
|
|
41
|
+
componentTests,
|
|
42
|
+
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(componentTests),
|
|
43
|
+
tmpl: '',
|
|
44
|
+
});
|
|
45
|
+
for (const c of host.listChanges()) {
|
|
46
|
+
let deleteFile = false;
|
|
47
|
+
if ((options.skipTests || options.inSourceTests) &&
|
|
48
|
+
/.*spec.tsx/.test(c.path)) {
|
|
49
|
+
deleteFile = true;
|
|
50
|
+
}
|
|
51
|
+
if ((options.styledModule || !options.hasStyles) &&
|
|
52
|
+
c.path.endsWith(`.${options.style}`)) {
|
|
53
|
+
deleteFile = true;
|
|
54
|
+
}
|
|
55
|
+
if (options.globalCss && c.path.endsWith(`.module.${options.style}`)) {
|
|
56
|
+
deleteFile = true;
|
|
57
|
+
}
|
|
58
|
+
if (!options.globalCss &&
|
|
59
|
+
c.path.endsWith(`${options.fileName}.${options.style}`)) {
|
|
60
|
+
deleteFile = true;
|
|
61
|
+
}
|
|
62
|
+
if (deleteFile) {
|
|
63
|
+
host.delete(c.path);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (options.js) {
|
|
67
|
+
(0, devkit_1.toJS)(host);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let tsModule;
|
|
71
|
+
function addExportsToBarrel(host, options) {
|
|
72
|
+
if (!tsModule) {
|
|
73
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
74
|
+
}
|
|
75
|
+
const workspace = (0, devkit_1.getProjects)(host);
|
|
76
|
+
const isApp = workspace.get(options.projectName).projectType === 'application';
|
|
77
|
+
if (options.export && !isApp) {
|
|
78
|
+
const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts');
|
|
79
|
+
const indexSource = host.read(indexFilePath, 'utf-8');
|
|
80
|
+
if (indexSource !== null) {
|
|
81
|
+
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
82
|
+
const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
|
|
83
|
+
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, ast_utils_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
|
|
84
|
+
host.write(indexFilePath, changes);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function getRelativeImportToFile(indexPath, filePath) {
|
|
89
|
+
const { name, dir } = (0, path_1.parse)(filePath);
|
|
90
|
+
const relativeDirToTarget = (0, path_1.relative)((0, path_1.dirname)(indexPath), dir);
|
|
91
|
+
return `./${(0, devkit_1.joinPathFragments)(relativeDirToTarget, name)}`;
|
|
92
|
+
}
|
|
93
|
+
exports.default = componentGenerator;
|
|
File without changes
|