Prepared tailwind system for plugin builds and exports via nuget. Removed obsolete old css bundling. Added helper scripts for building. Rewritten build scripts
This commit is contained in:
60
Resources/Scripts/Functions/ContentFunctions.cs
Normal file
60
Resources/Scripts/Functions/ContentFunctions.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Scripts.Functions;
|
||||
|
||||
public static class ContentFunctions
|
||||
{
|
||||
public static async Task Run(string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Please provide the path to a nuget file and at least one regex expression");
|
||||
return;
|
||||
}
|
||||
|
||||
var nugetPath = args[0];
|
||||
|
||||
var regexs = args
|
||||
.Skip(1)
|
||||
.Select(x => new Regex(x))
|
||||
.ToArray();
|
||||
|
||||
Console.WriteLine(string.Join(", ", args
|
||||
.Skip(1)
|
||||
.Select(x => new Regex(x))));
|
||||
|
||||
if (!File.Exists(nugetPath))
|
||||
{
|
||||
Console.WriteLine("The provided file does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Modding nuget package...");
|
||||
using var zipFile = ZipFile.Open(nugetPath, ZipArchiveMode.Update);
|
||||
|
||||
foreach (var zipArchiveEntry in zipFile.Entries)
|
||||
{
|
||||
Console.WriteLine(zipArchiveEntry.FullName);
|
||||
}
|
||||
|
||||
Console.WriteLine("Searching for files to remove");
|
||||
var files = zipFile.Entries
|
||||
.Where(x => x.FullName.Trim('/').StartsWith("content"))
|
||||
.Where(x =>
|
||||
{
|
||||
var name = x.FullName
|
||||
.Replace("contentFiles/", "")
|
||||
.Replace("content/", "");
|
||||
|
||||
Console.WriteLine(name);
|
||||
|
||||
return regexs.Any(y => y.IsMatch(name));
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
Console.WriteLine($"Found {files.Length} file(s) to remove");
|
||||
foreach (var file in files)
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
47
Resources/Scripts/Functions/SrcFunctions.cs
Normal file
47
Resources/Scripts/Functions/SrcFunctions.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace Scripts.Functions;
|
||||
|
||||
public static class SrcFunctions
|
||||
{
|
||||
public static async Task Run(string[] args)
|
||||
{
|
||||
if (args.Length != 3)
|
||||
{
|
||||
Console.WriteLine("Please provide the path to a nuget file, a search pattern and a path");
|
||||
return;
|
||||
}
|
||||
|
||||
var nugetPath = args[0];
|
||||
var path = args[1];
|
||||
var pattern = args[2];
|
||||
|
||||
if (!File.Exists(nugetPath))
|
||||
{
|
||||
Console.WriteLine("The provided file does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Modding nuget package...");
|
||||
using var zipFile = ZipFile.Open(nugetPath, ZipArchiveMode.Update);
|
||||
|
||||
var filesToAdd = Directory.GetFiles(path, pattern, SearchOption.AllDirectories);
|
||||
|
||||
foreach (var file in filesToAdd)
|
||||
{
|
||||
var name = file.Replace(path, "").Replace("\\", "/");
|
||||
|
||||
Console.WriteLine($"{file} => /src/{name}");
|
||||
|
||||
var entry = zipFile.CreateEntry($"src/{name}");
|
||||
await using var entryStream = entry.Open();
|
||||
|
||||
await using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
await fs.CopyToAsync(entryStream);
|
||||
fs.Close();
|
||||
|
||||
await entryStream.FlushAsync();
|
||||
entryStream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
93
Resources/Scripts/Functions/StaticWebAssetsFunctions.cs
Normal file
93
Resources/Scripts/Functions/StaticWebAssetsFunctions.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Scripts.Functions;
|
||||
|
||||
public static class StaticWebAssetsFunctions
|
||||
{
|
||||
public static async Task Run(string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Please provide the path to a nuget file and at least one regex expression");
|
||||
return;
|
||||
}
|
||||
|
||||
var nugetPath = args[0];
|
||||
|
||||
var regexs = args
|
||||
.Skip(1)
|
||||
.Select(x => new Regex(x))
|
||||
.ToArray();
|
||||
|
||||
if (!File.Exists(nugetPath))
|
||||
{
|
||||
Console.WriteLine("The provided file does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Modding nuget package...");
|
||||
using var zipFile = ZipFile.Open(nugetPath, ZipArchiveMode.Update);
|
||||
|
||||
Console.WriteLine("Searching for files to remove");
|
||||
var files = zipFile.Entries
|
||||
.Where(x => x.FullName.Trim('/').StartsWith("staticwebassets"))
|
||||
.Where(x =>
|
||||
{
|
||||
var name = x.FullName.Replace("staticwebassets/", "");
|
||||
|
||||
return regexs.Any(y => y.IsMatch(name));
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
Console.WriteLine($"Found {files.Length} file(s) to remove");
|
||||
foreach (var file in files)
|
||||
file.Delete();
|
||||
|
||||
Console.WriteLine("Modifying static web assets build target");
|
||||
var oldBuildTargetEntry = zipFile
|
||||
.Entries
|
||||
.FirstOrDefault(x => x.FullName == "build/Microsoft.AspNetCore.StaticWebAssets.props");
|
||||
|
||||
if (oldBuildTargetEntry == null)
|
||||
{
|
||||
Console.WriteLine("Build target file not found in nuget packages");
|
||||
return;
|
||||
}
|
||||
|
||||
await using var oldBuildTargetStream = oldBuildTargetEntry.Open();
|
||||
|
||||
var contentXml = await XDocument.LoadAsync(
|
||||
oldBuildTargetStream,
|
||||
LoadOptions.None,
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
oldBuildTargetStream.Close();
|
||||
oldBuildTargetEntry.Delete();
|
||||
|
||||
var assetRefsToRemove = contentXml
|
||||
.Descendants("StaticWebAsset")
|
||||
.Where(asset =>
|
||||
{
|
||||
var element = asset.Element("RelativePath");
|
||||
|
||||
if (element == null)
|
||||
return false;
|
||||
|
||||
return regexs.Any(y => y.IsMatch(element.Value));
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var asset in assetRefsToRemove)
|
||||
asset.Remove();
|
||||
|
||||
var newBuildTargetEntry = zipFile.CreateEntry("build/Microsoft.AspNetCore.StaticWebAssets.props");
|
||||
await using var newBuildTargetStream = newBuildTargetEntry.Open();
|
||||
|
||||
await contentXml.SaveAsync(newBuildTargetStream, SaveOptions.None, CancellationToken.None);
|
||||
|
||||
newBuildTargetStream.Close();
|
||||
}
|
||||
}
|
||||
26
Resources/Scripts/Program.cs
Normal file
26
Resources/Scripts/Program.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Scripts.Functions;
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.WriteLine("You need to specify a module to run");
|
||||
return;
|
||||
}
|
||||
|
||||
var module = args[0];
|
||||
var moduleArgs = args.Skip(1).ToArray();
|
||||
|
||||
switch (module)
|
||||
{
|
||||
case "staticWebAssets":
|
||||
await StaticWebAssetsFunctions.Run(moduleArgs);
|
||||
break;
|
||||
case "content":
|
||||
await ContentFunctions.Run(moduleArgs);
|
||||
break;
|
||||
case "src":
|
||||
await SrcFunctions.Run(moduleArgs);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"No module named {module} found");
|
||||
break;
|
||||
}
|
||||
10
Resources/Scripts/Scripts.csproj
Normal file
10
Resources/Scripts/Scripts.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,97 +0,0 @@
|
||||
# Set strict mode to stop on errors
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Ensure the script is running in the main directory
|
||||
Write-Host "Building nuget packages"
|
||||
|
||||
Write-Host "Searching & building project files"
|
||||
# Find all .csproj files recursively
|
||||
$projectFiles = Get-ChildItem -Recurse -Filter "*.csproj"
|
||||
|
||||
foreach ($project in $projectFiles) {
|
||||
# Extract project name (without extension)
|
||||
$projectName = $project.BaseName
|
||||
|
||||
# Extract version from the .csproj file
|
||||
$projectVersion = Select-String -Path $project.FullName -Pattern "<Version>(.*?)</Version>" | ForEach-Object {
|
||||
$_.Matches.Groups[1].Value
|
||||
}
|
||||
|
||||
if (-not $projectVersion) {
|
||||
Write-Host "No <Version> tag found in $($project.FullName), skipping."
|
||||
continue
|
||||
}
|
||||
|
||||
# Build and pack the project
|
||||
$projectPath = $project.DirectoryName
|
||||
$pwd = (Get-Location).Path
|
||||
Push-Location $projectPath
|
||||
dotnet build --configuration Release
|
||||
dotnet pack --configuration Release --output "$pwd\nupkgs"
|
||||
Pop-Location
|
||||
|
||||
# Modifying the NuGet package
|
||||
Write-Host "Modding nuget package"
|
||||
$nugetPackage = Get-ChildItem "$pwd\nupkgs" -Filter "*.nupkg" | Select-Object -First 1
|
||||
|
||||
# Rename .nupkg to .zip
|
||||
$zipPackage = "$($nugetPackage.FullName).zip"
|
||||
Rename-Item -Path $nugetPackage.FullName -NewName $zipPackage
|
||||
|
||||
Expand-Archive -Path $zipPackage -DestinationPath "$pwd\nupkgs\mod" -Force
|
||||
|
||||
if ($projectName -eq "Moonlight.ApiServer") {
|
||||
Remove-Item "$pwd\nupkgs\mod\content" -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item "$pwd\nupkgs\mod\contentFiles" -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
$xmlFilePath = "$pwd\nupkgs\mod\$projectName.nuspec"
|
||||
$xmlContent = Get-Content -Path $xmlFilePath -Raw
|
||||
$regexPattern = '<contentFiles\b[^>]*>[\s\S]*?<\/contentFiles>'
|
||||
|
||||
$updatedContent = [System.Text.RegularExpressions.Regex]::Replace(
|
||||
$xmlContent,
|
||||
$regexPattern,
|
||||
"",
|
||||
[System.Text.RegularExpressions.RegexOptions]::IgnoreCase
|
||||
)
|
||||
|
||||
Set-Content -Path $xmlFilePath -Value $updatedContent -Encoding UTF8
|
||||
}
|
||||
|
||||
if ($projectName -eq "Moonlight.Client") {
|
||||
Remove-Item "$pwd\nupkgs\mod\staticwebassets\_framework" -Recurse -Force
|
||||
|
||||
$xmlFilePath = "$pwd\nupkgs\mod\build\Microsoft.AspNetCore.StaticWebAssets.props"
|
||||
$xmlContent = Get-Content -Path $xmlFilePath -Raw
|
||||
|
||||
$regexPattern = '<StaticWebAsset\b[^>]*>(?:(?!<\/StaticWebAsset>).)*?<RelativePath>_framework/blazor\.webassembly\.js(?:\.gz)?<\/RelativePath>.*?<\/StaticWebAsset>'
|
||||
|
||||
$updatedContent = [System.Text.RegularExpressions.Regex]::Replace(
|
||||
$xmlContent,
|
||||
$regexPattern,
|
||||
"",
|
||||
[System.Text.RegularExpressions.RegexOptions]::Singleline
|
||||
)
|
||||
|
||||
Set-Content -Path $xmlFilePath -Value $updatedContent -Encoding UTF8
|
||||
}
|
||||
|
||||
# Repack the modified NuGet package
|
||||
Write-Host "Repacking nuget package"
|
||||
Remove-Item $zipPackage
|
||||
Push-Location "$pwd\nupkgs\mod"
|
||||
Compress-Archive -Path * -DestinationPath $zipPackage -Force
|
||||
Pop-Location
|
||||
|
||||
# Rename .zip back to .nupkg
|
||||
Rename-Item -Path $zipPackage -NewName $nugetPackage.FullName
|
||||
|
||||
# Move the final package to the output directory
|
||||
$finalDir = "$pwd\finalPackages"
|
||||
New-Item -ItemType Directory -Path $finalDir -Force | Out-Null
|
||||
Move-Item -Path $nugetPackage.FullName -Destination $finalDir
|
||||
|
||||
# Cleanup
|
||||
Write-Host "Cleaning up"
|
||||
Remove-Item "$pwd\nupkgs\mod" -Recurse -Force
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Note: Run in main directory, i.e. where the Moonlight.sln is
|
||||
|
||||
echo "Building nuget packages"
|
||||
|
||||
echo "Searching & building project files"
|
||||
project_files=$(find . -name "*.csproj")
|
||||
|
||||
for project in $project_files; do
|
||||
# Extract project name
|
||||
project_name=$(basename "$project" .csproj)
|
||||
|
||||
# Extract version
|
||||
project_version=$(grep -oPm1 "(?<=<Version>)[^<]+" "$project")
|
||||
if [ -z "$project_version" ]; then
|
||||
echo "No <Version> tag found in $project, skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Building nuget package
|
||||
pwd=$(pwd)
|
||||
project_path=$(dirname $project)
|
||||
(cd $project_path; dotnet build --configuration Release; dotnet pack --configuration Release --output $pwd/nupkgs)
|
||||
|
||||
# Mod nuget package
|
||||
echo "Modding nuget package"
|
||||
nugetPackage=$(find $pwd/nupkgs -name "*.nupkg")
|
||||
|
||||
unzip -o $nugetPackage -d $pwd/nupkgs/mod
|
||||
|
||||
if [ "$project_name" = "Moonlight.ApiServer" ]; then
|
||||
rm -r $pwd/nupkgs/mod/content
|
||||
rm -r $pwd/nupkgs/mod/contentFiles
|
||||
|
||||
sed -i "/<contentFiles>/,/<\/contentFiles>/d" $pwd/nupkgs/mod/Moonlight.ApiServer.nuspec
|
||||
fi
|
||||
|
||||
if [ "$project_name" = "Moonlight.Client" ]; then
|
||||
rm -r $pwd/nupkgs/mod/staticwebassets/_framework
|
||||
|
||||
sed -i '/<StaticWebAsset Include=.*blazor.webassembly.js.gz.*>/,/<\/StaticWebAsset>/d' $pwd/nupkgs/mod/build/Microsoft.AspNetCore.StaticWebAssets.props
|
||||
sed -i '/<StaticWebAsset Include=.*blazor.webassembly.js.*>/,/<\/StaticWebAsset>/d' $pwd/nupkgs/mod/build/Microsoft.AspNetCore.StaticWebAssets.props
|
||||
|
||||
fi
|
||||
|
||||
echo "Repacking nuget package"
|
||||
rm $nugetPackage
|
||||
(cd nupkgs/mod/; zip -r -o $nugetPackage *)
|
||||
|
||||
mkdir -p $pwd/finalPackages/
|
||||
|
||||
mv $nugetPackage $pwd/finalPackages/
|
||||
|
||||
echo "Cleaning up"
|
||||
rm -r $pwd/nupkgs/mod
|
||||
done
|
||||
25
Resources/Scripts/generateNuget.sh
Normal file
25
Resources/Scripts/generateNuget.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# We are building the packages in the debug mode because they are meant for development
|
||||
# purposes only. When build for production, release builds will be used ofc
|
||||
|
||||
set -e
|
||||
|
||||
echo "Creating nuget packages"
|
||||
mkdir -p finalPackages
|
||||
|
||||
echo "+ ApiServer Server"
|
||||
dotnet build -c Debug Moonlight.ApiServer
|
||||
dotnet pack -c Debug Moonlight.ApiServer --output finalPackages/
|
||||
dotnet run --project Resources/Scripts/Scripts.csproj content finalPackages/Moonlight.ApiServer.2.1.0.nupkg ".*"
|
||||
|
||||
echo "+ Client"
|
||||
dotnet build -c Debug Moonlight.Client
|
||||
dotnet pack -c Debug Moonlight.Client --output finalPackages/
|
||||
dotnet run --project Resources/Scripts/Scripts.csproj staticWebAssets finalPackages/Moonlight.Client.2.1.0.nupkg "_framework\/.*" style.min.css
|
||||
dotnet run --project Resources/Scripts/Scripts.csproj src finalPackages/Moonlight.Client.2.1.0.nupkg Moonlight.Client/ *.razor
|
||||
dotnet run --project Resources/Scripts/Scripts.csproj src finalPackages/Moonlight.Client.2.1.0.nupkg Moonlight.Client/ wwwroot/*.html
|
||||
|
||||
echo "+ Shared library"
|
||||
dotnet build -c Debug Moonlight.Shared
|
||||
dotnet pack -c Debug Moonlight.Shared --output finalPackages/
|
||||
@@ -1,66 +0,0 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
// Handle arguments
|
||||
if (Args.Count != 1)
|
||||
{
|
||||
Console.WriteLine("You need to provide the path to a nuget file as a parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
var nugetPath = Args[0];
|
||||
|
||||
// Check if file exists
|
||||
if (!File.Exists(nugetPath))
|
||||
{
|
||||
Console.WriteLine("The provided file does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
// Open file to modify
|
||||
Console.WriteLine($"Modding nuget package: {nugetPath}");
|
||||
var zipFile = ZipFile.Open(nugetPath, ZipArchiveMode.Update, Encoding.UTF8);
|
||||
|
||||
// First we want to remove the framework files
|
||||
Console.WriteLine("Removing framework files");
|
||||
|
||||
var frameworkEntries = zipFile.Entries
|
||||
.Where(x => x.FullName.Contains("staticwebassets/_framework"))
|
||||
.ToArray();
|
||||
|
||||
foreach (var frameworkEntry in frameworkEntries)
|
||||
frameworkEntry.Delete();
|
||||
|
||||
// Then we want to modify the build targets for static web assets
|
||||
var oldBuildTarget = zipFile.Entries
|
||||
.First(x => x.FullName == "build/Microsoft.AspNetCore.StaticWebAssets.props");
|
||||
|
||||
// Load old content
|
||||
var oldContentStream = oldBuildTarget.Open();
|
||||
|
||||
// Parse xml and remove framework references
|
||||
Console.WriteLine("Removing framework web asset references");
|
||||
|
||||
var contentXml = XDocument.Load(oldContentStream);
|
||||
oldContentStream.Close();
|
||||
oldContentStream.Dispose();
|
||||
oldBuildTarget.Delete();
|
||||
|
||||
var assetsToRemove = contentXml
|
||||
.Descendants("StaticWebAsset")
|
||||
.Where(asset =>
|
||||
asset.Element("RelativePath")?.Value.Contains("_framework") == true)
|
||||
.ToArray();
|
||||
|
||||
foreach (var asset in assetsToRemove)
|
||||
asset.Remove();
|
||||
|
||||
var newBuildTarget = zipFile.CreateEntry("build/Microsoft.AspNetCore.StaticWebAssets.props");
|
||||
var newContentStream = newBuildTarget.Open();
|
||||
contentXml.Save(newContentStream);
|
||||
|
||||
await newContentStream.FlushAsync();
|
||||
newContentStream.Close();
|
||||
|
||||
zipFile.Dispose();
|
||||
@@ -1,15 +0,0 @@
|
||||
# This script requires a NuGet override folder at %userprofile%\NugetOverride
|
||||
|
||||
# Clear old build cache
|
||||
Remove-Item -Recurse -Force nupkgs, finalPackages
|
||||
|
||||
# Build and replace NuGet packages
|
||||
& "Resources\Scripts\buildNuget.ps1"
|
||||
Copy-Item -Path finalPackages\* -Destination $env:userprofile\NugetOverride -Force
|
||||
|
||||
# Clean package cache
|
||||
Remove-Item -Recurse -Force $env:userprofile\.nuget\packages\moonlight.apiserver
|
||||
Remove-Item -Recurse -Force $env:userprofile\.nuget\packages\moonlight.shared
|
||||
Remove-Item -Recurse -Force $env:userprofile\.nuget\packages\moonlight.client
|
||||
|
||||
Write-Output "Done :>"
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script required a nuget override folder at ~/NugetOverride
|
||||
|
||||
# Clear old build cache
|
||||
rm -rf nupkgs/ finalPackages/
|
||||
|
||||
# Build and replace nuget packages
|
||||
bash Resources/Scripts/buildNuget.sh
|
||||
cp finalPackages/* ~/NugetOverride/
|
||||
|
||||
# Clean package cache
|
||||
rm -rf ~/.nuget/packages/moonlight.apiserver/
|
||||
rm -rf ~/.nuget/packages/moonlight.shared/
|
||||
rm -rf ~/.nuget/packages/moonlight.client/
|
||||
|
||||
echo "Done :>"
|
||||
7
Resources/Scripts/prepareNugetOverride.sh
Normal file
7
Resources/Scripts/prepareNugetOverride.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
bash Resources/Scripts/generateNuget.sh
|
||||
|
||||
echo "+ Copying to nuget override"
|
||||
cp finalPackages/*.nupkg ~/NugetOverride/
|
||||
rm -r ~/.nuget/packages/moonlight.*
|
||||
Reference in New Issue
Block a user