Skip to content

Commit

Permalink
Merge pull request #1 from PrincipleStudios/vite-development-server
Browse files Browse the repository at this point in the history
Vite development server
  • Loading branch information
mdekrey authored Feb 7, 2024
2 parents 11b8788 + 522297a commit 39e4e98
Show file tree
Hide file tree
Showing 36 changed files with 2,555 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
indent_style = tab
dotnet_style_prefer_collection_expression = true:suggestion
end_of_line = lf

[*.cs]
csharp_indent_labels = one_less_than_current
Expand All @@ -89,4 +91,5 @@ csharp_style_throw_expression = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_space_around_binary_operators = before_and_after
csharp_space_around_binary_operators = before_and_after
csharp_style_prefer_primary_constructors = true:suggestion
66 changes: 66 additions & 0 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: All packages build

on:
push:
branches: [ main ]
pull_request:
branches:
- '**/*'

jobs:
build:

runs-on: ubuntu-latest
permissions:
packages: write

steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/parts/cache/

###########
# BUILD
- name: Restore dependencies
run: dotnet restore
- name: Build
run: |
if [[ $VERSION_SUFFIX ]]; then
VERSION_SUFFIX_PARAM="--version-suffix sha.$VERSION_SUFFIX"
else
VERSION_SUFFIX_PARAM=''
fi
dotnet build --no-restore --configuration Release ${VERSION_SUFFIX_PARAM}
env:
VERSION_SUFFIX: ${{ github.ref != 'refs/heads/main' && github.sha || '' }}

###########
# TEST
- name: Test
run: dotnet test --no-build --verbosity normal --configuration Release --collect:"XPlat Code Coverage"
# - name: 'Upload Code Coverage'
# uses: actions/upload-artifact@v3
# with:
# name: code-coverage
# path: ./lib/*/TestResults/*/coverage.cobertura.xml
# retention-days: 7
# - name: Record code coverage
# uses: 5monkeys/cobertura-action@master
# with:
# path: ./lib/*/TestResults/*/coverage.cobertura.xml
# repo_token: ${{ secrets.GITHUB_TOKEN }}
# minimum_coverage: 90
# fail_below_threshold: false

