1 import * as fs from "fs";
3 // This script expects you to write the output to
4 // ts/WoltLabSuite/WebComponent/fa-metadata.js
6 if (process.argv.length !== 4) {
8 "Expected the path to the `icons.json` metadata as argument #1 and the output format (js, php) as argument #2.",
12 const iconsJson = process.argv[2];
13 const outputFormat = process.argv[3];
15 if (!fs.existsSync(iconsJson)) {
16 throw new Error(`The path '${iconsJson}' does not exist.`);
19 const content = fs.readFileSync(iconsJson, { encoding: "utf8" });
20 let json: MetadataIcons;
22 json = JSON.parse(content);
24 throw new Error(`Unable to parse the metadata file: ${e.message}`);
27 const values: IconData[] = [];
28 const aliases: IconAlias[] = [];
29 Object.entries(json).forEach(([name, icon]) => {
30 // Skip brand icons, because those are only supported as SVG
31 // through the `{icon}` template helper.
32 if (icon.styles.includes("brands")) {
36 const codepoint = String.fromCharCode(parseInt(icon.unicode, 16));
37 values.push([name, [codepoint, icon.styles.includes("regular")]]);
39 if (icon.aliases && Array.isArray(icon.aliases.names)) {
40 icon.aliases.names.forEach((alias) => {
41 aliases.push([alias, name]);
47 switch (outputFormat) {
50 const aliases = new Map(
51 ${JSON.stringify(aliases)}
53 const metadata = new Map(
54 ${JSON.stringify(values)}
57 window.getFontAwesome6Metadata = () => {
58 return new Map(metadata);
61 window.getFontAwesome6IconMetadata = (name) => {
62 return metadata.get(aliases.get(name) || name);
71 .map(([name]) => name)
73 .map((name) => ` '${name}' => true,`)
78 .map(([alias]) => alias)
80 .map((name) => ` '${name}' => true,`)
85 throw new Error("Invalid output format");
88 process.stdout.write(output);
90 type MetadataIcons = {
91 [key: string]: MetadataIcon;
94 type MetadataIconAliases = {
99 aliases?: MetadataIconAliases;
104 type Codepoint = string;
105 type HasRegularVariant = boolean;
107 type IconAlternateName = string;
108 type IconName = string;
109 type IconAlias = [IconAlternateName, IconName];
111 type IconData = [string, IconMetadata];
113 type IconMetadata = [Codepoint, HasRegularVariant];