@htyf-mp/cli 0.2.4 → 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 +1 -1
- package/src/config.mjs +1 -1
- package/src/project-initializer.mjs +2 -3
- package/src/template-processor.mjs +3 -60
package/package.json
CHANGED
package/src/config.mjs
CHANGED
|
@@ -191,9 +191,8 @@ 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, 'app.json');
|
|
195
|
+
const configPath = path.join(appRootPath, template.tempPath, 'app.json');
|
|
197
196
|
let existingConfig = {};
|
|
198
197
|
|
|
199
198
|
// 检查 app.json 是否存在
|
|
@@ -245,7 +244,7 @@ export class ProjectInitializer {
|
|
|
245
244
|
} catch (error) {
|
|
246
245
|
// 清理临时目录
|
|
247
246
|
if (fs.existsSync(tmpdir)) {
|
|
248
|
-
fse.removeSync(tmpdir);
|
|
247
|
+
// fse.removeSync(tmpdir);
|
|
249
248
|
}
|
|
250
249
|
throw error;
|
|
251
250
|
}
|
|
@@ -47,9 +47,10 @@ export class TemplateProcessor {
|
|
|
47
47
|
];
|
|
48
48
|
|
|
49
49
|
// 根据模板类型移除不需要的模板
|
|
50
|
-
if (templateType === CONSTANTS.TEMPLATE_TYPES.
|
|
50
|
+
if (templateType === CONSTANTS.TEMPLATE_TYPES.GAME_TEMPLATE) {
|
|
51
51
|
pathsToRemove.push(path.join(tmpdir, 'mini-game-template'));
|
|
52
|
-
}
|
|
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' : 'app.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' : 'app.json'}`);
|
|
129
|
-
|
|
130
|
-
if (fs.existsSync(srcPath)) {
|
|
131
|
-
fse.copySync(srcPath, destPath);
|
|
132
|
-
Logger.debug(`已复制: ${fileName} -> ${destPath}`);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
79
|
}
|
|
137
80
|
|