Skip to content
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

add figma.ts with bun #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

add figma.ts with bun #36

wants to merge 3 commits into from

Conversation

takanorip
Copy link
Contributor

@takanorip takanorip commented May 4, 2024

I have rewritten the script for downloading SVGs from Figma in TypeScript, and made it runnable on Bun.
https://bun.sh/

While Bun has some problems of making it difficult to check differences in the lock file, there are means provided to check differences on Git, and since this repository only contains small scripts, I consider it not to be a problem.
https://bun.sh/docs/install/lockfile

motivation

Although the values are obtained from Figma's API, I feel that maintainability is low because we have to read the documentation to find out what structure of data is returned from the API.
Figma has published typescript types for its REST API, which will allow API responses to be typed, making them easier to develop.
https://github.com/figma/rest-api-spec

The reasons for adopting Bun are the following 3 points:

  • TypeScript can run as is.
  • .env files can be used without any flags.
  • Environment variables and Node.js built-in modules can be used in the same way as in Node.js.

@takanorip takanorip requested review from jmblog, 8845musign and kodai3 May 4, 2024 18:39
@takanorip takanorip self-assigned this May 4, 2024
@jmblog
Copy link
Contributor

jmblog commented May 5, 2024

@takanorip Can you please share the motivations behind rewriting the script in TypeScript?

@takanorip
Copy link
Contributor Author

@jmblog
Sorry, I forgot to mention why I wanted to rewrite it in Typescript.
The main reason is that I wanted to type the API response, as I added in the description.

'X-FIGMA-TOKEN': TOKEN,
},
});
const { meta }: GetFileComponentsResponse = await response.json();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typed with @figma/rest-api-spec

'X-FIGMA-TOKEN': TOKEN,
},
});
const { images }: GetImagesResponse = await svgResponse.json();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typed with @figma/rest-api-spec

package.json Outdated
@@ -27,6 +27,7 @@
],
"scripts": {
"figma": "node ./scripts/figma.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the old one yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this is using it in GitHub Actions, but I noticed the file was deleted recently.
Since it seems unnecessary, I will remove it and add a section about Bun in the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done with fc2b434

@takanorip takanorip requested a review from jmblog May 7, 2024 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants