@infly/libs 2.7.1 → 2.7.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/adapters/webpack/auto-export.js +53 -53
- package/build/build-utils/deps.js +28 -28
- package/build/build-utils/webhook.js +135 -135
- package/build/docker/release-paths.js +30 -30
- package/build/project-files.js +47 -47
- package/core/async/concurrency.js +29 -29
- package/package.json +2 -2
- package/script/git-automation/check-packages.js +40 -40
- package/script/git-automation/git-clone.js +69 -69
- package/script/git-automation/git-configure.js +29 -29
- package/script/git-automation/git-submodule.js +18 -18
- package/script/git-automation/git-utils.js +59 -59
- package/script/git-automation/submodule-utils.js +16 -16
- package/workspace/config.js +144 -144
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 框架无关的异步并发控制。
|
|
3
|
-
* 异步并发限流器。
|
|
4
|
-
* 对 items 数组中的每一项执行 worker,同时最多运行 concurrency 个 worker。
|
|
5
|
-
*
|
|
6
|
-
* @param {Array} items - 待处理项
|
|
7
|
-
* @param {number} concurrency - 最大并发数
|
|
8
|
-
* @param {Function} worker - 处理函数 (item, index) => Promise
|
|
9
|
-
* @returns {Promise<Array>} 结果数组,索引与 items 一一对应
|
|
10
|
-
*/
|
|
11
|
-
async function runWithConcurrency(items, concurrency, worker) {
|
|
12
|
-
if (!Number.isInteger(concurrency) || concurrency < 1) {
|
|
13
|
-
throw new TypeError("concurrency must be a positive integer");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const results = new Array(items.length);
|
|
17
|
-
let nextIndex = 0;
|
|
18
|
-
const runWorker = async () => {
|
|
19
|
-
while (nextIndex < items.length) {
|
|
20
|
-
const index = nextIndex;
|
|
21
|
-
nextIndex += 1;
|
|
22
|
-
results[index] = await worker(items[index], index);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const workerCount = Math.min(concurrency, items.length);
|
|
27
|
-
await Promise.all(Array.from({ length: workerCount }, runWorker));
|
|
28
|
-
return results;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = { runWithConcurrency };
|
|
3
|
+
* 异步并发限流器。
|
|
4
|
+
* 对 items 数组中的每一项执行 worker,同时最多运行 concurrency 个 worker。
|
|
5
|
+
*
|
|
6
|
+
* @param {Array} items - 待处理项
|
|
7
|
+
* @param {number} concurrency - 最大并发数
|
|
8
|
+
* @param {Function} worker - 处理函数 (item, index) => Promise
|
|
9
|
+
* @returns {Promise<Array>} 结果数组,索引与 items 一一对应
|
|
10
|
+
*/
|
|
11
|
+
async function runWithConcurrency(items, concurrency, worker) {
|
|
12
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) {
|
|
13
|
+
throw new TypeError("concurrency must be a positive integer");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const results = new Array(items.length);
|
|
17
|
+
let nextIndex = 0;
|
|
18
|
+
const runWorker = async () => {
|
|
19
|
+
while (nextIndex < items.length) {
|
|
20
|
+
const index = nextIndex;
|
|
21
|
+
nextIndex += 1;
|
|
22
|
+
results[index] = await worker(items[index], index);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const workerCount = Math.min(concurrency, items.length);
|
|
27
|
+
await Promise.all(Array.from({ length: workerCount }, runWorker));
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { runWithConcurrency };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infly/libs",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "不受前端框架限制的独立工具库",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"author": "Kahal",
|
|
69
69
|
"license": "ISC",
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@infly/ts-libs": "^1.0.
|
|
71
|
+
"@infly/ts-libs": "^1.0.2",
|
|
72
72
|
"connect": "^3.7.0",
|
|
73
73
|
"dotenv": "16.6.1",
|
|
74
74
|
"enquirer": "^2.4.1",
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
const { logTerminal } = require("../../cli/terminal-style");
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { checkAndUpdatePackages } = require('./index');
|
|
4
|
-
|
|
5
|
-
// 设置基本的日志颜色
|
|
6
|
-
/**
|
|
7
|
-
* 主函数:检查 packages 并处理
|
|
8
|
-
*/
|
|
9
|
-
async function main() {
|
|
10
|
-
// packages 目录路径(相对于当前脚本的位置)
|
|
11
|
-
const packagesDir = path.resolve(__dirname, '../../../../packages');
|
|
12
|
-
|
|
13
|
-
logTerminal("info", `\n开始检查 packages 目录: ${packagesDir}\n`);
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
// 执行完整的检查和更新流程
|
|
17
|
-
// 如果有未提交代码会自动中止并退出进程
|
|
18
|
-
// 如果没有问题会自动切换到 master 分支并拉取最新代码
|
|
19
|
-
await checkAndUpdatePackages(packagesDir, 'master');
|
|
20
|
-
|
|
21
|
-
logTerminal("success", `\npackages 检查和更新完成,可以继续执行后续操作!\n`);
|
|
22
|
-
|
|
23
|
-
// 在这里可以继续执行你的其他逻辑
|
|
24
|
-
// 比如构建、发布等操作
|
|
25
|
-
|
|
26
|
-
} catch (error) {
|
|
27
|
-
logTerminal("error", `\n执行失败: ${error.message}\n`);
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 如果直接运行此文件,则执行主函数
|
|
33
|
-
if (require.main === module) {
|
|
34
|
-
main().catch(error => {
|
|
35
|
-
logTerminal("error", `\n执行失败: ${error.message}\n`);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = { main };
|
|
1
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { checkAndUpdatePackages } = require('./index');
|
|
4
|
+
|
|
5
|
+
// 设置基本的日志颜色
|
|
6
|
+
/**
|
|
7
|
+
* 主函数:检查 packages 并处理
|
|
8
|
+
*/
|
|
9
|
+
async function main() {
|
|
10
|
+
// packages 目录路径(相对于当前脚本的位置)
|
|
11
|
+
const packagesDir = path.resolve(__dirname, '../../../../packages');
|
|
12
|
+
|
|
13
|
+
logTerminal("info", `\n开始检查 packages 目录: ${packagesDir}\n`);
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// 执行完整的检查和更新流程
|
|
17
|
+
// 如果有未提交代码会自动中止并退出进程
|
|
18
|
+
// 如果没有问题会自动切换到 master 分支并拉取最新代码
|
|
19
|
+
await checkAndUpdatePackages(packagesDir, 'master');
|
|
20
|
+
|
|
21
|
+
logTerminal("success", `\npackages 检查和更新完成,可以继续执行后续操作!\n`);
|
|
22
|
+
|
|
23
|
+
// 在这里可以继续执行你的其他逻辑
|
|
24
|
+
// 比如构建、发布等操作
|
|
25
|
+
|
|
26
|
+
} catch (error) {
|
|
27
|
+
logTerminal("error", `\n执行失败: ${error.message}\n`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 如果直接运行此文件,则执行主函数
|
|
33
|
+
if (require.main === module) {
|
|
34
|
+
main().catch(error => {
|
|
35
|
+
logTerminal("error", `\n执行失败: ${error.message}\n`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = { main };
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
const { logTerminal } = require("../../cli/terminal-style");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const { execSync } = require("child_process");
|
|
5
|
-
|
|
6
|
-
// 读取配置文件
|
|
7
|
-
const projectRoot = process.cwd().replace(/\\node_modules.*$/g, "");
|
|
8
|
-
const projectPkgPath = path.resolve(projectRoot, "package.json");
|
|
9
|
-
const config = JSON.parse(fs.readFileSync(projectPkgPath, "utf-8"));
|
|
10
|
-
const { projectConfig } = config || {};
|
|
11
|
-
const { autoCloneProject, gitBranch, baseGitUrl } = projectConfig || {};
|
|
12
|
-
|
|
13
|
-
function cloneRepository(url, branch, targetDir) {
|
|
14
|
-
try {
|
|
15
|
-
execSync(`git clone -b ${branch} ${url} ${targetDir}`);
|
|
16
|
-
logTerminal("success", `项目克隆成功: ${path.basename(targetDir)}`);
|
|
17
|
-
} catch (err) {
|
|
18
|
-
logTerminal("error", `项目克隆失败: ${url} ${err.message}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 批量克隆项目
|
|
24
|
-
* @param {Array} projects
|
|
25
|
-
* @returns
|
|
26
|
-
* @description
|
|
27
|
-
* eg: package.json
|
|
28
|
-
* {
|
|
29
|
-
"name": "example-monorepo",
|
|
30
|
-
"version": "1.0.0",
|
|
31
|
-
"private": true,
|
|
32
|
-
"projectConfig": {
|
|
33
|
-
"autoCloneProject": true,
|
|
34
|
-
"gitBranch": "master",
|
|
35
|
-
"baseGitUrl": "https://gitee.com/gdinfly_1/"
|
|
36
|
-
},
|
|
37
|
-
"workspaces": [
|
|
38
|
-
"apps/example-admin",
|
|
39
|
-
"apps/example-portal"
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
function batchCloneProject(projects = config.workspaces || [], autoClone = autoCloneProject) {
|
|
45
|
-
if (typeof autoClone === "boolean" && !autoClone) {
|
|
46
|
-
process.exit(0);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (autoClone) {
|
|
50
|
-
if (!Array.isArray(projects) || projects.length === 0) {
|
|
51
|
-
logTerminal("warning", "没有可克隆的项目或配置错误。");
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
logTerminal("info", `项目克隆开始 =======>`);
|
|
55
|
-
projects.forEach((repo = "") => {
|
|
56
|
-
const [targetFileDir = "", projectName = ""] = repo.split("/");
|
|
57
|
-
const repoUrl = baseGitUrl + projectName + ".git";
|
|
58
|
-
const targetDir = path.resolve(projectRoot, repo);
|
|
59
|
-
cloneRepository(repoUrl, gitBranch, targetDir);
|
|
60
|
-
});
|
|
61
|
-
logTerminal("info", `项目克隆完成 =======>`);
|
|
62
|
-
process.exit(0);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = {
|
|
67
|
-
cloneRepository,
|
|
68
|
-
batchCloneProject
|
|
69
|
-
};
|
|
1
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
|
|
6
|
+
// 读取配置文件
|
|
7
|
+
const projectRoot = process.cwd().replace(/\\node_modules.*$/g, "");
|
|
8
|
+
const projectPkgPath = path.resolve(projectRoot, "package.json");
|
|
9
|
+
const config = JSON.parse(fs.readFileSync(projectPkgPath, "utf-8"));
|
|
10
|
+
const { projectConfig } = config || {};
|
|
11
|
+
const { autoCloneProject, gitBranch, baseGitUrl } = projectConfig || {};
|
|
12
|
+
|
|
13
|
+
function cloneRepository(url, branch, targetDir) {
|
|
14
|
+
try {
|
|
15
|
+
execSync(`git clone -b ${branch} ${url} ${targetDir}`);
|
|
16
|
+
logTerminal("success", `项目克隆成功: ${path.basename(targetDir)}`);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
logTerminal("error", `项目克隆失败: ${url} ${err.message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 批量克隆项目
|
|
24
|
+
* @param {Array} projects
|
|
25
|
+
* @returns
|
|
26
|
+
* @description
|
|
27
|
+
* eg: package.json
|
|
28
|
+
* {
|
|
29
|
+
"name": "example-monorepo",
|
|
30
|
+
"version": "1.0.0",
|
|
31
|
+
"private": true,
|
|
32
|
+
"projectConfig": {
|
|
33
|
+
"autoCloneProject": true,
|
|
34
|
+
"gitBranch": "master",
|
|
35
|
+
"baseGitUrl": "https://gitee.com/gdinfly_1/"
|
|
36
|
+
},
|
|
37
|
+
"workspaces": [
|
|
38
|
+
"apps/example-admin",
|
|
39
|
+
"apps/example-portal"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
function batchCloneProject(projects = config.workspaces || [], autoClone = autoCloneProject) {
|
|
45
|
+
if (typeof autoClone === "boolean" && !autoClone) {
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (autoClone) {
|
|
50
|
+
if (!Array.isArray(projects) || projects.length === 0) {
|
|
51
|
+
logTerminal("warning", "没有可克隆的项目或配置错误。");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
logTerminal("info", `项目克隆开始 =======>`);
|
|
55
|
+
projects.forEach((repo = "") => {
|
|
56
|
+
const [targetFileDir = "", projectName = ""] = repo.split("/");
|
|
57
|
+
const repoUrl = baseGitUrl + projectName + ".git";
|
|
58
|
+
const targetDir = path.resolve(projectRoot, repo);
|
|
59
|
+
cloneRepository(repoUrl, gitBranch, targetDir);
|
|
60
|
+
});
|
|
61
|
+
logTerminal("info", `项目克隆完成 =======>`);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = {
|
|
67
|
+
cloneRepository,
|
|
68
|
+
batchCloneProject
|
|
69
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
const { execSync } = require("node:child_process");
|
|
2
|
-
const { logTerminal } = require("../../cli/terminal-style");
|
|
3
|
-
|
|
4
|
-
function configureMergeDriver() {
|
|
5
|
-
try {
|
|
6
|
-
const current = execSync("git config --global merge.ours.driver").toString().trim();
|
|
7
|
-
if (current) {
|
|
8
|
-
logTerminal("success", " merge.ours.driver 已配置:", current);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
} catch (_) {
|
|
12
|
-
// 未配置,继续设置。
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
execSync("git config --global merge.ours.driver true");
|
|
17
|
-
logTerminal("success", " merge.ours.driver 配置成功");
|
|
18
|
-
return true;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error(" × merge.ours.driver 配置失败:", error.message);
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function configureGitAliases() {
|
|
26
|
-
// 预留:后续可在此配置 git alias
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = { configureGitAliases, configureMergeDriver };
|
|
1
|
+
const { execSync } = require("node:child_process");
|
|
2
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
3
|
+
|
|
4
|
+
function configureMergeDriver() {
|
|
5
|
+
try {
|
|
6
|
+
const current = execSync("git config --global merge.ours.driver").toString().trim();
|
|
7
|
+
if (current) {
|
|
8
|
+
logTerminal("success", " merge.ours.driver 已配置:", current);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
} catch (_) {
|
|
12
|
+
// 未配置,继续设置。
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
execSync("git config --global merge.ours.driver true");
|
|
17
|
+
logTerminal("success", " merge.ours.driver 配置成功");
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(" × merge.ours.driver 配置失败:", error.message);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function configureGitAliases() {
|
|
26
|
+
// 预留:后续可在此配置 git alias
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { configureGitAliases, configureMergeDriver };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
const { logTerminal } = require("../../cli/terminal-style");
|
|
2
|
-
const { execSync } = require("child_process");
|
|
3
|
-
|
|
4
|
-
function submoduleInit() {
|
|
5
|
-
try {
|
|
6
|
-
execSync("git submodule update --init --recursive", { stdio: "inherit" });
|
|
7
|
-
logTerminal("success", "Git子模块初始化完成");
|
|
8
|
-
} catch (error) {
|
|
9
|
-
logTerminal("error", "Git命令执行失败:", error.message);
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
submoduleInit();
|
|
15
|
-
|
|
16
|
-
module.exports = {
|
|
17
|
-
submoduleInit
|
|
18
|
-
};
|
|
1
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
2
|
+
const { execSync } = require("child_process");
|
|
3
|
+
|
|
4
|
+
function submoduleInit() {
|
|
5
|
+
try {
|
|
6
|
+
execSync("git submodule update --init --recursive", { stdio: "inherit" });
|
|
7
|
+
logTerminal("success", "Git子模块初始化完成");
|
|
8
|
+
} catch (error) {
|
|
9
|
+
logTerminal("error", "Git命令执行失败:", error.message);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
submoduleInit();
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
submoduleInit
|
|
18
|
+
};
|
|
@@ -1,63 +1,63 @@
|
|
|
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
|
-
|
|
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
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
|
-
}
|
|
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
61
|
}
|
|
62
62
|
|
|
63
63
|
function resolveGitWorktreeRoot(cwd) {
|
|
@@ -3,20 +3,20 @@ const fs = require("fs");
|
|
|
3
3
|
function normalizeRelativePath(value) {
|
|
4
4
|
return String(value).replace(/\\/g, "/");
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 从 .gitmodules 中解析所有子模块路径
|
|
9
|
-
*/
|
|
10
|
-
function parseGitmodulesPaths(rootDir) {
|
|
11
|
-
const p = require("path").join(rootDir, ".gitmodules");
|
|
12
|
-
if (!fs.existsSync(p)) return [];
|
|
13
|
-
const content = fs.readFileSync(p, "utf8");
|
|
14
|
-
const paths = [];
|
|
15
|
-
content.split(/\[submodule/).forEach((block) => {
|
|
16
|
-
const m = block.match(/path\s*=\s*(.+)/);
|
|
17
|
-
if (m) paths.push(m[1].trim());
|
|
18
|
-
});
|
|
19
|
-
return paths;
|
|
20
|
-
}
|
|
21
|
-
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 从 .gitmodules 中解析所有子模块路径
|
|
9
|
+
*/
|
|
10
|
+
function parseGitmodulesPaths(rootDir) {
|
|
11
|
+
const p = require("path").join(rootDir, ".gitmodules");
|
|
12
|
+
if (!fs.existsSync(p)) return [];
|
|
13
|
+
const content = fs.readFileSync(p, "utf8");
|
|
14
|
+
const paths = [];
|
|
15
|
+
content.split(/\[submodule/).forEach((block) => {
|
|
16
|
+
const m = block.match(/path\s*=\s*(.+)/);
|
|
17
|
+
if (m) paths.push(m[1].trim());
|
|
18
|
+
});
|
|
19
|
+
return paths;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
22
|
module.exports = { normalizeRelativePath, parseGitmodulesPaths };
|