-
Notifications
You must be signed in to change notification settings - Fork 18
/
update.js
46 lines (44 loc) · 1.5 KB
/
update.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
const gitdl = require('download-git-repo');
const request = require('request');
const yesno = require('yesno');
const exec = require('child_process').exec;
function download(tag) {
gitdl('musiqpad/mqp-server#' + tag, process.cwd(), function (err) {
if (err) {
console.log(colors.red('Error: '.error) + err);
process.exit();
} else {
console.log('Download finished, now (re)installing dependencies');
console.log('This step might take some time ...');
exec('npm install', { cwd: (process.cwd()) }, function (error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
return;
} else {
console.log('Succesfully installed all dependencies of musiqpad');
process.exit();
}
});
}
});
}
module.exports = function update() {
var options = {
url: 'https://api.github.com/repos/musiqpad/mqp-server/releases/latest',
headers: {
'User-Agent': 'request',
},
};
request(options, function (err, res, data) {
if (!err && res.statusCode == 200) {
yesno.ask('This will overide all existing code exept new files and modules. Do you want to continue? (y/N)', false, function (ok) {
if (ok) {
console.log('Now updating to latest version (' + JSON.parse(data).tag_name + ')!');
download(JSON.parse(data).tag_name);
} else
process.exit();
});
} else
console.log('Error getting the latest musiqpad version: ' + err);
});
};