@htyf-mp/cli 0.2.3 → 0.2.5

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.3",
3
+ "version": "0.2.5",
4
4
  "description": "红糖云服app小程序模板-cli",
5
5
  "type": "module",
6
6
  "bin": {
package/src/config.mjs CHANGED
@@ -19,7 +19,7 @@ export class ProjectConfig {
19
19
  },
20
20
  [CONSTANTS.TEMPLATE_TYPES.GAME_TEMPLATE]: {
21
21
  name: 'game-template',
22
- tempPath: '_games_temp_'
22
+ tempPath: '_game_temp_'
23
23
  }
24
24
  };
25
25
  }
@@ -191,10 +191,27 @@ export class ProjectInitializer {
191
191
  spinner.text = '正在生成项目配置...';
192
192
  const appid = this.config.generateAppId();
193
193
  const projectConfig = this.config.createProjectConfig(appName, displayName, appid);
194
-
195
194
  // 写入配置文件
196
- const configPath = path.join(appRootPath, 'htyf.json');
197
- fs.writeFileSync(configPath, JSON.stringify(projectConfig, undefined, 2));
195
+ const configPath = path.join(appRootPath, template.tempPath, 'app.json');
196
+ let existingConfig = {};
197
+
198
+ // 检查 app.json 是否存在
199
+ if (fs.existsSync(configPath)) {
200
+ // 如果存在,读取现有内容
201
+ const existingContent = fs.readFileSync(configPath, 'utf-8');
202
+ try {
203
+ existingConfig = JSON.parse(existingContent);
204
+ } catch (error) {
205
+ Logger.warn('app.json 格式错误,将创建新配置');
206
+ existingConfig = {};
207
+ }
208
+ }
209
+
210
+ // 添加 htyf 字段
211
+ existingConfig.htyf = projectConfig;
212
+
213
+ // 写入配置文件
214
+ fs.writeFileSync(configPath, JSON.stringify(existingConfig, undefined, 2));
198
215
 
199
216
  // 清理临时文件
200
217
  spinner.text = '正在清理临时文件...';
@@ -227,7 +244,7 @@ export class ProjectInitializer {
227
244
  } catch (error) {
228
245
  // 清理临时目录
229
246
  if (fs.existsSync(tmpdir)) {
230
- fse.removeSync(tmpdir);
247
+ // fse.removeSync(tmpdir);
231
248
  }
232
249
  throw error;
233
250
  }
@@ -47,9 +47,10 @@ export class TemplateProcessor {
47
47
  ];
48
48
 
49
49
  // 根据模板类型移除不需要的模板
50
- if (templateType === CONSTANTS.TEMPLATE_TYPES.TARO || templateType === CONSTANTS.TEMPLATE_TYPES.EXPO) {
50
+ if (templateType === CONSTANTS.TEMPLATE_TYPES.GAME_TEMPLATE) {
51
51
  pathsToRemove.push(path.join(tmpdir, 'mini-game-template'));
52
- } else if (templateType === CONSTANTS.TEMPLATE_TYPES.GAME_COCOS) {
52
+ }
53
+ if (templateType === CONSTANTS.TEMPLATE_TYPES.APP_TEMPLATE) {
53
54
  pathsToRemove.push(path.join(tmpdir, 'mini-apps-template'));
54
55
  }
55
56
 
@@ -73,65 +74,7 @@ export class TemplateProcessor {
73
74
 
74
75
  const tempPath = path.join(appRootPath, '__TEMP__');
75
76
 
76
- if (templateType === CONSTANTS.TEMPLATE_TYPES.TARO) {
77
- this.processTaroTemplate(appRootPath, tempPath, template);
78
- } else if (templateType === CONSTANTS.TEMPLATE_TYPES.EXPO) {
79
- this.processExpoTemplate(appRootPath, tempPath, template);
80
- } else if (templateType === CONSTANTS.TEMPLATE_TYPES.GAME_COCOS) {
81
- // 预留游戏模板处理
82
- Logger.info('游戏模板处理功能开发中...');
83
- }
84
- }
85
-
86
- processTaroTemplate(appRootPath, tempPath, template) {
87
- Logger.info('正在处理 Taro 模板...');
88
-
89
- // 复制模板文件
90
- Object.entries(template.files).forEach(([key, fileName]) => {
91
- const srcPath = path.join(tempPath, fileName);
92
- const destPath = path.join(appRootPath, key === 'src' ? './src' : `./${key === 'app' ? 'App.tsx' : key === 'index' ? 'index.js' : key === 'babel' ? 'babel.config.js' : 'htyf.json'}`);
93
-
94
- if (fs.existsSync(srcPath)) {
95
- fse.copySync(srcPath, destPath);
96
- Logger.debug(`已复制: ${fileName} -> ${destPath}`);
97
- }
98
- });
99
-
100
- // 更新 package.json
101
- const pkgPath = path.join(appRootPath, './package.json');
102
- if (fs.existsSync(pkgPath)) {
103
- const pkgInfo = fse.readJSONSync(pkgPath);
104
- if (template.scripts) {
105
- pkgInfo.scripts = {
106
- ...(pkgInfo.scripts || {}),
107
- ...template.scripts
108
- };
109
- }
110
-
111
- // 移除不需要的脚本
112
- if (pkgInfo.scripts) {
113
- delete pkgInfo.scripts.web;
114
- delete pkgInfo.scripts['web:dev'];
115
- }
116
-
117
- fse.writeJSONSync(pkgPath, pkgInfo, { spaces: 2 });
118
- Logger.info('package.json 已更新');
119
- }
120
77
  }
121
78
 
122
- processExpoTemplate(appRootPath, tempPath, template) {
123
- Logger.info('正在处理 Expo 模板...');
124
-
125
- // 复制模板文件
126
- Object.entries(template.files).forEach(([key, fileName]) => {
127
- const srcPath = path.join(tempPath, fileName);
128
- const destPath = path.join(appRootPath, key === 'src' ? './src' : `./${key === 'app' ? 'App.tsx' : key === 'index' ? 'index.js' : key === 'babel' ? 'babel.config.js' : 'htyf.json'}`);
129
-
130
- if (fs.existsSync(srcPath)) {
131
- fse.copySync(srcPath, destPath);
132
- Logger.debug(`已复制: ${fileName} -> ${destPath}`);
133
- }
134
- });
135
- }
136
79
  }
137
80