@infly/libs 2.0.43 → 2.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +104 -67
  2. package/{module → adapters/vue2/module}/Permission.js +2 -2
  3. package/{module → adapters/vue2/module}/REST.js +32 -20
  4. package/{module → adapters/vue2/module}/TokenService.js +10 -1
  5. package/adapters/vue2/module/file-export.js +18 -0
  6. package/adapters/vue2/postinstall.js +46 -0
  7. package/adapters/vue2/project-preview.js +152 -0
  8. package/adapters/vue2/script-config.js +26 -0
  9. package/adapters/vue2/store/index.js +1 -0
  10. package/{store → adapters/vue2/store}/modules/user.js +1 -1
  11. package/adapters/vue2/vite/index.js +95 -0
  12. package/adapters/vue2/vite/jest.config.js +11 -0
  13. package/{build → adapters/vue2}/webpack5/webpack.base.js +26 -79
  14. package/bin/cli.js +71 -71
  15. package/build/build-dist/index.js +863 -863
  16. package/build/build-dist/script-management.js +5 -5
  17. package/{script/build → build/build-utils}/command.js +13 -4
  18. package/{script/build → build/build-utils}/deps.js +1 -1
  19. package/{script/build → build/build-utils}/git.js +6 -4
  20. package/{script/build → build/build-utils}/preview.js +4 -1
  21. package/{script/webhook/webhook.js → build/build-utils/webhook-single.js} +7 -2
  22. package/{script/build → build/build-utils}/webhook.js +3 -2
  23. package/build/docker/compose-command.js +74 -74
  24. package/build/docker/compose-release.js +91 -91
  25. package/compat/init.js +9 -0
  26. package/index.js +8 -20
  27. package/module/Uts.js +77 -7265
  28. package/module/cjs/{request-url-rules.cjs → request-url-rules.js} +6 -0
  29. package/module/cjs/rest-error-rules.js +33 -0
  30. package/package.json +124 -92
  31. package/script/git-automation/git-clone.js +3 -4
  32. package/script/git-automation/git-configure.js +29 -0
  33. package/script/git-automation/index.js +0 -14
  34. package/script/git-automation/submodule-status.js +113 -0
  35. package/script/git-automation/submodule-utils.js +18 -0
  36. package/script/index.js +1 -26
  37. package/tools/auto-export.js +1 -2
  38. package/tools/concurrency.js +30 -0
  39. package/tools/progress.js +63 -0
  40. package/tools/project-command.js +198 -194
  41. package/tools/project-preview.js +1 -148
  42. package/tools/select-option.js +60 -60
  43. package/tools/workspace-config.js +145 -0
  44. package/.prettierrc +0 -5
  45. package/build/build-dist/script-management.test.js +0 -16
  46. package/build/docker/compose-command.test.js +0 -148
  47. package/build/docker/compose-release.test.js +0 -101
  48. package/build/docker/docker-build-push.test.js +0 -124
  49. package/build/webpack5/remove-legacy-assets-plugin.js +0 -84
  50. package/build/webpack5/webpack.base.test.js +0 -59
  51. package/lib/index.js +0 -6
  52. package/lib/server/connect.js +0 -3011
  53. package/lib/server/serve-static.js +0 -4848
  54. package/module/cjs/deep-merge.cjs +0 -38
  55. package/script/pts/cloud-scenes.mjs +0 -65
  56. package/script/pts/cloud.js +0 -151
  57. package/script/pts/generate-cloud-params.mjs +0 -210
  58. package/script/pts/generate-cloud-params.test.mjs +0 -67
  59. package/store/index.js +0 -0
  60. package/tools/file-export.js +0 -165
  61. package/tools/project-command.test.js +0 -267
  62. package/tools/select-option.test.js +0 -52
  63. package/webpack.config.js +0 -38
  64. /package/{module → adapters/vue2/module}/Router.js +0 -0
  65. /package/{build → adapters/vue2}/webpack5/inline-runtime-plugin.js +0 -0
  66. /package/{script/build → build/build-utils}/env.js +0 -0
  67. /package/module/cjs/{page-config.cjs → page-config.js} +0 -0
