@gmcb/cli 0.6.1 → 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 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.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
+
6
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)
7
18
 
8
19
 
@@ -69,6 +69,7 @@ async function getCommands(...args) {
69
69
  const buildEnv = ['master', 'main'].includes(opts.branch) ? 'prod' : opts.branch || opts.env;
70
70
  if (buildEnv) {
71
71
  commands.push(`BUILD_ENV=${buildEnv}`);
72
+ process.env.BUILD_ENV = buildEnv;
72
73
  }
73
74
  const currentName = (0, path_1.basename)(utils_1.COMMAND_PATH);
74
75
  const projectName = opts.project || currentName;
@@ -313,22 +314,28 @@ async function fetchRemoteResources(opts) {
313
314
  spinner.fail(`${appName} wgt链接未上传`);
314
315
  process.exit(1);
315
316
  }
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);
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);
319
321
  const tmpWgt = (0, path_1.join)(utils_1.COMMAND_PATH, '__tmp_remote.wgt');
320
322
  await downloadFile(wgtUrl, tmpWgt);
321
323
  const wgtZip = new adm_zip_1.default(tmpWgt);
322
- wgtZip.extractAllTo(assetsDir, true);
324
+ wgtZip.extractAllTo(tempDir, true);
323
325
  (0, fs_extra_1.removeSync)(tmpWgt);
324
326
  // 从目标目录读取 manifest
325
- const manifest = (0, fs_extra_1.readJsonSync)((0, path_1.join)(assetsDir, 'manifest.json'));
326
- const { versionName, versionCode } = 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);
327
334
  // 替换 build.gradle
328
335
  const gradlePath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle');
329
336
  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}"`);
337
+ gradleContent = gradleContent.replace(/versionCode\s+\d+/, `versionCode ${version.code}`);
338
+ gradleContent = gradleContent.replace(/versionName\s+"[^"]*"/, `versionName "${version.name}"`);
332
339
  (0, fs_1.writeFileSync)(gradlePath, gradleContent);
333
340
  // 替换 strings.xml
334
341
  const stringsPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
@@ -348,14 +355,10 @@ async function fetchRemoteResources(opts) {
348
355
  }
349
356
  async function default_1(...args) {
350
357
  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);
358
+ const commands = await getCommands(...args);
359
+ if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
355
360
  await fetchRemoteResources(opts);
356
- return [];
357
361
  }
358
- const commands = await getCommands(...args);
359
362
  const command = commands.join(' ');
360
363
  const time = Date.now();
361
364
  (0, utils_1.spawnSync)(command);
