#!/usr/bin/env node /** * Electron功能测试脚本 * 用于验证electron环境是否正确配置 */ const fs = require('fs'); const path = require('path'); console.log('🔍 Electron环境检测...'); console.log('='.repeat(50)); // 检查package.json配置 const packagePath = path.join(__dirname, 'package.json'); if (fs.existsSync(packagePath)) { const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8')); console.log('✅ package.json 存在'); console.log('📦 项目名称:', pkg.name); console.log('📦 版本:', pkg.version); // 检查electron相关脚本 if (pkg.scripts && pkg.scripts['electron:dev']) { console.log('✅ electron:dev 脚本已配置'); } else { console.log('❌ electron:dev 脚本未配置'); } // 检查electron依赖 const hasElectron = pkg.devDependencies && pkg.devDependencies.electron; if (hasElectron) { console.log('✅ electron 依赖已配置:', pkg.devDependencies.electron); } else { console.log('❌ electron 依赖未配置'); } // 检查electron-builder const hasBuilder = pkg.devDependencies && pkg.devDependencies['electron-builder']; if (hasBuilder) { console.log('✅ electron-builder 依赖已配置:', pkg.devDependencies['electron-builder']); } else { console.log('❌ electron-builder 依赖未配置'); } } else { console.log('❌ package.json 不存在'); } // 检查main进程文件 const mainPath = path.join(__dirname, '../main/main.js'); if (fs.existsSync(mainPath)) { console.log('✅ main.js 存在:', mainPath); } else { console.log('❌ main.js 不存在:', mainPath); } // 检查preload文件 const preloadPath = path.join(__dirname, '../main/preload.js'); if (fs.existsSync(preloadPath)) { console.log('✅ preload.js 存在:', preloadPath); } else { console.log('❌ preload.js 不存在:', preloadPath); } // 检查vite配置 const viteConfigPath = path.join(__dirname, 'vite.config.js'); if (fs.existsSync(viteConfigPath)) { console.log('✅ vite.config.js 存在'); const viteConfig = fs.readFileSync(viteConfigPath, 'utf8'); if (viteConfig.includes('electron-renderer')) { console.log('✅ vite配置包含electron-renderer目标'); } else { console.log('⚠️ vite配置可能需要electron-renderer目标'); } } else { console.log('❌ vite.config.js 不存在'); } // 检查node_modules const nodeModulesPath = path.join(__dirname, 'node_modules'); if (fs.existsSync(nodeModulesPath)) { console.log('✅ node_modules 存在'); // 检查electron是否安装 const electronPath = path.join(nodeModulesPath, 'electron'); if (fs.existsSync(electronPath)) { console.log('✅ electron 已安装'); } else { console.log('❌ electron 未安装,请运行 npm install'); } } else { console.log('❌ node_modules 不存在,请运行 npm install'); } // 检查启动脚本 const startScriptPath = path.join(__dirname, 'start-electron.bat'); if (fs.existsSync(startScriptPath)) { console.log('✅ start-electron.bat 启动脚本存在'); } else { console.log('❌ start-electron.bat 启动脚本不存在'); } const devScriptPath = path.join(__dirname, 'electron-dev.js'); if (fs.existsSync(devScriptPath)) { console.log('✅ electron-dev.js 开发脚本存在'); } else { console.log('❌ electron-dev.js 开发脚本不存在'); } console.log('='.repeat(50)); console.log('🎯 检测完成!'); console.log(''); console.log('📋 使用说明:'); console.log('1. 确保依赖已安装: npm install'); console.log('2. 启动开发环境: npm run electron:dev'); console.log('3. 或使用批处理: start-electron.bat'); console.log('4. 或使用脚本: node electron-dev.js');