From 998362217d25711a43509be60d9d1a70b6c4a909 Mon Sep 17 00:00:00 2001 From: junghyeonsu Date: Mon, 4 Dec 2023 12:54:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20preview=20=EC=95=84=EC=9D=B4=EC=BD=98?= =?UTF-8?q?=EC=9D=84=20=ED=86=B5=ED=95=B4=EC=84=9C=20deploy=20&=20icons.js?= =?UTF-8?q?on=20=ED=8C=8C=EC=9D=BC=20prettier=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- figma-plugin/common/fromUi.ts | 2 ++ figma-plugin/plugin-src/code.ts | 2 +- figma-plugin/plugin-src/github.ts | 14 ++++++++------ figma-plugin/plugin-src/listeners.ts | 17 +++-------------- figma-plugin/plugin-src/service.ts | 14 ++++++++++++-- figma-plugin/ui-src/pages/Deploy.tsx | 1 + 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/figma-plugin/common/fromUi.ts b/figma-plugin/common/fromUi.ts index 321490b..80d18d4 100644 --- a/figma-plugin/common/fromUi.ts +++ b/figma-plugin/common/fromUi.ts @@ -1,4 +1,5 @@ import { emit as e, on as o } from "@create-figma-plugin/utilities"; +import type { IconaIconData } from "@icona/types"; interface GithubData { owner: string; @@ -8,6 +9,7 @@ interface GithubData { interface IconaMetaData { githubData: GithubData; + icons: Record; options?: { withPng?: boolean; }; diff --git a/figma-plugin/plugin-src/code.ts b/figma-plugin/plugin-src/code.ts index 34d7878..5f40dd9 100644 --- a/figma-plugin/plugin-src/code.ts +++ b/figma-plugin/plugin-src/code.ts @@ -38,7 +38,7 @@ async function setPreviewIcons() { return; } else { const svgDatas = await getAssetInIconFrame(iconaFrame.id, { - withPng: false, + withPng: await getLocalData(KEY.DEPLOY_WITH_PNG), }); emit("GET_ICON_PREVIEW", { diff --git a/figma-plugin/plugin-src/github.ts b/figma-plugin/plugin-src/github.ts index d5aa7de..a2267df 100644 --- a/figma-plugin/plugin-src/github.ts +++ b/figma-plugin/plugin-src/github.ts @@ -217,12 +217,14 @@ export function createGithubClient( const head = await getHead(baseBranch); - const treeBody = await uploadBlob(JSON.stringify(svgs)).then((blob) => ({ - path: `.icona/icons.json`, - mode: "100644", - type: "blob", - sha: blob.sha, - })); + const treeBody = await uploadBlob(JSON.stringify(svgs, null, 2)).then( + (blob) => ({ + path: `.icona/icons.json`, + mode: "100644", + type: "blob", + sha: blob.sha, + }), + ); const tree = await createTree([treeBody], head.object.sha); const commit = await createCommit(tree.sha, commitTitle, [head.object.sha]); diff --git a/figma-plugin/plugin-src/listeners.ts b/figma-plugin/plugin-src/listeners.ts index a1890fb..a6c6c71 100644 --- a/figma-plugin/plugin-src/listeners.ts +++ b/figma-plugin/plugin-src/listeners.ts @@ -1,28 +1,17 @@ -import { FRAME_NAME, KEY } from "../common/constants.js"; +import { KEY } from "../common/constants.js"; import { emit } from "../common/fromPlugin.js"; import { on } from "../common/fromUi.js"; import { createGithubClient } from "./github.js"; -import { getAssetInIconFrame } from "./service.js"; import { setLocalData } from "./utils.js"; export function listenDeployIcon() { - on("DEPLOY_ICON", async ({ githubData, options }) => { - const { withPng } = options ?? { withPng: true }; - + on("DEPLOY_ICON", async ({ githubData, icons }) => { try { const { owner, name, apiKey } = githubData; const { createDeployPR } = createGithubClient(owner, name, apiKey); - const iconaFrame = figma.currentPage.findOne((node) => { - return node.name === FRAME_NAME; - }); - - if (!iconaFrame) throw new Error("Icona frame not found"); - const svgs = await getAssetInIconFrame(iconaFrame.id, { - withPng, - }); - await createDeployPR(svgs); + await createDeployPR(icons); emit("DEPLOY_DONE", null); figma.notify("Icons deployed", { timeout: 5000 }); } catch (error) { diff --git a/figma-plugin/plugin-src/service.ts b/figma-plugin/plugin-src/service.ts index fa40db4..2d1cbf6 100644 --- a/figma-plugin/plugin-src/service.ts +++ b/figma-plugin/plugin-src/service.ts @@ -96,7 +96,7 @@ export async function getAssetInIconFrame( const targetComponents = targetNodes.filter((component) => component); - const datas = await Promise.all( + const datas = await Promise.allSettled( targetComponents.map(async (component) => { const data = {} as IconaIconData; const node = figma.getNodeById(component.id) as ComponentNode; @@ -127,7 +127,17 @@ export async function getAssetInIconFrame( ); const dataMap = datas.reduce((acc, cur) => { - acc[cur.name] = cur; + if (cur.status === "rejected") { + console.error(cur.reason); + } + + if (cur.status === "fulfilled") { + const { name, ...rest } = cur.value as IconaIconData; + acc[name] = { + ...rest, + name, + }; + } return acc; }, {} as Record); diff --git a/figma-plugin/ui-src/pages/Deploy.tsx b/figma-plugin/ui-src/pages/Deploy.tsx index 63c31ea..779e0eb 100644 --- a/figma-plugin/ui-src/pages/Deploy.tsx +++ b/figma-plugin/ui-src/pages/Deploy.tsx @@ -30,6 +30,7 @@ const Deploy = () => { dispatch({ name: "DEPLOY_ICON", payload: { + icons: iconPreview, githubData, }, });