nuxt-gin-tools 0.2.22 → 0.3.0

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.
Files changed (49) hide show
  1. package/README.md +287 -79
  2. package/commands/cleanup.d.ts +7 -4
  3. package/commands/cleanup.js +32 -21
  4. package/commands/dev-go.js +8 -8
  5. package/commands/develop.js +19 -0
  6. package/commands/pack.js +47 -6
  7. package/commands/postinstall.d.ts +5 -1
  8. package/commands/postinstall.js +25 -8
  9. package/commands/update.d.ts +4 -2
  10. package/commands/update.js +16 -3
  11. package/index.js +40 -24
  12. package/package.json +2 -2
  13. package/src/assets/go-gin-server.json +5 -0
  14. package/src/assets/pack-config.schema.json +62 -0
  15. package/src/assets/server-config.schema.json +35 -0
  16. package/src/cli/commands/build.d.ts +1 -0
  17. package/src/cli/commands/build.js +22 -0
  18. package/src/cli/commands/cleanup.d.ts +11 -0
  19. package/src/cli/commands/cleanup.js +115 -0
  20. package/src/cli/commands/develop.d.ts +26 -0
  21. package/src/cli/commands/develop.js +168 -0
  22. package/src/cli/commands/install.d.ts +6 -0
  23. package/src/cli/commands/install.js +59 -0
  24. package/src/cli/commands/update.d.ts +9 -0
  25. package/src/cli/commands/update.js +55 -0
  26. package/src/cli/options.d.ts +10 -0
  27. package/src/cli/options.js +66 -0
  28. package/src/cli/terminal-ui.d.ts +7 -0
  29. package/src/cli/terminal-ui.js +118 -0
  30. package/src/cli-options.d.ts +1 -0
  31. package/src/cli-options.js +15 -0
  32. package/src/config/package-manager.d.ts +7 -0
  33. package/src/config/package-manager.js +39 -0
  34. package/src/nuxt-gin.d.ts +103 -0
  35. package/src/nuxt-gin.js +178 -0
  36. package/src/pack.d.ts +9 -1
  37. package/src/package-manager.d.ts +7 -0
  38. package/src/package-manager.js +39 -0
  39. package/src/services/build-service.d.ts +7 -0
  40. package/src/services/build-service.js +35 -0
  41. package/src/services/go-dev-service.d.ts +8 -0
  42. package/src/services/go-dev-service.js +356 -0
  43. package/src/services/pack-service.d.ts +23 -0
  44. package/src/services/pack-service.js +372 -0
  45. package/src/system/ports.d.ts +7 -0
  46. package/src/system/ports.js +112 -0
  47. package/src/terminal-ui.d.ts +3 -0
  48. package/src/terminal-ui.js +99 -14
  49. package/src/utils.js +3 -3
@@ -54,45 +54,56 @@ const Path = __importStar(require("path"));
54
54
  const concurrently_1 = __importDefault(require("concurrently"));
55
55
  const terminal_ui_1 = require("../src/terminal-ui");
56
56
  const cwd = process.cwd();
57
- function ifExistsRemove(relativePath) {
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
- ifExistsRemove(".build/production");
73
- // 清理原始 dist 目录
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, void 0, void 0, function* () {
99
+ return __awaiter(this, arguments, void 0, function* (options = {}) {
91
100
  (0, terminal_ui_1.printCommandBanner)("cleanup", "Remove generated build output and temporary files");
92
- const result = cleanUpNuxt();
93
- cleanUpBuild();
101
+ const actions = [];
102
+ const result = cleanUpNuxt(options, actions);
103
+ cleanUpBuild(options, actions);
94
104
  yield result;
95
- (0, terminal_ui_1.printCommandSuccess)("cleanup", "Temporary files removed");
105
+ (0, terminal_ui_1.printCommandSuccess)("cleanup", options.dryRun ? "Dry run completed" : "Temporary files removed");
106
+ (0, terminal_ui_1.printCommandSummary)("cleanup", actions);
96
107
  });
97
108
  }
98
109
  exports.default = cleanUp;
@@ -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 = chalk_1.default.bgMagenta.white(`[${LOG_TAG}]`);
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
- console.warn(`${GO_WATCH_PREFIX} invalid watch config JSON, fallback to defaults: ${configPath}`);
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
- console.log(`${GO_WATCH_PREFIX} start: ${command}`);
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
- console.log(`${GO_WATCH_PREFIX} watching: ${watchRoots.map((item) => toProjectRelative(item)).join(", ")}`);
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
- console.log(`${GO_WATCH_PREFIX} ${eventName}: ${relPath}, restarting...`);
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
- console.error(`${GO_WATCH_PREFIX} watcher error: ${String(error)}`);
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
- console.error(`${GO_WATCH_PREFIX} failed to start: ${String(error)}`);
303
+ (0, terminal_ui_1.printCommandError)(`${GO_WATCH_PREFIX} failed to start`, error);
304
304
  process.exit(1);
305
305
  });
