feat: add support for SVR.JS archives without "svr.compressed" and with "wwwroot"

This commit is contained in:
Dorian Niemiec 2025-01-05 10:05:13 +01:00
parent e460ab72b2
commit e436fec833

View file

@ -60,10 +60,6 @@ if (!(Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs")) {
New-Item -Path "$env:SYSTEMDRIVE\svrjs" -Name "svrjs" -ItemType "directory" | Out-Null
}
if (!(Test-Path -Path "$env:SYSTEMDRIVE\svrjs\wwwroot")) {
New-Item -Path "$env:SYSTEMDRIVE\svrjs" -Name "wwwroot" -ItemType "directory" | Out-Null
}
# Download SVR.JS zip archive
if ($installType -eq "manual") {
$svrjsZipArchive = Read-Host "Path to SVR.JS zip archive: "
@ -132,28 +128,40 @@ Remove-Item -Path $nodejsZipArchive
Write-Host "Extracting SVR.JS files..."
Expand-Archive -Path $svrjsZipArchive -DestinationPath "$env:SYSTEMDRIVE\svrjs\svrjs" -Force
Remove-Item -Path $svrjsZipArchive
Push-Location
Set-Location -Path "$env:SYSTEMDRIVE\svrjs\svrjs"
Start-Process -FilePath "$nodejsDir\node.exe" -ArgumentList "$env:SYSTEMDRIVE\svrjs\svrjs\svr.js" -Wait
Pop-Location
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\svr.compressed" -PathType "Leaf") {
Push-Location
Set-Location -Path "$env:SYSTEMDRIVE\svrjs\svrjs"
Start-Process -FilePath "$nodejsDir\node.exe" -ArgumentList "$env:SYSTEMDRIVE\svrjs\svrjs\svr.js" -Wait
Pop-Location
}
Start-Process -FilePath "$nodejsDir\node.exe" -ArgumentList "-e `"var fs=require('fs'),config=JSON.parse(fs.readFileSync('$env:SYSTEMDRIVE\\svrjs\\svrjs\\config.json').toString());config.wwwroot='$env:SYSTEMDRIVE\\svrjs\\wwwroot',fs.writeFileSync('$env:SYSTEMDRIVE\\svrjs\\svrjs\\config.json',JSON.stringify(config));`"" -Wait
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\index.html" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\tests.html" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\licenses" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\testdir" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\serverSideScript.js" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\logo.png" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\powered.png" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\favicon.ico") {
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\favicon.ico" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\wwwroot" -PathType "Container") {
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\wwwroot") {
Remove-Item -Path "$env:SYSTEMDRIVE\svrjs\wwwroot" -Recurse -Force | Out-Null
New-Item -Path "$env:SYSTEMDRIVE\svrjs" -Name "wwwroot" -ItemType "directory" | Out-Null
}
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\wwwroot" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
} else {
if (!(Test-Path -Path "$env:SYSTEMDRIVE\svrjs\wwwroot")) {
New-Item -Path "$env:SYSTEMDRIVE\svrjs" -Name "wwwroot" -ItemType "directory" | Out-Null
}
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\index.html" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\tests.html" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\licenses" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\testdir" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\serverSideScript.js" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\logo.png" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\powered.png" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\favicon.ico") {
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\favicon.ico" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
}
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\views.txt") {
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\views.txt" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
}
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\hviews.txt") {
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\hviews.txt" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
}
}
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\views.txt") {
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\views.txt" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
}
if (Test-Path -Path "$env:SYSTEMDRIVE\svrjs\svrjs\hviews.txt") {
Move-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\hviews.txt" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot"
}
Copy-Item -Path "$env:SYSTEMDRIVE\svrjs\svrjs\.dirimages" -Destination "$env:SYSTEMDRIVE\svrjs\wwwroot" -Recurse
# Generate WinSW Configuration
Write-Host "Generating WinSW configuration..."
@ -185,4 +193,4 @@ rd %SYSTEMDRIVE%\svrjs /s /q
$uninstallBat | Out-File -FilePath "$env:SYSTEMDRIVE\uninstall_svrjs.bat" -Encoding utf8
echo "Done! SVR.JS is installed successfully!"
echo "Done! SVR.JS is installed successfully!"