lightshortcuts 1.1.3 → 1.1.5

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/bin/lsc.js CHANGED
@@ -10,6 +10,10 @@ const { merge, getZipFileList, pwdMd5, fmtTime } = require("../lib/utils");
10
10
  const fileExists = require("../lib/helpers/file-exists");
11
11
  const { createZip } = require("../lib/helpers/zip");
12
12
 
13
+ // 读取 package.json 获取版本号
14
+ const packageJson = require("../package.json");
15
+ const version = packageJson.version;
16
+
13
17
  const log = (message, ...args) => {
14
18
  console.log(`[${fmtTime()}] ${message}`, ...args);
15
19
  };
@@ -50,7 +54,7 @@ const {
50
54
  sendWechatWebhook,
51
55
  } = require("../lib/core/api");
52
56
 
53
- program.version("1.1.3");
57
+ program.version(version);
54
58
 
55
59
  // 登录并保存token
56
60
  let lightBaseURL = "";
package/lib/LSC.js CHANGED
@@ -35,7 +35,7 @@ var token,
35
35
  need_wechat_push = false, //是否需要企业微信推送
36
36
  webhookUrl,
37
37
  //以下是H5web相关配置
38
- publish_h5web_arr,
38
+ publish_h5web_arr = [],
39
39
  h5web_name = {};
40
40
 
41
41
  //引入API
