@htyf-mp/cli 0.7.1 → 0.7.3
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/README.md +6 -3
- package/package.json +3 -3
- package/src/build.mjs +12 -1
- package/src/config.mjs +3 -3
- package/src/project-initializer.mjs +7 -4
- package/src/template-processor.mjs +2 -3
package/README.md
CHANGED
|
@@ -35,7 +35,9 @@ CLI 会自动:
|
|
|
35
35
|
- 生成 `app.json` 中的 `htyf` 配置(包含 `appid`、`name`、`zipUrl`、`appUrlConfig` 等)。
|
|
36
36
|
- 将模板拷贝到你指定的项目目录中。
|
|
37
37
|
|
|
38
|
-
>
|
|
38
|
+
> 各模板的具体用法,请参考生成项目根目录的 `README.md`。RN/Godot 模板在 htyf-cli 中维护;。
|
|
39
|
+
|
|
40
|
+
AI 全量/增量迁移规则单独安装:[htyf-skills](https://github.com/htyf-mp-community/htyf-skills)。当前 CLI 的非交互命令和版本说明见 [仓库指南](https://github.com/htyf-mp-community/htyf-cli)。
|
|
39
41
|
|
|
40
42
|
## AI / 脚本直接调用
|
|
41
43
|
|
|
@@ -103,7 +105,9 @@ node src/index.mjs
|
|
|
103
105
|
3. 提示输入版本号(默认在当前版本基础上自动 +1,例如 `1.0.0 -> 1.0.1`)。
|
|
104
106
|
4. 更新 `app.json` 中的版本号并执行构建,将资源输出到 `dist` 目录。
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
构建完成后,会在压缩包旁生成 `dist/share-qrcode.png`,并在终端显示分享链接和二维码。扫码进入应用分享页,二维码包含本次构建的应用信息和版本。原有 `dist/dist/qrcode.png` 仍为资源下载二维码。
|
|
109
|
+
|
|
110
|
+
使用分享二维码前,请将资源包和 `app.json` 分别上传到配置中的 `zipUrl` 和 `appUrlConfig` 地址,供红糖云服 App 拉取与更新。
|
|
107
111
|
|
|
108
112
|
### 真机调试
|
|
109
113
|
|
|
@@ -144,4 +148,3 @@ node src/index.mjs --clean cache # 清理缓存文件
|
|
|
144
148
|
> - React Native 应用小程序:`_apps_temp_/README.md`
|
|
145
149
|
> - Godot 游戏小程序:`_game_temp_/README.md`
|
|
146
150
|
> - Web/H5 小程序:`_web_temp_/RADME.md`
|
|
147
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htyf-mp/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "红糖云服app小程序模板-cli",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
33
|
"url": "https://github.com/htyf-mp-community/htyf-cli.git",
|
|
34
|
-
"directory": "
|
|
34
|
+
"directory": "packages/cli"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=18.0.0",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"publishConfig": {
|
|
83
83
|
"access": "public"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "23f12d9168179b8993548cec25ec4575930ef80d"
|
|
86
86
|
}
|
package/src/build.mjs
CHANGED
|
@@ -83,6 +83,7 @@ async function syncWebH5Output(projectDistRoot, zipInputDir) {
|
|
|
83
83
|
'build', // RN bundle 输出目录
|
|
84
84
|
'app.json',
|
|
85
85
|
'manifest.json',
|
|
86
|
+
'share-qrcode.png', // 分享图片不属于 H5 应用资源
|
|
86
87
|
]);
|
|
87
88
|
|
|
88
89
|
for (const entry of entries) {
|
|
@@ -117,6 +118,16 @@ async function generateBuildQrCode(outputPath, appJson) {
|
|
|
117
118
|
Logger.success(`二维码已生成: ${qrFilePath}`);
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
/** 在压缩包旁生成分享二维码,使用与 App 分享页一致的应用信息协议。 */
|
|
122
|
+
async function generateShareQrCode(outputPath, appJson) {
|
|
123
|
+
const shareUrl = `https://mp.dagouzhi.com/share?data=${encodeURIComponent(JSON.stringify(appJson))}`;
|
|
124
|
+
const qrFilePath = path.join(outputPath, 'share-qrcode.png');
|
|
125
|
+
await QRCode.toFile(qrFilePath, shareUrl, { scale: 6, margin: 4 });
|
|
126
|
+
Logger.success(`分享二维码已生成: ${qrFilePath}`);
|
|
127
|
+
Logger.info(`分享链接: ${shareUrl}`);
|
|
128
|
+
console.log(await QRCode.toString(shareUrl, { type: 'terminal', small: true }));
|
|
129
|
+
}
|
|
130
|
+
|
|
120
131
|
/**
|
|
121
132
|
* 压缩文件夹为 ZIP 文件
|
|
122
133
|
*
|
|
@@ -411,10 +422,10 @@ export async function mpBuildShell(newAppInfo, isGodot = false, buildOptions = {
|
|
|
411
422
|
// 压缩输出目录为最终包
|
|
412
423
|
const zipPath = await handleZip(outputPath, distPackagePath);
|
|
413
424
|
Logger.success(`压缩包已创建: ${zipPath}`);
|
|
425
|
+
await generateShareQrCode(mpOutputPath, appJson);
|
|
414
426
|
return zipPath;
|
|
415
427
|
} catch (error) {
|
|
416
428
|
Logger.error(`小程序构建失败: ${error.message}`);
|
|
417
429
|
throw error;
|
|
418
430
|
}
|
|
419
431
|
}
|
|
420
|
-
|
package/src/config.mjs
CHANGED
|
@@ -15,15 +15,15 @@ export class ProjectConfig {
|
|
|
15
15
|
this.templates = {
|
|
16
16
|
[CONSTANTS.TEMPLATE_TYPES.TARO_TEMPLATE]: {
|
|
17
17
|
name: 'taro-template',
|
|
18
|
-
tempPath: '_taro_temp_'
|
|
18
|
+
tempPath: 'packages/cli/_taro_temp_'
|
|
19
19
|
},
|
|
20
20
|
[CONSTANTS.TEMPLATE_TYPES.APP_TEMPLATE]: {
|
|
21
21
|
name: 'app-template',
|
|
22
|
-
tempPath: '_apps_temp_'
|
|
22
|
+
tempPath: 'packages/cli/_apps_temp_'
|
|
23
23
|
},
|
|
24
24
|
[CONSTANTS.TEMPLATE_TYPES.GAME_TEMPLATE]: {
|
|
25
25
|
name: 'game-template',
|
|
26
|
-
tempPath: '_game_temp_'
|
|
26
|
+
tempPath: 'packages/cli/_game_temp_'
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
29
|
}
|
|
@@ -179,11 +179,12 @@ export class ProjectInitializer {
|
|
|
179
179
|
try {
|
|
180
180
|
// 克隆仓库
|
|
181
181
|
spinner.text = '正在克隆模板仓库...';
|
|
182
|
-
|
|
182
|
+
const template = this.config.templates[templateType];
|
|
183
|
+
await this.processor.cloneRepository(template.repository || repoType, tmpdir, { nonInteractive: userInputs.nonInteractive });
|
|
183
184
|
|
|
184
185
|
// 确定应用根路径
|
|
185
|
-
const
|
|
186
|
-
|
|
186
|
+
const appRootPath = path.join(tmpdir, template.tempPath);
|
|
187
|
+
if (!fs.existsSync(appRootPath)) throw new Error(`模板目录不存在: ${template.tempPath}`);
|
|
187
188
|
|
|
188
189
|
// 清理不需要的文件
|
|
189
190
|
spinner.text = '正在清理模板文件...';
|
|
@@ -294,7 +295,9 @@ export class ProjectInitializer {
|
|
|
294
295
|
return commands.join('\n');
|
|
295
296
|
})() + '\n\n' +
|
|
296
297
|
chalk.blue('常用命令:') + '\n' +
|
|
297
|
-
chalk.white(
|
|
298
|
+
chalk.white(templateType === CONSTANTS.TEMPLATE_TYPES.TARO_TEMPLATE
|
|
299
|
+
? ' npm run build:htyf # 进入 Taro 平台菜单,选择打包或调试'
|
|
300
|
+
: ' npx @htyf-mp/cli # 打开构建与调试菜单') + '\n' +
|
|
298
301
|
chalk.gray('💡 提示: 使用 --debug 参数可以查看详细的调试信息'),
|
|
299
302
|
{
|
|
300
303
|
padding: 1,
|
|
@@ -48,12 +48,11 @@ export class TemplateProcessor {
|
|
|
48
48
|
path.join(tmpdir, 'README.md')
|
|
49
49
|
];
|
|
50
50
|
|
|
51
|
-
const cliTemplatesDir = path.join(tmpdir, 'packages/cli');
|
|
52
51
|
const selectedTemplate = this.config.templates[templateType];
|
|
53
52
|
if (selectedTemplate) {
|
|
54
|
-
const selectedPath = path.join(
|
|
53
|
+
const selectedPath = path.join(tmpdir, selectedTemplate.tempPath);
|
|
55
54
|
Object.values(this.config.templates).forEach((template) => {
|
|
56
|
-
const templatePath = path.join(
|
|
55
|
+
const templatePath = path.join(tmpdir, template.tempPath);
|
|
57
56
|
if (templatePath !== selectedPath) {
|
|
58
57
|
pathsToRemove.push(templatePath);
|
|
59
58
|
}
|