-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-check.js
More file actions
28 lines (25 loc) · 889 Bytes
/
Copy pathupdate-check.js
File metadata and controls
28 lines (25 loc) · 889 Bytes
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
const https = require("https");
function newerThan(a, b) {
const pa = a.split(".").map(Number);
const pb = b.split(".").map(Number);
for (let i = 0; i < 3; i++) {
if ((pa[i] || 0) > (pb[i] || 0)) return true;
if ((pa[i] || 0) < (pb[i] || 0)) return false;
}
return false;
}
function checkForUpdates(pkg, current) {
const url = `https://registry.npmjs.org/${pkg.replace("/", "%2F")}/latest`;
https.get(url, { headers: { "User-Agent": "torque-antinuke" } }, res => {
let raw = "";
res.on("data", d => (raw += d));
res.on("end", () => {
try {
const latest = JSON.parse(raw).version;
if (latest && newerThan(latest, current))
console.warn(`\n[TorqueAntiNuke] update available ${current} → ${latest}\n npm install ${pkg}@latest\n`);
} catch {}
});
}).on("error", () => {});
}
module.exports = checkForUpdates;