kiwix-js-pwa/scripts/Build-NWJS.ps1
Jaifroid be06ec252f Update release scripts
Former-commit-id: 2ba5ece9f4f261b1e97a5a4c22983c6513699c85 [formerly 8d32c176358fbdd0a425c50ce0a5aca4fbb556b8 [formerly 1b93af875187de579ae039876714833dd4ba03d7]]
Former-commit-id: 681fa8171260aec160fcfa5a70aea48da4bf9621
Former-commit-id: 486c431921735463bc73b3aa94c80968d5facc4a
2021-04-14 07:51:36 +01:00

72 lines
2.9 KiB
PowerShell

$builds = @("win-x64", "win-ia32", "win-xp")
$version = "0.52.2"
$versionXP = "0.14.7"
$appBuild = "1.2.4N"
$ZIMbase = "wikipedia_en_100_maxi"
cd $PSScriptRoot
cd ..
foreach ($build in $builds) {
"Building $build $version..."
$OBuild = $build
$sep = '-'
if ($build -eq "win-xp") {
$build = "win-ia32"
$version = $versionXP
$sep = '-XP-'
}
$folderTarget = "bld\nwjs\$build-$version"
$target = "$folderTarget\kiwix_js_windows$sep$appBuild"
$fullTarget = "$target-$build"
$ZipLocation = "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 = ".\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"
}