nuxt-gin-tools 0.2.21 → 0.2.23
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/README.md +91 -19
- package/commands/cleanup.d.ts +7 -4
- package/commands/cleanup.js +34 -22
- package/commands/dev-go.js +8 -8
- package/commands/develop.js +23 -0
- package/commands/pack.js +52 -6
- package/commands/postinstall.d.ts +5 -1
- package/commands/postinstall.js +30 -9
- package/commands/update.d.ts +4 -2
- package/commands/update.js +22 -4
- package/index.js +22 -12
- package/package.json +1 -1
- package/src/cli-options.d.ts +1 -0
- package/src/cli-options.js +15 -0
- package/src/pack.d.ts +8 -0
- package/src/package-manager.d.ts +7 -0
- package/src/package-manager.js +39 -0
- package/src/terminal-ui.d.ts +7 -0
- package/src/terminal-ui.js +118 -0
- package/src/utils.js +3 -3
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ Quick Jump:
|
|
|
24
24
|
- 🧩 `pack.config.ts` support with typed config helper
|
|
25
25
|
- 🛡️ Config validation with `warn` and `error` feedback
|
|
26
26
|
- 🔧 Useful CLI switches for partial workflows like `--skip-go`
|
|
27
|
+
- 🎨 Colorful command banners and clearer terminal feedback
|
|
28
|
+
- 📋 Fancy end-of-command summaries that show what just changed
|
|
27
29
|
|
|
28
30
|
### 📦 Install
|
|
29
31
|
|
|
@@ -31,6 +33,12 @@ Quick Jump:
|
|
|
31
33
|
pnpm add -D nuxt-gin-tools
|
|
32
34
|
```
|
|
33
35
|
|
|
36
|
+
or
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
bun add -d nuxt-gin-tools
|
|
40
|
+
```
|
|
41
|
+
|
|
34
42
|
### ⚡ Quick Start
|
|
35
43
|
|
|
36
44
|
```bash
|
|
@@ -62,6 +70,7 @@ Runs the local development stack:
|
|
|
62
70
|
|
|
63
71
|
- Nuxt: `npx nuxt dev --port=<nuxtPort> --host`
|
|
64
72
|
- Go: watches files and restarts `go run main.go`
|
|
73
|
+
- prints a styled command banner before startup
|
|
65
74
|
|
|
66
75
|
Flags:
|
|
67
76
|
|
|
@@ -75,41 +84,65 @@ Bootstraps the project:
|
|
|
75
84
|
|
|
76
85
|
- always runs `npx nuxt prepare`
|
|
77
86
|
- if Go is available, also runs `go mod download && go mod tidy`
|
|
87
|
+
- prints a styled command banner before execution
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Generates API code from `openapi.yaml`:
|
|
89
|
+
Options:
|
|
82
90
|
|
|
83
|
-
- Go
|
|
84
|
-
-
|
|
91
|
+
- `--skip-go`: skip Go dependency bootstrap
|
|
92
|
+
- `--skip-nuxt`: skip Nuxt prepare
|
|
85
93
|
|
|
86
94
|
#### `nuxt-gin build`
|
|
87
95
|
|
|
88
96
|
Runs the build-and-pack flow.
|
|
89
97
|
|
|
98
|
+
Terminal output includes:
|
|
99
|
+
|
|
100
|
+
- a styled command banner at startup
|
|
101
|
+
- the final `.7z` archive path after packing
|
|
102
|
+
- the bundle directory path used to assemble the release
|
|
103
|
+
|
|
90
104
|
Flags:
|
|
91
105
|
|
|
92
106
|
- `--skip-go`: skip Go build
|
|
93
107
|
- `--skip-nuxt`: skip Nuxt static build
|
|
108
|
+
- `--skip-build`: skip the build step and only assemble/package existing artifacts
|
|
109
|
+
- `--skip-zip`: skip `.7z` creation and only prepare the bundle directory
|
|
94
110
|
- `--binary-name <name>`: override the Go binary name under `.build/.server`
|
|
95
111
|
|
|
96
112
|
#### `nuxt-gin cleanup`
|
|
97
113
|
|
|
98
114
|
Removes generated temp files and build output.
|
|
99
115
|
|
|
116
|
+
Also prints a styled command banner before cleanup starts.
|
|
117
|
+
|
|
118
|
+
Options:
|
|
119
|
+
|
|
120
|
+
- `--dry-run`: print what would be removed without deleting anything
|
|
121
|
+
|
|
100
122
|
#### `nuxt-gin update`
|
|
101
123
|
|
|
102
124
|
Updates project dependencies with a conservative default strategy:
|
|
103
125
|
|
|
104
|
-
- Node:
|
|
126
|
+
- Node: package manager is controlled by `--package-manager`, default `auto`
|
|
105
127
|
- Go: `go get -u=patch ./... && go mod tidy`
|
|
106
128
|
|
|
107
|
-
|
|
129
|
+
Options:
|
|
108
130
|
|
|
109
|
-
- `--
|
|
131
|
+
- `--package-manager <auto|bun|pnpm|npm>`: package manager selection, default `auto`
|
|
132
|
+
- `--latest <true|false>`: whether to use the aggressive update strategy, default `false`
|
|
110
133
|
- `--skip-go`: skip Go dependency updates
|
|
111
134
|
- `--skip-node`: skip Node dependency updates
|
|
112
135
|
|
|
136
|
+
Examples:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
nuxt-gin update
|
|
140
|
+
nuxt-gin update --package-manager bun --latest true
|
|
141
|
+
nuxt-gin update --package-manager pnpm --latest false
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Also prints a styled command banner before execution.
|
|
145
|
+
|
|
113
146
|
### 🧩 `pack.config.ts` / `pack.config.json`
|
|
114
147
|
|
|
115
148
|
`nuxt-gin build` can auto-load pack config from the project root with this priority:
|
|
@@ -233,15 +266,18 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
233
266
|
### 🖥️ Environment
|
|
234
267
|
|
|
235
268
|
- Node.js
|
|
236
|
-
- pnpm
|
|
269
|
+
- pnpm or bun
|
|
237
270
|
- Go, if you need the Gin side to run
|
|
238
|
-
-
|
|
271
|
+
- no extra generator dependency is required for the current command set
|
|
239
272
|
|
|
240
273
|
### 📝 Notes
|
|
241
274
|
|
|
242
275
|
- 💨 Go hot reload no longer depends on Air
|
|
243
276
|
- 👀 The current watcher model is `chokidar` + restart `go run main.go`
|
|
244
277
|
- 🪟 Packaging uses platform-aware executable naming: Windows defaults to `.exe`, Linux/macOS defaults to no extension
|
|
278
|
+
- 🌈 Main commands print a consistent banner and clearer success/info output in the terminal
|
|
279
|
+
- 📋 Commands also print a styled summary of the actions they performed; long-running dev commands print the startup summary before entering watch mode
|
|
280
|
+
- 📦 Both `pnpm` and `bun` are supported, but one working tree should stick to one package manager at a time
|
|
245
281
|
|
|
246
282
|
---
|
|
247
283
|
|
|
@@ -255,6 +291,8 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
255
291
|
- 🧩 支持 `pack.config.ts`,并提供类型化 helper
|
|
256
292
|
- 🛡️ 对打包配置做校验,区分 `warn` 和 `error`
|
|
257
293
|
- 🔧 支持 `--skip-go` 等局部开发参数
|
|
294
|
+
- 🎨 提供更醒目的彩色命令行 banner 与输出提示
|
|
295
|
+
- 📋 命令结束时会打印更清晰的结果摘要
|
|
258
296
|
|
|
259
297
|
### 📦 安装
|
|
260
298
|
|
|
@@ -262,6 +300,12 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
262
300
|
pnpm add -D nuxt-gin-tools
|
|
263
301
|
```
|
|
264
302
|
|
|
303
|
+
或
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
bun add -d nuxt-gin-tools
|
|
307
|
+
```
|
|
308
|
+
|
|
265
309
|
### ⚡ 快速开始
|
|
266
310
|
|
|
267
311
|
```bash
|
|
@@ -293,6 +337,7 @@ nuxt-gin dev --no-cleanup
|
|
|
293
337
|
|
|
294
338
|
- Nuxt:`npx nuxt dev --port=<nuxtPort> --host`
|
|
295
339
|
- Go:监听文件变化并重启 `go run main.go`
|
|
340
|
+
- 启动前会输出一段样式化 banner
|
|
296
341
|
|
|
297
342
|
参数:
|
|
298
343
|
|
|
@@ -306,41 +351,65 @@ nuxt-gin dev --no-cleanup
|
|
|
306
351
|
|
|
307
352
|
- 总是执行 `npx nuxt prepare`
|
|
308
353
|
- 检测到 Go 后,额外执行 `go mod download && go mod tidy`
|
|
354
|
+
- 执行前会输出一段样式化 banner
|
|
309
355
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
基于 `openapi.yaml` 生成 API 代码:
|
|
356
|
+
参数:
|
|
313
357
|
|
|
314
|
-
- Go
|
|
315
|
-
-
|
|
358
|
+
- `--skip-go`:跳过 Go 依赖初始化
|
|
359
|
+
- `--skip-nuxt`:跳过 Nuxt prepare
|
|
316
360
|
|
|
317
361
|
#### `nuxt-gin build`
|
|
318
362
|
|
|
319
363
|
执行构建与打包流程。
|
|
320
364
|
|
|
365
|
+
命令行输出会额外包含:
|
|
366
|
+
|
|
367
|
+
- 启动时的样式化 banner
|
|
368
|
+
- 打包完成后的 `.7z` 文件绝对路径
|
|
369
|
+
- 组装发布产物时使用的 bundle 目录路径
|
|
370
|
+
|
|
321
371
|
参数:
|
|
322
372
|
|
|
323
373
|
- `--skip-go`:跳过 Go 构建
|
|
324
374
|
- `--skip-nuxt`:跳过 Nuxt 静态构建
|
|
375
|
+
- `--skip-build`:跳过构建阶段,仅组装或打包现有产物
|
|
376
|
+
- `--skip-zip`:跳过 `.7z` 生成,仅准备 bundle 目录
|
|
325
377
|
- `--binary-name <name>`:覆盖 `.build/.server` 下的 Go 二进制名称
|
|
326
378
|
|
|
327
379
|
#### `nuxt-gin cleanup`
|
|
328
380
|
|
|
329
381
|
清理临时文件与构建产物。
|
|
330
382
|
|
|
383
|
+
执行前也会输出一段样式化 banner。
|
|
384
|
+
|
|
385
|
+
参数:
|
|
386
|
+
|
|
387
|
+
- `--dry-run`:只打印将要删除的内容,不真正删除
|
|
388
|
+
|
|
331
389
|
#### `nuxt-gin update`
|
|
332
390
|
|
|
333
391
|
按偏保守的默认策略更新依赖:
|
|
334
392
|
|
|
335
|
-
- Node
|
|
393
|
+
- Node:通过 `--package-manager` 控制,默认值为 `auto`
|
|
336
394
|
- Go:`go get -u=patch ./... && go mod tidy`
|
|
337
395
|
|
|
338
396
|
参数:
|
|
339
397
|
|
|
340
|
-
- `--
|
|
398
|
+
- `--package-manager <auto|bun|pnpm|npm>`:指定包管理器,默认 `auto`
|
|
399
|
+
- `--latest <true|false>`:是否使用更激进的升级策略,默认 `false`
|
|
341
400
|
- `--skip-go`:跳过 Go 依赖更新
|
|
342
401
|
- `--skip-node`:跳过 Node 依赖更新
|
|
343
402
|
|
|
403
|
+
示例:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
nuxt-gin update
|
|
407
|
+
nuxt-gin update --package-manager bun --latest true
|
|
408
|
+
nuxt-gin update --package-manager pnpm --latest false
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
执行前也会输出一段样式化 banner。
|
|
412
|
+
|
|
344
413
|
### 🧩 `pack.config.ts` / `pack.config.json`
|
|
345
414
|
|
|
346
415
|
`nuxt-gin build` 会自动读取项目根目录中的打包配置,优先级如下:
|
|
@@ -464,12 +533,15 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
464
533
|
### 🖥️ 环境依赖
|
|
465
534
|
|
|
466
535
|
- Node.js
|
|
467
|
-
- pnpm
|
|
536
|
+
- pnpm 或 bun
|
|
468
537
|
- Go,若需要运行 Gin 侧开发流程
|
|
469
|
-
-
|
|
538
|
+
- 当前命令集不再依赖额外的代码生成器
|
|
470
539
|
|
|
471
540
|
### 📝 说明
|
|
472
541
|
|
|
473
542
|
- 💨 Go 热更新不再依赖 Air
|
|
474
543
|
- 👀 当前 Go 开发监听方案为 `chokidar` + 重启 `go run main.go`
|
|
475
544
|
- 🪟 打包时会按平台生成可执行文件名:Windows 默认 `.exe`,Linux/macOS 默认无扩展名
|
|
545
|
+
- 🌈 主要命令会输出统一风格的 banner,并提供更清晰的成功 / 信息提示
|
|
546
|
+
- 📋 命令结束后会打印本次实际执行内容的摘要;`dev` 这类常驻命令会在进入监听前先打印启动摘要
|
|
547
|
+
- 📦 同一个工作副本建议固定使用一种包管理器,不要在同一套依赖目录里反复混用 `pnpm` 与 `bun`
|
package/commands/cleanup.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type CleanupOptions = {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
};
|
|
4
|
+
export declare function ifExistsRemove(relativePath: string, options?: CleanupOptions, actions?: string[]): void;
|
|
5
|
+
export declare function cleanUpNuxt(options?: CleanupOptions, actions?: string[]): Promise<void> | Promise<import("concurrently").CloseEvent[]>;
|
|
6
|
+
export declare function cleanUpBuild(options?: CleanupOptions, actions?: string[]): void;
|
|
4
7
|
/**
|
|
5
8
|
* 清理构建目录和临时文件
|
|
6
9
|
*/
|
|
7
|
-
export declare function cleanUp(): Promise<void>;
|
|
10
|
+
export declare function cleanUp(options?: CleanupOptions): Promise<void>;
|
|
8
11
|
export default cleanUp;
|
package/commands/cleanup.js
CHANGED
|
@@ -52,46 +52,58 @@ exports.cleanUp = cleanUp;
|
|
|
52
52
|
const FS = __importStar(require("fs-extra"));
|
|
53
53
|
const Path = __importStar(require("path"));
|
|
54
54
|
const concurrently_1 = __importDefault(require("concurrently"));
|
|
55
|
-
const
|
|
55
|
+
const terminal_ui_1 = require("../src/terminal-ui");
|
|
56
56
|
const cwd = process.cwd();
|
|
57
|
-
|
|
57
|
+
const CLEANUP_PATHS = [
|
|
58
|
+
".build/production",
|
|
59
|
+
"dist",
|
|
60
|
+
".build",
|
|
61
|
+
"tmp",
|
|
62
|
+
"vue/.output",
|
|
63
|
+
".openapi-generator",
|
|
64
|
+
];
|
|
65
|
+
function ifExistsRemove(relativePath, options = {}, actions = []) {
|
|
58
66
|
const absolutePath = Path.resolve(cwd, relativePath);
|
|
59
67
|
if (FS.existsSync(absolutePath)) {
|
|
68
|
+
if (options.dryRun) {
|
|
69
|
+
(0, terminal_ui_1.printCommandInfo)("cleanup", `would remove ${absolutePath}`);
|
|
70
|
+
actions.push(`would remove ${relativePath}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
60
73
|
FS.removeSync(absolutePath);
|
|
74
|
+
actions.push(`removed ${relativePath}`);
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
|
-
function cleanUpNuxt() {
|
|
77
|
+
function cleanUpNuxt(options = {}, actions = []) {
|
|
78
|
+
if (options.dryRun) {
|
|
79
|
+
(0, terminal_ui_1.printCommandInfo)("cleanup", "would run `npx nuxt cleanup`");
|
|
80
|
+
actions.push("would run nuxt cleanup");
|
|
81
|
+
return Promise.resolve();
|
|
82
|
+
}
|
|
83
|
+
actions.push("ran nuxt cleanup");
|
|
64
84
|
return (0, concurrently_1.default)([
|
|
65
85
|
{
|
|
66
86
|
command: "npx nuxt cleanup",
|
|
67
87
|
},
|
|
68
88
|
]).result;
|
|
69
89
|
}
|
|
70
|
-
function cleanUpBuild() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
ifExistsRemove("dist");
|
|
75
|
-
// 清理临时文件
|
|
76
|
-
ifExistsRemove(".build");
|
|
77
|
-
// 清理临时文件
|
|
78
|
-
ifExistsRemove("tmp");
|
|
79
|
-
// 清理 Vue 应用构建输出目录
|
|
80
|
-
ifExistsRemove("vue/.output");
|
|
81
|
-
// 清理 OpenAPI 生成的文件
|
|
82
|
-
ifExistsRemove(".openapi-generator");
|
|
83
|
-
// 清理go.sum
|
|
84
|
-
// ifExistsRemove("go.sum");
|
|
90
|
+
function cleanUpBuild(options = {}, actions = []) {
|
|
91
|
+
for (const path of CLEANUP_PATHS) {
|
|
92
|
+
ifExistsRemove(path, options, actions);
|
|
93
|
+
}
|
|
85
94
|
}
|
|
86
95
|
/**
|
|
87
96
|
* 清理构建目录和临时文件
|
|
88
97
|
*/
|
|
89
98
|
function cleanUp() {
|
|
90
|
-
return __awaiter(this,
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
100
|
+
(0, terminal_ui_1.printCommandBanner)("cleanup", "Remove generated build output and temporary files");
|
|
101
|
+
const actions = [];
|
|
102
|
+
const result = cleanUpNuxt(options, actions);
|
|
103
|
+
cleanUpBuild(options, actions);
|
|
93
104
|
yield result;
|
|
94
|
-
|
|
105
|
+
(0, terminal_ui_1.printCommandSuccess)("cleanup", options.dryRun ? "Dry run completed" : "Temporary files removed");
|
|
106
|
+
(0, terminal_ui_1.printCommandSummary)("cleanup", actions);
|
|
95
107
|
});
|
|
96
108
|
}
|
|
97
109
|
exports.default = cleanUp;
|
package/commands/dev-go.js
CHANGED
|
@@ -15,15 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.startGoDev = startGoDev;
|
|
16
16
|
const child_process_1 = require("child_process");
|
|
17
17
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
18
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
19
18
|
const fs_extra_1 = require("fs-extra");
|
|
20
19
|
const path_1 = require("path");
|
|
21
20
|
const utils_1 = require("../src/utils");
|
|
21
|
+
const terminal_ui_1 = require("../src/terminal-ui");
|
|
22
22
|
const cwd = process.cwd();
|
|
23
23
|
const RESTART_DEBOUNCE_MS = 150;
|
|
24
24
|
const SHUTDOWN_TIMEOUT_MS = 2000;
|
|
25
25
|
const LOG_TAG = "go-watch";
|
|
26
|
-
const GO_WATCH_PREFIX =
|
|
26
|
+
const GO_WATCH_PREFIX = `[${LOG_TAG}]`;
|
|
27
27
|
const serverConfigPath = (0, path_1.join)(cwd, "server.config.json");
|
|
28
28
|
const ginPort = getGinPort();
|
|
29
29
|
function getGinPort() {
|
|
@@ -97,7 +97,7 @@ function loadWatchConfig() {
|
|
|
97
97
|
parsedConfig = JSON.parse((0, fs_extra_1.readFileSync)(configPath, "utf-8"));
|
|
98
98
|
}
|
|
99
99
|
catch (_j) {
|
|
100
|
-
|
|
100
|
+
(0, terminal_ui_1.printCommandWarn)(`${GO_WATCH_PREFIX} invalid watch config JSON, fallback to defaults: ${configPath}`);
|
|
101
101
|
return defaultConfig;
|
|
102
102
|
}
|
|
103
103
|
const includeExt = toStringArray((_a = parsedConfig.includeExt) !== null && _a !== void 0 ? _a : parsedConfig.include_ext)
|
|
@@ -184,7 +184,7 @@ function quote(arg) {
|
|
|
184
184
|
function runGoProcess() {
|
|
185
185
|
const command = `go run ${quote("main.go")}`;
|
|
186
186
|
killGinPortIfNeeded();
|
|
187
|
-
|
|
187
|
+
(0, terminal_ui_1.printCommandLog)(GO_WATCH_PREFIX, `start: ${command}`);
|
|
188
188
|
return (0, child_process_1.spawn)(command, {
|
|
189
189
|
cwd,
|
|
190
190
|
shell: true,
|
|
@@ -241,7 +241,7 @@ function startGoDev() {
|
|
|
241
241
|
const watchRoots = watchConfig.includeDir.length
|
|
242
242
|
? watchConfig.includeDir.map((dir) => (0, path_1.join)(cwd, dir))
|
|
243
243
|
: [cwd];
|
|
244
|
-
|
|
244
|
+
(0, terminal_ui_1.printCommandLog)(GO_WATCH_PREFIX, `watching: ${watchRoots.map((item) => toProjectRelative(item)).join(", ")}`);
|
|
245
245
|
let restarting = false;
|
|
246
246
|
let goProc = runGoProcess();
|
|
247
247
|
let restartTimer = null;
|
|
@@ -266,7 +266,7 @@ function startGoDev() {
|
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
268
|
restarting = true;
|
|
269
|
-
|
|
269
|
+
(0, terminal_ui_1.printCommandLog)(GO_WATCH_PREFIX, `${eventName}: ${relPath}, restarting...`);
|
|
270
270
|
yield stopGoProcess(goProc);
|
|
271
271
|
goProc = runGoProcess();
|
|
272
272
|
restarting = false;
|
|
@@ -277,7 +277,7 @@ function startGoDev() {
|
|
|
277
277
|
.on("change", (filePath) => triggerRestart("change", filePath))
|
|
278
278
|
.on("unlink", (filePath) => triggerRestart("unlink", filePath))
|
|
279
279
|
.on("error", (error) => {
|
|
280
|
-
|
|
280
|
+
(0, terminal_ui_1.printCommandError)(`${GO_WATCH_PREFIX} watcher error`, error);
|
|
281
281
|
});
|
|
282
282
|
const shutdown = () => __awaiter(this, void 0, void 0, function* () {
|
|
283
283
|
if (restartTimer) {
|
|
@@ -300,7 +300,7 @@ function startGoDev() {
|
|
|
300
300
|
if (require.main === module) {
|
|
301
301
|
// 兼容直接执行该文件(例如 node src/dev-go.js)。
|
|
302
302
|
startGoDev().catch((error) => {
|
|
303
|
-
|
|
303
|
+
(0, terminal_ui_1.printCommandError)(`${GO_WATCH_PREFIX} failed to start`, error);
|
|
304
304
|
process.exit(1);
|
|
305
305
|
});
|
|
306
306
|
}
|
package/commands/develop.js
CHANGED
|
@@ -22,6 +22,7 @@ const cleanup_1 = __importDefault(require("./cleanup"));
|
|
|
22
22
|
const postinstall_1 = __importDefault(require("./postinstall"));
|
|
23
23
|
const dev_go_1 = require("./dev-go");
|
|
24
24
|
const utils_1 = require("../src/utils");
|
|
25
|
+
const terminal_ui_1 = require("../src/terminal-ui");
|
|
25
26
|
const cwd = process.cwd();
|
|
26
27
|
const serverConfig = (0, fs_extra_1.readJSONSync)((0, path_1.join)(cwd, "server.config.json"));
|
|
27
28
|
function prepareDevelop() {
|
|
@@ -68,6 +69,8 @@ function runGoDev() {
|
|
|
68
69
|
*/
|
|
69
70
|
function develop() {
|
|
70
71
|
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
72
|
+
(0, terminal_ui_1.printCommandBanner)("dev", "Start Nuxt and Go development workflows");
|
|
73
|
+
const actions = [];
|
|
71
74
|
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
72
75
|
yield prepareDevelop(options);
|
|
73
76
|
// 在开发前确保占用端口被释放
|
|
@@ -76,14 +79,24 @@ function develop() {
|
|
|
76
79
|
options.skipGo ? undefined : serverConfig.ginPort,
|
|
77
80
|
options.skipNuxt ? undefined : serverConfig.nuxtPort,
|
|
78
81
|
]);
|
|
82
|
+
actions.push("released occupied development ports");
|
|
79
83
|
}
|
|
80
84
|
const tasks = [];
|
|
81
85
|
if (!options.skipGo) {
|
|
82
86
|
tasks.push(runGoDev());
|
|
87
|
+
actions.push(`started Go watcher on port ${serverConfig.ginPort}`);
|
|
83
88
|
}
|
|
84
89
|
if (!options.skipNuxt) {
|
|
85
90
|
tasks.push(runNuxtDev());
|
|
91
|
+
actions.push(`started Nuxt dev server on port ${serverConfig.nuxtPort}`);
|
|
86
92
|
}
|
|
93
|
+
if (options.skipGo) {
|
|
94
|
+
actions.push("skipped Go workflow");
|
|
95
|
+
}
|
|
96
|
+
if (options.skipNuxt) {
|
|
97
|
+
actions.push("skipped Nuxt workflow");
|
|
98
|
+
}
|
|
99
|
+
(0, terminal_ui_1.printCommandSummary)("dev", actions);
|
|
87
100
|
yield Promise.all(tasks);
|
|
88
101
|
});
|
|
89
102
|
}
|
|
@@ -94,11 +107,16 @@ function develop() {
|
|
|
94
107
|
*/
|
|
95
108
|
function developNuxt() {
|
|
96
109
|
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
110
|
+
(0, terminal_ui_1.printCommandBanner)("dev:nuxt", "Start Nuxt development server only");
|
|
111
|
+
const actions = [];
|
|
97
112
|
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
98
113
|
yield prepareDevelop(options);
|
|
99
114
|
if (killPortBeforeDevelop) {
|
|
100
115
|
(0, utils_1.killPorts)([serverConfig.nuxtPort]);
|
|
116
|
+
actions.push("released Nuxt dev port");
|
|
101
117
|
}
|
|
118
|
+
actions.push(`started Nuxt dev server on port ${serverConfig.nuxtPort}`);
|
|
119
|
+
(0, terminal_ui_1.printCommandSummary)("dev:nuxt", actions);
|
|
102
120
|
yield runNuxtDev();
|
|
103
121
|
});
|
|
104
122
|
}
|
|
@@ -109,11 +127,16 @@ function developNuxt() {
|
|
|
109
127
|
*/
|
|
110
128
|
function developGo() {
|
|
111
129
|
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
130
|
+
(0, terminal_ui_1.printCommandBanner)("dev:go", "Start Go watcher only");
|
|
131
|
+
const actions = [];
|
|
112
132
|
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
113
133
|
yield prepareDevelop(options);
|
|
114
134
|
if (killPortBeforeDevelop) {
|
|
115
135
|
(0, utils_1.killPorts)([serverConfig.ginPort]);
|
|
136
|
+
actions.push("released Go server port");
|
|
116
137
|
}
|
|
138
|
+
actions.push(`started Go watcher on port ${serverConfig.ginPort}`);
|
|
139
|
+
(0, terminal_ui_1.printCommandSummary)("dev:go", actions);
|
|
117
140
|
yield runGoDev();
|
|
118
141
|
});
|
|
119
142
|
}
|
package/commands/pack.js
CHANGED
|
@@ -58,6 +58,7 @@ const FS = __importStar(require("fs-extra"));
|
|
|
58
58
|
const Path = __importStar(require("path"));
|
|
59
59
|
const os = __importStar(require("os"));
|
|
60
60
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
61
|
+
const terminal_ui_1 = require("../src/terminal-ui");
|
|
61
62
|
const { createJiti } = require("jiti");
|
|
62
63
|
/**
|
|
63
64
|
* 生成相对于服务器构建目录的绝对路径
|
|
@@ -96,7 +97,7 @@ const DEFAULT_FILES_TO_COPY = {
|
|
|
96
97
|
// 兼容旧导出:默认构建目录下的绝对目标路径
|
|
97
98
|
exports.FILES_TO_COPY = Object.fromEntries(Object.entries(DEFAULT_FILES_TO_COPY).map(([src, dest]) => [src, builtPath(dest)]));
|
|
98
99
|
function warnPackConfig(message) {
|
|
99
|
-
|
|
100
|
+
(0, terminal_ui_1.printCommandWarn)(`[pack] ${message}`);
|
|
100
101
|
}
|
|
101
102
|
function errorPackConfig(message) {
|
|
102
103
|
throw new Error(`[nuxt-gin-tools][pack] ${message}`);
|
|
@@ -147,7 +148,15 @@ function validatePackConfig(config, sourcePath) {
|
|
|
147
148
|
issues.push({ level: "error", message: `${field} must be a string` });
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
|
-
const booleanFields = [
|
|
151
|
+
const booleanFields = [
|
|
152
|
+
"skipGo",
|
|
153
|
+
"skipNuxt",
|
|
154
|
+
"skipBuild",
|
|
155
|
+
"skipZip",
|
|
156
|
+
"cleanDist",
|
|
157
|
+
"writeScripts",
|
|
158
|
+
"overwrite",
|
|
159
|
+
];
|
|
151
160
|
for (const field of booleanFields) {
|
|
152
161
|
const value = typedConfig[field];
|
|
153
162
|
if (value !== undefined && typeof value !== "boolean") {
|
|
@@ -172,6 +181,9 @@ function validatePackConfig(config, sourcePath) {
|
|
|
172
181
|
if (typedConfig.skipGo === true && typedConfig.skipNuxt === true) {
|
|
173
182
|
issues.push({ level: "warn", message: `skipGo and skipNuxt are both true; build step will be skipped` });
|
|
174
183
|
}
|
|
184
|
+
if (typedConfig.skipBuild === true && typedConfig.skipZip === true) {
|
|
185
|
+
issues.push({ level: "warn", message: `skipBuild and skipZip are both true; only bundle assembly will run` });
|
|
186
|
+
}
|
|
175
187
|
for (const issue of issues) {
|
|
176
188
|
if (issue.level === "warn") {
|
|
177
189
|
warnPackConfig(`${Path.basename(sourcePath)}: ${issue.message}`);
|
|
@@ -295,10 +307,11 @@ function makeZip(serverPath, zipPath) {
|
|
|
295
307
|
// 使用 7zip 将服务器构建目录打包为 7z 文件
|
|
296
308
|
Zip.pack(serverPath, zipPath, (error) => {
|
|
297
309
|
if (error) {
|
|
298
|
-
|
|
310
|
+
(0, terminal_ui_1.printCommandError)("打包失败", error);
|
|
299
311
|
reject(error);
|
|
312
|
+
return;
|
|
300
313
|
}
|
|
301
|
-
|
|
314
|
+
(0, terminal_ui_1.printCommandSuccess)("pack", `archive ready: ${zipPath}`);
|
|
302
315
|
resolve(zipPath);
|
|
303
316
|
});
|
|
304
317
|
});
|
|
@@ -325,22 +338,55 @@ function cleanUp(config) {
|
|
|
325
338
|
*/
|
|
326
339
|
function buildAndPack(config) {
|
|
327
340
|
return __awaiter(this, void 0, void 0, function* () {
|
|
341
|
+
(0, terminal_ui_1.printCommandBanner)("build", "Build project artifacts and pack deployment bundle");
|
|
342
|
+
const actions = [];
|
|
328
343
|
const resolvedConfig = config !== null && config !== void 0 ? config : readPackConfigFromCwd();
|
|
329
344
|
const serverPath = resolveServerPath(resolvedConfig);
|
|
330
345
|
const zipPath = resolveZipPath(resolvedConfig);
|
|
331
|
-
|
|
346
|
+
if (!(resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.skipBuild)) {
|
|
347
|
+
yield (0, builder_1.default)(resolvedConfig); // 执行项目构建
|
|
348
|
+
actions.push("built project artifacts");
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
(0, terminal_ui_1.printCommandInfo)("build", "skipping build step");
|
|
352
|
+
actions.push("skipped build step");
|
|
353
|
+
}
|
|
332
354
|
if (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.beforePack) {
|
|
333
355
|
yield resolvedConfig.beforePack();
|
|
356
|
+
actions.push("ran beforePack hook");
|
|
334
357
|
}
|
|
335
358
|
copyGeneratedFiles(serverPath, resolvedConfig); // 复制相关文件
|
|
359
|
+
actions.push(`assembled bundle in ${serverPath}`);
|
|
336
360
|
if ((resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.writeScripts) !== false) {
|
|
337
361
|
writeScriptFiles(serverPath, resolvedConfig); // 写入脚本文件
|
|
362
|
+
actions.push("wrote startup scripts and package.json");
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
actions.push("skipped startup script generation");
|
|
338
366
|
}
|
|
339
|
-
|
|
367
|
+
if (!(resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.skipZip)) {
|
|
368
|
+
yield makeZip(serverPath, zipPath); // 打包文件
|
|
369
|
+
(0, terminal_ui_1.printCommandInfo)("pack", `7z archive: ${zipPath}`);
|
|
370
|
+
actions.push(`created 7z archive at ${zipPath}`);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
(0, terminal_ui_1.printCommandInfo)("pack", "skipping 7z archive step");
|
|
374
|
+
actions.push("skipped 7z archive step");
|
|
375
|
+
}
|
|
376
|
+
(0, terminal_ui_1.printCommandInfo)("pack", `bundle dir: ${serverPath}`);
|
|
340
377
|
if (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.afterPack) {
|
|
341
378
|
yield resolvedConfig.afterPack(zipPath);
|
|
379
|
+
actions.push("ran afterPack hook");
|
|
342
380
|
}
|
|
343
381
|
cleanUp(resolvedConfig); // 清理临时文件
|
|
382
|
+
if ((resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.cleanDist) === false) {
|
|
383
|
+
actions.push("kept dist directory by configuration");
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
actions.push("cleaned dist directory");
|
|
387
|
+
}
|
|
388
|
+
(0, terminal_ui_1.printCommandSuccess)("build", "Build and pack completed");
|
|
389
|
+
(0, terminal_ui_1.printCommandSummary)("build", actions);
|
|
344
390
|
});
|
|
345
391
|
}
|
|
346
392
|
exports.default = buildAndPack;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type PostInstallOptions = {
|
|
2
|
+
skipGo?: boolean;
|
|
3
|
+
skipNuxt?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare function postInstall(options?: PostInstallOptions): Promise<void>;
|
|
2
6
|
export default postInstall;
|
package/commands/postinstall.js
CHANGED
|
@@ -6,27 +6,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.postInstall = postInstall;
|
|
7
7
|
const concurrently_1 = __importDefault(require("concurrently"));
|
|
8
8
|
const node_child_process_1 = require("node:child_process");
|
|
9
|
-
|
|
9
|
+
const terminal_ui_1 = require("../src/terminal-ui");
|
|
10
|
+
function postInstall(options = {}) {
|
|
11
|
+
(0, terminal_ui_1.printCommandBanner)("install", "Prepare Nuxt and optional Go dependencies");
|
|
12
|
+
const actions = [];
|
|
13
|
+
const commands = [];
|
|
10
14
|
const hasGo = (0, node_child_process_1.spawnSync)("go", ["version"], { stdio: "ignore", shell: true }).status ===
|
|
11
15
|
0;
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
if (!options.skipNuxt) {
|
|
17
|
+
actions.push("prepared Nuxt runtime");
|
|
18
|
+
commands.push({
|
|
14
19
|
command: "npx nuxt prepare",
|
|
15
20
|
name: "nuxt",
|
|
16
21
|
prefixColor: "blue",
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (hasGo) {
|
|
20
|
-
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (!options.skipGo && hasGo) {
|
|
25
|
+
actions.push("downloaded and tidied Go modules");
|
|
26
|
+
commands.push({
|
|
21
27
|
command: "go mod download && go mod tidy",
|
|
22
28
|
name: "go",
|
|
23
29
|
prefixColor: "green",
|
|
24
30
|
});
|
|
25
31
|
}
|
|
32
|
+
else if (!options.skipGo) {
|
|
33
|
+
(0, terminal_ui_1.printCommandWarn)("Go was not detected, skipping Go dependency bootstrap");
|
|
34
|
+
actions.push("skipped Go bootstrap because Go was not detected");
|
|
35
|
+
}
|
|
26
36
|
else {
|
|
27
|
-
|
|
37
|
+
actions.push("skipped Go bootstrap by option");
|
|
38
|
+
}
|
|
39
|
+
if (options.skipNuxt) {
|
|
40
|
+
actions.push("skipped Nuxt prepare by option");
|
|
41
|
+
}
|
|
42
|
+
if (commands.length === 0) {
|
|
43
|
+
(0, terminal_ui_1.printCommandWarn)("Nothing selected for install, skipping bootstrap");
|
|
44
|
+
(0, terminal_ui_1.printCommandSummary)("install", actions.length > 0 ? actions : ["nothing was executed"]);
|
|
45
|
+
return Promise.resolve();
|
|
28
46
|
}
|
|
29
47
|
// 执行并发命令
|
|
30
|
-
return (0, concurrently_1.default)(commands).result
|
|
48
|
+
return (0, concurrently_1.default)(commands).result.then(() => {
|
|
49
|
+
(0, terminal_ui_1.printCommandSuccess)("install", "Project bootstrap completed");
|
|
50
|
+
(0, terminal_ui_1.printCommandSummary)("install", actions);
|
|
51
|
+
});
|
|
31
52
|
}
|
|
32
53
|
exports.default = postInstall;
|
package/commands/update.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type PackageManagerSelection } from "../src/package-manager";
|
|
1
2
|
export type UpdateOptions = {
|
|
2
|
-
latest
|
|
3
|
+
latest: boolean;
|
|
4
|
+
packageManager: PackageManagerSelection;
|
|
3
5
|
skipGo?: boolean;
|
|
4
6
|
skipNode?: boolean;
|
|
5
7
|
};
|
|
6
|
-
export declare function update(options
|
|
8
|
+
export declare function update(options: UpdateOptions): Promise<void>;
|
|
7
9
|
export default update;
|
package/commands/update.js
CHANGED
|
@@ -5,25 +5,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.update = update;
|
|
7
7
|
const concurrently_1 = __importDefault(require("concurrently"));
|
|
8
|
-
|
|
8
|
+
const package_manager_1 = require("../src/package-manager");
|
|
9
|
+
const terminal_ui_1 = require("../src/terminal-ui");
|
|
10
|
+
function update(options) {
|
|
11
|
+
(0, terminal_ui_1.printCommandBanner)("update", "Update Node and Go dependencies");
|
|
12
|
+
const actions = [];
|
|
9
13
|
const commands = [];
|
|
14
|
+
const packageManager = (0, package_manager_1.resolvePackageManager)(options.packageManager);
|
|
10
15
|
if (!options.skipNode) {
|
|
16
|
+
actions.push(`updated Node dependencies with ${packageManager} (${options.latest ? "latest" : "conservative"} mode)`);
|
|
11
17
|
commands.push({
|
|
12
|
-
command: options.latest
|
|
13
|
-
name:
|
|
18
|
+
command: (0, package_manager_1.packageManagerUpdateCommand)(packageManager, options.latest),
|
|
19
|
+
name: packageManager,
|
|
14
20
|
prefixColor: "magenta",
|
|
15
21
|
});
|
|
16
22
|
}
|
|
17
23
|
if (!options.skipGo) {
|
|
24
|
+
actions.push(`updated Go modules with ${options.latest ? "latest" : "patch"} strategy`);
|
|
18
25
|
commands.push({
|
|
19
26
|
command: options.latest ? "go get -u ./... && go mod tidy" : "go get -u=patch ./... && go mod tidy",
|
|
20
27
|
name: "go",
|
|
21
28
|
prefixColor: "green",
|
|
22
29
|
});
|
|
23
30
|
}
|
|
31
|
+
if (options.skipNode) {
|
|
32
|
+
actions.push("skipped Node dependency update");
|
|
33
|
+
}
|
|
34
|
+
if (options.skipGo) {
|
|
35
|
+
actions.push("skipped Go dependency update");
|
|
36
|
+
}
|
|
24
37
|
if (commands.length === 0) {
|
|
38
|
+
(0, terminal_ui_1.printCommandWarn)("No update targets selected, nothing to do");
|
|
39
|
+
(0, terminal_ui_1.printCommandSummary)("update", actions.length > 0 ? actions : ["nothing was executed"]);
|
|
25
40
|
return Promise.resolve();
|
|
26
41
|
}
|
|
27
|
-
return (0, concurrently_1.default)(commands).result
|
|
42
|
+
return (0, concurrently_1.default)(commands).result.then(() => {
|
|
43
|
+
(0, terminal_ui_1.printCommandSuccess)("update", "Dependency update completed");
|
|
44
|
+
(0, terminal_ui_1.printCommandSummary)("update", actions);
|
|
45
|
+
});
|
|
28
46
|
}
|
|
29
47
|
exports.default = update;
|
package/index.js
CHANGED
|
@@ -51,8 +51,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
51
51
|
const pack_1 = __importDefault(require("./commands/pack"));
|
|
52
52
|
// 导入开发模式功能
|
|
53
53
|
const develop_1 = __importStar(require("./commands/develop"));
|
|
54
|
-
// 导入API生成功能
|
|
55
|
-
const api_generate_1 = __importDefault(require("./commands/api-generate"));
|
|
56
54
|
// 导入安装后处理功能
|
|
57
55
|
const postinstall_1 = __importDefault(require("./commands/postinstall"));
|
|
58
56
|
// 导入清理功能
|
|
@@ -60,17 +58,25 @@ const cleanup_1 = __importDefault(require("./commands/cleanup"));
|
|
|
60
58
|
// 导入更新功能
|
|
61
59
|
const update_1 = __importDefault(require("./commands/update"));
|
|
62
60
|
const cli_options_1 = require("./src/cli-options");
|
|
61
|
+
const package_manager_1 = require("./src/package-manager");
|
|
62
|
+
const terminal_ui_1 = require("./src/terminal-ui");
|
|
63
63
|
// 获取命令行参数(去除前两个默认参数)
|
|
64
64
|
const args = process.argv.slice(2);
|
|
65
65
|
// 检查是否提供了命令
|
|
66
66
|
if (args.length === 0) {
|
|
67
|
-
|
|
67
|
+
(0, terminal_ui_1.printCommandError)("未提供命令。请指定要运行的命令。");
|
|
68
68
|
process.exit(1);
|
|
69
69
|
}
|
|
70
70
|
function main() {
|
|
71
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
72
|
const command = args[0];
|
|
73
73
|
const options = (0, cli_options_1.parseCLIOptions)(args.slice(1));
|
|
74
|
+
const rawPackageManager = (0, cli_options_1.getOption)(options, "package-manager");
|
|
75
|
+
const packageManagerCandidate = rawPackageManager !== null && rawPackageManager !== void 0 ? rawPackageManager : "auto";
|
|
76
|
+
if (!(0, package_manager_1.isPackageManagerSelection)(packageManagerCandidate)) {
|
|
77
|
+
throw new Error(`Invalid value for --package-manager: ${packageManagerCandidate}. Expected one of: auto, bun, pnpm, npm`);
|
|
78
|
+
}
|
|
79
|
+
const packageManagerOption = packageManagerCandidate;
|
|
74
80
|
switch (command) {
|
|
75
81
|
case "dev":
|
|
76
82
|
yield (0, develop_1.default)({
|
|
@@ -94,35 +100,39 @@ function main() {
|
|
|
94
100
|
binaryName: (0, cli_options_1.getOption)(options, "binary-name"),
|
|
95
101
|
skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
|
|
96
102
|
skipNuxt: (0, cli_options_1.hasFlag)(options, "skip-nuxt"),
|
|
103
|
+
skipBuild: (0, cli_options_1.hasFlag)(options, "skip-build"),
|
|
104
|
+
skipZip: (0, cli_options_1.hasFlag)(options, "skip-zip"),
|
|
97
105
|
});
|
|
98
106
|
break;
|
|
99
|
-
case "gen":
|
|
100
|
-
// 生成API代码(注:此处命令可能拼写错误,应为generate)
|
|
101
|
-
yield (0, api_generate_1.default)();
|
|
102
|
-
break;
|
|
103
107
|
case "install":
|
|
104
108
|
// 执行安装后的初始化操作
|
|
105
|
-
yield (0, postinstall_1.default)(
|
|
109
|
+
yield (0, postinstall_1.default)({
|
|
110
|
+
skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
|
|
111
|
+
skipNuxt: (0, cli_options_1.hasFlag)(options, "skip-nuxt"),
|
|
112
|
+
});
|
|
106
113
|
break;
|
|
107
114
|
case "cleanup":
|
|
108
115
|
// 执行清理操作
|
|
109
|
-
yield (0, cleanup_1.default)(
|
|
116
|
+
yield (0, cleanup_1.default)({
|
|
117
|
+
dryRun: (0, cli_options_1.hasFlag)(options, "dry-run"),
|
|
118
|
+
});
|
|
110
119
|
break;
|
|
111
120
|
case "update":
|
|
112
121
|
// 更新依赖
|
|
113
122
|
yield (0, update_1.default)({
|
|
114
|
-
latest: (0, cli_options_1.
|
|
123
|
+
latest: (0, cli_options_1.getBooleanOption)(options, "latest", false),
|
|
124
|
+
packageManager: packageManagerOption,
|
|
115
125
|
skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
|
|
116
126
|
skipNode: (0, cli_options_1.hasFlag)(options, "skip-node"),
|
|
117
127
|
});
|
|
118
128
|
break;
|
|
119
129
|
default:
|
|
120
|
-
|
|
130
|
+
(0, terminal_ui_1.printCommandError)(`未知命令: ${command}`);
|
|
121
131
|
process.exit(1);
|
|
122
132
|
}
|
|
123
133
|
});
|
|
124
134
|
}
|
|
125
135
|
void main().catch((error) => {
|
|
126
|
-
|
|
136
|
+
(0, terminal_ui_1.printCommandError)("命令执行失败", error);
|
|
127
137
|
process.exit(1);
|
|
128
138
|
});
|
package/package.json
CHANGED
package/src/cli-options.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export type CLIOptions = {
|
|
|
6
6
|
export declare function parseCLIOptions(args: string[]): CLIOptions;
|
|
7
7
|
export declare function hasFlag(options: CLIOptions, key: string): boolean;
|
|
8
8
|
export declare function getOption(options: CLIOptions, key: string): string | undefined;
|
|
9
|
+
export declare function getBooleanOption(options: CLIOptions, key: string, defaultValue: boolean): boolean;
|
package/src/cli-options.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseCLIOptions = parseCLIOptions;
|
|
4
4
|
exports.hasFlag = hasFlag;
|
|
5
5
|
exports.getOption = getOption;
|
|
6
|
+
exports.getBooleanOption = getBooleanOption;
|
|
6
7
|
function normalizeKey(key) {
|
|
7
8
|
return key.replace(/^-+/, "").trim();
|
|
8
9
|
}
|
|
@@ -41,3 +42,17 @@ function hasFlag(options, key) {
|
|
|
41
42
|
function getOption(options, key) {
|
|
42
43
|
return options.values.get(normalizeKey(key));
|
|
43
44
|
}
|
|
45
|
+
function getBooleanOption(options, key, defaultValue) {
|
|
46
|
+
const value = getOption(options, key);
|
|
47
|
+
if (value === undefined) {
|
|
48
|
+
return defaultValue;
|
|
49
|
+
}
|
|
50
|
+
const normalized = value.trim().toLowerCase();
|
|
51
|
+
if (["true", "1", "yes", "y", "on"].includes(normalized)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (["false", "0", "no", "n", "off"].includes(normalized)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Invalid boolean value for --${key}: ${value}`);
|
|
58
|
+
}
|
package/src/pack.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { BuildOptions } from "../commands/builder";
|
|
2
2
|
export interface PackConfig extends BuildOptions {
|
|
3
|
+
/**
|
|
4
|
+
* 是否跳过构建步骤
|
|
5
|
+
*/
|
|
6
|
+
skipBuild?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* 是否跳过 7z 打包步骤
|
|
9
|
+
*/
|
|
10
|
+
skipZip?: boolean;
|
|
3
11
|
/**
|
|
4
12
|
* 额外需要打包的文件映射
|
|
5
13
|
* key: 源文件路径(相对于项目根目录或绝对路径)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type PackageManager = "bun" | "pnpm" | "npm";
|
|
2
|
+
export type PackageManagerSelection = PackageManager | "auto";
|
|
3
|
+
export declare const PACKAGE_MANAGER_SELECTIONS: readonly ["auto", "bun", "pnpm", "npm"];
|
|
4
|
+
export declare function detectPackageManager(): PackageManager;
|
|
5
|
+
export declare function resolvePackageManager(selection: PackageManagerSelection): PackageManager;
|
|
6
|
+
export declare function isPackageManagerSelection(value: string): value is PackageManagerSelection;
|
|
7
|
+
export declare function packageManagerUpdateCommand(packageManager: PackageManager, latest: boolean): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PACKAGE_MANAGER_SELECTIONS = void 0;
|
|
4
|
+
exports.detectPackageManager = detectPackageManager;
|
|
5
|
+
exports.resolvePackageManager = resolvePackageManager;
|
|
6
|
+
exports.isPackageManagerSelection = isPackageManagerSelection;
|
|
7
|
+
exports.packageManagerUpdateCommand = packageManagerUpdateCommand;
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
exports.PACKAGE_MANAGER_SELECTIONS = ["auto", "bun", "pnpm", "npm"];
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
function detectPackageManager() {
|
|
13
|
+
if ((0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "bun.lock")) || (0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "bun.lockb"))) {
|
|
14
|
+
return "bun";
|
|
15
|
+
}
|
|
16
|
+
if ((0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "pnpm-lock.yaml"))) {
|
|
17
|
+
return "pnpm";
|
|
18
|
+
}
|
|
19
|
+
return "npm";
|
|
20
|
+
}
|
|
21
|
+
function resolvePackageManager(selection) {
|
|
22
|
+
if (selection === "auto") {
|
|
23
|
+
return detectPackageManager();
|
|
24
|
+
}
|
|
25
|
+
return selection;
|
|
26
|
+
}
|
|
27
|
+
function isPackageManagerSelection(value) {
|
|
28
|
+
return exports.PACKAGE_MANAGER_SELECTIONS.includes(value);
|
|
29
|
+
}
|
|
30
|
+
function packageManagerUpdateCommand(packageManager, latest) {
|
|
31
|
+
switch (packageManager) {
|
|
32
|
+
case "bun":
|
|
33
|
+
return latest ? "bun update --latest" : "bun update";
|
|
34
|
+
case "pnpm":
|
|
35
|
+
return latest ? "pnpm update --latest" : "pnpm update";
|
|
36
|
+
default:
|
|
37
|
+
return latest ? "npm update" : "npm update";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function printCommandBanner(command: string, subtitle: string): void;
|
|
2
|
+
export declare function printCommandSuccess(command: string, message: string): void;
|
|
3
|
+
export declare function printCommandInfo(label: string, message: string): void;
|
|
4
|
+
export declare function printCommandWarn(message: string): void;
|
|
5
|
+
export declare function printCommandError(message: string, error?: unknown): void;
|
|
6
|
+
export declare function printCommandLog(label: string, message: string): void;
|
|
7
|
+
export declare function printCommandSummary(command: string, items: string[]): void;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.printCommandBanner = printCommandBanner;
|
|
7
|
+
exports.printCommandSuccess = printCommandSuccess;
|
|
8
|
+
exports.printCommandInfo = printCommandInfo;
|
|
9
|
+
exports.printCommandWarn = printCommandWarn;
|
|
10
|
+
exports.printCommandError = printCommandError;
|
|
11
|
+
exports.printCommandLog = printCommandLog;
|
|
12
|
+
exports.printCommandSummary = printCommandSummary;
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const TERMINAL_WIDTH = 72;
|
|
15
|
+
function printLine(message, method = "log") {
|
|
16
|
+
if (method === "warn") {
|
|
17
|
+
console.warn(message);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (method === "error") {
|
|
21
|
+
console.error(message);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
console.log(message);
|
|
25
|
+
}
|
|
26
|
+
function repeat(char, width = TERMINAL_WIDTH) {
|
|
27
|
+
return char.repeat(width);
|
|
28
|
+
}
|
|
29
|
+
function formatClock() {
|
|
30
|
+
return new Date().toLocaleTimeString("en-GB", {
|
|
31
|
+
hour: "2-digit",
|
|
32
|
+
minute: "2-digit",
|
|
33
|
+
second: "2-digit",
|
|
34
|
+
hour12: false,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
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
|
+
function commandChip(command) {
|
|
64
|
+
return chalk_1.default.bgBlueBright.black(` ${command.toUpperCase()} `);
|
|
65
|
+
}
|
|
66
|
+
function subtleChip(text) {
|
|
67
|
+
return chalk_1.default.bgBlackBright.white(` ${text} `);
|
|
68
|
+
}
|
|
69
|
+
function printCommandBanner(command, subtitle) {
|
|
70
|
+
const timestamp = subtleChip(formatClock());
|
|
71
|
+
const title = `nuxt-gin-tools ${commandChip(command)} ${timestamp}`;
|
|
72
|
+
const detail = chalk_1.default.cyanBright(subtitle);
|
|
73
|
+
printLine("");
|
|
74
|
+
printSection([title, detail], {
|
|
75
|
+
color: chalk_1.default.blueBright,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function printCommandSuccess(command, message) {
|
|
79
|
+
printLine(chalk_1.default.greenBright(`◆ ${chalk_1.default.bold(command)} completed`) + chalk_1.default.green(` ${message}`));
|
|
80
|
+
}
|
|
81
|
+
function printCommandInfo(label, message) {
|
|
82
|
+
const head = chalk_1.default.bgCyan.black(` ${label.toUpperCase()} `);
|
|
83
|
+
printLine(`${head} ${chalk_1.default.cyanBright(message)}`);
|
|
84
|
+
}
|
|
85
|
+
function printCommandWarn(message) {
|
|
86
|
+
printSection([`${chalk_1.default.bold("warning")} ${message}`], {
|
|
87
|
+
color: chalk_1.default.yellow,
|
|
88
|
+
method: "warn",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function printCommandError(message, error) {
|
|
92
|
+
const detail = error instanceof Error ? error.message : error !== undefined ? String(error) : "";
|
|
93
|
+
const lines = [`${chalk_1.default.bold("error")} ${message}`];
|
|
94
|
+
if (detail) {
|
|
95
|
+
lines.push(chalk_1.default.redBright(detail));
|
|
96
|
+
}
|
|
97
|
+
printSection(lines, {
|
|
98
|
+
color: chalk_1.default.red,
|
|
99
|
+
method: "error",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function printCommandLog(label, message) {
|
|
103
|
+
const chip = chalk_1.default.bgMagenta.white(` ${label} `);
|
|
104
|
+
printLine(`${chip} ${chalk_1.default.white(message)}`);
|
|
105
|
+
}
|
|
106
|
+
function printCommandSummary(command, items) {
|
|
107
|
+
const normalizedItems = items.map((item) => item.trim()).filter(Boolean);
|
|
108
|
+
if (normalizedItems.length === 0) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const lines = [
|
|
112
|
+
`${chalk_1.default.bold(`${command} summary`)} ${chalk_1.default.gray(`(${normalizedItems.length} items)`)}`,
|
|
113
|
+
...normalizedItems.map((item) => chalk_1.default.magenta(`• ${item}`)),
|
|
114
|
+
];
|
|
115
|
+
printSection(lines, {
|
|
116
|
+
color: chalk_1.default.magentaBright,
|
|
117
|
+
});
|
|
118
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.killPort = killPort;
|
|
7
7
|
exports.killPorts = killPorts;
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
9
|
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const terminal_ui_1 = require("./terminal-ui");
|
|
11
11
|
function isValidPort(port) {
|
|
12
12
|
return Number.isInteger(port) && port > 0;
|
|
13
13
|
}
|
|
@@ -34,7 +34,7 @@ function killPortUnix(port, options) {
|
|
|
34
34
|
for (const pid of pids) {
|
|
35
35
|
try {
|
|
36
36
|
process.kill(pid, "SIGKILL");
|
|
37
|
-
|
|
37
|
+
(0, terminal_ui_1.printCommandSuccess)("port", buildMessage(pid, port, "unix", options));
|
|
38
38
|
}
|
|
39
39
|
catch (_a) {
|
|
40
40
|
// Best-effort: if the process is already gone, ignore.
|
|
@@ -81,7 +81,7 @@ function killPortWindows(port, options) {
|
|
|
81
81
|
(0, child_process_1.execSync)(`taskkill /PID ${pid} /F`, {
|
|
82
82
|
stdio: ["ignore", "ignore", "ignore"],
|
|
83
83
|
});
|
|
84
|
-
|
|
84
|
+
(0, terminal_ui_1.printCommandSuccess)("port", buildMessage(pid, port, "win32", options));
|
|
85
85
|
}
|
|
86
86
|
catch (_a) {
|
|
87
87
|
// Best-effort: if the process is already gone, ignore.
|