【问题标题】:How to check if your node.js application's version is the latest?如何检查您的 node.js 应用程序的版本是否是最新的?
【发布时间】:2023-03-21 06:20:01
【问题描述】:

因为my node.js application 是一个由用户直接运行的命令行应用程序。打电话给 github repo 并将其本地版本与 github repo 上的 master 分支上的最新版本进行比较是有意义的。如果版本过时,向用户显示一条消息。

那么如何完成这款手机之家并比较版本呢?

【问题讨论】:

  • 您只是发布问题并自己回答吗?
  • 是的,提出和回答您已经有答案的问题的做法,这将为社区增加价值,并且还没有被问到 - is encouraged。你有异议吗?
  • 不反对,不。我刚看到一连串的问题,马上就被你回答了,觉得很奇怪;)

标签: node.js


【解决方案1】:

自己创建了一个解决方案。需要依赖bal-util(所以npm install bal-util)。代码如下:

packageCompare函数的源代码可以在这里找到:https://github.com/balupton/bal-util/blob/master/src/lib/compare.coffee

咖啡脚本

# Prepare
balUtil = require('bal-util')
pathUtil = require('path')
debug = false

# Compare
balUtil.packageCompare({
    local: pathUtil.join(__dirname, '..', 'package.json')
    remote: 'https://raw.github.com/bevry/docpad/master/package.json'
    newVersionCallback: (details) ->
        if debug
            console.log """
                There is a new version of #{details.local.name} available, you should probably upgrade...
                current version:  #{details.local.version}
                new version:      #{details.remote.version}
                grab it here:     #{details.remote.homepage}
                """
        else
            console.log "There is a new version of #{details.local.name} available"
})

JavaScript

// Prepare
var balUtil, debug, pathUtil;
balUtil = require('bal-util');
pathUtil = require('path');
debug = false;

// Compare
balUtil.packageCompare({
  local: pathUtil.join(__dirname, '..', 'package.json'),
  remote: 'https://raw.github.com/bevry/docpad/master/package.json',
  newVersionCallback: function(details) {
    if (debug) {
      return console.log("There is a new version of " + details.local.name + " available, you should probably upgrade...\ncurrent version:  " + details.local.version + "\nnew version:      " + details.remote.version + "\ngrab it here:     " + details.remote.homepage);
    } else {
      return console.log("There is a new version of " + details.local.name + " available");
    }
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 2013-12-09
    相关资源
    最近更新 更多