const { execSync } = require('child_process')

console.log('🔍 验证 Electron 镜像源配置...\n')

// 检查 npm 配置
try {
  const registry = execSync('npm config get registry', { encoding: 'utf-8' }).trim()
  const electronMirror = execSync('npm config get electron_mirror', { encoding: 'utf-8' }).trim()
  const builderMirror = execSync('npm config get electron_builder_binaries_mirror', { encoding: 'utf-8' }).trim()

  console.log('✅ npm 配置:')
  console.log('  registry:', registry)
  console.log('  electron_mirror:', electronMirror)
  console.log('  electron_builder_binaries_mirror:', builderMirror)
  console.log()

  // 验证是否使用了镜像源
  const isUsingMirror = electronMirror.includes('npmmirror.com') ||
                        electronMirror.includes('huaweicloud.com') ||
                        electronMirror.includes('cloud.tencent.com')

  if (isUsingMirror) {
    console.log('✅ 已配置国内镜像源，无需翻墙即可打包！')
  } else {
    console.log('⚠️  未检测到国内镜像源，可能需要翻墙才能打包')
  }

  console.log()
  console.log('📦 现在可以执行打包命令:')
  console.log('  npm run pack:win    # Windows')
  console.log('  npm run pack:mac    # Mac')

} catch (error) {
  console.error('❌ 验证失败:', error.message)
}
