From ef3da7d14df9e68a9219b741437d25908db60ec9 Mon Sep 17 00:00:00 2001 From: SMAH1 Date: Wed, 31 Mar 2021 11:52:23 +0430 Subject: [PATCH] Build d.ts for use in typescript --- packages/lucide/scripts/buildTypes.js | 52 ++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/packages/lucide/scripts/buildTypes.js b/packages/lucide/scripts/buildTypes.js index d1abfc6..79cea3a 100644 --- a/packages/lucide/scripts/buildTypes.js +++ b/packages/lucide/scripts/buildTypes.js @@ -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, 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> {} +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 \`\`, 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');