@badisi/latest-version 8.0.1 → 8.0.3
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/cli.js +33 -33
- package/package.json +5 -6
package/cli.js
CHANGED
|
@@ -23,23 +23,23 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/cli.ts
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var import_index = __toESM(require("./index"));
|
|
26
|
+
var import_node_util = require("node:util");
|
|
27
|
+
var import_node_fs = require("node:fs");
|
|
28
|
+
var import_node_path = require("node:path");
|
|
30
29
|
var import_major = __toESM(require("semver/functions/major"));
|
|
31
30
|
var import_diff = __toESM(require("semver/functions/diff"));
|
|
31
|
+
var import_index = __toESM(require("./index"));
|
|
32
32
|
var colorizeDiff = (from, to) => {
|
|
33
33
|
const toParts = to.split(".");
|
|
34
34
|
const diffIndex = from.split(".").findIndex((part, i) => part !== toParts[i]);
|
|
35
35
|
if (diffIndex !== -1) {
|
|
36
|
-
let color =
|
|
36
|
+
let color = "magenta";
|
|
37
37
|
if (toParts[0] !== "0") {
|
|
38
|
-
color = diffIndex === 0 ?
|
|
38
|
+
color = diffIndex === 0 ? "red" : diffIndex === 1 ? "cyan" : "green";
|
|
39
39
|
}
|
|
40
40
|
const start = toParts.slice(0, diffIndex).join(".");
|
|
41
41
|
const mid = diffIndex === 0 ? "" : ".";
|
|
42
|
-
const end = color
|
|
42
|
+
const end = (0, import_node_util.styleText)(color, toParts.slice(diffIndex).join("."));
|
|
43
43
|
return `${start}${mid}${end}`;
|
|
44
44
|
}
|
|
45
45
|
return to;
|
|
@@ -49,15 +49,15 @@ var columnCellRenderer = (column, row) => {
|
|
|
49
49
|
const gap = text.length < column.maxLength ? " ".repeat(column.maxLength - text.length) : "";
|
|
50
50
|
switch (column.attrName) {
|
|
51
51
|
case "name":
|
|
52
|
-
text = (0,
|
|
52
|
+
text = (0, import_node_util.styleText)("yellow", text);
|
|
53
53
|
break;
|
|
54
54
|
case "installed":
|
|
55
55
|
case "separator":
|
|
56
|
-
text = (0,
|
|
56
|
+
text = (0, import_node_util.styleText)("blue", text);
|
|
57
57
|
break;
|
|
58
58
|
case "location":
|
|
59
59
|
case "tagOrRange":
|
|
60
|
-
text = (0,
|
|
60
|
+
text = (0, import_node_util.styleText)("gray", text);
|
|
61
61
|
break;
|
|
62
62
|
case "wanted":
|
|
63
63
|
text = colorizeDiff(row.installed, text);
|
|
@@ -75,17 +75,17 @@ var columnCellRenderer = (column, row) => {
|
|
|
75
75
|
var columnHeaderRenderer = (column) => {
|
|
76
76
|
const text = column.label;
|
|
77
77
|
const gap = text.length < column.maxLength ? " ".repeat(column.maxLength - text.length) : "";
|
|
78
|
-
return column.align === "right" ? `${gap}${(0,
|
|
78
|
+
return column.align === "right" ? `${gap}${(0, import_node_util.styleText)("underline", text)}` : `${(0, import_node_util.styleText)("underline", text)}${gap}`;
|
|
79
79
|
};
|
|
80
|
-
var drawBox = (lines, color =
|
|
81
|
-
const maxLineWidth = lines.reduce((max, row) => Math.max(max, (0,
|
|
82
|
-
console.log(color
|
|
80
|
+
var drawBox = (lines, color = "yellow", horizontalPadding = 3) => {
|
|
81
|
+
const maxLineWidth = lines.reduce((max, row) => Math.max(max, (0, import_node_util.stripVTControlCharacters)(row).length), 0);
|
|
82
|
+
console.log((0, import_node_util.styleText)(color, `\u250C${"\u2500".repeat(maxLineWidth + horizontalPadding * 2)}\u2510`));
|
|
83
83
|
lines.forEach((row) => {
|
|
84
84
|
const padding = " ".repeat(horizontalPadding);
|
|
85
|
-
const fullRow = `${row}${" ".repeat(maxLineWidth - (0,
|
|
86
|
-
console.log(`${color
|
|
85
|
+
const fullRow = `${row}${" ".repeat(maxLineWidth - (0, import_node_util.stripVTControlCharacters)(row).length)}`;
|
|
86
|
+
console.log(`${(0, import_node_util.styleText)(color, "\u2502")}${padding}${fullRow}${padding}${(0, import_node_util.styleText)(color, "\u2502")}`);
|
|
87
87
|
});
|
|
88
|
-
console.log(color
|
|
88
|
+
console.log((0, import_node_util.styleText)(color, `\u2514${"\u2500".repeat(maxLineWidth + horizontalPadding * 2)}\u2518`));
|
|
89
89
|
};
|
|
90
90
|
var getTableColumns = (rows) => {
|
|
91
91
|
const columns = [
|
|
@@ -171,29 +171,29 @@ var displayTable = (latestVersionPackages) => {
|
|
|
171
171
|
const items = rows.filter((row) => row.group === groupType).sort((a, b) => a.name > b.name ? 1 : -1);
|
|
172
172
|
return !items.length ? [] : [
|
|
173
173
|
"",
|
|
174
|
-
color
|
|
174
|
+
(0, import_node_util.styleText)(color, `${(0, import_node_util.styleText)("bold", title)} ${(0, import_node_util.styleText)("italic", `(${description})`)}`),
|
|
175
175
|
...items.map((row) => columns.map((column) => columnCellRenderer(column, row)).join(" ".repeat(columnGap)))
|
|
176
176
|
];
|
|
177
177
|
};
|
|
178
178
|
drawBox([
|
|
179
179
|
"",
|
|
180
|
-
hasUpdates ? (0,
|
|
180
|
+
hasUpdates ? (0, import_node_util.styleText)("yellow", "Important updates are available.") : void 0,
|
|
181
181
|
hasUpdates ? "" : void 0,
|
|
182
182
|
columns.map(columnHeaderRenderer).join(" ".repeat(columnGap)),
|
|
183
|
-
...getGroupLines("patch",
|
|
184
|
-
...getGroupLines("minor",
|
|
185
|
-
...getGroupLines("major",
|
|
186
|
-
...getGroupLines("majorVersionZero",
|
|
187
|
-
...getGroupLines("unknown",
|
|
183
|
+
...getGroupLines("patch", "green", "Patch", "backwards-compatible bug fixes"),
|
|
184
|
+
...getGroupLines("minor", "cyan", "Minor", "backwards-compatible features"),
|
|
185
|
+
...getGroupLines("major", "red", "Major", "potentially breaking API changes"),
|
|
186
|
+
...getGroupLines("majorVersionZero", "magenta", "Major version zero", "not stable, anything may change"),
|
|
187
|
+
...getGroupLines("unknown", "blue", "Missing", "not installed"),
|
|
188
188
|
""
|
|
189
189
|
].filter((line) => line !== void 0));
|
|
190
190
|
} else {
|
|
191
|
-
console.log((0,
|
|
191
|
+
console.log((0, import_node_util.styleText)("green", "\u{1F389} Packages are up-to-date"));
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
194
|
var checkVersions = async (packages, skipMissing, options = { useCache: true }) => {
|
|
195
195
|
const ora = (await import("ora")).default;
|
|
196
|
-
const spinner = ora({ text: (0,
|
|
196
|
+
const spinner = ora({ text: (0, import_node_util.styleText)("cyan", "Checking versions...") });
|
|
197
197
|
spinner.start();
|
|
198
198
|
let latestVersionPackages = await (0, import_index.default)(packages, options);
|
|
199
199
|
if (skipMissing) {
|
|
@@ -207,16 +207,16 @@ void (async () => {
|
|
|
207
207
|
const skipMissing = args.includes("--skip-missing");
|
|
208
208
|
args = args.filter((arg) => !arg.startsWith("-"));
|
|
209
209
|
if (args.length === 1 && args[0].endsWith("package.json")) {
|
|
210
|
-
if ((0,
|
|
211
|
-
process.chdir((0,
|
|
212
|
-
await checkVersions(JSON.parse((0,
|
|
210
|
+
if ((0, import_node_fs.existsSync)(args[0])) {
|
|
211
|
+
process.chdir((0, import_node_path.dirname)(args[0]));
|
|
212
|
+
await checkVersions(JSON.parse((0, import_node_fs.readFileSync)(args[0]).toString()), skipMissing);
|
|
213
213
|
} else {
|
|
214
|
-
console.log((0,
|
|
214
|
+
console.log((0, import_node_util.styleText)("cyan", "No package.json file were found"));
|
|
215
215
|
}
|
|
216
216
|
} else {
|
|
217
217
|
let localPkgJson;
|
|
218
|
-
if ((0,
|
|
219
|
-
localPkgJson = JSON.parse((0,
|
|
218
|
+
if ((0, import_node_fs.existsSync)("package.json")) {
|
|
219
|
+
localPkgJson = JSON.parse((0, import_node_fs.readFileSync)("package.json").toString());
|
|
220
220
|
}
|
|
221
221
|
if (args.length) {
|
|
222
222
|
args = args.map((arg) => {
|
|
@@ -233,7 +233,7 @@ void (async () => {
|
|
|
233
233
|
} else if (localPkgJson) {
|
|
234
234
|
await checkVersions(localPkgJson, skipMissing);
|
|
235
235
|
} else {
|
|
236
|
-
console.log((0,
|
|
236
|
+
console.log((0, import_node_util.styleText)("cyan", "No packages were found"));
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@badisi/latest-version",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.3",
|
|
4
4
|
"description": "Get latest versions of packages",
|
|
5
5
|
"homepage": "https://github.com/Badisi/latest-version",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,13 +41,12 @@
|
|
|
41
41
|
"module"
|
|
42
42
|
],
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": ">= 20"
|
|
44
|
+
"node": ">= 20.12.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@colors/colors": "^1.6.0",
|
|
48
47
|
"global-dirs": "3.0.1",
|
|
49
|
-
"ora": "^9.
|
|
50
|
-
"registry-auth-token": "^5.1.
|
|
51
|
-
"semver": "^7.7.
|
|
48
|
+
"ora": "^9.3.0",
|
|
49
|
+
"registry-auth-token": "^5.1.1",
|
|
50
|
+
"semver": "^7.7.4"
|
|
52
51
|
}
|
|
53
52
|
}
|