Last active
July 24, 2020 23:32
-
-
Save Hypnosphi/043d6f138c3dd2ad88472ea74f7bc12f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// __mocks__/icons.js | |
import path from 'path'; | |
import fs from 'fs'; | |
const svgRE = /\.svg$/ | |
function getIcons(kind) { | |
const files = {}; | |
function readDirectory(directory) { | |
fs.readdirSync(directory).forEach((file) => { | |
const fullPath = path.resolve(directory, file); | |
if (fs.statSync(fullPath).isDirectory()) { | |
readDirectory(fullPath); | |
return; | |
} | |
if (!svgRE.test(fullPath)) return; | |
const key = `${kind} ${file.replace(svgRE, '')}`; | |
files[key] = key; | |
}); | |
} | |
return files; | |
} | |
export default { | |
Line: getIcons('Line'), | |
Solid: getIcons('Solid'), | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// icons.js | |
const lineIcons = require.context('../../assets/icons/Line', true, /.+\.svg$/); | |
const solidIcons = require.context('../../assets/icons/Solid', true, /.+\.svg$/); | |
const requireAll = requireContext => requireContext.keys().map(requireContext); | |
const toObjectNames = (state, icon) => ({ ...state, [icon.default.id]: icon.default.id }); | |
export default { | |
Line: requireAll(lineIcons).reduce(toObjectNames, {}), | |
Solid: requireAll(solidIcons).reduce(toObjectNames, {}), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment