| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- // Electron 应用配置
- const path = require('path')
- const fs = require('fs')
- // 根目录 = config 文件所在目录的上级(本文件在 <根>/configs/config.js,故 projectRoot = path.dirname(__dirname))
- const projectRoot = (typeof __dirname !== 'undefined' && __dirname.includes('app.asar'))
- ? path.dirname(process.execPath)
- : path.resolve(__dirname, '..')
- // 根据 process.arch 判断架构(arm64 / x64)
- const isArm64 = process.arch === 'arm64'
- const arch = isArm64 ? 'arm64' : 'x64'
- // Node.js:优先 nodejs/{arch}/node,不存在则回退到 nodejs/node(兼容当前结构)
- const nodeDirArch = path.join(projectRoot, 'nodejs', arch, 'node')
- const nodeDirLegacy = path.join(projectRoot, 'nodejs', 'node')
- const nodeDir = fs.existsSync(nodeDirArch) ? nodeDirArch : nodeDirLegacy
- // Python:python/{arch}
- const pythonDir = path.join(projectRoot, 'python', arch)
- // 虚拟环境:python/{arch}/env
- const pythonVenvPath = path.join(pythonDir, 'env')
- const isWin = process.platform === 'win32'
- module.exports = {
- // 当前架构
- arch,
- // 项目根目录:开发时为仓库根,打包后由 package/x64/config.js 提供(exe 同目录)
- projectRoot,
- // 窗口配置
- window: {
- width: 800,
- height: 600,
- autoHideMenuBar: true, // 隐藏菜单栏(File、Edit、View、Window、Help)
- },
- // 开发工具配置
- devTools: {
- enabled: false, // 是否显示调试侧边栏(DevTools)
- },
- // Vite 开发服务器配置
- vite: {
- port: 9527, // Vite 开发服务器端口(如果被占用会自动尝试下一个端口)
- host: 'localhost' // 服务器主机地址
- },
- // Python 路径(按架构:python/x64 或 python/arm64)
- pythonPath: {
- path: pythonDir
- },
- pythonDir,
- pythonVenvPath,
- // ADB 路径配置(相对于项目根目录)
- adbPath: {
- path: path.join(projectRoot, 'lib/scrcpy-adb/adb.exe')
- },
- // Node.js 路径(按架构:nodejs/x64/node 或 nodejs/arm64/node,不存在时用 nodejs/node)
- nodejsPath: path.join(nodeDir, isWin ? 'node.exe' : 'node'),
- // Node.js 目录及 npm 路径(供 install / env 脚本读取)
- nodeDir,
- npmCmdPath: path.join(nodeDir, isWin ? 'npm.cmd' : 'npm'),
- npmCliPath: path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js')
- }
- // 被直接执行时:供 bat / PowerShell 读取路径。 node config.js → 输出 set "NODE_EXE=..." 等(bat); node config.js --json → 输出 JSON
- if (typeof require !== 'undefined' && require.main === module) {
- const args = (process.argv || []).slice(2)
- const wantJson = args.includes('--json')
- const nodeExe = path.join(nodeDir, isWin ? 'node.exe' : 'node')
- const adbPathVal = (module.exports.adbPath && module.exports.adbPath.path) ? module.exports.adbPath.path : ''
- const safe = (s) => String(s || '').replace(/"/g, '')
- if (wantJson) {
- console.log(JSON.stringify({
- arch,
- nodeDir,
- npmCmdPath: path.join(nodeDir, isWin ? 'npm.cmd' : 'npm'),
- npmCliPath: path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
- pythonDir,
- pythonVenvPath
- }))
- } else {
- console.log('set "NODE_EXE=' + safe(nodeExe) + '"')
- console.log('set "ADB_PATH=' + safe(adbPathVal) + '"')
- }
- }
|