mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 11:07:41 +01:00
* New setup for new NPM package * Add build scripts for dist * Add introduction readme * Refactor names * update package.json * remove log * rename variable * Factoring * Improve optimize script * Add eslint config * Eslint fixes * rename import * Move packeges * Setup rollup and build progress * Refactor scripts * fix lint error * remove lint disabler * Bring back old libraries * add indentation * reset packages directory * remove vscode setting files * 0.1.0-alpha.0 * new version * 0.1.0-alpha.1 * Fix build process * Add create element to the entry file * update version number * publish new alhpa version * fixing bugs * Add jest and tests * replace with XML createElement * set new version * Fix svg generation * Add tests for main library * Update docs * Adjust tests and selectors * update the spec * Update README.md * Update README.md * Update README.md * update version * Update README.md * Move function to helpers file * rename license, package and readme * Fix build files * rename packages Co-authored-by: Eric Fennis <eric.fennis@endurance.com>
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
/* eslint-disable import/no-extraneous-dependencies */
|
|
import path from 'path';
|
|
import cheerio from 'cheerio';
|
|
import { minify } from 'html-minifier';
|
|
import { readSvg } from '../helpers';
|
|
|
|
/**
|
|
* Get contents between opening and closing `<svg>` tags.
|
|
* @param {string} svg
|
|
* @returns {string}
|
|
*/
|
|
function getSvgContents(svg) {
|
|
const $ = cheerio.load(svg);
|
|
|
|
return minify($('svg').html(), { collapseWhitespace: true });
|
|
}
|
|
|
|
/**
|
|
* Build an object in the format: `{ <name>: <contents> }`.
|
|
* @param {string[]} svgFiles - A list of filenames.
|
|
* @param {Function} getSvg - A function that returns the contents of an SVG file given a filename.
|
|
* @returns {Object}
|
|
*/
|
|
export default (svgFiles, iconsDirectory) =>
|
|
svgFiles
|
|
.map(svgFile => {
|
|
const name = path.basename(svgFile, '.svg');
|
|
const svg = readSvg(svgFile, iconsDirectory);
|
|
const contents = getSvgContents(svg);
|
|
return { name, contents };
|
|
})
|
|
.reduce((icons, icon) => {
|
|
icons[icon.name] = icon.contents;
|
|
return icons;
|
|
}, {});
|