use shared supported style info

This commit is contained in:
Brett Jephson
2026-04-30 09:41:57 +01:00
parent c765394914
commit 07be0e224c
3 changed files with 36 additions and 46 deletions
@@ -5,26 +5,29 @@ const path = require('node:path');
const packageJSONPath = require.resolve('@gitbook/fontawesome-pro/package.json');
const packageRoot = path.dirname(packageJSONPath);
const supportedStyles = require('../src/lib/icons/supported-styles.json');
const outputDirectory = path.resolve(__dirname, '../.generated/icon-symbols');
const loadersModulePath = path.resolve(__dirname, '../.generated/icon-symbol-loaders.ts');
const metadataPath = path.join(packageRoot, 'icons', 'metadata', 'icons.json');
const supportedStyles = [
'brands',
'custom-icons',
'duotone',
'light',
'regular',
'sharp-duotone-solid',
'sharp-light',
'sharp-regular',
'sharp-solid',
'sharp-thin',
'solid',
'thin',
];
const symbolPattern = /<symbol id="([^"]+)" viewBox="([^"]+)">([\s\S]*?)<\/symbol>/g;
function generateLoadersModule(styles) {
const entries = styles
.map((style) => {
return ` ${JSON.stringify(style)}: () =>
import('./icon-symbols/${style}.json', { with: { type: 'json' } }),`;
})
.join('\n');
return `import type { StyleIconSymbolManifest } from '../src/lib/icons/types';
export const loaders = {
${entries}
} satisfies Record<string, () => Promise<{ default: StyleIconSymbolManifest }>>;
`;
}
async function main() {
await fs.rm(outputDirectory, { recursive: true, force: true });
await fs.mkdir(outputDirectory, { recursive: true });
@@ -63,6 +66,8 @@ async function main() {
})
);
await fs.writeFile(loadersModulePath, generateLoadersModule(supportedStyles), 'utf8');
// biome-ignore lint/suspicious/noConsole: CLI output is useful when regenerating manifests.
console.log(`Generated ${supportedStyles.length} icon symbol manifests in ${outputDirectory}`);
}
@@ -0,0 +1,14 @@
[
"brands",
"custom-icons",
"duotone",
"light",
"regular",
"sharp-duotone-solid",
"sharp-light",
"sharp-regular",
"sharp-solid",
"sharp-thin",
"solid",
"thin"
]
+2 -31
View File
@@ -1,37 +1,8 @@
import 'server-only';
import { loaders } from '../../../.generated/icon-symbol-loaders';
import type { StyleIconSymbolManifest } from './types';
const loaders = {
brands: () =>
import('../../../.generated/icon-symbols/brands.json', { with: { type: 'json' } }),
'custom-icons': () =>
import('../../../.generated/icon-symbols/custom-icons.json', {
with: { type: 'json' },
}),
duotone: () =>
import('../../../.generated/icon-symbols/duotone.json', { with: { type: 'json' } }),
light: () => import('../../../.generated/icon-symbols/light.json', { with: { type: 'json' } }),
regular: () =>
import('../../../.generated/icon-symbols/regular.json', { with: { type: 'json' } }),
'sharp-duotone-solid': () =>
import('../../../.generated/icon-symbols/sharp-duotone-solid.json', {
with: { type: 'json' },
}),
'sharp-light': () =>
import('../../../.generated/icon-symbols/sharp-light.json', { with: { type: 'json' } }),
'sharp-regular': () =>
import('../../../.generated/icon-symbols/sharp-regular.json', {
with: { type: 'json' },
}),
'sharp-solid': () =>
import('../../../.generated/icon-symbols/sharp-solid.json', { with: { type: 'json' } }),
'sharp-thin': () =>
import('../../../.generated/icon-symbols/sharp-thin.json', { with: { type: 'json' } }),
solid: () => import('../../../.generated/icon-symbols/solid.json', { with: { type: 'json' } }),
thin: () => import('../../../.generated/icon-symbols/thin.json', { with: { type: 'json' } }),
} satisfies Record<string, () => Promise<{ default: StyleIconSymbolManifest }>>;
type SupportedSymbolStyle = keyof typeof loaders;
const manifestPromises = new Map<string, Promise<StyleIconSymbolManifest>>();
@@ -56,7 +27,7 @@ export async function getIconStyleManifest(style: string): Promise<StyleIconSymb
}
const manifestPromise: Promise<StyleIconSymbolManifest> = load().then(
(module) => module.default
(module) => module.default as StyleIconSymbolManifest
);
manifestPromises.set(style, manifestPromise);