forked from 17thshard/roshar-map
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert-textures.js
60 lines (51 loc) · 1.67 KB
/
convert-textures.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
/* eslint-disable no-console */
const childProcess = require('child_process')
const imagemin = require('imagemin')
const imageminWebp = require('imagemin-webp')
const imageminZopfli = require('imagemin-zopfli')
const textures = {
map_bg: { lossy: true },
map: { hqAvailable: true },
shadesmar_map_bg: { lossy: true },
transition: {},
text_pattern: {},
map_text: { hqAvailable: true },
shadesmar_map_text: { hqAvailable: true },
hover_text: {},
factions: { hqAvailable: true },
oathgate_text: { hqAvailable: true }
}
const basePath = './public/img/textures'
Promise.all(Object.keys(textures).flatMap((name) => {
const texture = textures[name]
const files = [`${basePath}/${name}.png`]
if (texture.hqAvailable === true) {
files.push(`${basePath}/hq_${name}.png`)
}
const changedFiles = files.filter(path => childProcess.execSync(`git status -s ${path}`).toString().length > 0)
if (changedFiles.length === 0) {
console.log(`Files for texture '${name}' haven't changed, ignoring...`)
return
}
console.log(`Optimizing and converting texture '${name}'...`)
return imagemin(changedFiles, {
destination: basePath,
plugins: [
imageminZopfli({ more: true })
]
}).then(() => {
console.log(`Optimized PNGs for texture '${name}'`)
return imagemin(changedFiles, {
destination: basePath,
plugins: [
imageminWebp({ quality: texture.lossy === true ? 90 : 100, lossless: texture.lossy !== true })
]
})
}).then(() => {
console.log(`Converted texture '${name}' to WEBP`)
})
})).catch((error) => {
console.error(error)
}).then(() => {
console.log('All textures optimized and converted successfully')
})