Skip to content

Commit

Permalink
feat: update icons
Browse files Browse the repository at this point in the history
  • Loading branch information
fran-ink committed Feb 5, 2025
1 parent a543272 commit 5a8c75d
Show file tree
Hide file tree
Showing 58 changed files with 346 additions and 102 deletions.
106 changes: 74 additions & 32 deletions scripts/import-svgs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,84 @@
import fs from "fs/promises";
import path from "path";

const currentDir = import.meta.dirname;
const iconsDir = path.join(currentDir, "../src/icons");

const svgs = await fs.readdir(iconsDir);
await Promise.all(
svgs
.filter((svg) => svg.endsWith(".svg"))
.map(async (svg) => {
const svgContent = await fs.readFile(path.join(iconsDir, svg), "utf8");
const result = svgContent
.replace(/stroke="#160F1F"/g, 'stroke="currentColor"')
.replace(/fill="#160F1F"/g, 'fill="currentColor"')
.replace(/width="24"/g, 'width="100%"')
.replace(/height="24"/g, 'height="100%"');
await fs.writeFile(path.join(iconsDir, svg), result, "utf8");
})
);

/** Use this to map an invalid name temporarily (until it is fixed in the Figma) */
const iconNameMapping = {};

function getIconName(svg) {
const result = svg.replace(".svg", "").replace("Type=", "");
const result = svg.replace(".svg", "");
return iconNameMapping[result] ?? result;
}

const header = `/**\n * This file is auto-generated by the \`import-svgs.mjs\` script.\n */`;
const content = svgs
.filter((svg) => svg.endsWith(".svg"))
.map(
(svg) => `export { default as ${getIconName(svg)} } from "./${svg}?react";`
)
.join("\n");

await fs.writeFile(
path.join(iconsDir, "index.ts"),
`${header}\n\n${content}\n`,
"utf8"
);
async function processSvgsInFolder(folder) {
// Start by renaming the files to remove the "Type=" or "Propery 1=" prefix
await Promise.all(
(await fs.readdir(folder, { recursive: true })).map(async (name) => {
if (name.includes("=")) {
const newName = name.split("=")[1];
if (await fs.access(path.join(folder, newName)).catch(() => false)) {
await fs.unlink(path.join(folder, newName));
}
await fs.rename(path.join(folder, name), path.join(folder, newName));
}
})
);

const svgs = await fs.readdir(folder, { recursive: true });
await Promise.all(
svgs
.filter((svg) => svg.endsWith(".svg"))
.map(async (svg) => {
console.log(path.join(folder, svg));
const svgContent = await fs.readFile(path.join(folder, svg), "utf8");
const result = svgContent
.replace(/stroke="#160F1F"/g, 'stroke="currentColor"')
.replace(/fill="#160F1F"/g, 'fill="currentColor"')
.replace(/width="24"/g, 'width="100%"')
.replace(/height="24"/g, 'height="100%"');
await fs.writeFile(path.join(folder, svg), result, "utf8");
})
);
}

async function createIndexFile(folder) {
const header = `/**\n * This file is auto-generated by the \`import-svgs.mjs\` script.\n */`;
const stuffInDir = await fs.readdir(folder);
const foundSvgs = [];
const foundFolders = [];
await Promise.all(
stuffInDir.map(async (stuff) => {
if (stuff.endsWith(".svg")) {
foundSvgs.push(stuff);
} else if ((await fs.stat(path.join(folder, stuff))).isDirectory()) {
foundFolders.push(stuff);
}
})
);
await Promise.all(
foundFolders.map(async (f) => {
await createIndexFile(path.join(folder, f));
})
);
const content = foundSvgs
.map(
(svg) =>
`export { default as ${getIconName(svg)} } from "./${svg}?react";`
)
.concat(
foundFolders.map(
(folder) => `export * as ${folder} from "./${folder}/index.ts";`
)
)
.join("\n");

await fs.writeFile(
path.join(folder, "index.ts"),
`${header}\n\n${content}\n`,
"utf8"
);
}

const currentDir = import.meta.dirname;
const dirToProcess = path.join(currentDir, "../src/icons");
await processSvgsInFolder(dirToProcess);
await createIndexFile(dirToProcess);
3 changes: 3 additions & 0 deletions src/icons/Apps.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
5 changes: 5 additions & 0 deletions src/icons/Bridge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/Check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/CheckBadge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
5 changes: 5 additions & 0 deletions src/icons/Code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions src/icons/Dots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions src/icons/History.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/Home.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
5 changes: 5 additions & 0 deletions src/icons/Icon/SocialFarcaster.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading

0 comments on commit 5a8c75d

Please sign in to comment.