Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit efe2a7d

Browse files
committed
feat: add custom icons kit to rivet-gg/icons
1 parent e797c8f commit efe2a7d

File tree

6 files changed

+120
-12
lines changed

6 files changed

+120
-12
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"**/coverage/**",
99
"**/tmp",
1010
"**/.turbo/**",
11-
"*gen*"
11+
"*.gen.*"
1212
]
1313
},
1414
"formatter": {

packages/icons/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ Rivet Icons are a set of SVG icons that are used in Rivet products. This package
1616

1717
## Contributing
1818

19-
### Adding new icons
19+
### Prerequisites
20+
21+
Obtain a Font Awesome Pro license and set the `FONTAWESOME_PACKAGE_TOKEN` environment variable to your Font Awesome Pro token. This is required to download the premium icons.
2022

21-
Modify `generateManifest.js` to include new icons. The script will generate a new icon set with the new icons. Commit the changes to the `manifest.json` file.
23+
### Adding new icons
2224

25+
1. Modify `generateManifest.js` to include new icons.
26+
2. Run `./scripts/generateManifest.js` to generate a new `manifest.json` file.
27+
- If you're getting an error: `Could not find package @fortawesome/pro-solid-svg-icons`,
28+
3. Commit the changes to the `manifest.json` file.
29+
4. Run `yarn rebuild @rivet-gg/icons` to generate a new icon set with the new icons.
2330

2431
## Troubleshooting
2532

@@ -30,3 +37,6 @@ Some icons used in the open-source Rivet products are part of the premium Font A
3037
### Can't start/build project
3138
The description of these kinds of errors may vary. This package heavily depends on [postinstall scripts](https://yarnpkg.com/advanced/lifecycle-scripts#postinstall) from Yarn/npm. Make sure you didn't disable them accidentally. Turn on post-installation script support and run `yarn install` or `yarn rebuild @rivet-gg/cions` again. If there is still a problem, please contact us on [Discord](https://rivet.gg/discord").
3239

40+
41+
### `Could not find package @fortawesome/pro-solid-svg-icons` when generating manifest
42+
Make sure you have installed pro icons. If you're getting an error, you can try to install them manually by running `yarn add @fortawesome/pro-solid-svg-icons`, or run `yarn install` in `src` folder. Finally run `./scripts/generateManifest.js` again.

packages/icons/manifest.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,7 @@
20002000
{ "icon": "faTableCellsColumnLock", "aliases": [] },
20012001
{ "icon": "faTableCellsLarge", "aliases": ["faThLarge"] },
20022002
{ "icon": "faTableCellsRowLock", "aliases": [] },
2003+
{ "icon": "faTableCellsRowUnlock", "aliases": [] },
20032004
{ "icon": "faTableColumns", "aliases": ["faColumns"] },
20042005
{ "icon": "faTableList", "aliases": ["faThList"] },
20052006
{
@@ -2176,6 +2177,7 @@
21762177
{ "icon": "faThumbsDown", "aliases": [] },
21772178
{ "icon": "faThumbsUp", "aliases": [] },
21782179
{ "icon": "faThumbtack", "aliases": ["faThumbTack"] },
2180+
{ "icon": "faThumbtackSlash", "aliases": ["faThumbTackSlash"] },
21792181
{ "icon": "faThunderstorm", "aliases": ["faThunderstorm"] },
21802182
{ "icon": "faTicket", "aliases": [] },
21812183
{ "icon": "faTicketAlt", "aliases": ["faTicketAlt"] },
@@ -2403,6 +2405,7 @@
24032405
"aliases": ["faLadderWater", "faSwimmingPool"]
24042406
},
24052407
{ "icon": "faWaveSquare", "aliases": [] },
2408+
{ "icon": "faWebAwesome", "aliases": [] },
24062409
{ "icon": "faWeight", "aliases": ["faWeight"] },
24072410
{ "icon": "faWeightHanging", "aliases": [] },
24082411
{ "icon": "faWeightScale", "aliases": ["faWeight"] },
@@ -2561,6 +2564,7 @@
25612564
{ "icon": "faDAndD", "aliases": [] },
25622565
{ "icon": "faDAndDBeyond", "aliases": [] },
25632566
{ "icon": "faDailymotion", "aliases": [] },
2567+
{ "icon": "faDartLang", "aliases": [] },
25642568
{ "icon": "faDashcube", "aliases": [] },
25652569
{ "icon": "faDebian", "aliases": [] },
25662570
{ "icon": "faDeezer", "aliases": [] },
@@ -2612,6 +2616,7 @@
26122616
{ "icon": "faFirstdraft", "aliases": [] },
26132617
{ "icon": "faFlickr", "aliases": [] },
26142618
{ "icon": "faFlipboard", "aliases": [] },
2619+
{ "icon": "faFlutter", "aliases": [] },
26152620
{ "icon": "faFly", "aliases": [] },
26162621
{
26172622
"icon": "faFontAwesome",
@@ -4431,6 +4436,7 @@
44314436
{ "icon": "faDiamondHalf", "aliases": [] },
44324437
{ "icon": "faDiamondHalfStroke", "aliases": [] },
44334438
{ "icon": "faDiamondTurnRight", "aliases": ["faDirections"] },
4439+
{ "icon": "faDiamonds4", "aliases": [] },
44344440
{ "icon": "faDice", "aliases": [] },
44354441
{ "icon": "faDiceD10", "aliases": [] },
44364442
{ "icon": "faDiceD12", "aliases": [] },
@@ -5092,6 +5098,7 @@
50925098
{ "icon": "faGlobePointer", "aliases": [] },
50935099
{ "icon": "faGlobeSnow", "aliases": [] },
50945100
{ "icon": "faGlobeStand", "aliases": [] },
5101+
{ "icon": "faGlobeWifi", "aliases": [] },
50955102
{ "icon": "faGloveBoxing", "aliases": ["faGloveBoxing"] },
50965103
{ "icon": "faGoalNet", "aliases": [] },
50975104
{ "icon": "faGolfBall", "aliases": ["faGolfBall"] },
@@ -5449,6 +5456,7 @@
54495456
{ "icon": "faHumidity", "aliases": ["faHumidity"] },
54505457
{ "icon": "faHundredPoints", "aliases": ["fa100"] },
54515458
{ "icon": "faHurricane", "aliases": [] },
5459+
{ "icon": "faHydra", "aliases": [] },
54525460
{ "icon": "faHyphen", "aliases": [] },
54535461
{ "icon": "faI", "aliases": [] },
54545462
{ "icon": "faICursor", "aliases": [] },
@@ -5625,6 +5633,7 @@
56255633
{ "icon": "faLightbulbExclamation", "aliases": [] },
56265634
{ "icon": "faLightbulbExclamationOn", "aliases": [] },
56275635
{ "icon": "faLightbulbGear", "aliases": [] },
5636+
{ "icon": "faLightbulbMessage", "aliases": [] },
56285637
{ "icon": "faLightbulbOn", "aliases": [] },
56295638
{ "icon": "faLightbulbSlash", "aliases": [] },
56305639
{ "icon": "faLighthouse", "aliases": [] },
@@ -6033,6 +6042,7 @@
60336042
"icon": "faOctagonXmark",
60346043
"aliases": ["faTimesOctagon", "faXmarkOctagon"]
60356044
},
6045+
{ "icon": "faOctopus", "aliases": [] },
60366046
{ "icon": "faOilCan", "aliases": [] },
60376047
{ "icon": "faOilCanDrip", "aliases": [] },
60386048
{ "icon": "faOilTemp", "aliases": ["faOilTemp"] },
@@ -7201,9 +7211,12 @@
72017211
{ "icon": "faTable", "aliases": [] },
72027212
{ "icon": "faTableCells", "aliases": ["faTh"] },
72037213
{ "icon": "faTableCellsColumnLock", "aliases": [] },
7214+
{ "icon": "faTableCellsColumnUnlock", "aliases": [] },
72047215
{ "icon": "faTableCellsLarge", "aliases": ["faThLarge"] },
72057216
{ "icon": "faTableCellsLock", "aliases": [] },
72067217
{ "icon": "faTableCellsRowLock", "aliases": [] },
7218+
{ "icon": "faTableCellsRowUnlock", "aliases": [] },
7219+
{ "icon": "faTableCellsUnlock", "aliases": [] },
72077220
{ "icon": "faTableColumns", "aliases": ["faColumns"] },
72087221
{ "icon": "faTableLayout", "aliases": [] },
72097222
{ "icon": "faTableList", "aliases": ["faThList"] },
@@ -7424,6 +7437,7 @@
74247437
{ "icon": "faThumbsDown", "aliases": [] },
74257438
{ "icon": "faThumbsUp", "aliases": [] },
74267439
{ "icon": "faThumbtack", "aliases": ["faThumbTack"] },
7440+
{ "icon": "faThumbtackSlash", "aliases": ["faThumbTackSlash"] },
74277441
{ "icon": "faThunderstorm", "aliases": ["faThunderstorm"] },
74287442
{ "icon": "faThunderstormMoon", "aliases": ["faThunderstormMoon"] },
74297443
{ "icon": "faThunderstormSun", "aliases": ["faThunderstormSun"] },
@@ -7748,6 +7762,7 @@
77487762
{ "icon": "faUserAlt", "aliases": ["faUserAlt"] },
77497763
{ "icon": "faUserAltSlash", "aliases": ["faUserAltSlash"] },
77507764
{ "icon": "faUserAstronaut", "aliases": [] },
7765+
{ "icon": "faUserBeardBolt", "aliases": [] },
77517766
{ "icon": "faUserBountyHunter", "aliases": [] },
77527767
{ "icon": "faUserChart", "aliases": ["faUserChart"] },
77537768
{ "icon": "faUserCheck", "aliases": [] },
@@ -7788,6 +7803,7 @@
77887803
"icon": "faUserHelmetSafety",
77897804
"aliases": ["faUserConstruction", "faUserHardHat"]
77907805
},
7806+
{ "icon": "faUserHoodie", "aliases": [] },
77917807
{ "icon": "faUserInjured", "aliases": [] },
77927808
{ "icon": "faUserLarge", "aliases": ["faUserAlt"] },
77937809
{ "icon": "faUserLargeSlash", "aliases": ["faUserAltSlash"] },
@@ -8040,5 +8056,11 @@
80408056
{ "icon": "faZzz", "aliases": ["faZzz"] }
80418057
],
80428058
"prefix": "fas"
8059+
},
8060+
"@awesome.me/kit-63db24046b/icons/kit/custom": {
8061+
"icons": [
8062+
{ "icon": "faActors", "aliases": [] },
8063+
{ "icon": "faSelect", "aliases": [] }
8064+
]
80438065
}
80448066
}

