From 301d2d27c19c665164bb831182a78014f0fc03e5 Mon Sep 17 00:00:00 2001 From: junghyeonsu Date: Thu, 7 Nov 2024 14:14:36 +0900 Subject: [PATCH] feat: add drawable's fillColor, strokeColor option --- packages/generator/CHANGELOG.md | 8 ++++++++ packages/generator/package.json | 4 ++-- packages/generator/src/core/drawable.ts | 14 ++++++++++++++ packages/types/CHANGELOG.md | 6 ++++++ packages/types/package.json | 2 +- packages/types/src/lib.d.ts | 3 +++ test/icona.ts | 5 +++-- 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/generator/CHANGELOG.md b/packages/generator/CHANGELOG.md index fdf3646..3bea3b3 100644 --- a/packages/generator/CHANGELOG.md +++ b/packages/generator/CHANGELOG.md @@ -1,5 +1,13 @@ # @icona/generator +## 0.9.1 + +### Patch Changes + +- feat: add drawable's fillColor, strokeColor option +- Updated dependencies + - @icona/types@0.9.1 + ## 0.9.0 ### Minor Changes diff --git a/packages/generator/package.json b/packages/generator/package.json index 519b1d4..e74fb9a 100644 --- a/packages/generator/package.json +++ b/packages/generator/package.json @@ -1,6 +1,6 @@ { "name": "@icona/generator", - "version": "0.9.0", + "version": "0.9.1", "repository": { "type": "git", "url": "git+https://github.com/daangn/icona.git", @@ -25,7 +25,7 @@ "prepack": "yarn build" }, "dependencies": { - "@icona/types": "^0.9.0", + "@icona/types": "^0.9.1", "@svgr/core": "^8.0.0", "@types/cli-progress": "^3.11.5", "cli-progress": "^3.12.0", diff --git a/packages/generator/src/core/drawable.ts b/packages/generator/src/core/drawable.ts index 0b8bfb5..94f0337 100644 --- a/packages/generator/src/core/drawable.ts +++ b/packages/generator/src/core/drawable.ts @@ -26,6 +26,7 @@ export const generateDrawable = async (props: Props) => { const targetPath = getTargetPath(config.path || "drawable"); const drawableConfig = config.svg2vectordrawableConfig || {}; const defaultColor = config.defaultColor; + const fillColor = config.fillColor; if (!icons) { throw new Error("There is no icons data"); @@ -61,6 +62,19 @@ export const generateDrawable = async (props: Props) => { drawable = drawable.replace(/#FF212124/g, defaultColor); } + // NOTE(@junghyeonsu): android:fillColor="something" 인거를 ""사이에 있는 값을 변경하기 + if (fillColor) { + drawable = drawable.replace( + /android:fillColor="[^"]*"/g, + `android:fillColor="${fillColor}"`, + ); + + drawable = drawable.replace( + /android:strokeColor="[^"]*"/g, + `android:strokeColor="${fillColor}"`, + ); + } + await writeFile(drawablePath, drawable); bar.increment(); } diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index ec7abec..cf564c8 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -1,5 +1,11 @@ # @icona/types +## 0.9.1 + +### Patch Changes + +- feat: add drawable's fillColor, strokeColor option + ## 0.9.0 ### Minor Changes diff --git a/packages/types/package.json b/packages/types/package.json index 4236322..2c9371b 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@icona/types", - "version": "0.9.0", + "version": "0.9.1", "repository": { "type": "git", "url": "git+https://github.com/daangn/icona.git", diff --git a/packages/types/src/lib.d.ts b/packages/types/src/lib.d.ts index 5c60328..9748656 100644 --- a/packages/types/src/lib.d.ts +++ b/packages/types/src/lib.d.ts @@ -125,8 +125,11 @@ export interface DrawableConfig extends BaseConfig { * drawable default color is #FF212124 * if you want to change default color, you can use this option * @default #FF212124 + * @deprecated */ defaultColor?: string; + + fillColor?: string; } export interface PNGConfig extends BaseConfig {} diff --git a/test/icona.ts b/test/icona.ts index 64eb6c5..e2eec06 100644 --- a/test/icona.ts +++ b/test/icona.ts @@ -55,10 +55,11 @@ const pdfConfig: PDFConfig = { }; const drawableConfig: DrawableConfig = { - active: false, + active: true, path: "drawable", svg2vectordrawableConfig: {}, - defaultColor: "@color/gray900", + // defaultColor: "@color/gray900", + // fillColor: "@color/gray900", }; const reactConfig: ReactConfig = {