Last active
March 11, 2021 01:45
Revisions
-
antony revised this gist
Jan 30, 2021 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ [ "airplay", "at-sign", "minus", "plus", "check", "x", ... ] -
antony created this gist
Jan 30, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ const feather = require('feather-icons/dist/icons.json') const pascal = require('just-pascal-case') const { promises: fs } = require('fs') const { join } = require('path') const iconList = require('./icon-list.json') const handleComponentName = name => name.replace(/\-(\d+)/, '$1') const component = icon => `<script> export let size = "100%"; export let strokeWidth = 2; let customClass = ""; export { customClass as class }; if (size !== "100%") { size = size.slice(-1) === 'x' ? size.slice(0, size.length -1) + 'em' : parseInt(size) + 'px'; } </script> <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="{strokeWidth}" stroke-linecap="round" stroke-linejoin="round" class="feather feather-${icon} {customClass}">${feather[icon]}</svg> ` const srcDir = join(__dirname, 'src') const iconPath = join(srcDir, 'icons') async function build () { await fs.rmdir(iconPath, { recursive: true }) await fs.mkdir(iconPath) const { exportList, writeFunctions } = [ ...new Set(iconList) ].reduce((out, icon) => { const name = pascal(`${handleComponentName(icon)}-icon`) out.exportList.push(`export { default as ${name} } from './icons/${name}.svelte'`) out.writeFunctions.push(fs.writeFile(join(iconPath, `${name}.svelte`), component(icon), { encoding: 'utf8' })) return out }, { exportList: [], writeFunctions: [] }) await Promise.all([ ...writeFunctions, fs.writeFile(join(srcDir, 'index.js'), exportList.join('\n'), { encoding: 'utf8' }) ]) } build() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ [ "airplay", "at-sign", "minus", "plus", "check", "x", ... ] This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ { "main": "src/index.js", "svelte": "src/index.js", "scripts": { "build": "node ./build.js" }, "devDependencies": { "feather-icons": "~4.28.0", "just-pascal-case": "~1.1.0" } }