306
306
  }
@@ -70,6 +70,7 @@ function runGoDev() {
70
70
  function develop() {
71
71
  return __awaiter(this, arguments, void 0, function* (options = {}) {
72
72
  (0, terminal_ui_1.printCommandBanner)("dev", "Start Nuxt and Go development workflows");
73
+ const actions = [];
73
74
  const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
74
75
  yield prepareDevelop(options);
75
76
  // 在开发前确保占用端口被释放
@@ -78,14 +79,24 @@ function develop() {
78
79
  options.skipGo ? undefined : serverConfig.ginPort,
79
80
  options.skipNuxt ? undefined : serverConfig.nuxtPort,
80
81
  ]);
82
+ actions.push("released occupied development ports");
81
83
  }
82
84
  const tasks = [];
83
85
  if (!options.skipGo) {
84
86
  tasks.push(runGoDev());
87
+ actions.push(`started Go watcher on port ${serverConfig.ginPort}`);
85
88
  }
86
89
  if (!options.skipNuxt) {
87
90
  tasks.push(runNuxtDev());
91
+ actions.push(`started Nuxt dev server on port ${serverConfig.nuxtPort}`);
88
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);
89
100
  yield Promise.all(tasks);
90
101
  });
91
102
  }
@@ -97,11 +108,15 @@ function develop() {
97
108
  function developNuxt() {
98
109
  return __awaiter(this, arguments, void 0, function* (options = {}) {
99
110
  (0, terminal_ui_1.printCommandBanner)("dev:nuxt", "Start Nuxt development server only");
111
+ const actions = [];
100
112
  const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
101
113
  yield prepareDevelop(options);
102
114
  if (killPortBeforeDevelop) {
103
115
  (0, utils_1.killPorts)([serverConfig.nuxtPort]);
116
+ actions.push("released Nuxt dev port");
104
117
  }
118
+ actions.push(`started Nuxt dev server on port ${serverConfig.nuxtPort}`);
119
+ (0, terminal_ui_1.printCommandSummary)("dev:nuxt", actions);
105
120
  yield runNuxtDev();
106
121
  });
107
122
  }
@@ -113,11 +128,15 @@ function developNuxt() {
113
128
  function developGo() {
114
129
  return __awaiter(this, arguments, void 0, function* (options = {}) {
115
130
  (0, terminal_ui_1.printCommandBanner)("dev:go", "Start Go watcher only");
131
+ const actions = [];
116
132
  const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
117
133
  yield prepareDevelop(options);
118
134
  if (killPortBeforeDevelop) {
119
135
  (0, utils_1.killPorts)([serverConfig.ginPort]);
136
+ actions.push("released Go server port");
120
137
  }
138
+ actions.push(`started Go watcher on port ${serverConfig.ginPort}`);
139
+ (0, terminal_ui_1.printCommandSummary)("dev:go", actions);
121
140
  yield runGoDev();
122
141
  });
123
142
  }
package/commands/pack.js CHANGED
@@ -148,7 +148,15 @@ function validatePackConfig(config, sourcePath) {
148
148
  issues.push({ level: "error", message: `${field} must be a string` });
149
149
  }
150
150
  }
151
- const booleanFields = ["skipGo", "skipNuxt", "cleanDist", "writeScripts", "overwrite"];
151
+ const booleanFields = [
152
+ "skipGo",
153
+ "skipNuxt",
154
+ "skipBuild",
155
+ "skipZip",
156
+ "cleanDist",
157
+ "writeScripts",
158
+ "overwrite",
159
+ ];
152
160
  for (const field of booleanFields) {
153
161
  const value = typedConfig[field];
154
162
  if (value !== undefined && typeof value !== "boolean") {
@@ -173,6 +181,9 @@ function validatePackConfig(config, sourcePath) {
173
181
  if (typedConfig.skipGo === true && typedConfig.skipNuxt === true) {
174
182
  issues.push({ level: "warn", message: `skipGo and skipNuxt are both true; build step will be skipped` });
175
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
+ }
176
187
  for (const issue of issues) {
177
188
  if (issue.level === "warn") {
178
189
  warnPackConfig(`${Path.basename(sourcePath)}: ${issue.message}`);
@@ -296,10 +307,11 @@ function makeZip(serverPath, zipPath) {
296
307
  // 使用 7zip 将服务器构建目录打包为 7z 文件
297
308
  Zip.pack(serverPath, zipPath, (error) => {
298
309
  if (error) {
299
- console.error("打包失败:", error);
310
+ (0, terminal_ui_1.printCommandError)("打包失败", error);
300
311
  reject(error);
312
+ return;
301
313
  }
302
- console.log("打包成功:", zipPath);
314
+ (0, terminal_ui_1.printCommandSuccess)("pack", `archive ready: ${zipPath}`);
303
315
  resolve(zipPath);
304
316
  });
305
317
  });
@@ -327,25 +339,54 @@ function cleanUp(config) {
327
339
  function buildAndPack(config) {
328
340
  return __awaiter(this, void 0, void 0, function* () {
329
341
  (0, terminal_ui_1.printCommandBanner)("build", "Build project artifacts and pack deployment bundle");
342
+ const actions = [];
330
343
  const resolvedConfig = config !== null && config !== void 0 ? config : readPackConfigFromCwd();
331
344
  const serverPath = resolveServerPath(resolvedConfig);
332
345
  const zipPath = resolveZipPath(resolvedConfig);
333
- yield (0, builder_1.default)(resolvedConfig); // 执行项目构建
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
+ }
334
354
  if (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.beforePack) {
335
355
  yield resolvedConfig.beforePack();
356
+ actions.push("ran beforePack hook");
336
357
  }
337
358
  copyGeneratedFiles(serverPath, resolvedConfig); // 复制相关文件
359
+ actions.push(`assembled bundle in ${serverPath}`);
338
360
  if ((resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.writeScripts) !== false) {
339
361
  writeScriptFiles(serverPath, resolvedConfig); // 写入脚本文件
362
+ actions.push("wrote startup scripts and package.json");
363
+ }
364
+ else {
365
+ actions.push("skipped startup script generation");
366
+ }
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");
340
375
  }
341
- yield makeZip(serverPath, zipPath); // 打包文件
342
- (0, terminal_ui_1.printCommandInfo)("pack", `7z archive: ${zipPath}`);
343
376
  (0, terminal_ui_1.printCommandInfo)("pack", `bundle dir: ${serverPath}`);
344
377
  if (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.afterPack) {
345
378
  yield resolvedConfig.afterPack(zipPath);
379
+ actions.push("ran afterPack hook");
346
380
  }
347
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
+ }
348
388
  (0, terminal_ui_1.printCommandSuccess)("build", "Build and pack completed");
389
+ (0, terminal_ui_1.printCommandSummary)("build", actions);
349
390
  });
350
391
  }
351
392
  exports.default = buildAndPack;
@@ -1,2 +1,6 @@
1
- export declare function postInstall(): Promise<void>;
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;
@@ -7,30 +7,47 @@ 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() {
10
+ function postInstall(options = {}) {
11
11
  (0, terminal_ui_1.printCommandBanner)("install", "Prepare Nuxt and optional Go dependencies");
12
+ const actions = [];
13
+ const commands = [];
12
14
  const hasGo = (0, node_child_process_1.spawnSync)("go", ["version"], { stdio: "ignore", shell: true }).status ===
13
15
  0;
14
- const commands = [
15
- {
16
+ if (!options.skipNuxt) {
17
+ actions.push("prepared Nuxt runtime");
18
+ commands.push({
16
19
  command: "npx nuxt prepare",
17
20
  name: "nuxt",
18
21
  prefixColor: "blue",
19
- },
20
- ];
21
- if (hasGo) {
22
- commands.unshift({
22
+ });
23
+ }
24
+ if (!options.skipGo && hasGo) {
25
+ actions.push("downloaded and tidied Go modules");
26
+ commands.push({
23
27
  command: "go mod download && go mod tidy",
24
28
  name: "go",
25
29
  prefixColor: "green",
26
30
  });
27
31
  }
28
- else {
32
+ else if (!options.skipGo) {
29
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
+ }
36
+ else {
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();
30
46
  }
31
47
  // 执行并发命令
32
48
  return (0, concurrently_1.default)(commands).result.then(() => {
33
49
  (0, terminal_ui_1.printCommandSuccess)("install", "Project bootstrap completed");
50
+ (0, terminal_ui_1.printCommandSummary)("install", actions);
34
51
  });
35
52
  }
36
53
  exports.default = postInstall;
@@ -1,7 +1,9 @@
1
+ import { type PackageManagerSelection } from "../src/package-manager";
1
2
  export type UpdateOptions = {
2
- latest?: boolean;
3
+ latest: boolean;
4
+ packageManager: PackageManagerSelection;
3
5
  skipGo?: boolean;
4
6
  skipNode?: boolean;
5
7
  };
6
- export declare function update(options?: UpdateOptions): Promise<void>;
8
+ export declare function update(options: UpdateOptions): Promise<void>;
7
9
  export default update;
@@ -5,30 +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
+ const package_manager_1 = require("../src/package-manager");
8
9
  const terminal_ui_1 = require("../src/terminal-ui");
9
- function update(options = {}) {
10
+ function update(options) {
10
11
  (0, terminal_ui_1.printCommandBanner)("update", "Update Node and Go dependencies");
12
+ const actions = [];
11
13
  const commands = [];
14
+ const packageManager = (0, package_manager_1.resolvePackageManager)(options.packageManager);
12
15
  if (!options.skipNode) {
16
+ actions.push(`updated Node dependencies with ${packageManager} (${options.latest ? "latest" : "conservative"} mode)`);
13
17
  commands.push({
14
- command: options.latest ? "pnpm update --latest" : "pnpm update",
15
- name: "pnpm",
18
+ command: (0, package_manager_1.packageManagerUpdateCommand)(packageManager, options.latest),
19
+ name: packageManager,
16
20
  prefixColor: "magenta",
17
21
  });
18
22
  }
19
23
  if (!options.skipGo) {
24
+ actions.push(`updated Go modules with ${options.latest ? "latest" : "patch"} strategy`);
20
25
  commands.push({
21
26
  command: options.latest ? "go get -u ./... && go mod tidy" : "go get -u=patch ./... && go mod tidy",
22
27
  name: "go",
23
28
  prefixColor: "green",
24
29
  });
25
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
+ }
26
37
  if (commands.length === 0) {
27
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"]);
28
40
  return Promise.resolve();
29
41
  }
30
42
  return (0, concurrently_1.default)(commands).result.then(() => {
31
43
  (0, terminal_ui_1.printCommandSuccess)("update", "Dependency update completed");
44
+ (0, terminal_ui_1.printCommandSummary)("update", actions);
32
45
  });
33
46
  }
34
47
  exports.default = update;
package/index.js CHANGED
@@ -48,75 +48,91 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  // index.ts - 入口文件,用于处理命令行参数并调用相应的功能模块
50
50
  // 导入构建和打包功能
51
- const pack_1 = __importDefault(require("./commands/pack"));
51
+ const build_1 = __importDefault(require("./src/cli/commands/build"));
52
52
  // 导入开发模式功能
53
- const develop_1 = __importStar(require("./commands/develop"));
53
+ const develop_1 = __importStar(require("./src/cli/commands/develop"));
54
54
  // 导入安装后处理功能
55
- const postinstall_1 = __importDefault(require("./commands/postinstall"));
55
+ const install_1 = __importDefault(require("./src/cli/commands/install"));
56
56
  // 导入清理功能
57
- const cleanup_1 = __importDefault(require("./commands/cleanup"));
57
+ const cleanup_1 = __importDefault(require("./src/cli/commands/cleanup"));
58
58
  // 导入更新功能
59
- const update_1 = __importDefault(require("./commands/update"));
60
- const cli_options_1 = require("./src/cli-options");
59
+ const update_1 = __importDefault(require("./src/cli/commands/update"));
60
+ const options_1 = require("./src/cli/options");
61
+ const package_manager_1 = require("./src/config/package-manager");
62
+ const terminal_ui_1 = require("./src/cli/terminal-ui");
61
63
  // 获取命令行参数(去除前两个默认参数)
62
64
  const args = process.argv.slice(2);
63
65
  // 检查是否提供了命令
64
66
  if (args.length === 0) {
65
- console.error("未提供命令。请指定要运行的命令。");
67
+ (0, terminal_ui_1.printCommandError)("未提供命令。请指定要运行的命令。");
66
68
  process.exit(1);
67
69
  }
68
70
  function main() {
69
71
  return __awaiter(this, void 0, void 0, function* () {
70
72
  const command = args[0];
71
- const options = (0, cli_options_1.parseCLIOptions)(args.slice(1));
73
+ const options = (0, options_1.parseCLIOptions)(args.slice(1));
74
+ const rawPackageManager = (0, 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;
72
80
  switch (command) {
73
81
  case "dev":
74
82
  yield (0, develop_1.default)({
75
- noCleanup: (0, cli_options_1.hasFlag)(options, "no-cleanup"),
76
- skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
77
- skipNuxt: (0, cli_options_1.hasFlag)(options, "skip-nuxt"),
83
+ noCleanup: (0, options_1.hasFlag)(options, "no-cleanup"),
84
+ skipGo: (0, options_1.hasFlag)(options, "skip-go"),
85
+ skipNuxt: (0, options_1.hasFlag)(options, "skip-nuxt"),
78
86
  });
79
87
  break;
80
88
  case "dev:nuxt":
81
89
  yield (0, develop_1.developNuxt)({
82
- noCleanup: (0, cli_options_1.hasFlag)(options, "no-cleanup"),
90
+ noCleanup: (0, options_1.hasFlag)(options, "no-cleanup"),
83
91
  });
84
92
  break;
85
93
  case "dev:go":
86
94
  yield (0, develop_1.developGo)({
87
- noCleanup: (0, cli_options_1.hasFlag)(options, "no-cleanup"),
95
+ noCleanup: (0, options_1.hasFlag)(options, "no-cleanup"),
88
96
  });
89
97
  break;
90
98
  case "build":
91
- yield (0, pack_1.default)({
92
- binaryName: (0, cli_options_1.getOption)(options, "binary-name"),
93
- skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
94
- skipNuxt: (0, cli_options_1.hasFlag)(options, "skip-nuxt"),
99
+ yield (0, build_1.default)({
100
+ binaryName: (0, options_1.getOption)(options, "binary-name"),
101
+ skipGo: (0, options_1.hasFlag)(options, "skip-go"),
102
+ skipNuxt: (0, options_1.hasFlag)(options, "skip-nuxt"),
103
+ skipBuild: (0, options_1.hasFlag)(options, "skip-build"),
104
+ skipZip: (0, options_1.hasFlag)(options, "skip-zip"),
95
105
  });
96
106
  break;
97
107
  case "install":
98
108
  // 执行安装后的初始化操作
99
- yield (0, postinstall_1.default)();
109
+ yield (0, install_1.default)({
110
+ skipGo: (0, options_1.hasFlag)(options, "skip-go"),
111
+ skipNuxt: (0, options_1.hasFlag)(options, "skip-nuxt"),
112
+ });
100
113
  break;
101
114
  case "cleanup":
102
115
  // 执行清理操作
103
- yield (0, cleanup_1.default)();
116
+ yield (0, cleanup_1.default)({
117
+ dryRun: (0, options_1.hasFlag)(options, "dry-run"),
118
+ });
104
119
  break;
105
120
  case "update":
106
121
  // 更新依赖
107
122
  yield (0, update_1.default)({
108
- latest: (0, cli_options_1.hasFlag)(options, "latest"),
109
- skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
110
- skipNode: (0, cli_options_1.hasFlag)(options, "skip-node"),
123
+ latest: (0, options_1.getOptionalBooleanOption)(options, "latest"),
124
+ packageManager: packageManagerOption,
125
+ skipGo: (0, options_1.hasFlag)(options, "skip-go"),
126
+ skipNode: (0, options_1.hasFlag)(options, "skip-node"),
111
127
  });
112
128
  break;
113
129
  default:
114
- console.error(`未知命令: ${command}`);
130
+ (0, terminal_ui_1.printCommandError)(`未知命令: ${command}`);
115
131
  process.exit(1);
116
132
  }
117
133
  });
118
134
  }
119
135
  void main().catch((error) => {
120
- console.error(error);
136
+ (0, terminal_ui_1.printCommandError)("命令执行失败", error);
121
137
  process.exit(1);
122
138
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-gin-tools",
3
- "version": "0.2.22",
3
+ "version": "0.3.0",
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"
@@ -9,7 +9,7 @@
9
9
  "author": "",
10
10
  "license": "MIT",
11
11
  "scripts": {
12
- "build": "ts-node build.ts",
12
+ "build": "ts-node scripts/build-package.ts",
13
13
  "publish": "npm publish --access public"
14
14
  },
15
15
  "dependencies": {
@@ -0,0 +1,5 @@
1
+ {
2
+ "apiPath": "server/api",
3
+ "packageName": "api",
4
+ "serverPort": "8099"
5
+ }
@@ -0,0 +1,62 @@
1
+ {
2
+ "title": "Nuxt Gin Tools Pack Config",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "extraFiles": {
7
+ "type": "object",
8
+ "description": "额外需要打包的文件映射(key: 源文件路径,value: 打包后对应位置)",
9
+ "additionalProperties": {
10
+ "type": "string"
11
+ }
12
+ },
13
+ "extraFilesGlobs": {
14
+ "type": "array",
15
+ "description": "额外需要打包的文件 Glob(相对于项目根目录)",
16
+ "items": {
17
+ "type": "string"
18
+ }
19
+ },
20
+ "exclude": {
21
+ "type": "array",
22
+ "description": "排除文件/目录 Glob(相对于项目根目录)",
23
+ "items": {
24
+ "type": "string"
25
+ }
26
+ },
27
+ "zipName": {
28
+ "type": "string",
29
+ "description": "打包输出 zip 名称(相对于默认 zip 目录)"
30
+ },
31
+ "zipPath": {
32
+ "type": "string",
33
+ "description": "打包输出 zip 路径(相对于项目根目录或绝对路径)"
34
+ },
35
+ "serverPath": {
36
+ "type": "string",
37
+ "description": "服务器构建输出目录(相对于项目根目录或绝对路径)"
38
+ },
39
+ "beforePack": {
40
+ "description": "打包前钩子(仅在代码调用传入时生效)"
41
+ },
42
+ "afterPack": {
43
+ "description": "打包后钩子(仅在代码调用传入时生效)"
44
+ },
45
+ "cleanDist": {
46
+ "type": "boolean",
47
+ "description": "是否清理 dist"
48
+ },
49
+ "writeScripts": {
50
+ "type": "boolean",
51
+ "description": "是否写入启动脚本和 package.json"
52
+ },
53
+ "packageJson": {
54
+ "type": "object",
55
+ "description": "写入/覆盖 package.json 内容"
56
+ },
57
+ "overwrite": {
58
+ "type": "boolean",
59
+ "description": "复制时是否覆盖同名文件"
60
+ }
61
+ }
62
+ }