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.
- package/README.md +6 -2
- package/index.js +1 -1
- package/package.json +7 -17
- package/src/cli/commands/build.d.ts +4 -1
- package/src/cli/commands/build.js +114 -19
- package/src/cli/commands/cleanup.d.ts +2 -0
- package/src/cli/commands/cleanup.js +65 -2
- package/src/cli/commands/develop.js +67 -22
- package/src/cli/commands/install.js +99 -44
- package/src/cli/commands/update.js +52 -17
- package/src/cli/prompt.d.ts +20 -0
- package/src/cli/prompt.js +72 -0
- package/src/config/package-manager.d.ts +2 -2
- package/src/config/package-manager.js +9 -2
- package/.go-watch.json +0 -20
- package/commands/api-generate.d.ts +0 -11
- package/commands/api-generate.js +0 -133
- package/commands/builder.d.ts +0 -7
- package/commands/builder.js +0 -35
- package/commands/cleanup.d.ts +0 -11
- package/commands/cleanup.js +0 -109
- package/commands/dev-go.d.ts +0 -8
- package/commands/dev-go.js +0 -306
- package/commands/develop.d.ts +0 -26
- package/commands/develop.js +0 -143
- package/commands/pack.d.ts +0 -36
- package/commands/pack.js +0 -392
- package/commands/postinstall.d.ts +0 -6
- package/commands/postinstall.js +0 -53
- package/commands/update.d.ts +0 -9
- package/commands/update.js +0 -47
- package/src/cli-options.d.ts +0 -9
- package/src/cli-options.js +0 -58
- package/src/go-gin-server.json +0 -5
- package/src/pack-config.schema.json +0 -62
- package/src/package-manager.d.ts +0 -7
- package/src/package-manager.js +0 -39
- package/src/server-config.json +0 -35
- package/src/terminal-ui.d.ts +0 -7
- package/src/terminal-ui.js +0 -118
- package/src/utils.d.ts +0 -7
- package/src/utils.js +0 -112
package/commands/pack.js
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.FILES_TO_COPY = exports.PACKAGE_JSON_CONTENT = exports.SERVER_EXECUTABLE = exports.BUILD_EXECUTABLE = exports.PACK_CONFIG_MJS_PATH = exports.PACK_CONFIG_CJS_PATH = exports.PACK_CONFIG_JS_PATH = exports.PACK_CONFIG_TS_PATH = exports.PACK_CONFIG_PATH = exports.ORIGINAL_DIST_PATH = exports.SERVER_PATH = exports.ZIP_PATH = void 0;
|
|
49
|
-
exports.builtPath = builtPath;
|
|
50
|
-
exports.buildAndPack = buildAndPack;
|
|
51
|
-
// 导入项目构建工具,用于执行 Nuxt 项目的构建流程
|
|
52
|
-
const builder_1 = __importDefault(require("./builder"));
|
|
53
|
-
// 导入 7zip 压缩工具库,用于将构建后的文件打包为 7z 格式
|
|
54
|
-
const Zip = __importStar(require("7zip-min"));
|
|
55
|
-
// 导入增强版的文件系统模块,提供更丰富的文件操作 API
|
|
56
|
-
const FS = __importStar(require("fs-extra"));
|
|
57
|
-
// 导入路径处理模块,用于规范化和解析文件路径
|
|
58
|
-
const Path = __importStar(require("path"));
|
|
59
|
-
const os = __importStar(require("os"));
|
|
60
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
61
|
-
const terminal_ui_1 = require("../src/terminal-ui");
|
|
62
|
-
const { createJiti } = require("jiti");
|
|
63
|
-
/**
|
|
64
|
-
* 生成相对于服务器构建目录的绝对路径
|
|
65
|
-
* @param relativePath - 相对路径
|
|
66
|
-
* @returns 解析后的绝对路径
|
|
67
|
-
*/
|
|
68
|
-
function builtPath(relativePath) {
|
|
69
|
-
return Path.resolve(exports.SERVER_PATH, relativePath);
|
|
70
|
-
}
|
|
71
|
-
// 定义打包后的 7z 文件输出路径
|
|
72
|
-
exports.ZIP_PATH = Path.resolve(process.cwd(), ".build/production/server.7z");
|
|
73
|
-
// 定义服务器构建文件的输出目录
|
|
74
|
-
exports.SERVER_PATH = Path.resolve(process.cwd(), ".build/production/server");
|
|
75
|
-
// 定义原始 dist 目录路径,用于清理操作
|
|
76
|
-
exports.ORIGINAL_DIST_PATH = Path.resolve(process.cwd(), "dist");
|
|
77
|
-
exports.PACK_CONFIG_PATH = Path.resolve(process.cwd(), "pack.config.json");
|
|
78
|
-
exports.PACK_CONFIG_TS_PATH = Path.resolve(process.cwd(), "pack.config.ts");
|
|
79
|
-
exports.PACK_CONFIG_JS_PATH = Path.resolve(process.cwd(), "pack.config.js");
|
|
80
|
-
exports.PACK_CONFIG_CJS_PATH = Path.resolve(process.cwd(), "pack.config.cjs");
|
|
81
|
-
exports.PACK_CONFIG_MJS_PATH = Path.resolve(process.cwd(), "pack.config.mjs");
|
|
82
|
-
exports.BUILD_EXECUTABLE = os.platform() === "win32" ? "production.exe" : "production";
|
|
83
|
-
exports.SERVER_EXECUTABLE = os.platform() === "win32" ? "server-production.exe" : "server-production"; // 根据操作系统选择可执行文件名
|
|
84
|
-
// 定义打包后项目的 package.json 内容
|
|
85
|
-
exports.PACKAGE_JSON_CONTENT = {
|
|
86
|
-
private: true,
|
|
87
|
-
scripts: {
|
|
88
|
-
start: `./${exports.SERVER_EXECUTABLE}`, // 定义启动命令
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
// 定义需要复制到构建目录的文件映射关系(目标为构建目录下的相对路径)
|
|
92
|
-
const DEFAULT_FILES_TO_COPY = {
|
|
93
|
-
"vue/.output": "vue/.output", // Vue 应用构建输出
|
|
94
|
-
[`.build/.server/${exports.BUILD_EXECUTABLE}`]: exports.SERVER_EXECUTABLE, // 生产环境可执行文件
|
|
95
|
-
"server.config.json": "server.config.json", // 服务器配置文件
|
|
96
|
-
};
|
|
97
|
-
// 兼容旧导出:默认构建目录下的绝对目标路径
|
|
98
|
-
exports.FILES_TO_COPY = Object.fromEntries(Object.entries(DEFAULT_FILES_TO_COPY).map(([src, dest]) => [src, builtPath(dest)]));
|
|
99
|
-
function warnPackConfig(message) {
|
|
100
|
-
(0, terminal_ui_1.printCommandWarn)(`[pack] ${message}`);
|
|
101
|
-
}
|
|
102
|
-
function errorPackConfig(message) {
|
|
103
|
-
throw new Error(`[nuxt-gin-tools][pack] ${message}`);
|
|
104
|
-
}
|
|
105
|
-
function isPlainObject(value) {
|
|
106
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107
|
-
}
|
|
108
|
-
function validateStringArray(fieldName, value, issues) {
|
|
109
|
-
if (value === undefined) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (!Array.isArray(value)) {
|
|
113
|
-
issues.push({ level: "error", message: `${fieldName} must be an array of strings` });
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
for (const item of value) {
|
|
117
|
-
if (typeof item !== "string") {
|
|
118
|
-
issues.push({ level: "error", message: `${fieldName} must contain only strings` });
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function validateStringRecord(fieldName, value, issues) {
|
|
124
|
-
if (value === undefined) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (!isPlainObject(value)) {
|
|
128
|
-
issues.push({ level: "error", message: `${fieldName} must be an object of string to string` });
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
for (const [key, item] of Object.entries(value)) {
|
|
132
|
-
if (typeof key !== "string" || typeof item !== "string") {
|
|
133
|
-
issues.push({ level: "error", message: `${fieldName} must be an object of string to string` });
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function validatePackConfig(config, sourcePath) {
|
|
139
|
-
if (!isPlainObject(config)) {
|
|
140
|
-
errorPackConfig(`${Path.basename(sourcePath)} must export an object`);
|
|
141
|
-
}
|
|
142
|
-
const issues = [];
|
|
143
|
-
const typedConfig = config;
|
|
144
|
-
const stringFields = ["binaryName", "zipName", "zipPath", "serverPath"];
|
|
145
|
-
for (const field of stringFields) {
|
|
146
|
-
const value = typedConfig[field];
|
|
147
|
-
if (value !== undefined && typeof value !== "string") {
|
|
148
|
-
issues.push({ level: "error", message: `${field} must be a string` });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const booleanFields = [
|
|
152
|
-
"skipGo",
|
|
153
|
-
"skipNuxt",
|
|
154
|
-
"skipBuild",
|
|
155
|
-
"skipZip",
|
|
156
|
-
"cleanDist",
|
|
157
|
-
"writeScripts",
|
|
158
|
-
"overwrite",
|
|
159
|
-
];
|
|
160
|
-
for (const field of booleanFields) {
|
|
161
|
-
const value = typedConfig[field];
|
|
162
|
-
if (value !== undefined && typeof value !== "boolean") {
|
|
163
|
-
issues.push({ level: "error", message: `${field} must be a boolean` });
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
validateStringArray("extraFilesGlobs", typedConfig.extraFilesGlobs, issues);
|
|
167
|
-
validateStringArray("exclude", typedConfig.exclude, issues);
|
|
168
|
-
validateStringRecord("extraFiles", typedConfig.extraFiles, issues);
|
|
169
|
-
if (typedConfig.packageJson !== undefined && !isPlainObject(typedConfig.packageJson)) {
|
|
170
|
-
issues.push({ level: "error", message: `packageJson must be an object` });
|
|
171
|
-
}
|
|
172
|
-
if (typedConfig.beforePack !== undefined && typeof typedConfig.beforePack !== "function") {
|
|
173
|
-
issues.push({ level: "error", message: `beforePack must be a function` });
|
|
174
|
-
}
|
|
175
|
-
if (typedConfig.afterPack !== undefined && typeof typedConfig.afterPack !== "function") {
|
|
176
|
-
issues.push({ level: "error", message: `afterPack must be a function` });
|
|
177
|
-
}
|
|
178
|
-
if (typedConfig.zipName !== undefined && typedConfig.zipPath !== undefined) {
|
|
179
|
-
issues.push({ level: "warn", message: `zipPath and zipName are both set; zipPath takes precedence` });
|
|
180
|
-
}
|
|
181
|
-
if (typedConfig.skipGo === true && typedConfig.skipNuxt === true) {
|
|
182
|
-
issues.push({ level: "warn", message: `skipGo and skipNuxt are both true; build step will be skipped` });
|
|
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
|
-
}
|
|
187
|
-
for (const issue of issues) {
|
|
188
|
-
if (issue.level === "warn") {
|
|
189
|
-
warnPackConfig(`${Path.basename(sourcePath)}: ${issue.message}`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const errors = issues.filter((issue) => issue.level === "error");
|
|
193
|
-
if (errors.length > 0) {
|
|
194
|
-
errorPackConfig(`${Path.basename(sourcePath)} is invalid:\n- ${errors.map((item) => item.message).join("\n- ")}`);
|
|
195
|
-
}
|
|
196
|
-
return config;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* 写入启动脚本和 package.json 文件到构建目录
|
|
200
|
-
*/
|
|
201
|
-
function writeScriptFiles(serverPath, config) {
|
|
202
|
-
// 写入 Windows 批处理启动脚本
|
|
203
|
-
FS.outputFileSync(Path.resolve(serverPath, "start.bat"), `powershell -ExecutionPolicy ByPass -File ./start.ps1`);
|
|
204
|
-
// 写入 PowerShell 启动脚本
|
|
205
|
-
FS.outputFileSync(Path.resolve(serverPath, "start.ps1"), `./${exports.SERVER_EXECUTABLE}`);
|
|
206
|
-
// 写入 Linux/macOS 启动脚本
|
|
207
|
-
FS.outputFileSync(Path.resolve(serverPath, "start.sh"), `./${exports.SERVER_EXECUTABLE}`);
|
|
208
|
-
// 写入 package.json 文件,使用 2 个空格缩进
|
|
209
|
-
const mergedPackageJson = mergePackageJson(exports.PACKAGE_JSON_CONTENT, config === null || config === void 0 ? void 0 : config.packageJson);
|
|
210
|
-
FS.outputJSONSync(Path.resolve(serverPath, "package.json"), mergedPackageJson, { spaces: 2 });
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* 将配置的源文件复制到构建目录
|
|
214
|
-
*/
|
|
215
|
-
function copyGeneratedFiles(serverPath, config) {
|
|
216
|
-
var _a;
|
|
217
|
-
const copyOptions = {
|
|
218
|
-
overwrite: (config === null || config === void 0 ? void 0 : config.overwrite) !== false,
|
|
219
|
-
errorOnExist: (config === null || config === void 0 ? void 0 : config.overwrite) === false,
|
|
220
|
-
};
|
|
221
|
-
// 遍历文件映射,将每个源文件复制到目标位置
|
|
222
|
-
for (const [src, dest] of Object.entries(DEFAULT_FILES_TO_COPY)) {
|
|
223
|
-
const resolvedDest = Path.resolve(serverPath, dest);
|
|
224
|
-
FS.copySync(Path.resolve(process.cwd(), src), resolvedDest, copyOptions);
|
|
225
|
-
}
|
|
226
|
-
if (config === null || config === void 0 ? void 0 : config.extraFiles) {
|
|
227
|
-
for (const [src, dest] of Object.entries(config.extraFiles)) {
|
|
228
|
-
const resolvedSrc = Path.resolve(process.cwd(), src);
|
|
229
|
-
const resolvedDest = Path.isAbsolute(dest) ? dest : Path.resolve(serverPath, dest);
|
|
230
|
-
FS.copySync(resolvedSrc, resolvedDest, copyOptions);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if ((_a = config === null || config === void 0 ? void 0 : config.extraFilesGlobs) === null || _a === void 0 ? void 0 : _a.length) {
|
|
234
|
-
const matchedFiles = fast_glob_1.default.sync(config.extraFilesGlobs, {
|
|
235
|
-
cwd: process.cwd(),
|
|
236
|
-
onlyFiles: true,
|
|
237
|
-
dot: true,
|
|
238
|
-
ignore: config.exclude,
|
|
239
|
-
});
|
|
240
|
-
for (const file of matchedFiles) {
|
|
241
|
-
const resolvedSrc = Path.resolve(process.cwd(), file);
|
|
242
|
-
const resolvedDest = Path.resolve(serverPath, file);
|
|
243
|
-
FS.copySync(resolvedSrc, resolvedDest, copyOptions);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function mergePackageJson(base, override) {
|
|
248
|
-
if (!override) {
|
|
249
|
-
return base;
|
|
250
|
-
}
|
|
251
|
-
const baseScripts = typeof base.scripts === "object" && base.scripts ? base.scripts : {};
|
|
252
|
-
const overrideScripts = typeof override.scripts === "object" && override.scripts ? override.scripts : {};
|
|
253
|
-
return Object.assign(Object.assign(Object.assign({}, base), override), { scripts: Object.assign(Object.assign({}, baseScripts), overrideScripts) });
|
|
254
|
-
}
|
|
255
|
-
function readPackConfigFromCwd() {
|
|
256
|
-
const candidates = [
|
|
257
|
-
exports.PACK_CONFIG_TS_PATH,
|
|
258
|
-
exports.PACK_CONFIG_JS_PATH,
|
|
259
|
-
exports.PACK_CONFIG_CJS_PATH,
|
|
260
|
-
exports.PACK_CONFIG_MJS_PATH,
|
|
261
|
-
exports.PACK_CONFIG_PATH,
|
|
262
|
-
].filter((configPath) => FS.existsSync(configPath));
|
|
263
|
-
if (candidates.length === 0) {
|
|
264
|
-
return undefined;
|
|
265
|
-
}
|
|
266
|
-
if (candidates.length > 1) {
|
|
267
|
-
warnPackConfig(`multiple pack config files found (${candidates.map((item) => Path.basename(item)).join(", ")}); using ${Path.basename(candidates[0])}`);
|
|
268
|
-
}
|
|
269
|
-
const selectedPath = candidates[0];
|
|
270
|
-
let loadedConfig;
|
|
271
|
-
if (selectedPath.endsWith(".json")) {
|
|
272
|
-
loadedConfig = FS.readJSONSync(selectedPath);
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
const jiti = createJiti(__filename, { moduleCache: false, interopDefault: true });
|
|
276
|
-
loadedConfig = jiti(selectedPath);
|
|
277
|
-
}
|
|
278
|
-
const normalizedConfig = isPlainObject(loadedConfig) && "default" in loadedConfig
|
|
279
|
-
? loadedConfig.default
|
|
280
|
-
: loadedConfig;
|
|
281
|
-
return validatePackConfig(normalizedConfig, selectedPath);
|
|
282
|
-
}
|
|
283
|
-
function resolveServerPath(config) {
|
|
284
|
-
if (!(config === null || config === void 0 ? void 0 : config.serverPath)) {
|
|
285
|
-
return exports.SERVER_PATH;
|
|
286
|
-
}
|
|
287
|
-
return Path.isAbsolute(config.serverPath)
|
|
288
|
-
? config.serverPath
|
|
289
|
-
: Path.resolve(process.cwd(), config.serverPath);
|
|
290
|
-
}
|
|
291
|
-
function resolveZipPath(config) {
|
|
292
|
-
if (config === null || config === void 0 ? void 0 : config.zipPath) {
|
|
293
|
-
return Path.isAbsolute(config.zipPath)
|
|
294
|
-
? config.zipPath
|
|
295
|
-
: Path.resolve(process.cwd(), config.zipPath);
|
|
296
|
-
}
|
|
297
|
-
if (config === null || config === void 0 ? void 0 : config.zipName) {
|
|
298
|
-
return Path.resolve(Path.dirname(exports.ZIP_PATH), config.zipName);
|
|
299
|
-
}
|
|
300
|
-
return exports.ZIP_PATH;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* 打包文件为7z格式
|
|
304
|
-
*/
|
|
305
|
-
function makeZip(serverPath, zipPath) {
|
|
306
|
-
return new Promise((resolve, reject) => {
|
|
307
|
-
// 使用 7zip 将服务器构建目录打包为 7z 文件
|
|
308
|
-
Zip.pack(serverPath, zipPath, (error) => {
|
|
309
|
-
if (error) {
|
|
310
|
-
(0, terminal_ui_1.printCommandError)("打包失败", error);
|
|
311
|
-
reject(error);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
(0, terminal_ui_1.printCommandSuccess)("pack", `archive ready: ${zipPath}`);
|
|
315
|
-
resolve(zipPath);
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* 清理原始 dist 目录
|
|
321
|
-
*/
|
|
322
|
-
function cleanUp(config) {
|
|
323
|
-
if ((config === null || config === void 0 ? void 0 : config.cleanDist) === false) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
// 检查原始 dist 目录是否存在,存在则删除
|
|
327
|
-
if (FS.existsSync(exports.ORIGINAL_DIST_PATH)) {
|
|
328
|
-
FS.removeSync(exports.ORIGINAL_DIST_PATH);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* 构建并打包项目的主函数
|
|
333
|
-
* 1. 执行项目构建
|
|
334
|
-
* 2. 复制生成的文件
|
|
335
|
-
* 3. 写入启动脚本
|
|
336
|
-
* 4. 打包文件为 7z 格式
|
|
337
|
-
* 5. 清理原始 dist 目录
|
|
338
|
-
*/
|
|
339
|
-
function buildAndPack(config) {
|
|
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 = [];
|
|
343
|
-
const resolvedConfig = config !== null && config !== void 0 ? config : readPackConfigFromCwd();
|
|
344
|
-
const serverPath = resolveServerPath(resolvedConfig);
|
|
345
|
-
const zipPath = resolveZipPath(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
|
-
}
|
|
354
|
-
if (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.beforePack) {
|
|
355
|
-
yield resolvedConfig.beforePack();
|
|
356
|
-
actions.push("ran beforePack hook");
|
|
357
|
-
}
|
|
358
|
-
copyGeneratedFiles(serverPath, resolvedConfig); // 复制相关文件
|
|
359
|
-
actions.push(`assembled bundle in ${serverPath}`);
|
|
360
|
-
if ((resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.writeScripts) !== false) {
|
|
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");
|
|
375
|
-
}
|
|
376
|
-
(0, terminal_ui_1.printCommandInfo)("pack", `bundle dir: ${serverPath}`);
|
|
377
|
-
if (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.afterPack) {
|
|
378
|
-
yield resolvedConfig.afterPack(zipPath);
|
|
379
|
-
actions.push("ran afterPack hook");
|
|
380
|
-
}
|
|
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);
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
exports.default = buildAndPack;
|
package/commands/postinstall.js
DELETED
|
@@ -1,53 +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.postInstall = postInstall;
|
|
7
|
-
const concurrently_1 = __importDefault(require("concurrently"));
|
|
8
|
-
const node_child_process_1 = require("node:child_process");
|
|
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 = [];
|
|
14
|
-
const hasGo = (0, node_child_process_1.spawnSync)("go", ["version"], { stdio: "ignore", shell: true }).status ===
|
|
15
|
-
0;
|
|
16
|
-
if (!options.skipNuxt) {
|
|
17
|
-
actions.push("prepared Nuxt runtime");
|
|
18
|
-
commands.push({
|
|
19
|
-
command: "npx nuxt prepare",
|
|
20
|
-
name: "nuxt",
|
|
21
|
-
prefixColor: "blue",
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
if (!options.skipGo && hasGo) {
|
|
25
|
-
actions.push("downloaded and tidied Go modules");
|
|
26
|
-
commands.push({
|
|
27
|
-
command: "go mod download && go mod tidy",
|
|
28
|
-
name: "go",
|
|
29
|
-
prefixColor: "green",
|
|
30
|
-
});
|
|
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
|
-
}
|
|
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();
|
|
46
|
-
}
|
|
47
|
-
// 执行并发命令
|
|
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
|
-
});
|
|
52
|
-
}
|
|
53
|
-
exports.default = postInstall;
|
package/commands/update.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type PackageManagerSelection } from "../src/package-manager";
|
|
2
|
-
export type UpdateOptions = {
|
|
3
|
-
latest: boolean;
|
|
4
|
-
packageManager: PackageManagerSelection;
|
|
5
|
-
skipGo?: boolean;
|
|
6
|
-
skipNode?: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare function update(options: UpdateOptions): Promise<void>;
|
|
9
|
-
export default update;
|
package/commands/update.js
DELETED
|
@@ -1,47 +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.update = update;
|
|
7
|
-
const concurrently_1 = __importDefault(require("concurrently"));
|
|
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 = [];
|
|
13
|
-
const commands = [];
|
|
14
|
-
const packageManager = (0, package_manager_1.resolvePackageManager)(options.packageManager);
|
|
15
|
-
if (!options.skipNode) {
|
|
16
|
-
actions.push(`updated Node dependencies with ${packageManager} (${options.latest ? "latest" : "conservative"} mode)`);
|
|
17
|
-
commands.push({
|
|
18
|
-
command: (0, package_manager_1.packageManagerUpdateCommand)(packageManager, options.latest),
|
|
19
|
-
name: packageManager,
|
|
20
|
-
prefixColor: "magenta",
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (!options.skipGo) {
|
|
24
|
-
actions.push(`updated Go modules with ${options.latest ? "latest" : "patch"} strategy`);
|
|
25
|
-
commands.push({
|
|
26
|
-
command: options.latest ? "go get -u ./... && go mod tidy" : "go get -u=patch ./... && go mod tidy",
|
|
27
|
-
name: "go",
|
|
28
|
-
prefixColor: "green",
|
|
29
|
-
});
|
|
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
|
-
}
|
|
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"]);
|
|
40
|
-
return Promise.resolve();
|
|
41
|
-
}
|
|
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
|
-
});
|
|
46
|
-
}
|
|
47
|
-
exports.default = update;
|
package/src/cli-options.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type CLIOptions = {
|
|
2
|
-
flags: Set<string>;
|
|
3
|
-
values: Map<string, string>;
|
|
4
|
-
positionals: string[];
|
|
5
|
-
};
|
|
6
|
-
export declare function parseCLIOptions(args: string[]): CLIOptions;
|
|
7
|
-
export declare function hasFlag(options: CLIOptions, key: string): boolean;
|
|
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
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseCLIOptions = parseCLIOptions;
|
|
4
|
-
exports.hasFlag = hasFlag;
|
|
5
|
-
exports.getOption = getOption;
|
|
6
|
-
exports.getBooleanOption = getBooleanOption;
|
|
7
|
-
function normalizeKey(key) {
|
|
8
|
-
return key.replace(/^-+/, "").trim();
|
|
9
|
-
}
|
|
10
|
-
function parseCLIOptions(args) {
|
|
11
|
-
var _a, _b, _c, _d;
|
|
12
|
-
const flags = new Set();
|
|
13
|
-
const values = new Map();
|
|
14
|
-
const positionals = [];
|
|
15
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
16
|
-
const current = (_b = (_a = args[i]) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
|
|
17
|
-
if (!current)
|
|
18
|
-
continue;
|
|
19
|
-
if (!current.startsWith("-")) {
|
|
20
|
-
positionals.push(current);
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const eqIndex = current.indexOf("=");
|
|
24
|
-
if (eqIndex >= 0) {
|
|
25
|
-
values.set(normalizeKey(current.slice(0, eqIndex)), current.slice(eqIndex + 1));
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
const key = normalizeKey(current);
|
|
29
|
-
const next = (_d = (_c = args[i + 1]) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : "";
|
|
30
|
-
if (next && !next.startsWith("-")) {
|
|
31
|
-
values.set(key, next);
|
|
32
|
-
i += 1;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
flags.add(key);
|
|
36
|
-
}
|
|
37
|
-
return { flags, values, positionals };
|
|
38
|
-
}
|
|
39
|
-
function hasFlag(options, key) {
|
|
40
|
-
return options.flags.has(normalizeKey(key));
|
|
41
|
-
}
|
|
42
|
-
function getOption(options, key) {
|
|
43
|
-
return options.values.get(normalizeKey(key));
|
|
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/go-gin-server.json
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
}
|
package/src/package-manager.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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;
|