Skip to content

Commit 6730f65

Browse files
committed
feat: Automate icon registry
1 parent 369b1f5 commit 6730f65

13 files changed

Lines changed: 89 additions & 13 deletions

File tree

442 Bytes
Loading
691 Bytes
Loading
225 Bytes
Loading
-14.7 KB
Binary file not shown.

apps/next/next.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const withAutomation = () => {
2222
// -i- Makes regular img src paths like on the web work for AetherImage in Expo
2323
console.log('\n')
2424
require('aetherspace/scripts/collect-assets')
25+
// -i- Build 'packages/@registries/icons.generated.ts':
26+
// -i- Registers icons for use in the <AetherIcon/> component
27+
console.log('\n')
28+
require('aetherspace/scripts/collect-icons')
2529
// -i- Clear out autogenerated docs folder so it can be rebuilt
2630
console.log('\n')
2731
require('aetherspace/scripts/documentation-reset')

features/app-core/routes/opengraph-image.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ export const contentType = 'image/png'
1919

2020
/* --- Fonts ----------------------------------------------------------------------------------- */
2121

22-
const robotoBlack = fetch(
23-
'https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfChc9AMP6lQ.ttf'
24-
//'https://fonts.googleapis.com/css2?family=Roboto:wght@900&display=swap'
25-
).then((res) => res.arrayBuffer())
22+
const robotoGoogleFontURL = 'https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfChc9AMP6lQ.ttf' // prettier-ignore
23+
const robotoBlack = fetch(robotoGoogleFontURL).then((res) => res.arrayBuffer())
2624

2725
/* --- Image Generation ------------------------------------------------------------------------ */
2826

@@ -50,7 +48,7 @@ export async function Image() {
5048
<img
5149
src="https://codinsonn.dev/_next/image?url=%2Fimg%2FCodelyFansLogoPic160x160.jpeg&w=256&q=75"
5250
alt="Thorr Stevens, a.k.a. codinsonn.dev"
53-
style={{ marginRight: 60, marginTop: 20, borderRadius: 100 }}
51+
style={{ marginRight: 66, marginTop: 20, borderRadius: 100 }}
5452
width="160"
5553
height="160"
5654
/>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"eas-cli": "yarn workspace expo-app eas-cli",
7171
"link-routes": "yarn turbo run aetherspace#link-routes",
7272
"collect-assets": "yarn turbo run aetherspace#collect-assets",
73+
"collect-icons": "yarn turbo run aetherspace#collect-icons",
7374
"collect-resolvers": "yarn turbo run aetherspace#collect-resolvers",
7475
"document-components": "yarn turbo run aetherspace#document-components",
7576
"lint": "turbo run lint",

packages/@aetherspace/components/AetherIcon/AetherIcon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// -i- Also keep the React import around, as it breaks Storybook if removed
44
import React, { useMemo } from 'react'
55
import { z, aetherSchema } from '../../schemas'
6-
import { REGISTERED_ICONS, REGISTERED_ICON_KEYS } from 'registries/icons.generated'
6+
import { REGISTERED_ICONS } from 'registries/icons.generated'
77
// Primitives
88
import { AetherImage, AetherView } from '../../primitives'
99

1010
/* --- Types ----------------------------------------------------------------------------------- */
1111

12-
export type AetherIconKey = REGISTERED_ICON_KEYS
12+
export type AetherIconKey = keyof typeof REGISTERED_ICONS
1313

1414
export type AetherIconRenderer = (props: {
1515
name: AetherIconKey

packages/@aetherspace/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": "tsc --project .",
1313
"link-routes": "node scripts/link-routes",
1414
"collect-assets": "node scripts/collect-assets",
15+
"collect-icons": "node scripts/collect-icons",
1516
"collect-resolvers": "node scripts/collect-resolvers",
1617
"documentation-reset": "node scripts/documentation-reset",
1718
"document-components": "node scripts/document-components",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import glob from 'glob'
2+
import fs from 'fs'
3+
// Utils
4+
import { findTargetString, dashToCamel } from '../utils/stringUtils'
5+
6+
/* --- Template ------------------------------------------------------------------------------- */
7+
8+
let iconRegistry = `// -i- Auto generated with 'yarn ats collect-icons'
9+
{{iconRegistryImports}}
10+
11+
/* --- Exports --------------------------------------------------------------------------------- */
12+
13+
export const REGISTERED_ICONS = {
14+
{{iconRegistryExports}}
15+
} as const // prettier-ignore
16+
`
17+
18+
/* --- collect-resolvers ----------------------------------------------------------------------- */
19+
20+
const collectResolvers = () => {
21+
try {
22+
// Get all resolver file paths in the next app's api folder
23+
const featureIconRegistries = glob.sync('../../features/**/icons/registry.tsx')
24+
const packageIconRegistries = glob.sync('../../packages/**/icons/registry.tsx')
25+
const allIconRegistries = [...featureIconRegistries, ...packageIconRegistries]
26+
27+
// Collect all icon registry export parts
28+
const iconRegistryImports = [] as string[]
29+
const iconRegistryExports = [] as string[]
30+
allIconRegistries.forEach((iconRegistryPath) => {
31+
const importPath = iconRegistryPath.replace('.tsx', '')
32+
const importType = iconRegistryPath.includes('features') ? 'features' : 'packages'
33+
const importWorkspace = findTargetString(importPath, `${importType}/$target$/icons/registry`)
34+
const importAlias = `${dashToCamel(importWorkspace!)}Icons`
35+
iconRegistryImports.push(`import { iconRegistry as ${importAlias} } from '${importPath}'`)
36+
iconRegistryExports.push(`...${importAlias},`)
37+
})
38+
39+
// Write iconRegistry file to 'packages/@registries/icons.generated.ts'
40+
iconRegistry = iconRegistry.replace('{{iconRegistryImports}}', iconRegistryImports.join('\n'))
41+
iconRegistry = iconRegistry.replace('{{iconRegistryExports}}', iconRegistryExports.join('\n ')) // prettier-ignore
42+
fs.writeFileSync('../../packages/@registries/icons.generated.ts', iconRegistry)
43+
44+
// Log success
45+
console.log('-----------------------------------------------------------------')
46+
console.log('-i- Successfully created icon registry at:')
47+
console.log('-----------------------------------------------------------------')
48+
console.log(' ✅ packages/@registries/icons.generated.ts')
49+
} catch (err) {
50+
console.log(err)
51+
console.error(err)
52+
process.exit(1)
53+
}
54+
}
55+
56+
/* --- init ------------------------------------------------------------------------------------ */
57+
58+
collectResolvers()

0 commit comments

Comments
 (0)