From 9e98a6d952790cdca8c5a8bbdc889a41765a094b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=98=84=EC=88=98?= <54893898+junghyeonsu@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:09:36 +0900 Subject: [PATCH] feat: export png & width, height includes in icons.json & refactoring (#26) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 여러가지 - 폴더 리팩토링 - png 포맷 뽑기 - 피그마 노드의 width, height도 데이터에 넣기 * chore: changeset --- .changeset/lucky-waves-obey.md | 7 + figma-plugin/plugin-src/service.ts | 24 ++- .../figma-svg-extract-action/README.md | 0 .../figma-svg-extract-action/action.yml | 0 .../figma-svg-extract-action/dist/index.d.ts | 0 .../figma-svg-extract-action/dist/index.js | 0 .../dist/octokit.d.ts | 0 .../figma-svg-extract-action/dist/octokit.js | 0 .../figma-svg-extract-action/package.json | 0 .../figma-svg-extract-action/src/index.ts | 0 .../figma-svg-extract-action/src/octokit.ts | 0 .../figma-svg-extract-action/tsconfig.json | 0 .../figma-svg-extracter/.gitignore | 0 .../figma-svg-extracter/README.md | 0 .../figma-svg-extracter/package.json | 0 .../figma-svg-extracter/src/api.ts | 0 .../figma-svg-extracter/src/core.ts | 0 .../figma-svg-extracter/src/index.ts | 0 .../figma-svg-extracter/src/interface.ts | 0 .../figma-svg-extracter/tsconfig.json | 0 .../legacy => legacy}/icona-cli/.gitignore | 0 .../legacy => legacy}/icona-cli/CHANGELOG.md | 0 .../legacy => legacy}/icona-cli/README.md | 0 .../legacy => legacy}/icona-cli/build.mjs | 0 .../legacy => legacy}/icona-cli/package.json | 0 .../legacy => legacy}/icona-cli/src/cli.ts | 2 +- .../icona-cli/src/commands/generate.ts | 0 .../icona-cli/src/commands/init.ts | 0 .../icona-cli/src/core/generate.ts | 0 legacy/icona-cli/src/index.ts | 3 + .../icona-cli/src/templates.ts | 0 .../legacy => legacy}/icona-cli/tsconfig.json | 0 package.json | 4 +- .../{icona-generator => generator}/.gitignore | 0 .../CHANGELOG.md | 0 .../{icona-generator => generator}/README.md | 0 .../package.json | 0 .../src/core/drawable.ts | 0 .../src/core/pdf.ts | 0 .../src/core/png.ts | 0 .../src/core/react.ts | 3 +- .../src/core/svg.ts | 0 .../src/generator.ts | 10 +- packages/generator/src/index.ts | 17 ++ .../tsconfig.json | 0 packages/icona-generator/src/index.ts | 17 -- packages/legacy/icona-cli/src/index.ts | 3 - packages/types/src/data.ts | 13 ++ packages/types/src/index.ts | 166 +----------------- packages/types/src/lib.ts | 157 +++++++++++++++++ packages/{icona-utils => utils}/.gitignore | 0 packages/{icona-utils => utils}/CHANGELOG.md | 0 packages/{icona-utils => utils}/README.md | 0 packages/{icona-utils => utils}/package.json | 2 +- packages/{icona-utils => utils}/src/index.ts | 0 packages/{icona-utils => utils}/tsconfig.json | 0 yarn.lock | 8 +- 57 files changed, 230 insertions(+), 206 deletions(-) create mode 100644 .changeset/lucky-waves-obey.md rename {packages/legacy => legacy}/figma-svg-extract-action/README.md (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/action.yml (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/dist/index.d.ts (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/dist/index.js (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/dist/octokit.d.ts (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/dist/octokit.js (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/package.json (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/src/index.ts (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/src/octokit.ts (100%) rename {packages/legacy => legacy}/figma-svg-extract-action/tsconfig.json (100%) rename {packages/legacy => legacy}/figma-svg-extracter/.gitignore (100%) rename {packages/legacy => legacy}/figma-svg-extracter/README.md (100%) rename {packages/legacy => legacy}/figma-svg-extracter/package.json (100%) rename {packages/legacy => legacy}/figma-svg-extracter/src/api.ts (100%) rename {packages/legacy => legacy}/figma-svg-extracter/src/core.ts (100%) rename {packages/legacy => legacy}/figma-svg-extracter/src/index.ts (100%) rename {packages/legacy => legacy}/figma-svg-extracter/src/interface.ts (100%) rename {packages/legacy => legacy}/figma-svg-extracter/tsconfig.json (100%) rename {packages/legacy => legacy}/icona-cli/.gitignore (100%) rename {packages/legacy => legacy}/icona-cli/CHANGELOG.md (100%) rename {packages/legacy => legacy}/icona-cli/README.md (100%) rename {packages/legacy => legacy}/icona-cli/build.mjs (100%) rename {packages/legacy => legacy}/icona-cli/package.json (100%) rename {packages/legacy => legacy}/icona-cli/src/cli.ts (89%) rename {packages/legacy => legacy}/icona-cli/src/commands/generate.ts (100%) rename {packages/legacy => legacy}/icona-cli/src/commands/init.ts (100%) rename {packages/legacy => legacy}/icona-cli/src/core/generate.ts (100%) create mode 100644 legacy/icona-cli/src/index.ts rename {packages/legacy => legacy}/icona-cli/src/templates.ts (100%) rename {packages/legacy => legacy}/icona-cli/tsconfig.json (100%) rename packages/{icona-generator => generator}/.gitignore (100%) rename packages/{icona-generator => generator}/CHANGELOG.md (100%) rename packages/{icona-generator => generator}/README.md (100%) rename packages/{icona-generator => generator}/package.json (100%) rename packages/{icona-generator => generator}/src/core/drawable.ts (100%) rename packages/{icona-generator => generator}/src/core/pdf.ts (100%) rename packages/{icona-generator => generator}/src/core/png.ts (100%) rename packages/{icona-generator => generator}/src/core/react.ts (92%) rename packages/{icona-generator => generator}/src/core/svg.ts (100%) rename packages/{icona-generator => generator}/src/generator.ts (82%) create mode 100644 packages/generator/src/index.ts rename packages/{icona-generator => generator}/tsconfig.json (100%) delete mode 100644 packages/icona-generator/src/index.ts delete mode 100644 packages/legacy/icona-cli/src/index.ts create mode 100644 packages/types/src/data.ts create mode 100644 packages/types/src/lib.ts rename packages/{icona-utils => utils}/.gitignore (100%) rename packages/{icona-utils => utils}/CHANGELOG.md (100%) rename packages/{icona-utils => utils}/README.md (100%) rename packages/{icona-utils => utils}/package.json (100%) rename packages/{icona-utils => utils}/src/index.ts (100%) rename packages/{icona-utils => utils}/tsconfig.json (100%) diff --git a/.changeset/lucky-waves-obey.md b/.changeset/lucky-waves-obey.md new file mode 100644 index 0000000..0037ed0 --- /dev/null +++ b/.changeset/lucky-waves-obey.md @@ -0,0 +1,7 @@ +--- +"@icona/generator": minor +"@icona/types": minor +"@icona/utils": minor +--- + +PNG 내보내기 & width, height 정보 받기 diff --git a/figma-plugin/plugin-src/service.ts b/figma-plugin/plugin-src/service.ts index 960153e..fa40db4 100644 --- a/figma-plugin/plugin-src/service.ts +++ b/figma-plugin/plugin-src/service.ts @@ -96,33 +96,41 @@ export async function getAssetInIconFrame( const targetComponents = targetNodes.filter((component) => component); - const svgs = await Promise.all( + const datas = await Promise.all( targetComponents.map(async (component) => { + const data = {} as IconaIconData; const node = figma.getNodeById(component.id) as ComponentNode; + // base + data.style = { + width: node.width, + height: node.height, + }; + data.name = component.name; + // svg const svg = await node.exportAsync({ format: "SVG_STRING", svgIdAttribute: true, }); + data.svg = svg; // png if (withPng) { - const png = await node.exportAsync({ - format: "PNG", - }); + const png = await node.exportAsync({ format: "PNG" }); const base64String = Base64.fromUint8Array(png); - return { name: component.name, svg, png: base64String }; + data.png = base64String; } - return { name: component.name, svg }; + + return data; }), ); - const svgsMap = svgs.reduce((acc, cur) => { + const dataMap = datas.reduce((acc, cur) => { acc[cur.name] = cur; return acc; }, {} as Record); - return svgsMap; + return dataMap; } diff --git a/packages/legacy/figma-svg-extract-action/README.md b/legacy/figma-svg-extract-action/README.md similarity index 100% rename from packages/legacy/figma-svg-extract-action/README.md rename to legacy/figma-svg-extract-action/README.md diff --git a/packages/legacy/figma-svg-extract-action/action.yml b/legacy/figma-svg-extract-action/action.yml similarity index 100% rename from packages/legacy/figma-svg-extract-action/action.yml rename to legacy/figma-svg-extract-action/action.yml diff --git a/packages/legacy/figma-svg-extract-action/dist/index.d.ts b/legacy/figma-svg-extract-action/dist/index.d.ts similarity index 100% rename from packages/legacy/figma-svg-extract-action/dist/index.d.ts rename to legacy/figma-svg-extract-action/dist/index.d.ts diff --git a/packages/legacy/figma-svg-extract-action/dist/index.js b/legacy/figma-svg-extract-action/dist/index.js similarity index 100% rename from packages/legacy/figma-svg-extract-action/dist/index.js rename to legacy/figma-svg-extract-action/dist/index.js diff --git a/packages/legacy/figma-svg-extract-action/dist/octokit.d.ts b/legacy/figma-svg-extract-action/dist/octokit.d.ts similarity index 100% rename from packages/legacy/figma-svg-extract-action/dist/octokit.d.ts rename to legacy/figma-svg-extract-action/dist/octokit.d.ts diff --git a/packages/legacy/figma-svg-extract-action/dist/octokit.js b/legacy/figma-svg-extract-action/dist/octokit.js similarity index 100% rename from packages/legacy/figma-svg-extract-action/dist/octokit.js rename to legacy/figma-svg-extract-action/dist/octokit.js diff --git a/packages/legacy/figma-svg-extract-action/package.json b/legacy/figma-svg-extract-action/package.json similarity index 100% rename from packages/legacy/figma-svg-extract-action/package.json rename to legacy/figma-svg-extract-action/package.json diff --git a/packages/legacy/figma-svg-extract-action/src/index.ts b/legacy/figma-svg-extract-action/src/index.ts similarity index 100% rename from packages/legacy/figma-svg-extract-action/src/index.ts rename to legacy/figma-svg-extract-action/src/index.ts diff --git a/packages/legacy/figma-svg-extract-action/src/octokit.ts b/legacy/figma-svg-extract-action/src/octokit.ts similarity index 100% rename from packages/legacy/figma-svg-extract-action/src/octokit.ts rename to legacy/figma-svg-extract-action/src/octokit.ts diff --git a/packages/legacy/figma-svg-extract-action/tsconfig.json b/legacy/figma-svg-extract-action/tsconfig.json similarity index 100% rename from packages/legacy/figma-svg-extract-action/tsconfig.json rename to legacy/figma-svg-extract-action/tsconfig.json diff --git a/packages/legacy/figma-svg-extracter/.gitignore b/legacy/figma-svg-extracter/.gitignore similarity index 100% rename from packages/legacy/figma-svg-extracter/.gitignore rename to legacy/figma-svg-extracter/.gitignore diff --git a/packages/legacy/figma-svg-extracter/README.md b/legacy/figma-svg-extracter/README.md similarity index 100% rename from packages/legacy/figma-svg-extracter/README.md rename to legacy/figma-svg-extracter/README.md diff --git a/packages/legacy/figma-svg-extracter/package.json b/legacy/figma-svg-extracter/package.json similarity index 100% rename from packages/legacy/figma-svg-extracter/package.json rename to legacy/figma-svg-extracter/package.json diff --git a/packages/legacy/figma-svg-extracter/src/api.ts b/legacy/figma-svg-extracter/src/api.ts similarity index 100% rename from packages/legacy/figma-svg-extracter/src/api.ts rename to legacy/figma-svg-extracter/src/api.ts diff --git a/packages/legacy/figma-svg-extracter/src/core.ts b/legacy/figma-svg-extracter/src/core.ts similarity index 100% rename from packages/legacy/figma-svg-extracter/src/core.ts rename to legacy/figma-svg-extracter/src/core.ts diff --git a/packages/legacy/figma-svg-extracter/src/index.ts b/legacy/figma-svg-extracter/src/index.ts similarity index 100% rename from packages/legacy/figma-svg-extracter/src/index.ts rename to legacy/figma-svg-extracter/src/index.ts diff --git a/packages/legacy/figma-svg-extracter/src/interface.ts b/legacy/figma-svg-extracter/src/interface.ts similarity index 100% rename from packages/legacy/figma-svg-extracter/src/interface.ts rename to legacy/figma-svg-extracter/src/interface.ts diff --git a/packages/legacy/figma-svg-extracter/tsconfig.json b/legacy/figma-svg-extracter/tsconfig.json similarity index 100% rename from packages/legacy/figma-svg-extracter/tsconfig.json rename to legacy/figma-svg-extracter/tsconfig.json diff --git a/packages/legacy/icona-cli/.gitignore b/legacy/icona-cli/.gitignore similarity index 100% rename from packages/legacy/icona-cli/.gitignore rename to legacy/icona-cli/.gitignore diff --git a/packages/legacy/icona-cli/CHANGELOG.md b/legacy/icona-cli/CHANGELOG.md similarity index 100% rename from packages/legacy/icona-cli/CHANGELOG.md rename to legacy/icona-cli/CHANGELOG.md diff --git a/packages/legacy/icona-cli/README.md b/legacy/icona-cli/README.md similarity index 100% rename from packages/legacy/icona-cli/README.md rename to legacy/icona-cli/README.md diff --git a/packages/legacy/icona-cli/build.mjs b/legacy/icona-cli/build.mjs similarity index 100% rename from packages/legacy/icona-cli/build.mjs rename to legacy/icona-cli/build.mjs diff --git a/packages/legacy/icona-cli/package.json b/legacy/icona-cli/package.json similarity index 100% rename from packages/legacy/icona-cli/package.json rename to legacy/icona-cli/package.json diff --git a/packages/legacy/icona-cli/src/cli.ts b/legacy/icona-cli/src/cli.ts similarity index 89% rename from packages/legacy/icona-cli/src/cli.ts rename to legacy/icona-cli/src/cli.ts index 100a976..cbb04dd 100644 --- a/packages/legacy/icona-cli/src/cli.ts +++ b/legacy/icona-cli/src/cli.ts @@ -4,7 +4,7 @@ import { Command } from "commander"; import pkg from "../package.json" assert { type: "json" }; // import { generateCommand } from "./commands/generate"; -import { initCommand } from "./commands/init"; +import { initCommand } from "./commands/init.js"; const program = new Command(); const version = pkg.version; diff --git a/packages/legacy/icona-cli/src/commands/generate.ts b/legacy/icona-cli/src/commands/generate.ts similarity index 100% rename from packages/legacy/icona-cli/src/commands/generate.ts rename to legacy/icona-cli/src/commands/generate.ts diff --git a/packages/legacy/icona-cli/src/commands/init.ts b/legacy/icona-cli/src/commands/init.ts similarity index 100% rename from packages/legacy/icona-cli/src/commands/init.ts rename to legacy/icona-cli/src/commands/init.ts diff --git a/packages/legacy/icona-cli/src/core/generate.ts b/legacy/icona-cli/src/core/generate.ts similarity index 100% rename from packages/legacy/icona-cli/src/core/generate.ts rename to legacy/icona-cli/src/core/generate.ts diff --git a/legacy/icona-cli/src/index.ts b/legacy/icona-cli/src/index.ts new file mode 100644 index 0000000..257d465 --- /dev/null +++ b/legacy/icona-cli/src/index.ts @@ -0,0 +1,3 @@ +import { generate } from "./core/generate.js"; + +export { generate }; diff --git a/packages/legacy/icona-cli/src/templates.ts b/legacy/icona-cli/src/templates.ts similarity index 100% rename from packages/legacy/icona-cli/src/templates.ts rename to legacy/icona-cli/src/templates.ts diff --git a/packages/legacy/icona-cli/tsconfig.json b/legacy/icona-cli/tsconfig.json similarity index 100% rename from packages/legacy/icona-cli/tsconfig.json rename to legacy/icona-cli/tsconfig.json diff --git a/package.json b/package.json index a923d5f..2eb02a0 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "author": "junghyeonsu ", "workspaces": [ "packages/types", - "packages/icona-utils", - "packages/icona-generator", + "packages/utils", + "packages/generator", "figma-plugin" ], "scripts": { diff --git a/packages/icona-generator/.gitignore b/packages/generator/.gitignore similarity index 100% rename from packages/icona-generator/.gitignore rename to packages/generator/.gitignore diff --git a/packages/icona-generator/CHANGELOG.md b/packages/generator/CHANGELOG.md similarity index 100% rename from packages/icona-generator/CHANGELOG.md rename to packages/generator/CHANGELOG.md diff --git a/packages/icona-generator/README.md b/packages/generator/README.md similarity index 100% rename from packages/icona-generator/README.md rename to packages/generator/README.md diff --git a/packages/icona-generator/package.json b/packages/generator/package.json similarity index 100% rename from packages/icona-generator/package.json rename to packages/generator/package.json diff --git a/packages/icona-generator/src/core/drawable.ts b/packages/generator/src/core/drawable.ts similarity index 100% rename from packages/icona-generator/src/core/drawable.ts rename to packages/generator/src/core/drawable.ts diff --git a/packages/icona-generator/src/core/pdf.ts b/packages/generator/src/core/pdf.ts similarity index 100% rename from packages/icona-generator/src/core/pdf.ts rename to packages/generator/src/core/pdf.ts diff --git a/packages/icona-generator/src/core/png.ts b/packages/generator/src/core/png.ts similarity index 100% rename from packages/icona-generator/src/core/png.ts rename to packages/generator/src/core/png.ts diff --git a/packages/icona-generator/src/core/react.ts b/packages/generator/src/core/react.ts similarity index 92% rename from packages/icona-generator/src/core/react.ts rename to packages/generator/src/core/react.ts index 1bf1455..0782ad5 100644 --- a/packages/icona-generator/src/core/react.ts +++ b/packages/generator/src/core/react.ts @@ -37,7 +37,8 @@ export const generateReact = ({ const componentName = name .replace(/^[a-z]/, (ch) => ch.toUpperCase()) - .replace(/_[a-z]/g, (ch) => ch[1].toUpperCase()); + .replace(/_[a-z]/g, (ch) => ch[1].toUpperCase()) + .replace(/-[a-z]/g, (ch) => ch[1].toUpperCase()); const component = await transform(svg, svgrConfig as Config, { componentName, diff --git a/packages/icona-generator/src/core/svg.ts b/packages/generator/src/core/svg.ts similarity index 100% rename from packages/icona-generator/src/core/svg.ts rename to packages/generator/src/core/svg.ts diff --git a/packages/icona-generator/src/generator.ts b/packages/generator/src/generator.ts similarity index 82% rename from packages/icona-generator/src/generator.ts rename to packages/generator/src/generator.ts index 25781c4..e9d6252 100644 --- a/packages/icona-generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -1,11 +1,11 @@ import type { IconaConfig, IconaIconData } from "@icona/types"; import { getIconaIconsFile } from "@icona/utils"; -import { generateDrawable } from "./core/drawable"; -import { generatePDF } from "./core/pdf"; -import { generatePNG } from "./core/png"; -import { generateReact } from "./core/react"; -import { generateSVG } from "./core/svg"; +import { generateDrawable } from "./core/drawable.js"; +import { generatePDF } from "./core/pdf.js"; +import { generatePNG } from "./core/png.js"; +import { generateReact } from "./core/react.js"; +import { generateSVG } from "./core/svg.js"; export const generator = ( icons: Record, diff --git a/packages/generator/src/index.ts b/packages/generator/src/index.ts new file mode 100644 index 0000000..ff1d308 --- /dev/null +++ b/packages/generator/src/index.ts @@ -0,0 +1,17 @@ +import { generateDrawable } from "./core/drawable.js"; +import { generatePDF } from "./core/pdf.js"; +import { generatePNG } from "./core/png.js"; +import { generateReact } from "./core/react.js"; +import { generateSVG } from "./core/svg.js"; +import { generate, generator } from "./generator.js"; + +export { + generate, + generateDrawable, + generatePDF, + generatePNG, + generateReact, + generateSVG, +}; + +export default generator; diff --git a/packages/icona-generator/tsconfig.json b/packages/generator/tsconfig.json similarity index 100% rename from packages/icona-generator/tsconfig.json rename to packages/generator/tsconfig.json diff --git a/packages/icona-generator/src/index.ts b/packages/icona-generator/src/index.ts deleted file mode 100644 index 0e8b524..0000000 --- a/packages/icona-generator/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { generateDrawable } from "./core/drawable"; -import { generatePDF } from "./core/pdf"; -import { generatePNG } from "./core/png"; -import { generateReact } from "./core/react"; -import { generateSVG } from "./core/svg"; -import { generate, generator } from "./generator"; - -export { - generate, - generateDrawable, - generatePDF, - generatePNG, - generateReact, - generateSVG, -}; - -export default generator; diff --git a/packages/legacy/icona-cli/src/index.ts b/packages/legacy/icona-cli/src/index.ts deleted file mode 100644 index b3744e7..0000000 --- a/packages/legacy/icona-cli/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { generate } from "./core/generate"; - -export { generate }; diff --git a/packages/types/src/data.ts b/packages/types/src/data.ts new file mode 100644 index 0000000..aca33b1 --- /dev/null +++ b/packages/types/src/data.ts @@ -0,0 +1,13 @@ +type Base64 = string; + +export interface Style { + width: number; + height: number; +} + +export interface IconaIconData { + name: string; + style: Style; + svg: string; + png?: Base64; +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 8a18ad3..a8f7990 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,164 +1,2 @@ -import type { Config as SvgrConfig } from "@svgr/core"; -import type { SVGtoPDFOptions } from "svg-to-pdfkit"; -import type { Config as SvgoConfig } from "svgo"; - -type PDFKitConfig = PDFKit.PDFDocumentOptions & { - /** - * @readme - * If you use `info` option, pdf output will be different every time. - * So it occur git diff. So we use default info option. - * If user want change info option, they can change it. - * **But not recommend.** - * - * ```ts - * const defaultPdfkitConfigInfo = { - Author: "Icona", - Creator: "Icona", - Producer: "Icona", - Title: IconName, - Subject: IconName, - Keywords: IconName, - CreationDate: new Date(0), - ModDate: new Date(0), - }; - * ``` - */ - info?: PDFKit.PDFDocumentOptions["info"]; -}; - -type Base64 = string; -export type IconaIconData = { - name: string; - svg: string; - png?: Base64; -}; - -export interface SvgToPdfOptions extends SVGtoPDFOptions { - x?: number; - y?: number; -} -export interface GeneratePDFConfig { - /** - * generate drawable pdf files - * @default false - */ - active: boolean; - - /** - * pdf files path that will be generated - * @default pdf - */ - path?: string; - - /** - * PDFKit.PDFDocumentOptions - * @see https://pdfkit.org/docs/getting_started.html#document-structure - * - * @readme - * If you use `info` option, pdf output will be different every time. - * So it occur git diff. So we use default info option. - * - * If user want change info option, they can change it. - * But not recommend. - */ - pdfKitConfig?: PDFKitConfig; - - svgToPdfOptions?: SvgToPdfOptions; -} - -export interface GenerateReactConfig { - /** - * generate drawable react files - * @default false - */ - active: boolean; - - /** - * react component files path that will be generated - * @default react - */ - path?: string; - - /** - * Config (@svgr/core) - * @see https://react-svgr.com/docs/options/ - */ - svgrConfig?: SvgrConfig; -} - -export interface GenerateSVGConfig { - /** - * generate drawable svg files - * @default true - */ - active: boolean; - - /** - * svg files path that will be generated - * @default svg - */ - path?: string; - - /** - * Config (svgo) - * @see https://github.com/svg/svgo#configuration - */ - svgoConfig?: SvgoConfig; -} - -interface Svg2vectordrawableOptions { - floatPrecision?: number; // default 2 - strict?: boolean; // defaults to false - fillBlack?: boolean; // defaults to false - xmlTag?: boolean; // defaults to false - tint?: string; -} - -export interface GenerateDrawableConfig { - /** - * generate drawable xml files - * @default false - */ - active: boolean; - - /** - * xml files path that will be generated - * @default xml - */ - path?: string; - - /** - * Config (svg2vectordrawable) - * @see https://github.com/Ashung/svg2vectordrawable - */ - svg2vectordrawableConfig?: Svg2vectordrawableOptions; - - /** - * drawable default color is #FF212124 - * if you want to change default color, you can use this option - * @default #FF212124 - */ - defaultColor?: string; -} - -export interface GeneratePNGConfig { - /** - * generate drawable xml files - * @default false - */ - active: boolean; - - /** - * xml files path that will be generated - * @default xml - */ - path?: string; -} - -export interface IconaConfig { - svg: GenerateSVGConfig; - react: GenerateReactConfig; - pdf: GeneratePDFConfig; - drawable: GenerateDrawableConfig; - png: GeneratePNGConfig; -} +export * from "./data"; +export * from "./lib"; diff --git a/packages/types/src/lib.ts b/packages/types/src/lib.ts new file mode 100644 index 0000000..e41bac4 --- /dev/null +++ b/packages/types/src/lib.ts @@ -0,0 +1,157 @@ +import type { Config as SvgrConfig } from "@svgr/core"; +import type { SVGtoPDFOptions } from "svg-to-pdfkit"; +import type { Config as SvgoConfig } from "svgo"; + +type PDFKitConfig = PDFKit.PDFDocumentOptions & { + /** + * @readme + * If you use `info` option, pdf output will be different every time. + * So it occur git diff. So we use default info option. + * If user want change info option, they can change it. + * **But not recommend.** + * + * ```ts + * const defaultPdfkitConfigInfo = { + Author: "Icona", + Creator: "Icona", + Producer: "Icona", + Title: IconName, + Subject: IconName, + Keywords: IconName, + CreationDate: new Date(0), + ModDate: new Date(0), + }; + * ``` + */ + info?: PDFKit.PDFDocumentOptions["info"]; +}; + +export interface SvgToPdfOptions extends SVGtoPDFOptions { + x?: number; + y?: number; +} +export interface GeneratePDFConfig { + /** + * generate drawable pdf files + * @default false + */ + active: boolean; + + /** + * pdf files path that will be generated + * @default pdf + */ + path?: string; + + /** + * PDFKit.PDFDocumentOptions + * @see https://pdfkit.org/docs/getting_started.html#document-structure + * + * @readme + * If you use `info` option, pdf output will be different every time. + * So it occur git diff. So we use default info option. + * + * If user want change info option, they can change it. + * But not recommend. + */ + pdfKitConfig?: PDFKitConfig; + + svgToPdfOptions?: SvgToPdfOptions; +} + +export interface GenerateReactConfig { + /** + * generate drawable react files + * @default false + */ + active: boolean; + + /** + * react component files path that will be generated + * @default react + */ + path?: string; + + /** + * Config (@svgr/core) + * @see https://react-svgr.com/docs/options/ + */ + svgrConfig?: SvgrConfig; +} + +export interface GenerateSVGConfig { + /** + * generate drawable svg files + * @default true + */ + active: boolean; + + /** + * svg files path that will be generated + * @default svg + */ + path?: string; + + /** + * Config (svgo) + * @see https://github.com/svg/svgo#configuration + */ + svgoConfig?: SvgoConfig; +} + +interface Svg2vectordrawableOptions { + floatPrecision?: number; // default 2 + strict?: boolean; // defaults to false + fillBlack?: boolean; // defaults to false + xmlTag?: boolean; // defaults to false + tint?: string; +} + +export interface GenerateDrawableConfig { + /** + * generate drawable xml files + * @default false + */ + active: boolean; + + /** + * xml files path that will be generated + * @default xml + */ + path?: string; + + /** + * Config (svg2vectordrawable) + * @see https://github.com/Ashung/svg2vectordrawable + */ + svg2vectordrawableConfig?: Svg2vectordrawableOptions; + + /** + * drawable default color is #FF212124 + * if you want to change default color, you can use this option + * @default #FF212124 + */ + defaultColor?: string; +} + +export interface GeneratePNGConfig { + /** + * generate drawable xml files + * @default false + */ + active: boolean; + + /** + * xml files path that will be generated + * @default xml + */ + path?: string; +} + +export interface IconaConfig { + svg: GenerateSVGConfig; + react: GenerateReactConfig; + pdf: GeneratePDFConfig; + drawable: GenerateDrawableConfig; + png: GeneratePNGConfig; +} diff --git a/packages/icona-utils/.gitignore b/packages/utils/.gitignore similarity index 100% rename from packages/icona-utils/.gitignore rename to packages/utils/.gitignore diff --git a/packages/icona-utils/CHANGELOG.md b/packages/utils/CHANGELOG.md similarity index 100% rename from packages/icona-utils/CHANGELOG.md rename to packages/utils/CHANGELOG.md diff --git a/packages/icona-utils/README.md b/packages/utils/README.md similarity index 100% rename from packages/icona-utils/README.md rename to packages/utils/README.md diff --git a/packages/icona-utils/package.json b/packages/utils/package.json similarity index 100% rename from packages/icona-utils/package.json rename to packages/utils/package.json index 5aa0760..bf6a521 100644 --- a/packages/icona-utils/package.json +++ b/packages/utils/package.json @@ -25,10 +25,10 @@ "prepack": "yarn build" }, "dependencies": { + "@icona/types": "^0.0.13", "findup-sync": "^5.0.0" }, "devDependencies": { - "@icona/types": "^0.0.13", "@types/findup-sync": "^4.0.2", "@types/node": "^20.3.1", "nanobundle": "^1.6.0", diff --git a/packages/icona-utils/src/index.ts b/packages/utils/src/index.ts similarity index 100% rename from packages/icona-utils/src/index.ts rename to packages/utils/src/index.ts diff --git a/packages/icona-utils/tsconfig.json b/packages/utils/tsconfig.json similarity index 100% rename from packages/icona-utils/tsconfig.json rename to packages/utils/tsconfig.json diff --git a/yarn.lock b/yarn.lock index 23fb30d..b9ef46a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3646,9 +3646,9 @@ __metadata: languageName: unknown linkType: soft -"@icona/generator@workspace:packages/icona-generator": +"@icona/generator@workspace:packages/generator": version: 0.0.0-use.local - resolution: "@icona/generator@workspace:packages/icona-generator" + resolution: "@icona/generator@workspace:packages/generator" dependencies: "@icona/types": ^0.0.13 "@icona/utils": ^0.0.13 @@ -3703,9 +3703,9 @@ __metadata: languageName: unknown linkType: soft -"@icona/utils@^0.0.13, @icona/utils@workspace:packages/icona-utils": +"@icona/utils@^0.0.13, @icona/utils@workspace:packages/utils": version: 0.0.0-use.local - resolution: "@icona/utils@workspace:packages/icona-utils" + resolution: "@icona/utils@workspace:packages/utils" dependencies: "@icona/types": ^0.0.13 "@types/findup-sync": ^4.0.2