nuxt-gin-tools 0.2.23 → 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.
@@ -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;
@@ -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
@@ -1,4 +1,4 @@
1
- import type { BuildOptions } from "../commands/builder";
1
+ import type { BuildOptions } from "./services/build-service";
2
2
  export interface PackConfig extends BuildOptions {
3
3
  /**
4
4
  * 是否跳过构建步骤
@@ -0,0 +1,7 @@
1
+ export type BuildOptions = {
2
+ binaryName?: string;
3
+ skipGo?: boolean;
4
+ skipNuxt?: boolean;
5
+ };
6
+ export declare function build(options?: BuildOptions): Promise<void> | Promise<import("concurrently").CloseEvent[]>;
7
+ export default build;
@@ -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;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 启动 Go 开发监听流程:执行 `go run main.go`,并在文件变更后自动重启。
3
+ *
4
+ * 该函数通常由 `develop()` 调用;执行后会持续监听,直到收到退出信号。
5
+ *
6
+ * @returns {Promise<void>} 仅在监听流程被中断并完成清理后返回。
7
+ */
8
+ export declare function startGoDev(ginPortOverride?: number | null): Promise<void>;