check-update.js 1.0 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
module.exports = async function checkUpdate () {
  const {
    isInHBuilderX
  } = require('@dcloudio/uni-cli-shared')

  if (isInHBuilderX) { // 仅 cli 提供检测更新
    return
  }

  const pkg = require('../package.json')
  const checkForUpdate = require('update-check')
  let update = null

  try {
    const options = {}
    if (pkg.version.indexOf('alpha') !== -1) {
      options.distTag = 'alpha'
    }
    update = await checkForUpdate(pkg, options)
  } catch (err) {
21
    // console.error(`检查更新失败: ${err}`)
fxy060608's avatar
fxy060608 已提交
22 23 24 25 26 27
  }

  if (update) {
    if (pkg.version.split('.')[0] !== update.latest.split('.')[0]) {
      console.log(`发现 uni-app 新版本 ${update.latest}`)
      console.log(`1.修改 package.json 中 @dcloudio 相关包版本为 ^${update.latest}`)
fxy060608's avatar
fxy060608 已提交
28 29
      console.log('2.删除 package-lock.json 或 yarn.lock')
      console.log('3.执行 npm install 或 yarn')
fxy060608's avatar
fxy060608 已提交
30 31 32 33 34
    } else {
      console.log(`发现 uni-app 新版本 ${update.latest}. 请执行 npm update 升级`)
    }
  }
}