kiwix-js-pwa/scripts/Build-NWJS.ps1
Jaifroid d3b0bdca05 Don't change working directory
Former-commit-id: df69dfc2a223cb26a864ebd972dcddbd386ed3fa [formerly 928904ff43a037ae582542b929071ec9ea8f93fa] [formerly d3bf39642520b696e4f419a71326e5008e10a21a] [formerly 555a8f23ecb7b28e71778de7f4c19d721c9c467d [formerly 0b67c2af1c74af54cb4a5aeca9348b7529a0825d [formerly ce22482c1ad912c98d3f056ddd127aaada149263]]]
Former-commit-id: 641fa88d4734f7e9c68a4c57949896262f75f2fc [formerly cd5564faf1552c0dbb721700697042ee137099fa [formerly 149d33d7092bb1d80b7bc1551a4232dddf6719e1]]
Former-commit-id: 563a3cb0ca11aad469a1a4c93d7441ec6ce02665 [formerly 389848b8638d038ac66d815f5efd9acff4310e2f]
Former-commit-id: c71441688fa4abbdb2921e7af046780b928fd4b2
2021-05-20 17:58:55 +01:00

80 lines
3.3 KiB
PowerShell

param (
[switch]$32bitonly = $false
)
$builds = @("win-ia32", "win-xp")
if (-Not $32bitonly) {
$builds += "win-x64"
"Caller requested 32bit and 64bit build"
} else {
"Caller requested 32bitonly build"
}
$version = "0.53.1" # <<< value updated automatically from package.json if launched from Create-DraftRelease
$versionXP = "0.14.7"
$appBuild = "1.3.0N" # <<< value updated auotmatically from package.json if launched form Create-DraftRelease
$ZIMbase = "wikipedia_en_100_maxi"
foreach ($build in $builds) {
$OBuild = $build
$sep = '-'
if ($build -eq "win-xp") {
$build = "win-ia32"
$version = $versionXP
$sep = '-XP-'
}
"`nBuilding $build $version..."
$folderTarget = "$PSScriptRoot\..\bld\nwjs\$build-$version"
$target = "$folderTarget\kiwix_js_windows$sep$appBuild"
$fullTarget = "$target-$build"
$ZipLocation = "$PSScriptRoot\..\node_modules\nwjs-builder-phoenix\caches\nwjs-v$version-$build.zip"
$UnzipLocation = "$ZipLocation-extracted\"
$buildLocation = "$ZipLocation-extracted\nwjs-v$version-$build\"
if (-Not (Test-Path $buildLocation -PathType Container)) {
# We need to download and/or unzip the release, as it is not available
if (-Not (Test-Path $ZipLocation -PathType Leaf)) {
$serverFile = "https://dl.nwjs.io/v$version/nwjs-v$version-$build.zip"
"Downloading $serverFile"
Invoke-WebRequest -Uri $serverFile -OutFile $ZipLocation
}
"Unzipping archive $ZipLocation"
Expand-Archive $ZipLocation $UnzipLocation
if (-Not (Test-Path $buildLocation -PathType Container)) {
"There was an error! The unzipped folder $buildLocation could not be found!"
return
}
}
$archiveFolder = "$fullTarget\archives"
if (Test-Path $folderTarget -PathType Container) {
"Removing directory $folderTarget..."
rm $folderTarget\* -Recurse
rm $folderTarget
}
md $fullTarget
# Copy latest binary x64
cp $buildLocation\* $fullTarget -Recurse
cp .\package.json, .\pwabuilder-sw.js, .\index.html, .\CHANGELOG.md, .\LICENSE, .\www $fullTarget -Recurse
"Copying archive..."
md $archiveFolder
cp "archives\$ZIMbase*.*", "archives\README.md" $archiveFolder
"Creating launchers..."
$launcherStub = $PSScriptRoot -replace 'scripts.*$', "bld\nwjs\$build-$version\Start Kiwix JS Windows"
$foldername = "kiwix_js_windows$sep$appBuild-$build"
# Batch file
$batch = '@cd "' + $foldername + '"' + "`r`n" + '@start "Kiwix JS Windows" "nw.exe"' + "`r`n"
$batch > "$launcherStub.bat"
# Shortcut
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$launcherStub.lnk")
$Shortcut.TargetPath = '%windir%\explorer.exe'
$Shortcut.Arguments = "$foldername\nw.exe"
$Shortcut.IconLocation = '%windir%\explorer.exe,12'
$Shortcut.Save()
# Zip everything up
$ZipBuild = "bld\nwjs\$foldername.zip"
if (Test-Path $ZipBuild -PathType Leaf) {
"Deleting old Zip build $ZipBuild..."
del $ZipBuild
}
"Compressing folder..."
Compress-Archive "bld\nwjs\$build-$version\*" "bld\nwjs\$foldername.zip" -Force
"Build $OBuild finished.`n"
}