@infly/libs 2.0.26 → 2.0.37

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.
Files changed (39) hide show
  1. package/bin/cli.js +29 -21
  2. package/build/build-dist/index.js +258 -61
  3. package/build/webpack5/remove-legacy-assets-plugin.js +84 -0
  4. package/build/webpack5/webpack.base.js +228 -20
  5. package/build/webpack5/webpack.base.test.js +59 -0
  6. package/index.js +10 -0
  7. package/module/Permission.js +121 -55
  8. package/module/REST.js +136 -26
  9. package/module/Router.js +15 -0
  10. package/module/Uts.js +380 -331
  11. package/module/cjs/deep-merge.cjs +38 -0
  12. package/module/cjs/page-config.cjs +119 -0
  13. package/module/cjs/request-url-rules.cjs +55 -0
  14. package/package.json +11 -10
  15. package/script/build/command.js +48 -0
  16. package/script/build/env.js +28 -0
  17. package/script/build/git.js +252 -0
  18. package/script/build/preview.js +75 -0
  19. package/script/build/webhook.js +118 -0
  20. package/script/git-automation/check-packages.js +11 -8
  21. package/script/git-automation/git-utils.js +67 -0
  22. package/script/git-automation/index.js +378 -106
  23. package/script/index.js +8 -8
  24. package/script/pts/cloud-scenes.mjs +65 -0
  25. package/script/pts/cloud.js +151 -0
  26. package/script/pts/generate-cloud-params.mjs +210 -0
  27. package/script/pts/generate-cloud-params.test.mjs +67 -0
  28. package/script/webhook/webhook.js +75 -4
  29. package/store/modules/user.js +111 -9
  30. package/tools/auto-export.js +56 -0
  31. package/tools/file-export.js +32 -9
  32. package/tools/file-process.js +3 -0
  33. package/tools/project-preview.js +110 -97
  34. package/dataInit/commonTypeMap.js +0 -31
  35. package/dataInit/marketingActivitiesMap.js +0 -214
  36. package/dataInit/orderMap.js +0 -13
  37. package/dataInit/personalMap.js +0 -19
  38. package/dataInit/settlementMap.js +0 -17
  39. package/types/unused.index.d.ts +0 -71
