@gmcb/cli 0.5.5 → 0.6.2
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/CHANGELOG.md +22 -0
- package/README.md +35 -0
- package/lib/actions/build.js +184 -45
- package/lib/actions/copy.js +2 -2
- package/lib/actions/create.js +2 -3
- package/lib/actions/publish.js +67 -38
- package/lib/actions/skill.js +2 -3
- package/lib/apis/http.d.ts +49 -0
- package/lib/apis/http.js +133 -0
- package/lib/apis/index.d.ts +116 -0
- package/lib/apis/index.js +252 -0
- package/lib/bin.js +3 -1
- package/lib/commands/option.d.ts +2 -0
- package/lib/commands/option.js +2 -1
- package/lib/commands/platform.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/scripts/app-apk.d.ts +1 -0
- package/lib/scripts/app-apk.js +15 -0
- package/lib/scripts/app-wgt.d.ts +1 -0
- package/lib/scripts/app-wgt.js +15 -0
- package/lib/scripts/asar-zip.d.ts +1 -0
- package/lib/scripts/asar-zip.js +17 -0
- package/lib/scripts/h5-exe.d.ts +1 -0
- package/lib/scripts/h5-exe.js +17 -0
- package/lib/scripts/h5-zip.d.ts +1 -0
- package/lib/scripts/h5-zip.js +15 -0
- package/lib/scripts/mp-weixin.d.ts +1 -0
- package/lib/scripts/mp-weixin.js +37 -0
- package/lib/scripts/publish.d.ts +9 -0
- package/lib/scripts/publish.js +112 -0
- package/lib/scripts/wgt-zip.d.ts +1 -0
- package/lib/scripts/wgt-zip.js +15 -0
- package/lib/{actions → utils}/config.d.ts +23 -6
- package/lib/{actions → utils}/config.js +19 -17
- package/lib/utils/const.d.ts +25 -1
- package/lib/utils/const.js +31 -2
- package/lib/utils/function.d.ts +2 -0
- package/lib/utils/function.js +20 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/png2ico.d.ts +1 -0
- package/lib/utils/png2ico.js +48 -0
- package/package.json +8 -4
- package/schema.json +35 -3
- package/LICENSE +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.6.2](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.5.5...@gmcb/cli@0.6.2) (2026-07-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* 优化cli ([676ac43](http://10.10.10.16/caoben/front-end/commits/676ac4381ca645ef232936b86e3b77124337a03c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [0.6.0](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.5.5...@gmcb/cli@0.6.0) (2026-07-05)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* 优化cli ([676ac43](http://10.10.10.16/caoben/front-end/commits/676ac4381ca645ef232936b86e3b77124337a03c))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [0.5.5](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.5.4...@gmcb/cli@0.5.5) (2026-06-30)
|
|
7
29
|
|
|
8
30
|
**Note:** Version bump only for package @gmcb/cli
|
package/README.md
CHANGED
|
@@ -21,6 +21,41 @@ npm i @gmcb/cli -g
|
|
|
21
21
|
| `gmcb skill sync` | 同步技能到本地项目 |
|
|
22
22
|
| `gmcb skill list` | 列出当前项目所有技能 |
|
|
23
23
|
|
|
24
|
+
## `gmcb build`
|
|
25
|
+
|
|
26
|
+
应用程序构建。支持以下选项:
|
|
27
|
+
|
|
28
|
+
| 选项 | 描述 |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `-p, --platform` | 编译平台,默认 h5 |
|
|
31
|
+
| `-c, --compiler` | 构建工具,默认 uni |
|
|
32
|
+
| `-b, --branch` | Git 分支名称 |
|
|
33
|
+
| `-e, --env` | 构建环境,默认 prod |
|
|
34
|
+
| `--wgt` | 构建移动应用热更新资源 |
|
|
35
|
+
| `--zip` | 构建桌面应用热更新资源 |
|
|
36
|
+
|
|
37
|
+
使用 `--wgt` 构建移动应用热更新资源时,会先通过 vite/uni 正常构建 app,再将构建产物(`dist/build/app` 或 `unpackage/dist/build/app-plus`)打包为 `.wgt` 文件,输出路径默认为 `unpackage/release`。
|
|
38
|
+
|
|
39
|
+
`uni.build.json` 中可通过 `app.wgt` 配置导出文件名和路径:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"app": {
|
|
44
|
+
"wgt": {
|
|
45
|
+
"name": "app.wgt",
|
|
46
|
+
"path": "unpackage/release"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
示例:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 构建 app 并打包 wgt
|
|
56
|
+
gmcb build -p app --wgt
|
|
57
|
+
```
|
|
58
|
+
|
|
24
59
|
## `gmcb publish`
|
|
25
60
|
|
|
26
61
|
应用程序发布。支持以下选项:
|
package/lib/actions/build.js
CHANGED
|
@@ -30,6 +30,8 @@ exports.getCommands = getCommands;
|
|
|
30
30
|
exports.default = default_1;
|
|
31
31
|
const fs_1 = require("fs");
|
|
32
32
|
const path_1 = require("path");
|
|
33
|
+
const https_1 = __importDefault(require("https"));
|
|
34
|
+
const http_1 = __importDefault(require("http"));
|
|
33
35
|
const fs_extra_1 = require("fs-extra");
|
|
34
36
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
35
37
|
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
@@ -38,16 +40,13 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
38
40
|
const delay_1 = __importDefault(require("delay"));
|
|
39
41
|
const platform = __importStar(require("../commands/platform"));
|
|
40
42
|
const utils_1 = require("../utils");
|
|
41
|
-
const config_1 = require("
|
|
42
|
-
|
|
43
|
+
const config_1 = require("../utils/config");
|
|
44
|
+
const apis_1 = require("../apis");
|
|
43
45
|
let envPath = utils_1.BUILD_ENV_PATH;
|
|
44
46
|
async function getCommands(...args) {
|
|
45
|
-
if (!config) {
|
|
46
|
-
config = (0, config_1.getMergeConfig)();
|
|
47
|
-
}
|
|
48
47
|
const opts = args[0];
|
|
49
|
-
if (
|
|
50
|
-
opts.branch =
|
|
48
|
+
if (config_1.CONFIG_DATA.branch && config_1.CONFIG_DATA.branch !== 'false') {
|
|
49
|
+
opts.branch = config_1.CONFIG_DATA.branch;
|
|
51
50
|
}
|
|
52
51
|
if (opts.branch) {
|
|
53
52
|
try {
|
|
@@ -70,6 +69,7 @@ async function getCommands(...args) {
|
|
|
70
69
|
const buildEnv = ['master', 'main'].includes(opts.branch) ? 'prod' : opts.branch || opts.env;
|
|
71
70
|
if (buildEnv) {
|
|
72
71
|
commands.push(`BUILD_ENV=${buildEnv}`);
|
|
72
|
+
process.env.BUILD_ENV = buildEnv;
|
|
73
73
|
}
|
|
74
74
|
const currentName = (0, path_1.basename)(utils_1.COMMAND_PATH);
|
|
75
75
|
const projectName = opts.project || currentName;
|
|
@@ -81,7 +81,7 @@ async function getCommands(...args) {
|
|
|
81
81
|
commands = [...commands, bin, 'build -p', opts.platform];
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
-
if (!(0, fs_1.existsSync)(
|
|
84
|
+
if (!(0, fs_1.existsSync)(config_1.CONFIG_DATA?.cli?.hbuilderx)) {
|
|
85
85
|
utils_1.log.error('HbuilderX Cli路径不正确,请执行“gmcb config --cli.hbuilderx <cli-path>”设置正确的路径!');
|
|
86
86
|
}
|
|
87
87
|
if (projectName !== currentName) {
|
|
@@ -107,18 +107,26 @@ async function getCommands(...args) {
|
|
|
107
107
|
if (opts.platform.startsWith('app')) {
|
|
108
108
|
const app = platform.app(opts);
|
|
109
109
|
if (opts.wgt) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
index = app.wgt.
|
|
113
|
-
|
|
110
|
+
if (opts.pack) {
|
|
111
|
+
// HBuilderX CLI publish 流程
|
|
112
|
+
let index = app.wgt.indexOf('--path');
|
|
113
|
+
if (index === -1) {
|
|
114
|
+
index = app.wgt.length;
|
|
115
|
+
app.wgt = [...app.wgt, '--path', (0, path_1.resolve)('unpackage/release')];
|
|
116
|
+
}
|
|
117
|
+
const wgtDist = app.wgt[index + 1];
|
|
118
|
+
(0, fs_extra_1.ensureDirSync)(wgtDist);
|
|
119
|
+
const manifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(utils_1.MAINFEST_PATH).toString()));
|
|
120
|
+
if (manifest.appid) {
|
|
121
|
+
(0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
|
|
122
|
+
}
|
|
123
|
+
cmds = ['publish', '--platform APP', '--type wgt', ...app.wgt];
|
|
114
124
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
(0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
|
|
125
|
+
else {
|
|
126
|
+
// 普通构建,后续由 generatePackage 打包 wgt
|
|
127
|
+
commands = [...commands, bin, 'build -p', opts.platform];
|
|
128
|
+
cmds = null;
|
|
120
129
|
}
|
|
121
|
-
cmds = ['publish', '--platform APP', '--type wgt', ...app.wgt];
|
|
122
130
|
}
|
|
123
131
|
else if (opts.res) {
|
|
124
132
|
cmds = ['publish', '--platform APP', '--type appResource'];
|
|
@@ -151,15 +159,18 @@ async function getCommands(...args) {
|
|
|
151
159
|
const h5 = platform.h5();
|
|
152
160
|
cmds = ['publish', '--platform h5', ...h5];
|
|
153
161
|
}
|
|
154
|
-
|
|
162
|
+
if (cmds) {
|
|
163
|
+
commands = [...commands, config_1.CONFIG_DATA?.cli?.hbuilderx, ...cmds, '--project', projectName];
|
|
164
|
+
}
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
167
|
else if (opts.compiler === 'electron-vite') {
|
|
168
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
158
169
|
commands = [
|
|
159
170
|
...commands,
|
|
160
171
|
bin,
|
|
161
172
|
'build',
|
|
162
|
-
`&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`}`,
|
|
173
|
+
`&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`} VERSION_CODE=${pkg.versionCode || ''} VERSION_NAME=${pkg.version || ''}`,
|
|
163
174
|
];
|
|
164
175
|
if (opts.zip) {
|
|
165
176
|
commands.push('electron-builder --dir');
|
|
@@ -174,6 +185,9 @@ async function getCommands(...args) {
|
|
|
174
185
|
commands.push('electron-builder --linux');
|
|
175
186
|
}
|
|
176
187
|
}
|
|
188
|
+
else if (opts.compiler === 'gradlew') {
|
|
189
|
+
commands = ['gradlew assembleRelease'];
|
|
190
|
+
}
|
|
177
191
|
else {
|
|
178
192
|
commands = [...commands, bin, 'build'];
|
|
179
193
|
}
|
|
@@ -191,37 +205,160 @@ function generateH5Manifest() {
|
|
|
191
205
|
versionCode: manifest['versionCode'] || '',
|
|
192
206
|
});
|
|
193
207
|
}
|
|
194
|
-
async function
|
|
208
|
+
async function generatePackage(opts) {
|
|
209
|
+
const { compiler, platform, win } = opts;
|
|
195
210
|
const spinner = (0, ora_1.default)(`正在生成资源文件...`).start();
|
|
196
211
|
await (0, delay_1.default)(1000);
|
|
197
|
-
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
212
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH, { throws: false }) || {};
|
|
198
213
|
const manifest = (0, utils_1.readManifest)();
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
let dest;
|
|
215
|
+
if (compiler === 'electron-vite' && win) {
|
|
216
|
+
const exeCfg = config_1.CONFIG_DATA.h5?.windows;
|
|
217
|
+
dest = (0, path_1.join)(utils_1.COMMAND_PATH, exeCfg?.path ?? 'dist', exeCfg?.name ?? `${pkg.version}.${pkg.versionCode}.exe`);
|
|
218
|
+
}
|
|
219
|
+
else if (compiler === 'gradlew') {
|
|
220
|
+
const apkCfg = config_1.CONFIG_DATA.app?.android;
|
|
221
|
+
dest = (0, path_1.join)(utils_1.COMMAND_PATH, apkCfg?.path ?? 'app/build/outputs/apk/release', apkCfg?.name ?? 'app-release.apk');
|
|
205
222
|
}
|
|
206
223
|
else {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
const zip = new adm_zip_1.default();
|
|
225
|
+
let zipConfig;
|
|
226
|
+
let defaultSource;
|
|
227
|
+
if (compiler === 'uni') {
|
|
228
|
+
if (platform === 'h5') {
|
|
229
|
+
zipConfig = config_1.CONFIG_DATA.h5?.zip || {};
|
|
230
|
+
defaultSource = utils_1.HAS_SRC ? 'dist/build/h5' : 'unpackage/dist/build/web';
|
|
231
|
+
}
|
|
232
|
+
else if (platform?.startsWith('app')) {
|
|
233
|
+
zipConfig = config_1.CONFIG_DATA.app?.wgt || {};
|
|
234
|
+
defaultSource = utils_1.HAS_SRC ? 'dist/build/app' : 'unpackage/dist/build/app-plus';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else if (compiler === 'electron-vite') {
|
|
238
|
+
zipConfig = config_1.CONFIG_DATA.h5?.zip || {};
|
|
239
|
+
defaultSource = 'dist/win-unpacked/resources';
|
|
240
|
+
}
|
|
241
|
+
const ext = platform?.startsWith('app') ? '.wgt' : '.zip';
|
|
242
|
+
const name = zipConfig.name || `${manifest['appid'] || pkg.name}${ext}`;
|
|
243
|
+
const source = (0, path_1.join)(utils_1.COMMAND_PATH, zipConfig.source ?? defaultSource);
|
|
244
|
+
dest = (0, path_1.join)(utils_1.COMMAND_PATH, `${zipConfig.path ?? 'unpackage/release'}/${name}`);
|
|
245
|
+
if ((0, fs_1.existsSync)(dest)) {
|
|
246
|
+
(0, fs_1.unlinkSync)(dest);
|
|
247
|
+
}
|
|
248
|
+
const zipRoot = compiler === 'uni' && platform === 'h5' ? (pkg.appId || '') : '';
|
|
249
|
+
zip.addLocalFolder(source, zipRoot);
|
|
250
|
+
zip.writeZip(dest);
|
|
251
|
+
}
|
|
219
252
|
spinner.stop();
|
|
220
|
-
spinner.succeed(
|
|
253
|
+
spinner.succeed(`资源路径:${dest}`);
|
|
254
|
+
}
|
|
255
|
+
function downloadFile(url, dest) {
|
|
256
|
+
return new Promise((res, rej) => {
|
|
257
|
+
const mod = url.startsWith('https') ? https_1.default : http_1.default;
|
|
258
|
+
mod.get(url, (response) => {
|
|
259
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
260
|
+
downloadFile(response.headers.location, dest).then(res, rej);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const ws = require('fs').createWriteStream(dest);
|
|
264
|
+
response.pipe(ws);
|
|
265
|
+
ws.on('finish', () => { ws.close(); res(); });
|
|
266
|
+
ws.on('error', rej);
|
|
267
|
+
}).on('error', rej);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
async function fetchRemoteResources(opts) {
|
|
271
|
+
const spinner = (0, ora_1.default)('正在加载主应用数据...').start();
|
|
272
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
273
|
+
const appId = pkg.appId;
|
|
274
|
+
const result = await (0, apis_1.fetchRemoteVersionInfo)(appId);
|
|
275
|
+
const { appName, iconUrl } = result;
|
|
276
|
+
if (opts.win) {
|
|
277
|
+
// Windows
|
|
278
|
+
const zipUrl = result.resourcePackageUrl;
|
|
279
|
+
if (!zipUrl) {
|
|
280
|
+
spinner.fail(`${appName} zip链接未上传`);
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
const rendererDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'out', 'renderer');
|
|
284
|
+
(0, fs_extra_1.removeSync)(rendererDir);
|
|
285
|
+
(0, fs_extra_1.ensureDirSync)(rendererDir);
|
|
286
|
+
const tmpZip = (0, path_1.join)(utils_1.COMMAND_PATH, '__tmp_remote.zip');
|
|
287
|
+
await downloadFile(zipUrl, tmpZip);
|
|
288
|
+
const zip = new adm_zip_1.default(tmpZip);
|
|
289
|
+
zip.extractAllTo(rendererDir, true);
|
|
290
|
+
(0, fs_extra_1.removeSync)(tmpZip);
|
|
291
|
+
// 从目标目录读取 manifest
|
|
292
|
+
const manifest = (0, fs_extra_1.readJsonSync)((0, path_1.join)(rendererDir, appId, 'manifest.json'));
|
|
293
|
+
const { versionName, versionCode } = manifest;
|
|
294
|
+
// 替换 package.json
|
|
295
|
+
const pkgPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'package.json');
|
|
296
|
+
let pkgContent = (0, fs_1.readFileSync)(pkgPath, 'utf-8');
|
|
297
|
+
pkgContent = pkgContent.replace(/"version":\s*"[^"]*"/, `"version": "${versionName}"`);
|
|
298
|
+
pkgContent = pkgContent.replace(/"versionCode":\s*\d+/, `"versionCode": ${versionCode}`);
|
|
299
|
+
pkgContent = pkgContent.replace(/"productName":\s*"[^"]*"/, `"productName": "${appName}"`);
|
|
300
|
+
(0, fs_1.writeFileSync)(pkgPath, pkgContent);
|
|
301
|
+
// 下载图标
|
|
302
|
+
if (iconUrl) {
|
|
303
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(utils_1.COMMAND_PATH, 'res'));
|
|
304
|
+
const iconPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'res', 'icon.png');
|
|
305
|
+
await downloadFile(iconUrl, iconPath);
|
|
306
|
+
await (0, utils_1.png2ico)(iconPath, (0, path_1.join)(utils_1.COMMAND_PATH, 'res', 'icon.ico'));
|
|
307
|
+
}
|
|
308
|
+
spinner.succeed(`Windows本地资源已更新`);
|
|
309
|
+
}
|
|
310
|
+
else if (opts.compiler === 'gradlew') {
|
|
311
|
+
// Android
|
|
312
|
+
const wgtUrl = result.fullPackageUrl;
|
|
313
|
+
if (!wgtUrl) {
|
|
314
|
+
spinner.fail(`${appName} wgt链接未上传`);
|
|
315
|
+
process.exit(1);
|
|
316
|
+
}
|
|
317
|
+
const appDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'assets', 'apps');
|
|
318
|
+
const tempDir = (0, path_1.join)(appDir, appId);
|
|
319
|
+
(0, fs_extra_1.removeSync)(tempDir);
|
|
320
|
+
(0, fs_extra_1.ensureDirSync)(tempDir);
|
|
321
|
+
const tmpWgt = (0, path_1.join)(utils_1.COMMAND_PATH, '__tmp_remote.wgt');
|
|
322
|
+
await downloadFile(wgtUrl, tmpWgt);
|
|
323
|
+
const wgtZip = new adm_zip_1.default(tmpWgt);
|
|
324
|
+
wgtZip.extractAllTo(tempDir, true);
|
|
325
|
+
(0, fs_extra_1.removeSync)(tmpWgt);
|
|
326
|
+
// 从目标目录读取 manifest
|
|
327
|
+
const manifest = (0, fs_extra_1.readJsonSync)((0, path_1.join)(tempDir, 'manifest.json'));
|
|
328
|
+
const { version, id } = manifest;
|
|
329
|
+
const assetsDir = (0, path_1.join)(appDir, id, 'www');
|
|
330
|
+
// 将解压内容复制到 assetsDir,然后删除临时目录
|
|
331
|
+
(0, fs_extra_1.ensureDirSync)(assetsDir);
|
|
332
|
+
(0, fs_extra_1.copySync)(tempDir, assetsDir, { overwrite: true });
|
|
333
|
+
(0, fs_extra_1.removeSync)(tempDir);
|
|
334
|
+
// 替换 build.gradle
|
|
335
|
+
const gradlePath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle');
|
|
336
|
+
let gradleContent = (0, fs_1.readFileSync)(gradlePath, 'utf-8');
|
|
337
|
+
gradleContent = gradleContent.replace(/versionCode\s+\d+/, `versionCode ${version.code}`);
|
|
338
|
+
gradleContent = gradleContent.replace(/versionName\s+"[^"]*"/, `versionName "${version.name}"`);
|
|
339
|
+
(0, fs_1.writeFileSync)(gradlePath, gradleContent);
|
|
340
|
+
// 替换 strings.xml
|
|
341
|
+
const stringsPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
|
|
342
|
+
let stringsContent = (0, fs_1.readFileSync)(stringsPath, 'utf-8');
|
|
343
|
+
stringsContent = stringsContent.replace(/<string name="app_name">[^<]*<\/string>/, `<string name="app_name">${appName}</string>`);
|
|
344
|
+
(0, fs_1.writeFileSync)(stringsPath, stringsContent);
|
|
345
|
+
// 下载图标
|
|
346
|
+
if (iconUrl) {
|
|
347
|
+
const drawableDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'drawable-xxhdpi');
|
|
348
|
+
(0, fs_extra_1.ensureDirSync)(drawableDir);
|
|
349
|
+
const iconPath = (0, path_1.join)(drawableDir, 'icon.png');
|
|
350
|
+
await downloadFile(iconUrl, iconPath);
|
|
351
|
+
(0, fs_1.copyFileSync)(iconPath, (0, path_1.join)(drawableDir, 'push.png'));
|
|
352
|
+
}
|
|
353
|
+
spinner.succeed(`Android本地资源已更新`);
|
|
354
|
+
}
|
|
221
355
|
}
|
|
222
356
|
async function default_1(...args) {
|
|
223
357
|
const opts = args[0];
|
|
224
358
|
const commands = await getCommands(...args);
|
|
359
|
+
if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
|
|
360
|
+
await fetchRemoteResources(opts);
|
|
361
|
+
}
|
|
225
362
|
const command = commands.join(' ');
|
|
226
363
|
const time = Date.now();
|
|
227
364
|
(0, utils_1.spawnSync)(command);
|
|
@@ -229,7 +366,7 @@ async function default_1(...args) {
|
|
|
229
366
|
(0, fs_1.unlinkSync)(envPath);
|
|
230
367
|
}
|
|
231
368
|
if ((Date.now() - time) / 1000 <= 1) {
|
|
232
|
-
if (command.includes(
|
|
369
|
+
if (command.includes(config_1.CONFIG_DATA.cli.hbuilderx)) {
|
|
233
370
|
utils_1.log.error('检测到您的HbuilderX未启动或项目管理器中未发现构建项目,请检查后重试!');
|
|
234
371
|
}
|
|
235
372
|
}
|
|
@@ -237,9 +374,11 @@ async function default_1(...args) {
|
|
|
237
374
|
if (opts.compiler === 'uni' && opts.platform === 'h5') {
|
|
238
375
|
generateH5Manifest();
|
|
239
376
|
}
|
|
240
|
-
if ((opts.compiler === 'electron-vite' && opts.zip) ||
|
|
241
|
-
(opts.compiler === 'uni' && opts.platform === 'h5' && opts.zip)
|
|
242
|
-
|
|
377
|
+
if ((opts.compiler === 'electron-vite' && (opts.zip || opts.win)) ||
|
|
378
|
+
(opts.compiler === 'uni' && opts.platform === 'h5' && opts.zip) ||
|
|
379
|
+
(opts.compiler === 'uni' && opts.platform?.startsWith('app') && opts.wgt && !opts.pack) ||
|
|
380
|
+
opts.compiler === 'gradlew' && opts.platform === 'app') {
|
|
381
|
+
await generatePackage(opts);
|
|
243
382
|
}
|
|
244
383
|
return commands;
|
|
245
384
|
}
|
package/lib/actions/copy.js
CHANGED
|
@@ -11,7 +11,7 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
11
11
|
const delay_1 = __importDefault(require("delay"));
|
|
12
12
|
const flat_1 = require("flat");
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
|
-
const config_1 = require("
|
|
14
|
+
const config_1 = require("../utils/config");
|
|
15
15
|
async function default_1(...args) {
|
|
16
16
|
const opts = args[0];
|
|
17
17
|
if (!opts.source) {
|
|
@@ -21,7 +21,7 @@ async function default_1(...args) {
|
|
|
21
21
|
utils_1.log.error('请使用-d或--dest设置复制资源的目标目录');
|
|
22
22
|
}
|
|
23
23
|
const data = {};
|
|
24
|
-
const flatConfig = (0, flat_1.flatten)(
|
|
24
|
+
const flatConfig = (0, flat_1.flatten)(config_1.CONFIG_DATA);
|
|
25
25
|
const flatManifest = (0, flat_1.flatten)((0, utils_1.readManifest)());
|
|
26
26
|
const flatPackage = (0, flat_1.flatten)((0, fs_1.existsSync)(utils_1.PACKAGE_PATH) ? ((0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH, { throws: false }) || {}) : {});
|
|
27
27
|
Object.keys(flatConfig).forEach((k) => {
|
package/lib/actions/create.js
CHANGED
|
@@ -36,13 +36,12 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
36
36
|
const fsExtra = __importStar(require("fs-extra"));
|
|
37
37
|
const os_1 = __importDefault(require("os"));
|
|
38
38
|
const utils_1 = require("../utils");
|
|
39
|
-
const config_1 = require("
|
|
39
|
+
const config_1 = require("../utils/config");
|
|
40
40
|
async function default_1(...args) {
|
|
41
41
|
const name = args[0];
|
|
42
42
|
const opts = args[1];
|
|
43
43
|
const dest = (0, path_1.join)(utils_1.COMMAND_PATH, name);
|
|
44
|
-
const
|
|
45
|
-
const repoUrl = opts['template.repo'] || config.template?.repo || utils_1.DEFAULT_TEMPLATE_REPO;
|
|
44
|
+
const repoUrl = opts['template.repo'] || config_1.CONFIG_DATA.template?.repo || utils_1.DEFAULT_TEMPLATE_REPO;
|
|
46
45
|
const tempDir = (0, path_1.join)(os_1.default.tmpdir(), `gmcb-template-${Date.now()}`);
|
|
47
46
|
const spinner = (0, ora_1.default)('正在克隆模板仓库...');
|
|
48
47
|
try {
|
package/lib/actions/publish.js
CHANGED
|
@@ -4,19 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = default_1;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = require("path");
|
|
9
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
8
|
const utils_1 = require("../utils");
|
|
11
9
|
const build_1 = __importDefault(require("./build"));
|
|
12
|
-
const config_1 = require("
|
|
10
|
+
const config_1 = require("../utils/config");
|
|
13
11
|
async function default_1(...args) {
|
|
14
|
-
if (!(0, fs_1.existsSync)((0, path_1.join)(utils_1.COMMAND_PATH, 'node_modules/@gmcb/publish'))) {
|
|
15
|
-
utils_1.log.error('缺少必要的依赖,请执行“npm i @gmcb/publish -D”安装依赖!');
|
|
16
|
-
}
|
|
17
|
-
const config = (0, config_1.getMergeConfig)();
|
|
18
12
|
const opts = args[0];
|
|
19
|
-
const isPublishFlow = !!
|
|
13
|
+
const isPublishFlow = !!config_1.CONFIG_DATA.publish;
|
|
20
14
|
const isAuto = opts.auto;
|
|
21
15
|
const pub = { platform: 0, status: 0, updateType: 0 };
|
|
22
16
|
let install = true;
|
|
@@ -33,7 +27,7 @@ async function default_1(...args) {
|
|
|
33
27
|
if (/^(app|h5)/.test(opts.platform)) {
|
|
34
28
|
if (isPublishFlow) {
|
|
35
29
|
// publish 流程
|
|
36
|
-
if (!
|
|
30
|
+
if (!config_1.CONFIG_DATA.publish?.platform && config_1.CONFIG_DATA.publish?.publishType == 1 && !(opts.wgt && opts.zip)) {
|
|
37
31
|
const { platform } = await inquirer_1.default.prompt([
|
|
38
32
|
{
|
|
39
33
|
type: 'list',
|
|
@@ -55,7 +49,7 @@ async function default_1(...args) {
|
|
|
55
49
|
]);
|
|
56
50
|
pub.platform = platform;
|
|
57
51
|
}
|
|
58
|
-
if (!
|
|
52
|
+
if (!config_1.CONFIG_DATA.publish?.updateType) {
|
|
59
53
|
const { updateType } = await inquirer_1.default.prompt([
|
|
60
54
|
{
|
|
61
55
|
type: 'list',
|
|
@@ -72,7 +66,7 @@ async function default_1(...args) {
|
|
|
72
66
|
}
|
|
73
67
|
else {
|
|
74
68
|
// pub 流程
|
|
75
|
-
if (!
|
|
69
|
+
if (!config_1.CONFIG_DATA.pub?.platform) {
|
|
76
70
|
const { platform } = await inquirer_1.default.prompt([
|
|
77
71
|
{
|
|
78
72
|
type: 'list',
|
|
@@ -94,7 +88,7 @@ async function default_1(...args) {
|
|
|
94
88
|
]);
|
|
95
89
|
pub.platform = platform;
|
|
96
90
|
}
|
|
97
|
-
if (!
|
|
91
|
+
if (!config_1.CONFIG_DATA.pub?.status) {
|
|
98
92
|
const { status } = await inquirer_1.default.prompt([
|
|
99
93
|
{
|
|
100
94
|
type: 'list',
|
|
@@ -141,51 +135,86 @@ async function default_1(...args) {
|
|
|
141
135
|
install = false;
|
|
142
136
|
}
|
|
143
137
|
if (install) {
|
|
144
|
-
(0, utils_1.spawnSync)(
|
|
138
|
+
(0, utils_1.spawnSync)(config_1.CONFIG_DATA.install || 'npm install');
|
|
139
|
+
}
|
|
140
|
+
let cmds;
|
|
141
|
+
if (opts.compiler === 'uni' && opts.wgt && opts.zip) {
|
|
142
|
+
const originalPlatform = opts.platform;
|
|
143
|
+
// 先构建 app(生成 wgt)
|
|
144
|
+
opts.platform = 'app';
|
|
145
|
+
cmds = await (0, build_1.default)(...args);
|
|
146
|
+
// 再构建 h5(生成 zip)
|
|
147
|
+
opts.platform = 'h5';
|
|
148
|
+
await (0, build_1.default)(...args);
|
|
149
|
+
// 恢复
|
|
150
|
+
opts.platform = originalPlatform;
|
|
145
151
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (!commands[2].startsWith('BUILD_ENV')) {
|
|
149
|
-
commands[2] = 'BUILD_ENV=';
|
|
152
|
+
else {
|
|
153
|
+
cmds = await (0, build_1.default)(...args);
|
|
150
154
|
}
|
|
151
|
-
if (
|
|
155
|
+
if (opts.compiler === 'gradlew' || opts.remote) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// 从 cmds 提取 buildEnv
|
|
159
|
+
const buildEnv = cmds[2]?.split('=')[1];
|
|
160
|
+
if (!buildEnv || !['dev', 'sit', 'uat', 'pre', 'prod'].includes(buildEnv)) {
|
|
152
161
|
utils_1.log.error('没有检测到需要发布的环境,无法完成上传,请切换到dev/sit/uat/pre/master分支再次执行脚本,或者您可以选择手动上传!');
|
|
153
162
|
}
|
|
163
|
+
// 更新 CONFIG_DATA(动态 require 前,确保脚本模块能读取到正确值)
|
|
164
|
+
process.env.BUILD_ENV = buildEnv;
|
|
154
165
|
if (isPublishFlow) {
|
|
155
|
-
if (
|
|
156
|
-
|
|
166
|
+
if (!config_1.CONFIG_DATA.publish) {
|
|
167
|
+
config_1.CONFIG_DATA.publish = {};
|
|
168
|
+
}
|
|
169
|
+
if (opts.wgt && opts.zip) {
|
|
170
|
+
// 2个都传则为发布主应用
|
|
171
|
+
config_1.CONFIG_DATA.publish.publishType = 2;
|
|
157
172
|
}
|
|
158
173
|
if (pub.platform) {
|
|
159
|
-
|
|
174
|
+
config_1.CONFIG_DATA.publish.platform = pub.platform;
|
|
175
|
+
}
|
|
176
|
+
if (pub.updateType) {
|
|
177
|
+
config_1.CONFIG_DATA.publish.updateType = pub.updateType;
|
|
160
178
|
}
|
|
161
179
|
}
|
|
162
180
|
else {
|
|
181
|
+
if (!config_1.CONFIG_DATA.pub) {
|
|
182
|
+
config_1.CONFIG_DATA.pub = {};
|
|
183
|
+
}
|
|
163
184
|
if (pub.platform) {
|
|
164
|
-
|
|
185
|
+
config_1.CONFIG_DATA.pub.platform = pub.platform;
|
|
165
186
|
}
|
|
166
187
|
if (pub.status) {
|
|
167
|
-
|
|
188
|
+
config_1.CONFIG_DATA.pub.status = pub.status;
|
|
168
189
|
}
|
|
169
190
|
}
|
|
170
|
-
|
|
171
|
-
const scriptPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'node_modules/@gmcb/publish/lib');
|
|
172
|
-
if (opts.platform?.startsWith('mp')) {
|
|
173
|
-
commands.push((0, path_1.join)(scriptPath, opts.platform));
|
|
174
|
-
}
|
|
175
|
-
else if (opts.platform === 'h5') {
|
|
191
|
+
if (opts.compiler === 'electron-vite') {
|
|
176
192
|
if (opts.zip) {
|
|
177
|
-
|
|
193
|
+
await require('../scripts/asar-zip').default();
|
|
194
|
+
}
|
|
195
|
+
else if (opts.win) {
|
|
196
|
+
await require('../scripts/h5-exe').default();
|
|
178
197
|
}
|
|
179
198
|
}
|
|
180
|
-
else if (opts.
|
|
181
|
-
if (opts.
|
|
182
|
-
|
|
199
|
+
else if (opts.compiler === 'uni') {
|
|
200
|
+
if (opts.platform?.startsWith('mp')) {
|
|
201
|
+
await require('../scripts/mp-weixin').default();
|
|
202
|
+
}
|
|
203
|
+
else if (opts.platform === 'h5') {
|
|
204
|
+
if (opts.wgt && opts.zip) {
|
|
205
|
+
await require('../scripts/wgt-zip').default();
|
|
206
|
+
}
|
|
207
|
+
else if (opts.zip) {
|
|
208
|
+
await require('../scripts/h5-zip').default();
|
|
209
|
+
}
|
|
183
210
|
}
|
|
184
|
-
else if (opts.
|
|
185
|
-
|
|
211
|
+
else if (opts.platform?.startsWith('app')) {
|
|
212
|
+
if (opts.wgt && opts.zip) {
|
|
213
|
+
await require('../scripts/wgt-zip').default();
|
|
214
|
+
}
|
|
215
|
+
else if (opts.wgt) {
|
|
216
|
+
await require('../scripts/app-wgt').default();
|
|
217
|
+
}
|
|
186
218
|
}
|
|
187
219
|
}
|
|
188
|
-
if (commands[commands.length - 1] !== 'node') {
|
|
189
|
-
(0, utils_1.spawnSync)(commands.join(' '));
|
|
190
|
-
}
|
|
191
220
|
}
|
package/lib/actions/skill.js
CHANGED
|
@@ -37,7 +37,7 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
37
37
|
const chalk_1 = __importDefault(require("chalk"));
|
|
38
38
|
const fsExtra = __importStar(require("fs-extra"));
|
|
39
39
|
const os_1 = __importDefault(require("os"));
|
|
40
|
-
const config_1 = require("
|
|
40
|
+
const config_1 = require("../utils/config");
|
|
41
41
|
const utils_1 = require("../utils");
|
|
42
42
|
const ENV_MAP = {
|
|
43
43
|
default: ".agents",
|
|
@@ -101,8 +101,7 @@ function scanRemoteSkills(repoDir) {
|
|
|
101
101
|
}
|
|
102
102
|
async function syncSkill(...args) {
|
|
103
103
|
const opts = args[0];
|
|
104
|
-
const
|
|
105
|
-
const repoUrl = opts["skill.repo"] || config.skill?.repo || utils_1.DEFAULT_SKILL_REPO;
|
|
104
|
+
const repoUrl = opts["skill.repo"] || config_1.CONFIG_DATA.skill?.repo || utils_1.DEFAULT_SKILL_REPO;
|
|
106
105
|
const tempDir = (0, path_1.join)(os_1.default.tmpdir(), `gmcb-skill-${Date.now()}`);
|
|
107
106
|
const spinner = (0, ora_1.default)("正在克隆技能仓库...");
|
|
108
107
|
try {
|