Compare commits

..

1 Commits

Author SHA1 Message Date
swcs 26d8c5ec23 initial draft for SVG sprite generation 2021-07-09 14:36:00 +02:00
4 changed files with 77 additions and 14126 deletions
+5
View File
@@ -11,3 +11,8 @@ stats
*.log
packages/**/src/icons/*.js
packages/**/src/icons/*.ts
.pnp.js
.yarn
.yarn*
*.lock
package-lock.json
+36
View File
@@ -0,0 +1,36 @@
import fs from 'fs';
import path from 'path';
import getArgumentOptions from 'minimist'; // eslint-disable-line import/no-extraneous-dependencies
import transformsIconToSymbols from './render/transformsIconToSymbols';
import generateSpriteFile from './build/generateSpriteFile';
import { readSvgDirectory } from './helpers';
const cliArguments = getArgumentOptions(process.argv.slice(2));
const ICONS_DIR = path.resolve(__dirname, '../icons');
const OUTPUT_DIR = path.resolve(__dirname, cliArguments.output || '../build');
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR);
}
const {
renderUniqueKey = false,
templateSrc = './templates/defaultIconFileTemplate',
silent = false,
iconFileExtention = '.js',
exportFileName = 'lucide.svg',
} = cliArguments;
const svgFiles = readSvgDirectory(ICONS_DIR);
const icons = transformsIconToSymbols(svgFiles, ICONS_DIR);
// Generates entry files for the compiler filled with icons exports
generateSpriteFile(
path.join(OUTPUT_DIR, 'sprite', exportFileName),
path.join(OUTPUT_DIR, 'sprite'),
icons
);
+36
View File
@@ -0,0 +1,36 @@
/* eslint-disable import/no-extraneous-dependencies */
import { basename } from 'path';
import { parseSync, stringify } from 'svgson';
import { generateHashedKey, readSvg, hasDuplicatedChildren } from '../helpers';
/**
* 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 = basename(svgFile, '.svg');
const svg = readSvg(svgFile, iconsDirectory);
const contents = parseSync(svg);
if (!(contents.children && contents.children.length)) {
throw new Error(`${name}.svg has no children!`);
}
if (hasDuplicatedChildren(contents.children)) {
throw new Error(`Duplicated children in ${name}.svg`);
}
return stringify({
name: 'symbol',
type: 'element',
attributes: {
id: name,
viewBox: contents.attributes.viewBox
},
children: contents.children
});
});
-14126
View File
File diff suppressed because it is too large Load Diff