Files
lucide/packages/lucide-static/scripts/buildLib.js
Eric Fennis bb4f05e6c5 lucide-static (#401)
* Add lucide static

* add render files

* add read scripts

* Add sprite generator

* start with documentation

* Add docs

* adding documentation

* fix build command

* Add some extra static files

* bump version

* Update packages/lucide-static/README.md

Co-authored-by: Kathryn Reeve <67553+BinaryKitten@users.noreply.github.com>

* Fix sprite generation

* update readme

* Add lucide static workflow

* adjust readme

* Add font to release yml

* Temporary turn of new versioning for lucide-static

Co-authored-by: Kathryn Reeve <67553+BinaryKitten@users.noreply.github.com>
2021-11-21 20:27:15 +01:00

48 lines
1.5 KiB
JavaScript

/* eslint-disable import/no-extraneous-dependencies */
import fs from 'fs';
import path from 'path';
import getArgumentOptions from 'minimist';
import { parseSync } from 'svgson';
// import renderIconsObject from '../../../scripts/render/renderIconsObject';
import { appendFile, readSvgDirectory, toCamelCase } from '../../../scripts/helpers';
import readSvgs from './readSvgs';
import generateSprite from './generateSprite';
import generateIconNodes from './generateIconNodes';
const cliArguments = getArgumentOptions(process.argv.slice(2));
const createDirectory = dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
};
const PACKAGE_DIR = path.resolve(__dirname, '../');
const ICONS_DIR = path.join(PACKAGE_DIR, 'icons');
const LIB_DIR = path.join(PACKAGE_DIR, cliArguments.output || 'lib');
const ICON_MODULE_DIR = path.join(LIB_DIR, 'icons');
createDirectory(LIB_DIR);
createDirectory(ICON_MODULE_DIR);
const svgFiles = readSvgDirectory(ICONS_DIR);
const svgs = readSvgs(svgFiles, ICONS_DIR);
svgs.forEach(({ name, contents }) => {
const componentName = toCamelCase(name);
const importString = `module.exports.${componentName} = require('./icons/${name}');\n`;
appendFile(importString, `index.js`, LIB_DIR);
const exportString = `module.exports = \`${contents}\`;\n`;
appendFile(exportString, `${name}.js`, ICON_MODULE_DIR);
});
const parsedSvgs = svgs.map(({ name, contents }) => ({
name,
contents,
parsedSvg: parseSync(contents),
}));
generateSprite(parsedSvgs, PACKAGE_DIR);
generateIconNodes(parsedSvgs, PACKAGE_DIR);