Repository navigation
[CHORE] SVGR 세팅 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[CHORE] SVGR 세팅 #55
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d160772
chore(ui): @svgr/cli 의존성 추가 (#54)
ehye1 cc60683
chore(ui): SVGR 설정 및 아이콘 생성 스크립트 추가 (#54)
ehye1 baa7300
chore(root): Turborepo icons:generate 태스크 등록 및 빌드 파이프라인 연결 (#54)
ehye1 92358c4
fix(root): check-types 실행 전 icons:generate 선행 의존성 추가 (#54)
ehye1 47cc83d
chore(ui): SVGR 템플릿 export 방식 인라인으로 변경 (#54)
ehye1 ae2dbdb
Merge branch 'develop' of https://github.com/Team-Timo/Timo-client in…
ehye1 6f59da0
chore(ui): icons/index.ts gitignore 추가 및 추적 제거 (#54)
ehye1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 on lines
+10
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}개 아이콘 생성 완료`); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export {}; | ||
| export { PlayIcon } from "./generated/Play"; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} }; | ||
| `; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }, | ||
| }; | ||
|
|
||
| export default config; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.