This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.ts
58 lines (49 loc) · 1.41 KB
/
build.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { ensureDir } from 'https://deno.land/std@v0.186.0/fs/ensure_dir.ts'
import { build, stop } from 'https://deno.land/x/esbuild@v0.17.18/mod.js'
import { getEmojis } from './getEmojis.ts'
let imports = ''
let types = `import * as React from 'react'\n\n`
const exports = []
let components = await Deno.readTextFile('./createComponent.txt') + '\n\n'
await ensureDir('cache')
const emojis = await getEmojis()
for (const emoji of emojis) {
const name = (emoji.path as string)
.toLowerCase()
.replaceAll('!', '')
.replaceAll('-', ' ')
.replace('1st', 'first')
.replace('2nd', 'second')
.replace('3rd', 'third')
.split(' ')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join('')
imports += `import src_${name} from '../emojis/${name}.png'\n`
types +=
`declare function ${name}(props: React.ImgHTMLAttributes<HTMLImageElement>): React.ReactElement\n`
components +=
`export const ${name} = createComponent('${name}', src_${name})\n`
exports.push(name)
}
await Deno.writeTextFile(
'./cache/index.tsx',
imports + components,
)
await build({
entryPoints: ['./cache/index.tsx'],
allowOverwrite: true,
format: 'esm',
bundle: true,
minify: true,
target: 'es2020',
external: ['react'],
loader: {
'.png': 'base64',
},
outfile: './index.js',
})
await Deno.writeTextFile(
'./index.d.ts',
types + `\nexport { ${exports.join(', ')} }`,
)
stop()