diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 2cd00cb89..6096ba239 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -8,13 +8,9 @@ echo Install .NET dev certs dotnet tool update -g linux-dev-certs dotnet linux-dev-certs install -echo Install the SWA CLI -npm install -g @azure/static-web-apps-cli - -echo Install SWA demo packages -cd examples/swa/CommunityToolkit.Aspire.StaticWebApps.WebApp -npm ci -cd ../../../ +echo Install JS monorepo tools +npm install -g turbo +npm install -g nx echo Install Aspire 9 templates dotnet new install Aspire.ProjectTemplates diff --git a/.github/actions/setup-runtimes-caching/action.yml b/.github/actions/setup-runtimes-caching/action.yml index ca5f9cbc6..866e88de1 100644 --- a/.github/actions/setup-runtimes-caching/action.yml +++ b/.github/actions/setup-runtimes-caching/action.yml @@ -93,13 +93,12 @@ runs: dotnet tool update -g linux-dev-certs dotnet linux-dev-certs install - - name: Setup Node projects + - name: Setup Node globals shell: bash - if: ${{ contains(inputs.name, 'StaticWebApps') }} + if: ${{ contains(inputs.name, 'Node') }} run: | - npm install -g @azure/static-web-apps-cli - cd examples/swa/CommunityToolkit.Aspire.StaticWebApps.WebApp - npm ci + npm install -g turbo + npm install -g nx - name: Login to docker uses: docker/login-action@v3 diff --git a/examples/nodejs-ext/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.AppHost/Program.cs b/examples/nodejs-ext/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.AppHost/Program.cs index 6170fd874..8b4b2553d 100644 --- a/examples/nodejs-ext/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.AppHost/Program.cs +++ b/examples/nodejs-ext/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.AppHost/Program.cs @@ -12,4 +12,26 @@ .WithPnpmPackageInstallation() .WithHttpHealthCheck(); +// Example of Nx monorepo support - uncomment if you have an Nx workspace +var nx = builder.AddNxApp("nx-demo") + .WithNpmPackageInstaller(); + +nx.AddApp("blog-monorepo") + .WithHttpEndpoint() + .WithMappedEndpointPort() + .WithHttpHealthCheck(); + +// Example of Turborepo monorepo support - uncomment if you have a Turborepo workspace +var turbo = builder.AddTurborepoApp("turborepo-demo") + .WithNpmPackageInstaller(); + +turbo.AddApp("turbo-web", filter: "web") + .WithHttpEndpoint() + .WithMappedEndpointPort() + .WithHttpHealthCheck(); +turbo.AddApp("turbo-docs", filter: "docs") + .WithHttpEndpoint() + .WithMappedEndpointPort() + .WithHttpHealthCheck(); + builder.Build().Run(); diff --git a/examples/nodejs-ext/nx-demo/.editorconfig b/examples/nodejs-ext/nx-demo/.editorconfig new file mode 100644 index 000000000..6e87a003d --- /dev/null +++ b/examples/nodejs-ext/nx-demo/.editorconfig @@ -0,0 +1,13 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/examples/nodejs-ext/nx-demo/.gitignore b/examples/nodejs-ext/nx-demo/.gitignore new file mode 100644 index 000000000..451ee7276 --- /dev/null +++ b/examples/nodejs-ext/nx-demo/.gitignore @@ -0,0 +1,47 @@ +# See https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files for more about ignoring files. + +# compiled output +dist +tmp +out-tsc + +# dependencies +node_modules + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# misc +/.sass-cache +/connect.lock +/coverage +/libpeerconnection.log +npm-debug.log +yarn-error.log +testem.log +/typings + +# System Files +.DS_Store +Thumbs.db + +.nx/cache +.nx/workspace-data +.cursor/rules/nx-rules.mdc +.github/instructions/nx.instructions.md + +vite.config.*.timestamp* +vitest.config.*.timestamp* \ No newline at end of file diff --git a/examples/nodejs-ext/nx-demo/.prettierignore b/examples/nodejs-ext/nx-demo/.prettierignore new file mode 100644 index 000000000..e26f0b3f7 --- /dev/null +++ b/examples/nodejs-ext/nx-demo/.prettierignore @@ -0,0 +1,5 @@ +# Add files here to ignore them from prettier formatting +/dist +/coverage +/.nx/cache +/.nx/workspace-data \ No newline at end of file diff --git a/examples/nodejs-ext/nx-demo/.prettierrc b/examples/nodejs-ext/nx-demo/.prettierrc new file mode 100644 index 000000000..544138be4 --- /dev/null +++ b/examples/nodejs-ext/nx-demo/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/examples/nodejs-ext/nx-demo/.vscode/extensions.json b/examples/nodejs-ext/nx-demo/.vscode/extensions.json new file mode 100644 index 000000000..462e29bbf --- /dev/null +++ b/examples/nodejs-ext/nx-demo/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "nrwl.angular-console", + "esbenp.prettier-vscode", + "dbaeumer.vscode-eslint" + ] +} diff --git a/examples/nodejs-ext/nx-demo/README.md b/examples/nodejs-ext/nx-demo/README.md new file mode 100644 index 000000000..f2a13b9a5 --- /dev/null +++ b/examples/nodejs-ext/nx-demo/README.md @@ -0,0 +1,101 @@ +# BlogMonorepo + + + +✨ Your new, shiny [Nx workspace](https://nx.dev) is ready ✨. + +[Learn more about this workspace setup and its capabilities](https://nx.dev/getting-started/tutorials/react-monorepo-tutorial?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) or run `npx nx graph` to visually explore what was created. Now, let's get you up to speed! + +## Run tasks + +To run the dev server for your app, use: + +```sh +npx nx serve blog-monorepo +``` + +To create a production bundle: + +```sh +npx nx build blog-monorepo +``` + +To see all available targets to run for a project, run: + +```sh +npx nx show project blog-monorepo +``` + +These targets are either [inferred automatically](https://nx.dev/concepts/inferred-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) or defined in the `project.json` or `package.json` files. + +[More about running tasks in the docs »](https://nx.dev/features/run-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) + +## Add new projects + +While you could add new projects to your workspace manually, you might want to leverage [Nx plugins](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) and their [code generation](https://nx.dev/features/generate-code?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) feature. + +Use the plugin's generator to create new projects. + +To generate a new application, use: + +```sh +npx nx g @nx/react:app demo +``` + +To generate a new library, use: + +```sh +npx nx g @nx/react:lib mylib +``` + +You can use `npx nx list` to get a list of installed plugins. Then, run `npx nx list ` to learn about more specific capabilities of a particular plugin. Alternatively, [install Nx Console](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) to browse plugins and generators in your IDE. + +[Learn more about Nx plugins »](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) | [Browse the plugin registry »](https://nx.dev/plugin-registry?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) + +## Set up CI! + +### Step 1 + +To connect to Nx Cloud, run the following command: + +```sh +npx nx connect +``` + +Connecting to Nx Cloud ensures a [fast and scalable CI](https://nx.dev/ci/intro/why-nx-cloud?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) pipeline. It includes features such as: + +- [Remote caching](https://nx.dev/ci/features/remote-cache?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) +- [Task distribution across multiple machines](https://nx.dev/ci/features/distribute-task-execution?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) +- [Automated e2e test splitting](https://nx.dev/ci/features/split-e2e-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) +- [Task flakiness detection and rerunning](https://nx.dev/ci/features/flaky-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) + +### Step 2 + +Use the following command to configure a CI workflow for your workspace: + +```sh +npx nx g ci-workflow +``` + +[Learn more about Nx on CI](https://nx.dev/ci/intro/ci-with-nx#ready-get-started-with-your-provider?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) + +## Install Nx Console + +Nx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ. + +[Install Nx Console »](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) + +## Useful links + +Learn more: + +- [Learn more about this workspace setup](https://nx.dev/getting-started/tutorials/react-monorepo-tutorial?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) +- [Learn about Nx on CI](https://nx.dev/ci/intro/ci-with-nx?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) +- [Releasing Packages with Nx release](https://nx.dev/features/manage-releases?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) +- [What are Nx plugins?](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) + +And join the Nx community: +- [Discord](https://go.nx.dev/community) +- [Follow us on X](https://twitter.com/nxdevtools) or [LinkedIn](https://www.linkedin.com/company/nrwl) +- [Our Youtube channel](https://www.youtube.com/@nxdevtools) +- [Our blog](https://nx.dev/blog?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) diff --git a/examples/nodejs-ext/nx-demo/apps/blog-monorepo/eslint.config.mjs b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/eslint.config.mjs new file mode 100644 index 000000000..e8e4590e6 --- /dev/null +++ b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/eslint.config.mjs @@ -0,0 +1,12 @@ +import nx from '@nx/eslint-plugin'; +import baseConfig from '../../eslint.config.mjs'; + +export default [ + ...baseConfig, + ...nx.configs['flat/react'], + { + files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], + // Override or add rules here + rules: {}, + }, +]; diff --git a/examples/nodejs-ext/nx-demo/apps/blog-monorepo/index.html b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/index.html new file mode 100644 index 000000000..1fa59419d --- /dev/null +++ b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/index.html @@ -0,0 +1,16 @@ + + + + + BlogMonorepo + + + + + + + +
+ + + diff --git a/examples/nodejs-ext/nx-demo/apps/blog-monorepo/package.json b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/package.json new file mode 100644 index 000000000..cafa7f023 --- /dev/null +++ b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/package.json @@ -0,0 +1,5 @@ +{ + "name": "@blog-monorepo/blog-monorepo", + "version": "0.0.1", + "private": true +} diff --git a/examples/nodejs-ext/nx-demo/apps/blog-monorepo/public/favicon.ico b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/public/favicon.ico new file mode 100644 index 000000000..317ebcb23 Binary files /dev/null and b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/public/favicon.ico differ diff --git a/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/app.module.css b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/app.module.css new file mode 100644 index 000000000..7b88fbabf --- /dev/null +++ b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/app.module.css @@ -0,0 +1 @@ +/* Your styles goes here. */ diff --git a/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/app.tsx b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/app.tsx new file mode 100644 index 000000000..3a4289818 --- /dev/null +++ b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/app.tsx @@ -0,0 +1,52 @@ +// Uncomment this line to use CSS modules +// import styles from './app.module.css'; +import NxWelcome from './nx-welcome'; + +import { Route, Routes, Link } from 'react-router-dom'; + +export function App() { + return ( +
+ + + {/* START: routes */} + {/* These routes and navigation have been generated for you */} + {/* Feel free to move and update them to fit your needs */} +
+
+
+
+
    +
  • + Home +
  • +
  • + Page 2 +
  • +
+
+ + + This is the generated root route.{' '} + Click here for page 2. +
+ } + /> + + Click here to go back to root page. + + } + /> + + {/* END: routes */} + + ); +} + +export default App; diff --git a/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/nx-welcome.tsx b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/nx-welcome.tsx new file mode 100644 index 000000000..f3c5c7a9f --- /dev/null +++ b/examples/nodejs-ext/nx-demo/apps/blog-monorepo/src/app/nx-welcome.tsx @@ -0,0 +1,856 @@ +/* + * * * * * * * * * * * * * * * * * * * * * * * * * * * * + This is a starter component and can be deleted. + * * * * * * * * * * * * * * * * * * * * * * * * * * * * + Delete this file and get started with your project! + * * * * * * * * * * * * * * * * * * * * * * * * * * * * + */ +export function NxWelcome({ title }: { title: string }) { + return ( + <> +