Add lucide-react-native package (#687)

* Add `lucide-react-native` package

Closes #394

* minor fixes build config

* Add `lucide-react-native` package

Closes #394

* make it work

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
Wojciech Maj
2022-06-12 22:31:05 +02:00
committed by GitHub
parent 8053cca0ed
commit ecf61d304a
16 changed files with 837 additions and 14 deletions

View File

@@ -0,0 +1,47 @@
import path from 'path';
import {
appendFile,
readSvgDirectory,
resetFile,
toPascalCase,
writeFile,
} from '../../../scripts/helpers';
const srcDirectory = path.join(__dirname, '../dist');
// Declare type definitions
const typeDefinitions = `\
/// <reference types="react" />
import { SVGAttributes } from 'react'
declare module 'lucide-react-native'
// Create interface extending SVGProps
export interface LucideProps extends Partial<React.SVGProps<SVGSVGElement>> {
size?: string | number
}
export declare const createReactComponent: (iconName: string, iconNode: any[]) => (props: LucideProps) => JSX.Element;
export type Icon = React.FC<LucideProps>;
// Generated icons
`;
const ICONS_DIR = path.resolve(__dirname, '../../../icons');
const TYPES_FILE = 'lucide-react-native.d.ts';
resetFile(TYPES_FILE, srcDirectory);
writeFile(typeDefinitions, TYPES_FILE, srcDirectory);
const svgFiles = readSvgDirectory(ICONS_DIR);
svgFiles.forEach(svgFile => {
const iconName = path.basename(svgFile, '.svg');
const componentName = toPascalCase(iconName);
const exportTypeString = `export declare const ${componentName}: (props: LucideProps) => JSX.Element;\n`;
appendFile(exportTypeString, TYPES_FILE, srcDirectory);
});
console.log(`Generated ${TYPES_FILE} file with`, svgFiles.length, 'icons');

View File

@@ -0,0 +1,7 @@
export default ({ componentName, children }) => `
import createReactComponent from '../createReactComponent';
const ${componentName} = createReactComponent('${componentName}', ${JSON.stringify(children)});
export default ${componentName};
`;