@gmcb/cli 0.5.5 → 0.6.1
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 +11 -0
- package/README.md +35 -0
- package/lib/actions/build.js +181 -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 +234 -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 -3
- package/schema.json +35 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.0](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.5.5...@gmcb/cli@0.6.0) (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
|
+
|
|
6
17
|
## [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
18
|
|
|
8
19
|
**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 {
|
|
@@ -81,7 +80,7 @@ async function getCommands(...args) {
|
|
|
81
80
|
commands = [...commands, bin, 'build -p', opts.platform];
|
|
82
81
|
}
|
|
83
82
|
else {
|
|
84
|
-
if (!(0, fs_1.existsSync)(
|
|
83
|
+
if (!(0, fs_1.existsSync)(config_1.CONFIG_DATA?.cli?.hbuilderx)) {
|
|
85
84
|
utils_1.log.error('HbuilderX Cli路径不正确,请执行“gmcb config --cli.hbuilderx <cli-path>”设置正确的路径!');
|
|
86
85
|
}
|
|
87
86
|
if (projectName !== currentName) {
|
|
@@ -107,18 +106,26 @@ async function getCommands(...args) {
|
|
|
107
106
|
if (opts.platform.startsWith('app')) {
|
|
108
107
|
const app = platform.app(opts);
|
|
109
108
|
if (opts.wgt) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
index = app.wgt.
|
|
113
|
-
|
|
109
|
+
if (opts.pack) {
|
|
110
|
+
// HBuilderX CLI publish 流程
|
|
111
|
+
let index = app.wgt.indexOf('--path');
|
|
112
|
+
if (index === -1) {
|
|
113
|
+
index = app.wgt.length;
|
|
114
|
+
app.wgt = [...app.wgt, '--path', (0, path_1.resolve)('unpackage/release')];
|
|
115
|
+
}
|
|
116
|
+
const wgtDist = app.wgt[index + 1];
|
|
117
|
+
(0, fs_extra_1.ensureDirSync)(wgtDist);
|
|
118
|
+
const manifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(utils_1.MAINFEST_PATH).toString()));
|
|
119
|
+
if (manifest.appid) {
|
|
120
|
+
(0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
|
|
121
|
+
}
|
|
122
|
+
cmds = ['publish', '--platform APP', '--type wgt', ...app.wgt];
|
|
114
123
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
(0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
|
|
124
|
+
else {
|
|
125
|
+
// 普通构建,后续由 generatePackage 打包 wgt
|
|
126
|
+
commands = [...commands, bin, 'build -p', opts.platform];
|
|
127
|
+
cmds = null;
|
|
120
128
|
}
|
|
121
|
-
cmds = ['publish', '--platform APP', '--type wgt', ...app.wgt];
|
|
122
129
|
}
|
|
123
130
|
else if (opts.res) {
|
|
124
131
|
cmds = ['publish', '--platform APP', '--type appResource'];
|
|
@@ -151,15 +158,18 @@ async function getCommands(...args) {
|
|
|
151
158
|
const h5 = platform.h5();
|
|
152
159
|
cmds = ['publish', '--platform h5', ...h5];
|
|
153
160
|
}
|
|
154
|
-
|
|
161
|
+
if (cmds) {
|
|
162
|
+
commands = [...commands, config_1.CONFIG_DATA?.cli?.hbuilderx, ...cmds, '--project', projectName];
|
|
163
|
+
}
|
|
155
164
|
}
|
|
156
165
|
}
|
|
157
166
|
else if (opts.compiler === 'electron-vite') {
|
|
167
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
158
168
|
commands = [
|
|
159
169
|
...commands,
|
|
160
170
|
bin,
|
|
161
171
|
'build',
|
|
162
|
-
`&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`}`,
|
|
172
|
+
`&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`} VERSION_CODE=${pkg.versionCode || ''} VERSION_NAME=${pkg.version || ''}`,
|
|
163
173
|
];
|
|
164
174
|
if (opts.zip) {
|
|
165
175
|
commands.push('electron-builder --dir');
|
|
@@ -174,6 +184,9 @@ async function getCommands(...args) {
|
|
|
174
184
|
commands.push('electron-builder --linux');
|
|
175
185
|
}
|
|
176
186
|
}
|
|
187
|
+
else if (opts.compiler === 'gradlew') {
|
|
188
|
+
commands = ['gradlew assembleRelease'];
|
|
189
|
+
}
|
|
177
190
|
else {
|
|
178
191
|
commands = [...commands, bin, 'build'];
|
|
179
192
|
}
|
|
@@ -191,36 +204,157 @@ function generateH5Manifest() {
|
|
|
191
204
|
versionCode: manifest['versionCode'] || '',
|
|
192
205
|
});
|
|
193
206
|
}
|
|
194
|
-
async function
|
|
207
|
+
async function generatePackage(opts) {
|
|
208
|
+
const { compiler, platform, win } = opts;
|
|
195
209
|
const spinner = (0, ora_1.default)(`正在生成资源文件...`).start();
|
|
196
210
|
await (0, delay_1.default)(1000);
|
|
197
|
-
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
211
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH, { throws: false }) || {};
|
|
198
212
|
const manifest = (0, utils_1.readManifest)();
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
213
|
+
let dest;
|
|
214
|
+
if (compiler === 'electron-vite' && win) {
|
|
215
|
+
const exeCfg = config_1.CONFIG_DATA.h5?.windows;
|
|
216
|
+
dest = (0, path_1.join)(utils_1.COMMAND_PATH, exeCfg?.path ?? 'dist', exeCfg?.name ?? `${pkg.version}.${pkg.versionCode}.exe`);
|
|
217
|
+
}
|
|
218
|
+
else if (compiler === 'gradlew') {
|
|
219
|
+
const apkCfg = config_1.CONFIG_DATA.app?.android;
|
|
220
|
+
dest = (0, path_1.join)(utils_1.COMMAND_PATH, apkCfg?.path ?? 'app/build/outputs/apk/release', apkCfg?.name ?? 'app-release.apk');
|
|
205
221
|
}
|
|
206
222
|
else {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
223
|
+
const zip = new adm_zip_1.default();
|
|
224
|
+
let zipConfig;
|
|
225
|
+
let defaultSource;
|
|
226
|
+
if (compiler === 'uni') {
|
|
227
|
+
if (platform === 'h5') {
|
|
228
|
+
zipConfig = config_1.CONFIG_DATA.h5?.zip || {};
|
|
229
|
+
defaultSource = utils_1.HAS_SRC ? 'dist/build/h5' : 'unpackage/dist/build/web';
|
|
230
|
+
}
|
|
231
|
+
else if (platform?.startsWith('app')) {
|
|
232
|
+
zipConfig = config_1.CONFIG_DATA.app?.wgt || {};
|
|
233
|
+
defaultSource = utils_1.HAS_SRC ? 'dist/build/app' : 'unpackage/dist/build/app-plus';
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else if (compiler === 'electron-vite') {
|
|
237
|
+
zipConfig = config_1.CONFIG_DATA.h5?.zip || {};
|
|
238
|
+
defaultSource = 'dist/win-unpacked/resources';
|
|
239
|
+
}
|
|
240
|
+
const ext = platform?.startsWith('app') ? '.wgt' : '.zip';
|
|
241
|
+
const name = zipConfig.name || `${manifest['appid'] || pkg.name}${ext}`;
|
|
242
|
+
const source = (0, path_1.join)(utils_1.COMMAND_PATH, zipConfig.source ?? defaultSource);
|
|
243
|
+
dest = (0, path_1.join)(utils_1.COMMAND_PATH, `${zipConfig.path ?? 'unpackage/release'}/${name}`);
|
|
244
|
+
if ((0, fs_1.existsSync)(dest)) {
|
|
245
|
+
(0, fs_1.unlinkSync)(dest);
|
|
246
|
+
}
|
|
247
|
+
const zipRoot = compiler === 'uni' && platform === 'h5' ? (pkg.appId || '') : '';
|
|
248
|
+
zip.addLocalFolder(source, zipRoot);
|
|
249
|
+
zip.writeZip(dest);
|
|
250
|
+
}
|
|
219
251
|
spinner.stop();
|
|
220
|
-
spinner.succeed(
|
|
252
|
+
spinner.succeed(`资源路径:${dest}`);
|
|
253
|
+
}
|
|
254
|
+
function downloadFile(url, dest) {
|
|
255
|
+
return new Promise((res, rej) => {
|
|
256
|
+
const mod = url.startsWith('https') ? https_1.default : http_1.default;
|
|
257
|
+
mod.get(url, (response) => {
|
|
258
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
259
|
+
downloadFile(response.headers.location, dest).then(res, rej);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const ws = require('fs').createWriteStream(dest);
|
|
263
|
+
response.pipe(ws);
|
|
264
|
+
ws.on('finish', () => { ws.close(); res(); });
|
|
265
|
+
ws.on('error', rej);
|
|
266
|
+
}).on('error', rej);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
async function fetchRemoteResources(opts) {
|
|
270
|
+
const spinner = (0, ora_1.default)('正在加载主应用数据...').start();
|
|
271
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
272
|
+
const appId = pkg.appId;
|
|
273
|
+
const result = await (0, apis_1.fetchRemoteVersionInfo)(appId);
|
|
274
|
+
const { appName, iconUrl } = result;
|
|
275
|
+
if (opts.win) {
|
|
276
|
+
// Windows
|
|
277
|
+
const zipUrl = result.resourcePackageUrl;
|
|
278
|
+
if (!zipUrl) {
|
|
279
|
+
spinner.fail(`${appName} zip链接未上传`);
|
|
280
|
+
process.exit(1);
|
|
281
|
+
}
|
|
282
|
+
const rendererDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'out', 'renderer');
|
|
283
|
+
(0, fs_extra_1.removeSync)(rendererDir);
|
|
284
|
+
(0, fs_extra_1.ensureDirSync)(rendererDir);
|
|
285
|
+
const tmpZip = (0, path_1.join)(utils_1.COMMAND_PATH, '__tmp_remote.zip');
|
|
286
|
+
await downloadFile(zipUrl, tmpZip);
|
|
287
|
+
const zip = new adm_zip_1.default(tmpZip);
|
|
288
|
+
zip.extractAllTo(rendererDir, true);
|
|
289
|
+
(0, fs_extra_1.removeSync)(tmpZip);
|
|
290
|
+
// 从目标目录读取 manifest
|
|
291
|
+
const manifest = (0, fs_extra_1.readJsonSync)((0, path_1.join)(rendererDir, appId, 'manifest.json'));
|
|
292
|
+
const { versionName, versionCode } = manifest;
|
|
293
|
+
// 替换 package.json
|
|
294
|
+
const pkgPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'package.json');
|
|
295
|
+
let pkgContent = (0, fs_1.readFileSync)(pkgPath, 'utf-8');
|
|
296
|
+
pkgContent = pkgContent.replace(/"version":\s*"[^"]*"/, `"version": "${versionName}"`);
|
|
297
|
+
pkgContent = pkgContent.replace(/"versionCode":\s*\d+/, `"versionCode": ${versionCode}`);
|
|
298
|
+
pkgContent = pkgContent.replace(/"productName":\s*"[^"]*"/, `"productName": "${appName}"`);
|
|
299
|
+
(0, fs_1.writeFileSync)(pkgPath, pkgContent);
|
|
300
|
+
// 下载图标
|
|
301
|
+
if (iconUrl) {
|
|
302
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(utils_1.COMMAND_PATH, 'res'));
|
|
303
|
+
const iconPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'res', 'icon.png');
|
|
304
|
+
await downloadFile(iconUrl, iconPath);
|
|
305
|
+
await (0, utils_1.png2ico)(iconPath, (0, path_1.join)(utils_1.COMMAND_PATH, 'res', 'icon.ico'));
|
|
306
|
+
}
|
|
307
|
+
spinner.succeed(`Windows本地资源已更新`);
|
|
308
|
+
}
|
|
309
|
+
else if (opts.compiler === 'gradlew') {
|
|
310
|
+
// Android
|
|
311
|
+
const wgtUrl = result.fullPackageUrl;
|
|
312
|
+
if (!wgtUrl) {
|
|
313
|
+
spinner.fail(`${appName} wgt链接未上传`);
|
|
314
|
+
process.exit(1);
|
|
315
|
+
}
|
|
316
|
+
const assetsDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'assets', 'apps', appId, 'www');
|
|
317
|
+
(0, fs_extra_1.removeSync)(assetsDir);
|
|
318
|
+
(0, fs_extra_1.ensureDirSync)(assetsDir);
|
|
319
|
+
const tmpWgt = (0, path_1.join)(utils_1.COMMAND_PATH, '__tmp_remote.wgt');
|
|
320
|
+
await downloadFile(wgtUrl, tmpWgt);
|
|
321
|
+
const wgtZip = new adm_zip_1.default(tmpWgt);
|
|
322
|
+
wgtZip.extractAllTo(assetsDir, true);
|
|
323
|
+
(0, fs_extra_1.removeSync)(tmpWgt);
|
|
324
|
+
// 从目标目录读取 manifest
|
|
325
|
+
const manifest = (0, fs_extra_1.readJsonSync)((0, path_1.join)(assetsDir, 'manifest.json'));
|
|
326
|
+
const { versionName, versionCode } = manifest;
|
|
327
|
+
// 替换 build.gradle
|
|
328
|
+
const gradlePath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle');
|
|
329
|
+
let gradleContent = (0, fs_1.readFileSync)(gradlePath, 'utf-8');
|
|
330
|
+
gradleContent = gradleContent.replace(/versionCode\s+\d+/, `versionCode ${versionCode}`);
|
|
331
|
+
gradleContent = gradleContent.replace(/versionName\s+"[^"]*"/, `versionName "${versionName}"`);
|
|
332
|
+
(0, fs_1.writeFileSync)(gradlePath, gradleContent);
|
|
333
|
+
// 替换 strings.xml
|
|
334
|
+
const stringsPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
|
|
335
|
+
let stringsContent = (0, fs_1.readFileSync)(stringsPath, 'utf-8');
|
|
336
|
+
stringsContent = stringsContent.replace(/<string name="app_name">[^<]*<\/string>/, `<string name="app_name">${appName}</string>`);
|
|
337
|
+
(0, fs_1.writeFileSync)(stringsPath, stringsContent);
|
|
338
|
+
// 下载图标
|
|
339
|
+
if (iconUrl) {
|
|
340
|
+
const drawableDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'drawable-xxhdpi');
|
|
341
|
+
(0, fs_extra_1.ensureDirSync)(drawableDir);
|
|
342
|
+
const iconPath = (0, path_1.join)(drawableDir, 'icon.png');
|
|
343
|
+
await downloadFile(iconUrl, iconPath);
|
|
344
|
+
(0, fs_1.copyFileSync)(iconPath, (0, path_1.join)(drawableDir, 'push.png'));
|
|
345
|
+
}
|
|
346
|
+
spinner.succeed(`Android本地资源已更新`);
|
|
347
|
+
}
|
|
221
348
|
}
|
|
222
349
|
async function default_1(...args) {
|
|
223
350
|
const opts = args[0];
|
|
351
|
+
if (opts.remote) {
|
|
352
|
+
const buildEnv = ['master', 'main'].includes(opts.branch) ? 'prod' : opts.branch || opts.env;
|
|
353
|
+
if (buildEnv)
|
|
354
|
+
process.env.BUILD_ENV = String(buildEnv);
|
|
355
|
+
await fetchRemoteResources(opts);
|
|
356
|
+
return [];
|
|
357
|
+
}
|
|
224
358
|
const commands = await getCommands(...args);
|
|
225
359
|
const command = commands.join(' ');
|
|
226
360
|
const time = Date.now();
|
|
@@ -229,7 +363,7 @@ async function default_1(...args) {
|
|
|
229
363
|
(0, fs_1.unlinkSync)(envPath);
|
|
230
364
|
}
|
|
231
365
|
if ((Date.now() - time) / 1000 <= 1) {
|
|
232
|
-
if (command.includes(
|
|
366
|
+
if (command.includes(config_1.CONFIG_DATA.cli.hbuilderx)) {
|
|
233
367
|
utils_1.log.error('检测到您的HbuilderX未启动或项目管理器中未发现构建项目,请检查后重试!');
|
|
234
368
|
}
|
|
235
369
|
}
|
|
@@ -237,9 +371,11 @@ async function default_1(...args) {
|
|
|
237
371
|
if (opts.compiler === 'uni' && opts.platform === 'h5') {
|
|
238
372
|
generateH5Manifest();
|
|
239
373
|
}
|
|
240
|
-
if ((opts.compiler === 'electron-vite' && opts.zip) ||
|
|
241
|
-
(opts.compiler === 'uni' && opts.platform === 'h5' && opts.zip)
|
|
242
|
-
|
|
374
|
+
if ((opts.compiler === 'electron-vite' && (opts.zip || opts.win)) ||
|
|
375
|
+
(opts.compiler === 'uni' && opts.platform === 'h5' && opts.zip) ||
|
|
376
|
+
(opts.compiler === 'uni' && opts.platform?.startsWith('app') && opts.wgt && !opts.pack) ||
|
|
377
|
+
opts.compiler === 'gradlew' && opts.platform === 'app') {
|
|
378
|
+
await generatePackage(opts);
|
|
243
379
|
}
|
|
244
380
|
return commands;
|
|
245
381
|
}
|
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 {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
interface HttpRequestHeader {
|
|
2
|
+
Authorization?: string;
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
type HttpRequestParams = Record<string, any>;
|
|
6
|
+
type HttpRequestData = HttpRequestParams | FormData | string;
|
|
7
|
+
interface HttpRequestConfig {
|
|
8
|
+
url?: string;
|
|
9
|
+
method?: 'POST' | 'DELETE' | 'PUT' | 'GET';
|
|
10
|
+
params?: Record<string, any>;
|
|
11
|
+
data?: HttpRequestData;
|
|
12
|
+
header?: HttpRequestHeader;
|
|
13
|
+
config?: HttpRequestConfig;
|
|
14
|
+
}
|
|
15
|
+
type ResponseData<T = any> = {
|
|
16
|
+
code?: number;
|
|
17
|
+
data?: T;
|
|
18
|
+
msg?: string;
|
|
19
|
+
};
|
|
20
|
+
declare class Http {
|
|
21
|
+
private _header;
|
|
22
|
+
get options(): {
|
|
23
|
+
baseUrl: any;
|
|
24
|
+
header: Record<string, any>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 发送请求
|
|
28
|
+
*/
|
|
29
|
+
request(config: HttpRequestConfig): Promise<ResponseData>;
|
|
30
|
+
/**
|
|
31
|
+
* 发送POST请求
|
|
32
|
+
*/
|
|
33
|
+
post(url: string, data?: HttpRequestData, config?: HttpRequestConfig): Promise<ResponseData<any>>;
|
|
34
|
+
/**
|
|
35
|
+
* 发送DELETE请求
|
|
36
|
+
*/
|
|
37
|
+
delete(url: string, params?: HttpRequestParams, config?: HttpRequestConfig): Promise<ResponseData<any>>;
|
|
38
|
+
/**
|
|
39
|
+
* 发送PUT请求
|
|
40
|
+
*/
|
|
41
|
+
put(url: string, data?: HttpRequestData, config?: HttpRequestConfig): Promise<ResponseData<any>>;
|
|
42
|
+
/**
|
|
43
|
+
* 发送GET请求
|
|
44
|
+
*/
|
|
45
|
+
get(url: string, params?: HttpRequestParams, config?: HttpRequestConfig): Promise<ResponseData<any>>;
|
|
46
|
+
}
|
|
47
|
+
export declare function setToken(token?: string): void;
|
|
48
|
+
export declare const http: Http;
|
|
49
|
+
export {};
|