Skip to content

Commit 2047ded

Browse files
authored
Add PublishDemoLocally script (#4277)
1 parent 66dd5da commit 2047ded

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

_PublishDemoLocally.ps1

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env pwsh
2+
3+
# Ask user for configuration
4+
Write-Host "👉 Configuration setup..." -ForegroundColor Cyan
5+
Write-Host ""
6+
7+
# Ask for .NET version
8+
$dotnetVersionChoice = Read-Host "❓ Which .NET version do you want to use? (9 for net9.0, 10 for net10.0) [default: 9]"
9+
if ($dotnetVersionChoice -eq "" -or $dotnetVersionChoice -eq "9") {
10+
$dotnetVersion = "net9.0"
11+
} elseif ($dotnetVersionChoice -eq "10") {
12+
$dotnetVersion = "net10.0"
13+
} else {
14+
Write-Host "⛔ Invalid choice." -ForegroundColor Red
15+
exit 1
16+
}
17+
18+
# Ask for build number
19+
$buildNumber = Read-Host "❓ What is the BuildNumber version to use? (e.g., 4.13.0)"
20+
if ([string]::IsNullOrWhiteSpace($buildNumber)) {
21+
Write-Host "⛔ Build number cannot be empty." -ForegroundColor Red
22+
exit 1
23+
}
24+
25+
Write-Host ""
26+
Write-Host "Configuration:" -ForegroundColor Green
27+
Write-Host " .NET Version: $dotnetVersion" -ForegroundColor White
28+
Write-Host " Build Number: $buildNumber" -ForegroundColor White
29+
Write-Host ""
30+
31+
# Clean previous build artifacts
32+
Write-Host "👉 Cleaning previous build artifacts (bin and obj)..." -ForegroundColor Yellow
33+
34+
if (Test-Path "./examples/Demo/Client/bin") {
35+
Remove-Item -Path "./examples/Demo/Client/bin" -Recurse -Force
36+
}
37+
38+
if (Test-Path "./examples/Demo/Client/obj") {
39+
Remove-Item -Path "./examples/Demo/Client/obj" -Recurse -Force
40+
}
41+
42+
if (Test-Path "./src/Core/bin/") {
43+
Remove-Item -Path "./src/Core/bin" -Recurse -Force
44+
}
45+
46+
if (Test-Path "./src/Core/obj/") {
47+
Remove-Item -Path "./src/Core/obj" -Recurse -Force
48+
}
49+
50+
if (Test-Path "./src/Extensions/DesignToken.Generator/bin/") {
51+
Remove-Item -Path "./src/Extensions/DesignToken.Generator/bin" -Recurse -Force
52+
}
53+
54+
if (Test-Path "./src/Extensions/DesignToken.Generator/obj/") {
55+
Remove-Item -Path "./src/Extensions/DesignToken.Generator/obj" -Recurse -Force
56+
}
57+
58+
# Publish the demo
59+
Write-Host "👉 Publishing demo..." -ForegroundColor Yellow
60+
dotnet publish "./examples/Demo/Client/FluentUI.Demo.Client.csproj" -c Release -o "./examples/Demo/Client/bin/Publish" -f $dotnetVersion -r linux-x64 --self-contained=true -p:BuildNumber=$buildNumber
61+
62+
# Verify that the bundle JS file has the expected size
63+
Write-Host "👉 Verifying bundle JS file size..." -ForegroundColor Yellow
64+
$bundleFilePath = "./examples/Demo/Client/bin/Publish/wwwroot/_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js.br"
65+
66+
if (Test-Path $bundleFilePath) {
67+
$fileSize = (Get-Item $bundleFilePath).Length
68+
$fileSizeKB = [math]::Round($fileSize / 1024, 2)
69+
70+
if ($fileSize -gt 1024) {
71+
Write-Host "☑️ Bundle JS file verified: $fileSizeKB KB" -ForegroundColor Green
72+
} else {
73+
Write-Host "⛔ Bundle JS file is too small: $fileSizeKB KB (expected > 1KB)" -ForegroundColor Red
74+
Write-Host "⛔ This may indicate a build issue with the JS bundle generation." -ForegroundColor Red
75+
Write-Host "⛔ Install .NET 9.0.205 SDK, remove the references to 'net10' and add a `global.json` file with `{ ""sdk"": { ""version"": ""9.0.205"" } }`." -ForegroundColor Red
76+
exit 1
77+
}
78+
} else {
79+
Write-Host "⛔ Bundle JS file not found: $bundleFilePath" -ForegroundColor Red
80+
Write-Host "⛔ This may indicate a build issue with the JS bundle generation." -ForegroundColor Red
81+
exit 1
82+
}
83+
84+
Write-Host "✅ Demo publish process completed successfully!" -ForegroundColor Green
85+
86+
Write-Host "👉 You can deploy to Azure using a command like:" -ForegroundColor Green
87+
Write-Host "▶️ swa deploy --output-location ./examples/Demo/Client/bin/Publish/wwwroot --env production --deployment-token <TOKEN>" -ForegroundColor Green
88+
89+
# Ask user if they want to run the website
90+
# Require 'dotnet tool install --global dotnet-serve'
91+
Write-Host ""
92+
$runWebsite = Read-Host "Do you want to run the local website now? (Y/n) ... using `dotnet serve` "
93+
if ($runWebsite -eq "" -or $runWebsite -eq "Y" -or $runWebsite -eq "y") {
94+
Write-Host "👉 Starting the website..." -ForegroundColor Green
95+
dotnet serve --directory "./examples/Demo/Client/bin/Publish/wwwroot" --brotli --gzip --open-browser
96+
}

0 commit comments

Comments
 (0)