@opscompass/opscompass-cli 1.0.46 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/colors.js +5 -4
- package/credentials.js +20 -29
- package/environment/current.js +6 -6
- package/environment/demo.js +6 -6
- package/environment/dev.js +6 -6
- package/environment/local.js +6 -6
- package/environment/production.js +6 -6
- package/error.js +1 -1
- package/index.js +42 -23
- package/lib/cliHelpers.js +34 -15
- package/lib/consts.js +2 -11
- package/lib/homeInteraction.js +21 -22
- package/lib/maskValues.js +17 -17
- package/lib/parseMetrics.js +25 -21
- package/lib/pgpTools.js +8 -10
- package/lib/utils.js +15 -19
- package/login.js +90 -40
- package/modules/accounts.js +32 -26
- package/modules/compliance.js +75 -76
- package/modules/data-gathering-scripts.js +41 -41
- package/modules/defaults.js +12 -12
- package/modules/expiration-info.js +54 -25
- package/modules/license-manager/microsoft.js +95 -72
- package/modules/license-manager/nutanix.js +31 -22
- package/modules/license-manager/vcenter.js +31 -22
- package/modules/license-manager.js +89 -91
- package/modules/resources.js +140 -70
- package/modules.js +31 -15
- package/oauth.js +2 -2
- package/opscompass.js +8 -9
- package/package.json +3 -2
- package/updates.js +58 -48
package/updates.js
CHANGED
|
@@ -1,71 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import pkg from "./package.json" with { type: "json" };
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
import { exec } from "child_process";
|
|
4
|
+
import { yellowText, redText } from "./colors.js";
|
|
5
|
+
import { opscompassHome } from "./environment/current.js";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
8
8
|
|
|
9
9
|
/* versionCheck sends a command to the terminal to check the latest package version and compares it to the current version specified in package.json, prompting the user to upgrade if it is out of date. */
|
|
10
10
|
/* This is turned off by default when using the local environment. To turn it on for dev purposes, comment out isLocal check in index.js */
|
|
11
11
|
|
|
12
12
|
function versionCheck() {
|
|
13
13
|
if (global.isOffline) {
|
|
14
|
-
|
|
14
|
+
console.error(yellowText, "Using CLI in offline mode");
|
|
15
|
+
return Promise.resolve();
|
|
15
16
|
}
|
|
16
17
|
const checkPath = path.join(opscompassHome, ".versioncheck");
|
|
17
18
|
|
|
18
|
-
// If .versioncheck exists and is less than 24 hours old, return
|
|
19
|
+
// If .versioncheck exists and is less than 24 hours old, return the cached version
|
|
19
20
|
if (fs.existsSync(checkPath)) {
|
|
20
21
|
const stats = fs.statSync(checkPath);
|
|
21
22
|
const now = Date.now();
|
|
22
23
|
const mtime = new Date(stats.mtime).getTime();
|
|
23
24
|
const hours24 = 24 * 60 * 60 * 1000;
|
|
24
25
|
if (now - mtime < hours24) {
|
|
25
|
-
|
|
26
|
+
try {
|
|
27
|
+
const cachedVersionData = fs.readFileSync(checkPath, "utf8").trim();
|
|
28
|
+
const versionObject = JSON.parse(cachedVersionData);
|
|
29
|
+
return Promise.resolve(versionObject);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
// If we can't read or parse the file, fall through to do a fresh check
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
// Remove the existing .versioncheck file since we need to check the version
|
|
37
|
+
try {
|
|
38
|
+
fs.unlinkSync(checkPath);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
// Ignore errors when removing the file
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Return a Promise that resolves when version check completes
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
const environmentSpecificPackageVersion = `npm view ${pkg.name} version`;
|
|
46
|
+
/* latestVersion is the standard output(stdout)
|
|
47
|
+
This is usually fast, but it can hang, so we set a timeout.
|
|
48
|
+
On error, we just resolve without doing anything further.
|
|
49
|
+
*/
|
|
50
|
+
exec(
|
|
51
|
+
environmentSpecificPackageVersion,
|
|
52
|
+
{ timeout: 6000 },
|
|
53
|
+
(error, latestVersion, stderr) => {
|
|
54
|
+
if (error) {
|
|
55
|
+
if (error.killed) {
|
|
56
|
+
console.error(yellowText, "CLI Version check warning: timed out.");
|
|
57
|
+
} else {
|
|
58
|
+
console.error(redText, `CLI Version check error: ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
resolve();
|
|
61
|
+
return;
|
|
40
62
|
}
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
63
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// If .versioncheck doesn't exist, create it
|
|
49
|
-
fs.closeSync(fs.openSync(checkPath, "w"));
|
|
50
|
-
}
|
|
64
|
+
const result = {
|
|
65
|
+
pkg: pkg.name,
|
|
66
|
+
latest: latestVersion.trim(),
|
|
67
|
+
};
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
);
|
|
69
|
+
// Update the .versioncheck file with the versions after successful check
|
|
70
|
+
try {
|
|
71
|
+
fs.writeFileSync(checkPath, JSON.stringify(result, null, 2) + "\n");
|
|
72
|
+
} catch (err) {
|
|
73
|
+
// Ignore errors when writing the version file
|
|
74
|
+
}
|
|
75
|
+
resolve(result);
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
});
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
|
|
70
|
-
versionCheck,
|
|
71
|
-
};
|
|
81
|
+
export { versionCheck };
|