feat: add Deduplicator class for managing unique promises and implement icon library generator
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { write } from "bun";
|
||||
import { libraryRaw } from "@/assets/icons";
|
||||
|
||||
function toJsx(
|
||||
name: string,
|
||||
{ viewBox, svg }: { viewBox: string; svg: string },
|
||||
) {
|
||||
return ` "${name}": (props: SVGProps<SVGSVGElement>) => (<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="${viewBox}"
|
||||
{...props}
|
||||
>
|
||||
<title>${name}</title>
|
||||
${svg
|
||||
.replaceAll("xlink:href", "xlinkHref")
|
||||
.replace(
|
||||
/<style([^>]*)>([^<]+)<\/style>/g,
|
||||
(_, p, g) => `<style${p}>{${JSON.stringify(g)}}</style>`,
|
||||
)
|
||||
.replace(/class(="[^"]+")/g, "className$1")
|
||||
.replace(
|
||||
/style="([^"]+)"/g,
|
||||
(_, g: string) =>
|
||||
`style={${JSON.stringify(
|
||||
Object.fromEntries(
|
||||
g
|
||||
.split(";")
|
||||
.filter((e) => !e.startsWith("-"))
|
||||
.map((r) => r.split(":"))
|
||||
.map(([name, value]) => [
|
||||
name.replace(/-([a-z])/g, (_, m: string) =>
|
||||
m.toUpperCase(),
|
||||
),
|
||||
value,
|
||||
]),
|
||||
),
|
||||
)}}`,
|
||||
)}
|
||||
</svg>),
|
||||
`;
|
||||
}
|
||||
|
||||
console.log(toJsx("Const", libraryRaw.Const));
|
||||
write(
|
||||
"result.tsx",
|
||||
`import { SVGProps } from "react";
|
||||
|
||||
const library = {
|
||||
${Object.entries(libraryRaw)
|
||||
.map(([name, p]) => toJsx(name, p))
|
||||
.join("\n")}
|
||||
};`,
|
||||
);
|
||||
Reference in New Issue
Block a user