mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-17 14:28:25 +00:00
Generate index.d.ts when build (#269)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import path from 'path';
|
||||
|
||||
import { readSvgDirectory, resetFile, appendFile, toPascalCase } from './helpers';
|
||||
|
||||
const ICONS_DIR = path.resolve(__dirname, '../icons');
|
||||
const DTS_FILE_NAME = 'index.d.ts';
|
||||
const DTS_FILE_ROOT = path.resolve(__dirname, '../');
|
||||
|
||||
resetFile(DTS_FILE_NAME, DTS_FILE_ROOT);
|
||||
|
||||
// Generates header of d.ts file include some types and functions
|
||||
appendFile(
|
||||
`
|
||||
export type IconData = readonly [string, object, IconData?];
|
||||
export type IconString = string;
|
||||
|
||||
export function createElement(ico: IconData): SVGSVGElement;
|
||||
|
||||
export declare const icons: { [key: string]: IconData };
|
||||
|
||||
// Generated icons
|
||||
`,
|
||||
DTS_FILE_NAME,
|
||||
DTS_FILE_ROOT,
|
||||
);
|
||||
|
||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
||||
|
||||
svgFiles.forEach(svgFile => {
|
||||
const nameSvg = path.basename(svgFile, '.svg');
|
||||
const namePascal = toPascalCase(nameSvg);
|
||||
appendFile(`export declare const ${namePascal}: IconData;\n`, DTS_FILE_NAME, DTS_FILE_ROOT);
|
||||
});
|
||||
|
||||
console.log(`Successfully generated '${DTS_FILE_NAME}'.`);
|
||||
Reference in New Issue
Block a user