@gmcb/cli 0.7.8 → 0.7.9
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 +8 -0
- package/lib/actions/build.js +95 -60
- package/lib/actions/copy.js +1 -1
- package/lib/actions/publish.js +31 -26
- package/lib/apis/index.d.ts +12 -4
- package/lib/apis/index.js +13 -17
- package/lib/bin.js +1 -1
- package/lib/commands/option.d.ts +2 -2
- package/lib/commands/option.js +2 -2
- package/lib/scripts/app-apk.js +1 -3
- package/lib/scripts/app-wgt.js +1 -3
- package/lib/scripts/asar-zip.js +1 -3
- package/lib/scripts/h5-exe.js +1 -3
- package/lib/scripts/h5-zip.js +1 -3
- package/lib/scripts/publish.d.ts +6 -3
- package/lib/scripts/publish.js +5 -6
- package/lib/scripts/wgt-apk.d.ts +1 -0
- package/lib/scripts/wgt-apk.js +27 -0
- package/lib/scripts/wgt-zip.js +4 -3
- package/lib/scripts/zip-exe.d.ts +1 -0
- package/lib/scripts/zip-exe.js +24 -0
- package/lib/utils/config.d.ts +5 -1
- package/package.json +1 -1
- package/schema.json +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.7.9](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.7...@gmcb/cli@0.7.9) (2026-07-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [0.7.8](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.7...@gmcb/cli@0.7.8) (2026-07-09)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @gmcb/cli
|
package/lib/actions/build.js
CHANGED
|
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.getCommands = getCommands;
|
|
30
30
|
exports.default = default_1;
|
|
31
31
|
const fs_1 = require("fs");
|
|
32
|
+
const child_process_1 = require("child_process");
|
|
32
33
|
const path_1 = require("path");
|
|
33
34
|
const https_1 = __importDefault(require("https"));
|
|
34
35
|
const http_1 = __importDefault(require("http"));
|
|
@@ -268,37 +269,74 @@ function downloadFile(url, dest) {
|
|
|
268
269
|
});
|
|
269
270
|
}
|
|
270
271
|
async function fetchRemoteResources(opts) {
|
|
271
|
-
const spinner = (0, ora_1.default)(
|
|
272
|
+
const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
|
|
272
273
|
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (!config_1.CONFIG_DATA.publish) {
|
|
277
|
-
config_1.CONFIG_DATA.publish = {};
|
|
274
|
+
// 校验 version 和 versionCode 必须存在
|
|
275
|
+
if (!pkg.version) {
|
|
276
|
+
throw new Error('package.json 缺少 version 字段');
|
|
278
277
|
}
|
|
279
|
-
if (
|
|
280
|
-
|
|
278
|
+
if (!pkg.versionCode) {
|
|
279
|
+
throw new Error('package.json 缺少 versionCode 字段');
|
|
281
280
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
281
|
+
const appId = pkg.appId;
|
|
282
|
+
// 1. 获取应用信息
|
|
283
|
+
const appInfo = await (0, apis_1.getAppInfo)(appId);
|
|
284
|
+
const { appName, iconUrl, configJson } = appInfo;
|
|
285
|
+
// 2. 确定仓库地址
|
|
286
|
+
const repoUrl = configJson.repo || config_1.CONFIG_DATA.render?.repo;
|
|
287
|
+
// 3. 确定分支:使用 buildEnv,默认 master;prod 对应 master 分支
|
|
288
|
+
const buildEnv = process.env.BUILD_ENV || 'master';
|
|
289
|
+
const branch = buildEnv === 'prod' ? 'master' : buildEnv;
|
|
290
|
+
// 4. 拉取代码到 COMMAND_PATH/.repo/{appId}
|
|
291
|
+
const repoDir = (0, path_1.join)(utils_1.COMMAND_PATH, '.repo', appId);
|
|
292
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(repoDir, '.git'))) {
|
|
293
|
+
// 已有目录:fetch + 强制切换分支 + pull
|
|
294
|
+
const repoGit = (0, simple_git_1.default)(repoDir);
|
|
295
|
+
await repoGit.fetch('origin');
|
|
296
|
+
const remoteBranches = await repoGit.branch(['-r']);
|
|
297
|
+
if (!remoteBranches.all.includes(`origin/${branch}`)) {
|
|
298
|
+
throw new Error(`远程分支 origin/${branch} 不存在,请检查仓库 ${repoUrl}`);
|
|
299
|
+
}
|
|
300
|
+
await repoGit.checkout(branch, ['-f']);
|
|
301
|
+
await repoGit.pull('origin', branch);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
// 新克隆:直接使用 branch 分支,失败则抛出异常
|
|
305
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(utils_1.COMMAND_PATH, '.repo'));
|
|
306
|
+
const cloneGit = (0, simple_git_1.default)();
|
|
307
|
+
try {
|
|
308
|
+
await cloneGit.clone(repoUrl, repoDir, ['--branch', branch, '--single-branch']);
|
|
309
|
+
}
|
|
310
|
+
catch (err) {
|
|
311
|
+
throw new Error(`远程仓库或分支 ${branch} 不存在:${repoUrl}`);
|
|
288
312
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
313
|
+
}
|
|
314
|
+
spinner.stop();
|
|
315
|
+
// 5. 修改仓库 src/manifest.json 的 versionName 和 versionCode
|
|
316
|
+
const manifestPath = (0, path_1.join)(repoDir, 'src', 'manifest.json');
|
|
317
|
+
let manifestContent = (0, fs_1.readFileSync)(manifestPath, 'utf-8');
|
|
318
|
+
manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name" : "${appName}"`);
|
|
319
|
+
manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName" : "${pkg.version}"`);
|
|
320
|
+
manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode" : ${pkg.versionCode}`);
|
|
321
|
+
(0, fs_1.writeFileSync)(manifestPath, manifestContent);
|
|
322
|
+
// 6. 修改仓库 package.json scripts
|
|
323
|
+
const repoPkgPath = (0, path_1.join)(repoDir, 'package.json');
|
|
324
|
+
const repoPkg = (0, fs_extra_1.readJsonSync)(repoPkgPath);
|
|
325
|
+
if (!repoPkg.scripts)
|
|
326
|
+
repoPkg.scripts = {};
|
|
327
|
+
repoPkg.scripts['copy:h5'] = 'gmcb copy -s ./dist/build/h5 -d ../../out/renderer/{package.appId}/ --clean';
|
|
328
|
+
repoPkg.scripts['copy:app'] = 'gmcb copy -s ./dist/build/app -d ../../app/src/main/assets/apps/{manifest.appid}/www/ --clean';
|
|
329
|
+
(0, fs_extra_1.writeJsonSync)(repoPkgPath, repoPkg, { spaces: 2 });
|
|
330
|
+
// 7. 执行 npm install
|
|
331
|
+
(0, child_process_1.execSync)('npm install', { cwd: repoDir, stdio: 'inherit' });
|
|
332
|
+
// 8. 构建 + 拷贝 + 修改主项目配置(根据 compiler 类型)
|
|
333
|
+
if (opts.compiler === 'electron-vite') {
|
|
334
|
+
// 构建 H5 并拷贝
|
|
335
|
+
(0, child_process_1.execSync)(`npm run build:h5:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
|
|
336
|
+
(0, child_process_1.execSync)('npm run copy:h5', { cwd: repoDir, stdio: 'inherit' });
|
|
337
|
+
// 修改主项目 package.json 中的应用名称
|
|
298
338
|
const pkgPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'package.json');
|
|
299
339
|
let pkgContent = (0, fs_1.readFileSync)(pkgPath, 'utf-8');
|
|
300
|
-
pkgContent = pkgContent.replace(/"version":\s*"[^"]*"/, `"version": "${versionName}"`);
|
|
301
|
-
pkgContent = pkgContent.replace(/"versionCode":\s*\d+/, `"versionCode": ${versionNum}`);
|
|
302
340
|
pkgContent = pkgContent.replace(/"productName":\s*"[^"]*"/, `"productName": "${appName}"`);
|
|
303
341
|
(0, fs_1.writeFileSync)(pkgPath, pkgContent);
|
|
304
342
|
// 下载图标
|
|
@@ -308,44 +346,22 @@ async function fetchRemoteResources(opts) {
|
|
|
308
346
|
await downloadFile(iconUrl, iconPath);
|
|
309
347
|
await (0, utils_1.png2ico)(iconPath, (0, path_1.join)(utils_1.COMMAND_PATH, 'res', 'icon.ico'));
|
|
310
348
|
}
|
|
311
|
-
config_1.CONFIG_DATA.publish['_remoteResourceUrl'] = zipUrl;
|
|
312
|
-
spinner.succeed(`Windows本地资源已更新`);
|
|
313
349
|
}
|
|
314
|
-
|
|
315
|
-
//
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
process.exit(1);
|
|
320
|
-
}
|
|
321
|
-
const appDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'assets', 'apps');
|
|
322
|
-
const tempDir = (0, path_1.join)(appDir, appId);
|
|
323
|
-
(0, fs_extra_1.removeSync)(tempDir);
|
|
324
|
-
(0, fs_extra_1.ensureDirSync)(tempDir);
|
|
325
|
-
const tmpWgt = (0, path_1.join)(utils_1.COMMAND_PATH, '__tmp_remote.wgt');
|
|
326
|
-
await downloadFile(wgtUrl, tmpWgt);
|
|
327
|
-
const wgtZip = new adm_zip_1.default(tmpWgt);
|
|
328
|
-
wgtZip.extractAllTo(tempDir, true);
|
|
329
|
-
(0, fs_extra_1.removeSync)(tmpWgt);
|
|
330
|
-
// 从目标目录读取 manifest
|
|
331
|
-
const manifest = (0, fs_extra_1.readJsonSync)((0, path_1.join)(tempDir, 'manifest.json'));
|
|
332
|
-
const { id } = manifest;
|
|
333
|
-
const assetsDir = (0, path_1.join)(appDir, id, 'www');
|
|
334
|
-
// 将解压内容复制到 assetsDir,然后删除临时目录
|
|
335
|
-
(0, fs_extra_1.ensureDirSync)(assetsDir);
|
|
336
|
-
(0, fs_extra_1.copySync)(tempDir, assetsDir, { overwrite: true });
|
|
337
|
-
(0, fs_extra_1.removeSync)(tempDir);
|
|
338
|
-
// 替换 build.gradle
|
|
339
|
-
const gradlePath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle');
|
|
340
|
-
let gradleContent = (0, fs_1.readFileSync)(gradlePath, 'utf-8');
|
|
341
|
-
gradleContent = gradleContent.replace(/versionName\s+"[^"]*"/, `versionName "${versionName}"`);
|
|
342
|
-
gradleContent = gradleContent.replace(/versionCode\s+\d+/, `versionCode ${versionNum}`);
|
|
343
|
-
(0, fs_1.writeFileSync)(gradlePath, gradleContent);
|
|
344
|
-
// 替换 strings.xml
|
|
350
|
+
if (opts.compiler === 'gradlew') {
|
|
351
|
+
// 构建 App 并拷贝
|
|
352
|
+
(0, child_process_1.execSync)(`npm run build:app:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
|
|
353
|
+
(0, child_process_1.execSync)('npm run copy:app', { cwd: repoDir, stdio: 'inherit' });
|
|
354
|
+
// 修改主项目 strings.xml 中的应用名称
|
|
345
355
|
const stringsPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
|
|
346
356
|
let stringsContent = (0, fs_1.readFileSync)(stringsPath, 'utf-8');
|
|
347
357
|
stringsContent = stringsContent.replace(/<string name="app_name">[^<]*<\/string>/, `<string name="app_name">${appName}</string>`);
|
|
348
358
|
(0, fs_1.writeFileSync)(stringsPath, stringsContent);
|
|
359
|
+
// 修改主项目 build.gradle(versionName/versionCode 取 COMMAND_PATH/package.json 对应值)
|
|
360
|
+
const gradlePath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle');
|
|
361
|
+
let gradleContent = (0, fs_1.readFileSync)(gradlePath, 'utf-8');
|
|
362
|
+
gradleContent = gradleContent.replace(/versionName\s+"[^"]*"/, `versionName "${pkg.version}"`);
|
|
363
|
+
gradleContent = gradleContent.replace(/versionCode\s+\d+/, `versionCode ${pkg.versionCode}`);
|
|
364
|
+
(0, fs_1.writeFileSync)(gradlePath, gradleContent);
|
|
349
365
|
// 下载图标
|
|
350
366
|
if (iconUrl) {
|
|
351
367
|
const drawableDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'drawable-xxhdpi');
|
|
@@ -354,8 +370,27 @@ async function fetchRemoteResources(opts) {
|
|
|
354
370
|
await downloadFile(iconUrl, iconPath);
|
|
355
371
|
(0, fs_1.copyFileSync)(iconPath, (0, path_1.join)(drawableDir, 'push.png'));
|
|
356
372
|
}
|
|
357
|
-
|
|
358
|
-
|
|
373
|
+
}
|
|
374
|
+
// 9. updateMode=2 时打包资源为 zip/wgt
|
|
375
|
+
if (config_1.CONFIG_DATA.publish?.updateMode == 2) {
|
|
376
|
+
const repoManifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)((0, path_1.join)(repoDir, 'src', 'manifest.json'), 'utf-8')));
|
|
377
|
+
const releaseDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'unpackage', 'release');
|
|
378
|
+
(0, fs_extra_1.ensureDirSync)(releaseDir);
|
|
379
|
+
if (opts.compiler === 'electron-vite') {
|
|
380
|
+
const h5Dir = (0, path_1.join)(repoDir, 'dist', 'build', 'h5');
|
|
381
|
+
(0, fs_extra_1.writeJsonSync)((0, path_1.join)(h5Dir, 'manifest.json'), {
|
|
382
|
+
versionName: pkg.version,
|
|
383
|
+
versionCode: pkg.versionCode,
|
|
384
|
+
});
|
|
385
|
+
const zip = new adm_zip_1.default();
|
|
386
|
+
zip.addLocalFolder(h5Dir, appId);
|
|
387
|
+
zip.writeZip((0, path_1.join)(releaseDir, `${repoManifest.appid}.zip`));
|
|
388
|
+
}
|
|
389
|
+
else if (opts.compiler === 'gradlew') {
|
|
390
|
+
const zip = new adm_zip_1.default();
|
|
391
|
+
zip.addLocalFolder((0, path_1.join)(repoDir, 'dist', 'build', 'app'));
|
|
392
|
+
zip.writeZip((0, path_1.join)(releaseDir, `${repoManifest.appid}.wgt`));
|
|
393
|
+
}
|
|
359
394
|
}
|
|
360
395
|
}
|
|
361
396
|
async function default_1(...args) {
|
package/lib/actions/copy.js
CHANGED
|
@@ -47,7 +47,7 @@ async function default_1(...args) {
|
|
|
47
47
|
if (opts.ignore) {
|
|
48
48
|
ignore = opts.ignore.toLowerCase().split(',');
|
|
49
49
|
}
|
|
50
|
-
const spinner = (0, ora_1.default)('
|
|
50
|
+
const spinner = (0, ora_1.default)('正在复制资源...').start();
|
|
51
51
|
await (0, delay_1.default)(1000);
|
|
52
52
|
(0, fs_1.readdirSync)(sourcePath).forEach((file) => {
|
|
53
53
|
if (!file.startsWith('.') &&
|
package/lib/actions/publish.js
CHANGED
|
@@ -11,7 +11,7 @@ const config_1 = require("../utils/config");
|
|
|
11
11
|
async function default_1(...args) {
|
|
12
12
|
const opts = args[0];
|
|
13
13
|
const isPublishFlow = !!config_1.CONFIG_DATA.publish;
|
|
14
|
-
const isAuto = opts.
|
|
14
|
+
const isAuto = opts.skip || !!config_1.CONFIG_DATA.skip;
|
|
15
15
|
const pub = { platform: 0, status: 0, updateType: 0, updateMode: 0 };
|
|
16
16
|
let install = true;
|
|
17
17
|
if (!isAuto) {
|
|
@@ -158,34 +158,12 @@ async function default_1(...args) {
|
|
|
158
158
|
if (install) {
|
|
159
159
|
(0, utils_1.spawnSync)(config_1.CONFIG_DATA.install || 'npm install');
|
|
160
160
|
}
|
|
161
|
-
|
|
162
|
-
if (opts.compiler === 'uni' && opts.wgt && opts.zip) {
|
|
163
|
-
const originalPlatform = opts.platform;
|
|
164
|
-
// 先构建 app(生成 wgt)
|
|
165
|
-
opts.platform = 'app';
|
|
166
|
-
cmds = await (0, build_1.default)(...args);
|
|
167
|
-
// 再构建 h5(生成 zip)
|
|
168
|
-
opts.platform = 'h5';
|
|
169
|
-
await (0, build_1.default)(...args);
|
|
170
|
-
// 恢复
|
|
171
|
-
opts.platform = originalPlatform;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
cmds = await (0, build_1.default)(...args);
|
|
175
|
-
}
|
|
176
|
-
// 从 cmds 提取 buildEnv
|
|
177
|
-
const buildEnv = cmds[2]?.split('=')[1];
|
|
178
|
-
if (!buildEnv || !['dev', 'sit', 'uat', 'pre', 'prod'].includes(buildEnv)) {
|
|
179
|
-
utils_1.log.error('没有检测到需要发布的环境,无法完成上传,请切换到dev/sit/uat/pre/master分支再次执行脚本,或者您可以选择手动上传!');
|
|
180
|
-
}
|
|
181
|
-
// 更新 CONFIG_DATA(动态 require 前,确保脚本模块能读取到正确值)
|
|
182
|
-
process.env.BUILD_ENV = buildEnv;
|
|
161
|
+
// 更新 CONFIG_DATA(build 之前,确保 fetchRemoteResources 能读取到)
|
|
183
162
|
if (isPublishFlow) {
|
|
184
163
|
if (!config_1.CONFIG_DATA.publish) {
|
|
185
164
|
config_1.CONFIG_DATA.publish = {};
|
|
186
165
|
}
|
|
187
166
|
if (opts.wgt && opts.zip) {
|
|
188
|
-
// 2个都传则为发布主应用
|
|
189
167
|
config_1.CONFIG_DATA.publish.publishType = 2;
|
|
190
168
|
}
|
|
191
169
|
if (pub.platform) {
|
|
@@ -209,8 +187,32 @@ async function default_1(...args) {
|
|
|
209
187
|
config_1.CONFIG_DATA.pub.status = pub.status;
|
|
210
188
|
}
|
|
211
189
|
}
|
|
190
|
+
let cmds;
|
|
191
|
+
if (opts.compiler === 'uni' && opts.wgt && opts.zip) {
|
|
192
|
+
const originalPlatform = opts.platform;
|
|
193
|
+
// 先构建 app(生成 wgt)
|
|
194
|
+
opts.platform = 'app';
|
|
195
|
+
cmds = await (0, build_1.default)(...args);
|
|
196
|
+
// 再构建 h5(生成 zip)
|
|
197
|
+
opts.platform = 'h5';
|
|
198
|
+
await (0, build_1.default)(...args);
|
|
199
|
+
// 恢复
|
|
200
|
+
opts.platform = originalPlatform;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
cmds = await (0, build_1.default)(...args);
|
|
204
|
+
}
|
|
205
|
+
// 从 cmds 提取 buildEnv
|
|
206
|
+
const buildEnv = cmds[2]?.split('=')[1];
|
|
207
|
+
if (!buildEnv || !['dev', 'sit', 'uat', 'pre', 'prod'].includes(buildEnv)) {
|
|
208
|
+
utils_1.log.error('没有检测到需要发布的环境,无法完成上传,请切换到dev/sit/uat/pre/master分支再次执行脚本,或者您可以选择手动上传!');
|
|
209
|
+
}
|
|
210
|
+
const isHotUpdate = opts.remote && config_1.CONFIG_DATA.publish?.updateMode == 2;
|
|
212
211
|
if (opts.compiler === 'electron-vite') {
|
|
213
|
-
if (
|
|
212
|
+
if (isHotUpdate) {
|
|
213
|
+
await require('../scripts/zip-exe').default();
|
|
214
|
+
}
|
|
215
|
+
else if (opts.zip) {
|
|
214
216
|
await require('../scripts/asar-zip').default();
|
|
215
217
|
}
|
|
216
218
|
else if (opts.win) {
|
|
@@ -218,7 +220,10 @@ async function default_1(...args) {
|
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
else if (opts.compiler === 'gradlew') {
|
|
221
|
-
if (
|
|
223
|
+
if (isHotUpdate) {
|
|
224
|
+
await require('../scripts/wgt-apk').default();
|
|
225
|
+
}
|
|
226
|
+
else if (opts.apk) {
|
|
222
227
|
await require('../scripts/app-apk').default();
|
|
223
228
|
}
|
|
224
229
|
}
|
package/lib/apis/index.d.ts
CHANGED
|
@@ -68,9 +68,13 @@ export declare function getVersionPage(params: {
|
|
|
68
68
|
msg?: string;
|
|
69
69
|
}>;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* 查询应用分页列表
|
|
72
72
|
*/
|
|
73
|
-
export declare function
|
|
73
|
+
export declare function getAppPage(params: {
|
|
74
|
+
appId: string;
|
|
75
|
+
pageNo?: number;
|
|
76
|
+
pageSize?: number;
|
|
77
|
+
}): Promise<{
|
|
74
78
|
code?: number;
|
|
75
79
|
data?: any;
|
|
76
80
|
msg?: string;
|
|
@@ -112,6 +116,10 @@ export declare function uploadVersion(params: VersionParams): Promise<void>;
|
|
|
112
116
|
*/
|
|
113
117
|
export declare function publishVersion(params: VersionParams): Promise<void>;
|
|
114
118
|
/**
|
|
115
|
-
*
|
|
119
|
+
* 获取应用信息(自动登录)
|
|
116
120
|
*/
|
|
117
|
-
export declare function
|
|
121
|
+
export declare function getAppInfo(appId: string): Promise<{
|
|
122
|
+
appName: any;
|
|
123
|
+
iconUrl: any;
|
|
124
|
+
configJson: Record<string, any>;
|
|
125
|
+
}>;
|
package/lib/apis/index.js
CHANGED
|
@@ -8,11 +8,11 @@ exports.saveVersion = saveVersion;
|
|
|
8
8
|
exports.createVersion = createVersion;
|
|
9
9
|
exports.postVersion = postVersion;
|
|
10
10
|
exports.getVersionPage = getVersionPage;
|
|
11
|
-
exports.
|
|
11
|
+
exports.getAppPage = getAppPage;
|
|
12
12
|
exports.getVersionHistory = getVersionHistory;
|
|
13
13
|
exports.uploadVersion = uploadVersion;
|
|
14
14
|
exports.publishVersion = publishVersion;
|
|
15
|
-
exports.
|
|
15
|
+
exports.getAppInfo = getAppInfo;
|
|
16
16
|
const http_1 = require("./http");
|
|
17
17
|
const const_1 = require("../utils/const");
|
|
18
18
|
const config_1 = require("../utils/config");
|
|
@@ -65,10 +65,10 @@ function getVersionPage(params) {
|
|
|
65
65
|
return http_1.http.get('/admin-api/system/app-mofang/version/page', params);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* 查询应用分页列表
|
|
69
69
|
*/
|
|
70
|
-
function
|
|
71
|
-
return http_1.http.get('/admin-api/system/app-mofang/app/
|
|
70
|
+
function getAppPage(params) {
|
|
71
|
+
return http_1.http.get('/admin-api/system/app-mofang/app/page', params);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* 查询版本历史
|
|
@@ -221,9 +221,6 @@ async function publishVersion(params) {
|
|
|
221
221
|
let fallbackFullUrl = existingVersion?.fullPackageUrl || latest?.fullPackageUrl || '';
|
|
222
222
|
let fallbackResUrl = existingVersion?.resourcePackageUrl || latest?.resourcePackageUrl || '';
|
|
223
223
|
if (publishType == 1 && fullUrl) {
|
|
224
|
-
const isHotUpdate = updateMode == 2;
|
|
225
|
-
const hotResUrl = isHotUpdate ? (config_1.CONFIG_DATA.publish['_remoteResourceUrl'] || '') : '';
|
|
226
|
-
resUrl = hotResUrl;
|
|
227
224
|
fallbackFullUrl = '';
|
|
228
225
|
fallbackResUrl = '';
|
|
229
226
|
}
|
|
@@ -239,27 +236,26 @@ async function publishVersion(params) {
|
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
/**
|
|
242
|
-
*
|
|
239
|
+
* 获取应用信息(自动登录)
|
|
243
240
|
*/
|
|
244
|
-
async function
|
|
241
|
+
async function getAppInfo(appId) {
|
|
245
242
|
try {
|
|
246
243
|
const web = config_1.CONFIG_DATA.web;
|
|
247
244
|
const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
|
|
248
245
|
const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
|
|
249
246
|
(0, http_1.setToken)(accessToken);
|
|
250
|
-
const { data: pageData } = await
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
247
|
+
const { data: pageData } = await getAppPage({ appId, pageNo: 1, pageSize: 10 });
|
|
248
|
+
const appData = pageData?.list?.[0];
|
|
249
|
+
if (!appData)
|
|
253
250
|
throw new Error(`未查询到 ${appId} 应用数据`);
|
|
254
|
-
const { data: appDetail } = await getAppDetail(version.appMofangId);
|
|
255
251
|
let configJson = {};
|
|
256
252
|
try {
|
|
257
|
-
configJson = JSON.parse(
|
|
253
|
+
configJson = JSON.parse(appData?.configJson || '{}');
|
|
258
254
|
}
|
|
259
255
|
catch { }
|
|
260
256
|
return {
|
|
261
|
-
|
|
262
|
-
iconUrl:
|
|
257
|
+
appName: appData.name,
|
|
258
|
+
iconUrl: appData.iconUrl,
|
|
263
259
|
configJson,
|
|
264
260
|
};
|
|
265
261
|
}
|
package/lib/bin.js
CHANGED
package/lib/commands/option.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare const pack: readonly ["--pack", "是否使用hbuilderx构建应
|
|
|
22
22
|
export declare const wgt: readonly ["--wgt", "是否构建移动应用热更新资源"];
|
|
23
23
|
export declare const res: readonly ["--res", "是否构建移动应用本地资源"];
|
|
24
24
|
export declare const apk: readonly ["--apk", "是否构建Android应用"];
|
|
25
|
-
export declare const
|
|
25
|
+
export declare const skip: readonly ["--skip", "跳过所有确认,自动发布"];
|
|
26
26
|
export declare const remote: readonly ["--remote", "是否从远程拉取资源构建"];
|
|
27
27
|
export declare const hbuilderxCli: readonly ["--cli.hbuilderx <cli-path>", "HbuilderX Cli路径"];
|
|
28
28
|
export declare const weixinCli: readonly ["--cli.weixin <cli-path>", "微信开发者工具 Cli路径"];
|
|
@@ -42,7 +42,7 @@ export interface Options {
|
|
|
42
42
|
custom?: boolean;
|
|
43
43
|
pack?: boolean;
|
|
44
44
|
res?: boolean;
|
|
45
|
-
|
|
45
|
+
skip?: boolean;
|
|
46
46
|
ignore?: string;
|
|
47
47
|
clean: boolean;
|
|
48
48
|
source?: string;
|
package/lib/commands/option.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.templateRepo = exports.skillRepo = exports.cosSecretkey = exports.cosSecretid = exports.alipayCli = exports.weixinCli = exports.hbuilderxCli = exports.remote = exports.
|
|
3
|
+
exports.templateRepo = exports.skillRepo = exports.cosSecretkey = exports.cosSecretid = exports.alipayCli = exports.weixinCli = exports.hbuilderxCli = exports.remote = exports.skip = exports.apk = exports.res = exports.wgt = exports.pack = exports.custom = exports.zip = exports.linux = exports.mac = exports.win = exports.link = exports.path = exports.name = exports.clean = exports.ignore = exports.dest = exports.source = exports.branch = exports.env = exports.compiler = exports.project = exports.platform = exports.template = exports.version = void 0;
|
|
4
4
|
exports.version = ['-v, --version', '输出版本号'];
|
|
5
5
|
exports.template = ['-t, --template <template-name>', '模版仓库名称'];
|
|
6
6
|
exports.platform = ['-p, --platform <platform-name>', '编译平台,默认h5', 'h5'];
|
|
@@ -24,7 +24,7 @@ exports.pack = ['--pack', '是否使用hbuilderx构建应用'];
|
|
|
24
24
|
exports.wgt = ['--wgt', '是否构建移动应用热更新资源'];
|
|
25
25
|
exports.res = ['--res', '是否构建移动应用本地资源'];
|
|
26
26
|
exports.apk = ['--apk', '是否构建Android应用'];
|
|
27
|
-
exports.
|
|
27
|
+
exports.skip = ['--skip', '跳过所有确认,自动发布'];
|
|
28
28
|
exports.remote = ['--remote', '是否从远程拉取资源构建'];
|
|
29
29
|
exports.hbuilderxCli = ['--cli.hbuilderx <cli-path>', 'HbuilderX Cli路径'];
|
|
30
30
|
exports.weixinCli = ['--cli.weixin <cli-path>', '微信开发者工具 Cli路径'];
|
package/lib/scripts/app-apk.js
CHANGED
|
@@ -10,9 +10,7 @@ async function default_1() {
|
|
|
10
10
|
const versionName = gradleContent.match(/versionName\s+"([^"]*)"/)?.[1];
|
|
11
11
|
const versionCode = gradleContent.match(/versionCode\s+(\d+)/)?.[1];
|
|
12
12
|
await (0, publish_1.publish)({
|
|
13
|
-
ext: 'apk',
|
|
14
|
-
name: 'app-release',
|
|
15
|
-
path: 'app/build/outputs/apk/release',
|
|
13
|
+
files: [{ ext: 'apk', name: 'app-release', path: 'app/build/outputs/apk/release' }],
|
|
16
14
|
versionName,
|
|
17
15
|
versionCode: versionCode ? Number(versionCode) : undefined,
|
|
18
16
|
});
|
package/lib/scripts/app-wgt.js
CHANGED
|
@@ -6,9 +6,7 @@ const publish_1 = require("./publish");
|
|
|
6
6
|
async function default_1() {
|
|
7
7
|
const manifest = (0, utils_1.readManifest)();
|
|
8
8
|
await (0, publish_1.publish)({
|
|
9
|
-
ext: 'wgt',
|
|
10
|
-
name: manifest['appid'],
|
|
11
|
-
path: 'unpackage/release',
|
|
9
|
+
files: [{ ext: 'wgt', name: manifest['appid'], path: 'unpackage/release' }],
|
|
12
10
|
versionName: manifest['versionName'],
|
|
13
11
|
versionCode: manifest['versionCode'],
|
|
14
12
|
});
|
package/lib/scripts/asar-zip.js
CHANGED
|
@@ -8,9 +8,7 @@ const publish_1 = require("./publish");
|
|
|
8
8
|
async function default_1() {
|
|
9
9
|
const pkg = (0, fs_extra_1.readJsonSync)((0, path_1.join)(const_1.COMMAND_PATH, 'package.json'));
|
|
10
10
|
await (0, publish_1.publish)({
|
|
11
|
-
ext: 'zip',
|
|
12
|
-
name: pkg['name'],
|
|
13
|
-
path: 'unpackage/release',
|
|
11
|
+
files: [{ ext: 'zip', name: pkg['name'], path: 'unpackage/release' }],
|
|
14
12
|
versionName: pkg['version'],
|
|
15
13
|
versionCode: pkg['versionCode'],
|
|
16
14
|
});
|
package/lib/scripts/h5-exe.js
CHANGED
|
@@ -8,9 +8,7 @@ const publish_1 = require("./publish");
|
|
|
8
8
|
async function default_1() {
|
|
9
9
|
const pkg = (0, fs_extra_1.readJsonSync)((0, path_1.join)(const_1.COMMAND_PATH, 'package.json'));
|
|
10
10
|
await (0, publish_1.publish)({
|
|
11
|
-
ext: 'exe',
|
|
12
|
-
name: 'app-release',
|
|
13
|
-
path: 'dist',
|
|
11
|
+
files: [{ ext: 'exe', name: 'app-release', path: 'dist' }],
|
|
14
12
|
versionName: pkg['version'],
|
|
15
13
|
versionCode: pkg['versionCode'],
|
|
16
14
|
});
|
package/lib/scripts/h5-zip.js
CHANGED
|
@@ -6,9 +6,7 @@ const publish_1 = require("./publish");
|
|
|
6
6
|
async function default_1() {
|
|
7
7
|
const manifest = (0, utils_1.readManifest)();
|
|
8
8
|
await (0, publish_1.publish)({
|
|
9
|
-
ext: 'zip',
|
|
10
|
-
name: manifest['appid'],
|
|
11
|
-
path: 'unpackage/release',
|
|
9
|
+
files: [{ ext: 'zip', name: manifest['appid'], path: 'unpackage/release' }],
|
|
12
10
|
versionName: manifest['versionName'],
|
|
13
11
|
versionCode: manifest['versionCode'],
|
|
14
12
|
});
|
package/lib/scripts/publish.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export type PublishExt = 'wgt' | 'zip' | 'wgt-zip' | 'exe' | 'apk';
|
|
2
|
+
export interface PublishFile {
|
|
3
|
+
ext: PublishExt;
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
2
7
|
export interface PublishOptions {
|
|
3
|
-
|
|
4
|
-
name?: string;
|
|
5
|
-
path?: string;
|
|
8
|
+
files: PublishFile[];
|
|
6
9
|
versionName?: string;
|
|
7
10
|
versionCode?: string | number;
|
|
8
11
|
}
|
package/lib/scripts/publish.js
CHANGED
|
@@ -21,7 +21,6 @@ const PUBLISH_APP_CFG = {
|
|
|
21
21
|
apk: config_1.CONFIG_DATA.app?.android,
|
|
22
22
|
};
|
|
23
23
|
async function publish(options) {
|
|
24
|
-
const exts = Array.isArray(options.ext) ? options.ext : [options.ext];
|
|
25
24
|
const buildEnv = process.env.BUILD_ENV || '';
|
|
26
25
|
const pkg = (0, fs_extra_1.readJsonSync)(const_1.PACKAGE_PATH, { throws: false }) || {};
|
|
27
26
|
const versionName = options.versionName;
|
|
@@ -36,11 +35,11 @@ async function publish(options) {
|
|
|
36
35
|
SecretKey: secretKey,
|
|
37
36
|
});
|
|
38
37
|
const remoteUrls = [];
|
|
39
|
-
for (const
|
|
40
|
-
const appCfg = PUBLISH_APP_CFG[ext];
|
|
41
|
-
const fileName = appCfg?.name ?? `${
|
|
42
|
-
const filePath = (0, path_1.join)(const_1.COMMAND_PATH, appCfg?.path ??
|
|
43
|
-
const destName = `${versionName}.${versionCode}.${ext}`;
|
|
38
|
+
for (const file of options.files) {
|
|
39
|
+
const appCfg = PUBLISH_APP_CFG[file.ext];
|
|
40
|
+
const fileName = appCfg?.name ?? `${file.name}.${file.ext}`;
|
|
41
|
+
const filePath = (0, path_1.join)(const_1.COMMAND_PATH, appCfg?.path ?? file.path);
|
|
42
|
+
const destName = `${versionName}.${versionCode}.${file.ext}`;
|
|
44
43
|
const path = `${remotePath}/${destName}`;
|
|
45
44
|
const remoteUrl = `https://${bucket}.cos.${region}.myqcloud.com${`/${path}`.replace(/\/+/g, '/')}`;
|
|
46
45
|
await new Promise((res) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = default_1;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const fs_extra_1 = require("fs-extra");
|
|
10
|
+
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
11
|
+
const const_1 = require("../utils/const");
|
|
12
|
+
const publish_1 = require("./publish");
|
|
13
|
+
async function default_1() {
|
|
14
|
+
const pkg = (0, fs_extra_1.readJsonSync)(const_1.PACKAGE_PATH);
|
|
15
|
+
const repoManifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)((0, path_1.join)(const_1.COMMAND_PATH, '.repo', pkg.appId, 'src', 'manifest.json'), 'utf-8')));
|
|
16
|
+
const gradleContent = (0, fs_1.readFileSync)((0, path_1.join)(const_1.COMMAND_PATH, 'app', 'build.gradle'), 'utf-8');
|
|
17
|
+
const versionName = gradleContent.match(/versionName\s+"([^"]*)"/)?.[1];
|
|
18
|
+
const versionCode = gradleContent.match(/versionCode\s+(\d+)/)?.[1];
|
|
19
|
+
await (0, publish_1.publish)({
|
|
20
|
+
files: [
|
|
21
|
+
{ ext: 'wgt', name: repoManifest.appid, path: 'unpackage/release' },
|
|
22
|
+
{ ext: 'apk', name: 'app-release', path: 'app/build/outputs/apk/release' },
|
|
23
|
+
],
|
|
24
|
+
versionName,
|
|
25
|
+
versionCode: versionCode ? Number(versionCode) : undefined,
|
|
26
|
+
});
|
|
27
|
+
}
|
package/lib/scripts/wgt-zip.js
CHANGED
|
@@ -6,9 +6,10 @@ const publish_1 = require("./publish");
|
|
|
6
6
|
async function default_1() {
|
|
7
7
|
const manifest = (0, utils_1.readManifest)();
|
|
8
8
|
await (0, publish_1.publish)({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
files: [
|
|
10
|
+
{ ext: 'wgt', name: manifest['appid'], path: 'unpackage/release' },
|
|
11
|
+
{ ext: 'zip', name: manifest['appid'], path: 'unpackage/release' },
|
|
12
|
+
],
|
|
12
13
|
versionName: manifest['versionName'],
|
|
13
14
|
versionCode: manifest['versionCode'],
|
|
14
15
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = default_1;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const fs_extra_1 = require("fs-extra");
|
|
10
|
+
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
11
|
+
const const_1 = require("../utils/const");
|
|
12
|
+
const publish_1 = require("./publish");
|
|
13
|
+
async function default_1() {
|
|
14
|
+
const pkg = (0, fs_extra_1.readJsonSync)(const_1.PACKAGE_PATH);
|
|
15
|
+
const repoManifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)((0, path_1.join)(const_1.COMMAND_PATH, '.repo', pkg.appId, 'src', 'manifest.json'), 'utf-8')));
|
|
16
|
+
await (0, publish_1.publish)({
|
|
17
|
+
files: [
|
|
18
|
+
{ ext: 'zip', name: repoManifest.appid, path: 'unpackage/release' },
|
|
19
|
+
{ ext: 'exe', name: 'app-release', path: 'dist' },
|
|
20
|
+
],
|
|
21
|
+
versionName: pkg['version'],
|
|
22
|
+
versionCode: pkg['versionCode'],
|
|
23
|
+
});
|
|
24
|
+
}
|
package/lib/utils/config.d.ts
CHANGED
|
@@ -93,6 +93,9 @@ export interface WebCredentials {
|
|
|
93
93
|
username?: string;
|
|
94
94
|
password?: string;
|
|
95
95
|
}
|
|
96
|
+
interface Render {
|
|
97
|
+
repo?: string;
|
|
98
|
+
}
|
|
96
99
|
export interface BaseConfig {
|
|
97
100
|
branch?: string | boolean;
|
|
98
101
|
cos?: Cos;
|
|
@@ -100,9 +103,10 @@ export interface BaseConfig {
|
|
|
100
103
|
skill?: Skill;
|
|
101
104
|
template?: Template;
|
|
102
105
|
web?: Record<string, WebCredentials> | WebCredentials;
|
|
106
|
+
render?: Render;
|
|
103
107
|
}
|
|
104
108
|
export interface Config extends BaseConfig {
|
|
105
|
-
|
|
109
|
+
skip?: boolean | number;
|
|
106
110
|
env?: string;
|
|
107
111
|
install?: string;
|
|
108
112
|
app?: App;
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
3
|
"type": "object",
|
|
4
4
|
"properties": {
|
|
5
|
-
"
|
|
5
|
+
"skip": {
|
|
6
6
|
"type": ["boolean", "number"],
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "是否跳过所有确认提示自动发布。true/1 跳过,false/0 不跳过。CLI 传入 --skip 时会覆盖此配置"
|
|
8
8
|
},
|
|
9
9
|
"branch": {
|
|
10
10
|
"type": ["boolean", "string"],
|
|
@@ -39,6 +39,16 @@
|
|
|
39
39
|
},
|
|
40
40
|
"required": ["username", "password"]
|
|
41
41
|
},
|
|
42
|
+
"render": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"description": "渲染端资源配置",
|
|
45
|
+
"properties": {
|
|
46
|
+
"repo": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"description": "远程渲染端仓库地址,--remote 拉取代码时使用"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
42
52
|
"pub": {
|
|
43
53
|
"type": "object",
|
|
44
54
|
"description": "发布配置",
|