Skip to content

Commit

Permalink
Merge pull request #8 from pbilyk/pass-path-to-frame
Browse files Browse the repository at this point in the history
add ability to pass the path to frame if it is nested within groups
  • Loading branch information
tsimenis authored Jul 24, 2021
2 parents 684b87a + 9a4e3e1 commit 7cf6139
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 322 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Update: from > v1.3.0 you can set the frame to -1 and it will fetch the icons fr
- Icons with the same name are marked with `${iconName}-duplicate-name.svg` so you can easily spot them and fix figma file
- Running the script with `-c` will clear the config and run the wizard again
- You can use a custom path to your configuration file with `--config=path/to/config.json`
- `frame` can be a path if your icons are nested, e.g. `frame="Atoms/icons"`

## Installation

Expand Down
18 changes: 15 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ function findDuplicates (propertyName, arr) {
}, [])
}

function getPathToFrame(root, current) {
if(!current.length) return root
const path = [...current]
const name = path.shift()
const foundChild = root.children.find(c => c.name === name)
if (!foundChild) return root;
return getPathToFrame(foundChild, path)
}

function getFigmaFile () {
return new Promise((resolve) => {
spinner.start('Fetching Figma file (this might take a while depending on the figma file size)')
Expand All @@ -160,11 +169,14 @@ function getFigmaFile () {
const shouldGetFrame = isNaN(config.frame) && parseInt(config.frame) !== -1
let iconsArray = page.children
if (shouldGetFrame) {
if (!page.children.find(c => c.name === config.frame)) {
console.log(chalk.red.bold('Cannot find Icons Frame in this Page, check your settings'))
const frameNameArr = config.frame.split('/').filter(Boolean)
const frameName = frameNameArr.pop()
const frameRoot = getPathToFrame(page, frameNameArr)
if (!frameRoot.children.find(c => c.name === frameName)) {
console.log(chalk.red.bold('Cannot find', chalk.white.bgRed(frameName), 'Frame in this Page, check your settings'))
return
}
iconsArray = iconsArray.find(c => c.name === config.frame).children
iconsArray = frameRoot.children.find(c => c.name === frameName).children
}
let icons = iconsArray.map((icon) => {
return { id: icon.id, name: icon.name }
Expand Down
320 changes: 1 addition & 319 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cf6139

Please sign in to comment.