Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ 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/
packages/timo-design-system/src/icons/index.ts
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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.
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 --build-script-name=build:storybook"
"chromatic": "chromatic --project-token=$CHROMATIC_PROJECT_TOKEN --only-changed --exit-zero-on-changes --build-script-name=build:storybook",
"icons:generate": "node generate-icons.mjs"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
Expand All @@ -29,6 +30,7 @@
"@storybook/react": "8.6.14",
"@storybook/react-vite": "^8.6.14",
"@storybook/theming": "^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
1 change: 0 additions & 1 deletion packages/timo-design-system/src/icons/index.ts

This file was deleted.

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.
39 changes: 39 additions & 0 deletions packages/timo-design-system/svgr.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @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};

export const ${name} = (${variables.props}) => (
${variables.jsx}
);
`;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
},
};

export default config;
Loading
Loading