Skip to content

Commit

Permalink
build: update tsc config
Browse files Browse the repository at this point in the history
co-authored-by: Pram Gurusinga <[email protected]>
  • Loading branch information
joschka and pgurusinga committed Jun 21, 2024
1 parent 662b4c5 commit 5351cea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ do
mv "$file" "${file/_24px/}"
done

npx @svgr/cli --template template.cjs --typescript --no-svgo --svg-props role="graphics-symbol img" --svg-props focusable=false --svg-props aria-hidden=true --out-dir $react_tmp_path -- $original_svg_path
npx @svgr/cli --index-template index-template.cjs --template component-template.cjs --typescript --no-svgo --svg-props role="graphics-symbol img" --svg-props focusable=false --svg-props aria-hidden=true --out-dir $react_tmp_path -- $original_svg_path

ls $react_tmp_path > files.txt

cd $react_tmp_path

npx tsc --target es6 --jsx react-jsx --outDir ../../$dist_path --declaration --declarationDir ../../$dist_path @../../files.txt
npx tsc --target es6 --module nodenext --moduleResolution nodenext --jsx react-jsx --outDir ../../$dist_path --declaration --declarationDir ../../$dist_path @../../files.txt

File renamed without changes.
25 changes: 25 additions & 0 deletions index-template.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const path = require("path");
const camelCase = require("camelcase");

const formatExportName = (name) => {
if (/[-]/g.test(name) && /^\d/.test(name)) {
return `Svg${camelCase(name, { pascalCase: true })}`
}

if (/^\d/.test(name)) {
return `Svg${name}`
}

return camelCase(name, { pascalCase: true })
}

const indexTemplate = (paths) => {
const exportEntries = paths.map(({ path: filePath }) => {
const basename = path.basename(filePath, path.extname(filePath))
const exportName = formatExportName(basename)
return `export { default as ${exportName} } from './${basename}.js'`
})
return exportEntries.join('\n')
}

exports.default = indexTemplate;

0 comments on commit 5351cea

Please sign in to comment.