@infly/libs 2.0.43 → 2.0.45
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/README.md +104 -67
- package/{module → adapters/vue2/module}/Permission.js +2 -2
- package/{module → adapters/vue2/module}/REST.js +32 -20
- package/{module → adapters/vue2/module}/TokenService.js +10 -1
- package/adapters/vue2/module/file-export.js +18 -0
- package/adapters/vue2/postinstall.js +46 -0
- package/adapters/vue2/project-preview.js +152 -0
- package/adapters/vue2/script-config.js +26 -0
- package/adapters/vue2/store/index.js +1 -0
- package/{store → adapters/vue2/store}/modules/user.js +1 -1
- package/adapters/vue2/vite/index.js +95 -0
- package/adapters/vue2/vite/jest.config.js +11 -0
- package/{build → adapters/vue2}/webpack5/webpack.base.js +26 -79
- package/bin/cli.js +71 -71
- package/build/build-dist/index.js +863 -863
- package/build/build-dist/script-management.js +5 -5
- package/{script/build → build/build-utils}/command.js +13 -4
- package/{script/build → build/build-utils}/deps.js +1 -1
- package/{script/build → build/build-utils}/git.js +6 -4
- package/{script/build → build/build-utils}/preview.js +4 -1
- package/{script/webhook/webhook.js → build/build-utils/webhook-single.js} +7 -2
- package/{script/build → build/build-utils}/webhook.js +3 -2
- package/build/docker/compose-command.js +74 -74
- package/build/docker/compose-release.js +91 -91
- package/compat/init.js +9 -0
- package/index.js +8 -20
- package/module/Uts.js +77 -7265
- package/module/cjs/{request-url-rules.cjs → request-url-rules.js} +6 -0
- package/module/cjs/rest-error-rules.js +33 -0
- package/package.json +124 -92
- package/script/git-automation/git-clone.js +3 -4
- package/script/git-automation/git-configure.js +29 -0
- package/script/git-automation/index.js +0 -14
- package/script/git-automation/submodule-status.js +113 -0
- package/script/git-automation/submodule-utils.js +18 -0
- package/script/index.js +1 -26
- package/tools/auto-export.js +1 -2
- package/tools/concurrency.js +30 -0
- package/tools/progress.js +63 -0
- package/tools/project-command.js +198 -194
- package/tools/project-preview.js +1 -148
- package/tools/select-option.js +60 -60
- package/tools/workspace-config.js +145 -0
- package/.prettierrc +0 -5
- package/build/build-dist/script-management.test.js +0 -16
- package/build/docker/compose-command.test.js +0 -148
- package/build/docker/compose-release.test.js +0 -101
- package/build/docker/docker-build-push.test.js +0 -124
- package/build/webpack5/remove-legacy-assets-plugin.js +0 -84
- package/build/webpack5/webpack.base.test.js +0 -59
- package/lib/index.js +0 -6
- package/lib/server/connect.js +0 -3011
- package/lib/server/serve-static.js +0 -4848
- package/module/cjs/deep-merge.cjs +0 -38
- package/script/pts/cloud-scenes.mjs +0 -65
- package/script/pts/cloud.js +0 -151
- package/script/pts/generate-cloud-params.mjs +0 -210
- package/script/pts/generate-cloud-params.test.mjs +0 -67
- package/store/index.js +0 -0
- package/tools/file-export.js +0 -165
- package/tools/project-command.test.js +0 -267
- package/tools/select-option.test.js +0 -52
- package/webpack.config.js +0 -38
- /package/{module → adapters/vue2/module}/Router.js +0 -0
- /package/{build → adapters/vue2}/webpack5/inline-runtime-plugin.js +0 -0
- /package/{script/build → build/build-utils}/env.js +0 -0
- /package/module/cjs/{page-config.cjs → page-config.js} +0 -0
|
@@ -16,6 +16,11 @@ function normalizePathIncludes(pathIncludes) {
|
|
|
16
16
|
return pathIncludes.filter(Boolean).map((path) => String(path));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function matchesConfiguredBaseURL(baseURL, configuredBaseURLs) {
|
|
20
|
+
const normalizedBaseURL = String(baseURL || "").trim().replace(/\/+$/, "");
|
|
21
|
+
return normalizeRuleDomains(configuredBaseURLs).includes(normalizedBaseURL);
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
function resolveInternalServiceURL(url, rules = []) {
|
|
20
25
|
if (!url || !Array.isArray(rules) || rules.length === 0) {
|
|
21
26
|
return null;
|
|
@@ -51,5 +56,6 @@ function resolveInternalServiceURL(url, rules = []) {
|
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
module.exports = {
|
|
59
|
+
matchesConfiguredBaseURL,
|
|
54
60
|
resolveInternalServiceURL
|
|
55
61
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function normalizeErrorPayload(payload) {
|
|
2
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const message = payload.error || payload.detail || payload.message || payload.msg;
|
|
7
|
+
if (message && !payload.error) {
|
|
8
|
+
payload.error = message;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function resolveStatusErrorMessage(status, payload) {
|
|
15
|
+
const backendMessage = normalizeErrorPayload(payload);
|
|
16
|
+
const fallbackMessage = `请求失败(${status})`;
|
|
17
|
+
const statusMessages = {
|
|
18
|
+
400: backendMessage || fallbackMessage,
|
|
19
|
+
401: backendMessage || "登录信息已过期,请重新登录",
|
|
20
|
+
403: "您没有权限访问,请联系管理员",
|
|
21
|
+
500: backendMessage || fallbackMessage,
|
|
22
|
+
502: "网关错误,请稍后重试或联系开发人员",
|
|
23
|
+
503: "服务暂时不可用,请稍后重试",
|
|
24
|
+
504: "网关超时,请稍后重试或联系开发人员",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return statusMessages[status];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
normalizeErrorPayload,
|
|
32
|
+
resolveStatusErrorMessage,
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,92 +1,124 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@infly/libs",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"infly-libs",
|
|
33
|
-
"libs"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@infly/libs",
|
|
3
|
+
"version": "2.0.45",
|
|
4
|
+
"description": "不受前端框架限制的独立工具库",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"bin/",
|
|
10
|
+
"compat/",
|
|
11
|
+
"adapters/vue2/",
|
|
12
|
+
"build/",
|
|
13
|
+
"module/",
|
|
14
|
+
"script/git-automation/",
|
|
15
|
+
"script/index.js",
|
|
16
|
+
"tools/",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"!**/*.test.js",
|
|
20
|
+
"!**/*.test.mjs"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:coverage": "vitest run --coverage",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"check": "vitest run core-entry.test.js",
|
|
27
|
+
"prepublishOnly": "pnpm test",
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"lint:strict": "eslint . --max-warnings 0",
|
|
30
|
+
"postinstall": "node adapters/vue2/postinstall.js",
|
|
31
|
+
"publishPkg": "npm publish --access=public --registry=https://registry.npmjs.org/",
|
|
32
|
+
"preview": "infly-libs --preview",
|
|
33
|
+
"preview:no-build": "infly-libs --preview --no-build",
|
|
34
|
+
"origin:preview": "infly-libs --preview",
|
|
35
|
+
"origin:preview:no-build": "infly-libs --preview --no-build"
|
|
36
|
+
},
|
|
37
|
+
"bin": {
|
|
38
|
+
"infly-libs": "bin/cli.js"
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
".": "./index.js",
|
|
42
|
+
"./adapters/vue2/*": "./adapters/vue2/*",
|
|
43
|
+
"./adapters/vue2/build/*": "./adapters/vue2/build/*",
|
|
44
|
+
"./module/*": "./module/*",
|
|
45
|
+
"./store/*": "./adapters/vue2/store/*",
|
|
46
|
+
"./tools/*": "./tools/*",
|
|
47
|
+
"./build/*": "./build/*",
|
|
48
|
+
"./build/build-utils/*": "./build/build-utils/*",
|
|
49
|
+
"./script/git-automation/*": "./script/git-automation/*"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://gitee.com/gdinfly_1/admin-monorepo.git"
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"infly",
|
|
57
|
+
"infly-libs",
|
|
58
|
+
"libs"
|
|
59
|
+
],
|
|
60
|
+
"author": "Kahal",
|
|
61
|
+
"license": "ISC",
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@infly/ts-libs": "workspace:*",
|
|
64
|
+
"connect": "^3.7.0",
|
|
65
|
+
"enquirer": "^2.4.1",
|
|
66
|
+
"path-browserify": "^1.0.1",
|
|
67
|
+
"serve-static": "^1.15.0",
|
|
68
|
+
"yaml": "^2.3.4"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@babel/core": "^7.23.3",
|
|
72
|
+
"@babel/preset-env": "^7.23.3",
|
|
73
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
74
|
+
"babel-loader": "^10.0.0",
|
|
75
|
+
"vite": "7.0.0",
|
|
76
|
+
"vitest": "^4.0.0",
|
|
77
|
+
"eslint": "^9.0.0",
|
|
78
|
+
"@eslint/js": "^9.0.0",
|
|
79
|
+
"globals": "^15.0.0"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"axios": "^0.27.2",
|
|
83
|
+
"html-webpack-plugin": "^5.5.3"
|
|
84
|
+
},
|
|
85
|
+
"optionalDependencies": {
|
|
86
|
+
"axios": "^0.27.2",
|
|
87
|
+
"html-webpack-plugin": "^5.5.3"
|
|
88
|
+
},
|
|
89
|
+
"infly": {
|
|
90
|
+
"buildConfigs": {
|
|
91
|
+
"buildFoldName": "[构建后目录名] 可选, 默认取值vue.config.js的outputDir, 配置化 eg: example-admin",
|
|
92
|
+
"outputPath": "[输出文件目录链接] eg: ./ ",
|
|
93
|
+
"enabled": "[是否启用压缩] eg: true",
|
|
94
|
+
"gitAuto": "[是否自动提交git] eg: true",
|
|
95
|
+
"gitAutoPushReposBranchMap": {
|
|
96
|
+
"release-eg": "develop-eg [自动提交推送项目构建分支和构建仓库推送分支对应配置,必须]"
|
|
97
|
+
},
|
|
98
|
+
"gitAutoCommitText": "[自动提交文案] eg: build: 更新版本为v{version}, 推送构建文件与zip压缩包 --build by infly-libs",
|
|
99
|
+
"enablePreview": "[是否启用项目预览] eg: true",
|
|
100
|
+
"enableClipboard": "[是否启用粘贴板粘贴git信息] eg: true",
|
|
101
|
+
"openExplorer": "[是否自动打开资源管理器] eg: true",
|
|
102
|
+
"webhookUrl": "[消息推送机器人链接配置] eg: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=",
|
|
103
|
+
"webhookAtUser": [
|
|
104
|
+
"@人手机号"
|
|
105
|
+
],
|
|
106
|
+
"webhookExtraText": "[消息推送额外文案] eg: 麻烦发下版",
|
|
107
|
+
"compressionLevel": 9
|
|
108
|
+
},
|
|
109
|
+
"versionConfig": {
|
|
110
|
+
"mainVersion": "[主版本号] 可选, 默认取值项目package version, eg: 1",
|
|
111
|
+
"links": {
|
|
112
|
+
"master": "[master分支构建文件推送地址] eg: https://example.com",
|
|
113
|
+
"release": "[release分支构建文件推送地址] eg: https://staging.example.com"
|
|
114
|
+
},
|
|
115
|
+
"platformName": "[用以split的项目平台名称] eg: 示例平台-运营端",
|
|
116
|
+
"baseName": "v{version}-{timestamp}.zip",
|
|
117
|
+
"versionList": [],
|
|
118
|
+
"disableUpdateVersionEnv": [
|
|
119
|
+
"development",
|
|
120
|
+
"staging [禁用更新版本号的环境, 比如测试环境构建不需要更新version, 不配置默认禁用stage测试环境]"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -25,7 +25,7 @@ function cloneRepository(url, branch, targetDir) {
|
|
|
25
25
|
* @description
|
|
26
26
|
* eg: package.json
|
|
27
27
|
* {
|
|
28
|
-
"name": "
|
|
28
|
+
"name": "example-monorepo",
|
|
29
29
|
"version": "1.0.0",
|
|
30
30
|
"private": true,
|
|
31
31
|
"projectConfig": {
|
|
@@ -34,9 +34,8 @@ function cloneRepository(url, branch, targetDir) {
|
|
|
34
34
|
"baseGitUrl": "https://gitee.com/gdinfly_1/"
|
|
35
35
|
},
|
|
36
36
|
"workspaces": [
|
|
37
|
-
"apps/
|
|
38
|
-
"apps/
|
|
39
|
-
"apps/postal-benefits-platform-level"
|
|
37
|
+
"apps/example-admin",
|
|
38
|
+
"apps/example-portal"
|
|
40
39
|
]
|
|
41
40
|
}
|
|
42
41
|
*
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { execSync } = require("node:child_process");
|
|
2
|
+
|
|
3
|
+
function configureMergeDriver() {
|
|
4
|
+
try {
|
|
5
|
+
const current = execSync("git config --global merge.ours.driver").toString().trim();
|
|
6
|
+
if (current) {
|
|
7
|
+
console.log(" -> merge.ours.driver 已配置:", current);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
} catch (_) {
|
|
11
|
+
// 未配置,继续设置。
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
execSync("git config --global merge.ours.driver true");
|
|
16
|
+
console.log(" √ merge.ours.driver 配置成功");
|
|
17
|
+
return true;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(" × merge.ours.driver 配置失败:", error.message);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function configureGitAliases() {
|
|
25
|
+
// 预留:后续可在此配置 git alias
|
|
26
|
+
console.log(" -> git aliases 配置完成");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { configureGitAliases, configureMergeDriver };
|
|
@@ -521,20 +521,6 @@ function checkAndUpdateRootPackages(packagesDir, targetBranch = "master") {
|
|
|
521
521
|
stdio: "inherit"
|
|
522
522
|
});
|
|
523
523
|
|
|
524
|
-
// 只同步共享内容,保留当前分支配置和子模块集合
|
|
525
|
-
const mergeScriptPath = path.join(rootDir, "script", "sync-from-branch.sh");
|
|
526
|
-
if (fs.existsSync(mergeScriptPath)) {
|
|
527
|
-
execSync(`bash "${mergeScriptPath}" ${targetBranch}`, {
|
|
528
|
-
cwd: rootDir,
|
|
529
|
-
stdio: "inherit"
|
|
530
|
-
});
|
|
531
|
-
} else {
|
|
532
|
-
// 如果脚本不存在,使用基本的 merge 命令
|
|
533
|
-
execSync(`git merge origin/${targetBranch} --no-edit`, {
|
|
534
|
-
cwd: rootDir,
|
|
535
|
-
stdio: "inherit"
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
524
|
|
|
539
525
|
console.log(global.logColor.success, `✅ admin-monorepo[${currentBranch}]: 已合并 ${targetBranch} 的最新更改到 packages、docs 等目录`);
|
|
540
526
|
return [{ module: "admin-monorepo", success: true }];
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const path = require("node:path");
|
|
2
|
+
const { spawnSync } = require("node:child_process");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 在指定目录执行 git 命令,自动处理 safe.directory
|
|
6
|
+
*/
|
|
7
|
+
function runGit(cwd, args, { allowFailure = false } = {}) {
|
|
8
|
+
const absoluteCwd = path.resolve(cwd);
|
|
9
|
+
const safeDirectory = absoluteCwd.replaceAll("\\", "/");
|
|
10
|
+
const result = spawnSync(
|
|
11
|
+
"git",
|
|
12
|
+
["-c", `safe.directory=${safeDirectory}`, "-C", absoluteCwd, ...args],
|
|
13
|
+
{ encoding: "utf8", windowsHide: true },
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
if (result.status !== 0 && !allowFailure) {
|
|
17
|
+
const detail = (result.stderr || result.stdout || "Git command failed").trim();
|
|
18
|
+
throw new Error(detail);
|
|
19
|
+
}
|
|
20
|
+
if (result.status !== 0 && allowFailure) {
|
|
21
|
+
const detail = String(result.stderr || result.stdout || "").trim();
|
|
22
|
+
if (detail) {
|
|
23
|
+
process.stderr.write(`[submodule:status] git ${args.join(" ")}: ${detail}\n`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result.status === 0 ? result.stdout.trim() : "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 从 .gitmodules 中读取所有已配置的子模块(名称、路径、配置分支)
|
|
32
|
+
*/
|
|
33
|
+
function getConfiguredSubmodules(rootDir) {
|
|
34
|
+
const output = runGit(rootDir, [
|
|
35
|
+
"config",
|
|
36
|
+
"--file",
|
|
37
|
+
".gitmodules",
|
|
38
|
+
"--get-regexp",
|
|
39
|
+
"^submodule\\..*\\.path$",
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
return output.split(/\r?\n/).filter(Boolean).map((line) => {
|
|
43
|
+
const separator = line.search(/\s/);
|
|
44
|
+
const key = line.slice(0, separator);
|
|
45
|
+
const submodulePath = line.slice(separator).trim();
|
|
46
|
+
const name = key.slice("submodule.".length, -".path".length);
|
|
47
|
+
const configuredBranch = runGit(
|
|
48
|
+
rootDir,
|
|
49
|
+
["config", "--file", ".gitmodules", "--get", `submodule.${name}.branch`],
|
|
50
|
+
{ allowFailure: true },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return { name, path: submodulePath, configuredBranch };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 获取主仓 HEAD 中记录的某个子模块指针 commit
|
|
59
|
+
*/
|
|
60
|
+
function getParentPointer(rootDir, submodulePath) {
|
|
61
|
+
const treeEntry = runGit(rootDir, ["ls-tree", "HEAD", "--", submodulePath]);
|
|
62
|
+
return treeEntry ? treeEntry.split(/\s+/)[2] : "";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 检查单个子模块的状态:当前分支、HEAD、指针漂移、远程漂移、是否 dirty
|
|
67
|
+
*/
|
|
68
|
+
function inspectSubmodule(rootDir, submodule) {
|
|
69
|
+
const worktree = path.join(rootDir, submodule.path);
|
|
70
|
+
const pointer = getParentPointer(rootDir, submodule.path);
|
|
71
|
+
const head = runGit(worktree, ["rev-parse", "HEAD"], { allowFailure: true });
|
|
72
|
+
|
|
73
|
+
if (!head) {
|
|
74
|
+
return {
|
|
75
|
+
path: submodule.path,
|
|
76
|
+
branch: "-",
|
|
77
|
+
head: "-",
|
|
78
|
+
pointer: pointer ? pointer.slice(0, 8) : "-",
|
|
79
|
+
originMaster: "-",
|
|
80
|
+
state: "not-initialized",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const branch = runGit(worktree, ["branch", "--show-current"], { allowFailure: true });
|
|
85
|
+
const remoteBranch = submodule.configuredBranch || branch || "master";
|
|
86
|
+
const originHead = runGit(
|
|
87
|
+
worktree,
|
|
88
|
+
["rev-parse", "--verify", `origin/${remoteBranch}`],
|
|
89
|
+
{ allowFailure: true },
|
|
90
|
+
);
|
|
91
|
+
const dirty = Boolean(runGit(worktree, ["status", "--porcelain"], { allowFailure: true }));
|
|
92
|
+
const states = [];
|
|
93
|
+
|
|
94
|
+
if (dirty) states.push("dirty");
|
|
95
|
+
if (pointer && head !== pointer) states.push("pointer-drift");
|
|
96
|
+
if (originHead && head !== originHead) states.push("remote-drift");
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
path: submodule.path,
|
|
100
|
+
branch: branch || "DETACHED",
|
|
101
|
+
head: head.slice(0, 8),
|
|
102
|
+
pointer: pointer ? pointer.slice(0, 8) : "-",
|
|
103
|
+
originMaster: originHead ? originHead.slice(0, 8) : "-",
|
|
104
|
+
state: states.length > 0 ? states.join(",") : "ok",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
getConfiguredSubmodules,
|
|
110
|
+
getParentPointer,
|
|
111
|
+
inspectSubmodule,
|
|
112
|
+
runGit,
|
|
113
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 从 .gitmodules 中解析所有子模块路径
|
|
5
|
+
*/
|
|
6
|
+
function parseGitmodulesPaths(rootDir) {
|
|
7
|
+
const p = require("path").join(rootDir, ".gitmodules");
|
|
8
|
+
if (!fs.existsSync(p)) return [];
|
|
9
|
+
const content = fs.readFileSync(p, "utf8");
|
|
10
|
+
const paths = [];
|
|
11
|
+
content.split(/\[submodule/).forEach((block) => {
|
|
12
|
+
const m = block.match(/path\s*=\s*(.+)/);
|
|
13
|
+
if (m) paths.push(m[1].trim());
|
|
14
|
+
});
|
|
15
|
+
return paths;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = { parseGitmodulesPaths };
|
package/script/index.js
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
module.exports =
|
|
2
|
-
previewList: [
|
|
3
|
-
{
|
|
4
|
-
key: "preview",
|
|
5
|
-
value: "infly-libs --preview"
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
key: "preview:no-build",
|
|
9
|
-
value: "infly-libs --preview --no-build"
|
|
10
|
-
}
|
|
11
|
-
],
|
|
12
|
-
buildList: [
|
|
13
|
-
{
|
|
14
|
-
key: "build:prod",
|
|
15
|
-
value: "infly-libs beforeBuild && vue-cli-service build && infly-libs afterBuild"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
key: "build:stage",
|
|
19
|
-
value: "infly-libs beforeBuild && vue-cli-service build --mode staging && infly-libs afterBuild"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
key: "build:test",
|
|
23
|
-
value: "infly-libs beforeBuild && infly-libs afterBuild"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
};
|
|
1
|
+
module.exports = require("../adapters/vue2/script-config.js");
|
package/tools/auto-export.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 自动导出目录下所有文件
|
|
3
3
|
* @param {Function} requireContext - require.context 返回的函数
|
|
4
|
-
* @param {RegExp} [filePattern=/\.vue$/] - 文件匹配正则
|
|
5
4
|
* @returns {Object} 导出对象,key 为文件名(不含扩展名),value 为模块内容
|
|
6
5
|
*
|
|
7
6
|
* @example
|
|
@@ -15,7 +14,7 @@
|
|
|
15
14
|
* // 或者直接一行
|
|
16
15
|
* Object.assign(module.exports, autoExportFiles(require.context('./', false, /\.vue$/)));
|
|
17
16
|
*/
|
|
18
|
-
function autoExportFiles(requireContext
|
|
17
|
+
function autoExportFiles(requireContext) {
|
|
19
18
|
if (!requireContext || typeof requireContext !== 'function') {
|
|
20
19
|
console.error('autoExportFiles: requireContext 必须是 require.context 返回的函数');
|
|
21
20
|
return {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 异步并发限流器。
|
|
3
|
+
* 对 items 数组中的每一项执行 worker,同时最多运行 concurrency 个 worker。
|
|
4
|
+
*
|
|
5
|
+
* @param {Array} items - 待处理项
|
|
6
|
+
* @param {number} concurrency - 最大并发数
|
|
7
|
+
* @param {Function} worker - 处理函数 (item, index) => Promise
|
|
8
|
+
* @returns {Promise<Array>} 结果数组,索引与 items 一一对应
|
|
9
|
+
*/
|
|
10
|
+
async function runWithConcurrency(items, concurrency, worker) {
|
|
11
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) {
|
|
12
|
+
throw new TypeError("concurrency must be a positive integer");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const results = new Array(items.length);
|
|
16
|
+
let nextIndex = 0;
|
|
17
|
+
const runWorker = async () => {
|
|
18
|
+
while (nextIndex < items.length) {
|
|
19
|
+
const index = nextIndex;
|
|
20
|
+
nextIndex += 1;
|
|
21
|
+
results[index] = await worker(items[index], index);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const workerCount = Math.min(concurrency, items.length);
|
|
26
|
+
await Promise.all(Array.from({ length: workerCount }, runWorker));
|
|
27
|
+
return results;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { runWithConcurrency };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function formatProgressLine({ label, completed, total, path = "" }) {
|
|
2
|
+
const safeTotal = Math.max(total, 1);
|
|
3
|
+
const percentage = total === 0 ? 100 : Math.round((completed / safeTotal) * 100);
|
|
4
|
+
const filled = Math.round(percentage / 5);
|
|
5
|
+
const bar = `${"█".repeat(filled)}${"░".repeat(20 - filled)}`;
|
|
6
|
+
return `${label} [${bar}] ${percentage}% (${completed}/${total})${path ? ` ${path}` : ""}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function createProgressReporter(options = {}) {
|
|
10
|
+
const stream = options.stream || process.stdout;
|
|
11
|
+
const quiet = Boolean(options.quiet);
|
|
12
|
+
const defaultLabels = {
|
|
13
|
+
status: "检查状态",
|
|
14
|
+
deinit: "停用模块",
|
|
15
|
+
init: "模块加载",
|
|
16
|
+
};
|
|
17
|
+
const labels = { ...defaultLabels, ...options.labels };
|
|
18
|
+
return (event) => {
|
|
19
|
+
if (quiet || !labels[event.phase] || event.total === 0) return;
|
|
20
|
+
const line = formatProgressLine({
|
|
21
|
+
...event,
|
|
22
|
+
label: labels[event.phase],
|
|
23
|
+
});
|
|
24
|
+
if (stream.isTTY) {
|
|
25
|
+
stream.write(`\r${line}\x1b[K${event.done || event.completed >= event.total ? "\n" : ""}`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (event.completed === 0 || event.done || event.completed >= event.total) stream.write(`${line}\n`);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function formatSwitchSummary(name, totalMs, dependencyResult, timings) {
|
|
33
|
+
const seconds = (totalMs / 1000).toFixed(1);
|
|
34
|
+
const dependencyLabel = dependencyResult.installed ? ",依赖已更新" : "";
|
|
35
|
+
const summary = `\n✅ ${name}(${seconds}s${dependencyLabel})`;
|
|
36
|
+
if (!timings) return summary;
|
|
37
|
+
const labels = {
|
|
38
|
+
analyze: "分析",
|
|
39
|
+
precheck: "预检",
|
|
40
|
+
status: "状态",
|
|
41
|
+
deinit: "停用",
|
|
42
|
+
init: "加载",
|
|
43
|
+
install: "依赖",
|
|
44
|
+
};
|
|
45
|
+
const phases = Object.entries(labels)
|
|
46
|
+
.filter(([phase]) => Number.isFinite(timings[phase]))
|
|
47
|
+
.map(([phase, label]) => `${label} ${(timings[phase] / 1000).toFixed(1)}s`);
|
|
48
|
+
return phases.length > 0 ? `${summary}\n 阶段: ${phases.join(" | ")}` : summary;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatSlowStatusDetails(details, thresholdMs = 2000) {
|
|
52
|
+
return details
|
|
53
|
+
.filter((detail) => detail.durationMs > thresholdMs)
|
|
54
|
+
.sort((left, right) => right.durationMs - left.durationMs)
|
|
55
|
+
.map((detail) => `${detail.path} ${detail.durationMs}ms`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
createProgressReporter,
|
|
60
|
+
formatProgressLine,
|
|
61
|
+
formatSlowStatusDetails,
|
|
62
|
+
formatSwitchSummary,
|
|
63
|
+
};
|