Skip to content

Commit

Permalink
Merge pull request #18 from CommunityToolkit/node-extensions
Browse files Browse the repository at this point in the history
Adding a NodeJS extensions pack
  • Loading branch information
aaronpowell authored Sep 12, 2024
2 parents 3d6ee2d + 4f1dace commit 399b7a0
Show file tree
Hide file tree
Showing 77 changed files with 15,194 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
with:
node-version: "latest"

- uses: pnpm/action-setup@v4
name: Setup pnpm
with:
version: 9
run_install: false

- uses: actions/cache@v4
name: Cache NuGet packages
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/dotnet-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
with:
node-version: "latest"

- uses: pnpm/action-setup@v4
name: Setup pnpm
with:
version: 9
run_install: false

- uses: actions/cache@v4
name: Cache NuGet packages
with:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ jobs:
with:
node-version: "latest"

- uses: pnpm/action-setup@v4
name: Setup pnpm
with:
version: 9
run_install: false

- uses: actions/cache@v4
name: Cache NuGet packages
with:
Expand Down Expand Up @@ -147,3 +153,4 @@ jobs:

- name: Publish to GitHub packages
run: dotnet nuget push ./*.nupkg --source "https://nuget.pkg.github.com/communitytoolkit/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ appsettings.*.json
*.orig
test-results
TestResults
nuget
nuget
.pnpm-store
24 changes: 24 additions & 0 deletions CommunityToolkit.Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Sta
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults", "examples\swa\CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults\CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults.csproj", "{83FF8083-7EE2-4196-86A8-239F921B443C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.NodeJS.Extensions", "src\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.csproj", "{1F299343-30DF-4599-A95D-BCFB1754DA48}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nodejs-ext", "nodejs-ext", "{261AC321-8982-4C3A-8DBF-DAFC95F97697}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.AppHost", "examples\nodejs-ext\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.AppHost\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.AppHost.csproj", "{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests", "tests\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests.csproj", "{E8F93376-1367-4A7B-A729-116199804356}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -91,6 +99,18 @@ Global
{83FF8083-7EE2-4196-86A8-239F921B443C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83FF8083-7EE2-4196-86A8-239F921B443C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83FF8083-7EE2-4196-86A8-239F921B443C}.Release|Any CPU.Build.0 = Release|Any CPU
{1F299343-30DF-4599-A95D-BCFB1754DA48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F299343-30DF-4599-A95D-BCFB1754DA48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F299343-30DF-4599-A95D-BCFB1754DA48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F299343-30DF-4599-A95D-BCFB1754DA48}.Release|Any CPU.Build.0 = Release|Any CPU
{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1}.Release|Any CPU.Build.0 = Release|Any CPU
{E8F93376-1367-4A7B-A729-116199804356}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8F93376-1367-4A7B-A729-116199804356}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8F93376-1367-4A7B-A729-116199804356}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8F93376-1367-4A7B-A729-116199804356}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -110,6 +130,10 @@ Global
{C083A377-13CA-47C1-8B17-1FE353EA76F0} = {564FA6A0-EC54-41C6-A35F-89890E1D06E3}
{BAEA0F6F-39E9-4893-8787-C4D292D3B169} = {564FA6A0-EC54-41C6-A35F-89890E1D06E3}
{83FF8083-7EE2-4196-86A8-239F921B443C} = {564FA6A0-EC54-41C6-A35F-89890E1D06E3}
{1F299343-30DF-4599-A95D-BCFB1754DA48} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
{261AC321-8982-4C3A-8DBF-DAFC95F97697} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1} = {261AC321-8982-4C3A-8DBF-DAFC95F97697}
{E8F93376-1367-4A7B-A729-116199804356} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08B1D4B8-D2C5-4A64-BB8B-E1A2B29525F0}
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ All features are contributed by you, our amazing .NET community, and maintained

This repository contains the source code for the .NET Aspire Community Toolkit, a collection of community created Integrations and extensions for [.NET Aspire](https://aka.ms/dotnet/aspire).

| Package | Latest stable | Latest Preview | Description |
| ----------------------------------------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`Hosting.Azure.StaticWebApps`][swa-integration-docs] | [![CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps][swa-shields]][swa-nuget] | [![CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps][swa-shields-preview]][swa-nuget-preview] | A hosting component for the [Azure Static Web Apps emulator](https://learn.microsoft.com/azure/static-web-apps/static-web-apps-cli-overview) (Note: this does not support deployment of a project to Azure Static Web Apps). |
| [`Hosting.Java`][java-integration-docs] | [![CommunityToolkit.Aspire.Java][java-shields]][java-nuget] | [![CommunityToolkit.Aspire.Hosting.Java][java-shields-preview]][java-nuget-preview] | A component for running Java code in .NET Aspire either using the local JDK or using a container. |
| Package | Latest stable | Latest Preview | Description |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`Hosting.Azure.StaticWebApps`][swa-integration-docs] | [![CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps][swa-shields]][swa-nuget] | [![CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps][swa-shields-preview]][swa-nuget-preview] | A hosting integration for the [Azure Static Web Apps emulator](https://learn.microsoft.com/azure/static-web-apps/static-web-apps-cli-overview) (Note: this does not support deployment of a project to Azure Static Web Apps). |
| [`Hosting.Java`][java-integration-docs] | [![CommunityToolkit.Aspire.Java][java-shields]][java-nuget] | [![CommunityToolkit.Aspire.Hosting.Java][java-shields-preview]][java-nuget-preview] | A integration for running Java code in .NET Aspire either using the local JDK or using a container. |
| [`Hosting.NodeJS.Extensions`][nodejs-ext-integration-docs] | [![CommunityToolkit.Aspire.NodeJS.Extensions][nodejs-ext-shields]][nodejs-ext-nuget] | [![CommunityToolkit.Aspire.Hosting.NodeJS.Extensions][nodejs-ext-shields-preview]][nodejs-ext-nuget-preview] | An integration that contains some additional extensions for running Node.js applications |

## 🙌 Getting Started

Expand Down Expand Up @@ -45,3 +46,8 @@ Made with [contrib.rocks](https://contrib.rocks).
[java-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.Java/
[java-shields-preview]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.Java?label=nuget%20(preview)
[java-nuget-preview]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.Java/absoluteLatest
[nodejs-ext-integration-docs]: https://communitytoolkit.github.io/aspire/integrations/hosting-nodejs-extensions
[nodejs-ext-shields]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions
[nodejs-ext-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/
[nodejs-ext-shields-preview]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions?label=nuget%20(preview)
[nodejs-ext-nuget-preview]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/absoluteLatest
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Welcome to the .NET Aspire Community Toolkit, a collection of integrations and e

The Community Toolkit consists of a collection of NuGet packages that can be added to your .NET project, each representing an individual .NET Aspire component. The following packages are available:

- [CommunityToolkit.Aspire.Hosting.Java](integrations/hosting-java.md)
- [CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps](integrations/hosting-azure-static-web-apps.md)
- [CommunityToolkit.Aspire.Hosting.Java](integrations/hosting-java.md)
- [CommunityToolkit.Aspire.Hosting.NodeJS.Extensions](integrations/hosting-nodejs-extensions.md)

## .NET Aspire and the Community Toolkit

Expand Down
30 changes: 30 additions & 0 deletions docs/integrations/hosting-nodejs-extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# CommunityToolkit.Aspire.Hosting.NodeJS.Extensions

[![CommunityToolkit.Aspire.Hosting.NodeJS.Extensions](https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions)](https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/) | [![CommunityToolkit.Aspire.Hosting.NodeJS.Extensions (latest)](<https://img.shields.io/nuget/vpre/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions?label=nuget%20(preview)>)](https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/absoluteLatest)

## Overview

This package provides some extensions on the .NET Aspire [NodeJS hosting package](https://nuget.org/packages/Aspire.Hosting.NodeJS) and adds support for:

- Running [Vite](https://vitejs.dev/) applications
- Running Node.js applications using [Yarn](https://yarnpkg.com/) and [pnpm](https://pnpm.io/)
- Ensuring that the packages are installed before running the application (using the specified package manager)

## Usage

```csharp
using CommunityToolkit.Aspire.Hosting.NodeJS.Extensions;

var builder = DistributedApplication.CreateBuilder(args);

builder.AddViteApp("vite-demo")
.WithNpmPackageInstallation();

builder.AddViteApp("yarn-demo", packageManager: "yarn")
.WithYarnPackageInstallation();

builder.AddViteApp("pnpm-demo", packageManager: "pnpm")
.WithPnpmPackageInstallation();

builder.Build().Run();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>125d4633-7e41-4639-b0ce-cfc16cd67e39</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.csproj" IsAspireProjectResource="false" />
</ItemGroup>

<Target Name="CleanNodeModules" AfterTargets="Build">
<Exec WorkingDirectory="../vite-demo" Command="rm -r node_modules" Condition="Exists('../vite-demo/node_modules')" />
<Exec WorkingDirectory="../pnpm-demo" Command="rm -r node_modules" Condition="Exists('../pnpm-demo/node_modules')" />
<Exec WorkingDirectory="../yarn-demo" Command="rm -r node_modules" Condition="Exists('../yarn-demo/node_modules')" />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using CommunityToolkit.Aspire.Hosting.NodeJS.Extensions;

var builder = DistributedApplication.CreateBuilder(args);

builder.AddViteApp("vite-demo")
.WithNpmPackageInstallation();

builder.AddViteApp("yarn-demo", packageManager: "yarn")
.WithYarnPackageInstallation();

builder.AddViteApp("pnpm-demo", packageManager: "pnpm")
.WithPnpmPackageInstallation();

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17113;http://localhost:15271",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21203",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22089"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15271",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19015",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20243"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
24 changes: 24 additions & 0 deletions examples/nodejs-ext/pnpm-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
50 changes: 50 additions & 0 deletions examples/nodejs-ext/pnpm-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions examples/nodejs-ext/pnpm-demo/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions examples/nodejs-ext/pnpm-demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit 399b7a0

Please sign in to comment.