@@ -0,0 +1,118 @@
1
+ const fs = require("fs");
2
+
3
+ function shouldSkipWebhook(args) {
4
+ return args.some((arg) => ["--nowebhook", "--noWebhook", "--no-webhook"].includes(arg));
5
+ }
6
+
7
+ function getVersionFromRecord(record) {
8
+ const fileName = record.extraParams?.newFileName || "";
9
+ const match = fileName.match(/-v([^-.]+(?:\.[^-.]+)*)-/);
10
+ return match ? match[1] : "";
11
+ }
12
+
13
+ function getProjectLine(record) {
14
+ const { projectName, gitInfo = {}, repos } = record.extraParams || {};
15
+ const version = getVersionFromRecord(record);
16
+ const branch = gitInfo.branch || "";
17
+ const repoText = repos ? `,构建仓库:${repos}` : "";
18
+ return `- ${projectName || "unknown"}${version ? ` v${version}` : ""}${branch ? ` ${branch}` : ""}${repoText}`;
19
+ }
20
+
21
+ function getRecordContent(record, deployUrl) {
22
+ const { publishText = "", extraParams = {} } = record || {};
23
+ const {
24
+ gitInfo = {},
25
+ gitAutoPushReposBranchMap,
26
+ repos,
27
+ newFileName,
28
+ projectName,
29
+ webhookExtraText = ""
30
+ } = extraParams;
31
+ const { branch, author } = gitInfo || {};
32
+
33
+ if (gitAutoPushReposBranchMap) {
34
+ const targetBranch = gitAutoPushReposBranchMap[branch] || branch || "";
35
+ return [
36
+ publishText,
37
+ `构建文件:已推送对应仓库【${repos || ""}】- 分支【${targetBranch}】`,
38
+ `构建人:${author || ""}`,
39
+ `部署系统:${deployUrl}`
40
+ ]
41
+ .filter(Boolean)
42
+ .join("\n");
43
+ }
44
+
45
+ const gitPath =
46
+ projectName && branch && newFileName
47
+ ? `https://gitee.com/gdinfly_1/${projectName}/blob/${branch}/${newFileName}`
48
+ : "";
49
+
50
+ return [
51
+ publishText,
52
+ gitPath ? `构建文件下载地址:${gitPath}` : "",
53
+ webhookExtraText
54
+ ]
55
+ .filter(Boolean)
56
+ .join("\n");
57
+ }
58
+
59
+ async function postBatchWebhook(batchWebhookFile, extraArgs, mode) {
60
+ if (shouldSkipWebhook(extraArgs)) {
61
+ console.log("\n已跳过企业微信机器人汇总推送(nowebhook)");
62
+ return;
63
+ }
64
+
65
+ if (!fs.existsSync(batchWebhookFile)) {
66
+ return;
67
+ }
68
+
69
+ const records = fs
70
+ .readFileSync(batchWebhookFile, "utf8")
71
+ .split(/\r?\n/)
72
+ .filter(Boolean)
73
+ .map((line) => JSON.parse(line));
74
+
75
+ if (records.length === 0) {
76
+ return;
77
+ }
78
+
79
+ const [firstRecord] = records;
80
+ const { webhookUrl, webhookAtUser = [], gitInfo = {}, deployUrl = "https://cicd.sutpay.com/" } =
81
+ firstRecord.extraParams || {};
82
+
83
+ if (!webhookUrl) {
84
+ return;
85
+ }
86
+
87
+ let content = [
88
+ records.map((record) => getRecordContent(record, deployUrl)).join("\n\n")
89
+ ].join("\n");
90
+ // 防御性过滤:防止运行时数据中的 %s 等格式化占位符泄露到推送内容
91
+ content = (content || "").replace(/%s/g, "");
92
+ const mentionedMobileList = Array.isArray(webhookAtUser) ? webhookAtUser : webhookAtUser[gitInfo.branch];
93
+
94
+ try {
95
+ await require("axios").post(
96
+ webhookUrl,
97
+ {
98
+ msgtype: "text",
99
+ text: {
100
+ content,
101
+ mentioned_mobile_list: mentionedMobileList
102
+ }
103
+ },
104
+ {
105
+ headers: {
106
+ "Content-Type": "application/json"
107
+ }
108
+ }
109
+ );
110
+ console.log("\n已发送批量构建企业微信汇总推送");
111
+ } catch (error) {
112
+ console.error("企业微信汇总推送失败", error.message);
113
+ }
114
+ }
115
+
116
+ module.exports = {
117
+ postBatchWebhook
118
+ };
@@ -13,23 +13,23 @@ global.logColor = {
13
13
  /**
14
14
  * 主函数:检查 packages 并处理
15
15
  */
16
- function main() {
16
+ async function main() {
17
17
  // packages 目录路径(相对于当前脚本的位置)
18
18
  const packagesDir = path.resolve(__dirname, '../../../../packages');
19
-
19
+
20
20
  console.log(global.logColor.info, `\n🔍 开始检查 packages 目录: ${packagesDir}\n`);
21
-
21
+
22
22
  try {
23
23
  // 执行完整的检查和更新流程
24
24
  // 如果有未提交代码会自动中止并退出进程
25
25
  // 如果没有问题会自动切换到 master 分支并拉取最新代码
26
- checkAndUpdatePackages(packagesDir, 'master');
27
-
26
+ await checkAndUpdatePackages(packagesDir, 'master');
27
+
28
28
  console.log(global.logColor.success, `\n✨ packages 检查和更新完成,可以继续执行后续操作!\n`);
29
-
29
+
30
30
  // 在这里可以继续执行你的其他逻辑
31
31
  // 比如构建、发布等操作
32
-
32
+
33
33
  } catch (error) {
34
34
  console.error(global.logColor.error, `\n💥 执行失败: ${error.message}\n`);
35
35
  process.exit(1);
@@ -38,7 +38,10 @@ function main() {
38
38
 
39
39
  // 如果直接运行此文件,则执行主函数
40
40
  if (require.main === module) {
41
- main();
41
+ main().catch(error => {
42
+ console.error(global.logColor.error, `\n💥 执行失败: ${error.message}\n`);
43
+ process.exit(1);
44
+ });
42
45
  }
43
46
 
44
47
  module.exports = { main };
@@ -0,0 +1,67 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { execFileSync } = require("child_process");
4
+
5
+ function gitOutput(args, cwd = process.cwd()) {
6
+ return execFileSync("git", args, {
7
+ cwd,
8
+ encoding: "utf8",
9
+ shell: process.platform === "win32"
10
+ }).trim();
11
+ }
12
+
13
+ function findGitRepo(cwd) {
14
+ let currentDir = path.resolve(cwd || process.cwd());
15
+
16
+ while (true) {
17
+ const gitPath = path.join(currentDir, ".git");
18
+
19
+ if (fs.existsSync(gitPath)) {
20
+ const stat = fs.statSync(gitPath);
21
+ const repo = {
22
+ root: currentDir,
23
+ commonDir: gitPath
24
+ };
25
+
26
+ if (stat.isFile()) {
27
+ const content = fs.readFileSync(gitPath, "utf8");
28
+ const match = content.match(/gitdir:\s*(.+)/i);
29
+
30
+ if (match) {
31
+ repo.commonDir = path.resolve(currentDir, match[1].trim());
32
+ }
33
+ }
34
+
35
+ return repo;
36
+ }
37
+
38
+ const parentDir = path.dirname(currentDir);
39
+
40
+ if (parentDir === currentDir) {
41
+ return null;
42
+ }
43
+
44
+ currentDir = parentDir;
45
+ }
46
+ }
47
+
48
+ function getGitCommonDir(cwd) {
49
+ const repo = findGitRepo(cwd);
50
+
51
+ if (repo) {
52
+ return repo.commonDir;
53
+ }
54
+
55
+ try {
56
+ const commonDir = gitOutput(["-C", cwd, "rev-parse", "--git-common-dir"]);
57
+ return path.resolve(cwd, commonDir);
58
+ } catch {
59
+ return path.resolve(cwd || process.cwd());
60
+ }
61
+ }
62
+
63
+ module.exports = {
64
+ gitOutput,
65
+ findGitRepo,
66
+ getGitCommonDir
67
+ };