@infly/libs 2.7.0 → 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/README.md +3 -1
- package/adapters/webpack/auto-export.js +53 -53
- package/build/build-dist/index.js +18 -23
- package/build/build-utils/deps.js +28 -28
- package/build/build-utils/webhook.js +135 -135
- package/build/docker/deployment/release.sh +20 -1
- 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 +4 -4
- 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/index.js +136 -87
- package/script/git-automation/submodule-utils.js +16 -16
- package/workspace/config.js +144 -144
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const fs = require("node:fs");
|
|
2
|
-
const path = require("node:path");
|
|
3
|
-
|
|
4
|
-
function inside(root, relative) {
|
|
5
|
-
if (typeof relative !== "string" || !relative || path.isAbsolute(relative)) throw new Error(`必须配置相对路径: ${relative}`);
|
|
6
|
-
const result = path.resolve(root, relative);
|
|
7
|
-
const offset = path.relative(root, result);
|
|
8
|
-
if (offset === ".." || offset.startsWith(`..${path.sep}`)) throw new Error(`路径越界: ${relative}`);
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function confinedPath(root, relative, io = fs) {
|
|
13
|
-
const candidate = inside(root, relative);
|
|
14
|
-
let existing = candidate;
|
|
15
|
-
while (existing !== root && !io.existsSync(existing)) {
|
|
16
|
-
if (io.lstatSync) {
|
|
17
|
-
try {
|
|
18
|
-
if (io.lstatSync(existing).isSymbolicLink()) throw new Error(`无法解析链接路径: ${relative}`);
|
|
19
|
-
} catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
20
|
-
}
|
|
21
|
-
existing = path.dirname(existing);
|
|
22
|
-
}
|
|
23
|
-
if (io.realpathSync && io.existsSync(existing)) {
|
|
24
|
-
const offset = path.relative(io.realpathSync(root), io.realpathSync(existing));
|
|
25
|
-
if (offset === ".." || offset.startsWith(`..${path.sep}`) || path.isAbsolute(offset)) throw new Error(`链接路径越界: ${relative}`);
|
|
26
|
-
}
|
|
27
|
-
return candidate;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = { inside, confinedPath };
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
|
|
4
|
+
function inside(root, relative) {
|
|
5
|
+
if (typeof relative !== "string" || !relative || path.isAbsolute(relative)) throw new Error(`必须配置相对路径: ${relative}`);
|
|
6
|
+
const result = path.resolve(root, relative);
|
|
7
|
+
const offset = path.relative(root, result);
|
|
8
|
+
if (offset === ".." || offset.startsWith(`..${path.sep}`)) throw new Error(`路径越界: ${relative}`);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function confinedPath(root, relative, io = fs) {
|
|
13
|
+
const candidate = inside(root, relative);
|
|
14
|
+
let existing = candidate;
|
|
15
|
+
while (existing !== root && !io.existsSync(existing)) {
|
|
16
|
+
if (io.lstatSync) {
|
|
17
|
+
try {
|
|
18
|
+
if (io.lstatSync(existing).isSymbolicLink()) throw new Error(`无法解析链接路径: ${relative}`);
|
|
19
|
+
} catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
20
|
+
}
|
|
21
|
+
existing = path.dirname(existing);
|
|
22
|
+
}
|
|
23
|
+
if (io.realpathSync && io.existsSync(existing)) {
|
|
24
|
+
const offset = path.relative(io.realpathSync(root), io.realpathSync(existing));
|
|
25
|
+
if (offset === ".." || offset.startsWith(`..${path.sep}`) || path.isAbsolute(offset)) throw new Error(`链接路径越界: ${relative}`);
|
|
26
|
+
}
|
|
27
|
+
return candidate;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { inside, confinedPath };
|
package/build/project-files.js
CHANGED
|
@@ -3,53 +3,53 @@ const path = require("path");
|
|
|
3
3
|
|
|
4
4
|
// 兼容旧 tools/file-process.js 的 __dirname 路径语义。
|
|
5
5
|
const legacyToolsDir = path.resolve(__dirname, "../tools");
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 覆盖写入构建脚本
|
|
9
|
-
* @param {String} filePath - 覆盖文件路径
|
|
10
|
-
* @param {Array | Object} scriptsList - 写入脚本配置
|
|
11
|
-
* @param {String} 更新字段值
|
|
12
|
-
*/
|
|
13
|
-
function scriptWrite(filePath, scriptsList, updateKey = "scripts") {
|
|
14
|
-
const pkg = JSON.parse(fs.readFileSync(filePath));
|
|
15
|
-
pkg[updateKey] = pkg[updateKey] || {};
|
|
16
|
-
if (Array.isArray(scriptsList)) {
|
|
17
|
-
scriptsList.forEach(item => {
|
|
18
|
-
if (pkg[updateKey][item.key]) {
|
|
19
|
-
pkg[updateKey][`origin:${item.key}`] = pkg[updateKey][item.key];
|
|
20
|
-
}
|
|
21
|
-
pkg[updateKey][item.key] = item.value;
|
|
22
|
-
});
|
|
23
|
-
} else if (typeof scriptsList === "object") {
|
|
24
|
-
pkg[updateKey] = scriptsList;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 获取文件绝对路径
|
|
32
|
-
* @param {String} filePath - 文件路径
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
function targetProjectFileResolve(filePath) {
|
|
36
|
-
// 初始脚本自动执行路径会自动读取node_modules
|
|
37
|
-
const projectRoot = process.cwd();
|
|
38
|
-
const absoluteProjectRoot = projectRoot.replace(/\\node_modules.*$/g, "");
|
|
39
|
-
return path.resolve(absoluteProjectRoot, filePath);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 获取文件绝对路径
|
|
44
|
-
* @param {String} filePath - 文件路径
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 覆盖写入构建脚本
|
|
9
|
+
* @param {String} filePath - 覆盖文件路径
|
|
10
|
+
* @param {Array | Object} scriptsList - 写入脚本配置
|
|
11
|
+
* @param {String} 更新字段值
|
|
12
|
+
*/
|
|
13
|
+
function scriptWrite(filePath, scriptsList, updateKey = "scripts") {
|
|
14
|
+
const pkg = JSON.parse(fs.readFileSync(filePath));
|
|
15
|
+
pkg[updateKey] = pkg[updateKey] || {};
|
|
16
|
+
if (Array.isArray(scriptsList)) {
|
|
17
|
+
scriptsList.forEach(item => {
|
|
18
|
+
if (pkg[updateKey][item.key]) {
|
|
19
|
+
pkg[updateKey][`origin:${item.key}`] = pkg[updateKey][item.key];
|
|
20
|
+
}
|
|
21
|
+
pkg[updateKey][item.key] = item.value;
|
|
22
|
+
});
|
|
23
|
+
} else if (typeof scriptsList === "object") {
|
|
24
|
+
pkg[updateKey] = scriptsList;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 获取文件绝对路径
|
|
32
|
+
* @param {String} filePath - 文件路径
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
function targetProjectFileResolve(filePath) {
|
|
36
|
+
// 初始脚本自动执行路径会自动读取node_modules
|
|
37
|
+
const projectRoot = process.cwd();
|
|
38
|
+
const absoluteProjectRoot = projectRoot.replace(/\\node_modules.*$/g, "");
|
|
39
|
+
return path.resolve(absoluteProjectRoot, filePath);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 获取文件绝对路径
|
|
44
|
+
* @param {String} filePath - 文件路径
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
47
|
function currentProjectFileResolve(filePath) {
|
|
48
48
|
return path.join(legacyToolsDir, filePath);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
module.exports = {
|
|
52
|
-
scriptWrite,
|
|
53
|
-
targetProjectFileResolve,
|
|
54
|
-
currentProjectFileResolve
|
|
55
|
-
};
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
scriptWrite,
|
|
53
|
+
targetProjectFileResolve,
|
|
54
|
+
currentProjectFileResolve
|
|
55
|
+
};
|
|
@@ -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",
|
|
@@ -90,11 +90,11 @@
|
|
|
90
90
|
"@vitest/coverage-v8": "4.1.10"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
|
-
"axios": "^0.
|
|
93
|
+
"axios": "^0.35.0",
|
|
94
94
|
"html-webpack-plugin": "^5.5.3"
|
|
95
95
|
},
|
|
96
96
|
"optionalDependencies": {
|
|
97
|
-
"axios": "^0.
|
|
97
|
+
"axios": "^0.35.0",
|
|
98
98
|
"html-webpack-plugin": "^5.5.3"
|
|
99
99
|
},
|
|
100
100
|
"infly": {
|
|
@@ -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
|
+
};
|