Skip to content

Commit

Permalink
feat(Icon): build icon dictionary within icon bundler (#761)
Browse files Browse the repository at this point in the history
* feat: build icon dictionary within icon bundler

* refactor: renamed file to be icons/dictionary.json

* dict with labels

* fix(SplitButton): persist selection disabled by default
  • Loading branch information
fredmaggiowski authored Dec 13, 2024
1 parent 28a7a03 commit 3aca939
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
56 changes: 55 additions & 1 deletion scripts/build-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ import path from 'path'
import url from 'url'

const REACT_ICONS_VERSION = '5.3.0'
const REACT_ICONS_PACKAGES = ['lib', 'ai', 'fi', 'pi']

const MIA_IP_PREFIX = 'mi'
const FEATHER_IP_PREFIX = 'fi'
const PHOSPSHOR_IP_PREFIX = 'pi'

const REACT_ICONS_PACKAGES = ['lib', MIA_IP_PREFIX, FEATHER_IP_PREFIX, PHOSPSHOR_IP_PREFIX]
const ICON_PACK_LABELS: Record<string, string> = {
[MIA_IP_PREFIX]: 'Mia-Platform Icons',
[FEATHER_IP_PREFIX]: 'Feather Icons',
[PHOSPSHOR_IP_PREFIX]: 'Phosphor Icons',
}

const dirname = path.dirname(url.fileURLToPath(import.meta.url))
const rootDir = path.resolve(dirname, '..')
Expand Down Expand Up @@ -162,6 +172,47 @@ async function buildMiaIcons(): Promise<void> {
await Promise.all(promises)
}

type DictionaryPack ={
label: string,
list: string[],
}

async function buildIconDictionary(): Promise<void> {
const files = await glob(path.resolve(outDir, '*/*.mjs'))

const parsePath = (fullPath: string): {name: string, pkg: string} => {
const tokens = fullPath.split('/')
const file = tokens[tokens.length - 1]
const pkg = tokens[tokens.length - 2]
return { name: file.replace('.mjs', ''), pkg }
}

const dictionary = files.reduce((acc, filePath) => {
const { name, pkg } = parsePath(filePath)
if (pkg === 'lib') {
return acc
}

let pack = acc[pkg]
if (!pack) {
pack = {
label: ICON_PACK_LABELS[pkg],
list: [],
}
}

return {
...acc,
[pkg]: {
...pack,
list: pack.list.concat(name),
},
}
}, {} as Record<string, DictionaryPack>)

await fs.writeFile(`${outDir}/dictionary.json`, JSON.stringify(dictionary))
}

async function main(): Promise<void> {
console.info(`» Start icons building process`)

Expand All @@ -173,6 +224,9 @@ async function main(): Promise<void> {

await buildMiaIcons()
console.debug('» Mia-Platform icons built')

await buildIconDictionary()
console.debug('» Icon dictionary built')
}

main()
Expand Down
1 change: 1 addition & 0 deletions src/components/SplitButton/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const SplitButton = ({
<Dropdown
itemLayout={itemLayout}
items={items}
persistSelection={false}
placement={Dropdown.Placement.BottomRight}
onClick={onItemClick}
onOpenChange={onOpenChange}
Expand Down

0 comments on commit 3aca939

Please sign in to comment.