This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
update-notifier.js
83 lines (74 loc) · 2.25 KB
/
update-notifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* @Author: gbk
* @Date: 2016-06-25 12:42:56
* @Last Modified by: gbk
* @Last Modified time: 2017-06-21 20:53:33
*/
'use strict';
var os = require('os');
var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var chalk = require('chalk');
var semver = require('semver');
module.exports = function() {
// do not show update tip inside nowa-gui
if (process.env.NOWA_GUI) {
return;
}
// check for nowa-gui installation
try {
fs.statSync(path.join(os.homedir(), '.nowa-gui', 'user_config.json'))
} catch (e) {
console.log(
chalk.yellow(
'\n Nowa GUI for all platform is available now!' +
'\n You can download it here:' +
'\n https://nowa-webpack.github.io/')
);
}
// read latest versions
var versionsFile = path.join(os.homedir(), '.nowa', 'latest-versions.json');
var store = {};
try {
store = JSON.parse(fs.readFileSync(versionsFile, 'utf-8'));
} catch(e) {}
var versions = store.versions || {};
// compare versions and show tip
var isTipShow = false;
var argvs = Array.prototype.slice.call(arguments, 0);
argvs.slice(1).concat([ 'nowa' ]).forEach(function(plugin) {
try {
var pkg = require(path.join(__dirname, '..', '..', plugin, 'package.json'));
if (versions[plugin] && semver.lt(pkg.version, versions[plugin])) {
if (plugin === 'nowa') {
// do not show nowa update tip if any plugins need update
if (!isTipShow) {
console.log(
chalk.yellow(
'\n Update available: ' +
plugin + '@' + versions[plugin] + ' (Current: ' + pkg.version + ')' +
'\n Run `npm i nowa -g` to update.')
);
}
} else {
console.log(
chalk.yellow(
'\n Update available: ' +
plugin + '@' + versions[plugin] + ' (Current: ' + pkg.version + ')' +
'\n Run `nowa install ' + plugin.substring(5) + '` to update.')
);
}
isTipShow = true;
}
} catch(e) {
}
});
// fetch latest versions
spawn(process.execPath, [
path.join(__dirname, 'check')
].concat(argvs), {
detached: true,
stdio: 'ignore'
}).unref();
};