@htyf-mp/cli 0.2.0-alpha.10 → 0.2.0-alpha.11
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/package.json +1 -1
- package/src/build.mjs +1 -5
- package/src/debug.mjs +17 -15
- package/src/export_godot.mjs +42 -15
package/package.json
CHANGED
package/src/build.mjs
CHANGED
|
@@ -139,15 +139,11 @@ export async function mpBuildShell(newAppInfo, isGodot) {
|
|
|
139
139
|
});
|
|
140
140
|
} else {
|
|
141
141
|
Logger.info('检测到 Godot 项目,开始执行 Godot 导出流程...');
|
|
142
|
-
const defaultPlatform = ['android', 'ios'].includes(CONSTANTS.BUNDLE_PLATFORM)
|
|
143
|
-
? CONSTANTS.BUNDLE_PLATFORM
|
|
144
|
-
: 'ios';
|
|
145
142
|
const godotDefaults = {
|
|
146
143
|
targetBaseDir: outputPath,
|
|
147
144
|
projectDir: guessGodotProjectDir(PROJECT_ROOT),
|
|
148
145
|
name: newAppInfo.appid || 'GodotApp',
|
|
149
|
-
preset:
|
|
150
|
-
platform: defaultPlatform
|
|
146
|
+
preset: ''
|
|
151
147
|
};
|
|
152
148
|
const godotOptions = await promptGodotOptions(godotDefaults);
|
|
153
149
|
outputPath = path.resolve(godotOptions.targetBaseDir);
|
package/src/debug.mjs
CHANGED
|
@@ -14,19 +14,19 @@ import { printQrcode } from './utils-functions.mjs';
|
|
|
14
14
|
* 小程序真机调试
|
|
15
15
|
* @param {object} newAppInfo - 应用信息
|
|
16
16
|
*/
|
|
17
|
-
export async function mpDebugShell(newAppInfo) {
|
|
17
|
+
export async function mpDebugShell(newAppInfo, isGodot) {
|
|
18
18
|
try {
|
|
19
|
-
//
|
|
20
|
-
if (!newAppInfo.entry) {
|
|
19
|
+
// 验证必需字段(非 Godot 项目需要 entry)
|
|
20
|
+
if (!isGodot && !newAppInfo.entry) {
|
|
21
21
|
throw new Error('缺少必需的应用信息: entry');
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const zipPath = await mpBuildShell(newAppInfo);
|
|
24
|
+
const zipPath = await mpBuildShell(newAppInfo, isGodot);
|
|
25
25
|
const assetsPath = path.dirname(zipPath);
|
|
26
26
|
const appJsonPath = path.join(assetsPath, 'app.json');
|
|
27
27
|
|
|
28
28
|
Logger.info(`资源路径: ${assetsPath}`);
|
|
29
|
-
const applocaljson = fse.
|
|
29
|
+
const applocaljson = await fse.readJson(appJsonPath);
|
|
30
30
|
|
|
31
31
|
// 验证网络配置
|
|
32
32
|
const networkValidation = await ConfigValidator.validateNetworkConfig();
|
|
@@ -43,26 +43,28 @@ export async function mpDebugShell(newAppInfo) {
|
|
|
43
43
|
cwd: assetsPath
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
const server = app.listen(function () {
|
|
46
|
+
const server = app.listen(async function () {
|
|
47
47
|
const address = server.address();
|
|
48
48
|
|
|
49
49
|
const debugerAppUrlConfig = `http://${host}:${address.port}/app.json`;
|
|
50
50
|
const debugerZip = `http://${host}:${address.port}/dist.dgz`;
|
|
51
|
+
const { name, appid, version } = applocaljson;
|
|
51
52
|
const args = {
|
|
52
53
|
...applocaljson,
|
|
53
54
|
development: true,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
name,
|
|
56
|
+
appid,
|
|
57
|
+
version,
|
|
57
58
|
appUrlConfig: debugerAppUrlConfig,
|
|
58
59
|
zipUrl: debugerZip,
|
|
59
60
|
};
|
|
60
61
|
|
|
61
|
-
fse.
|
|
62
|
-
|
|
62
|
+
const currentAppJson = await fse.readJson(appJsonPath);
|
|
63
|
+
await fse.writeJson(appJsonPath, {
|
|
64
|
+
...currentAppJson,
|
|
63
65
|
appUrlConfig: debugerAppUrlConfig,
|
|
64
66
|
zipUrl: debugerZip,
|
|
65
|
-
});
|
|
67
|
+
}, { spaces: 2 });
|
|
66
68
|
|
|
67
69
|
const qrcodeUrl = `https://share.dagouzhi.com/#/pages/index/index?data=${encodeURIComponent(JSON.stringify(args))}`;
|
|
68
70
|
|
|
@@ -71,9 +73,9 @@ export async function mpDebugShell(newAppInfo) {
|
|
|
71
73
|
console.log(boxen(
|
|
72
74
|
gradient.rainbow('小程序真机调试') + '\n\n' +
|
|
73
75
|
chalk.cyan('服务器地址: ') + chalk.white(`${host}:${address.port}`) + '\n' +
|
|
74
|
-
chalk.cyan('应用名称: ') + chalk.white(
|
|
75
|
-
chalk.cyan('应用ID: ') + chalk.white(
|
|
76
|
-
chalk.cyan('版本: ') + chalk.white(
|
|
76
|
+
chalk.cyan('应用名称: ') + chalk.white(name) + '\n' +
|
|
77
|
+
chalk.cyan('应用ID: ') + chalk.white(appid) + '\n' +
|
|
78
|
+
chalk.cyan('版本: ') + chalk.white(version),
|
|
77
79
|
{
|
|
78
80
|
padding: 1,
|
|
79
81
|
margin: 1,
|
package/src/export_godot.mjs
CHANGED
|
@@ -29,16 +29,22 @@ export async function promptGodotOptions(defaults = {}) {
|
|
|
29
29
|
if (
|
|
30
30
|
defaults.targetBaseDir &&
|
|
31
31
|
defaults.projectDir &&
|
|
32
|
-
defaults.appid
|
|
33
|
-
defaults.preset &&
|
|
34
|
-
defaults.platform
|
|
32
|
+
defaults.appid
|
|
35
33
|
) {
|
|
34
|
+
// platform 是可选的,如果不指定则默认为全部平台
|
|
35
|
+
let platform = defaults.platform || [PLATFORMS.IOS, PLATFORMS.ANDROID];
|
|
36
|
+
// 处理 'all' 的情况
|
|
37
|
+
if (platform === 'all') {
|
|
38
|
+
platform = [PLATFORMS.IOS, PLATFORMS.ANDROID];
|
|
39
|
+
} else if (!Array.isArray(platform)) {
|
|
40
|
+
platform = [platform];
|
|
41
|
+
}
|
|
36
42
|
return {
|
|
37
43
|
targetBaseDir: String(defaults.targetBaseDir).trim(),
|
|
38
44
|
projectDir: String(defaults.projectDir).trim(),
|
|
39
45
|
name: String(defaults.appid).trim(),
|
|
40
46
|
preset: String(defaults.preset).trim(),
|
|
41
|
-
platform
|
|
47
|
+
platform
|
|
42
48
|
};
|
|
43
49
|
}
|
|
44
50
|
|
|
@@ -76,19 +82,25 @@ export async function promptGodotOptions(defaults = {}) {
|
|
|
76
82
|
name: 'platform',
|
|
77
83
|
message: '请选择导出平台:',
|
|
78
84
|
choices: [
|
|
85
|
+
{ name: '全部 (iOS + Android)', value: 'all' },
|
|
79
86
|
{ name: 'iOS', value: PLATFORMS.IOS },
|
|
80
87
|
{ name: 'Android', value: PLATFORMS.ANDROID }
|
|
81
88
|
],
|
|
82
|
-
default: defaults.platform || '
|
|
89
|
+
default: defaults.platform || 'all'
|
|
83
90
|
}
|
|
84
91
|
]);
|
|
85
92
|
|
|
93
|
+
// 将 'all' 转换为数组,单个平台也转换为数组以保持一致性
|
|
94
|
+
const platform = answers.platform === 'all'
|
|
95
|
+
? [PLATFORMS.IOS, PLATFORMS.ANDROID]
|
|
96
|
+
: [answers.platform];
|
|
97
|
+
|
|
86
98
|
return {
|
|
87
99
|
targetBaseDir: answers.targetBaseDir.trim(),
|
|
88
100
|
projectDir: answers.projectDir.trim(),
|
|
89
101
|
name: answers.name.trim(),
|
|
90
102
|
preset: answers.preset.trim(),
|
|
91
|
-
platform
|
|
103
|
+
platform
|
|
92
104
|
};
|
|
93
105
|
}
|
|
94
106
|
|
|
@@ -202,15 +214,30 @@ export async function exportGodot(options) {
|
|
|
202
214
|
await runGodotCommand(godotBin, importArgs);
|
|
203
215
|
await runGodotCommand(godotBin, importArgs);
|
|
204
216
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
217
|
+
// platform 现在是数组,支持多个平台
|
|
218
|
+
// 处理 'all' 的情况和未指定的情况
|
|
219
|
+
let platforms;
|
|
220
|
+
if (platform === 'all') {
|
|
221
|
+
platforms = [PLATFORMS.IOS, PLATFORMS.ANDROID];
|
|
222
|
+
} else if (Array.isArray(platform)) {
|
|
223
|
+
platforms = platform;
|
|
224
|
+
} else if (platform) {
|
|
225
|
+
platforms = [platform];
|
|
226
|
+
} else {
|
|
227
|
+
platforms = [PLATFORMS.IOS, PLATFORMS.ANDROID];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const plat of platforms) {
|
|
231
|
+
switch (plat) {
|
|
232
|
+
case PLATFORMS.IOS:
|
|
233
|
+
await handleIosExport({ godotBin, projectDir, preset, targetBaseDir, name });
|
|
234
|
+
break;
|
|
235
|
+
case PLATFORMS.ANDROID:
|
|
236
|
+
await handleAndroidExport({ godotBin, projectDir, preset, targetBaseDir, name });
|
|
237
|
+
break;
|
|
238
|
+
default:
|
|
239
|
+
throw new Error(`Unsupported platform: ${plat}. Supported: ${Object.values(PLATFORMS).join(', ')}`);
|
|
240
|
+
}
|
|
214
241
|
}
|
|
215
242
|
}
|
|
216
243
|
|