@htyf-mp/cli 0.2.0-alpha.11 → 0.2.0-alpha.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htyf-mp/cli",
3
- "version": "0.2.0-alpha.11",
3
+ "version": "0.2.0-alpha.12",
4
4
  "description": "红糖云服app小程序模板-cli",
5
5
  "type": "module",
6
6
  "bin": {
package/src/build.mjs CHANGED
@@ -139,11 +139,15 @@ 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';
142
145
  const godotDefaults = {
143
146
  targetBaseDir: outputPath,
144
147
  projectDir: guessGodotProjectDir(PROJECT_ROOT),
145
148
  name: newAppInfo.appid || 'GodotApp',
146
- preset: ''
149
+ preset: defaultPlatform === 'android' ? 'Android' : 'iOS',
150
+ platform: defaultPlatform
147
151
  };
148
152
  const godotOptions = await promptGodotOptions(godotDefaults);
149
153
  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, isGodot) {
17
+ export async function mpDebugShell(newAppInfo) {
18
18
  try {
19
- // 验证必需字段(非 Godot 项目需要 entry)
20
- if (!isGodot && !newAppInfo.entry) {
19
+ // 验证必需字段
20
+ if (!newAppInfo.entry) {
21
21
  throw new Error('缺少必需的应用信息: entry');
22
22
  }
23
23
 
24
- const zipPath = await mpBuildShell(newAppInfo, isGodot);
24
+ const zipPath = await mpBuildShell(newAppInfo);
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 = await fse.readJson(appJsonPath);
29
+ const applocaljson = fse.readJsonSync(appJsonPath);
30
30
 
31
31
  // 验证网络配置
32
32
  const networkValidation = await ConfigValidator.validateNetworkConfig();
@@ -43,28 +43,26 @@ export async function mpDebugShell(newAppInfo, isGodot) {
43
43
  cwd: assetsPath
44
44
  });
45
45
 
46
- const server = app.listen(async function () {
46
+ const server = app.listen(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;
52
51
  const args = {
53
52
  ...applocaljson,
54
53
  development: true,
55
- name,
56
- appid,
57
- version,
54
+ "name": applocaljson.name,
55
+ "appid": applocaljson.appid,
56
+ "version": applocaljson.version,
58
57
  appUrlConfig: debugerAppUrlConfig,
59
58
  zipUrl: debugerZip,
60
59
  };
61
60
 
62
- const currentAppJson = await fse.readJson(appJsonPath);
63
- await fse.writeJson(appJsonPath, {
64
- ...currentAppJson,
61
+ fse.writeJSONSync(appJsonPath, {
62
+ ...fse.readJSONSync(appJsonPath),
65
63
  appUrlConfig: debugerAppUrlConfig,
66
64
  zipUrl: debugerZip,
67
- }, { spaces: 2 });
65
+ });
68
66
 
69
67
  const qrcodeUrl = `https://share.dagouzhi.com/#/pages/index/index?data=${encodeURIComponent(JSON.stringify(args))}`;
70
68
 
@@ -73,9 +71,9 @@ export async function mpDebugShell(newAppInfo, isGodot) {
73
71
  console.log(boxen(
74
72
  gradient.rainbow('小程序真机调试') + '\n\n' +
75
73
  chalk.cyan('服务器地址: ') + chalk.white(`${host}:${address.port}`) + '\n' +
76
- chalk.cyan('应用名称: ') + chalk.white(name) + '\n' +
77
- chalk.cyan('应用ID: ') + chalk.white(appid) + '\n' +
78
- chalk.cyan('版本: ') + chalk.white(version),
74
+ chalk.cyan('应用名称: ') + chalk.white(applocaljson.name) + '\n' +
75
+ chalk.cyan('应用ID: ') + chalk.white(applocaljson.appid) + '\n' +
76
+ chalk.cyan('版本: ') + chalk.white(applocaljson.version),
79
77
  {
80
78
  padding: 1,
81
79
  margin: 1,
@@ -29,22 +29,16 @@ export async function promptGodotOptions(defaults = {}) {
29
29
  if (
30
30
  defaults.targetBaseDir &&
31
31
  defaults.projectDir &&
32
- defaults.appid
32
+ defaults.appid &&
33
+ defaults.preset &&
34
+ defaults.platform
33
35
  ) {
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
- }
42
36
  return {
43
37
  targetBaseDir: String(defaults.targetBaseDir).trim(),
44
38
  projectDir: String(defaults.projectDir).trim(),
45
39
  name: String(defaults.appid).trim(),
46
40
  preset: String(defaults.preset).trim(),
47
- platform
41
+ platform: defaults.platform
48
42
  };
49
43
  }
50
44
 
@@ -82,25 +76,19 @@ export async function promptGodotOptions(defaults = {}) {
82
76
  name: 'platform',
83
77
  message: '请选择导出平台:',
84
78
  choices: [
85
- { name: '全部 (iOS + Android)', value: 'all' },
86
79
  { name: 'iOS', value: PLATFORMS.IOS },
87
80
  { name: 'Android', value: PLATFORMS.ANDROID }
88
81
  ],
89
- default: defaults.platform || 'all'
82
+ default: defaults.platform || 'ios'
90
83
  }
91
84
  ]);
92
85
 
93
- // 将 'all' 转换为数组,单个平台也转换为数组以保持一致性
94
- const platform = answers.platform === 'all'
95
- ? [PLATFORMS.IOS, PLATFORMS.ANDROID]
96
- : [answers.platform];
97
-
98
86
  return {
99
87
  targetBaseDir: answers.targetBaseDir.trim(),
100
88
  projectDir: answers.projectDir.trim(),
101
89
  name: answers.name.trim(),
102
90
  preset: answers.preset.trim(),
103
- platform
91
+ platform: answers.platform
104
92
  };
105
93
  }
106
94
 
@@ -214,30 +202,15 @@ export async function exportGodot(options) {
214
202
  await runGodotCommand(godotBin, importArgs);
215
203
  await runGodotCommand(godotBin, importArgs);
216
204
 
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
- }
205
+ switch (platform) {
206
+ case PLATFORMS.IOS:
207
+ await handleIosExport({ godotBin, projectDir, preset, targetBaseDir, name });
208
+ break;
209
+ case PLATFORMS.ANDROID:
210
+ await handleAndroidExport({ godotBin, projectDir, preset, targetBaseDir, name });
211
+ break;
212
+ default:
213
+ throw new Error(`Unsupported platform: ${platform}. Supported: ${Object.values(PLATFORMS).join(', ')}`);
241
214
  }
242
215
  }
243
216