packages/icons/scripts/generateManifest.js

100644100755
Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// @ts-check
22
const fs = require("node:fs");
3-
const { getPackageInfo } = require("local-pkg");
3+
const { getPackageInfo, importModule, resolveModule } = require("local-pkg");
4+
const { join } = require("node:path");
45

56
const icons = new Set();
67

8+
const searchPaths = [
9+
join(__dirname, "..", "src", "node_modules"),
10+
join(__dirname, "..", "..", "..", "node_modules"),
11+
];
12+
713
function faCamelCase(str) {
814
const [firstLetter, ...restLetters] = str.replace(/-./g, (g) =>
915
g[1].toUpperCase(),
@@ -12,22 +18,27 @@ function faCamelCase(str) {
1218
}
1319

1420
async function registerIcons(iconModuleName) {
15-
const info = await getPackageInfo(iconModuleName);
21+
const info = await getPackageInfo(iconModuleName, {
22+
paths: searchPaths,
23+
});
1624

1725
if (!info) {
18-
console.error("Could not find package", iconModuleName);
19-
return;
26+
throw new Error(`Could not find package ${iconModuleName}`);
2027
}
2128

2229
const { rootPath } = info;
2330

31+
const module = resolveModule(iconModuleName, { paths: [rootPath] });
32+
if (!module) {
33+
throw new Error(`Could not resolve module ${iconModuleName}`);
34+
}
2435
const files = await fs.promises.readdir(rootPath);
2536

2637
const iconFiles = files.filter(
2738
(file) => file.startsWith("fa") && file.endsWith(".js"),
2839
);
2940

30-
const iconsModule = require(iconModuleName);
41+
const iconsModule = await importModule(module);
3142

3243
const foundIcons = [];
3344

@@ -54,14 +65,50 @@ async function registerIcons(iconModuleName) {
5465
};
5566
}
5667

68+
function registerCustomIcons(iconKit) {
69+
const module = require.resolve(iconKit, { paths: searchPaths });
70+
71+
if (!module) {
72+
throw new Error(`Could not resolve module ${iconKit}`);
73+
}
74+
75+
const customIcons = require(module);
76+
77+
const foundIcons = [];
78+
79+
for (const [iconName, iconDefinition] of Object.entries(customIcons)) {
80+
const aliases = iconDefinition.icon?.[2].filter(
81+
(alias) => typeof alias === "string",
82+
);
83+
84+
if (
85+
icons.has(iconDefinition.iconName) ||
86+
aliases.some((alias) => icons.has(alias))
87+
) {
88+
continue;
89+
}
90+
91+
foundIcons.push({ icon: iconName, aliases: aliases.map(faCamelCase) });
92+
}
93+
94+
return { [iconKit]: { icons: foundIcons } };
95+
}
96+
5797
async function generateManifest() {
5898
const manifest = {
5999
...(await registerIcons("@fortawesome/free-solid-svg-icons")),
60100
...(await registerIcons("@fortawesome/free-brands-svg-icons")),
61101
...(await registerIcons("@fortawesome/pro-solid-svg-icons")),
102+
...registerCustomIcons("@awesome.me/kit-63db24046b/icons/kit/custom"),
62103
};
63104

64-
fs.writeFileSync("./manifest.json", JSON.stringify(manifest));
105+
fs.writeFileSync(
106+
join(__dirname, "../manifest.json"),
107+
JSON.stringify(manifest),
108+
);
65109
}
66110

67-
generateManifest().catch(() => process.exit(1));
111+
generateManifest().catch((e) => {
112+
console.error(e);
113+
process.exit(1);
114+
});

packages/icons/scripts/postinstall.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ if (process.env.FONTAWESOME_PACKAGE_TOKEN) {
2626
npmAlwaysAuth: true
2727
npmRegistryServer: 'https://npm.fontawesome.com/'
2828
npmAuthToken: \${FONTAWESOME_PACKAGE_TOKEN}
29+
awesome.me:
30+
npmAlwaysAuth: true
31+
npmRegistryServer: "https://npm.fontawesome.com/"
32+
npmAuthToken: \${FONTAWESOME_PACKAGE_TOKEN}
2933
`,
3034
);
3135

@@ -74,6 +78,18 @@ let indexTsSource = dedent`
7478

7579
for (const [pkg, { icons }] of Object.entries(manifest)) {
7680
const pkgExists = pkg.includes("pro") ? isPro : true;
81+
const isCustom = pkg.startsWith("@awesome.me/kit-");
82+
83+
if (isCustom) {
84+
if (!pkgExists) {
85+
const iconNames = icons.map(({ icon }) => icon);
86+
const exp = iconNames.map((icon) => `definition as ${icon}`).join(", ");
87+
indexTsSource += `export { ${exp} } from "@fortawesome/free-solid-svg-icons/faSquare";\n`;
88+
} else {
89+
indexTsSource += `export * from "${pkg}";\n`;
90+
}
91+
continue;
92+
}
7793

7894
for (const { icon, aliases } of icons) {
7995
if (!indexTsSource.includes(`export { definition as ${icon} }`)) {
@@ -101,6 +117,18 @@ import {type IconPack} from "@fortawesome/fontawesome-common-types";\n`;
101117

102118
for (const [pkg, { icons }] of Object.entries(manifest)) {
103119
const pkgExists = pkg.includes("pro") ? isPro : true;
120+
const isCustom = pkg.startsWith("@awesome.me/kit-");
121+
122+
if (isCustom) {
123+
const iconNames = icons.map(({ icon }) => icon);
124+
if (!pkgExists) {
125+
const exp = iconNames.map((icon) => `definition as ${icon}`).join(", ");
126+
iconsPackTsSource += `import {${exp}} from "@fortawesome/free-solid-svg-icons/faSquare";\n`;
127+
} else {
128+
iconsPackTsSource += `import {${iconNames.join(",")}} from "${pkg}";\n`;
129+
}
130+
continue;
131+
}
104132

105133
for (const { icon } of icons) {
106134
if (iconsPackTsSource.includes(`import {definition as ${icon}}`)) {

packages/icons/src/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "@rivet-gg/internal-icons",
33
"private": true,
44
"dependencies": {
5-
"@fortawesome/pro-regular-svg-icons": "^6.6.0",
6-
"@fortawesome/pro-solid-svg-icons": "^6.6.0"
5+
"@awesome.me/kit-63db24046b": "^1.0.11",
6+
"@fortawesome/pro-regular-svg-icons": "6.6.0",
7+
"@fortawesome/pro-solid-svg-icons": "6.6.0"
78
}
89
}

0 commit comments

Comments
 (0)