* Generate types for all exported icons * renderUniqueKey will generate duplicate keys if the SVG attributse are identical. Fixed by adding an index attribute to the hash. * Revert "renderUniqueKey will generate duplicate keys if the SVG attributse are identical. Fixed by adding an index attribute to the hash." This reverts commit 1c42b39e * Update packages/lucide-react/build-types.js * Update packages/lucide-react/build-types.js Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
const fs = require("fs")
|
|
const path = require("path")
|
|
const srcDirectory = path.join(__dirname, "dist")
|
|
|
|
// Declare type definitions
|
|
const typeDefinitions = `
|
|
/// <reference types="react" />
|
|
import { SVGAttributes } from 'react'
|
|
|
|
// Create interface extending SVGAttributes
|
|
export interface LucideProps extends Partial<React.SVGProps<SVGSVGElement>> {
|
|
color?: string
|
|
size?: string | number
|
|
stroke?: string | number
|
|
strokeWidth?: string | number
|
|
}
|
|
|
|
// Generated icons
|
|
`
|
|
|
|
// Write type definitions to file
|
|
fs.writeFileSync(
|
|
path.join(srcDirectory, "index.d.ts"),
|
|
typeDefinitions,
|
|
"utf-8",
|
|
)
|
|
|
|
const iconsFolder = "./build/icons"
|
|
fs.readdir(iconsFolder, (err, files) => {
|
|
|
|
files.forEach(file => {
|
|
|
|
const fileName = file.replace(".js", "")
|
|
|
|
// Convert fileName to component name
|
|
const componentName = fileName.split("-")
|
|
.map(word => word[0].toUpperCase() + word.substr(1, word.length))
|
|
.join("")
|
|
|
|
// Declare component type
|
|
const exportTypeString = `export declare const ${componentName}: (props: LucideProps) => JSX.Element;\n`
|
|
|
|
// Add component to the types file
|
|
fs.appendFileSync(
|
|
path.join(srcDirectory, "index.d.ts"),
|
|
exportTypeString,
|
|
"utf-8",
|
|
)
|
|
|
|
})
|
|
|
|
console.log("Generated index.d.ts file with", files.length, "icons")
|
|
|
|
})
|