mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-11 13:28:19 +00:00
* init modernization * implement esbuild * Make first build work * Fix esbuild for lucide-react * Add vitest for lucide-react * add esbuild lucide and lucide-react * update package lock * implement preact * Add typescript and vitest * adjust workflows * Fix mocking react-native package * update lock file * Add esbuild in svelte * make svelte test work in vitest * Refactor lucide svelte * Transform lucide vue to typescript * Finish lucide-vue-next typescript * 0.104.0-beta.0 * remove version in main package.json * cleanup * Fix svelte tests snapshots * clean up * add rollup lucide-vue-next * Fix lucide svelte package * change to workspace link * revert filter position * revert preact workflow change * cleanup * Fix some types * add semi
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,
|
|
iconFileExtension = '.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}${iconFileExtension}`);
|
|
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}`);
|
|
});
|
|
};
|