nuxt-gin-tools 0.2.23 → 0.3.1
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 +194 -72
- package/index.js +28 -28
- package/package.json +2 -2
- package/src/assets/go-gin-server.json +5 -0
- package/src/assets/pack-config.schema.json +62 -0
- package/src/assets/server-config.schema.json +35 -0
- package/src/cli/commands/build.d.ts +1 -0
- package/src/cli/commands/build.js +22 -0
- package/src/cli/commands/cleanup.d.ts +11 -0
- package/src/cli/commands/cleanup.js +115 -0
- package/src/cli/commands/develop.d.ts +26 -0
- package/src/cli/commands/develop.js +168 -0
- package/src/cli/commands/install.d.ts +6 -0
- package/src/cli/commands/install.js +59 -0
- package/src/cli/commands/update.d.ts +9 -0
- package/src/cli/commands/update.js +89 -0
- package/src/cli/options.d.ts +10 -0
- package/src/cli/options.js +66 -0
- package/src/cli/terminal-ui.d.ts +7 -0
- package/src/cli/terminal-ui.js +191 -0
- package/src/config/package-manager.d.ts +7 -0
- package/src/config/package-manager.js +39 -0
- package/src/nuxt-gin.d.ts +103 -0
- package/src/nuxt-gin.js +178 -0
- package/src/pack.d.ts +1 -1
- package/src/services/build-service.d.ts +7 -0
- package/src/services/build-service.js +35 -0
- package/src/services/go-dev-service.d.ts +8 -0
- package/src/services/go-dev-service.js +356 -0
- package/src/services/pack-service.d.ts +23 -0
- package/src/services/pack-service.js +372 -0
- package/src/system/ports.d.ts +7 -0
- package/src/system/ports.js +112 -0
|
@@ -0,0 +1,191 @@
|
|
|
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 MIN_WIDTH = 60;
|
|
15
|
+
const DEFAULT_WIDTH = 96;
|
|
16
|
+
const INDENT = " ";
|
|
17
|
+
function printLine(message = "", method = "log") {
|
|
18
|
+
if (method === "warn") {
|
|
19
|
+
console.warn(message);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (method === "error") {
|
|
23
|
+
console.error(message);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
console.log(message);
|
|
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));
|
|
107
|
+
}
|
|
108
|
+
function formatClock() {
|
|
109
|
+
return new Date().toLocaleTimeString("en-GB", {
|
|
110
|
+
hour: "2-digit",
|
|
111
|
+
minute: "2-digit",
|
|
112
|
+
second: "2-digit",
|
|
113
|
+
hour12: false,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function commandChip(command) {
|
|
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);
|
|
133
|
+
}
|
|
134
|
+
function printCommandBanner(command, subtitle) {
|
|
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);
|
|
137
|
+
}
|
|
138
|
+
function printCommandSuccess(command, message) {
|
|
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
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function printCommandInfo(label, message) {
|
|
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
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function printCommandWarn(message) {
|
|
153
|
+
printBlock(chalk_1.default.bold.yellow("warning"), chalk_1.default.yellow(message), chalk_1.default.yellow, "warn");
|
|
154
|
+
}
|
|
155
|
+
function printCommandError(message, error) {
|
|
156
|
+
const detail = error instanceof Error ? error.message : error !== undefined ? String(error) : "";
|
|
157
|
+
printBlock(chalk_1.default.bold.red("error"), chalk_1.default.redBright(message), chalk_1.default.red, "error");
|
|
158
|
+
if (detail) {
|
|
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");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function printCommandLog(label, message) {
|
|
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
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function printCommandSummary(command, items) {
|
|
175
|
+
const normalizedItems = items.map((item) => item.trim()).filter(Boolean);
|
|
176
|
+
if (normalizedItems.length === 0) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
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: " ",
|
|
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));
|
|
191
|
+
}
|
|
@@ -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,103 @@
|
|
|
1
|
+
import type { CleanupOptions } from "./cli/commands/cleanup";
|
|
2
|
+
import type { DevelopOptions } from "./cli/commands/develop";
|
|
3
|
+
import type { PostInstallOptions } from "./cli/commands/install";
|
|
4
|
+
import type { UpdateOptions } from "./cli/commands/update";
|
|
5
|
+
import type { PackConfig } from "./pack";
|
|
6
|
+
import type { ServerConfigJson } from "./nuxt-config";
|
|
7
|
+
/**
|
|
8
|
+
* Go watcher configurable defaults.
|
|
9
|
+
* Go watcher 的可配置默认项。
|
|
10
|
+
*/
|
|
11
|
+
export type GoWatchListConfig = {
|
|
12
|
+
/** File extensions. / 文件扩展名。 */
|
|
13
|
+
ext?: string[];
|
|
14
|
+
/** Directories. / 目录。 */
|
|
15
|
+
dir?: string[];
|
|
16
|
+
/** Individual files. / 单个文件。 */
|
|
17
|
+
file?: string[];
|
|
18
|
+
/** Regex patterns, mainly for exclude rules. / 正则模式,主要用于排除规则。 */
|
|
19
|
+
regex?: string[];
|
|
20
|
+
};
|
|
21
|
+
export type GoWatchConfigOptions = {
|
|
22
|
+
/** Include rules. / 包含规则。 */
|
|
23
|
+
include?: Omit<GoWatchListConfig, "regex">;
|
|
24
|
+
/** Exclude rules. / 排除规则。 */
|
|
25
|
+
exclude?: GoWatchListConfig;
|
|
26
|
+
/** Temporary output directory. / 临时输出目录。 */
|
|
27
|
+
tmpDir?: string;
|
|
28
|
+
/** Test data directory name. / 测试数据目录名称。 */
|
|
29
|
+
testDataDir?: string;
|
|
30
|
+
/** Deprecated flat include ext. / 兼容旧版:扁平 includeExt。 */
|
|
31
|
+
includeExt?: string[];
|
|
32
|
+
/** Deprecated flat include dir. / 兼容旧版:扁平 includeDir。 */
|
|
33
|
+
includeDir?: string[];
|
|
34
|
+
/** Deprecated flat include file. / 兼容旧版:扁平 includeFile。 */
|
|
35
|
+
includeFile?: string[];
|
|
36
|
+
/** Deprecated flat exclude dir. / 兼容旧版:扁平 excludeDir。 */
|
|
37
|
+
excludeDir?: string[];
|
|
38
|
+
/** Deprecated flat exclude file. / 兼容旧版:扁平 excludeFile。 */
|
|
39
|
+
excludeFile?: string[];
|
|
40
|
+
/** Deprecated flat exclude regex. / 兼容旧版:扁平 excludeRegex。 */
|
|
41
|
+
excludeRegex?: string[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Unified project config consumed by `nuxt-gin-tools`.
|
|
45
|
+
* `nuxt-gin-tools` 使用的统一项目配置。
|
|
46
|
+
*/
|
|
47
|
+
export interface NuxtGinConfig {
|
|
48
|
+
/** CLI defaults for development commands. / 开发命令的默认配置。 */
|
|
49
|
+
dev?: DevelopOptions & {
|
|
50
|
+
/** Force cleanup/bootstrap before dev starts. / 开发前强制执行清理与初始化。 */
|
|
51
|
+
cleanupBeforeDevelop?: boolean;
|
|
52
|
+
/** Kill occupied ports before dev starts. / 开发前释放已占用端口。 */
|
|
53
|
+
killPortBeforeDevelop?: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** Built-in Go watcher defaults. / Go watcher 的内置默认规则。 */
|
|
56
|
+
goWatch?: GoWatchConfigOptions;
|
|
57
|
+
/** CLI defaults for install/bootstrap. / install 初始化命令的默认配置。 */
|
|
58
|
+
install?: PostInstallOptions;
|
|
59
|
+
/** CLI defaults for cleanup. / cleanup 命令的默认配置。 */
|
|
60
|
+
cleanup?: CleanupOptions;
|
|
61
|
+
/** CLI defaults for dependency updates. / 依赖更新命令的默认配置。 */
|
|
62
|
+
update?: Partial<UpdateOptions>;
|
|
63
|
+
/** CLI defaults for build/pack. / build 与 pack 的默认配置。 */
|
|
64
|
+
pack?: PackConfig;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Result of resolving `nuxt-gin.config.*`.
|
|
68
|
+
* 解析 `nuxt-gin.config.*` 后得到的结果。
|
|
69
|
+
*/
|
|
70
|
+
export type LoadedNuxtGinConfig = {
|
|
71
|
+
/** Parsed config object. / 解析后的配置对象。 */
|
|
72
|
+
config: NuxtGinConfig;
|
|
73
|
+
/** Selected config file path. / 实际选中的配置文件路径。 */
|
|
74
|
+
sourcePath?: string;
|
|
75
|
+
/** Non-fatal warnings collected during resolution. / 解析过程中收集到的非致命警告。 */
|
|
76
|
+
warnings: string[];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Identity helper for typed config authoring in `nuxt-gin.config.ts`.
|
|
80
|
+
* 用于 `nuxt-gin.config.ts` 的类型化配置 helper。
|
|
81
|
+
*/
|
|
82
|
+
export declare function createNuxtGinConfig(config: NuxtGinConfig): NuxtGinConfig;
|
|
83
|
+
/**
|
|
84
|
+
* Load `nuxt-gin.config.*` from the current project root.
|
|
85
|
+
* 从当前项目根目录加载 `nuxt-gin.config.*`。
|
|
86
|
+
*/
|
|
87
|
+
export declare function loadNuxtGinConfig(): LoadedNuxtGinConfig | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Read and validate legacy runtime server config from `server.config.json`.
|
|
90
|
+
* 从 `server.config.json` 读取并校验运行时服务配置。
|
|
91
|
+
*/
|
|
92
|
+
export declare function readLegacyServerConfig(): ServerConfigJson | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Resolve the project config and always return a stable object shape.
|
|
95
|
+
* 解析项目配置,并始终返回稳定的对象结构。
|
|
96
|
+
*/
|
|
97
|
+
export declare function resolveNuxtGinProjectConfig(): LoadedNuxtGinConfig;
|
|
98
|
+
/**
|
|
99
|
+
* Merge objects while ignoring `undefined` from the override side.
|
|
100
|
+
* 合并对象时忽略 override 侧的 `undefined` 值。
|
|
101
|
+
*/
|
|
102
|
+
export declare function mergeDefined<T extends object>(base?: Partial<T>, override?: Partial<T>): T;
|
|
103
|
+
export default createNuxtGinConfig;
|
package/src/nuxt-gin.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createNuxtGinConfig = createNuxtGinConfig;
|
|
37
|
+
exports.loadNuxtGinConfig = loadNuxtGinConfig;
|
|
38
|
+
exports.readLegacyServerConfig = readLegacyServerConfig;
|
|
39
|
+
exports.resolveNuxtGinProjectConfig = resolveNuxtGinProjectConfig;
|
|
40
|
+
exports.mergeDefined = mergeDefined;
|
|
41
|
+
const FS = __importStar(require("fs-extra"));
|
|
42
|
+
const Path = __importStar(require("path"));
|
|
43
|
+
const { createJiti } = require("jiti");
|
|
44
|
+
const NUXT_GIN_CONFIG_PATH = Path.resolve(process.cwd(), "nuxt-gin.config.json");
|
|
45
|
+
const NUXT_GIN_CONFIG_TS_PATH = Path.resolve(process.cwd(), "nuxt-gin.config.ts");
|
|
46
|
+
const NUXT_GIN_CONFIG_JS_PATH = Path.resolve(process.cwd(), "nuxt-gin.config.js");
|
|
47
|
+
const NUXT_GIN_CONFIG_CJS_PATH = Path.resolve(process.cwd(), "nuxt-gin.config.cjs");
|
|
48
|
+
const NUXT_GIN_CONFIG_MJS_PATH = Path.resolve(process.cwd(), "nuxt-gin.config.mjs");
|
|
49
|
+
const LEGACY_SERVER_CONFIG_PATH = Path.resolve(process.cwd(), "server.config.json");
|
|
50
|
+
/**
|
|
51
|
+
* Identity helper for typed config authoring in `nuxt-gin.config.ts`.
|
|
52
|
+
* 用于 `nuxt-gin.config.ts` 的类型化配置 helper。
|
|
53
|
+
*/
|
|
54
|
+
function createNuxtGinConfig(config) {
|
|
55
|
+
return config;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Narrow an unknown value to a plain object.
|
|
59
|
+
* 将未知值收窄为普通对象。
|
|
60
|
+
*/
|
|
61
|
+
function isPlainObject(value) {
|
|
62
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Unwrap default export from CJS/ESM loaded modules.
|
|
66
|
+
* 解包通过 CJS/ESM 加载后的默认导出。
|
|
67
|
+
*/
|
|
68
|
+
function normalizeModuleExport(moduleValue) {
|
|
69
|
+
if (isPlainObject(moduleValue) && "default" in moduleValue) {
|
|
70
|
+
return moduleValue.default;
|
|
71
|
+
}
|
|
72
|
+
return moduleValue;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Load config from JSON or executable module files.
|
|
76
|
+
* 从 JSON 或可执行模块文件中加载配置。
|
|
77
|
+
*/
|
|
78
|
+
function loadConfigModule(configPath) {
|
|
79
|
+
if (configPath.endsWith(".json")) {
|
|
80
|
+
return FS.readJSONSync(configPath);
|
|
81
|
+
}
|
|
82
|
+
const jiti = createJiti(__filename, { moduleCache: false, interopDefault: true });
|
|
83
|
+
return jiti(configPath);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Validate runtime server config that still lives in `server.config.json`.
|
|
87
|
+
* 校验仍然保存在 `server.config.json` 中的运行时服务配置。
|
|
88
|
+
*/
|
|
89
|
+
function validateServerConfig(serverConfig, sourceLabel) {
|
|
90
|
+
if (!isPlainObject(serverConfig)) {
|
|
91
|
+
throw new Error(`${sourceLabel}: serverConfig must be an object`);
|
|
92
|
+
}
|
|
93
|
+
const { baseUrl, nuxtPort, ginPort } = serverConfig;
|
|
94
|
+
if (typeof baseUrl !== "string" || baseUrl.trim().length === 0) {
|
|
95
|
+
throw new Error(`${sourceLabel}: serverConfig.baseUrl must be a non-empty string`);
|
|
96
|
+
}
|
|
97
|
+
if (!Number.isInteger(nuxtPort) || nuxtPort <= 0) {
|
|
98
|
+
throw new Error(`${sourceLabel}: serverConfig.nuxtPort must be a positive integer`);
|
|
99
|
+
}
|
|
100
|
+
if (!Number.isInteger(ginPort) || ginPort <= 0) {
|
|
101
|
+
throw new Error(`${sourceLabel}: serverConfig.ginPort must be a positive integer`);
|
|
102
|
+
}
|
|
103
|
+
return serverConfig;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Validate the top-level `nuxt-gin.config.*` shape.
|
|
107
|
+
* 校验顶层 `nuxt-gin.config.*` 的结构。
|
|
108
|
+
*/
|
|
109
|
+
function validateNuxtGinConfig(config, sourcePath) {
|
|
110
|
+
if (!isPlainObject(config)) {
|
|
111
|
+
throw new Error(`${Path.basename(sourcePath)} must export an object`);
|
|
112
|
+
}
|
|
113
|
+
return config;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Load `nuxt-gin.config.*` from the current project root.
|
|
117
|
+
* 从当前项目根目录加载 `nuxt-gin.config.*`。
|
|
118
|
+
*/
|
|
119
|
+
function loadNuxtGinConfig() {
|
|
120
|
+
const candidates = [
|
|
121
|
+
NUXT_GIN_CONFIG_TS_PATH,
|
|
122
|
+
NUXT_GIN_CONFIG_JS_PATH,
|
|
123
|
+
NUXT_GIN_CONFIG_CJS_PATH,
|
|
124
|
+
NUXT_GIN_CONFIG_MJS_PATH,
|
|
125
|
+
NUXT_GIN_CONFIG_PATH,
|
|
126
|
+
].filter((configPath) => FS.existsSync(configPath));
|
|
127
|
+
if (candidates.length === 0) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const warnings = [];
|
|
131
|
+
if (candidates.length > 1) {
|
|
132
|
+
warnings.push(`multiple nuxt-gin config files found (${candidates.map((item) => Path.basename(item)).join(", ")}); using ${Path.basename(candidates[0])}`);
|
|
133
|
+
}
|
|
134
|
+
const selectedPath = candidates[0];
|
|
135
|
+
const loadedConfig = normalizeModuleExport(loadConfigModule(selectedPath));
|
|
136
|
+
return {
|
|
137
|
+
config: validateNuxtGinConfig(loadedConfig, selectedPath),
|
|
138
|
+
sourcePath: selectedPath,
|
|
139
|
+
warnings,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Read and validate legacy runtime server config from `server.config.json`.
|
|
144
|
+
* 从 `server.config.json` 读取并校验运行时服务配置。
|
|
145
|
+
*/
|
|
146
|
+
function readLegacyServerConfig() {
|
|
147
|
+
if (!FS.existsSync(LEGACY_SERVER_CONFIG_PATH)) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
return validateServerConfig(FS.readJSONSync(LEGACY_SERVER_CONFIG_PATH), Path.basename(LEGACY_SERVER_CONFIG_PATH));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Resolve the project config and always return a stable object shape.
|
|
154
|
+
* 解析项目配置,并始终返回稳定的对象结构。
|
|
155
|
+
*/
|
|
156
|
+
function resolveNuxtGinProjectConfig() {
|
|
157
|
+
var _a, _b;
|
|
158
|
+
const loaded = loadNuxtGinConfig();
|
|
159
|
+
return {
|
|
160
|
+
config: (_a = loaded === null || loaded === void 0 ? void 0 : loaded.config) !== null && _a !== void 0 ? _a : {},
|
|
161
|
+
sourcePath: loaded === null || loaded === void 0 ? void 0 : loaded.sourcePath,
|
|
162
|
+
warnings: (_b = loaded === null || loaded === void 0 ? void 0 : loaded.warnings) !== null && _b !== void 0 ? _b : [],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Merge objects while ignoring `undefined` from the override side.
|
|
167
|
+
* 合并对象时忽略 override 侧的 `undefined` 值。
|
|
168
|
+
*/
|
|
169
|
+
function mergeDefined(base, override) {
|
|
170
|
+
const merged = Object.assign({}, (base !== null && base !== void 0 ? base : {}));
|
|
171
|
+
for (const [key, value] of Object.entries(override !== null && override !== void 0 ? override : {})) {
|
|
172
|
+
if (value !== undefined) {
|
|
173
|
+
merged[key] = value;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return merged;
|
|
177
|
+
}
|
|
178
|
+
exports.default = createNuxtGinConfig;
|
package/src/pack.d.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
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.build = build;
|
|
7
|
+
const concurrently_1 = __importDefault(require("concurrently"));
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
const defaultBinaryName = os_1.default.platform() === "win32" ? "production.exe" : "production";
|
|
13
|
+
function build(options = {}) {
|
|
14
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(cwd, "vue/.output"));
|
|
15
|
+
const commands = [];
|
|
16
|
+
if (!options.skipGo) {
|
|
17
|
+
commands.push({
|
|
18
|
+
command: `go build -o ./.build/.server/${options.binaryName || defaultBinaryName} .`,
|
|
19
|
+
name: "go",
|
|
20
|
+
prefixColor: "green",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (!options.skipNuxt) {
|
|
24
|
+
commands.push({
|
|
25
|
+
command: "npx nuxt generate",
|
|
26
|
+
name: "nuxt",
|
|
27
|
+
prefixColor: "blue",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (commands.length === 0) {
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
return (0, concurrently_1.default)(commands).result;
|
|
34
|
+
}
|
|
35
|
+
exports.default = build;
|