From 2b8da85726a50c792ace2faaa663d4966af8c107 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 28 Jun 2017 11:35:14 +0100 Subject: [PATCH] Strip the emoji meta-data for the data we need This is done at build time by parsing emojione/emoji.json, stripping it and then writing to ./lib/stripped-emoji.json. --- package.json | 5 +++-- scripts/emoji-data-strip.js | 17 +++++++++++++++++ src/autocomplete/EmojiProvider.js | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 scripts/emoji-data-strip.js diff --git a/package.json b/package.json index 8d638a5928..cd0946ffc8 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,9 @@ "scripts": { "reskindex": "node scripts/reskindex.js -h header", "reskindex:watch": "node scripts/reskindex.js -h header -w", - "build": "npm run reskindex && babel src -d lib --source-maps", - "build:watch": "babel src -w -d lib --source-maps", + "build": "npm run emoji-data-strip && npm run reskindex && babel src -d lib --source-maps", + "build:watch": "npm run emoji-data-strip && babel src -w -d lib --source-maps", + "emoji-data-strip": "node scripts/emoji-data-strip.js", "start": "parallelshell \"npm run build:watch\" \"npm run reskindex:watch\"", "lint": "eslint src/", "lintall": "eslint src/ test/", diff --git a/scripts/emoji-data-strip.js b/scripts/emoji-data-strip.js new file mode 100644 index 0000000000..14110c1c8b --- /dev/null +++ b/scripts/emoji-data-strip.js @@ -0,0 +1,17 @@ +#!/usr/bin/env node +const EMOJI_DATA = require('emojione/emoji.json'); +const fs = require('fs'); + +const output = Object.keys(EMOJI_DATA).map( + (key) => { + const datum = EMOJI_DATA[key]; + return { + name: datum.name, + shortname: datum.shortname, + category: datum.category, + emoji_order: datum.emoji_order, + }; + } +); + +fs.writeFileSync('./lib/stripped-emoji.json', JSON.stringify(output)); diff --git a/src/autocomplete/EmojiProvider.js b/src/autocomplete/EmojiProvider.js index 6adb820cd8..fb7936d77e 100644 --- a/src/autocomplete/EmojiProvider.js +++ b/src/autocomplete/EmojiProvider.js @@ -24,7 +24,7 @@ import sdk from '../index'; import {PillCompletion} from './Components'; import type {SelectionRange, Completion} from './Autocompleter'; -import EmojiData from 'emojione/emoji.json'; +import EmojiData from '../stripped-emoji.json'; const LIMIT = 20; const CATEGORY_ORDER = [