package/lib/apis/index.js CHANGED
@@ -80,155 +80,173 @@ function getVersionHistory(params) {
80
80
  * 上传新版本
81
81
  */
82
82
  async function uploadVersion(params) {
83
- const { brand, username, password, type, status, platform, path, remoteUrl, versionName, versionCode, } = params;
84
- let brandId = '';
85
- const { data: { accessToken }, } = await login({ username, password });
86
- (0, http_1.setToken)(accessToken);
87
- const { data: brandList } = await getBrandList();
88
- const brandItem = brandList?.find(({ name, id }) => name === brand && Number(id) > 10000);
89
- brandId = brandItem?.id;
90
- const packageName = path?.split('/').filter(Boolean).pop();
91
- const { data: latest } = await getLastVersion({ type, platform, packageName, version: 0 });
92
- await saveVersion({
93
- type,
94
- status: status || 4,
95
- platform,
96
- brandId,
97
- fileUrl: latest?.fileUrl || 'none',
98
- hotUpdateUrl: remoteUrl,
99
- name: versionName,
100
- version: versionCode,
101
- packageName,
102
- comment: '修复一些已知问题',
103
- });
83
+ try {
84
+ const { brand, username, password, type, status, platform, path, remoteUrl, versionName, versionCode, } = params;
85
+ let brandId = '';
86
+ const { data: { accessToken }, } = await login({ username, password });
87
+ (0, http_1.setToken)(accessToken);
88
+ const { data: brandList } = await getBrandList();
89
+ const brandItem = brandList?.find(({ name, id }) => name === brand && Number(id) > 10000);
90
+ brandId = brandItem?.id;
91
+ const packageName = path?.split('/').filter(Boolean).pop();
92
+ const { data: latest } = await getLastVersion({ type, platform, packageName, version: 0 });
93
+ await saveVersion({
94
+ type,
95
+ status: status || 4,
96
+ platform,
97
+ brandId,
98
+ fileUrl: latest?.fileUrl || 'none',
99
+ hotUpdateUrl: remoteUrl,
100
+ name: versionName,
101
+ version: versionCode,
102
+ packageName,
103
+ comment: '修复一些已知问题',
104
+ });
105
+ }
106
+ catch (err) {
107
+ console.error(err);
108
+ process.exit(1);
109
+ }
104
110
  }
105
111
  /**
106
112
  * 发布版本
107
113
  */
108
114
  async function publishVersion(params) {
109
- const { brandName, brandId, appId, username, password, remoteUrl, versionName, versionCode, channel, versionDesc, platform, ...rest } = params;
110
- const publishType = Number(rest.publishType) || 3;
111
- const updateType = Number(rest.updateType) || 2;
112
- const { data: { accessToken }, } = await login({ username, password });
113
- (0, http_1.setToken)(accessToken);
114
- const { data: pageData } = await getVersionPage({ appId, publishType, pageNo: 1, pageSize: 10 });
115
- const pageList = pageData?.list?.filter((item) => {
116
- if (publishType == 1) {
117
- return item.platformType === const_1.PLATFORM_TYPE[platform];
115
+ try {
116
+ const { brandName, brandId, appId, username, password, remoteUrl, versionName, versionCode, channel, versionDesc, platform, ...rest } = params;
117
+ const publishType = Number(rest.publishType) || 3;
118
+ const updateType = Number(rest.updateType) || 2;
119
+ const { data: { accessToken }, } = await login({ username, password });
120
+ (0, http_1.setToken)(accessToken);
121
+ const { data: pageData } = await getVersionPage({ appId, publishType, pageNo: 1, pageSize: 10 });
122
+ const pageList = pageData?.list?.filter((item) => {
123
+ if (publishType == 1) {
124
+ return item.platformType === const_1.PLATFORM_TYPE[platform];
125
+ }
126
+ return true;
127
+ }) || [];
128
+ const existingVersion = pageList.find((item) => String(item.versionNum) === String(versionCode));
129
+ let latest;
130
+ const firstPage = pageList[0];
131
+ if (firstPage) {
132
+ let historyParams;
133
+ if (firstPage.publishType == 1) {
134
+ historyParams = {
135
+ publishType: firstPage.publishType,
136
+ appName: firstPage.appName,
137
+ channelType: firstPage.channelType,
138
+ platformType: firstPage.platformType,
139
+ };
140
+ }
141
+ else {
142
+ historyParams = {
143
+ publishType,
144
+ appMofangId: firstPage.appMofangId,
145
+ };
146
+ }
147
+ const { data: historyData } = await getVersionHistory({ ...historyParams, pageNo: 1, pageSize: 1 });
148
+ latest = (Array.isArray(historyData) ? historyData : historyData?.list)?.[0];
118
149
  }
119
- return true;
120
- }) || [];
121
- const existingVersion = pageList.find((item) => String(item.versionNum) === String(versionCode));
122
- let latest;
123
- const firstPage = pageList[0];
124
- if (firstPage) {
125
- let historyParams;
126
- if (firstPage.publishType == 1) {
127
- historyParams = {
128
- publishType: firstPage.publishType,
129
- appName: firstPage.appName,
130
- channelType: firstPage.channelType,
131
- platformType: firstPage.platformType,
132
- };
150
+ if (!existingVersion && latest && Number(versionCode) <= Number(latest.versionNum)) {
151
+ throw new Error(`版本号不能小于上次发布 ${latest.versionNum}`);
133
152
  }
134
- else {
135
- historyParams = {
136
- publishType,
137
- appMofangId: firstPage.appMofangId,
138
- };
139
- }
140
- const { data: historyData } = await getVersionHistory({ ...historyParams, pageNo: 1, pageSize: 1 });
141
- latest = (Array.isArray(historyData) ? historyData : historyData?.list)?.[0];
142
- }
143
- if (!existingVersion && latest && Number(versionCode) <= Number(latest.versionNum)) {
144
- throw new Error(`版本号不能小于上次发布 ${latest.versionNum}`);
145
- }
146
- let versionId;
147
- if (existingVersion) {
148
- versionId = existingVersion.id;
149
- }
150
- else {
151
- let createData;
152
- if (publishType == 1) {
153
- const { data: brandList } = await getBrandList();
154
- const brandItem = brandList?.find(({ name, id }) => {
155
- if (Number(id) > 10000) {
156
- if (brandId && id === brandId) {
157
- return true;
158
- }
159
- if (brandName && name === brandName) {
160
- return true;
161
- }
162
- }
163
- return false;
164
- });
165
- createData = {
166
- brandId: brandItem?.id,
167
- appName: brandItem?.name,
168
- channelType: const_1.CHANNEL_TYPE[channel],
169
- platformType: const_1.PLATFORM_TYPE[platform],
170
- updateType,
171
- versionName,
172
- versionNum: versionCode,
173
- versionDesc: versionDesc || '修复一些已知问题',
174
- fullPackageUrl: '',
175
- fullPackageFileName: '',
176
- resourcePackageUrl: '',
177
- resourcePackageFileName: '',
178
- publishType,
179
- };
153
+ let versionId;
154
+ if (existingVersion) {
155
+ versionId = existingVersion.id;
180
156
  }
181
157
  else {
182
- const { data: appList } = await getAppList();
183
- const appItem = appList?.find((item) => item.appId === appId);
184
- createData = {
185
- appMofangId: appItem?.id,
186
- appId,
187
- appName: appItem?.name,
188
- updateType,
189
- versionName,
190
- versionNum: versionCode,
191
- versionDesc: versionDesc || '修复一些已知问题',
192
- resourcePackageUrl: '',
193
- resourcePackageFileName: '',
194
- publishType,
195
- };
158
+ let createData;
159
+ if (publishType == 1) {
160
+ const { data: brandList } = await getBrandList();
161
+ const brandItem = brandList?.find(({ name, id }) => {
162
+ if (Number(id) > 10000) {
163
+ if (brandId && id === brandId) {
164
+ return true;
165
+ }
166
+ if (brandName && name === brandName) {
167
+ return true;
168
+ }
169
+ }
170
+ return false;
171
+ });
172
+ createData = {
173
+ brandId: brandItem?.id,
174
+ appName: brandItem?.name,
175
+ channelType: const_1.CHANNEL_TYPE[channel],
176
+ platformType: const_1.PLATFORM_TYPE[platform],
177
+ updateType,
178
+ versionName,
179
+ versionNum: versionCode,
180
+ versionDesc: versionDesc || '修复一些已知问题',
181
+ fullPackageUrl: '',
182
+ fullPackageFileName: '',
183
+ resourcePackageUrl: '',
184
+ resourcePackageFileName: '',
185
+ publishType,
186
+ };
187
+ }
188
+ else {
189
+ const { data: appList } = await getAppList();
190
+ const appItem = appList?.find((item) => item.appId === appId);
191
+ createData = {
192
+ appMofangId: appItem?.id,
193
+ appId,
194
+ appName: appItem?.name,
195
+ updateType,
196
+ versionName,
197
+ versionNum: versionCode,
198
+ versionDesc: versionDesc || '修复一些已知问题',
199
+ resourcePackageUrl: '',
200
+ resourcePackageFileName: '',
201
+ publishType,
202
+ };
203
+ }
204
+ const { data: newId } = await createVersion(createData);
205
+ versionId = newId;
196
206
  }
197
- const { data: newId } = await createVersion(createData);
198
- versionId = newId;
207
+ const urls = Array.isArray(remoteUrl) ? remoteUrl : [remoteUrl || ''];
208
+ const fullUrl = urls.find((u) => !/\.zip$/i.test(u)) || '';
209
+ const resUrl = urls.find((u) => /\.zip$/i.test(u)) || '';
210
+ const fallbackFullUrl = existingVersion?.fullPackageUrl || latest?.fullPackageUrl || '';
211
+ const fallbackResUrl = existingVersion?.resourcePackageUrl || latest?.resourcePackageUrl || '';
212
+ await postVersion({
213
+ id: versionId,
214
+ fullPackageUrl: fullUrl || fallbackFullUrl,
215
+ resourcePackageUrl: resUrl || fallbackResUrl,
216
+ });
217
+ }
218
+ catch (err) {
219
+ console.error(err);
220
+ process.exit(1);
199
221
  }
200
- const urls = Array.isArray(remoteUrl) ? remoteUrl : [remoteUrl || ''];
201
- const fullUrl = urls.find((u) => !/\.zip$/i.test(u)) || '';
202
- const resUrl = urls.find((u) => /\.zip$/i.test(u)) || '';
203
- const fallbackFullUrl = existingVersion?.fullPackageUrl || latest?.fullPackageUrl || '';
204
- const fallbackResUrl = existingVersion?.resourcePackageUrl || latest?.resourcePackageUrl || '';
205
- await postVersion({
206
- id: versionId,
207
- fullPackageUrl: fullUrl || fallbackFullUrl,
208
- resourcePackageUrl: resUrl || fallbackResUrl,
209
- });
210
222
  }
211
223
  /**
212
224
  * 获取远程版本信息(自动登录)
213
225
  */
214
226
  async function fetchRemoteVersionInfo(appId) {
215
- const web = config_1.CONFIG_DATA.web;
216
- const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
217
- const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
218
- (0, http_1.setToken)(accessToken);
219
- const { data: pageData } = await getVersionPage({ appId, publishType: 2, pageNo: 1, pageSize: 10 });
220
- const version = pageData?.list?.[0];
221
- if (!version)
222
- throw new Error(`未查询到 ${appId} 应用数据`);
223
- const { data: appDetail } = await getAppDetail(version.appMofangId);
224
- let configJson = {};
225
227
  try {
226
- configJson = JSON.parse(appDetail?.configJson || '{}');
228
+ const web = config_1.CONFIG_DATA.web;
229
+ const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
230
+ const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
231
+ (0, http_1.setToken)(accessToken);
232
+ const { data: pageData } = await getVersionPage({ appId, publishType: 2, pageNo: 1, pageSize: 10 });
233
+ const version = pageData?.list?.[0];
234
+ if (!version)
235
+ throw new Error(`未查询到 ${appId} 应用数据`);
236
+ const { data: appDetail } = await getAppDetail(version.appMofangId);
237
+ let configJson = {};
238
+ try {
239
+ configJson = JSON.parse(appDetail?.configJson || '{}');
240
+ }
241
+ catch { }
242
+ return {
243
+ ...version,
244
+ iconUrl: appDetail?.iconUrl,
245
+ configJson,
246
+ };
247
+ }
248
+ catch (err) {
249
+ console.error(err);
250
+ process.exit(1);
227
251
  }
228
- catch { }
229
- return {
230
- ...version,
231
- iconUrl: appDetail?.iconUrl,
232
- configJson,
233
- };
234
252
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmcb/cli",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "工茂草本前端命令行工具",
5
5
  "author": "yinjiazeng@163.com",
6
6
  "license": "MIT",
@@ -58,6 +58,5 @@
58
58
  "@types/inquirer": "^9.0.7",
59
59
  "@types/rimraf": "^4.0.5",
60
60
  "@types/user-home": "^2.0.2"
61
- },
62
- "gitHead": "7c47fc74419f1ef0f1b3f70148c6dfabb4251f14"
61
+ }
63
62
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 aniu
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.