Skip to content

Commit

Permalink
Merge pull request #26 from eduardconstantin/feat/add-types
Browse files Browse the repository at this point in the history
Feat/add types
  • Loading branch information
eduardconstantin authored Oct 9, 2023
2 parents 2242ec2 + 5d9dd98 commit 8dcfe38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
19 changes: 15 additions & 4 deletions build/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "doticons",
"version": "0.6.0",
"version": "0.6.1",
"description": "Doticons is a comprehensive and carefully curated collection of SVG dot icons.",
"author": "Eduard-Constantin Ibinceanu",
"license": "MIT",
"keywords": [
"doticons",
"icons",
"svg",
"dot matrix"
"dot matrix",
"collection"
],
"homepage": "https://github.com/eduardconstantin/doticons#readme",
"repository": {
Expand All @@ -31,10 +32,20 @@
"default": "./package.json"
},
"./16/index": {
"default": "./16/index.js"
"default": "./16/index.js",
"types":"./16/index.d.ts"
},
"./16": {
"default": "./16/index.js",
"types":"./16/index.d.ts"
},
"./32/index": {
"default": "./32/index.js"
"default": "./32/index.js",
"types":"./32/index.d.ts"
},
"./32": {
"default": "./32/index.js",
"types":"./32/index.d.ts"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doticons-source",
"version": "0.6.0",
"version": "0.6.1",
"description": "Doticons is a comprehensive and carefully curated collection of SVG dot icons.",
"author": "Eduard-Constantin Ibinceanu",
"license": "MIT",
Expand Down
11 changes: 9 additions & 2 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ const buildIcons = async (size, icons) => {
let { code } = await transformAsync(content, {
plugins: [[("@babel/plugin-transform-react-jsx"), { useBuiltIns: true }]],
})

let type = `import * as React from 'react';\ndeclare const ${componentName}: React.ForwardRefExoticComponent<React.PropsWithoutRef<React.SVGProps<SVGSVGElement>> & { width?: string, height?: string, fill?: string } & React.RefAttributes<SVGSVGElement>>;\nexport default ${componentName};\n`

await writeFiles(`build/${size}/${componentName}.js`, code)
await writeFiles(`build/${size}/${componentName}.d.ts`, type)
})
)
await writeFiles(`build/${size}/index.js`, exportIcons(icons))
await writeFiles(`build/${size}/index.d.ts`, exportIcons(icons, false))

}

async function writeFiles(file, text) {
await fs.mkdir(dirname(file), { recursive: true })
await fs.writeFile(file, text, 'utf8')
}

function exportIcons(icons) {
function exportIcons(icons, includeExtension = true) {
return icons
.map(({ componentName }) => {
return `export { default as ${componentName} } from './${componentName}.js'`
let extension = includeExtension ? '.js' : ''
return `export { default as ${componentName} } from './${componentName}${extension}'`
})
.join("\n")
}
Expand Down

0 comments on commit 8dcfe38

Please sign in to comment.