Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build d.ts for use in typescript #277

Merged
merged 38 commits into from
Apr 5, 2021
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
53d3a31
Add lucide-angular
SMAH1 Mar 30, 2021
ef3da7d
Build d.ts for use in typescript
SMAH1 Mar 31, 2021
c40df12
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
7e676e3
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
d883fc2
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
d9981fc
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
08e4ff1
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
b07c5fe
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
9de8e78
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
a01d5c6
Update packages/lucide/scripts/buildTypes.js
SMAH1 Apr 3, 2021
ecc1b12
Update package.json
SMAH1 Apr 4, 2021
486f4fa
Update package.json
SMAH1 Apr 4, 2021
3fa2ca3
Delete .gitignore
SMAH1 Apr 4, 2021
ded1a24
Delete angular.json
SMAH1 Apr 4, 2021
4eb4837
Delete package.json
SMAH1 Apr 4, 2021
e968bf5
Delete README.md
SMAH1 Apr 4, 2021
49e0889
Delete default-attributes.ts
SMAH1 Apr 4, 2021
80239f7
Delete icons-index.ts
SMAH1 Apr 4, 2021
74dfc92
Delete package.json
SMAH1 Apr 4, 2021
49dffc9
Delete karma.conf.js
SMAH1 Apr 4, 2021
8aa0295
Delete lucide.ts
SMAH1 Apr 4, 2021
7a08818
Delete ng-package.json
SMAH1 Apr 4, 2021
b6e4749
Delete package.json
SMAH1 Apr 4, 2021
9266183
Delete lib-index.ts
SMAH1 Apr 4, 2021
8cdd66a
Delete icons.provider.ts
SMAH1 Apr 4, 2021
4021f69
Delete lucide-angular.component.spec.ts
SMAH1 Apr 4, 2021
78cbae1
Delete lucide-angular.component.ts
SMAH1 Apr 4, 2021
686d6f8
Delete lucide-angular.module.ts
SMAH1 Apr 4, 2021
e9d24e0
Delete test.ts
SMAH1 Apr 4, 2021
bd0bdda
Delete tsconfig.lib.json
SMAH1 Apr 4, 2021
c707c94
Delete tsconfig.lib.prod.json
SMAH1 Apr 4, 2021
a334521
Delete tsconfig.spec.json
SMAH1 Apr 4, 2021
a7e2399
Delete tslint.json
SMAH1 Apr 4, 2021
1c0d763
Delete buildIconsIndex.js
SMAH1 Apr 4, 2021
dcef099
Delete exportTemplate.js
SMAH1 Apr 4, 2021
676ded8
Delete tsconfig.json
SMAH1 Apr 4, 2021
d95e217
Delete tslint.json
SMAH1 Apr 4, 2021
9ca395c
Update buildTypes.js
SMAH1 Apr 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions packages/lucide/scripts/buildTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

SMAH1 marked this conversation as resolved.
Show resolved Hide resolved
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 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;

export interface Attributes extends Partial<Props<Element>> {}
/**
* 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
`;
Expand All @@ -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');