@htyf-mp/cli 0.2.0-alpha.4 → 0.2.0-alpha.6

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,9 +1,12 @@
1
1
  {
2
2
  "name": "@htyf-mp/cli",
3
- "version": "0.2.0-alpha.4",
3
+ "version": "0.2.0-alpha.6",
4
4
  "description": "红糖云服app小程序模板-cli",
5
5
  "type": "module",
6
- "bin": "src/index.mjs",
6
+ "bin": {
7
+ "htyf": "src/index.mjs",
8
+ "htyf-mp": "src/index.mjs"
9
+ },
7
10
  "files": [
8
11
  "src",
9
12
  "README.md"
@@ -62,6 +62,24 @@ export class FileSystemUtils {
62
62
  return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
63
63
  }
64
64
 
65
+ /**
66
+ * 检查目录是否为空
67
+ * @param {string} dirPath
68
+ * @returns {boolean}
69
+ */
70
+ static isDirectoryEmpty(dirPath) {
71
+ if (!fs.existsSync(dirPath)) {
72
+ return true;
73
+ }
74
+ try {
75
+ const entries = fs.readdirSync(dirPath);
76
+ return entries.length === 0;
77
+ } catch (error) {
78
+ Logger.warn(`读取目录内容失败: ${dirPath}`, error.message);
79
+ return false;
80
+ }
81
+ }
82
+
65
83
  static validatePath(path) {
66
84
  // if (/[ - fa5]/gi.test(path)) {
67
85
  // return { isValid: false, error: '路径中包含中文字符' };
@@ -86,7 +86,7 @@ export class ProjectInitializer {
86
86
  process.removeListener('SIGTERM', handleExit);
87
87
 
88
88
  // 5. 显示成功信息
89
- this.showSuccessInfo(userInputs.appName, rootPath);
89
+ this.showSuccessInfo(userInputs.appName, rootPath, userInputs.templateType);
90
90
 
91
91
  } catch (error) {
92
92
  process.removeListener('SIGINT', handleExit);
@@ -193,7 +193,7 @@ export class ProjectInitializer {
193
193
  const projectConfig = this.config.createProjectConfig(appName, displayName, appid);
194
194
 
195
195
  // 写入配置文件
196
- const configPath = path.join(appRootPath, 'project.dgz.json');
196
+ const configPath = path.join(appRootPath, 'htyf.json');
197
197
  fs.writeFileSync(configPath, JSON.stringify(projectConfig, undefined, 2));
198
198
 
199
199
  // 清理临时文件
@@ -205,7 +205,19 @@ export class ProjectInitializer {
205
205
 
206
206
  // 移动到目标目录
207
207
  spinner.text = '正在创建项目目录...';
208
- fse.moveSync(appRootPath, rootPath);
208
+
209
+ if (fs.existsSync(rootPath)) {
210
+ fse.ensureDirSync(rootPath);
211
+ const items = fs.readdirSync(appRootPath);
212
+ items.forEach((item) => {
213
+ const source = path.join(appRootPath, item);
214
+ const destination = path.join(rootPath, item);
215
+ fse.moveSync(source, destination, { overwrite: true });
216
+ });
217
+ fse.removeSync(appRootPath);
218
+ } else {
219
+ fse.moveSync(appRootPath, rootPath);
220
+ }
209
221
 
210
222
  // 清理临时目录
211
223
  fse.removeSync(tmpdir);
@@ -221,19 +233,33 @@ export class ProjectInitializer {
221
233
  }
222
234
  }
223
235
 
224
- showSuccessInfo(appName, rootPath) {
236
+ showSuccessInfo(appName, rootPath, templateType) {
225
237
  console.log('\n' + boxen(
226
238
  gradient.rainbow('🎉 项目创建成功!') + '\n\n' +
227
239
  chalk.cyan('项目名称: ') + chalk.white(appName) + '\n' +
228
240
  chalk.cyan('项目路径: ') + chalk.white(rootPath) + '\n\n' +
229
241
  chalk.yellow('下一步操作:') + '\n' +
230
- chalk.white(` cd ${appName}`) + '\n' +
231
- chalk.white(' npm install') + '\n' +
232
- chalk.white(' npm run dev:weapp') + '\n\n' +
242
+ (() => {
243
+ const relativePath = path.relative(process.cwd(), rootPath);
244
+ const commands = [];
245
+ if (relativePath) {
246
+ commands.push(chalk.white(` cd ${relativePath}`));
247
+ }
248
+
249
+ if (templateType === CONSTANTS.TEMPLATE_TYPES.GAME_TEMPLATE) {
250
+ commands.push(chalk.white(' npm install'));
251
+ } else {
252
+ commands.push(
253
+ chalk.white(' npm install'),
254
+ chalk.white(' npm run ios'),
255
+ chalk.white(' npm run android')
256
+ );
257
+ }
258
+
259
+ return commands.join('\n');
260
+ })() + '\n\n' +
233
261
  chalk.blue('常用命令:') + '\n' +
234
- chalk.white(' npm run build:weapp # 构建微信小程序') + '\n' +
235
- chalk.white(' npm run build:h5 # 构建H5版本') + '\n' +
236
- chalk.white(' npm run build:rn # 构建React Native版本') + '\n\n' +
262
+ chalk.white(' npm run htyf # 构建红糖云服小程序') + '\n' +
237
263
  chalk.gray('💡 提示: 使用 --debug 参数可以查看详细的调试信息'),
238
264
  {
239
265
  padding: 1,
@@ -89,7 +89,7 @@ export class TemplateProcessor {
89
89
  // 复制模板文件
90
90
  Object.entries(template.files).forEach(([key, fileName]) => {
91
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' : 'project.dgz.json'}`);
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
93
 
94
94
  if (fs.existsSync(srcPath)) {
95
95
  fse.copySync(srcPath, destPath);
@@ -125,7 +125,7 @@ export class TemplateProcessor {
125
125
  // 复制模板文件
126
126
  Object.entries(template.files).forEach(([key, fileName]) => {
127
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' : 'project.dgz.json'}`);
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
129
 
130
130
  if (fs.existsSync(srcPath)) {
131
131
  fse.copySync(srcPath, destPath);