-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
98 lines (74 loc) · 2.4 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import fs from 'node:fs/promises'
import gitmojis from './json/gitmoji.json'
gitmojis.sort((a, b) => a.code > b.code ? 1 : a.code < b.code ? -1 : 0)
// console.log(gitmojis)
const cwd = process.cwd()
const emojiFontSize = '3'
let doc = `# Gitmoji Markdown
This is an overview of emojis for use in Git commit messages and GitHub Markdown. Based on [Gitmoji](https://github.com/carloscuesta/gitmoji) and [this Gist with the complete list of GitHub emoji markup](https://gist.github.com/rxaviers/7360908).
#### Table of contents
- [Git messages](#git-messages)
- [People](#people)
- [Nature](#nature)
- [Objects](#objects)
- [Places](#places)
- [Symbols](#symbols)
## Git messages
| Emoji | Code | Description |
|---|---|---|
`
for (const { emoji, code, description } of gitmojis) {
doc += `| ${emoji} | \`${code}\` | ${description} |\n`
}
doc += '\n\n'
async function txt2json(category: string) {
const txt = await fs.readFile(`${cwd}/json/${category}.txt`, 'utf-8')
const lines = txt.split('\n')
const emojis = lines.reduce((emojis: [string, string][], line) => {
const found = line.split('\t')
const pairs = found.reduce((pairs: [string, string][], pair: string) => {
const [emoji, code] = pair.split(' ').slice(0, 2).map(str => str.trim())
if (emoji && code && emoji[0]!==':' ) {
pairs.push([emoji, code])
}
return pairs
}, [])
emojis.push(...pairs)
return emojis
}, [])
const jsonFile = `${cwd}/json/${category}.json`
await fs.writeFile(jsonFile, JSON.stringify(emojis, null, 2))
}
for (const category of [
'people',
'nature',
'objects',
'places',
'symbols'
]) {
// await txt2json(category)
const emojis = JSON.parse(await fs.readFile(`${cwd}/json/${category}.json`, 'utf-8'))
doc += `## ${category[0].toUpperCase() + category.slice(1)}
| Emoji | Code | Emoji | Code |
|---|---|---|---|
`
const columnsPerRow = 2
for (let i=0, len=emojis.length; i < (len+3); i+= columnsPerRow) {
for (let j=0; j <= columnsPerRow-1; j++) {
const e = emojis[i + j]
if (!e) {
// Fill the rest of table columns for this row
if (j===0) break
if (j===1) doc += `| | `
// if (j<=2) doc += `| | `
doc += `|\n`
break
}
const [emoji, code] = e
doc += `| ${emoji} | \`${code}\` `
if (j===columnsPerRow-1) doc += `|\n`
}
}
doc += '\n\n'
}
await fs.writeFile(`${cwd}/readme.md`, doc)