-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.ts
83 lines (63 loc) · 1.88 KB
/
update.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
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
import { gray, white } from 'https://deno.land/std@v0.184.0/fmt/colors.ts'
import { ensureDir } from 'https://deno.land/std@v0.184.0/fs/ensure_dir.ts'
import { log } from 'https://deno.land/x/drgn@v0.10.2/mod.ts'
async function getEmojis() {
const tags = await (await fetch(
'https://api.github.com/repos/jdecked/twemoji/tags',
)).json()
const result = await (await fetch(
`https://api.github.com/repos/jdecked/twemoji/git/trees/${tags[0].name}`,
)).json()
const sha1 =
// deno-lint-ignore no-explicit-any
(result.tree as Array<any>).find((item) => item.path === 'assets').sha
const assets = await (await fetch(
`https://api.github.com/repos/jdecked/twemoji/git/trees/${sha1}`,
)).json()
const sha2 =
// deno-lint-ignore no-explicit-any
(assets.tree as Array<any>).find((item) => item.path === 'svg').sha
const emojis = await (await fetch(
`https://api.github.com/repos/jdecked/twemoji/git/trees/${sha2}`,
)).json()
return emojis.tree as { path: string; [key: string]: unknown }[]
}
await ensureDir('./files')
let workers: Worker[] = []
let threads = 10
while (threads--) {
workers = [
new Worker(new URL('./worker.ts', import.meta.url).href, {
type: 'module',
}),
...workers,
]
}
const emojis = await getEmojis()
const amountOfEmojis = emojis.length
let emojisProcessed = 0
for (const worker of workers) {
worker.onmessage = async () => {
emojisProcessed++
await log(
gray(
`downloading svg... ${
white(`${Math.round((emojisProcessed / amountOfEmojis) * 100)}%`)
}`,
),
{ clear: true },
)
}
}
threads = 10
let workerNumber = 0
while (emojis.length > 0) {
const chunk = emojis.splice(0, Math.round(amountOfEmojis / threads) + 1)
if (workerNumber === 10) {
workerNumber = 0
}
workers[workerNumber].postMessage({
emojis: chunk,
})
workerNumber++
}