nuxt-gin-tools 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +6 -2
  2. package/index.js +1 -1
  3. package/package.json +7 -17
  4. package/src/cli/commands/build.d.ts +4 -1
  5. package/src/cli/commands/build.js +114 -19
  6. package/src/cli/commands/cleanup.d.ts +2 -0
  7. package/src/cli/commands/cleanup.js +65 -2
  8. package/src/cli/commands/develop.js +67 -22
  9. package/src/cli/commands/install.js +99 -44
  10. package/src/cli/commands/update.js +52 -17
  11. package/src/cli/prompt.d.ts +20 -0
  12. package/src/cli/prompt.js +72 -0
  13. package/src/config/package-manager.d.ts +2 -2
  14. package/src/config/package-manager.js +9 -2
  15. package/.go-watch.json +0 -20
  16. package/commands/api-generate.d.ts +0 -11
  17. package/commands/api-generate.js +0 -133
  18. package/commands/builder.d.ts +0 -7
  19. package/commands/builder.js +0 -35
  20. package/commands/cleanup.d.ts +0 -11
  21. package/commands/cleanup.js +0 -109
  22. package/commands/dev-go.d.ts +0 -8
  23. package/commands/dev-go.js +0 -306
  24. package/commands/develop.d.ts +0 -26
  25. package/commands/develop.js +0 -143
  26. package/commands/pack.d.ts +0 -36
  27. package/commands/pack.js +0 -392
  28. package/commands/postinstall.d.ts +0 -6
  29. package/commands/postinstall.js +0 -53
  30. package/commands/update.d.ts +0 -9
  31. package/commands/update.js +0 -47
  32. package/src/cli-options.d.ts +0 -9
  33. package/src/cli-options.js +0 -58
  34. package/src/go-gin-server.json +0 -5
  35. package/src/pack-config.schema.json +0 -62
  36. package/src/package-manager.d.ts +0 -7
  37. package/src/package-manager.js +0 -39
  38. package/src/server-config.json +0 -35
  39. package/src/terminal-ui.d.ts +0 -7
  40. package/src/terminal-ui.js +0 -118
  41. package/src/utils.d.ts +0 -7
  42. package/src/utils.js +0 -112
