@gmcb/cli 0.7.11 → 0.7.12
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 +25 -8
- package/lib/apis/http.d.ts +1 -0
- package/lib/apis/http.js +4 -0
- package/lib/apis/index.d.ts +16 -1
- package/lib/apis/index.js +67 -37
- package/package.json +2 -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.12](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.11...@gmcb/cli@0.7.12) (2026-07-14)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [0.7.11](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.10...@gmcb/cli@0.7.11) (2026-07-13)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @gmcb/cli
|
package/lib/actions/build.js
CHANGED
|
@@ -269,7 +269,25 @@ function downloadFile(url, dest) {
|
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
async function fetchRemoteResources(opts) {
|
|
272
|
-
const spinner = (0, ora_1.default)(
|
|
272
|
+
const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
|
|
273
|
+
// 查询版本数据,更新 package.json
|
|
274
|
+
const appIdPkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
275
|
+
const appId = appIdPkg.appId;
|
|
276
|
+
const { versionName, versionCode, brandId } = await (0, apis_1.fetchLatestVersion)({
|
|
277
|
+
appId,
|
|
278
|
+
brandId: config_1.CONFIG_DATA.publish?.brandId,
|
|
279
|
+
brandName: config_1.CONFIG_DATA.publish?.brandName,
|
|
280
|
+
platform: config_1.CONFIG_DATA.publish?.platform,
|
|
281
|
+
});
|
|
282
|
+
if (brandId) {
|
|
283
|
+
config_1.CONFIG_DATA.publish.brandId = brandId;
|
|
284
|
+
}
|
|
285
|
+
if (versionName && versionCode) {
|
|
286
|
+
let pkgContent = (0, fs_1.readFileSync)(utils_1.PACKAGE_PATH, 'utf-8');
|
|
287
|
+
pkgContent = pkgContent.replace(/"version"\s*:\s*"[^"]*"/, `"version": "${versionName}"`);
|
|
288
|
+
pkgContent = pkgContent.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
|
|
289
|
+
(0, fs_1.writeFileSync)(utils_1.PACKAGE_PATH, pkgContent);
|
|
290
|
+
}
|
|
273
291
|
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
274
292
|
// 校验 version 和 versionCode 必须存在
|
|
275
293
|
if (!pkg.version) {
|
|
@@ -278,7 +296,6 @@ async function fetchRemoteResources(opts) {
|
|
|
278
296
|
if (!pkg.versionCode) {
|
|
279
297
|
utils_1.log.error('package.json 缺少 versionCode 字段');
|
|
280
298
|
}
|
|
281
|
-
const appId = pkg.appId;
|
|
282
299
|
// 1. 获取应用信息
|
|
283
300
|
const appInfo = await (0, apis_1.getAppInfo)(appId);
|
|
284
301
|
const { appName, iconUrl, configJson } = appInfo;
|
|
@@ -315,9 +332,9 @@ async function fetchRemoteResources(opts) {
|
|
|
315
332
|
// 5. 修改仓库 src/manifest.json 的 versionName 和 versionCode
|
|
316
333
|
const manifestPath = (0, path_1.join)(repoDir, 'src', 'manifest.json');
|
|
317
334
|
let manifestContent = (0, fs_1.readFileSync)(manifestPath, 'utf-8');
|
|
318
|
-
manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name"
|
|
319
|
-
manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName"
|
|
320
|
-
manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode"
|
|
335
|
+
manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name": "${appName}"`);
|
|
336
|
+
manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${pkg.version}"`);
|
|
337
|
+
manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode": ${pkg.versionCode}`);
|
|
321
338
|
(0, fs_1.writeFileSync)(manifestPath, manifestContent);
|
|
322
339
|
// 6. 修改仓库 package.json scripts
|
|
323
340
|
const repoPkgPath = (0, path_1.join)(repoDir, 'package.json');
|
|
@@ -397,6 +414,9 @@ async function default_1(...args) {
|
|
|
397
414
|
const opts = args[0];
|
|
398
415
|
const commands = await getCommands(...args);
|
|
399
416
|
const command = commands.join(' ');
|
|
417
|
+
if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
|
|
418
|
+
await fetchRemoteResources(opts);
|
|
419
|
+
}
|
|
400
420
|
if (!opts.nobuild) {
|
|
401
421
|
const time = Date.now();
|
|
402
422
|
(0, utils_1.spawnSync)(command);
|
|
@@ -409,9 +429,6 @@ async function default_1(...args) {
|
|
|
409
429
|
if ((0, fs_1.existsSync)(envPath)) {
|
|
410
430
|
(0, fs_1.unlinkSync)(envPath);
|
|
411
431
|
}
|
|
412
|
-
if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
|
|
413
|
-
await fetchRemoteResources(opts);
|
|
414
|
-
}
|
|
415
432
|
// H5 构建完成后立即生成 manifest.json
|
|
416
433
|
if (opts.compiler === 'uni' && opts.platform === 'h5') {
|
|
417
434
|
generateH5Manifest();
|
package/lib/apis/http.d.ts
CHANGED
|
@@ -45,5 +45,6 @@ declare class Http {
|
|
|
45
45
|
get(url: string, params?: HttpRequestParams, config?: HttpRequestConfig): Promise<ResponseData<any>>;
|
|
46
46
|
}
|
|
47
47
|
export declare function setToken(token?: string): void;
|
|
48
|
+
export declare function getToken(): string | undefined;
|
|
48
49
|
export declare const http: Http;
|
|
49
50
|
export {};
|
package/lib/apis/http.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.http = void 0;
|
|
4
4
|
exports.setToken = setToken;
|
|
5
|
+
exports.getToken = getToken;
|
|
5
6
|
const const_1 = require("../utils/const");
|
|
6
7
|
class Http {
|
|
7
8
|
_header = {
|
|
@@ -130,4 +131,7 @@ function setToken(token) {
|
|
|
130
131
|
delete header['Authorization'];
|
|
131
132
|
}
|
|
132
133
|
}
|
|
134
|
+
function getToken() {
|
|
135
|
+
return exports.http.options.header['Authorization'];
|
|
136
|
+
}
|
|
133
137
|
exports.http = new Http();
|
package/lib/apis/index.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export declare function postVersion(data: any): Promise<{
|
|
|
60
60
|
export declare function getVersionPage(params: {
|
|
61
61
|
appId: string;
|
|
62
62
|
publishType: number;
|
|
63
|
+
brandId?: number | string;
|
|
64
|
+
platform?: number;
|
|
63
65
|
pageNo?: number;
|
|
64
66
|
pageSize?: number;
|
|
65
67
|
}): Promise<{
|
|
@@ -89,7 +91,7 @@ export declare function getVersionHistory(params: Record<string, any>): Promise<
|
|
|
89
91
|
}>;
|
|
90
92
|
export interface VersionParams {
|
|
91
93
|
brand?: string;
|
|
92
|
-
brandId?:
|
|
94
|
+
brandId?: string;
|
|
93
95
|
brandName?: string;
|
|
94
96
|
appId?: string;
|
|
95
97
|
username?: string;
|
|
@@ -115,6 +117,19 @@ export declare function uploadVersion(params: VersionParams): Promise<void>;
|
|
|
115
117
|
* 发布版本
|
|
116
118
|
*/
|
|
117
119
|
export declare function publishVersion(params: VersionParams): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* 获取最新版本信息(自动登录)
|
|
122
|
+
*/
|
|
123
|
+
export declare function fetchLatestVersion(params: {
|
|
124
|
+
appId: string;
|
|
125
|
+
brandId?: string;
|
|
126
|
+
brandName?: string;
|
|
127
|
+
platform?: number;
|
|
128
|
+
}): Promise<{
|
|
129
|
+
versionName: any;
|
|
130
|
+
versionCode: number;
|
|
131
|
+
brandId: string;
|
|
132
|
+
}>;
|
|
118
133
|
/**
|
|
119
134
|
* 获取应用信息(自动登录)
|
|
120
135
|
*/
|
package/lib/apis/index.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.getAppPage = getAppPage;
|
|
|
12
12
|
exports.getVersionHistory = getVersionHistory;
|
|
13
13
|
exports.uploadVersion = uploadVersion;
|
|
14
14
|
exports.publishVersion = publishVersion;
|
|
15
|
+
exports.fetchLatestVersion = fetchLatestVersion;
|
|
15
16
|
exports.getAppInfo = getAppInfo;
|
|
16
17
|
const http_1 = require("./http");
|
|
17
18
|
const const_1 = require("../utils/const");
|
|
@@ -23,6 +24,14 @@ const utils_1 = require("../utils");
|
|
|
23
24
|
function login(data) {
|
|
24
25
|
return http_1.http.post('/admin-api/system/auth/login', data);
|
|
25
26
|
}
|
|
27
|
+
async function ensureLoggedIn() {
|
|
28
|
+
if ((0, http_1.getToken)())
|
|
29
|
+
return;
|
|
30
|
+
const web = config_1.CONFIG_DATA.web;
|
|
31
|
+
const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
|
|
32
|
+
const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
|
|
33
|
+
(0, http_1.setToken)(accessToken);
|
|
34
|
+
}
|
|
26
35
|
/**
|
|
27
36
|
* 获取品牌列表
|
|
28
37
|
*/
|
|
@@ -82,10 +91,9 @@ function getVersionHistory(params) {
|
|
|
82
91
|
*/
|
|
83
92
|
async function uploadVersion(params) {
|
|
84
93
|
try {
|
|
85
|
-
const { brand,
|
|
94
|
+
const { brand, type, status, platform, path, remoteUrl, versionName, versionCode, } = params;
|
|
86
95
|
let brandId = '';
|
|
87
|
-
|
|
88
|
-
(0, http_1.setToken)(accessToken);
|
|
96
|
+
await ensureLoggedIn();
|
|
89
97
|
const { data: brandList } = await getBrandList();
|
|
90
98
|
const brandItem = brandList?.find(({ name, id }) => name === brand && Number(id) > 10000);
|
|
91
99
|
brandId = brandItem?.id;
|
|
@@ -114,20 +122,19 @@ async function uploadVersion(params) {
|
|
|
114
122
|
*/
|
|
115
123
|
async function publishVersion(params) {
|
|
116
124
|
try {
|
|
117
|
-
const { brandName, brandId, appId,
|
|
125
|
+
const { brandName, brandId, appId, remoteUrl, versionName, versionCode, channel, versionDesc, platform, ...rest } = params;
|
|
118
126
|
const publishType = Number(rest.publishType || 3);
|
|
119
127
|
const updateType = Number(rest.updateType || 2);
|
|
120
128
|
const updateMode = Number(rest.updateMode || 0);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const existingVersion = pageList.find((item) => String(item.versionNum) === String(versionCode));
|
|
129
|
+
await ensureLoggedIn();
|
|
130
|
+
const pageParams = { appId, publishType, pageNo: 1, pageSize: 1 };
|
|
131
|
+
if (publishType == 1) {
|
|
132
|
+
pageParams.brandId = config_1.CONFIG_DATA.publish?.brandId;
|
|
133
|
+
pageParams.platform = platform;
|
|
134
|
+
}
|
|
135
|
+
const { data: pageData } = await getVersionPage(pageParams);
|
|
136
|
+
const pageList = pageData?.list || [];
|
|
137
|
+
const existingVersion = pageList.find((item) => item.status < 2 && String(item.versionNum) === String(versionCode));
|
|
131
138
|
let latest;
|
|
132
139
|
const firstPage = pageList[0];
|
|
133
140
|
if (firstPage) {
|
|
@@ -158,22 +165,20 @@ async function publishVersion(params) {
|
|
|
158
165
|
}
|
|
159
166
|
else {
|
|
160
167
|
let createData;
|
|
168
|
+
const { data: appList } = await getAppList();
|
|
169
|
+
const appItem = appList?.find((item) => item.appId === appId);
|
|
161
170
|
if (publishType == 1) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
});
|
|
171
|
+
let resolvedBrandId = config_1.CONFIG_DATA.publish?.brandId || brandId;
|
|
172
|
+
if (!resolvedBrandId && brandName) {
|
|
173
|
+
const { data: brandList } = await getBrandList();
|
|
174
|
+
const matched = brandList?.find(({ name, id }) => {
|
|
175
|
+
return Number(id) > 10000 && name === brandName;
|
|
176
|
+
});
|
|
177
|
+
resolvedBrandId = matched?.id;
|
|
178
|
+
}
|
|
174
179
|
createData = {
|
|
175
|
-
brandId:
|
|
176
|
-
appName:
|
|
180
|
+
brandId: resolvedBrandId,
|
|
181
|
+
appName: appItem?.name,
|
|
177
182
|
channelType: const_1.CHANNEL_TYPE[channel],
|
|
178
183
|
platformType: const_1.PLATFORM_TYPE[platform],
|
|
179
184
|
updateType,
|
|
@@ -189,11 +194,9 @@ async function publishVersion(params) {
|
|
|
189
194
|
};
|
|
190
195
|
}
|
|
191
196
|
else {
|
|
192
|
-
const { data: appList } = await getAppList();
|
|
193
|
-
const appItem = appList?.find((item) => item.appId === appId);
|
|
194
197
|
createData = {
|
|
195
|
-
appMofangId: appItem?.id,
|
|
196
198
|
appId,
|
|
199
|
+
appMofangId: appItem?.id,
|
|
197
200
|
appName: appItem?.name,
|
|
198
201
|
updateType,
|
|
199
202
|
updateMode,
|
|
@@ -219,8 +222,8 @@ async function publishVersion(params) {
|
|
|
219
222
|
fullUrl = urls.find((u) => !/\.zip$/i.test(u)) || '';
|
|
220
223
|
resUrl = urls.find((u) => /\.zip$/i.test(u)) || '';
|
|
221
224
|
}
|
|
222
|
-
let fallbackFullUrl =
|
|
223
|
-
let fallbackResUrl =
|
|
225
|
+
let fallbackFullUrl = latest?.fullPackageUrl || '';
|
|
226
|
+
let fallbackResUrl = latest?.resourcePackageUrl || '';
|
|
224
227
|
if (publishType == 1 && fullUrl) {
|
|
225
228
|
fallbackFullUrl = '';
|
|
226
229
|
fallbackResUrl = '';
|
|
@@ -236,15 +239,42 @@ async function publishVersion(params) {
|
|
|
236
239
|
process.exit(1);
|
|
237
240
|
}
|
|
238
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* 获取最新版本信息(自动登录)
|
|
244
|
+
*/
|
|
245
|
+
async function fetchLatestVersion(params) {
|
|
246
|
+
const { appId, brandId, brandName, platform } = params;
|
|
247
|
+
await ensureLoggedIn();
|
|
248
|
+
let resolvedBrandId = brandId;
|
|
249
|
+
if (!resolvedBrandId && brandName) {
|
|
250
|
+
const { data: brandList } = await getBrandList();
|
|
251
|
+
const matched = brandList?.find(({ name, id }) => {
|
|
252
|
+
return Number(id) > 10000 && name === brandName;
|
|
253
|
+
});
|
|
254
|
+
resolvedBrandId = matched?.id;
|
|
255
|
+
}
|
|
256
|
+
const { data: versionPage } = await getVersionPage({
|
|
257
|
+
appId,
|
|
258
|
+
publishType: 1,
|
|
259
|
+
brandId: resolvedBrandId,
|
|
260
|
+
platform,
|
|
261
|
+
pageNo: 1,
|
|
262
|
+
pageSize: 1,
|
|
263
|
+
});
|
|
264
|
+
const versionList = (versionPage?.list || []).filter((item) => item.status < 2);
|
|
265
|
+
const latestVersion = versionList[0];
|
|
266
|
+
return {
|
|
267
|
+
versionName: latestVersion?.versionName ?? '',
|
|
268
|
+
versionCode: Number(latestVersion?.versionNum ?? 0),
|
|
269
|
+
brandId: resolvedBrandId ?? '',
|
|
270
|
+
};
|
|
271
|
+
}
|
|
239
272
|
/**
|
|
240
273
|
* 获取应用信息(自动登录)
|
|
241
274
|
*/
|
|
242
275
|
async function getAppInfo(appId) {
|
|
243
276
|
try {
|
|
244
|
-
|
|
245
|
-
const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
|
|
246
|
-
const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
|
|
247
|
-
(0, http_1.setToken)(accessToken);
|
|
277
|
+
await ensureLoggedIn();
|
|
248
278
|
const { data: pageData } = await getAppPage({ appId, pageNo: 1, pageSize: 10 });
|
|
249
279
|
const appData = pageData?.list?.[0];
|
|
250
280
|
if (!appData)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmcb/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12",
|
|
4
4
|
"description": "工茂草本前端命令行工具",
|
|
5
5
|
"author": "yinjiazeng@163.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"@types/rimraf": "^4.0.5",
|
|
60
60
|
"@types/user-home": "^2.0.2"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "03c7901a7dba2e7364e9eaabf7a6f0e5199064aa"
|
|
63
63
|
}
|