Skip to content

Instantly share code, notes, and snippets.

@dohomi
Created October 2, 2022 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dohomi/5a8f411710de68718646ff16a885eaef to your computer and use it in GitHub Desktop.
Save dohomi/5a8f411710de68718646ff16a885eaef to your computer and use it in GitHub Desktop.
build script for mdi-icons
const fs = require('fs')
const uppercamelcase = require('uppercamelcase')
const path = require('path')
const prettier = require('prettier')
const util = require('@mdi/util')
const meta = util.getMeta(true);
const rootDir = path.join(__dirname, '..')
fs.writeFileSync(path.join(rootDir, 'src', 'index.ts'), '', 'utf-8')
meta.forEach((i) => {
const id = `mdi-${i.name}`
const fileName = id + '.tsx'
const location = path.join(rootDir, 'src/icons', fileName)
const cname = uppercamelcase(id)
const element = `
import { memo } from 'react'
import { IconProps } from '../IconProps'
import {
Svg,
Path
} from 'react-native-svg'
import { themed } from '../themed'
const Icon = (props) => {
const { color = 'black', size, ...otherProps } = props
return (
<Svg id="${id}" viewBox="0 0 24 24" width={size} height={size} fill={color} {...otherProps}><Path d="${i.path}"/></Svg>
)
}
Icon.displayName = '${cname}'
export const ${cname} = memo<IconProps>(themed(Icon))
`
const component = element
// prettier.format(element, {
// singleQuote: true,
// trailingComma: 'es5',
// arrowParens: 'always',
// plugins: [require.resolve('prettier-plugin-import-sort')],
// parser: 'typescript',
// semi: false,
// })
fs.writeFileSync(location, component, 'utf-8')
const exportString = `export { ${cname} } from './icons/${id}'\n`
fs.appendFileSync(path.join(rootDir, 'src', 'index.ts'), exportString, 'utf-8')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment