mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 17:17:43 +01:00
* Update `svgo` and `svgson` version and fix some tests * Update eslint-related packages and fix all linter errors * Update all rollup-related packages version * Update all rollup-related packages (part 2) * Update the rest of package which need to be updated * Fix unwanted comment * Fix unwanted comment (again)
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import prettier from 'prettier';
|
|
import { toPascalCase } from '../helpers.mjs';
|
|
|
|
export default ({
|
|
iconNodes,
|
|
outputDirectory,
|
|
template,
|
|
showLog = true,
|
|
iconFileExtention = '.js',
|
|
pretty = true,
|
|
}) => {
|
|
const icons = Object.keys(iconNodes);
|
|
const iconsDistDirectory = path.join(outputDirectory, `icons`);
|
|
|
|
if (!fs.existsSync(iconsDistDirectory)) {
|
|
fs.mkdirSync(iconsDistDirectory);
|
|
}
|
|
|
|
const writeIconFiles = icons.map(async (iconName) => {
|
|
const location = path.join(iconsDistDirectory, `${iconName}${iconFileExtention}`);
|
|
const componentName = toPascalCase(iconName);
|
|
|
|
let { children } = iconNodes[iconName];
|
|
children = children.map(({ name, attributes }) => [name, attributes]);
|
|
|
|
const elementTemplate = template({ componentName, iconName, children });
|
|
const output = pretty
|
|
? prettier.format(elementTemplate, {
|
|
singleQuote: true,
|
|
trailingComma: 'all',
|
|
parser: 'babel',
|
|
})
|
|
: elementTemplate;
|
|
|
|
await fs.promises.writeFile(location, output, 'utf-8');
|
|
});
|
|
|
|
Promise.all(writeIconFiles)
|
|
.then(() => {
|
|
if (showLog) {
|
|
console.log('Successfully built', icons.length, 'icons.');
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
throw new Error(`Something went wrong generating icon files,\n ${error}`);
|
|
});
|
|
};
|