由于my node.js application是由用户直接运行的命令行应用程序。它是有意义的,它打电话给github仓库,并将其本地版本与github repo上主分支上的最新版本进行比较。如果版本已过时,请向用户显示一条消息。
那么如何才能完成这款手机并对比版本呢?
答案 0 :(得分:0)
我自己创建了一个解决方案。需要依赖项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"
})
// 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");
}
}
});