-
Notifications
You must be signed in to change notification settings - Fork 5
/
createJsonOutput.js
70 lines (58 loc) · 1.73 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
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require('fs')
function getDirContents(p) {
return fs.readdirSync(p, function (err, files) {
var retArr = []
files.forEach(f => retArr.push(f))
return retArr
})
}
const keyArr = new Set(...[
[
...getDirContents('device'),
...getDirContents('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 (fs.existsSync(`device-lowres/${key}.png`)) lowresExists = true
if (fs.existsSync(`device/${key}.png`)) pngExists = true
if (fs.existsSync(`device/${key}/0.png`)) folderExists = true
if (folderExists) {
const folderContents = getDirContents(`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.map(x => x.dark).filter(x => x).length > 0,
index: images
})
continue
}
if (pngExists || lowresExists) {
retArr.push({
key: key,
count: 1,
dark: false,
index: [{
id: 0,
dark: false
}]
})
continue
}
}
if (!fs.existsSync('out')) fs.mkdirSync('out')
fs.writeFile('out/main.json', JSON.stringify(retArr), (err) => {
if (err) console.log(err)
})