Skip to content

Commit

Permalink
migrate to esm module
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvice committed Oct 3, 2024
1 parent d8067cc commit 206decf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
18 changes: 9 additions & 9 deletions generator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const path = require('path')
const axios = require('axios')
import fs from 'fs'
import path from 'path'
import axios from 'axios'

const GOOGLE_FONTS_URL =
'https://fonts.google.com/metadata/icons?key=material_symbols&incomplete=true'
Expand Down Expand Up @@ -42,17 +42,17 @@ function generatePropsFile() {
}
`

fs.writeFileSync(path.join(__dirname, 'src', 'types.ts'), typesFile)
fs.writeFileSync(path.join('src', 'types.ts'), typesFile)
}

function generateIndexFile() {
return fs.writeFileSync(path.join(__dirname, 'src', 'index.ts'), '')
return fs.writeFileSync(path.join('src', 'index.ts'), '')
}

function appendToIndexFile(iconName) {
return fs.appendFileSync(
path.join(__dirname, 'src', 'index.ts'),
`export * from './${iconName}'\n`,
path.join('src', 'index.ts'),
`export * from './${iconName}.js'\n`,
)
}

Expand All @@ -76,7 +76,7 @@ async function generateComponent(icon, family, filled = false) {
console.log(`Downloading ${name}`)

await fs.writeFileSync(
path.join(__dirname, 'src', `${name}.tsx`),
path.join('src', `${name}.tsx`),
mapSVGToTemplate(name, svg),
)

Expand Down Expand Up @@ -123,7 +123,7 @@ async function downloadSVG(icon, familyId, filled) {
function mapSVGToTemplate(name, svg) {
return `
import React from 'react'
import { IconProps } from './types'
import { IconProps } from './types.js'
export const ${name}: React.FC<IconProps> = ({ ...props }) => (
${svg}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"publishConfig": {
"access": "public"
},
"type": "module",
"main": "dist/index.js",
"files": [
"readme.md",
Expand Down
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES5",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2022",
"jsx": "react",
"moduleResolution": "Node",
"esModuleInterop": true,
"outDir": "./dist",
"declaration": true,
"strict": true,
"sourceMap": false
},
"include": ["src"],
"exclude": ["node_modules", "**/__test__/*", "**/__tests__/*"]
"exclude": ["node_modules"]
}

0 comments on commit 206decf

Please sign in to comment.