2023-04-19 02:05:01 -07:00
|
|
|
// This script regenerates the list of icons for the frontend (frontend/src/icons.json)
|
|
|
|
// and the backend (backend/icons/icons.go) 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" assert { type: "json" };
|
|
|
|
|
|
|
|
const keys = Object.keys(icons);
|
|
|
|
|
|
|
|
console.log(`Found ${keys.length} icons`);
|
|
|
|
const output = JSON.stringify(keys);
|
2023-04-19 02:06:52 -07:00
|
|
|
console.log(`Saving file as src/icons.ts`);
|
2023-04-19 02:05:01 -07:00
|
|
|
|
2023-04-19 02:06:52 -07:00
|
|
|
writeFileSync("src/icons.ts", `const icons = ${output};\nexport default icons;`);
|
2023-04-19 02:05:01 -07:00
|
|
|
|
|
|
|
const goCode1 = `// Generated code. DO NOT EDIT
|
|
|
|
package icons
|
|
|
|
|
2023-09-19 17:29:06 -07:00
|
|
|
var icons = map[string]struct{}{
|
2023-04-19 02:05:01 -07:00
|
|
|
`;
|
|
|
|
|
|
|
|
const goCode2 = `}
|
|
|
|
|
|
|
|
// IsValid returns true if the input is the name of a Bootstrap icon.
|
|
|
|
func IsValid(name string) bool {
|
2023-09-19 17:29:06 -07:00
|
|
|
_, ok := icons[name]
|
|
|
|
return ok
|
2023-04-19 02:05:01 -07:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
let goOutput = goCode1;
|
|
|
|
|
|
|
|
keys.forEach((element) => {
|
2023-09-19 17:29:06 -07:00
|
|
|
goOutput += ` "${element}": {},\n`;
|
2023-04-19 02:05:01 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
goOutput += goCode2;
|
|
|
|
|
|
|
|
console.log("Writing Go code");
|
|
|
|
writeFileSync("../backend/icons/icons.go", goOutput);
|