@@ -188,7 +188,7 @@ const publishH5web = async (pkg_id_arr, app_name = "") => {
188
188
  log(`*************发布H5web应用*************`);
189
189
  log("发布H5web离线包", pkg_id_arr, app_name);
190
190
  const __filePath = path.join(process.cwd(), `${pkg_dir}${pkg_zip_name}`);
191
- let file_size = await statSync(__filePath).size;
191
+ let pkg_size = await statSync(__filePath).size;
192
192
  log("上传H5应用离线包");
193
193
  let pkg_id = await fileUpload(__filePath, "h5_src");
194
194
  log("上传H5应用离线包成功", pkg_id);
@@ -196,7 +196,7 @@ const publishH5web = async (pkg_id_arr, app_name = "") => {
196
196
  let comp_pkg_id = await addH5webPkg({
197
197
  pkg_name: `${pkg_zip_name}(${new Date().getTime()})`,
198
198
  pkg_id,
199
- file_size,
199
+ pkg_size,
200
200
  pkg_desc: release_desc || "此版本为自动化方式进行快捷发布",
201
201
  });
202
202
  log("创建H5应用包成功", comp_pkg_id);
@@ -204,7 +204,7 @@ const publishH5web = async (pkg_id_arr, app_name = "") => {
204
204
 
205
205
  for (let i = 0; i < pkg_id_arr.length; i++) {
206
206
  const result = await releaseMuchVersion(pkg_id_arr[i], comp_pkg_id);
207
- log(`🔥发布${h5web_name[pkg_id_arr[i]]}H5应用包成功!`);
207
+ log(`🔥发布“${h5web_name[pkg_id_arr[i]]}H5应用包成功!`);
208
208
  const msg = `发布 ${h5web_name[pkg_id_arr[i]]} H5应用包成功!`;
209
209
  if (need_wechat_push && webhookUrl) {
210
210
  const message = msg;
@@ -214,7 +214,7 @@ const publishH5web = async (pkg_id_arr, app_name = "") => {
214
214
  } catch (error) {
215
215
  await sendWechatWebhook(
216
216
  webhookUrl,
217
- `发布 ${h5web_name[pkg_id_arr[i]]} H5应用包失败❌!原因:${error}`,
217
+ `发布“${h5web_name[pkg_id_arr[i]]}H5应用包失败❌!原因:${error}`,
218
218
  );
219
219
  error("消息发送失败:", error);
220
220
  }
@@ -223,7 +223,7 @@ const publishH5web = async (pkg_id_arr, app_name = "") => {
223
223
  } catch (error) {
224
224
  await sendWechatWebhook(
225
225
  webhookUrl,
226
- `发布${h5web_name[pkg_id_arr[i]]}H5应用包失败❌!原因:${error}`,
226
+ `发布“${h5web_name[pkg_id_arr[i]]}H5应用包失败❌!原因:${error}`,
227
227
  );
228
228
  log("发布H5web离线包失败:", error);
229
229
  }
@@ -247,18 +247,30 @@ async function MainH5web(publish_h5web_arr) {
247
247
 
248
248
  //检查H5web应用ID是否存在
249
249
  const checkH5webAppIds = function (appList, checkIds) {
250
+ //appList里面的id是数字类型,checkIds是字符串类型
250
251
  try {
251
- // 提取应用列表中的所有ID并存储在Set中,提高查找效率
252
- const existingIdsSet = new Set(appList.map((app) => app.id.toString()));
252
+ // 空值和类型检查
253
+ if (!Array.isArray(appList) || !Array.isArray(checkIds)) {
254
+ log("appList或checkIds不是数组");
255
+ return [];
256
+ }
253
257
 
254
- // 使用reduce过滤出存在的ID
255
- const foundIds = checkIds.reduce((acc, id) => {
256
- if (existingIdsSet.has(id)) {
257
- h5web_name[id] = appList.find((app) => app.id.toString() === id).name;
258
- acc.push(id);
259
- }
260
- return acc;
261
- }, []);
258
+ // 过滤无效的应用对象并构建Map,避免重复查找
259
+ const validApps = appList.filter(app => app && app.id !== undefined);
260
+ const appMap = new Map(validApps.map(app => [app.id.toString(), app]));
261
+
262
+ // 过滤无效的ID并查找存在的应用
263
+ const foundIds = checkIds
264
+ .filter(id => id !== undefined && id !== null && id !== '')
265
+ .map(id => String(id))
266
+ .filter(idStr => {
267
+ const app = appMap.get(idStr);
268
+ if (app && app.show_name) {
269
+ h5web_name[idStr] = app.show_name;
270
+ return true;
271
+ }
272
+ return false;
273
+ });
262
274
 
263
275
  return foundIds;
264
276
  } catch (error) {
@@ -296,7 +308,7 @@ async function LSC(config = {}) {
296
308
 
297
309
  token = publishInfo.token;
298
310
  pkgid = publishInfo.pkgid;
299
- publish_app_arr = publishInfo.publish_app_arr;
311
+ publish_app_arr = publishInfo.publish_app_arr || [];
300
312
 
301
313
  set_pkg_version = publishInfo.set_pkg_version;
302
314
  task_status = publishInfo.task_status;
@@ -309,8 +321,8 @@ async function LSC(config = {}) {
309
321
  apps_name = publishInfo.apps_name;
310
322
  need_wechat_push = publishInfo.need_wechat_push; //是否需要企业微信推送
311
323
  webhookUrl = wecomWebhook;
312
- publish_h5web_arr = publishInfo.publish_h5web_arr;
313
- h5web_name = publishInfo.h5web_name;
324
+ publish_h5web_arr = publishInfo.publish_h5web_arr || [];
325
+ h5web_name = publishInfo.h5web_name || {};
314
326
 
315
327
  //全局配置
316
328
  axios.defaults.baseURL = lightBaseURL;
package/lib/core/api.js CHANGED
@@ -727,14 +727,31 @@ const updateOfflineTask = async function (uotArgs = {}) {
727
727
  //查询执行发布任务状态成功与否接口,返回true或false
728
728
  const queryOfflineVersionDetail = async function ({ id, app_id }) {
729
729
  try {
730
- const res = await retryWrapper(
730
+ const result = await retryWrapper(
731
731
  async () => {
732
- return await axios.get(
732
+ const res = await axios.get(
733
733
  `${ApiList.queryOfflineVersionDetail}?id=${id}&app_id=${app_id}`,
734
734
  {
735
735
  ...getAxiosConfig(),
736
736
  },
737
737
  );
738
+
739
+ // 处理响应数据
740
+ const { err_no, data } = res.data;
741
+
742
+ if (err_no == 0) {
743
+ const { status } = data;
744
+ if (status == 1) {
745
+ // 状态1 表示任务执行成功
746
+ return true;
747
+ } else {
748
+ // 其他状态都认为是失败,则继续重试查询,直到状态为1或重试次数耗尽
749
+ log(`查询执行发布任务状态详情是:${status}`);
750
+ throw new Error(`查询执行发布任务状态详情是:${status}`);
751
+ }
752
+ } else {
753
+ return false;
754
+ }
738
755
  },
739
756
  {
740
757
  maxRetries: 5,
@@ -743,22 +760,7 @@ const queryOfflineVersionDetail = async function ({ id, app_id }) {
743
760
  },
744
761
  );
745
762
 
746
- // 处理响应数据
747
- const { err_no, data } = res.data;
748
-
749
- if (err_no == 0) {
750
- const { status } = data;
751
- if (status == 4) {
752
- // 状态4 表示任务执行成功
753
- return true;
754
- } else {
755
- // 其他状态都认为是失败,则继续重试查询,直到状态为4或重试次数耗尽
756
- log(`查询执行发布任务状态详情是:${status}`);
757
- throw new Error(`查询执行发布任务状态详情是:${status}`);
758
- }
759
- } else {
760
- return false;
761
- }
763
+ return result;
762
764
  } catch (error) {
763
765
  log(`查询执行发布任务状态报错:${error}`);
764
766
  throw error;
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "inquirer": "^8.2.0",
11
11
  "qs": "^6.10.3"
12
12
  },
13
- "version": "1.1.3",
13
+ "version": "1.1.5",
14
14
  "description": "Light离线包自动发布工具",
15
15
  "main": "index.js",
16
16
  "scripts": {