-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
68 lines (54 loc) · 2.3 KB
/
build.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
param (
[string]$browser = "chrome",
[string]$version = "3.0",
[switch]$commit = $false
)
# Set the permissions and version number
$manifestContent = Get-Content -Path "manifest.json" -Raw
if ($browser -Eq "chrome") {
$permissions = '"optional_permissions": ["favicon", "topSites"],'
} elseif ($browser -Eq "firefox") {
$permissions = '"permissions": ["topSites"], "browser_specific_settings": { "gecko": { "id": "splash-new-tab@fxzfun.com" } },'
}
$newManifestContent = $manifestContent -replace '"---PERMISSIONS---": {},', $permissions
$newManifestContent = $newManifestContent -replace '---VERSION---', $version
$newManifestContent | Set-Content -Path "manifest.json"
# Set the list of backgrounds in newtab.js
$backgrounds = Get-ChildItem -Path "backgrounds" -File | Select-Object -ExpandProperty Name
$jsonArray = $backgrounds | ConvertTo-Json
$newtabContent = Get-Content -Path "newtab.js" -Raw
$newContent = $newtabContent -replace '\["---BACKGROUNDS---"\]', $jsonArray
$newContent | Set-Content -Path "newtab.js"
# Create zip artifact
$sourceFolder = "../splash"
$destinationZip = "../splash/releases/splash-" + $version + "-" + $browser + ".zip"
$excludeFiles = @(".gitignore", "build.ps1")
$excludeFolders = @(".git", ".github", "releases")
if (Test-Path $sourceFolder) {
$tempFolder = Join-Path $env:TEMP ("TempZip" + [System.Guid]::NewGuid().ToString())
Copy-Item -Path $sourceFolder -Destination $tempFolder -Recurse -Force
foreach ($excludeFile in $excludeFiles) {
$excludePath = Join-Path $tempFolder $excludeFile
if (Test-Path $excludePath -PathType Leaf) {
Remove-Item $excludePath -Force
}
}
foreach ($excludeFolder in $excludeFolders) {
$excludePath = Join-Path $tempFolder $excludeFolder
if (Test-Path $excludePath -PathType Container) {
Remove-Item $excludePath -Recurse -Force
}
}
Compress-Archive -Path $tempFolder\* -DestinationPath $destinationZip -Force
Remove-Item $tempFolder -Recurse -Force
Write-Host "created zip release"
} else {
Write-Host "error: source folder does not exist"
}
# Update git repository
git restore manifest.json
git restore newtab.js
git add "releases/splash-$version-$browser.zip"
if ($commit) {
git commit -m "build release version $version for $browser"
}