From 24c98d66562f2a10accbd11c2dbd089734c808f7 Mon Sep 17 00:00:00 2001 From: Cris Stringfellow <22254235+crislin2046@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:29:03 +0000 Subject: [PATCH] Windows progress --- scripts/build_only.sh | 10 ++++- stampers/win.bat | 9 +--- stampers/win.ps1 | 100 ------------------------------------------ 3 files changed, 9 insertions(+), 110 deletions(-) delete mode 100755 stampers/win.ps1 diff --git a/scripts/build_only.sh b/scripts/build_only.sh index c6a4353..22a94e7 100755 --- a/scripts/build_only.sh +++ b/scripts/build_only.sh @@ -29,10 +29,16 @@ echo "#!/usr/bin/env node" > build/global/downloadnet.cjs cat build/cjs/dn.cjs >> build/global/downloadnet.cjs chmod +x build/global/downloadnet.cjs if [[ "$OSTYPE" == darwin* ]]; then + echo "Using macOS builder..." >&2 ./stampers/macos.sh dn build/cjs/dn.cjs build/bin/ -elif [[ "$OSTYPE" == win* ]]; then - ./stampers/win.sh dn build/cjs/dn.cjs build/bin/ +elif [[ "$(node.exe -p process.platform)" == win* ]]; then + echo "Using windows builder..." >&2 + ./stampers/win.bat dn build/cjs/dn.cjs build/bin/ else + echo "Using linux builder..." >&2 ./stampers/nix.sh dn build/cjs/dn.cjs build/bin/ fi +echo "Done" + +read -p "Any key to exit" diff --git a/stampers/win.bat b/stampers/win.bat index 81e7ebe..a0cbfdb 100644 --- a/stampers/win.bat +++ b/stampers/win.bat @@ -15,9 +15,6 @@ set "OUTPUT_FOLDER=%~3" :: Ensure output folder exists if not exist "%OUTPUT_FOLDER%" mkdir "%OUTPUT_FOLDER%" -:: Create a JavaScript file -echo console.log(`Hello, %%argv[2]!`); > "%JS_SOURCE_FILE%" - :: Create configuration file for SEA ( echo { @@ -43,17 +40,13 @@ node --experimental-sea-config "%OUTPUT_FOLDER%\%SEA_CONFIG%" node -e "require('fs').copyFileSync(process.execPath, '%OUTPUT_FOLDER%\%EXE_NAME%')" :: Optionally, remove signature from the binary (use signtool if necessary, or skip this step) -:: signtool remove /s "%OUTPUT_FOLDER%\%EXE_NAME%" +signtool remove /s "%OUTPUT_FOLDER%\%EXE_NAME%" :: Inject the blob into the copied binary npx postject "%OUTPUT_FOLDER%\%EXE_NAME%" NODE_SEA_BLOB sea-prep.blob ^ --sentinel-fuse %NODE_SEA_FUSE% :: Clean up -del "%JS_SOURCE_FILE%" -del "%OUTPUT_FOLDER%\%SEA_CONFIG%" -del sea-prep.blob - echo Application built successfully. :end diff --git a/stampers/win.ps1 b/stampers/win.ps1 deleted file mode 100755 index 7a936b7..0000000 --- a/stampers/win.ps1 +++ /dev/null @@ -1,100 +0,0 @@ -param( - [string]$exeName, - [string]$jsSourceFile, - [string]$outputFolder -) - -# Validate parameters -if (-not $exeName) { - Write-Error "Executable name is required." - exit 1 -} -if (-not $jsSourceFile) { - Write-Error "JavaScript source file path is required." - exit 1 -} -if (-not $outputFolder) { - Write-Error "Output folder is required." - exit 1 -} - -# Ensure NVM is installed -if (-not (Get-Command nvm -ErrorAction SilentlyContinue)) { - Write-Output "NVM not found. Installing..." - Invoke-WebRequest https://raw.githubusercontent.com/coreybutler/nvm-windows/master/nvm-setup.exe -OutFile nvm-setup.exe - Start-Process -Wait -FilePath nvm-setup.exe - Remove-Item nvm-setup.exe -} - -# Use Node 22 -nvm install 22 -nvm use 22 - -# Create sea-config.json -$seaConfigContent = @" -{ - "main": "$jsSourceFile", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true, - "useCodeCache": true, - "assets": { - "index.html": "public/index.html", - "favicon.ico": "public/favicon.ico", - "top.html": "public/top.html", - "style.css": "public/style.css", - "injection.js": "public/injection.js", - "redirector.html": "public/redirector.html" - } -} -"@ -$seaConfigContent | Out-File sea-config.json - -# Generate the blob -try { - node --experimental-sea-config sea-config.json -} catch { - Write-Error "Failed to generate the blob: $_" - exit 1 -} - -# Copy node binary -try { - node -e "require('fs').copyFileSync(process.execPath, '$exeName.exe')" -} catch { - Write-Error "Failed to copy node binary: $_" - exit 1 -} - -# Optionally remove the signature of the binary -signtool remove /s "$exeName.exe" - -# Inject the blob -try { - npx postject "$exeName.exe" NODE_SEA_BLOB sea-prep.blob ` - --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 -} catch { - Write-Error "Failed to inject the blob: $_" - exit 1 -} - -# Optionally sign the binary -signtool sign /fd SHA256 "$exeName.exe" - -# Move the executable to the output folder -try { - Move-Item -Path "$exeName.exe" -Destination (Join-Path -Path $outputFolder -ChildPath "$exeName.exe") -} catch { - Write-Error "Failed to move the executable: $_" - exit 1 -} - -# Clean up -try { - Remove-Item sea-config.json, sea-prep.blob -} catch { - Write-Error "Failed to clean up: $_" - exit 1 -} - -Write-Output "Process completed successfully." -