-
Notifications
You must be signed in to change notification settings - Fork 10
/
ver-pos-os-generator.js
76 lines (67 loc) · 1.8 KB
/
ver-pos-os-generator.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
const fs = require('fs')
const path = require('path')
const {
OSList,
PosRegex,
getVerPosOsJson,
getVerPosLinkOsJson,
getPosOsJson,
Dir,
FileName,
DownloadUrl,
} = require('./constants')
const osVerPosDir = path.join(Dir.base, Dir.verPosOs)
main()
function main() {
let VerPosMap = fs.readFileSync(
path.join(Dir.base, FileName.versionPosition),
'utf8'
)
VerPosMap = JSON.parse(VerPosMap)
Object.keys(VerPosMap).forEach((ver) => {
const pos = VerPosMap[ver]
// remove invalid format
if (!PosRegex.test(pos)) {
delete VerPosMap[ver]
}
})
OSList.forEach((os) => {
let PosArr = fs.readFileSync(
path.join(Dir.base, Dir.position, getPosOsJson(os)),
'utf8'
)
PosArr = JSON.parse(PosArr)
let posMap = {}
PosArr.filter((pos) => PosRegex.test(pos)).forEach((pos) => {
posMap[pos] = pos
})
let verPosMap = {}
Object.keys(VerPosMap).forEach((ver) => {
const pos = VerPosMap[ver]
if (posMap[pos]) {
verPosMap[ver] = pos
}
})
if (!fs.existsSync(osVerPosDir)) {
fs.mkdirSync(osVerPosDir, { recursive: true })
}
fs.writeFileSync(
path.join(osVerPosDir, getVerPosOsJson(os)),
JSON.stringify(verPosMap, null, 2)
)
const verPosLinkMap = Object.keys(verPosMap).reduce((all, item) => {
const pos = verPosMap[item]
all[item] = `${DownloadUrl}${os}/${pos}/`
return all
}, {})
const osVerPosLinkDir = path.join(Dir.base, Dir.verPosOSLink)
if (!fs.existsSync(osVerPosLinkDir)) {
fs.mkdirSync(osVerPosLinkDir, { recursive: true })
}
fs.writeFileSync(
path.join(osVerPosLinkDir, getVerPosLinkOsJson(os)),
JSON.stringify(verPosLinkMap, null, 2)
)
console.log(`${os} finish all -----------------------------`)
})
}