-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathversion.js
More file actions
55 lines (50 loc) · 1.98 KB
/
Copy pathversion.js
File metadata and controls
55 lines (50 loc) · 1.98 KB
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
try {
const buidDate = new Date().toLocaleString();
const commitId = execSync('git rev-parse HEAD').toString().trim().substring(0, 8);
const moduleCommitInfo = { 'web': commitId };
const commercialModulePath = path.join(__dirname, './src/commercial-module');
const communityModulsPath = path.join(__dirname, './src/community-module');
// 遍历 commercial-module 文件夹中的所有子文件夹
if (fs.existsSync(commercialModulePath)) {
fs.readdirSync(commercialModulePath).forEach((folder) => {
const modulePath = path.join(commercialModulePath, folder);
if (fs.lstatSync(modulePath).isDirectory()) {
try {
// 进入每个模块文件夹并获取最新的 commitId
const commitId = execSync('git rev-parse HEAD', { cwd: modulePath }).toString().trim().substring(0, 8);
moduleCommitInfo[folder] = commitId;
} catch (err) {
console.error(`Error fetching commitId for ${folder}:`, err);
}
}
});
}
// 遍历 community-module 文件夹中的所有子文件夹
if (fs.existsSync(communityModulsPath)) {
fs.readdirSync(communityModulsPath).forEach((folder) => {
const modulePath = path.join(communityModulsPath, folder);
if (fs.lstatSync(modulePath).isDirectory()) {
try {
// 进入每个模块文件夹并获取最新的 commitId
const commitId = execSync('git rev-parse HEAD', { cwd: modulePath }).toString().trim().substring(0, 8);
moduleCommitInfo[folder] = commitId;
} catch (err) {
console.error(`Error fetching commitId for ${folder}:`, err);
}
}
});
}
fs.writeFile('./public/version.md', JSON.stringify({ 'version': moduleCommitInfo, 'fcd': buidDate }), err => {
if (err) {
console.error(err);
return;
}
//文件写入成功。
});
} catch (error) {
console.error(error);
//
}