52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const sourceRoot = process.argv[2];
|
|
if (!sourceRoot) {
|
|
throw new Error('Usage: node scripts/generate-classic-regular-icons.mjs <font-awesome-web-root>');
|
|
}
|
|
|
|
const javascript = readFileSync(path.join(sourceRoot, 'js', 'regular.js'), 'utf8');
|
|
const metadata = JSON.parse(readFileSync(path.join(sourceRoot, 'metadata', 'icons.json'), 'utf8'));
|
|
const start = javascript.indexOf(' var icons = ') + ' var icons = '.length;
|
|
const end = javascript.indexOf('\n };', start) + '\n }'.length;
|
|
if (start < ' var icons = '.length || end < start)
|
|
throw new Error('Classic Regular icons not found');
|
|
|
|
const definitions = JSON.parse(javascript.slice(start, end));
|
|
const icons = Object.keys(definitions)
|
|
.map((name) => {
|
|
const details = metadata[name];
|
|
return {
|
|
name,
|
|
label: details?.label ?? name.replaceAll('-', ' '),
|
|
terms: details?.search?.terms ?? []
|
|
};
|
|
})
|
|
.sort((left, right) => left.label.localeCompare(right.label, 'en'));
|
|
|
|
const output = `// Generated from Font Awesome Pro Plus 7.0.0 Classic Regular metadata.
|
|
// Covered by the Font Awesome Pro commercial license; see THIRD_PARTY_NOTICES.md.
|
|
export type ClassicRegularIcon = {
|
|
\tname: string;
|
|
\tlabel: string;
|
|
\tterms: readonly string[];
|
|
};
|
|
|
|
export const classicRegularIcons: readonly ClassicRegularIcon[] = ${JSON.stringify(icons)};
|
|
|
|
export type IconName = string;
|
|
|
|
export const classicRegularIconNames = new Set<string>(
|
|
classicRegularIcons.map((icon) => icon.name)
|
|
);
|
|
`;
|
|
|
|
writeFileSync('src/lib/icons/classic-regular.ts', output);
|
|
mkdirSync('static/icons', { recursive: true });
|
|
copyFileSync(
|
|
path.join(sourceRoot, 'sprites-full', 'regular.svg'),
|
|
'static/icons/classic-regular.svg'
|
|
);
|
|
console.log(`Generated ${icons.length} Classic Regular icons.`);
|