Build d.ts for use in typescript
This commit is contained in:
@@ -8,16 +8,52 @@ const TYPES_FILE_NAME = 'lucide.d.ts';
|
||||
|
||||
// Generates header of d.ts file include some types and functions
|
||||
const typeDefinitions = `\
|
||||
export type IconName = string;
|
||||
export type IconNode = readonly [tag: string, object:SVGProps<SVGSVGElement>, children:IconNode?];
|
||||
export type IconsObj = { [IconName]: IconNode }
|
||||
export interface Attributes {
|
||||
width?: number;
|
||||
height?: number;
|
||||
viewBox?: string;
|
||||
fill?: string;
|
||||
stroke?: string;
|
||||
'stroke-width'?: number;
|
||||
'stroke-linecap'?: string;
|
||||
'stroke-linejoin'?: string;
|
||||
}
|
||||
|
||||
export interface Attributes extends Partial<Props<Element>> {}
|
||||
export declare type IconNode = readonly [string, object];
|
||||
export declare type IconData = readonly [tag: string, object: object, children: IconNode[]];
|
||||
export type Icons = { [key: string]: IconData }
|
||||
|
||||
export function createElement(icon: IconNode): SVGSVGElement;
|
||||
export function createIcons({ icons: IconsObj, nameAttr: string = 'icon-name', attrs: Attributes = {} }): VoidFunction;
|
||||
export interface CreateIconsOptions {
|
||||
/**
|
||||
* List of icons you want to replace
|
||||
*
|
||||
* For example: \`{ Menu, Circle}\`.
|
||||
*
|
||||
* For replace all icons in lucide library, import \`icons\` and use it.
|
||||
*/
|
||||
icons: Icons;
|
||||
|
||||
export declare const icons: IconsObj;
|
||||
/**
|
||||
* Search HTML emelemt by \`nameAttr\` property.
|
||||
*
|
||||
* For example if define \`<i lucide-icon="circle"></i>\`, fill by \`lucide-icon\`.
|
||||
*
|
||||
* @default 'icon-name'
|
||||
*/
|
||||
nameAttr?: string;
|
||||
|
||||
/**
|
||||
* Change defult attribute for show like color, fill, width , ...
|
||||
*
|
||||
* @default undefined
|
||||
*/
|
||||
attrs?: Attributes;
|
||||
}
|
||||
|
||||
export function createElement(icon: IconData): SVGSVGElement;
|
||||
export function createIcons(options: CreateIconsOptions): VoidFunction;
|
||||
|
||||
export declare const icons: Icons;
|
||||
|
||||
// Generated icons
|
||||
`;
|
||||
@@ -31,7 +67,7 @@ svgFiles.forEach(svgFile => {
|
||||
const nameSvg = path.basename(svgFile, '.svg');
|
||||
const namePascal = toPascalCase(nameSvg);
|
||||
|
||||
appendFile(`export declare const ${namePascal}: IconNode;\n`, TYPES_FILE_NAME, TARGET_DIR);
|
||||
appendFile(`export declare const ${namePascal}: IconData;\n`, TYPES_FILE_NAME, TARGET_DIR);
|
||||
});
|
||||
|
||||
console.log(`Generated ${TYPES_FILE_NAME} file with`, svgFiles.length, 'icons');
|
||||
|
||||
Reference in New Issue
Block a user