mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-14 13:58:21 +00:00
Add code examples
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { readSvgDirectory, toCamelCase } from './helpers.mjs';
|
||||
|
||||
const currentDir = process.cwd();
|
||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||
const iconJsonFiles = readSvgDirectory(ICONS_DIR, '.json');
|
||||
|
||||
fs.unlinkSync(path.resolve(currentDir, 'iconMetaData.ts'));
|
||||
|
||||
const location = path.resolve(currentDir, `iconMetaData.ts`);
|
||||
|
||||
let outputString = '';
|
||||
|
||||
iconJsonFiles.forEach((iconJsonFile) => {
|
||||
const iconName = path.basename(iconJsonFile, '.json');
|
||||
outputString += `export { default as ${toCamelCase(
|
||||
iconName,
|
||||
)} } from '../icons/${iconName}.json';\n`;
|
||||
});
|
||||
|
||||
fs.promises
|
||||
.writeFile(location, outputString, 'utf-8')
|
||||
.then(() => {
|
||||
console.log('Successfully write icon json file index');
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(`Something went wrong generating icon json file index file,\n ${error}`);
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import renderIconsObject from './render/renderIconsObject.mjs';
|
||||
import { readSvgDirectory, toCamelCase } from './helpers.mjs';
|
||||
|
||||
const currentDir = process.cwd();
|
||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
||||
const icons = renderIconsObject(svgFiles, ICONS_DIR, true);
|
||||
|
||||
const iconNodesDirectory = path.resolve(currentDir, 'iconNodes');
|
||||
|
||||
fs.unlinkSync(path.resolve(currentDir, 'iconNodes/index.ts'));
|
||||
|
||||
if (!fs.existsSync(iconNodesDirectory)) {
|
||||
fs.mkdirSync(iconNodesDirectory);
|
||||
}
|
||||
|
||||
const writeIconFiles = Object.entries(icons).map(async ([iconName, { children }]) => {
|
||||
const location = path.resolve(iconNodesDirectory, `${iconName}.json`);
|
||||
const iconNode = children.map(({ name, attributes }) => [name, attributes]);
|
||||
|
||||
const output = JSON.stringify(iconNode, null, 2);
|
||||
await fs.promises.writeFile(location, output, 'utf-8');
|
||||
|
||||
const indexFile = path.resolve(iconNodesDirectory, `index.ts`);
|
||||
await fs.promises.appendFile(
|
||||
indexFile,
|
||||
`export { default as ${toCamelCase(iconName)} } from './${iconName}.json';\n`,
|
||||
'utf-8',
|
||||
);
|
||||
});
|
||||
|
||||
Promise.all(writeIconFiles)
|
||||
.then(() => {
|
||||
console.log('Successfully write', writeIconFiles.length, 'iconNodes.');
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(`Something went wrong generating iconNode files,\n ${error}`);
|
||||
});
|
||||
Reference in New Issue
Block a user