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,11 @@
|
|
|
1
|
+
export type CleanupOptions = {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
};
|
|
4
|
+
export declare function ifExistsRemove(relativePath: string, options?: CleanupOptions, actions?: string[]): void;
|
|
5
|
+
export declare function cleanUpNuxt(options?: CleanupOptions, actions?: string[]): Promise<void> | Promise<import("concurrently").CloseEvent[]>;
|
|
6
|
+
export declare function cleanUpBuild(options?: CleanupOptions, actions?: string[]): void;
|
|
7
|
+
/**
|
|
8
|
+
* 清理构建目录和临时文件
|
|
9
|
+
*/
|
|
10
|
+
export declare function cleanUp(options?: CleanupOptions): Promise<void>;
|
|
11
|
+
export default cleanUp;
|
|
@@ -0,0 +1,115 @@
|
|
|
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.ifExistsRemove = ifExistsRemove;
|
|
49
|
+
exports.cleanUpNuxt = cleanUpNuxt;
|
|
50
|
+
exports.cleanUpBuild = cleanUpBuild;
|
|
51
|
+
exports.cleanUp = cleanUp;
|
|
52
|
+
const FS = __importStar(require("fs-extra"));
|
|
53
|
+
const Path = __importStar(require("path"));
|
|
54
|
+
const concurrently_1 = __importDefault(require("concurrently"));
|
|
55
|
+
const nuxt_gin_1 = require("../../nuxt-gin");
|
|
56
|
+
const terminal_ui_1 = require("../terminal-ui");
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
const CLEANUP_PATHS = [
|
|
59
|
+
".build/production",
|
|
60
|
+
"dist",
|
|
61
|
+
".build",
|
|
62
|
+
"tmp",
|
|
63
|
+
"vue/.output",
|
|
64
|
+
".openapi-generator",
|
|
65
|
+
];
|
|
66
|
+
function ifExistsRemove(relativePath, options = {}, actions = []) {
|
|
67
|
+
const absolutePath = Path.resolve(cwd, relativePath);
|
|
68
|
+
if (FS.existsSync(absolutePath)) {
|
|
69
|
+
if (options.dryRun) {
|
|
70
|
+
(0, terminal_ui_1.printCommandInfo)("cleanup", `would remove ${absolutePath}`);
|
|
71
|
+
actions.push(`would remove ${relativePath}`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
FS.removeSync(absolutePath);
|
|
75
|
+
actions.push(`removed ${relativePath}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function cleanUpNuxt(options = {}, actions = []) {
|
|
79
|
+
if (options.dryRun) {
|
|
80
|
+
(0, terminal_ui_1.printCommandInfo)("cleanup", "would run `npx nuxt cleanup`");
|
|
81
|
+
actions.push("would run nuxt cleanup");
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
}
|
|
84
|
+
actions.push("ran nuxt cleanup");
|
|
85
|
+
return (0, concurrently_1.default)([
|
|
86
|
+
{
|
|
87
|
+
command: "npx nuxt cleanup",
|
|
88
|
+
},
|
|
89
|
+
]).result;
|
|
90
|
+
}
|
|
91
|
+
function cleanUpBuild(options = {}, actions = []) {
|
|
92
|
+
for (const path of CLEANUP_PATHS) {
|
|
93
|
+
ifExistsRemove(path, options, actions);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 清理构建目录和临时文件
|
|
98
|
+
*/
|
|
99
|
+
function cleanUp() {
|
|
100
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
101
|
+
(0, terminal_ui_1.printCommandBanner)("cleanup", "Remove generated build output and temporary files");
|
|
102
|
+
const projectConfig = (0, nuxt_gin_1.resolveNuxtGinProjectConfig)();
|
|
103
|
+
for (const warning of projectConfig.warnings) {
|
|
104
|
+
(0, terminal_ui_1.printCommandWarn)(`[config] ${warning}`);
|
|
105
|
+
}
|
|
106
|
+
const resolvedOptions = (0, nuxt_gin_1.mergeDefined)(projectConfig.config.cleanup, options);
|
|
107
|
+
const actions = [];
|
|
108
|
+
const result = cleanUpNuxt(resolvedOptions, actions);
|
|
109
|
+
cleanUpBuild(resolvedOptions, actions);
|
|
110
|
+
yield result;
|
|
111
|
+
(0, terminal_ui_1.printCommandSuccess)("cleanup", resolvedOptions.dryRun ? "Dry run completed" : "Temporary files removed");
|
|
112
|
+
(0, terminal_ui_1.printCommandSummary)("cleanup", actions);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
exports.default = cleanUp;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type DevelopOptions = {
|
|
2
|
+
noCleanup?: boolean;
|
|
3
|
+
skipGo?: boolean;
|
|
4
|
+
skipNuxt?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* 启动本地开发环境。
|
|
8
|
+
*
|
|
9
|
+
* 行为包括:按配置执行预清理、释放开发端口、并行启动 Nuxt 与 Go 监听流程。
|
|
10
|
+
*
|
|
11
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
12
|
+
*/
|
|
13
|
+
export declare function develop(options?: DevelopOptions): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* 仅启动 Nuxt 开发服务(带 nuxt 标签输出)。
|
|
16
|
+
*
|
|
17
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
18
|
+
*/
|
|
19
|
+
export declare function developNuxt(options?: DevelopOptions): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* 仅启动 Go 开发监听流程。
|
|
22
|
+
*
|
|
23
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
24
|
+
*/
|
|
25
|
+
export declare function developGo(options?: DevelopOptions): Promise<void>;
|
|
26
|
+
export default develop;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.develop = develop;
|
|
16
|
+
exports.developNuxt = developNuxt;
|
|
17
|
+
exports.developGo = developGo;
|
|
18
|
+
const concurrently_1 = __importDefault(require("concurrently"));
|
|
19
|
+
const fs_extra_1 = require("fs-extra");
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
const cleanup_1 = __importDefault(require("./cleanup"));
|
|
22
|
+
const install_1 = __importDefault(require("./install"));
|
|
23
|
+
const go_dev_service_1 = require("../../services/go-dev-service");
|
|
24
|
+
const nuxt_gin_1 = require("../../nuxt-gin");
|
|
25
|
+
const ports_1 = require("../../system/ports");
|
|
26
|
+
const terminal_ui_1 = require("../terminal-ui");
|
|
27
|
+
const cwd = process.cwd();
|
|
28
|
+
function resolveDevelopContext(options = {}) {
|
|
29
|
+
var _a, _b, _c, _d;
|
|
30
|
+
const projectConfig = (0, nuxt_gin_1.resolveNuxtGinProjectConfig)();
|
|
31
|
+
for (const warning of projectConfig.warnings) {
|
|
32
|
+
(0, terminal_ui_1.printCommandWarn)(`[config] ${warning}`);
|
|
33
|
+
}
|
|
34
|
+
const serverConfig = (0, nuxt_gin_1.readLegacyServerConfig)();
|
|
35
|
+
if (!serverConfig) {
|
|
36
|
+
throw new Error("server.config.json is required in project root for ginPort, nuxtPort, and baseUrl.");
|
|
37
|
+
}
|
|
38
|
+
const resolvedOptions = (0, nuxt_gin_1.mergeDefined)(projectConfig.config.dev, options);
|
|
39
|
+
const cleanupBeforeDevelop = (_b = (_a = projectConfig.config.dev) === null || _a === void 0 ? void 0 : _a.cleanupBeforeDevelop) !== null && _b !== void 0 ? _b : false;
|
|
40
|
+
const killPortBeforeDevelop = (_d = (_c = projectConfig.config.dev) === null || _c === void 0 ? void 0 : _c.killPortBeforeDevelop) !== null && _d !== void 0 ? _d : true;
|
|
41
|
+
return {
|
|
42
|
+
options: resolvedOptions,
|
|
43
|
+
serverConfig,
|
|
44
|
+
cleanupBeforeDevelop,
|
|
45
|
+
killPortBeforeDevelop,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function prepareDevelop(context) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const shouldPrepare = !context.options.noCleanup;
|
|
51
|
+
if (!shouldPrepare) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (context.cleanupBeforeDevelop) {
|
|
55
|
+
yield (0, cleanup_1.default)();
|
|
56
|
+
yield (0, install_1.default)({
|
|
57
|
+
skipGo: context.options.skipGo,
|
|
58
|
+
skipNuxt: context.options.skipNuxt,
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!(0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "vue/.nuxt")) || !(0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "go.sum"))) {
|
|
63
|
+
yield (0, cleanup_1.default)();
|
|
64
|
+
yield (0, install_1.default)({
|
|
65
|
+
skipGo: context.options.skipGo,
|
|
66
|
+
skipNuxt: context.options.skipNuxt,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function runNuxtDev(serverConfig) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
yield (0, concurrently_1.default)([
|
|
74
|
+
{
|
|
75
|
+
command: `npx nuxt dev --port=${serverConfig.nuxtPort} --host`,
|
|
76
|
+
name: "nuxt",
|
|
77
|
+
prefixColor: "blue",
|
|
78
|
+
},
|
|
79
|
+
]).result;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function runGoDev(serverConfig) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(cwd, ".build/.server"));
|
|
85
|
+
yield (0, go_dev_service_1.startGoDev)(serverConfig.ginPort);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 启动本地开发环境。
|
|
90
|
+
*
|
|
91
|
+
* 行为包括:按配置执行预清理、释放开发端口、并行启动 Nuxt 与 Go 监听流程。
|
|
92
|
+
*
|
|
93
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
94
|
+
*/
|
|
95
|
+
function develop() {
|
|
96
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
97
|
+
(0, terminal_ui_1.printCommandBanner)("dev", "Start Nuxt and Go development workflows");
|
|
98
|
+
const context = resolveDevelopContext(options);
|
|
99
|
+
const actions = [];
|
|
100
|
+
yield prepareDevelop(context);
|
|
101
|
+
// 在开发前确保占用端口被释放
|
|
102
|
+
if (context.killPortBeforeDevelop) {
|
|
103
|
+
(0, ports_1.killPorts)([
|
|
104
|
+
context.options.skipGo ? undefined : context.serverConfig.ginPort,
|
|
105
|
+
context.options.skipNuxt ? undefined : context.serverConfig.nuxtPort,
|
|
106
|
+
]);
|
|
107
|
+
actions.push("released occupied development ports");
|
|
108
|
+
}
|
|
109
|
+
const tasks = [];
|
|
110
|
+
if (!context.options.skipGo) {
|
|
111
|
+
tasks.push(runGoDev(context.serverConfig));
|
|
112
|
+
actions.push(`started Go watcher on port ${context.serverConfig.ginPort}`);
|
|
113
|
+
}
|
|
114
|
+
if (!context.options.skipNuxt) {
|
|
115
|
+
tasks.push(runNuxtDev(context.serverConfig));
|
|
116
|
+
actions.push(`started Nuxt dev server on port ${context.serverConfig.nuxtPort}`);
|
|
117
|
+
}
|
|
118
|
+
if (context.options.skipGo) {
|
|
119
|
+
actions.push("skipped Go workflow");
|
|
120
|
+
}
|
|
121
|
+
if (context.options.skipNuxt) {
|
|
122
|
+
actions.push("skipped Nuxt workflow");
|
|
123
|
+
}
|
|
124
|
+
(0, terminal_ui_1.printCommandSummary)("dev", actions);
|
|
125
|
+
yield Promise.all(tasks);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 仅启动 Nuxt 开发服务(带 nuxt 标签输出)。
|
|
130
|
+
*
|
|
131
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
132
|
+
*/
|
|
133
|
+
function developNuxt() {
|
|
134
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
135
|
+
(0, terminal_ui_1.printCommandBanner)("dev:nuxt", "Start Nuxt development server only");
|
|
136
|
+
const context = resolveDevelopContext(options);
|
|
137
|
+
const actions = [];
|
|
138
|
+
yield prepareDevelop(Object.assign(Object.assign({}, context), { options: Object.assign(Object.assign({}, context.options), { skipGo: true }) }));
|
|
139
|
+
if (context.killPortBeforeDevelop) {
|
|
140
|
+
(0, ports_1.killPorts)([context.serverConfig.nuxtPort]);
|
|
141
|
+
actions.push("released Nuxt dev port");
|
|
142
|
+
}
|
|
143
|
+
actions.push(`started Nuxt dev server on port ${context.serverConfig.nuxtPort}`);
|
|
144
|
+
(0, terminal_ui_1.printCommandSummary)("dev:nuxt", actions);
|
|
145
|
+
yield runNuxtDev(context.serverConfig);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 仅启动 Go 开发监听流程。
|
|
150
|
+
*
|
|
151
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
152
|
+
*/
|
|
153
|
+
function developGo() {
|
|
154
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
155
|
+
(0, terminal_ui_1.printCommandBanner)("dev:go", "Start Go watcher only");
|
|
156
|
+
const context = resolveDevelopContext(options);
|
|
157
|
+
const actions = [];
|
|
158
|
+
yield prepareDevelop(Object.assign(Object.assign({}, context), { options: Object.assign(Object.assign({}, context.options), { skipNuxt: true }) }));
|
|
159
|
+
if (context.killPortBeforeDevelop) {
|
|
160
|
+
(0, ports_1.killPorts)([context.serverConfig.ginPort]);
|
|
161
|
+
actions.push("released Go server port");
|
|
162
|
+
}
|
|
163
|
+
actions.push(`started Go watcher on port ${context.serverConfig.ginPort}`);
|
|
164
|
+
(0, terminal_ui_1.printCommandSummary)("dev:go", actions);
|
|
165
|
+
yield runGoDev(context.serverConfig);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
exports.default = develop;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 nuxt_gin_1 = require("../../nuxt-gin");
|
|
10
|
+
const terminal_ui_1 = require("../terminal-ui");
|
|
11
|
+
function postInstall(options = {}) {
|
|
12
|
+
(0, terminal_ui_1.printCommandBanner)("install", "Prepare Nuxt and optional Go dependencies");
|
|
13
|
+
const projectConfig = (0, nuxt_gin_1.resolveNuxtGinProjectConfig)();
|
|
14
|
+
for (const warning of projectConfig.warnings) {
|
|
15
|
+
(0, terminal_ui_1.printCommandWarn)(`[config] ${warning}`);
|
|
16
|
+
}
|
|
17
|
+
const resolvedOptions = (0, nuxt_gin_1.mergeDefined)(projectConfig.config.install, options);
|
|
18
|
+
const actions = [];
|
|
19
|
+
const commands = [];
|
|
20
|
+
const hasGo = (0, node_child_process_1.spawnSync)("go", ["version"], { stdio: "ignore", shell: true }).status ===
|
|
21
|
+
0;
|
|
22
|
+
if (!resolvedOptions.skipNuxt) {
|
|
23
|
+
actions.push("prepared Nuxt runtime");
|
|
24
|
+
commands.push({
|
|
25
|
+
command: "npx nuxt prepare",
|
|
26
|
+
name: "nuxt",
|
|
27
|
+
prefixColor: "blue",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!resolvedOptions.skipGo && hasGo) {
|
|
31
|
+
actions.push("downloaded and tidied Go modules");
|
|
32
|
+
commands.push({
|
|
33
|
+
command: "go mod download && go mod tidy",
|
|
34
|
+
name: "go",
|
|
35
|
+
prefixColor: "green",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else if (!resolvedOptions.skipGo) {
|
|
39
|
+
(0, terminal_ui_1.printCommandWarn)("Go was not detected, skipping Go dependency bootstrap");
|
|
40
|
+
actions.push("skipped Go bootstrap because Go was not detected");
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
actions.push("skipped Go bootstrap by option");
|
|
44
|
+
}
|
|
45
|
+
if (resolvedOptions.skipNuxt) {
|
|
46
|
+
actions.push("skipped Nuxt prepare by option");
|
|
47
|
+
}
|
|
48
|
+
if (commands.length === 0) {
|
|
49
|
+
(0, terminal_ui_1.printCommandWarn)("Nothing selected for install, skipping bootstrap");
|
|
50
|
+
(0, terminal_ui_1.printCommandSummary)("install", actions.length > 0 ? actions : ["nothing was executed"]);
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
// 执行并发命令
|
|
54
|
+
return (0, concurrently_1.default)(commands).result.then(() => {
|
|
55
|
+
(0, terminal_ui_1.printCommandSuccess)("install", "Project bootstrap completed");
|
|
56
|
+
(0, terminal_ui_1.printCommandSummary)("install", actions);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.default = postInstall;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PackageManagerSelection } from "../../config/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;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.update = update;
|
|
16
|
+
const concurrently_1 = __importDefault(require("concurrently"));
|
|
17
|
+
const promises_1 = require("node:readline/promises");
|
|
18
|
+
const package_manager_1 = require("../../config/package-manager");
|
|
19
|
+
const nuxt_gin_1 = require("../../nuxt-gin");
|
|
20
|
+
const terminal_ui_1 = require("../terminal-ui");
|
|
21
|
+
function resolveLatestPreference(options) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (typeof options.latest === "boolean") {
|
|
24
|
+
return options.latest;
|
|
25
|
+
}
|
|
26
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
27
|
+
(0, terminal_ui_1.printCommandWarn)("Non-interactive terminal detected, defaulting update mode to conservative");
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const rl = (0, promises_1.createInterface)({
|
|
31
|
+
input: process.stdin,
|
|
32
|
+
output: process.stdout,
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
const answer = yield rl.question("Use latest dependency upgrade strategy? [y/N] ");
|
|
36
|
+
const normalized = answer.trim().toLowerCase();
|
|
37
|
+
return ["y", "yes"].includes(normalized);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
rl.close();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function update() {
|
|
45
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
(0, terminal_ui_1.printCommandBanner)("update", "Update Node and Go dependencies");
|
|
48
|
+
const projectConfig = (0, nuxt_gin_1.resolveNuxtGinProjectConfig)();
|
|
49
|
+
for (const warning of projectConfig.warnings) {
|
|
50
|
+
(0, terminal_ui_1.printCommandWarn)(`[config] ${warning}`);
|
|
51
|
+
}
|
|
52
|
+
const resolvedOptions = (0, nuxt_gin_1.mergeDefined)(Object.assign({ packageManager: "auto" }, ((_a = projectConfig.config.update) !== null && _a !== void 0 ? _a : {})), options);
|
|
53
|
+
const latest = yield resolveLatestPreference(resolvedOptions);
|
|
54
|
+
const actions = [];
|
|
55
|
+
const commands = [];
|
|
56
|
+
const packageManager = (0, package_manager_1.resolvePackageManager)((_b = resolvedOptions.packageManager) !== null && _b !== void 0 ? _b : "auto");
|
|
57
|
+
if (!resolvedOptions.skipNode) {
|
|
58
|
+
actions.push(`updated Node dependencies with ${packageManager} (${latest ? "latest" : "conservative"} mode)`);
|
|
59
|
+
commands.push({
|
|
60
|
+
command: (0, package_manager_1.packageManagerUpdateCommand)(packageManager, latest),
|
|
61
|
+
name: packageManager,
|
|
62
|
+
prefixColor: "magenta",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (!resolvedOptions.skipGo) {
|
|
66
|
+
actions.push(`updated Go modules with ${latest ? "latest" : "patch"} strategy`);
|
|
67
|
+
commands.push({
|
|
68
|
+
command: latest ? "go get -u ./... && go mod tidy" : "go get -u=patch ./... && go mod tidy",
|
|
69
|
+
name: "go",
|
|
70
|
+
prefixColor: "green",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (resolvedOptions.skipNode) {
|
|
74
|
+
actions.push("skipped Node dependency update");
|
|
75
|
+
}
|
|
76
|
+
if (resolvedOptions.skipGo) {
|
|
77
|
+
actions.push("skipped Go dependency update");
|
|
78
|
+
}
|
|
79
|
+
if (commands.length === 0) {
|
|
80
|
+
(0, terminal_ui_1.printCommandWarn)("No update targets selected, nothing to do");
|
|
81
|
+
(0, terminal_ui_1.printCommandSummary)("update", actions.length > 0 ? actions : ["nothing was executed"]);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
yield (0, concurrently_1.default)(commands).result;
|
|
85
|
+
(0, terminal_ui_1.printCommandSuccess)("update", "Dependency update completed");
|
|
86
|
+
(0, terminal_ui_1.printCommandSummary)("update", actions);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.default = update;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
10
|
+
export declare function getOptionalBooleanOption(options: CLIOptions, key: string): boolean | undefined;
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
exports.getOptionalBooleanOption = getOptionalBooleanOption;
|
|
8
|
+
function normalizeKey(key) {
|
|
9
|
+
return key.replace(/^-+/, "").trim();
|
|
10
|
+
}
|
|
11
|
+
function parseCLIOptions(args) {
|
|
12
|
+
var _a, _b, _c, _d;
|
|
13
|
+
const flags = new Set();
|
|
14
|
+
const values = new Map();
|
|
15
|
+
const positionals = [];
|
|
16
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
17
|
+
const current = (_b = (_a = args[i]) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
|
|
18
|
+
if (!current)
|
|
19
|
+
continue;
|
|
20
|
+
if (!current.startsWith("-")) {
|
|
21
|
+
positionals.push(current);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const eqIndex = current.indexOf("=");
|
|
25
|
+
if (eqIndex >= 0) {
|
|
26
|
+
values.set(normalizeKey(current.slice(0, eqIndex)), current.slice(eqIndex + 1));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const key = normalizeKey(current);
|
|
30
|
+
const next = (_d = (_c = args[i + 1]) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : "";
|
|
31
|
+
if (next && !next.startsWith("-")) {
|
|
32
|
+
values.set(key, next);
|
|
33
|
+
i += 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
flags.add(key);
|
|
37
|
+
}
|
|
38
|
+
return { flags, values, positionals };
|
|
39
|
+
}
|
|
40
|
+
function hasFlag(options, key) {
|
|
41
|
+
return options.flags.has(normalizeKey(key));
|
|
42
|
+
}
|
|
43
|
+
function getOption(options, key) {
|
|
44
|
+
return options.values.get(normalizeKey(key));
|
|
45
|
+
}
|
|
46
|
+
function getBooleanOption(options, key, defaultValue) {
|
|
47
|
+
const value = getOptionalBooleanOption(options, key);
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
return defaultValue;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function getOptionalBooleanOption(options, key) {
|
|
54
|
+
const value = getOption(options, key);
|
|
55
|
+
if (value === undefined) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const normalized = value.trim().toLowerCase();
|
|
59
|
+
if (["true", "1", "yes", "y", "on"].includes(normalized)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (["false", "0", "no", "n", "off"].includes(normalized)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Invalid boolean value for --${key}: ${value}`);
|
|
66
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|