This repository has been archived by the owner on Dec 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
updateCheck.js
51 lines (42 loc) · 1.76 KB
/
updateCheck.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
const json_package = require('./package.json');
const colors = require('colors');
const fetch = require('node-fetch');
module.exports = function () {
fetch('http://api.github.com/repos/clarkx86/papyrusjs/releases')
.then((response) => {
return response.json();
})
.then((json) => {
var remoteVersion = json[0]['tag_name'].slice(1, json[0]['tag_name'].search('-')).replace('.', '').replace('.', '');
remoteStage = json[0]['tag_name'].slice(json[0]['tag_name'].search('-') + 1),
localStage = json_package.version_stage;
switch (remoteStage) {
case 'alpha':
remoteStage = 0;
break;
case 'beta':
remoteStage = 1;
break;
case 'release':
remoteStage = 2;
break;
};
switch (localStage) {
case 'alpha':
localStage = 0;
break;
case 'beta':
localStage = 1;
break;
case 'release':
localStage = 2;
break;
};
if ((remoteStage > localStage) || (remoteVersion > (json_package.version.replace('.', '').replace('.', '')))) {
console.log('\n' + colors.inverse(colors.green('New update available!')) + '\nRelease ' + json[0]['tag_name'] + ' is available. You have v' + json_package.version + '-' + json_package.version_stage + '. Get it here: https://github.com/clarkx86/papyrusjs/releases' + '\n');
};
})
.catch((err) => {
console.log('Could not check for updates...');
});
};