nuxt-gin-tools 0.3.0 → 0.3.2
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/package.json +9 -9
- package/src/cli/commands/update.js +73 -39
- package/src/cli/terminal-ui.js +135 -62
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-gin-tools",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "This project is used as a dependency for [nuxt-gin-starter](https://github.com/RapboyGao/nuxt-gin-starter.git)",
|
|
5
5
|
"bin": {
|
|
6
6
|
"nuxt-gin": "index.js"
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
"publish": "npm publish --access public"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"7zip-min": "^
|
|
17
|
-
"chalk": "^5.
|
|
18
|
-
"chokidar": "^
|
|
19
|
-
"concurrently": "^9.2.
|
|
16
|
+
"7zip-min": "^3.0.1",
|
|
17
|
+
"chalk": "^5.6.2",
|
|
18
|
+
"chokidar": "^5.0.0",
|
|
19
|
+
"concurrently": "^9.2.1",
|
|
20
20
|
"fast-glob": "^3.3.3",
|
|
21
|
-
"fs-extra": "^11.3.
|
|
21
|
+
"fs-extra": "^11.3.4",
|
|
22
22
|
"jiti": "^2.6.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/fs-extra": "^11.0.4",
|
|
26
|
-
"@types/node": "^
|
|
27
|
-
"nuxt": "^4.
|
|
26
|
+
"@types/node": "^25.5.0",
|
|
27
|
+
"nuxt": "^4.4.2",
|
|
28
28
|
"ts-node": "^10.9.2",
|
|
29
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.9.3"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,53 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
15
|
exports.update = update;
|
|
7
16
|
const concurrently_1 = __importDefault(require("concurrently"));
|
|
17
|
+
const promises_1 = require("node:readline/promises");
|
|
8
18
|
const package_manager_1 = require("../../config/package-manager");
|
|
9
19
|
const nuxt_gin_1 = require("../../nuxt-gin");
|
|
10
20
|
const terminal_ui_1 = require("../terminal-ui");
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!resolvedOptions.skipNode) {
|
|
24
|
-
actions.push(`updated Node dependencies with ${packageManager} (${latest ? "latest" : "conservative"} mode)`);
|
|
25
|
-
commands.push({
|
|
26
|
-
command: (0, package_manager_1.packageManagerUpdateCommand)(packageManager, latest),
|
|
27
|
-
name: packageManager,
|
|
28
|
-
prefixColor: "magenta",
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (!resolvedOptions.skipGo) {
|
|
32
|
-
actions.push(`updated Go modules with ${latest ? "latest" : "patch"} strategy`);
|
|
33
|
-
commands.push({
|
|
34
|
-
command: latest ? "go get -u ./... && go mod tidy" : "go get -u=patch ./... && go mod tidy",
|
|
35
|
-
name: "go",
|
|
36
|
-
prefixColor: "green",
|
|
21
|
+
function resolveLatestPreference(options) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (typeof options.latest === "boolean") {
|
|
24
|
+
return options.latest;
|
|
25
|
+
}
|
|
26
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
27
|
+
(0, terminal_ui_1.printCommandWarn)("Non-interactive terminal detected, defaulting update mode to conservative");
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const rl = (0, promises_1.createInterface)({
|
|
31
|
+
input: process.stdin,
|
|
32
|
+
output: process.stdout,
|
|
37
33
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
34
|
+
try {
|
|
35
|
+
const answer = yield rl.question("Use latest dependency upgrade strategy? [y/N] ");
|
|
36
|
+
const normalized = answer.trim().toLowerCase();
|
|
37
|
+
return ["y", "yes"].includes(normalized);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
rl.close();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function update() {
|
|
45
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
(0, terminal_ui_1.printCommandBanner)("update", "Update Node and Go dependencies");
|
|
48
|
+
const projectConfig = (0, nuxt_gin_1.resolveNuxtGinProjectConfig)();
|
|
49
|
+
for (const warning of projectConfig.warnings) {
|
|
50
|
+
(0, terminal_ui_1.printCommandWarn)(`[config] ${warning}`);
|
|
51
|
+
}
|
|
52
|
+
const resolvedOptions = (0, nuxt_gin_1.mergeDefined)(Object.assign({ packageManager: "auto" }, ((_a = projectConfig.config.update) !== null && _a !== void 0 ? _a : {})), options);
|
|
53
|
+
const latest = yield resolveLatestPreference(resolvedOptions);
|
|
54
|
+
const actions = [];
|
|
55
|
+
const commands = [];
|
|
56
|
+
const packageManager = (0, package_manager_1.resolvePackageManager)((_b = resolvedOptions.packageManager) !== null && _b !== void 0 ? _b : "auto");
|
|
57
|
+
if (!resolvedOptions.skipNode) {
|
|
58
|
+
actions.push(`updated Node dependencies with ${packageManager} (${latest ? "latest" : "conservative"} mode)`);
|
|
59
|
+
commands.push({
|
|
60
|
+
command: (0, package_manager_1.packageManagerUpdateCommand)(packageManager, latest),
|
|
61
|
+
name: packageManager,
|
|
62
|
+
prefixColor: "magenta",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (!resolvedOptions.skipGo) {
|
|
66
|
+
actions.push(`updated Go modules with ${latest ? "latest" : "patch"} strategy`);
|
|
67
|
+
commands.push({
|
|
68
|
+
command: latest ? "go get -u ./... && go mod tidy" : "go get -u=patch ./... && go mod tidy",
|
|
69
|
+
name: "go",
|
|
70
|
+
prefixColor: "green",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (resolvedOptions.skipNode) {
|
|
74
|
+
actions.push("skipped Node dependency update");
|
|
75
|
+
}
|
|
76
|
+
if (resolvedOptions.skipGo) {
|
|
77
|
+
actions.push("skipped Go dependency update");
|
|
78
|
+
}
|
|
79
|
+
if (commands.length === 0) {
|
|
80
|
+
(0, terminal_ui_1.printCommandWarn)("No update targets selected, nothing to do");
|
|
81
|
+
(0, terminal_ui_1.printCommandSummary)("update", actions.length > 0 ? actions : ["nothing was executed"]);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
yield (0, concurrently_1.default)(commands).result;
|
|
51
85
|
(0, terminal_ui_1.printCommandSuccess)("update", "Dependency update completed");
|
|
52
86
|
(0, terminal_ui_1.printCommandSummary)("update", actions);
|
|
53
87
|
});
|
package/src/cli/terminal-ui.js
CHANGED
|
@@ -11,8 +11,10 @@ exports.printCommandError = printCommandError;
|
|
|
11
11
|
exports.printCommandLog = printCommandLog;
|
|
12
12
|
exports.printCommandSummary = printCommandSummary;
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const MIN_WIDTH = 60;
|
|
15
|
+
const DEFAULT_WIDTH = 96;
|
|
16
|
+
const INDENT = " ";
|
|
17
|
+
function printLine(message = "", method = "log") {
|
|
16
18
|
if (method === "warn") {
|
|
17
19
|
console.warn(message);
|
|
18
20
|
return;
|
|
@@ -23,8 +25,85 @@ function printLine(message, method = "log") {
|
|
|
23
25
|
}
|
|
24
26
|
console.log(message);
|
|
25
27
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
+
function getTerminalWidth() {
|
|
29
|
+
const detected = typeof process.stdout.columns === "number" ? process.stdout.columns : 0;
|
|
30
|
+
return Math.max(MIN_WIDTH, detected || DEFAULT_WIDTH);
|
|
31
|
+
}
|
|
32
|
+
function stripAnsi(value) {
|
|
33
|
+
return value.replace(/\u001B\[[0-9;]*m/g, "");
|
|
34
|
+
}
|
|
35
|
+
function wrapText(value, width) {
|
|
36
|
+
const normalized = value.replace(/\r/g, "");
|
|
37
|
+
const rawLines = normalized.split("\n");
|
|
38
|
+
const wrapped = [];
|
|
39
|
+
for (const rawLine of rawLines) {
|
|
40
|
+
const line = rawLine.trimEnd();
|
|
41
|
+
if (!line) {
|
|
42
|
+
wrapped.push("");
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
let current = "";
|
|
46
|
+
for (const word of line.split(/\s+/)) {
|
|
47
|
+
if (!word) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!current) {
|
|
51
|
+
if (stripAnsi(word).length <= width) {
|
|
52
|
+
current = word;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
let remainder = word;
|
|
56
|
+
while (stripAnsi(remainder).length > width) {
|
|
57
|
+
wrapped.push(remainder.slice(0, width));
|
|
58
|
+
remainder = remainder.slice(width);
|
|
59
|
+
}
|
|
60
|
+
current = remainder;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const candidate = `${current} ${word}`;
|
|
64
|
+
if (stripAnsi(candidate).length <= width) {
|
|
65
|
+
current = candidate;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
wrapped.push(current);
|
|
69
|
+
if (stripAnsi(word).length <= width) {
|
|
70
|
+
current = word;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
let remainder = word;
|
|
74
|
+
while (stripAnsi(remainder).length > width) {
|
|
75
|
+
wrapped.push(remainder.slice(0, width));
|
|
76
|
+
remainder = remainder.slice(width);
|
|
77
|
+
}
|
|
78
|
+
current = remainder;
|
|
79
|
+
}
|
|
80
|
+
if (current) {
|
|
81
|
+
wrapped.push(current);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return wrapped;
|
|
85
|
+
}
|
|
86
|
+
function printWrapped(prefix, message, options = {}) {
|
|
87
|
+
var _a, _b, _c;
|
|
88
|
+
const method = (_a = options.method) !== null && _a !== void 0 ? _a : "log";
|
|
89
|
+
const width = getTerminalWidth();
|
|
90
|
+
const visiblePrefix = stripAnsi(prefix).length;
|
|
91
|
+
const visibleContinuationPrefix = stripAnsi((_b = options.continuationPrefix) !== null && _b !== void 0 ? _b : prefix).length;
|
|
92
|
+
const firstWidth = Math.max(12, width - visiblePrefix);
|
|
93
|
+
const continuationWidth = Math.max(12, width - visibleContinuationPrefix);
|
|
94
|
+
const lines = wrapText(message, firstWidth);
|
|
95
|
+
if (lines.length === 0) {
|
|
96
|
+
printLine(prefix.trimEnd(), method);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
printLine(`${prefix}${lines[0]}`, method);
|
|
100
|
+
for (const line of lines.slice(1)) {
|
|
101
|
+
printLine(`${(_c = options.continuationPrefix) !== null && _c !== void 0 ? _c : " ".repeat(visiblePrefix)}${line}`, method);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function divider(color) {
|
|
105
|
+
const width = Math.max(20, getTerminalWidth() - 2);
|
|
106
|
+
return color(`┄`.repeat(width));
|
|
28
107
|
}
|
|
29
108
|
function formatClock() {
|
|
30
109
|
return new Date().toLocaleTimeString("en-GB", {
|
|
@@ -34,85 +113,79 @@ function formatClock() {
|
|
|
34
113
|
hour12: false,
|
|
35
114
|
});
|
|
36
115
|
}
|
|
37
|
-
function padText(value, width) {
|
|
38
|
-
const text = value.length > width ? `${value.slice(0, Math.max(0, width - 1))}…` : value;
|
|
39
|
-
return text + " ".repeat(Math.max(0, width - text.length));
|
|
40
|
-
}
|
|
41
|
-
function sectionBorder(color) {
|
|
42
|
-
return color(`╭${repeat("─", TERMINAL_WIDTH - 2)}╮`);
|
|
43
|
-
}
|
|
44
|
-
function sectionFooter(color) {
|
|
45
|
-
return color(`╰${repeat("─", TERMINAL_WIDTH - 2)}╯`);
|
|
46
|
-
}
|
|
47
|
-
function sectionBody(text, color) {
|
|
48
|
-
return color(`│ ${padText(text, TERMINAL_WIDTH - 4)} │`);
|
|
49
|
-
}
|
|
50
|
-
function printSection(lines, options) {
|
|
51
|
-
var _a;
|
|
52
|
-
if (lines.length === 0) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const method = (_a = options.method) !== null && _a !== void 0 ? _a : "log";
|
|
56
|
-
printLine(options.color(``), method);
|
|
57
|
-
printLine(sectionBorder(options.color), method);
|
|
58
|
-
for (const line of lines) {
|
|
59
|
-
printLine(sectionBody(line, options.color), method);
|
|
60
|
-
}
|
|
61
|
-
printLine(sectionFooter(options.color), method);
|
|
62
|
-
}
|
|
63
116
|
function commandChip(command) {
|
|
64
|
-
return chalk_1.default.
|
|
65
|
-
}
|
|
66
|
-
function
|
|
67
|
-
return chalk_1.default.
|
|
117
|
+
return chalk_1.default.bold.blueBright(`[${command.toUpperCase()}]`);
|
|
118
|
+
}
|
|
119
|
+
function timeChip(text) {
|
|
120
|
+
return chalk_1.default.gray(`[${text}]`);
|
|
121
|
+
}
|
|
122
|
+
function printBlock(title, subtitle, color, method = "log") {
|
|
123
|
+
const top = color(`┌ ${title}`);
|
|
124
|
+
const bodyPrefix = color("│ ");
|
|
125
|
+
const bottom = color("└");
|
|
126
|
+
printLine("", method);
|
|
127
|
+
printLine(top, method);
|
|
128
|
+
printWrapped(bodyPrefix, subtitle, {
|
|
129
|
+
method,
|
|
130
|
+
continuationPrefix: color("│ "),
|
|
131
|
+
});
|
|
132
|
+
printLine(bottom, method);
|
|
68
133
|
}
|
|
69
134
|
function printCommandBanner(command, subtitle) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const detail = chalk_1.default.cyanBright(subtitle);
|
|
73
|
-
printLine("");
|
|
74
|
-
printSection([title, detail], {
|
|
75
|
-
color: chalk_1.default.blueBright,
|
|
76
|
-
});
|
|
135
|
+
const title = `${chalk_1.default.bold("nuxt-gin-tools")} ${commandChip(command)} ${timeChip(formatClock())}`;
|
|
136
|
+
printBlock(title, chalk_1.default.cyanBright(subtitle), chalk_1.default.blueBright);
|
|
77
137
|
}
|
|
78
138
|
function printCommandSuccess(command, message) {
|
|
79
|
-
|
|
139
|
+
const prefix = `${chalk_1.default.greenBright("◆")} ${chalk_1.default.bold.green(command)} `;
|
|
140
|
+
const continuationPrefix = `${" ".repeat(stripAnsi(prefix).length)}${INDENT}`;
|
|
141
|
+
printWrapped(prefix, chalk_1.default.green(message), {
|
|
142
|
+
continuationPrefix,
|
|
143
|
+
});
|
|
80
144
|
}
|
|
81
145
|
function printCommandInfo(label, message) {
|
|
82
|
-
const
|
|
83
|
-
|
|
146
|
+
const prefix = `${chalk_1.default.bold.cyan(`[${label.toUpperCase()}]`)} `;
|
|
147
|
+
const continuationPrefix = `${" ".repeat(stripAnsi(prefix).length)}${INDENT}`;
|
|
148
|
+
printWrapped(prefix, chalk_1.default.cyanBright(message), {
|
|
149
|
+
continuationPrefix,
|
|
150
|
+
});
|
|
84
151
|
}
|
|
85
152
|
function printCommandWarn(message) {
|
|
86
|
-
|
|
87
|
-
color: chalk_1.default.yellow,
|
|
88
|
-
method: "warn",
|
|
89
|
-
});
|
|
153
|
+
printBlock(chalk_1.default.bold.yellow("warning"), chalk_1.default.yellow(message), chalk_1.default.yellow, "warn");
|
|
90
154
|
}
|
|
91
155
|
function printCommandError(message, error) {
|
|
92
156
|
const detail = error instanceof Error ? error.message : error !== undefined ? String(error) : "";
|
|
93
|
-
|
|
157
|
+
printBlock(chalk_1.default.bold.red("error"), chalk_1.default.redBright(message), chalk_1.default.red, "error");
|
|
94
158
|
if (detail) {
|
|
95
|
-
|
|
159
|
+
const prefix = `${chalk_1.default.red("│")} `;
|
|
160
|
+
printWrapped(prefix, chalk_1.default.red(detail), {
|
|
161
|
+
method: "error",
|
|
162
|
+
continuationPrefix: prefix,
|
|
163
|
+
});
|
|
164
|
+
printLine(chalk_1.default.red("└"), "error");
|
|
96
165
|
}
|
|
97
|
-
printSection(lines, {
|
|
98
|
-
color: chalk_1.default.red,
|
|
99
|
-
method: "error",
|
|
100
|
-
});
|
|
101
166
|
}
|
|
102
167
|
function printCommandLog(label, message) {
|
|
103
|
-
const
|
|
104
|
-
|
|
168
|
+
const prefix = `${chalk_1.default.bold.magenta(`[${label}]`)} `;
|
|
169
|
+
const continuationPrefix = `${" ".repeat(stripAnsi(prefix).length)}${INDENT}`;
|
|
170
|
+
printWrapped(prefix, chalk_1.default.white(message), {
|
|
171
|
+
continuationPrefix,
|
|
172
|
+
});
|
|
105
173
|
}
|
|
106
174
|
function printCommandSummary(command, items) {
|
|
107
175
|
const normalizedItems = items.map((item) => item.trim()).filter(Boolean);
|
|
108
176
|
if (normalizedItems.length === 0) {
|
|
109
177
|
return;
|
|
110
178
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
color: chalk_1.default.magentaBright,
|
|
179
|
+
printLine("");
|
|
180
|
+
printLine(divider(chalk_1.default.magentaBright));
|
|
181
|
+
printWrapped(`${chalk_1.default.magentaBright("■")} `, chalk_1.default.bold.magenta(`${command} summary`) +
|
|
182
|
+
chalk_1.default.gray(` (${normalizedItems.length} item${normalizedItems.length > 1 ? "s" : ""})`), {
|
|
183
|
+
continuationPrefix: " ",
|
|
117
184
|
});
|
|
185
|
+
for (const item of normalizedItems) {
|
|
186
|
+
printWrapped(`${chalk_1.default.magenta("•")} `, chalk_1.default.white(item), {
|
|
187
|
+
continuationPrefix: " ",
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
printLine(divider(chalk_1.default.magentaBright));
|
|
118
191
|
}
|