-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreateJsonOutput.js
58 lines (48 loc) · 1.5 KB
/
createJsonOutput.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
import { readdirSync, existsSync, mkdirSync, writeFileSync } from 'fs'
const keyArr = new Set(...[
[
...readdirSync('device'),
...readdirSync('device-lowres')
].filter(x => x != '.DS_Store')
.map(x => x.includes('.') ? x.split('.').slice(0,-1).join('.') : x) // Remove file extension
])
let retArr = []
for (const key of keyArr) {
let lowresExists = false
let pngExists = false
let folderExists = false
if (existsSync(`device-lowres/${key}.png`)) lowresExists = true
if (existsSync(`device/${key}.png`)) pngExists = true
if (existsSync(`device/${key}/0.png`)) folderExists = true
if (folderExists) {
const folderContents = readdirSync(`device/${key}`)
let images = []
for (let i = 0;; i++) {
if (folderContents.includes(`${i}.png`)) images.push({
id: i,
dark: folderContents.includes(`${i}_dark.png`)
})
else break
}
retArr.push({
key: key,
count: images.length,
dark: images.filter(x => x.dark).length > 0,
index: images
})
continue
}
if (pngExists || lowresExists) {
retArr.push({
key: key,
count: 1,
dark: false,
index: [{
id: 0,
dark: false
}]
})
}
}
if (!existsSync('out')) mkdirSync('out')
writeFileSync('out/main.json', JSON.stringify(retArr))