mirror of
https://github.com/tabler/tabler.git
synced 2026-10-14 06:07:07 +04:00
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
// Regenerates shared/data/icons.json and icons-info.json from the installed
|
|
// @tabler/icons package. `pnpm run update:icons` bumps the package first.
|
|
//
|
|
// Run: pnpm run import:icons
|
|
import { readFileSync, writeFileSync } from 'node:fs'
|
|
import { join, dirname } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
interface IconTag {
|
|
styles: {
|
|
outline?: unknown
|
|
filled?: unknown
|
|
}
|
|
}
|
|
|
|
interface IconEntry {
|
|
name: string
|
|
svg: {
|
|
outline: string | null
|
|
filled: string | null
|
|
}
|
|
}
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const repoRoot = join(__dirname, '..')
|
|
|
|
const iconsPackage = join(repoRoot, 'node_modules/@tabler/icons')
|
|
const iconsTags: Record<string, IconTag> = JSON.parse(readFileSync(join(iconsPackage, 'icons.json'), 'utf8'))
|
|
const { version }: { version: string } = JSON.parse(readFileSync(join(iconsPackage, 'package.json'), 'utf8'))
|
|
|
|
const prepareSvgFile = (svg: string): string => {
|
|
return svg.replace(/\n/g, '').replace(/>\s+</g, '><').replace(/\s+/g, ' ')
|
|
}
|
|
|
|
const svgList: Record<string, IconEntry> = {}
|
|
for (const iconName in iconsTags) {
|
|
const iconData = iconsTags[iconName]
|
|
svgList[iconName] = {
|
|
name: iconName,
|
|
svg: {
|
|
outline: iconData.styles.outline ? prepareSvgFile(readFileSync(join(iconsPackage, `icons/outline/${iconName}.svg`), 'utf8')) : null,
|
|
filled: iconData.styles.filled ? prepareSvgFile(readFileSync(join(iconsPackage, `icons/filled/${iconName}.svg`), 'utf8')) : null,
|
|
},
|
|
}
|
|
}
|
|
|
|
// `count` is the number of unique icons, not of the outline and filled files.
|
|
writeFileSync(join(repoRoot, 'shared/data/icons-info.json'), JSON.stringify({ version, count: Object.keys(svgList).length }))
|
|
|
|
writeFileSync(join(repoRoot, 'shared/data/icons.json'), JSON.stringify(svgList))
|
|
|
|
console.log(`import-icons: imported ${Object.keys(svgList).length} icons from @tabler/icons v${version}`)
|