-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild-ForBrowser.ps1
38 lines (31 loc) · 1.18 KB
/
Build-ForBrowser.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
param(
[string]$browser
)
# Create distribution folder
$distFolder = "dist/$browser"
if (Test-Path $distFolder) {
Remove-Item -Recurse -Force $distFolder
}
New-Item -ItemType Directory -Force -Path $distFolder
# Copy files except manifest.in.json
Get-ChildItem -Path 'src' -Exclude 'manifest.in.json' |
Copy-Item -Destination $distFolder -Recurse
$inputFile = 'src/manifest.in.json'
$processedLines = @()
$pattern = $browser
# Read each line from the input file
Get-Content $inputFile | ForEach-Object {
# Capture leading whitespace and line content separately
if ($_ -match "^(?<leadingWhitespace>\s*)//${pattern}:(?<content>.*)") {
# Append captured content with original leading whitespace
$processedLines += ($matches['leadingWhitespace'] + $matches['content'].Trim())
} elseif ($_ -notmatch "^\s*//.*:") {
# If line doesn't match any pattern, append as-is
$processedLines += $_
}
# Lines matching other patterns are skipped
}
# Write processed lines to output file
$processedLines | Out-File "${distfolder}/manifest.json"
# Zip the whole caboodle
Compress-Archive -Path "${distFolder}/*" -DestinationPath "dist/${browser}.zip" -Force