-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenReadMe.js
102 lines (84 loc) · 2.81 KB
/
genReadMe.js
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
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
93
94
95
96
97
98
99
100
101
102
const fs = require('fs').promises;
function versionNumberCompare(a, b) {
const splitA = a.split('.');
const splitB = b.split('.');
const majorA = parseInt(splitA[0]);
const majorB = parseInt(splitB[0]);
if (majorA !== majorB) {
return majorB - majorA;
}
const minorA = splitA[1] ? parseInt(splitA[1]) : 0;
const minorB = splitB[1] ? parseInt(splitB[1]) : 0;
return minorB - minorA;
}
function getCurrentFormattedTime() {
const current = new Date();
// 获取本地时间与 UTC 时间的分钟差
const timezoneOffsetInMinutes = current.getTimezoneOffset();
// 将本地时间根据 UTC 时间和目标时区得到 UTC+8 时间
const utcPlus8OffsetInMinutes = -8 * 60; // UTC+8 时区值
const targetOffsetInMinutes = timezoneOffsetInMinutes - utcPlus8OffsetInMinutes;
const targetTimestamp = current.getTime() + targetOffsetInMinutes * 60000;
const targetDate = new Date(targetTimestamp);
const year = targetDate.getFullYear();
const month = String(targetDate.getMonth() + 1).padStart(2, '0');
const day = String(targetDate.getDate()).padStart(2, '0');
const hours = String(targetDate.getHours()).padStart(2, '0');
const minutes = String(targetDate.getMinutes()).padStart(2, '0');
const seconds = String(targetDate.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
async function generateSortedUnityVersionsLinksTable(unityVersions) {
const sortedUnityVersions = unityVersions.sort(versionNumberCompare);
const rows = Math.ceil(sortedUnityVersions.length / 5);
let table = "# UnityReleaseNotes\n"
table += `**Last update time : \`${getCurrentFormattedTime()}\`\tPowered By ChatGPT**\n\n`
table += `## More Unity Versions \n`
var columns = 9;
for(var i = 0;i < columns;++i)
{
table += "| " //todo
}
table += "|\n";
for(var i = 0;i < columns;++i)
{
table += "|:-"
}
table += "|\n";
var end = false;
for (let i = 0; i < rows; i++) {
let row = '';
for (let j = 0; j < columns; j++) {
const index = i * columns + j;
if (index < sortedUnityVersions.length) {
const version = sortedUnityVersions[index];
const link = `./merge_htmls/${version}.md`;
if(j == 0)
{
row += "|";
}
row += ` [${version}](${link}) |`;
} else {
if(j == 0) {
end = true
break
}
else {
row += ' |';
}
}
}
if(!end)
{
table += row + '\n';
}
}
var version = "2020.3";
//var filePath = `./merge_htmls/${sortedUnityVersions[0]}.md`;
var filePath = `./merge_htmls/${version}.md`;
const fileContent = await fs.readFile(filePath, 'utf8');
table += `\n## ${version}\n\n`
table += fileContent;
return table;
}
module.exports = generateSortedUnityVersionsLinksTable;