@@ -1,194 +1,198 @@
1
- const { execFileSync } = require("node:child_process");
2
- const fs = require("node:fs");
3
- const path = require("node:path");
4
-
5
- const {
6
- EXIT_SELECTION,
7
- selectOption: defaultSelectOption,
8
- } = require("./select-option");
9
-
10
- function loadConfig(cwd = process.cwd()) {
11
- const packagePath = path.resolve(cwd, "package.json");
12
- if (!fs.existsSync(packagePath)) {
13
- throw new Error(`Project package not found: ${packagePath}.`);
14
- }
15
- delete require.cache[require.resolve(packagePath)];
16
- const inflyConfig = require(packagePath).infly;
17
- if (!inflyConfig?.dev && !inflyConfig?.build) {
18
- throw new Error(`Project config is missing in ${packagePath}. Add infly.dev or infly.build.`);
19
- }
20
- return {
21
- config: {
22
- targets: inflyConfig.targets,
23
- dev: inflyConfig.dev,
24
- build: inflyConfig.build,
25
- },
26
- configDir: path.dirname(packagePath),
27
- };
28
- }
29
-
30
- function normalizeTargets(targets) {
31
- if (Array.isArray(targets)) {
32
- return Object.fromEntries(targets.map((target) => [target, {}]));
33
- }
34
- if (targets && typeof targets === "object") return targets;
35
- throw new Error("Project targets must be a non-empty array or object.");
36
- }
37
-
38
- function normalizeEnvironments(environments) {
39
- if (Array.isArray(environments)) {
40
- return Object.fromEntries(environments.map((entry) => {
41
- const separatorIndex = entry.indexOf(":");
42
- const environment = separatorIndex < 0 ? entry : entry.slice(0, separatorIndex);
43
- const mode = separatorIndex < 0 ? entry : entry.slice(separatorIndex + 1);
44
- if (!environment || !mode) {
45
- throw new Error(`Invalid build environment mapping: ${entry}`);
46
- }
47
- return [environment, { mode, args: ["--mode", mode] }];
48
- }));
49
- }
50
- if (environments && typeof environments === "object") return environments;
51
- throw new Error("Build environments must be an array or object.");
52
- }
53
-
54
- function resolveBuildPlatforms(targets, buildConfig, targetName) {
55
- const normalizedTargets = normalizeTargets(targets);
56
- if (normalizedTargets[targetName]) return [targetName];
57
-
58
- const preset = buildConfig.presets?.[targetName];
59
- if (!preset) throw new Error(`Unknown build target: ${targetName}`);
60
-
61
- return preset.targets.map((name) => {
62
- if (!normalizedTargets[name]) {
63
- throw new Error(`Unknown build target in preset ${targetName}: ${name}`);
64
- }
65
- return name;
66
- });
67
- }
68
-
69
- function commandParts(command) {
70
- const parts = typeof command === "string"
71
- ? command.trim().split(/\s+/)
72
- : command;
73
- if (!Array.isArray(parts) || parts.length === 0 || !parts[0]) {
74
- throw new Error("Command configuration must be a non-empty string or array.");
75
- }
76
- return { command: parts[0], args: parts.slice(1) };
77
- }
78
-
79
- function defaultRunCommand(command, args, options) {
80
- execFileSync(command, args, {
81
- cwd: options.cwd,
82
- env: options.env,
83
- stdio: "inherit",
84
- });
85
- }
86
-
87
- function printDryRun(command, args, env) {
88
- const platform = env.VUE_APP_PLATFORM ? `VUE_APP_PLATFORM=${env.VUE_APP_PLATFORM} ` : "";
89
- console.log(`[dry-run] ${platform}${command} ${args.join(" ")}`.trim());
90
- }
91
-
92
- async function choose(selectOption, message, entries) {
93
- return selectOption(
94
- message,
95
- entries.map(([value, item]) => ({ value, label: item.label || value })),
96
- );
97
- }
98
-
99
- async function runProjectCommand(options = {}, dependencies = {}) {
100
- if (typeof options.config === "string") {
101
- throw new Error("--config is not supported for project commands; use package.json infly config.");
102
- }
103
-
104
- const configObject = options.configObject
105
- || (options.config && typeof options.config === "object" ? options.config : undefined);
106
- const loaded = configObject
107
- ? { config: configObject, configDir: options.configDir }
108
- : loadConfig(options.cwd || process.cwd());
109
- const config = loaded.config;
110
- const configDir = options.configDir || loaded.configDir || process.cwd();
111
- if (!config) throw new Error("Project command config is required.");
112
- const targets = normalizeTargets(config.targets);
113
-
114
- const selectOption = dependencies.selectOption || defaultSelectOption;
115
- const runCommand = dependencies.runCommand || defaultRunCommand;
116
- const log = dependencies.log || console.log;
117
- const exitIfSelected = (selection) => {
118
- if (selection !== EXIT_SELECTION) return false;
119
- log("已退出,未执行任何操作。");
120
- return true;
121
- };
122
- const action = options.action || await selectOption("请选择操作", [
123
- { value: "dev", label: "启动开发环境" },
124
- { value: "build", label: "构建项目" },
125
- ]);
126
- if (exitIfSelected(action)) return { cancelled: true };
127
-
128
- if (action === "dev") {
129
- const devConfig = config.dev;
130
- if (!devConfig) throw new Error("Dev configuration is missing.");
131
- const targetName = options.target || await choose(
132
- selectOption,
133
- "请选择目标平台",
134
- Object.entries(targets),
135
- );
136
- if (exitIfSelected(targetName)) return { cancelled: true };
137
- const target = targets[targetName];
138
- if (!target) throw new Error(`Unknown dev target: ${targetName}`);
139
- const parts = commandParts(devConfig.command);
140
- const env = { ...process.env, VUE_APP_PLATFORM: targetName };
141
- if (options.dryRun) printDryRun(parts.command, parts.args, env);
142
- else runCommand(parts.command, parts.args, { cwd: configDir, env });
143
- return { action, target: targetName };
144
- }
145
-
146
- if (action !== "build") throw new Error(`Unknown project action: ${action}`);
147
- const buildConfig = config.build;
148
- if (!buildConfig) throw new Error("Build configuration is missing.");
149
- const environments = normalizeEnvironments(buildConfig.environments);
150
- const environment = options.env || await choose(
151
- selectOption,
152
- "请选择构建环境",
153
- Object.entries(environments),
154
- );
155
- if (exitIfSelected(environment)) return { cancelled: true };
156
- const environmentConfig = environments[environment];
157
- if (!environmentConfig) throw new Error(`Unknown build environment: ${environment}`);
158
- const targetEntries = [
159
- ...Object.entries(targets),
160
- ...Object.entries(buildConfig.presets || {}),
161
- ];
162
- const targetName = options.target || await choose(
163
- selectOption,
164
- "请选择目标平台",
165
- targetEntries,
166
- );
167
- if (exitIfSelected(targetName)) return { cancelled: true };
168
- const platforms = resolveBuildPlatforms(targets, buildConfig, targetName);
169
-
170
- for (const platform of platforms) {
171
- const env = { ...process.env, VUE_APP_PLATFORM: platform };
172
- const lifecycleArgs = environmentConfig.mode ? ["--mode", environmentConfig.mode] : [];
173
- const steps = [
174
- { command: buildConfig.before, extraArgs: lifecycleArgs },
175
- { command: buildConfig.command, extraArgs: environmentConfig.args || [] },
176
- { command: buildConfig.after, extraArgs: lifecycleArgs },
177
- ];
178
-
179
- for (const step of steps) {
180
- const parts = commandParts(step.command);
181
- const args = [...parts.args, ...step.extraArgs];
182
- if (options.dryRun) printDryRun(parts.command, args, env);
183
- else runCommand(parts.command, args, { cwd: configDir, env });
184
- }
185
- }
186
-
187
- return { action, environment, target: targetName, platforms };
188
- }
189
-
190
- module.exports = {
191
- loadConfig,
192
- resolveBuildPlatforms,
193
- runProjectCommand,
194
- };
1
+ const { execFileSync } = require("node:child_process");
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+
5
+ const {
6
+ EXIT_SELECTION,
7
+ selectOption: defaultSelectOption,
8
+ } = require("./select-option");
9
+
10
+ function loadConfig(cwd = process.cwd()) {
11
+ const packagePath = path.resolve(cwd, "package.json");
12
+ if (!fs.existsSync(packagePath)) {
13
+ throw new Error(`Project package not found: ${packagePath}.`);
14
+ }
15
+ delete require.cache[require.resolve(packagePath)];
16
+ const inflyConfig = require(packagePath).infly;
17
+ if (!inflyConfig?.dev && !inflyConfig?.build) {
18
+ throw new Error(`Project config is missing in ${packagePath}. Add infly.dev or infly.build.`);
19
+ }
20
+ return {
21
+ config: {
22
+ targets: inflyConfig.targets,
23
+ dev: inflyConfig.dev,
24
+ build: inflyConfig.build,
25
+ },
26
+ configDir: path.dirname(packagePath),
27
+ };
28
+ }
29
+
30
+ function normalizeTargets(targets) {
31
+ if (Array.isArray(targets)) {
32
+ return Object.fromEntries(targets.map((target) => [target, {}]));
33
+ }
34
+ if (targets && typeof targets === "object") return targets;
35
+ throw new Error("Project targets must be a non-empty array or object.");
36
+ }
37
+
38
+ function normalizeEnvironments(environments) {
39
+ if (Array.isArray(environments)) {
40
+ return Object.fromEntries(environments.map((entry) => {
41
+ const separatorIndex = entry.indexOf(":");
42
+ const environment = separatorIndex < 0 ? entry : entry.slice(0, separatorIndex);
43
+ const mode = separatorIndex < 0 ? entry : entry.slice(separatorIndex + 1);
44
+ if (!environment || !mode) {
45
+ throw new Error(`Invalid build environment mapping: ${entry}`);
46
+ }
47
+ return [environment, { mode, args: ["--mode", mode] }];
48
+ }));
49
+ }
50
+ if (environments && typeof environments === "object") return environments;
51
+ throw new Error("Build environments must be an array or object.");
52
+ }
53
+
54
+ function resolveBuildPlatforms(targets, buildConfig, targetName) {
55
+ const normalizedTargets = normalizeTargets(targets);
56
+ if (normalizedTargets[targetName]) return [targetName];
57
+
58
+ const preset = buildConfig.presets?.[targetName];
59
+ if (!preset) throw new Error(`Unknown build target: ${targetName}`);
60
+
61
+ return preset.targets.map((name) => {
62
+ if (!normalizedTargets[name]) {
63
+ throw new Error(`Unknown build target in preset ${targetName}: ${name}`);
64
+ }
65
+ return name;
66
+ });
67
+ }
68
+
69
+ function commandParts(command) {
70
+ const parts = typeof command === "string"
71
+ ? command.trim().split(/\s+/)
72
+ : command;
73
+ if (!Array.isArray(parts) || parts.length === 0 || !parts[0]) {
74
+ throw new Error("Command configuration must be a non-empty string or array.");
75
+ }
76
+ return { command: parts[0], args: parts.slice(1) };
77
+ }
78
+
79
+ function defaultRunCommand(command, args, options) {
80
+ execFileSync(command, args, {
81
+ cwd: options.cwd,
82
+ env: options.env,
83
+ stdio: "inherit",
84
+ });
85
+ }
86
+
87
+ function printDryRun(command, args, env) {
88
+ const platform = env.VUE_APP_PLATFORM ? `VUE_APP_PLATFORM=${env.VUE_APP_PLATFORM} ` : "";
89
+ console.log(`[dry-run] ${platform}${command} ${args.join(" ")}`.trim());
90
+ }
91
+
92
+ async function choose(selectOption, message, entries) {
93
+ return selectOption(
94
+ message,
95
+ entries.map(([value, item]) => ({ value, label: item.label || value })),
96
+ );
97
+ }
98
+
99
+ async function runProjectCommand(options = {}, dependencies = {}) {
100
+ if (typeof options.config === "string") {
101
+ throw new Error("--config is not supported for project commands; use package.json infly config.");
102
+ }
103
+
104
+ const configObject = options.configObject
105
+ || (options.config && typeof options.config === "object" ? options.config : undefined);
106
+ const loaded = configObject
107
+ ? { config: configObject, configDir: options.configDir }
108
+ : loadConfig(options.cwd || process.cwd());
109
+ const config = loaded.config;
110
+ const configDir = options.configDir || loaded.configDir || process.cwd();
111
+ if (!config) throw new Error("Project command config is required.");
112
+ const targets = normalizeTargets(config.targets);
113
+
114
+ const selectOption = dependencies.selectOption || defaultSelectOption;
115
+ const runCommand = dependencies.runCommand || defaultRunCommand;
116
+ const log = dependencies.log || console.log;
117
+ const exitIfSelected = (selection) => {
118
+ if (selection !== EXIT_SELECTION) return false;
119
+ log("已退出,未执行任何操作。");
120
+ return true;
121
+ };
122
+ const action = options.action || await selectOption("请选择操作", [
123
+ { value: "dev", label: "启动开发环境" },
124
+ { value: "build", label: "构建项目" },
125
+ ]);
126
+ if (exitIfSelected(action)) return { cancelled: true };
127
+
128
+ if (action === "dev") {
129
+ const devConfig = config.dev;
130
+ if (!devConfig) throw new Error("Dev configuration is missing.");
131
+ const targetName = options.target || await choose(
132
+ selectOption,
133
+ "请选择目标平台",
134
+ Object.entries(targets),
135
+ );
136
+ if (exitIfSelected(targetName)) return { cancelled: true };
137
+ const target = targets[targetName];
138
+ if (!target) throw new Error(`Unknown dev target: ${targetName}`);
139
+ const parts = commandParts(devConfig.command);
140
+ const env = { ...process.env, VUE_APP_PLATFORM: targetName };
141
+ if (options.dryRun) printDryRun(parts.command, parts.args, env);
142
+ else runCommand(parts.command, parts.args, { cwd: configDir, env });
143
+ return { action, target: targetName };
144
+ }
145
+
146
+ if (action !== "build") throw new Error(`Unknown project action: ${action}`);
147
+ const buildConfig = config.build;
148
+ if (!buildConfig) throw new Error("Build configuration is missing.");
149
+ const environments = normalizeEnvironments(buildConfig.environments);
150
+ const environment = options.env || await choose(
151
+ selectOption,
152
+ "请选择构建环境",
153
+ Object.entries(environments),
154
+ );
155
+ if (exitIfSelected(environment)) return { cancelled: true };
156
+ const environmentConfig = environments[environment];
157
+ if (!environmentConfig) throw new Error(`Unknown build environment: ${environment}`);
158
+ const targetEntries = [
159
+ ...Object.entries(targets),
160
+ ...Object.entries(buildConfig.presets || {}),
161
+ ];
162
+ const targetName = options.target || await choose(
163
+ selectOption,
164
+ "请选择目标平台",
165
+ targetEntries,
166
+ );
167
+ if (exitIfSelected(targetName)) return { cancelled: true };
168
+ const platforms = resolveBuildPlatforms(targets, buildConfig, targetName);
169
+
170
+ for (const platform of platforms) {
171
+ const env = { ...process.env, VUE_APP_PLATFORM: platform };
172
+ const lifecycleArgs = environmentConfig.mode ? ["--mode", environmentConfig.mode] : [];
173
+ // staging 构建禁用 Vue CLI 5 默认的 modern mode 双构建(测试环境无需 legacy 兼容)
174
+ const buildArgs = environment === "stage"
175
+ ? [...(environmentConfig.args || []), "--no-module"]
176
+ : (environmentConfig.args || []);
177
+ const steps = [
178
+ { command: buildConfig.before, extraArgs: lifecycleArgs },
179
+ { command: buildConfig.command, extraArgs: buildArgs },
180
+ { command: buildConfig.after, extraArgs: lifecycleArgs },
181
+ ];
182
+
183
+ for (const step of steps) {
184
+ const parts = commandParts(step.command);
185
+ const args = [...parts.args, ...step.extraArgs];
186
+ if (options.dryRun) printDryRun(parts.command, args, env);
187
+ else runCommand(parts.command, args, { cwd: configDir, env });
188
+ }
189
+ }
190
+
191
+ return { action, environment, target: targetName, platforms };
192
+ }
193
+
194
+ module.exports = {
195
+ loadConfig,
196
+ resolveBuildPlatforms,
197
+ runProjectCommand,
198
+ };
@@ -1,148 +1 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const net = require("net");
4
- const { execSync } = require("child_process");
5
-
6
- const { scriptWrite } = require("./file-process.js");
7
- const { previewList } = require("../script");
8
-
9
- const projectRoot = process.cwd().replace(/\\node_modules.*$/g, "");
10
- const projectPkgPath = path.resolve(projectRoot, "package.json");
11
- const projectVueConfigPath = path.resolve(projectRoot, "vue.config.js");
12
- const projectConfig = fs.existsSync(projectVueConfigPath) ? require(projectVueConfigPath) : {};
13
- const projectPackage = fs.existsSync(projectPkgPath) ? require(projectPkgPath) : {};
14
- const rawArgv = process.argv.slice(2);
15
- const args = rawArgv.join(" ");
16
-
17
- function getBuildContext() {
18
- try {
19
- return JSON.parse(process.env.INFLY_BUILD_CONTEXT || "{}");
20
- } catch {
21
- return {};
22
- }
23
- }
24
-
25
- const buildContext = getBuildContext();
26
-
27
- global.logColor = global.logColor || {
28
- success: "\n\x1b[32m%s\x1b[0m",
29
- error: "\n\x1b[31m%s\x1b[0m",
30
- warning: "\n\x1b[33m%s\x1b[0m",
31
- link: "\x1b[34m%s\x1b[0m",
32
- info: "\n\x1b[36m%s\x1b[0m"
33
- };
34
-
35
- const DEFAULT_CONFIG = {
36
- port: 9001,
37
- publicPath: "/",
38
- outputDir: "dist"
39
- };
40
-
41
- function scriptInit() {
42
- if (fs.existsSync(projectVueConfigPath)) {
43
- return;
44
- }
45
- scriptWrite(projectPkgPath, previewList);
46
- }
47
-
48
- function isPortAvailable(port) {
49
- return new Promise((resolve) => {
50
- const server = net.createServer();
51
-
52
- server.listen(port, () => {
53
- server.once("close", () => {
54
- resolve(true);
55
- });
56
- server.close();
57
- });
58
-
59
- server.on("error", () => {
60
- resolve(false);
61
- });
62
- });
63
- }
64
-
65
- async function findAvailablePort(startPort, maxTries = 10) {
66
- for (let i = 0; i < maxTries; i++) {
67
- const port = startPort + i;
68
- const available = await isPortAvailable(port);
69
-
70
- if (available) {
71
- if (i > 0) {
72
- console.log(global.logColor.warning, `⚠️ 端口 ${startPort} 被占用,使用端口 ${port}`);
73
- }
74
- return port;
75
- }
76
- }
77
-
78
- throw new Error(`无法找到可用端口,已尝试从 ${startPort} 到 ${startPort + maxTries - 1}`);
79
- }
80
-
81
- async function init(skipBuild = false) {
82
- try {
83
- const { connect } = require("../lib/server/connect");
84
- const { serveStatic } = require("../lib/server/serve-static");
85
- const app = connect();
86
- const noBuild = skipBuild || rawArgv.includes("--no-build");
87
- const { devServer } = projectConfig || {};
88
- const { port: devServerPort } = devServer || {};
89
- projectConfig.port = devServerPort || DEFAULT_CONFIG.port;
90
- const { publicPath, outputDir, port } = {
91
- ...DEFAULT_CONFIG,
92
- ...projectConfig
93
- };
94
- const baseListenPort = port - 1000;
95
-
96
- if (!noBuild) {
97
- buildProject();
98
- }
99
-
100
- const listenPort = await findAvailablePort(baseListenPort);
101
-
102
- app.use(
103
- publicPath,
104
- serveStatic(outputDir, {
105
- index: ["index.html", "/"]
106
- })
107
- );
108
-
109
- const server = app.listen(listenPort, function () {
110
- const previewUrl = `http://localhost:${listenPort}${publicPath}`;
111
-
112
- if (buildContext.batchPreview === true || process.env.INFLY_BATCH_PREVIEW === "1") {
113
- console.log(global.logColor.link, `${projectPackage.name || path.basename(projectRoot)}: ${previewUrl}`);
114
- return;
115
- }
116
-
117
- console.log(global.logColor.success, `\x1b[42m\x1b[30m DONE \x1b[0m\x1b[32m 项目构建预览,CTRL + C结束:`);
118
- console.log(global.logColor.link, previewUrl);
119
- });
120
-
121
- server.on("error", (error) => {
122
- if (error.code === "EADDRINUSE") {
123
- console.log(global.logColor.error, `❌ 端口 ${listenPort} 仍然被占用`);
124
- } else {
125
- console.log(global.logColor.error, `❌ 服务器启动失败:${error.message}`);
126
- }
127
- });
128
-
129
- return server;
130
- } catch (error) {
131
- console.log(global.logColor.error, `❌ 预览项目失败:${error.message}`);
132
- throw error;
133
- }
134
- }
135
-
136
- function buildProject() {
137
- try {
138
- execSync(`vue-cli-service build ${args}`, { stdio: "inherit" });
139
- } catch (err) {
140
- console.error(global.logColor.error, "❌ 构建失败:", err.message);
141
- process.exit(1);
142
- }
143
- }
144
-
145
- module.exports = {
146
- init,
147
- scriptInit
148
- };
1
+ module.exports = require("../adapters/vue2/project-preview.js");
@@ -1,60 +1,60 @@
1
- const EXIT_SELECTION = "__exit__";
2
-
3
- function isReadlineClosedError(error) {
4
- return error?.code === "ERR_USE_AFTER_CLOSE";
5
- }
6
-
7
- function makePromptCancellationSafe(prompt) {
8
- const unsafeStop = prompt.stop;
9
- if (typeof unsafeStop !== "function") return;
10
-
11
- prompt.removeListener("close", unsafeStop);
12
- const safeStop = () => {
13
- try {
14
- unsafeStop();
15
- } catch (error) {
16
- if (!isReadlineClosedError(error)) throw error;
17
- }
18
- };
19
- prompt.stop = safeStop;
20
- prompt.once("close", safeStop);
21
- }
22
-
23
- async function selectOption(message, choices, dependencies = {}) {
24
- const stdin = dependencies.stdin || process.stdin;
25
- const stdout = dependencies.stdout || process.stdout;
26
- if (!stdin.isTTY || !stdout.isTTY) {
27
- throw new Error(`${message}: interactive selection requires a TTY; pass an explicit option.`);
28
- }
29
-
30
- const Select = dependencies.Select || require("enquirer").Select;
31
- const prompt = new Select({
32
- name: "selection",
33
- message,
34
- stdin,
35
- stdout,
36
- choices: [
37
- ...choices.map((choice) => ({
38
- name: choice.value,
39
- message: choice.label,
40
- })),
41
- { name: EXIT_SELECTION, message: "退出" },
42
- ],
43
- });
44
-
45
- prompt.once("start", makePromptCancellationSafe);
46
- try {
47
- return await prompt.run();
48
- } catch (error) {
49
- if (!error || error.name === "CancelPromptError" || isReadlineClosedError(error)) {
50
- return EXIT_SELECTION;
51
- }
52
- throw error;
53
- }
54
- }
55
-
56
- module.exports = {
57
- EXIT_SELECTION,
58
- makePromptCancellationSafe,
59
- selectOption,
60
- };
1
+ const EXIT_SELECTION = "__exit__";
2
+
3
+ function isReadlineClosedError(error) {
4
+ return error?.code === "ERR_USE_AFTER_CLOSE";
5
+ }
6
+
7
+ function makePromptCancellationSafe(prompt) {
8
+ const unsafeStop = prompt.stop;
9
+ if (typeof unsafeStop !== "function") return;
10
+
11
+ prompt.removeListener("close", unsafeStop);
12
+ const safeStop = () => {
13
+ try {
14
+ unsafeStop();
15
+ } catch (error) {
16
+ if (!isReadlineClosedError(error)) throw error;
17
+ }
18
+ };
19
+ prompt.stop = safeStop;
20
+ prompt.once("close", safeStop);
21
+ }
22
+
23
+ async function selectOption(message, choices, dependencies = {}) {
24
+ const stdin = dependencies.stdin || process.stdin;
25
+ const stdout = dependencies.stdout || process.stdout;
26
+ if (!stdin.isTTY || !stdout.isTTY) {
27
+ throw new Error(`${message}: interactive selection requires a TTY; pass an explicit option.`);
28
+ }
29
+
30
+ const Select = dependencies.Select || require("enquirer").Select;
31
+ const prompt = new Select({
32
+ name: "selection",
33
+ message,
34
+ stdin,
35
+ stdout,
36
+ choices: [
37
+ ...choices.map((choice) => ({
38
+ name: choice.value,
39
+ message: choice.label,
40
+ })),
41
+ { name: EXIT_SELECTION, message: "退出" },
42
+ ],
43
+ });
44
+
45
+ prompt.once("start", makePromptCancellationSafe);
46
+ try {
47
+ return await prompt.run();
48
+ } catch (error) {
49
+ if (!error || error.name === "CancelPromptError" || isReadlineClosedError(error)) {
50
+ return EXIT_SELECTION;
51
+ }
52
+ throw error;
53
+ }
54
+ }
55
+
56
+ module.exports = {
57
+ EXIT_SELECTION,
58
+ makePromptCancellationSafe,
59
+ selectOption,
60
+ };