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

feat: add typescript #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
lib
dist
22 changes: 11 additions & 11 deletions build/generate.js → commands/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const cheerio = require('cheerio')
const upperCamelCase = require('uppercamelcase')
const svgr = require('@svgr/core').default

const iconsComponentPath = path.join(process.cwd(), 'icons')
const iconsIndexPath = path.join(process.cwd(), 'index.js')
const iconsComponentPath = path.join(process.cwd(), 'src/icons')
const iconsIndexPath = path.join(process.cwd(), 'src/index.ts')
const uniconsConfig = require('@iconscout/unicons/json/monochrome.json')

const COLOR_CLASS = {
Expand Down Expand Up @@ -44,23 +44,23 @@ const babelTransform = (component) => {

uniconsConfig.forEach(icon => {
const baseName = `uim-${icon.name}`
const location = path.join(iconsComponentPath, `${baseName}.js`)
const location = path.join(iconsComponentPath, `${baseName}.tsx`)
const name = upperCamelCase(baseName)
let svgFile = fs.readFileSync(path.resolve('node_modules/@iconscout/unicons', icon.svg), 'utf-8')

Object.keys(COLOR_CLASS).forEach(key => {
svgFile = svgFile.replace(new RegExp(key, 'g'), COLOR_CLASS[key])
})

svgr(svgFile, { svgo: false, expandProps: 'start', svgProps: { width: "{props.size || '1em'}", height: "{props.size || '1em'}", fill: 'currentColor', className: "{`ui-svg-inline ${props.className || ''}`}" } }, { componentName: name }).then(template => {
babelTransform(template).then(code => {
// Add CSS in reactComponent
reactComponent = code.replace(`import * as React from "react";`, `import * as React from "react";\nimport "../utils/style.css";`)
fs.writeFileSync(location, reactComponent, 'utf-8')
})
svgr(svgFile, { typescript: true, svgo: false, svgProps: { width: "{props.size || '1em'}", height: "{props.size || '1em'}", fill: 'currentColor' } }, { componentName: name }).then(template => {
const updatedTemplate = template
.replace(`import * as React from "react";`, `import * as React from "react";\nimport { UimIconProps } from "../index.types"\nimport "../utils/style.css";`)
.replace(`props: React.SVGProps<SVGSVGElement>`, 'props: UimIconProps');

fs.writeFileSync(location, updatedTemplate, 'utf-8')
})

// Add it to index.js
// Add it to index.ts
indexJs.push(`export { default as ${name} } from './icons/${baseName}'`)
})

Expand Down
18 changes: 0 additions & 18 deletions icons/uim-500px.js

This file was deleted.

18 changes: 0 additions & 18 deletions icons/uim-adobe-alt.js

This file was deleted.

18 changes: 0 additions & 18 deletions icons/uim-adobe.js

This file was deleted.

24 changes: 0 additions & 24 deletions icons/uim-airplay.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-alt.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-center-justify.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-center.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-justify.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-left-justify.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-left.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-letter-right.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-right-justify.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-align-right.js

This file was deleted.

20 changes: 0 additions & 20 deletions icons/uim-align.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-amazon.js

This file was deleted.

20 changes: 0 additions & 20 deletions icons/uim-analysis.js

This file was deleted.

17 changes: 0 additions & 17 deletions icons/uim-analytics.js

This file was deleted.

Loading