Skip to content

Commit

Permalink
feat: preview 아이콘을 통해서 deploy & icons.json 파일 prettier해서 보내기
Browse files Browse the repository at this point in the history
  • Loading branch information
junghyeonsu committed Dec 4, 2023
1 parent 1256251 commit 9983622
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
2 changes: 2 additions & 0 deletions figma-plugin/common/fromUi.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +9,7 @@ interface GithubData {

interface IconaMetaData {
githubData: GithubData;
icons: Record<string, IconaIconData>;
options?: {
withPng?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion figma-plugin/plugin-src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
14 changes: 8 additions & 6 deletions figma-plugin/plugin-src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
17 changes: 3 additions & 14 deletions figma-plugin/plugin-src/listeners.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions figma-plugin/plugin-src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, IconaIconData>);
Expand Down
1 change: 1 addition & 0 deletions figma-plugin/ui-src/pages/Deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Deploy = () => {
dispatch({
name: "DEPLOY_ICON",
payload: {
icons: iconPreview,
githubData,
},
});
Expand Down

0 comments on commit 9983622

Please sign in to comment.