Skip to content

Commit

Permalink
feat(scripts): allow import script to pull using Figma API
Browse files Browse the repository at this point in the history
- handle both downloaded file version and API version
- handle input and edge cases (e.g., missing config)
- separate and handle parsing of token contents into theme file
- guard against committing local edsrc config
  • Loading branch information
booc0mtaco committed Feb 15, 2025
1 parent 8a312e8 commit 4b573e5
Show file tree
Hide file tree
Showing 6 changed files with 18,647 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ storybook-components
.env.production.local
.cache
.idea
.edsrc.json

npm-debug.log*
yarn-debug.log*
Expand Down
11 changes: 11 additions & 0 deletions bin/_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ module.exports = {
* the existing local theme. If there's a path in the local theme file, we can write there (using lodash/set
* or similar).
*
* TODO(next-major): remove this function
*
* @param {object} localTheme JSON file loaded, representing the data for the local theme
* @param {string} collectionName Name of the exported collection
* @param {string} variableName current variable name from figma (e.g., color/text/neutral/default)
Expand All @@ -160,6 +162,8 @@ module.exports = {
module.exports.getTokenPrefix(collectionName) +
module.exports.tokenNameToPath(variableName);

console.log(workingPath);

const found = at(localTheme, workingPath).filter(
(entries) => typeof entries !== 'undefined',
);
Expand Down Expand Up @@ -197,6 +201,8 @@ module.exports = {
* Data Types:
* - Type COLOR: https://www.figma.com/plugin-docs/api/RGB/
*
* TODO(next-major): remove this function
*
* @param {string} type Figma type for the token value (Set:)
* @param {object} figmaResolvedValue
* @returns {string} value using the type
Expand Down Expand Up @@ -232,6 +238,8 @@ module.exports = {
* a prefix to the token name that corresponds to the prefix used for those
* tokens.
*
* TODO(next-major): remove this function
*
* @param {string} collectionName The key to write to
* @returns {string|null} a text prefix for where to write the token value or null when no prefix is found
*/
Expand All @@ -247,6 +255,9 @@ module.exports = {
},
/**
* Conversion of the figma token name (e.g., some/path/to/token) to the equivalent path in a JSON object
*
* TODO(next-major): remove this function
*
* @param {string} figmaTokenName The name from the figma variables panel (slash separated)
* @returns {string} a lodash-compatible string representing the path to the token value in JSON
*/
Expand Down
Loading

0 comments on commit 4b573e5

Please sign in to comment.