@@ -1,39 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
1
- {
2
- "title": "API configuration schema",
3
- "description": "API configuration schema. For more info see http://json-schema.org/ and https://frontaid.io/blog/json-schema-vscode/",
4
- "type": "object",
5
- "properties": {
6
- "ginPort": {
7
- "title": "The port for Gin / Gin框架端口",
8
- "type": "integer"
9
- },
10
- "nuxtPort": {
11
- "title": "The port for Nuxt / Nuxt框架devServer端口",
12
- "type": "integer"
13
- },
14
- "baseUrl": {
15
- "title": "The base url for nuxt. / Nuxt的BaseUrl",
16
- "type": "string",
17
- "pattern": "^\\/\\w.+"
18
- },
19
- "killPortBeforeDevelop": {
20
- "title": "Kill port before develop / 开发前释放端口",
21
- "type": "boolean",
22
- "default": true
23
- },
24
- "cleanupBeforeDevelop": {
25
- "title": "Cleanup before develop / 开发前清理",
26
- "type": "boolean",
27
- "default": false
28
- }
29
- },
30
- "required": [
31
- "ginPort",
32
- "nuxtPort",
33
- "baseUrl"
34
- ]
35
- }
@@ -1,7 +0,0 @@
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;
@@ -1,118 +0,0 @@
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.d.ts DELETED
@@ -1,7 +0,0 @@
1
- type KillPortOptions = {
2
- logPrefix?: string;
3
- portLabel?: string;
4
- };
5
- export declare function killPort(port: number, options?: KillPortOptions): void;
6
- export declare function killPorts(ports: Array<number | undefined>, options?: KillPortOptions): void;
7
- export {};
package/src/utils.js DELETED
@@ -1,112 +0,0 @@
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.killPort = killPort;
7
- exports.killPorts = killPorts;
8
- const child_process_1 = require("child_process");
9
- const os_1 = __importDefault(require("os"));
10
- const terminal_ui_1 = require("./terminal-ui");
11
- function isValidPort(port) {
12
- return Number.isInteger(port) && port > 0;
13
- }
14
- function buildMessage(pid, port, platform, options) {
15
- var _a;
16
- const prefix = (options === null || options === void 0 ? void 0 : options.logPrefix) ? `[${options.logPrefix}] ` : "";
17
- const label = (_a = options === null || options === void 0 ? void 0 : options.portLabel) !== null && _a !== void 0 ? _a : "port";
18
- return `${prefix}killed process ${pid} on ${label} ${port} (${platform})`;
19
- }
20
- function killPortUnix(port, options) {
21
- try {
22
- const output = (0, child_process_1.execSync)(`lsof -ti tcp:${port}`, {
23
- stdio: ["ignore", "pipe", "ignore"],
24
- })
25
- .toString()
26
- .trim();
27
- if (!output) {
28
- return;
29
- }
30
- const pids = output
31
- .split("\n")
32
- .map((pid) => Number(pid.trim()))
33
- .filter((pid) => Number.isInteger(pid) && pid > 0);
34
- for (const pid of pids) {
35
- try {
36
- process.kill(pid, "SIGKILL");
37
- (0, terminal_ui_1.printCommandSuccess)("port", buildMessage(pid, port, "unix", options));
38
- }
39
- catch (_a) {
40
- // Best-effort: if the process is already gone, ignore.
41
- }
42
- }
43
- }
44
- catch (_b) {
45
- // Best-effort: lsof might be missing or no process is listening on the port.
46
- }
47
- }
48
- function killPortWindows(port, options) {
49
- try {
50
- const output = (0, child_process_1.execSync)(`netstat -ano -p tcp`, {
51
- stdio: ["ignore", "pipe", "ignore"],
52
- })
53
- .toString()
54
- .trim();
55
- if (!output) {
56
- return;
57
- }
58
- const pids = new Set();
59
- for (const line of output.split("\n")) {
60
- const trimmed = line.trim();
61
- if (!trimmed || !trimmed.startsWith("TCP")) {
62
- continue;
63
- }
64
- const parts = trimmed.split(/\s+/);
65
- if (parts.length < 5) {
66
- continue;
67
- }
68
- const localAddress = parts[1];
69
- const pid = Number(parts[parts.length - 1]);
70
- const match = localAddress.match(/:(\d+)$/);
71
- if (!match) {
72
- continue;
73
- }
74
- const localPort = Number(match[1]);
75
- if (localPort === port && Number.isInteger(pid) && pid > 0) {
76
- pids.add(pid);
77
- }
78
- }
79
- for (const pid of pids) {
80
- try {
81
- (0, child_process_1.execSync)(`taskkill /PID ${pid} /F`, {
82
- stdio: ["ignore", "ignore", "ignore"],
83
- });
84
- (0, terminal_ui_1.printCommandSuccess)("port", buildMessage(pid, port, "win32", options));
85
- }
86
- catch (_a) {
87
- // Best-effort: if the process is already gone, ignore.
88
- }
89
- }
90
- }
91
- catch (_b) {
92
- // Best-effort: netstat might be missing or no process is listening on the port.
93
- }
94
- }
95
- function killPort(port, options) {
96
- if (!isValidPort(port)) {
97
- return;
98
- }
99
- if (os_1.default.platform() === "win32") {
100
- killPortWindows(port, options);
101
- return;
102
- }
103
- killPortUnix(port, options);
104
- }
105
- function killPorts(ports, options) {
106
- const validPorts = ports
107
- .filter((port) => typeof port === "number" && isValidPort(port))
108
- .filter((port, index, list) => list.indexOf(port) === index);
109
- for (const port of validPorts) {
110
- killPort(port, options);
111
- }
112
- }