Browse Source

Updates emoji support

main
Eric Amodio 4 years ago
parent
commit
d691e23382
3 changed files with 34 additions and 30 deletions
  1. +32
    -28
      generateEmojiShortcodeMap.js
  2. +1
    -1
      package.json
  3. +1
    -1
      src/emojis.json

+ 32
- 28
generateEmojiShortcodeMap.js View File

@ -5,35 +5,42 @@ const path = require('path');
async function generate() {
/**
* @type {Record<string, string>}
* @type {Map<string, string>}
*/
let map = Object.create(null);
const shortcodeMap = new Map();
// Get emoji data from https://github.com/milesj/emojibase
// https://github.com/milesj/emojibase/blob/master/packages/data/en/raw.json
await download('https://raw.githubusercontent.com/milesj/emojibase/master/packages/data/en/raw.json', 'raw.json');
// https://github.com/milesj/emojibase/
/**
* @type {({ emoji: string; shortcodes: string[] })[]}
*/
// eslint-disable-next-line import/no-dynamic-require
const emojis = require(path.join(process.cwd(), 'raw.json'));
for (const emoji of emojis) {
if (emoji.shortcodes == null || emoji.shortcodes.length === 0) continue;
const files = ['github.raw.json', 'emojibase.raw.json']; //, 'iamcal.raw.json', 'joypixels.raw.json'];
for (let code of emoji.shortcodes) {
if (code.startsWith(':') && code.endsWith(':')) {
code = code.substring(1, code.length - 2);
}
for (const file of files) {
await download(
`https://raw.githubusercontent.com/milesj/emojibase/master/packages/data/en/shortcodes/${file}`,
file,
);
if (map[code] !== undefined) {
console.warn(code);
/**
* @type {Record<string, string | string[]>}}
*/
// eslint-disable-next-line import/no-dynamic-require
const data = require(path.join(process.cwd(), file));
for (const [emojis, codes] of Object.entries(data)) {
const emoji = emojis
.split('-')
.map(c => String.fromCodePoint(parseInt(c, 16)))
.join('');
for (const code of Array.isArray(codes) ? codes : [codes]) {
if (shortcodeMap.has(code)) {
// console.warn(`${file}: ${code}`);
continue;
}
shortcodeMap.set(code, emoji);
}
map[code] = emoji.emoji;
}
}
fs.unlink('raw.json', () => {});
fs.unlink(file, () => {});
}
// Get gitmoji data from https://github.com/carloscuesta/gitmoji
// https://github.com/carloscuesta/gitmoji/blob/master/src/data/gitmojis.json
@ -52,23 +59,20 @@ async function generate() {
emoji.code = emoji.code.substring(1, emoji.code.length - 2);
}
if (map[emoji.code] !== undefined) {
console.warn(emoji.code);
if (shortcodeMap.has(emoji.code)) {
// console.warn(`GitHub: ${emoji.code}`);
continue;
}
map[emoji.code] = emoji.emoji;
shortcodeMap.set(emoji.code, emoji.emoji);
}
fs.unlink('gitmojis.json', () => {});
// Sort the emojis for easier diff checking
/**
* @type { [string, string][] }}
*/
const list = Object.entries(map);
const list = [...shortcodeMap.entries()];
list.sort();
map = list.reduce((m, [key, value]) => {
const map = list.reduce((m, [key, value]) => {
m[key] = value;
return m;
}, Object.create(null));

+ 1
- 1
package.json View File

@ -7804,7 +7804,7 @@
"watch:webviews": "webpack --watch --mode development --config-name webviews --info-verbosity verbose",
"update-dts": "pushd \"src/@types\" && npx vscode-dts dev && popd",
"update-dts:master": "pushd \"src/@types\" && npx vscode-dts master && popd",
"update-emoji": "pushd emoji && node ./shortcodeToEmoji.js && popd",
"update-emoji": "node ./generateEmojiShortcodeMap.js",
"vscode:prepublish": "yarn run bundle"
},
"dependencies": {

+ 1
- 1
src/emojis.json
File diff suppressed because it is too large
View File


Loading…
Cancel
Save