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:
sam 2024-11-27 20:00:28 +01:00
parent f435ad4cf5
commit 71b59dbb00
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
6 changed files with 2116 additions and 0 deletions

View file

@ -3,3 +3,6 @@
resharper_entity_framework_model_validation_unlimited_string_length_highlighting = none
# This is raised for every single property of records returned by endpoints
resharper_not_accessed_positional_property_local_highlighting = none
[*generated.cs]
generated_code = true

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
namespace Foxnouns.Backend.Utils;
public static partial class BootstrapIcons
{
public static bool IsValid(string icon) => Icons.Contains(icon);
}

View file

@ -2,3 +2,4 @@
package-lock.json
pnpm-lock.yaml
yarn.lock
src/lib/icons.ts

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

File diff suppressed because one or more lines are too long