forked from microsoft/fluentui-emoji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerater.js
128 lines (120 loc) · 5.03 KB
/
generater.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const fs = require("fs")
const emojiList = fs.readdirSync("./assets")
const dirSVG = './plugin/assets/SVG/'
const dirPNG = './plugin/assets/PNG/'
const listSVG = []
const listPNG = []
let counter = 0
const Generate_SVG_version = true
const Generate_PNG_version = false
function getUnicodes(emoji) {
const jsonData = JSON.parse(fs.readFileSync(`./assets/${emoji}/metadata.json`, "utf8"))
if (jsonData.hasOwnProperty("unicodeSkintones")) {
const unicodeSkintones = jsonData.unicodeSkintones
for (let i = 0; i < unicodeSkintones.length; i++) {
unicodeSkintones[i] = unicodeSkintones[i].replaceAll(' ', '-')
}
return unicodeSkintones
} else {
return [jsonData.unicode.replaceAll(' ', '-')]
}
}
function copyFile(source, target) {
try{
fs.copyFileSync(source, target)
} catch (err) {
console.error(err)
}
}
function nameFormatting(emojiName) {
return emojiName.replaceAll(' ','_').toLowerCase()
}
function process(emoji) {
unicodes = getUnicodes(emoji)
if (unicodes.length === 1) {
// Simple Emoji
if (Generate_SVG_version) {
listSVG.push(unicodes[0])
copyFile(`./assets/${emoji}/Color/${nameFormatting(emoji)}_color.svg`, `${dirSVG}${unicodes[0]}.svg`)
}
if (Generate_PNG_version) {
listPNG.push(unicodes[0])
copyFile(`./assets/${emoji}/3D/${nameFormatting(emoji)}_3d.png`, `${dirPNG}${unicodes[0]}.png`)
}
} else if (unicodes.length === 6) {
// Skin tones Emoji
if (Generate_SVG_version) {
for (let i = 0; i < unicodes.length; i ++) {
listSVG.push(unicodes[i])
switch (i) {
case 0:
copyFile(`./assets/${emoji}/Default/Color/${nameFormatting(emoji)}_color_default.svg`, `${dirSVG}${unicodes[0]}.svg`)
break
case 1:
copyFile(`./assets/${emoji}/Light/Color/${nameFormatting(emoji)}_color_light.svg`, `${dirSVG}${unicodes[0]}.svg`)
break
case 2:
copyFile(`./assets/${emoji}/Medium-Light/Color/${nameFormatting(emoji)}_color_medium-light.svg`, `${dirSVG}${unicodes[0]}.svg`)
break
case 3:
copyFile(`./assets/${emoji}/Medium/Color/${nameFormatting(emoji)}_color_medium.svg`, `${dirSVG}${unicodes[0]}.svg`)
break
case 4:
copyFile(`./assets/${emoji}/Medium-Dark/Color/${nameFormatting(emoji)}_color_medium-dark.svg`, `${dirSVG}${unicodes[0]}.svg`)
break
case 5:
copyFile(`./assets/${emoji}/Dark/Color/${nameFormatting(emoji)}_color_dark.svg`, `${dirSVG}${unicodes[0]}.svg`)
break
default:
console.error(`Too many items (SVG): ${emoji}`)
}
}
}
if (Generate_PNG_version) {
for (let i = 0; i < unicodes.length; i ++) {
listPNG.push(unicodes[i])
switch (i) {
case 0:
copyFile(`./assets/${emoji}/Default/3D/${nameFormatting(emoji)}_3d_default.png`, `${dirPNG}${unicodes[0]}.png`)
break
case 1:
copyFile(`./assets/${emoji}/Light/3D/${nameFormatting(emoji)}_3d_light.png`, `${dirPNG}${unicodes[0]}.png`)
break
case 2:
copyFile(`./assets/${emoji}/Medium-Light/3D/${nameFormatting(emoji)}_3d_medium-light.png`, `${dirPNG}${unicodes[0]}.png`)
break
case 3:
copyFile(`./assets/${emoji}/Medium/3D/${nameFormatting(emoji)}_3d_medium.png`, `${dirPNG}${unicodes[0]}.png`)
break
case 4:
copyFile(`./assets/${emoji}/Medium-Dark/3D/${nameFormatting(emoji)}_3d_medium-dark.png`, `${dirPNG}${unicodes[0]}.png`)
break
case 5:
copyFile(`./assets/${emoji}/Dark/3D/${nameFormatting(emoji)}_3d_dark.png`, `${dirPNG}${unicodes[0]}.png`)
break
default:
console.error(`Too many items (PNG): ${emoji}`)
}
}
}
} else {
console.error(`Unknown type: ${emoji}`)
}
counter ++
}
function mkPHPArr(arr) {
let phpArray = `[`
for (let i = 0; i<arr.length; i++) {
phpArray = phpArray + `"${arr[i]}"`
if (i < arr.length - 1) {
phpArray = phpArray + ','
}
}
return phpArray + ']'
}
for(let item of emojiList) {
process(item)
console.log(`${counter} emoji processed`)
}
fs.writeFileSync('./plugin/listSVG.php', `$listSVG = ${mkPHPArr(listSVG)}`)
fs.writeFileSync('./plugin/listPNG.php', `$listPNG = ${mkPHPArr(listPNG)}`)