forked from axelpale/openmoji-spritemap-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
64 lines (57 loc) · 1.85 KB
/
run.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
// This runner is meant for customisation and to give an example of
// how multiple sprite sheets can be created with a single command.
//
const mojis = require('./openmoji.json')
const asyn = require('async')
const generate = require('./index')
const generateIndex = require('./lib/htmlIndex')
const path = require('path')
const fs = require('fs')
const MODE = 'png' // out of { 'svg', 'png' }
const EMOJI_DIR_NAME = {
png: 'openmoji-72x72-color',
svg: 'openmoji-svg-color'
}
// Filter out those with long hexcode, like skin tones.
// TODO include skin tones and other variants in some way.
const shortMojis = mojis.filter(moji => moji.hexcode.length <= 5)
// Group emojis by their group name into an object.
// Use the group names as keys.
const mojiGroups = shortMojis.reduce((acc, moji) => {
const groupName = moji.group
if (!acc[groupName]) {
acc[groupName] = []
}
acc[groupName].push(moji)
return acc
}, {})
// Limit all groups to 8 * 16 emojis to avoid bus error 10.
Object.keys(mojiGroups).forEach(groupName => {
mojiGroups[groupName] = mojiGroups[groupName].slice(0, 128)
})
// For each group, run sheet generator.
// Sheet generation is asynchronous operation, thus @caolan/async is used.
asyn.eachSeries(Object.keys(mojiGroups), (groupName, next) => {
const mojiGroup = mojiGroups[groupName]
generate({
mode: MODE,
name: groupName,
emojis: mojiGroup,
emojiDir: path.join(__dirname, EMOJI_DIR_NAME[MODE]),
targetDir: path.join(__dirname, 'target'),
emojiSize: 72,
columns: 8
}, next)
}, (err) => {
if (err) {
console.error(err)
return
}
// Generate an index page to browse the generated sheets.
const indexHtml = generateIndex(mojiGroups, {
mode: MODE
})
const indexPath = path.join(__dirname, 'target', 'index.html')
fs.writeFileSync(indexPath, indexHtml)
console.log('Finished successfully.')
})