mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 11:48:26 -04:00
Delete repeated code
Former-commit-id: 3fa8a721f5f332b8f7e20a274c46626e19a5cb73 [formerly 22b9bec19fa10bbcd11ec92052b0bf0b210ef4ba] [formerly 88318511d3d079fcf41be5a0edcb1b7735f67fcb] [formerly 19a8b23691f0e9a8a66d394138b1e016b43e68ab [formerly 7d6f7d81c71d82e5e311922404dd52cd9fb94078 [formerly ccd79b2fd5a6314261a1dfd1e58b3bdc6bf4891f]]] Former-commit-id: d20c3efcf1daf68977e2a1e76845ce5928233435 [formerly 6cf6a4df0b1b77fe4588a77b37e7e81346abdce8 [formerly 4a5f332cb30f2f6a9a1415af18370949636c29a6]] Former-commit-id: 921aa3ed2b817d7bfe1b5d190dbdb123e1c19a32 [formerly 10f50cd291a9d59ad4c9f1bc5a7008fce4be06ea] Former-commit-id: 43448b40430e96ed0cc7fcafeb23c1c42eab3ab1
This commit is contained in:
parent
6fab12adb8
commit
8e41af2c82
@ -1,4 +1,5 @@
|
||||
# This script is intended to be run by Create-DraftRelease
|
||||
# This script is intended to be run by Create-DraftRelease, and must be dot-sourced (run with `. ./Build-Electron.ps1`)
|
||||
# because it modifies variables needed in Create-DraftRelease
|
||||
$base_dir = "$PSScriptRoot/../bld/electron/"
|
||||
$comp_electron_archive = $base_dir + "Kiwix.JS.$text_tag.$base_tag.zip"
|
||||
# Package installer electron app for Windows
|
||||
@ -142,151 +143,4 @@ if ($old_windows_support) {
|
||||
"NWJS packages found."
|
||||
$found = $true
|
||||
}
|
||||
}
|
||||
$base_dir = "$PSScriptRoot/../bld/electron/"
|
||||
$comp_electron_archive = $base_dir + "Kiwix.JS.$text_tag.$base_tag.zip"
|
||||
# Package installer electron app for Windows
|
||||
"`nChecking for installer package for Windows..."
|
||||
$alt_tag = $text_tag -ireplace 'Windows', 'PWA'
|
||||
$WinInstaller = $base_dir + "Kiwix JS $alt_tag Setup $numeric_tag-E.exe"
|
||||
if ($alt_tag -imatch 'WikiMed|Wikivoyage') {
|
||||
$WinInstaller = $base_dir + "$alt_tag by Kiwix Setup $numeric_tag-E.exe"
|
||||
}
|
||||
if (-Not (Test-Path $WinInstaller -PathType Leaf)) {
|
||||
"No package found: building $WinInstaller..."
|
||||
if (-Not $dryrun) {
|
||||
npm run dist-win
|
||||
if (Test-Path $WinInstaller -PathType Leaf) {
|
||||
"Successfully built."
|
||||
} else {
|
||||
"Oh no! The Windows installer build failed!"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
"Package found."
|
||||
}
|
||||
if (-Not ($old_windows_support -or (Test-Path $comp_electron_archive -PathType Leaf))) {
|
||||
# Package portable electron app for Windows
|
||||
"Building portable Electron app for Windows"
|
||||
# Line below uses electron-packager, but not necessary if we run the setup version first above
|
||||
# if (-Not $dryrun) { npm run package-win }
|
||||
"Compressing release package for Electron..."
|
||||
$unpacked_folder = $base_dir + "win-ia32-unpacked"
|
||||
$foldername = "kiwix-js-windows-win32-ia32"
|
||||
$compressed_assets_dir = $base_dir + $foldername
|
||||
# Find the executable filename in the folder
|
||||
$executable = (ls "$unpacked_folder/*.exe") -replace '^.*[/\\]([^/\\]+)$', '$1'
|
||||
"Processing executable: $executable"
|
||||
# Rename the compressed assets folder
|
||||
if (-Not $dryrun) {
|
||||
if (Test-Path $compressed_assets_dir -PathType Container) {
|
||||
rm -r $compressed_assets_dir
|
||||
}
|
||||
# PowerShell bug: you have to make the directory before you can cleanly copy another folder's contents into it!
|
||||
mkdir $compressed_assets_dir
|
||||
cp -r "$unpacked_folder\*" $compressed_assets_dir
|
||||
}
|
||||
$comp_electron_archive = $base_dir + "Kiwix.JS.$text_tag.$base_tag.zip"
|
||||
"Creating launchers..."
|
||||
$launcherStub = "$base_dir\Start Kiwix JS $text_tag"
|
||||
# Batch file
|
||||
$batch = '@cd "' + $foldername + '"' + "`r`n" + '@start "Kiwix JS ' + $text_tag + '" "' + $executable + '"' + "`r`n"
|
||||
if (-Not $dryrun) {
|
||||
$batch > "$launcherStub.bat"
|
||||
# Shortcut
|
||||
$WshShell = New-Object -ComObject WScript.Shell
|
||||
$Shortcut = $WshShell.CreateShortcut("$launcherStub.lnk")
|
||||
$Shortcut.TargetPath = '%windir%\explorer.exe'
|
||||
$Shortcut.Arguments = "$foldername\$executable"
|
||||
$Shortcut.IconLocation = '%windir%\explorer.exe,12'
|
||||
$Shortcut.Save()
|
||||
} else {
|
||||
"Would have written batch file:"
|
||||
"$batch"
|
||||
}
|
||||
$AddAppPackage = $base_dir + "Start*$text_tag.*"
|
||||
"Compressing: $AddAppPackage, $compressed_assets_dir to $comp_electron_archive"
|
||||
if (-Not $dryrun) { "$AddAppPackage", "$compressed_assets_dir" | Compress-Archive -DestinationPath $comp_electron_archive -Force }
|
||||
}
|
||||
# Package Electron app for Linux
|
||||
"`nChecking for Electron packages for Linux..."
|
||||
$LinuxBasePackage = $base_dir + "Kiwix JS $alt_tag-$numeric_tag-E"
|
||||
if ($alt_tag -imatch 'Wikivoyage|WikiMed') {
|
||||
$LinuxBasePackage = $base_dir + "$alt_tag by Kiwix-$numeric_tag-E"
|
||||
}
|
||||
$DebBasePackage = $base_dir + $package_name + "_$numeric_tag-E"
|
||||
$AppImageArchives = @("$LinuxBasePackage.AppImage", ($LinuxBasePackage + "-i386.AppImage"),
|
||||
("$DebBasePackage" + "_i386.deb"), ("$DebBasePackage" + "_amd64.deb"))
|
||||
"Processing $AppImageArchives"
|
||||
foreach ($AppImageArchive in $AppImageArchives) {
|
||||
if (-Not (Test-Path $AppImageArchive -PathType Leaf)) {
|
||||
"No packages found: building $AppImageArchive..."
|
||||
if (-Not $dryrun) {
|
||||
# To get docker to start, you might need to run below commands as admin
|
||||
# net stop com.docker.service
|
||||
# taskkill /IM "Docker Desktop.exe" /F
|
||||
# net start com.docker.service
|
||||
# runas /noprofile /user:Administrator "net stop com.docker.service; taskkill /IM 'Docker Desktop.exe' /F; net start com.docker.service"
|
||||
$repo_dir = ($PSScriptRoot -replace '[\\/]scripts[\\/]*$', '')
|
||||
"Using docker command:"
|
||||
"docker run -v $repo_dir\:/project -w /project electronuserland/builder npm run dist-linux"
|
||||
docker run -v $repo_dir\:/project -w /project electronuserland/builder npm run dist-linux
|
||||
# Alternatively build with wsl
|
||||
# wsl . ~/.bashrc; npm run dist-linux
|
||||
# docker $build_command
|
||||
}
|
||||
} else {
|
||||
"Linux Electron package $AppImageArchive is available"
|
||||
}
|
||||
}
|
||||
if ($old_windows_support) {
|
||||
"`nSupport for XP and Vista was requested."
|
||||
"Searching for archives..."
|
||||
$nwjs_base = $PSScriptRoot -ireplace 'kiwix-js-windows.scripts.*$', 'kiwix-js-windows-nwjs'
|
||||
"NWJS base directory: " + $nwjs_base
|
||||
$nwjs_archives_path = "$nwjs_base/bld/nwjs/kiwix_js_windows*$numeric_tag" + "N-win-ia32.zip"
|
||||
"NWJS archives path: " + $nwjs_archives_path
|
||||
$nwjs_archives = dir $nwjs_archives_path
|
||||
if (-Not ($nwjs_archives.count -eq 2)) {
|
||||
"`nBuilding portable 32bit NWJS archives to add to Electron release for XP and Vista..."
|
||||
"Updating Build-NWJS script with required tags..."
|
||||
$nw_json = Get-Content -Raw "$nwjs_base/package.json"
|
||||
$script_body = Get-Content -Raw ("$nwjs_base/scripts/Build-NWJS.ps1")
|
||||
$json_nwVersion = ''
|
||||
if ($nw_json -match '"build":\s*\{[^"]*"nwVersion":\s*"([^"]+)') {
|
||||
$json_nwVersion = $matches[1]
|
||||
}
|
||||
if ($json_nwVersion) {
|
||||
"Updating Build-NWJS with NWJS version from package.json: $json_nwVersion"
|
||||
$script_body = $script_body -ireplace '(\$version10\s*=\s*")[^"]+', "`${1}$json_nwVersion"
|
||||
}
|
||||
$script_body = $script_body -ireplace '(appBuild\s*=\s*")[^"]+', ("`${1}$numeric_tag" + "N")
|
||||
$script_body = $script_body -replace '\s+$', "`n"
|
||||
if ($dryrun) {
|
||||
"[DRYRUN] would have written:`n"
|
||||
$script_body
|
||||
} else {
|
||||
Set-Content "$nwjs_base/scripts/Build-NWJS.ps1" $script_body
|
||||
}
|
||||
if (-Not $dryrun) {
|
||||
"Building..."
|
||||
& $nwjs_base/scripts/Build-NWJS.ps1 -only32bit
|
||||
} else {
|
||||
"Build command: $nwjs_base/scripts/Build-NWJS.ps1 -only32bit"
|
||||
}
|
||||
"Verifying build..."
|
||||
$nwjs_archives = dir $nwjs_archives_path
|
||||
if ($nwjs_archives.count -eq 2) {
|
||||
"NWJS packages were correclty built."
|
||||
$found = $true
|
||||
} else {
|
||||
"Oh no! The NWJS package build failed."
|
||||
}
|
||||
} else {
|
||||
"NWJS packages found."
|
||||
$found = $true
|
||||
}
|
||||
}
|
||||
# Pass variables back to launching script
|
||||
$GLOBAL:AppImageArchives = $AppImageArchives
|
||||
$GLOBAL:comp_electron_archive = $comp_electron_archive
|
||||
}
|
@ -86,7 +86,7 @@ $old_windows_support = $tag_name -match '\+N'
|
||||
$plus_electron = $tag_name -match '\+E'
|
||||
if ($text_tag -eq '') { $text_tag = 'Windows' }
|
||||
$release_title = "Kiwix JS $text_tag $base_tag UWP"
|
||||
if ($text_tag -imatch 'Wikivoyage|WikiMed') { $release_title = "$text_tag by Kiwix $base_tag UWP" }
|
||||
if ($text_tag -imatch 'Wikivoyage|WikiMed') { $release_title = "$text_tag by Kiwix UWP $base_tag" }
|
||||
$flavour = ''
|
||||
$file_version = ''
|
||||
if ($init_params -match 'params\[[''"]fileVersion[''"]]\s*=\s*(?:getSetting\([''"]fileVersion[''"]\)\s*\|\|\s*)?[''"]([^''"]+)') {
|
||||
@ -111,6 +111,7 @@ if ($tag_name -match 'E\+N') {
|
||||
if ($tag_name -match '\+E') {
|
||||
$title_flavour = 'UWP/PWA/Electron'
|
||||
$release_title = $release_title -replace 'Windows\s', ''
|
||||
$release_title = $release_title -replace 'UWP', '(Windows/Linux)'
|
||||
$release_tag_name = $tag_name -replace '\+E', ''
|
||||
}
|
||||
if ($text_tag -ne "Windows") { $branch = "Kiwix-JS-$text_tag" }
|
||||
@ -216,7 +217,7 @@ if ($dryrun -or $buildonly -or $release.assets_url -imatch '^https:') {
|
||||
$AppImageArchives = @()
|
||||
if ($flavour -eq '_E') {
|
||||
"Building Electron packages..."
|
||||
& $PSScriptRoot/Build-Electron.ps1
|
||||
. $PSScriptRoot/Build-Electron.ps1
|
||||
} elseif ($flavour -eq '_N') {
|
||||
# Package NWJS app if necessary
|
||||
$base_dir = "$PSScriptRoot/../bld/nwjs"
|
||||
@ -384,7 +385,7 @@ if ($dryrun -or $buildonly -or $release.assets_url -imatch '^https:') {
|
||||
# Build any extras requested
|
||||
if ($plus_electron) {
|
||||
"Building add-on: Electron packages..."
|
||||
& $PSScriptRoot/Build-Electron.ps1
|
||||
. $PSScriptRoot/Build-Electron.ps1
|
||||
}
|
||||
# Upload the release
|
||||
if ($flavour -eq '') { $upload_assets = @($compressed_archive, $ReleaseBundle) }
|
||||
@ -402,7 +403,7 @@ if ($dryrun -or $buildonly -or $release.assets_url -imatch '^https:') {
|
||||
$upload_assets += $comp_electron_archive
|
||||
}
|
||||
$upload_uri = $release.upload_url -ireplace '\{[^{}]+}', ''
|
||||
"Uploading assets to: $upload_uri..."
|
||||
"`nUploading assets to: $upload_uri..."
|
||||
|
||||
ForEach($asset in $upload_assets) {
|
||||
if (-Not $asset) { Continue }
|
||||
|
Loading…
x
Reference in New Issue
Block a user