config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Electron 应用配置
  2. const path = require('path')
  3. const fs = require('fs')
  4. // 根目录 = config 文件所在目录的上级(本文件在 <根>/configs/config.js,故 projectRoot = path.dirname(__dirname))
  5. const projectRoot = (typeof __dirname !== 'undefined' && __dirname.includes('app.asar'))
  6. ? path.dirname(process.execPath)
  7. : path.resolve(__dirname, '..')
  8. // 根据 process.arch 判断架构(arm64 / x64)
  9. const isArm64 = process.arch === 'arm64'
  10. const arch = isArm64 ? 'arm64' : 'x64'
  11. // Node.js:优先 nodejs/{arch}/node,不存在则回退到 nodejs/node(兼容当前结构)
  12. const nodeDirArch = path.join(projectRoot, 'nodejs', arch, 'node')
  13. const nodeDirLegacy = path.join(projectRoot, 'nodejs', 'node')
  14. const nodeDir = fs.existsSync(nodeDirArch) ? nodeDirArch : nodeDirLegacy
  15. // Python:python/{arch}
  16. const pythonDir = path.join(projectRoot, 'python', arch)
  17. // 虚拟环境:python/{arch}/env
  18. const pythonVenvPath = path.join(pythonDir, 'env')
  19. const isWin = process.platform === 'win32'
  20. module.exports = {
  21. // 当前架构
  22. arch,
  23. // 项目根目录:开发时为仓库根,打包后由 package/x64/config.js 提供(exe 同目录)
  24. projectRoot,
  25. // 窗口配置
  26. window: {
  27. width: 800,
  28. height: 600,
  29. autoHideMenuBar: true, // 隐藏菜单栏(File、Edit、View、Window、Help)
  30. },
  31. // 开发工具配置
  32. devTools: {
  33. enabled: false, // 是否显示调试侧边栏(DevTools)
  34. },
  35. // Vite 开发服务器配置
  36. vite: {
  37. port: 9527, // Vite 开发服务器端口(如果被占用会自动尝试下一个端口)
  38. host: 'localhost' // 服务器主机地址
  39. },
  40. // Python 路径(按架构:python/x64 或 python/arm64)
  41. pythonPath: {
  42. path: pythonDir
  43. },
  44. pythonDir,
  45. pythonVenvPath,
  46. // ADB 路径配置(相对于项目根目录)
  47. adbPath: {
  48. path: path.join(projectRoot, 'lib/scrcpy-adb/adb.exe')
  49. },
  50. // Node.js 路径(按架构:nodejs/x64/node 或 nodejs/arm64/node,不存在时用 nodejs/node)
  51. nodejsPath: path.join(nodeDir, isWin ? 'node.exe' : 'node'),
  52. // Node.js 目录及 npm 路径(供 install / env 脚本读取)
  53. nodeDir,
  54. npmCmdPath: path.join(nodeDir, isWin ? 'npm.cmd' : 'npm'),
  55. npmCliPath: path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js')
  56. }
  57. // 被直接执行时:供 bat / PowerShell 读取路径。 node config.js → 输出 set "NODE_EXE=..." 等(bat); node config.js --json → 输出 JSON
  58. if (typeof require !== 'undefined' && require.main === module) {
  59. const args = (process.argv || []).slice(2)
  60. const wantJson = args.includes('--json')
  61. const nodeExe = path.join(nodeDir, isWin ? 'node.exe' : 'node')
  62. const adbPathVal = (module.exports.adbPath && module.exports.adbPath.path) ? module.exports.adbPath.path : ''
  63. const safe = (s) => String(s || '').replace(/"/g, '')
  64. if (wantJson) {
  65. console.log(JSON.stringify({
  66. arch,
  67. nodeDir,
  68. npmCmdPath: path.join(nodeDir, isWin ? 'npm.cmd' : 'npm'),
  69. npmCliPath: path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
  70. pythonDir,
  71. pythonVenvPath
  72. }))
  73. } else {
  74. console.log('set "NODE_EXE=' + safe(nodeExe) + '"')
  75. console.log('set "ADB_PATH=' + safe(adbPathVal) + '"')
  76. }
  77. }