-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgenerateEmojisBundle.ts
42 lines (35 loc) · 1.01 KB
/
generateEmojisBundle.ts
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
import glob from 'glob'
import fs from 'fs'
import prettierFormat from './lib/prettierFormat'
glob('./src/components/Twemoji/*.tsx', (_: any, files: readonly string[]) => {
const uniqueNames = [
...new Set(
files.map(x =>
x.replace('./src/components/Twemoji/', '').replace(/\.tsx/, '')
)
)
]
const toComponentName = (name: string) => `Emoji${name.replace(/-/g, 'ZZ')}`
const importString = uniqueNames
.map(
name =>
`import ${toComponentName(name)} from 'src/components/Twemoji/${name}'`
)
.join('\n')
const bundleObjectString = uniqueNames
.map(name => `'${name}': ${toComponentName(name)}`)
.join(',\n')
const fileContents = prettierFormat(
`// WARNING: Do not modify this file - it's generated automatically.
${importString}
export default {
${bundleObjectString}
}`
)
fs.writeFile('./src/lib/emojisBundle.tsx', fileContents, err => {
if (err) {
throw err
}
console.log('Bundle regenerated')
})
})