-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.js
executable file
·50 lines (45 loc) · 1.34 KB
/
utils.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
const { execSync } = require("child_process");
function platformize(executable) {
return process.platform === "win32" ? `${executable}.cmd` : executable;
}
function checkVersions(metaManifest) {
const thisNPM = platformize("npm");
let exitCode = 0;
const nodeVersion = process.version.split(".")[0];
if (nodeVersion < metaManifest.requiredNodeVersion) {
console.error(
`⚠️ Node.js v${metaManifest.requiredNodeVersion} or later ` +
`required, you are on ${process.version}`
);
exitCode = 1;
}
let npmVersion;
try {
npmVersion = execSync(`${thisNPM} --version`, {
encoding: "utf-8",
}).split(".")[0];
if (npmVersion < metaManifest.requiredNPMVersion) {
console.error(
`⚠️ NPM ${metaManifest.requiredNPMVersion} or later ` +
`required, you are on ${npmVersion}`
);
exitCode = 1;
}
} catch (error) {
console.error(`⚠️ Error ${error} when trying to find NPM version`);
exitCode = 1;
}
return exitCode;
}
function ANSIBold(string) {
return `\x1b[1m${string}\x1b[0m`;
}
function ANSIInvert(string) {
return `\x1b[7m${string}\x1b[27m`;
}
module.exports = {
platformize,
checkVersions,
ANSIBold,
ANSIInvert,
};