Skip to content

Commit

Permalink
feat(bin): emit aliases as named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
rektdeckard committed Mar 5, 2023
1 parent d93c5c3 commit edae85f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions bin/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import chalk from "chalk";
import { exec } from "node:child_process";

import { ASSETS_PATH, COMPONENTS_PATH, INDEX_PATH } from "./index.js";
import { ALIASES } from "../core/bin/index.js";

const icons = {};
const weights = ["thin", "light", "regular", "bold", "fill", "duotone"];
Expand Down Expand Up @@ -49,6 +50,7 @@ function readFile(pathname, name, weight) {
)
.replace(/<title.*?/, "")
.replace(/"#0+"/g, "{color}")
.replace(/currentColor/g, "{color}")
.replace(/fill\-rule/g, "fillRule")
.replace(/stroke-linecap/g, "strokeLinecap")
.replace(/stroke-linejoin/g, "strokeLinejoin")
Expand Down Expand Up @@ -108,10 +110,7 @@ function generateComponents() {

for (let key in icons) {
const icon = icons[key];
const name = key
.split("-")
.map((substr) => substr.replace(/^\w/, (c) => c.toUpperCase()))
.join("");
const name = pascalize(key);

if (!checkFiles(icon)) {
fails += 1;
Expand Down Expand Up @@ -182,12 +181,11 @@ export { IconContext, IconBase } from "./lib";
`;
for (let key in icons) {
const name = key
.split("-")
.map((substr) => substr.replace(/^\w/, (c) => c.toUpperCase()))
.join("");
const name = pascalize(key);
indexString += `\
export { default as ${name} } from "./icons/${name}";
export { default as ${name}${
!!ALIASES[key] ? `, default as ${pascalize(ALIASES[key])}` : ""
} } from "./icons/${name}";
`;
}
try {
Expand All @@ -202,3 +200,10 @@ export { default as ${name} } from "./icons/${name}";
console.groupEnd();
}
}

function pascalize(str) {
return str
.split("-")
.map((substr) => substr.replace(/^\w/, (c) => c.toUpperCase()))
.join("");
}
2 changes: 1 addition & 1 deletion core
Submodule core updated 4 files
+33 −7 bin/fetch.js
+36 −0 bin/index.js
+120 −80 src/icons.ts
+5 −1 src/types.ts

0 comments on commit edae85f

Please sign in to comment.