Foxnouns.NET/Foxnouns.Frontend/icons.js

43 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

// 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);