Build d.ts for use in typescript (#277)

* Add lucide-angular

* Build d.ts for use in typescript

* Update packages/lucide/scripts/buildTypes.js

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* Update packages/lucide/scripts/buildTypes.js

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* Update packages/lucide/scripts/buildTypes.js

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* Update packages/lucide/scripts/buildTypes.js

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* Update packages/lucide/scripts/buildTypes.js

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* Update packages/lucide/scripts/buildTypes.js

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* Update packages/lucide/scripts/buildTypes.js

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>

* Update packages/lucide/scripts/buildTypes.js

* Update package.json

* Update package.json

* Delete .gitignore

* Delete angular.json

* Delete package.json

* Delete README.md

* Delete default-attributes.ts

* Delete icons-index.ts

* Delete package.json

* Delete karma.conf.js

* Delete lucide.ts

* Delete ng-package.json

* Delete package.json

* Delete lib-index.ts

* Delete icons.provider.ts

* Delete lucide-angular.component.spec.ts

* Delete lucide-angular.component.ts

* Delete lucide-angular.module.ts

* Delete test.ts

* Delete tsconfig.lib.json

* Delete tsconfig.lib.prod.json

* Delete tsconfig.spec.json

* Delete tslint.json

* Delete buildIconsIndex.js

* Delete exportTemplate.js

* Delete tsconfig.json

* Delete tslint.json

* Update buildTypes.js

Pretty code

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
SMAH1
2021-04-05 19:20:00 +04:30
committed by GitHub
parent 456cb01982
commit c7fc71a66e
+36 -7
View File
@@ -6,18 +6,47 @@ const TARGET_DIR = path.join(__dirname, '../dist');
const ICONS_DIR = path.resolve(__dirname, '../../../icons');
const TYPES_FILE_NAME = 'lucide.d.ts';
import defaultAttributes from '../src/defaultAttributes';
// 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 SVGProps extends Partial<SVGElement> ${JSON.stringify(defaultAttributes, null, 2)}
export interface Attributes extends Partial<Props<Element>> {}
export declare type IconNode = readonly [tag: string, attrs:SVGProps, children?:IconNode];
export declare type CustomAttrs = { [attr:string]: any }
export type Icons = { [key: string]: IconNode }
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;
/**
* 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?: CustomAttrs;
}
export function createElement(icon: IconNode): SVGSVGElement;
export function createIcons({ icons: IconsObj, nameAttr: string = 'icon-name', attrs: Attributes = {} }): VoidFunction;
export function createIcons(options: CreateIconsOptions): void;
export declare const icons: IconsObj;
export declare const icons: Icons;
// Generated icons
`;
@@ -31,7 +60,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');