You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 rivejä
2.1 KiB

  1. const fs = require('fs');
  2. const https = require('https');
  3. const path = require('path');
  4. async function generate() {
  5. let map = Object.create(null);
  6. // Get emoji data from https://github.com/milesj/emojibase
  7. // https://github.com/milesj/emojibase/blob/master/packages/data/en/raw.json
  8. await download('https://raw.githubusercontent.com/milesj/emojibase/master/packages/data/en/raw.json', 'raw.json');
  9. const emojis = require(path.join(process.cwd(), 'raw.json'));
  10. for (const emoji of emojis) {
  11. if (emoji.shortcodes == null || emoji.shortcodes.length === 0) continue;
  12. for (const code of emoji.shortcodes) {
  13. if (map[code] !== undefined) {
  14. console.warn(code);
  15. }
  16. map[code] = emoji.emoji;
  17. }
  18. }
  19. fs.unlink('raw.json', () => {});
  20. // Get gitmoji data from https://github.com/carloscuesta/gitmoji
  21. // https://github.com/carloscuesta/gitmoji/blob/master/src/data/gitmojis.json
  22. await download(
  23. 'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json',
  24. 'gitmojis.json'
  25. );
  26. const gitmojis = require(path.join(process.cwd(), 'gitmojis.json')).gitmojis;
  27. for (const emoji of gitmojis) {
  28. if (map[emoji.code] !== undefined) {
  29. console.warn(emoji.code);
  30. continue;
  31. }
  32. map[emoji.code] = emoji.emoji;
  33. }
  34. fs.unlink('gitmojis.json', () => {});
  35. // Sort the emojis for easier diff checking
  36. const list = Object.entries(map);
  37. list.sort();
  38. map = list.reduce((m, [key, value]) => {
  39. m[key] = value;
  40. return m;
  41. }, Object.create(null));
  42. fs.writeFileSync(path.join(process.cwd(), 'src/emojis.json'), JSON.stringify(map), 'utf8');
  43. }
  44. function download(url, destination) {
  45. return new Promise((resolve, reject) => {
  46. const stream = fs.createWriteStream(destination);
  47. https.get(url, rsp => {
  48. rsp.pipe(stream);
  49. stream.on('finish', () => {
  50. stream.close();
  51. resolve();
  52. });
  53. });
  54. });
  55. }
  56. generate();