Skip to content

Commit afa0f82

Browse files
csharpfritzCopilot
andcommitted
fix(migration): Account route prefix and CSS bundle expansion
- ConvertFrom-PageDirective now uses RelPath for routes (Account/Login.aspx /Account/Login) - Add webopt:bundlereference expansion to extract all CSS from bundle folders - Add .map to StaticExtensions for source map copying Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d3ab609 commit afa0f82

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

migration-toolkit/scripts/bwfc-migrate.ps1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ $ErrorActionPreference = 'Stop'
6767

6868
$WebFormsExtensions = @('.aspx', '.ascx', '.master')
6969
$CodeBehindExtensions = @('.aspx.cs', '.ascx.cs', '.master.cs', '.aspx.vb', '.ascx.vb', '.master.vb')
70-
$StaticExtensions = @('.css', '.js', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.eot')
70+
$StaticExtensions = @('.css', '.js', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.eot', '.map')
7171

7272
# Attributes to strip completely (case-insensitive patterns)
7373
$StripAttributes = @(
@@ -270,13 +270,30 @@ function New-AppRazorScaffold {
270270

271271
$componentsDir = Join-Path $OutputRoot "Components"
272272

273-
# Extract <link> stylesheet tags from the source master page (Site.Master)
273+
# Extract <link> stylesheet tags and <webopt:bundlereference> from the source master page (Site.Master)
274274
$cssLinks = @()
275275
if ($SourceRoot -and (Test-Path $SourceRoot)) {
276276
$masterFiles = Get-ChildItem -Path $SourceRoot -Recurse -Filter '*.Master' -ErrorAction SilentlyContinue
277277
foreach ($masterFile in $masterFiles) {
278278
$masterContent = Get-Content -Path $masterFile.FullName -Raw -ErrorAction SilentlyContinue
279279
if ($masterContent) {
280+
# Handle <webopt:bundlereference> — expand to individual CSS links from the referenced folder
281+
$bundleRegex = [regex]'<webopt:bundlereference[^>]*\bpath\s*=\s*"([^"]+)"[^>]*/?\s*>'
282+
$bundleMatches = $bundleRegex.Matches($masterContent)
283+
foreach ($bm in $bundleMatches) {
284+
$bundlePath = $bm.Groups[1].Value -replace '^~/', ''
285+
$cssFolder = Join-Path $SourceRoot $bundlePath
286+
if (Test-Path $cssFolder) {
287+
$cssFiles = Get-ChildItem -Path $cssFolder -Filter '*.css' | Where-Object { $_.Name -notmatch '\.min\.css$' } | Sort-Object Name
288+
foreach ($cf in $cssFiles) {
289+
$cssHref = "/$bundlePath/$($cf.Name)" -replace '\\','/'
290+
$cssLinks += " <link href=`"$cssHref`" rel=`"stylesheet`" />"
291+
}
292+
Write-TransformLog -File $masterFile.Name -Transform 'BundleExpand' -Detail "Expanded bundlereference '$bundlePath' → $($cssFiles.Count) CSS file(s) for App.razor"
293+
}
294+
}
295+
296+
# Handle explicit <link rel="stylesheet"> tags
280297
$linkRegex = [regex]'<link\b[^>]*\brel\s*=\s*["\x27]stylesheet["\x27][^>]*/?\s*>'
281298
$linkMatches = $linkRegex.Matches($masterContent)
282299
foreach ($m in $linkMatches) {
@@ -287,8 +304,8 @@ function New-AppRazorScaffold {
287304
$link = $link -replace '\s+runat\s*=\s*"server"',''
288305
$cssLinks += " $link"
289306
}
290-
if ($linkMatches.Count -gt 0) {
291-
Write-TransformLog -File $masterFile.Name -Transform 'CssExtract' -Detail "Extracted $($linkMatches.Count) stylesheet link(s) from master page for App.razor"
307+
if ($linkMatches.Count -gt 0 -or $bundleMatches.Count -gt 0) {
308+
Write-TransformLog -File $masterFile.Name -Transform 'CssExtract' -Detail "Extracted $($linkMatches.Count) link(s) + $($bundleMatches.Count) bundle(s) from master page for App.razor"
292309
}
293310
}
294311
}
@@ -453,8 +470,9 @@ public class MockAuthenticationStateProvider : AuthenticationStateProvider
453470
function ConvertFrom-PageDirective {
454471
param([string]$Content, [string]$FileName, [string]$RelPath)
455472

456-
# <%@ Page ... %> → @page "/route"
457-
$route = '/' + [System.IO.Path]::GetFileNameWithoutExtension($FileName)
473+
# <%@ Page ... %> → @page "/route" (preserving folder structure)
474+
$routePath = ($RelPath -replace '\\', '/') -replace '\.(aspx|ascx)$', ''
475+
$route = '/' + $routePath
458476
if ($route -eq '/Default' -or $route -eq '/default' -or $route -eq '/Index' -or $route -eq '/index') {
459477
$route = '/'
460478
}

0 commit comments

Comments
 (0)