fix windows extensions (#1968)

This commit is contained in:
Max Novich
2025-04-08 10:07:37 -07:00
committed by GitHub
parent 48ac6a3925
commit 03c06c9bf6
23 changed files with 562 additions and 415 deletions
+37 -72
View File
@@ -1,84 +1,49 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Required DLLs that must be present
const REQUIRED_DLLS = [
'libstdc++-6.dll',
'libgcc_s_seh-1.dll',
'libwinpthread-1.dll'
];
// Paths
const platformWinDir = path.join(__dirname, '..', 'src', 'platform', 'windows', 'bin');
const outDir = path.join(__dirname, '..', 'out', 'Goose-win32-x64', 'resources', 'bin');
const srcBinDir = path.join(__dirname, '..', 'src', 'bin');
// Source and target directories
const sourceDir = path.join(__dirname, '../src/bin');
const targetDir = path.join(__dirname, '../out/Goose-win32-x64/resources/bin');
function ensureDirectoryExists(dir) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
console.log(`Created directory: ${dir}`);
}
}
function copyDLLs() {
// Helper function to copy files
function copyFiles(sourceDir, targetDir) {
// Ensure target directory exists
ensureDirectoryExists(targetDir);
// Get list of DLLs in source directory
const sourceDLLs = fs.readdirSync(sourceDir)
.filter(file => file.toLowerCase().endsWith('.dll'));
console.log('Found DLLs in source directory:', sourceDLLs);
// Check for missing required DLLs
const missingDLLs = REQUIRED_DLLS.filter(dll =>
!sourceDLLs.includes(dll)
);
if (missingDLLs.length > 0) {
console.error('Missing required DLLs:', missingDLLs);
process.exit(1);
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
// Copy all DLLs and the executable to target directory
sourceDLLs.forEach(dll => {
const sourcePath = path.join(sourceDir, dll);
const targetPath = path.join(targetDir, dll);
// Copy all files from source to target directory
console.log(`Copying files to ${targetDir}...`);
fs.readdirSync(sourceDir).forEach(file => {
const srcPath = path.join(sourceDir, file);
const destPath = path.join(targetDir, file);
try {
fs.copyFileSync(sourcePath, targetPath);
console.log(`Copied ${dll} to ${targetDir}`);
} catch (err) {
console.error(`Error copying ${dll}:`, err);
process.exit(1);
// Skip .gitignore and README.md
if (file === '.gitignore' || file === 'README.md') {
return;
}
// Handle directories (like goose-npm)
if (fs.statSync(srcPath).isDirectory()) {
fs.cpSync(srcPath, destPath, { recursive: true, force: true });
console.log(`Copied directory: ${file}`);
return;
}
// Copy individual file
fs.copyFileSync(srcPath, destPath);
console.log(`Copied: ${file}`);
});
// Copy the executable
const exeName = 'goosed.exe';
const sourceExe = path.join(sourceDir, exeName);
const targetExe = path.join(targetDir, exeName);
try {
if (fs.existsSync(sourceExe)) {
fs.copyFileSync(sourceExe, targetExe);
console.log(`Copied ${exeName} to ${targetDir}`);
} else {
console.error(`${exeName} not found in source directory`);
process.exit(1);
}
} catch (err) {
console.error(`Error copying ${exeName}:`, err);
process.exit(1);
}
console.log('All files copied successfully');
}
// Main execution
try {
copyDLLs();
} catch (err) {
console.error('Error during copy process:', err);
process.exit(1);
}
// Copy to both directories
console.log('Copying Windows-specific files...');
// Copy to src/bin for development
copyFiles(platformWinDir, srcBinDir);
// Copy to output directory for distribution
copyFiles(platformWinDir, outDir);
console.log('Windows-specific files copied successfully');
+16
View File
@@ -0,0 +1,16 @@
const { execSync } = require('child_process');
const path = require('path');
try {
if (process.platform === 'win32') {
execSync(path.join(__dirname, 'prepare-windows-npm.bat'), { stdio: 'inherit' });
} else {
execSync(path.join(__dirname, 'prepare-windows-npm.sh'), {
stdio: 'inherit',
shell: '/bin/bash'
});
}
} catch (error) {
console.error('Error preparing platform:', error);
process.exit(1);
}
+101
View File
@@ -0,0 +1,101 @@
@echo off
setlocal enabledelayedexpansion
rem Script to prepare Windows npm bundle
set "SCRIPT_DIR=%~dp0"
set "PLATFORM_WIN_DIR=%SCRIPT_DIR%\..\src\platform\windows"
set "WIN_BIN_DIR=%PLATFORM_WIN_DIR%\bin"
set "DEST_BIN_DIR=%SCRIPT_DIR%\..\src\bin"
echo Preparing Windows npm bundle...
echo SCRIPT_DIR: %SCRIPT_DIR%
echo PLATFORM_WIN_DIR: %PLATFORM_WIN_DIR%
echo WIN_BIN_DIR: %WIN_BIN_DIR%
echo DEST_BIN_DIR: %DEST_BIN_DIR%
rem Ensure directories exist
if not exist "%WIN_BIN_DIR%" mkdir "%WIN_BIN_DIR%"
rem Node.js version and paths
set "NODE_VERSION=23.10.0"
set "NODE_MSI_URL=https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-x64.msi"
rem Create Windows Node.js installer script
echo Creating install-node.cmd...
(
echo @echo off
echo setlocal enabledelayedexpansion
echo.
echo REM Check if Node.js is installed in Program Files
echo if exist "C:\Program Files\nodejs\node.exe" ^(
echo echo Node.js found in Program Files
echo set "NODE_EXE=C:\Program Files\nodejs\node.exe"
echo goto :found
echo ^)
echo.
echo REM Check if Node.js is installed in Program Files ^(x86^)
echo if exist "C:\Program Files ^(x86^)\nodejs\node.exe" ^(
echo echo Node.js found in Program Files ^(x86^)
echo set "NODE_EXE=C:\Program Files ^(x86^)\nodejs\node.exe"
echo goto :found
echo ^)
echo.
echo echo Node.js not found in standard locations, installing...
echo.
echo REM Download Node.js MSI installer
echo powershell -Command "^& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%%1' -OutFile '%%TEMP%%\node-setup.msi'}"
echo.
echo REM Install Node.js silently
echo msiexec /i "%%TEMP%%\node-setup.msi" /qn
echo.
echo REM Wait a bit for installation to complete
echo timeout /t 5 /nobreak
echo.
echo REM Clean up
echo del "%%TEMP%%\node-setup.msi"
echo.
echo REM Set path to installed Node.js
echo set "NODE_EXE=C:\Program Files\nodejs\node.exe"
echo.
echo :found
echo echo Using Node.js: %%NODE_EXE%%
echo exit /b 0
) > "%WIN_BIN_DIR%\install-node.cmd"
rem Create a modified npx.cmd that checks for system Node.js first
echo Creating npx.cmd...
(
echo @ECHO OFF
echo SETLOCAL EnableDelayedExpansion
echo.
echo SET "SCRIPT_DIR=%%~dp0"
echo.
echo REM Try to find Node.js in standard locations first
echo if exist "C:\Program Files\nodejs\npx.cmd" ^(
echo "C:\Program Files\nodejs\npx.cmd" %%*
echo exit /b %%errorlevel%%
echo ^)
echo.
echo if exist "C:\Program Files ^(x86^)\nodejs\npx.cmd" ^(
echo "C:\Program Files ^(x86^)\nodejs\npx.cmd" %%*
echo exit /b %%errorlevel%%
echo ^)
echo.
echo REM If Node.js not found, run installer
echo call "%%SCRIPT_DIR%%install-node.cmd" "%NODE_MSI_URL%"
echo if errorlevel 1 ^(
echo echo Failed to install Node.js
echo exit /b 1
echo ^)
echo.
echo REM Try using the newly installed Node.js
echo if exist "C:\Program Files\nodejs\npx.cmd" ^(
echo "C:\Program Files\nodejs\npx.cmd" %%*
echo exit /b %%errorlevel%%
echo ^)
echo.
echo echo Failed to find npx after Node.js installation
echo exit /b 1
) > "%WIN_BIN_DIR%\npx.cmd"
echo Windows npm bundle prepared successfully
+101
View File
@@ -0,0 +1,101 @@
#!/bin/bash
set -e
# Script to prepare Windows npm bundle
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLATFORM_WIN_DIR="$SCRIPT_DIR/../src/platform/windows"
WIN_BIN_DIR="$PLATFORM_WIN_DIR/bin"
DEST_BIN_DIR="$SCRIPT_DIR/../src/bin"
echo "Preparing Windows npm bundle..."
echo "SCRIPT_DIR: $SCRIPT_DIR"
echo "PLATFORM_WIN_DIR: $PLATFORM_WIN_DIR"
echo "WIN_BIN_DIR: $WIN_BIN_DIR"
echo "DEST_BIN_DIR: $DEST_BIN_DIR"
# Ensure directories exist
mkdir -p "$WIN_BIN_DIR"
# Node.js version and paths
NODE_VERSION="23.10.0"
NODE_MSI_URL="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-x64.msi"
# Create Windows Node.js installer script
echo "Creating install-node.cmd..."
cat > "$WIN_BIN_DIR/install-node.cmd" << 'EOL'
@echo off
setlocal enabledelayedexpansion
REM Check if Node.js is installed in Program Files
if exist "C:\Program Files\nodejs\node.exe" (
echo Node.js found in Program Files
set "NODE_EXE=C:\Program Files\nodejs\node.exe"
goto :found
)
REM Check if Node.js is installed in Program Files (x86)
if exist "C:\Program Files (x86)\nodejs\node.exe" (
echo Node.js found in Program Files (x86)
set "NODE_EXE=C:\Program Files (x86)\nodejs\node.exe"
goto :found
)
echo Node.js not found in standard locations, installing...
REM Download Node.js MSI installer
powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%1' -OutFile '%TEMP%\node-setup.msi'}"
REM Install Node.js silently
msiexec /i "%TEMP%\node-setup.msi" /qn
REM Wait a bit for installation to complete
timeout /t 5 /nobreak
REM Clean up
del "%TEMP%\node-setup.msi"
REM Set path to installed Node.js
set "NODE_EXE=C:\Program Files\nodejs\node.exe"
:found
echo Using Node.js: %NODE_EXE%
exit /b 0
EOL
# Create a modified npx.cmd that checks for system Node.js first
echo "Creating npx.cmd..."
cat > "$WIN_BIN_DIR/npx.cmd" << 'EOL'
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET "SCRIPT_DIR=%~dp0"
REM Try to find Node.js in standard locations first
if exist "C:\Program Files\nodejs\npx.cmd" (
"C:\Program Files\nodejs\npx.cmd" %*
exit /b %errorlevel%
)
if exist "C:\Program Files (x86)\nodejs\npx.cmd" (
"C:\Program Files (x86)\nodejs\npx.cmd" %*
exit /b %errorlevel%
)
REM If Node.js not found, run installer
call "%SCRIPT_DIR%install-node.cmd" "https://nodejs.org/dist/v23.10.0/node-v23.10.0-x64.msi"
if errorlevel 1 (
echo Failed to install Node.js
exit /b 1
)
REM Try using the newly installed Node.js
if exist "C:\Program Files\nodejs\npx.cmd" (
"C:\Program Files\nodejs\npx.cmd" %*
exit /b %errorlevel%
)
echo Failed to find npx after Node.js installation
exit /b 1
EOL
echo "Windows npm bundle prepared successfully"