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');