Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ yarn-error.log*

# Storybook build output
packages/timo-design-system/storybook-static/
packages/timo-design-system/build-storybook.log
packages/timo-design-system/build-storybook.log

# Icon generated files
packages/timo-design-system/src/icons/generated/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"check-types": "turbo run check-types",
"check-types:web": "turbo run check-types --filter=timo-web",
"gen": "turbo gen",
"prepare": "husky"
"prepare": "husky",
"icons:generate": "pnpm --filter @repo/timo-design-system icons:generate"
},
"devDependencies": {
"@turbo/gen": "^2.9.18",
Expand Down
45 changes: 45 additions & 0 deletions packages/timo-design-system/generate-icons.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const toPascalCase = (str) =>
str
.replace(/[-_](.)/g, (_, c) => c.toUpperCase())
.replace(/^(.)/, (_, c) => c.toUpperCase());
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment on lines +10 to +11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음 보는 패턴이 있어서 찾아봤더니 정규식이라는 걸 처음 알게 됐어요! 복잡한 문자열 변환을 한 줄로 처리할 수 있는게 신기하네요 👀


const outputDir = path.join(__dirname, "src/icons/generated");
const barrelFile = path.join(__dirname, "src/icons/index.ts");

if (fs.existsSync(outputDir)) {
fs.rmSync(outputDir, { recursive: true });
}
fs.mkdirSync(outputDir, { recursive: true });

execSync(
`pnpm exec svgr --config-file svgr.config.mjs --no-index --out-dir src/icons/generated src/icons/source`,
{ cwd: __dirname, stdio: "inherit" },
);

const files = fs
.readdirSync(outputDir)
.filter((f) => f.endsWith(".tsx"))
.sort();

const exports = files
.map((f) => {
const base = path.basename(f, ".tsx");
return `export { ${toPascalCase(base)}Icon } from './generated/${base}';`;
})
.join("\n");

fs.writeFileSync(barrelFile, exports + "\n");

execSync(`pnpm prettier --write src/icons/generated src/icons/index.ts`, {
cwd: __dirname,
stdio: "inherit",
});

console.log(`✅ ${files.length}개 아이콘 생성 완료`);
4 changes: 3 additions & 1 deletion packages/timo-design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"check-types": "tsc --noEmit",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"chromatic": "chromatic --project-token=$CHROMATIC_PROJECT_TOKEN --only-changed --exit-zero-on-changes"
"chromatic": "chromatic --project-token=$CHROMATIC_PROJECT_TOKEN --only-changed --exit-zero-on-changes",
"icons:generate": "node generate-icons.mjs"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
Expand All @@ -27,6 +28,7 @@
"@storybook/addon-links": "^8.6.14",
"@storybook/react": "8.6.14",
"@storybook/react-vite": "^8.6.14",
"@svgr/cli": "^8.1.0",
"@tailwindcss/postcss": "^4.3.1",
"@types/node": "^22.15.3",
"@types/react": "19.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/timo-design-system/src/icons/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {};
export { PlayIcon } from "./generated/Play";
3 changes: 3 additions & 0 deletions packages/timo-design-system/src/icons/source/play.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions packages/timo-design-system/svgr.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/** @type {import('@svgr/core').Config} */
const config = {
icon: false,
typescript: true,
jsxRuntime: "automatic",
prettier: false,
svgo: true,
svgoConfig: {
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false,
},
},
},
{
name: "removeAttrs",
params: { attrs: ["style"] },
},
],
},
svgProps: {
"aria-hidden": "true",
},
template: (variables, { tpl }) => {
const name = variables.componentName.replace(/^Svg/, "") + "Icon";
return tpl`
${variables.imports};

const ${name} = (${variables.props}) => (
${variables.jsx}
);

export { ${name} };
`;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
};

export default config;
Loading
Loading