Added hex colors to manifest.json (#294)

This commit is contained in:
Smokie 2019-04-10 12:09:08 +01:00 committed by Luke Childs
parent ede61f7058
commit 7be9023fba
3 changed files with 860 additions and 427 deletions

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,8 @@
"globby-cli": "^1.0.1",
"husky": "^1.3.1",
"svgo": "^1.2.0",
"xo": "^0.24.0"
"xo": "^0.24.0",
"get-svg-colors": "^1.5.1"
},
"husky": {
"hooks": {

View File

@ -2,6 +2,7 @@
const fs = require('fs');
const path = require('path');
const coins = require('coinlist');
const getColors = require('get-svg-colors');
const alphaSort = require('alpha-sort');
const manifest = require('../manifest.json');
@ -44,10 +45,19 @@ const overrides = new Map([
const icons = manifest.map(icon => {
const id = typeof icon === 'string' ? icon : icon.symbol;
const fileName = `${id.toLowerCase()}.svg`;
const svgPath = path.resolve(__dirname, '../svg/color/', fileName);
let color;
if (fs.existsSync(svgPath)) {
const svg = fs.readFileSync(svgPath, 'utf8');
const fillColor = getColors(svg).fills[0];
color = fillColor ? fillColor.hex().toUpperCase() : undefined;
}
return {
symbol: id.toUpperCase(),
name: overrides.get(id) || coins.get(id, 'name') || id
name: overrides.get(id) || coins.get(id, 'name') || id,
color
};
});