-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-gitmojis
77 lines (68 loc) · 2.21 KB
/
fetch-gitmojis
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
#!/usr/bin/env node
// eslint-disable-next-line @typescript-eslint/no-var-requires
const https = require('https');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TYPE_NAMES } = require('./helpers');
/**
* Creates `gitmojis.json` for commitlint usage
*
* @param {Object} json - The json downloaded.
* @param {Object[]} json.gitmojis - The gitmoji.dev content array
* @param {string} json.gitmojis[].emoji - the pretty emoji representation
* @param {string} json.gitmojis[].code - the emoji name
* @param {string} json.gitmojis[].description - the meaning in gitmoji
*/
function createCommitlintTyping(json) {
const emojiArray = json.gitmojis.map((e) => e.emoji);
try {
fs.writeFileSync('gitmojis.json', JSON.stringify(emojiArray));
} catch (error) {
// eslint-disable-next-line no-console
console.error(error.message);
}
}
/**
* Creates `types.json` for commitzen usage
*
* @param {Object} json - The json downloaded.
* @param {Object[]} json.gitmojis - The gitmoji.dev content array
* @param {string} json.gitmojis[].emoji - the pretty emoji representation
* @param {string} json.gitmojis[].code - the emoji name
* @param {string} json.gitmojis[].description - the meaning in gitmoji
*/
function createCommitzenTyping(json) {
const commitTypes = json.gitmojis.map((e) => {
const value = TYPE_NAMES.has(e.code) ? TYPE_NAMES.get(e.code) : 'error';
return {
...e,
name: `${value}:\t${e.emoji} ${e.description}`,
value,
};
});
try {
fs.writeFileSync('types.json', JSON.stringify(commitTypes));
} catch (error) {
// eslint-disable-next-line no-console
console.error(error.message);
}
}
const url =
'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json';
https
.get(url, (res) => {
let body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
const json = JSON.parse(body);
createCommitlintTyping(json);
createCommitzenTyping(json);
});
})
.on('error', (error) => {
// eslint-disable-next-line no-console
console.error(error.message);
});