Skip to content
Open
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
src/** linguist-generated
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
type: string

env:
NODE_VERSION: 22
NODE_VERSION: 26

jobs:
build-and-publish:
Expand Down
20 changes: 3 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node_version: [18, 20, 22]
node_version: [26]
steps:
- uses: actions/checkout@v7
- uses: aboutbits/github-actions-node/setup-and-install@v3
Expand All @@ -26,20 +26,6 @@ jobs:
- name: Typecheck

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI only runs lint and typecheck, so nothing checks that the built package can actually be imported through exports. A cheap smoke test after Typecheck would catch a wrong path, file extension or export name (the build already ran during npm ci via prepare):

      - name: Smoke test
        run: node --input-type=module -e "import { IconCachedOutlined } from '@aboutbits/react-material-icons/IconCachedOutlined'"
        shell: bash

run: npm run typecheck
shell: bash

test:
runs-on: ubuntu-26.04
timeout-minutes: 10
strategy:
matrix:
node_version: [18, 20, 22]
steps:
- uses: actions/checkout@v7
- uses: aboutbits/github-actions-node/setup-and-install@v3
with:
node-version: ${{ matrix.node_version }}
registry-url: 'https://npm.pkg.github.com'
registry-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
- name: Test
run: npm run test
- name: Smoke test
run: node --input-type=module -e "import { IconCachedOutlined } from '@aboutbits/react-material-icons/IconCachedOutlined'"
shell: bash
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
26
2 changes: 0 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import jest from '@aboutbits/eslint-config/configs/jest'
import ts from '@aboutbits/eslint-config/configs/ts'
import { defineConfig } from 'eslint/config'

export default defineConfig([
ts,
jest,
{
ignores: ['dist', 'node_modules'],
},
Expand Down
77 changes: 44 additions & 33 deletions generator.js → generator.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable no-console */

const fs = require('fs')
const path = require('path')
const axios = require('axios')
import fs from 'node:fs'
import path from 'node:path'
import axios from 'axios'

const SRC_DIR = path.join(import.meta.dirname, 'src')

const GOOGLE_FONTS_URL =
'https://fonts.google.com/metadata/icons?key=material_symbols&incomplete=true'
Expand All @@ -23,6 +24,8 @@ const getIncludedFamilies = (unsupportedFamilies) => {
}

;(async () => {
const failures = []

generatePropsFile()

const res = await axios.get(GOOGLE_FONTS_URL)
Expand All @@ -32,47 +35,59 @@ const getIncludedFamilies = (unsupportedFamilies) => {
const icons = await JSON.parse(data)

for (const icon of icons.icons) {
await generateComponentsForAllFamilies(icon)
await generateComponentsForAllFamilies(icon, failures)
}

if (failures.length > 0) {
console.error(`\nFailed to generate ${failures.length} component(s):`)
for (const { name, error } of failures) {
console.error(` ${name}: ${error.message}`)
}
process.exitCode = 1
}
})()
})().catch((error) => {
console.error(error)
process.exitCode = 1
})

function generatePropsFile() {
const typesFile = `
import React from 'react'
export interface IconProps extends React.SVGProps<SVGSVGElement> {
title?: string
}
import type { SVGProps } from 'react'

export type IconProps = {
title?: string
} & SVGProps<SVGSVGElement>
`

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

async function generateComponentsForAllFamilies(icon) {
async function generateComponentsForAllFamilies(icon, failures) {
const families = getIncludedFamilies(icon.unsupported_families)

for (const family of families) {
await Promise.all([
generateComponent(icon, family),
generateComponent(icon, family, true),
generateComponent(icon, family, false, failures),
generateComponent(icon, family, true, failures),
])
}
}

async function generateComponent(icon, family, filled = false) {
try {
const name = formatName(icon.name, family.postfix, filled)
async function generateComponent(icon, family, filled, failures) {
const name = formatName(icon.name, family.postfix, filled)

try {
const svg = await downloadSVG(icon.name, family.id, filled)

console.log(`Downloading ${name}`)

await fs.writeFileSync(
path.join(__dirname, 'src', `${name}.tsx`),
fs.writeFileSync(
path.join(SRC_DIR, `${name}.tsx`),
mapSVGToTemplate(name, svg),
)
} catch {
console.log('Error generating component for', icon.name)
//process.abort()
} catch (error) {
console.error(`Error generating ${name}: ${error.message}`)
failures.push({ name, error })
}
}

Expand All @@ -89,11 +104,9 @@ function formatName(string, familyPostfix, filled) {

async function downloadSVG(icon, familyId, filled) {
const filledConfig = filled ? 'fill1' : 'default'
const svg = await axios
.get(
`https://fonts.gstatic.com/s/i/short-term/release/${familyId}/${icon}/${filledConfig}/24px.svg`,
)
.catch((err) => console.log(err))
const svg = await axios.get(
`https://fonts.gstatic.com/s/i/short-term/release/${familyId}/${icon}/${filledConfig}/24px.svg`,
)

return svg.data
.replace('height="24"', '')
Expand All @@ -111,13 +124,11 @@ async function downloadSVG(icon, familyId, filled) {

function mapSVGToTemplate(name, svg) {
return `
import React from 'react'
import { IconProps } from './types'
const ${name}: React.FC<IconProps> = ({ ...props }) => (
import type { IconProps } from './types.js'
import type { FC } from 'react'

export const ${name}: FC<IconProps> = (props) => (
${svg}
)

export { ${name} as default }
`
}
8 changes: 0 additions & 8 deletions jestconfig.json

This file was deleted.

Loading