feat: add icon list generation script
this is used to validate icons for custom preferences. it generates both typescript and c# code
This commit is contained in:
parent
f435ad4cf5
commit
71b59dbb00
6 changed files with 2116 additions and 0 deletions
42
Foxnouns.Frontend/icons.js
Normal file
42
Foxnouns.Frontend/icons.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
// This script regenerates the list of icons for the frontend (Foxnouns.Frontend/src/lib/icons.ts)
|
||||
// and the backend (Foxnouns.Backend/Utils/BootstrapIcons.Icons.cs) from the currently installed version of Bootstrap Icons.
|
||||
// Run with `pnpm node icons.js` in the frontend directory.
|
||||
|
||||
import { writeFileSync } from "fs";
|
||||
import icons from "bootstrap-icons/font/bootstrap-icons.json" with { type: "json" };
|
||||
|
||||
const keys = Object.keys(icons);
|
||||
|
||||
console.log(`Found ${keys.length} icons`);
|
||||
const output = JSON.stringify(keys);
|
||||
console.log(`Saving file as src/icons.ts`);
|
||||
|
||||
writeFileSync(
|
||||
"src/lib/icons.ts",
|
||||
`// Generated code: DO NOT EDIT\n\nconst icons = ${output};\nexport default icons;`,
|
||||
);
|
||||
|
||||
const csCode1 = `// <auto-generated />
|
||||
|
||||
namespace Foxnouns.Backend.Utils;
|
||||
|
||||
public static partial class BootstrapIcons
|
||||
{
|
||||
private static readonly HashSet<string> Icons =
|
||||
[
|
||||
`;
|
||||
|
||||
const csCode2 = ` ];
|
||||
}
|
||||
`;
|
||||
|
||||
let csOutput = csCode1;
|
||||
|
||||
keys.forEach((element) => {
|
||||
csOutput += ` "${element}",\n`;
|
||||
});
|
||||
|
||||
csOutput += csCode2;
|
||||
|
||||
console.log("Writing C# code");
|
||||
writeFileSync("../Foxnouns.Backend/Utils/BootstrapIcons.Icons.generated.cs", csOutput);
|
Loading…
Add table
Add a link
Reference in a new issue