###########
# PUBLISH
- name: Publish NuGet packages to GitHub registry if new version number
if: ${{ github.ref != 'refs/heads/main' }}
run: dotnet nuget push ./artifacts/packages/Release/*.nupkg -k ${GITHUB_TOKEN} -s https://nuget.pkg.github.com/$GITHUB_REPOSITORY_OWNER/index.json --skip-duplicate --no-symbols
continue-on-error: true # Dependabot and other outside contributors can't push to our GitHub packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish NuGet packages to NuGet registry if new version number
if: ${{ github.ref == 'refs/heads/main' }}
run: dotnet nuget push ./artifacts/packages/Release/*.nupkg -k ${NUGET_API_KEY} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
14 changes: 14 additions & 0 deletions .github/workflows/dotnet-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint DotNet
on:
pull_request:
types: [edited, opened, reopened, synchronize, ready_for_review]

jobs:
build:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/parts/cache/
- name: 'Run dotnet checks'
run: |
dotnet format --verify-no-changes
20 changes: 20 additions & 0 deletions .github/workflows/parts/cache/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Package Cache'
description: 'Caches packages for this repository'
inputs: {}
outputs: {}
runs:
using: 'composite'
steps:
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- uses: actions/setup-node@v3
with:
node-version: 20.8.1

- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.8.1
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageIcon>logo_black_small.png</PackageIcon>
<Copyright>2024 Principle Studios</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 28 additions & 0 deletions PrincipleStudios.NodeDevTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,40 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViteDevelopmentServer", "ViteDevelopmentServer\ViteDevelopmentServer.csproj", "{38497A4D-272C-459E-9630-B2C30A1037E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViteDevelopmentServer.Test", "ViteDevelopmentServer.Test\ViteDevelopmentServer.Test.csproj", "{EDA44AA3-CEAF-471F-8876-DFBDC5937318}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViteDevelopmentServer.Demo", "ViteDevelopmentServer.Demo\ViteDevelopmentServer.Demo.csproj", "{5F84DBF6-C2A6-495F-A5D5-5C75577E1C6E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0BB97384-E3F9-4DEE-A998-BC9B96A65F90}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{38497A4D-272C-459E-9630-B2C30A1037E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38497A4D-272C-459E-9630-B2C30A1037E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38497A4D-272C-459E-9630-B2C30A1037E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38497A4D-272C-459E-9630-B2C30A1037E4}.Release|Any CPU.Build.0 = Release|Any CPU
{EDA44AA3-CEAF-471F-8876-DFBDC5937318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDA44AA3-CEAF-471F-8876-DFBDC5937318}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDA44AA3-CEAF-471F-8876-DFBDC5937318}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDA44AA3-CEAF-471F-8876-DFBDC5937318}.Release|Any CPU.Build.0 = Release|Any CPU
{5F84DBF6-C2A6-495F-A5D5-5C75577E1C6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F84DBF6-C2A6-495F-A5D5-5C75577E1C6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F84DBF6-C2A6-495F-A5D5-5C75577E1C6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F84DBF6-C2A6-495F-A5D5-5C75577E1C6E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2659B23E-222F-4FE2-9424-023FD0C2A9C3}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions ViteDevelopmentServer.Demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vite/
9 changes: 9 additions & 0 deletions ViteDevelopmentServer.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using PrincipleStudios.ViteDevelopmentServer.Demo;

Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build()
.Run();
38 changes: 38 additions & 0 deletions ViteDevelopmentServer.Demo/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64422",
"sslPort": 44363
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5052",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7120;http://localhost:5052",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
38 changes: 38 additions & 0 deletions ViteDevelopmentServer.Demo/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.Extensions.Configuration;

namespace PrincipleStudios.ViteDevelopmentServer.Demo;

public class Startup
{
private readonly IWebHostEnvironment env;

public Startup(IWebHostEnvironment env)
{
this.env = env;
}


public void ConfigureServices(IServiceCollection services)
{
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ui/dist";
});
}

public void Configure(IApplicationBuilder app)
{
// Keep stray POSTs from hitting the SPA middleware
// Based on a comment in https://github.com/dotnet/aspnetcore/issues/5192
app.MapWhen(context => context.Request.Method == "GET" || context.Request.Method == "CONNECT", (when) =>
{
app.UseSpaStaticFiles();
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ui";

spa.UseViteDevelopmentServer("node_modules/.bin/vite", "--port {port}");
});
});
}
}
20 changes: 20 additions & 0 deletions ViteDevelopmentServer.Demo/ViteDevelopmentServer.Demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<RootNamespace>PrincipleStudios.ViteDevelopmentServer.Demo</RootNamespace>
<UiDir>$(ProjectDir)ui\</UiDir>
<NpmInstallRecordPath>$(UiDir)node_modules\_$(Configuration)._</NpmInstallRecordPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ViteDevelopmentServer\ViteDevelopmentServer.csproj" />
</ItemGroup>

<Target Name="NpmInstall" BeforeTargets="BeforeBuild" Inputs="$(UiDir)package.json;$(UiDir)package-lock.json" Outputs="$(NpmInstallRecordPath)">
<Exec WorkingDirectory="$(UiDir)" Condition=" $(Configuration) != 'Release' " Command="npm install" />
<Exec WorkingDirectory="$(UiDir)" Condition=" $(Configuration) == 'Release' " Command="npm ci" />
<!-- On either build, mark that it succeeded so it skips and goes fast next time... if there's no changes to package*.json -->
<Touch AlwaysCreate="true" ForceTouch="true" Files="$(NpmInstallRecordPath)" />
</Target>

</Project>
8 changes: 8 additions & 0 deletions ViteDevelopmentServer.Demo/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions ViteDevelopmentServer.Demo/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
18 changes: 18 additions & 0 deletions ViteDevelopmentServer.Demo/ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/white-book.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite Demo</title>
</head>
<body>
<div id="root"></div>
<script type="module">
import ReactDOM from 'react-dom/client'
import { AppElement } from './src/main.tsx'

ReactDOM.createRoot(document.getElementById('root')).render(AppElement);
</script>
</body>
</html>
Loading

0 comments on commit 39e4e98

Please sign in to comment.