318c024589
* add pnpm * make it work * fix comamnds in package.jsons * move some scripts to modules * workflow fixes * test workflow * test #2 * minor fix * update lockflite * create workflows * update workflow * Add copy license command * Fix build * update workflows * update contributions.md * migrate site directory to pnpm * Fix peer dependencies when install * fix types in lucide-angular * fix testing
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
/* eslint-disable import/no-extraneous-dependencies */
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import prettier from 'prettier';
|
|
import { toPascalCase } from '../helpers.mjs';
|
|
|
|
export default function({
|
|
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}`);
|
|
});
|
|
}
|