forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerger.js
More file actions
30 lines (29 loc) · 958 Bytes
/
merger.js
File metadata and controls
30 lines (29 loc) · 958 Bytes
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
const fs = require('fs')
const path = require('path')
function merger (inputPath, buildPath) {
const P = path.join(__dirname, inputPath)
console.log(P)
const result = {}
fs.readdir(P, (_err, files) => {
let totalImages = 0
files.forEach((file) => {
totalImages += 1
})
let loadedImages = 0
files.forEach((file) => {
const name = file.substr(0, file.length - 5)
const filePath = path.join(P, file)
fs.readFile(filePath, (err, data) => {
loadedImages += 1
if (err) throw err
data = JSON.parse(data)
result[name] = data
if (loadedImages === totalImages) {
fs.writeFileSync(path.join(__dirname, buildPath), JSON.stringify(result, null, 4))
}
})
})
})
}
merger('../assets/pack/assets/minecraft/models/block', '../src/assets/blocks/models.json')
merger('../assets/pack/assets/minecraft/blockstates', '../src/assets/blocks/blockStates.json')