mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
e69e207b7d
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
/**
|
|
* Generate icon names
|
|
*
|
|
* Reads all the icon svg files in app/images/icons
|
|
* and returns an object of icon name key value pairs
|
|
* stored in the environment variable ICON_NAMES
|
|
* Used with the Icon component in ./ui/component-library/icon
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const SVG_ICONS_FOLDER = './app/images/icons';
|
|
const ASSET_EXT = '.svg';
|
|
|
|
const getIconNameKebabCase = (fileName) =>
|
|
path.basename(fileName, ASSET_EXT).replace('icon-', '');
|
|
|
|
const getIconNameInSnakeCase = (fileName) =>
|
|
path
|
|
.basename(fileName, ASSET_EXT)
|
|
.replace('icon-', '')
|
|
.replace(/-/gu, '_')
|
|
.toUpperCase();
|
|
|
|
const generateIconNames = async () => {
|
|
const iconNames = {};
|
|
|
|
const svgIconsFolderPath = path.join(__dirname, `../${SVG_ICONS_FOLDER}`);
|
|
|
|
const fileList = await fs.promises.readdir(svgIconsFolderPath);
|
|
|
|
const svgIconsFileList = fileList.filter(
|
|
(fileName) => path.extname(fileName) === ASSET_EXT,
|
|
);
|
|
|
|
svgIconsFileList.forEach(
|
|
(fileName) =>
|
|
(iconNames[getIconNameInSnakeCase(fileName)] =
|
|
getIconNameKebabCase(fileName)),
|
|
);
|
|
|
|
console.log('ICON_NAMES env var successfully generated!');
|
|
|
|
return iconNames;
|
|
};
|
|
|
|
module.exports = { generateIconNames };
|