const { exec } = require('child_process')

let retries = 0
const maxRetries = 100

function publishPackage() {
  exec('npm publish', (error, stdout, stderr) => {
    if (error) {
      console.log(`错误: ${stderr}`)
      if (stderr.includes('ETIMEDOUT') && retries < maxRetries) {
        retries++
        console.log(`ETIMEDOUT 错误，正在重试第 ${retries} 次...`)
        setTimeout(publishPackage, 1000) // 5秒后重试
      } else {
        console.log('发布失败或达到最大重试次数。')
      }
    } else {
      console.log(`发布成功: ${stdout}`)
    }
  })
}

publishPackage()
