簡體   English   中英

如何檢查您的node.js應用程序的版本是否為最新?

[英]How to check if your node.js application's version is the latest?

由於我的node.js應用程序是一個由用戶直接運行的命令行應用程序。 給它打電話給github倉庫,並將其本地版本與github倉庫的master分支上的最新版本進行比較是有意義的。 並且如果版本已過時,則向用戶顯示一條消息。

那么,如何將這部手機帶回家並比較版本呢?

自己創建了解決方案。 需要依賴項bal-util (所以npm install bal-util )。 這是代碼:

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

CoffeeScript

# 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");
    }
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM