Skip to content

Commit

Permalink
Merge pull request #7 from LeonidasEsteban/master
Browse files Browse the repository at this point in the history
[feature] remove from name
  • Loading branch information
tsimenis authored Jun 14, 2021
2 parents eec8b6f + 7b8ec9b commit e99e368
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,74 @@
<a href="https://www.npmjs.com/package/figma-export-icons"><img src="https://badgen.net/npm/dm/figma-export-icons" alt="Downloads"></a>

> Command line script to export and download icons from a Figma file using the Figma REST api.
## Description
Running the script will bring up a wizard to fill in the config for fetching the assets. You can also provide the icons-config.json yourself, then the wizard is skipped.

Running the script will bring up a wizard to fill in the config for fetching the assets. You can also provide the icons-config.json yourself, then the wizard is skipped.
After the config is provided, the figma file is fetched and parsed to find the icons frame, the files are downloaded and put locally in the directory provided in the config.

example config file:

```json
{
"figmaPersonalToken": "YOUR_PERSONAL_TOKEN",
"fileId": "FILE_ID",
"page": "Identity",
"frame": "Icons",
"iconsPath": "assets/svg/icons"
"iconsPath": "assets/svg/icons",
"removeFromName": "Icon="
}
```
Update: from > v1.3.0 you can set the frame to -1 and it will fetch the icons from the whole page.


## Features

- Wizard to generate config, you will be prompted for any missing key
- icons-config.json is automatically added to .gitignore if it exists
- Directory to save the icons is created if it doesn't exist
- Icons are deleted from local directory when fetching new
- Icons are deleted from local directory when fetching new
- 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`

## Installation

Install the cli globally so you can use it on any directory

```sh
npm install -g figma-export-icons
```

Or if you prefer install it in your project

```sh
npm install figma-export-icons --save
```

## Usage

If you have installed the module globally:
```sh
$ export-icons
```

If you have installed it locally:

Create a script in your package.json
```js
scripts: {
'export-icons': 'export-icons'
}
```
and run
and run
```sh
npm run export-icons
```

OR

run it directly with:
run it directly with:
```sh
npx export-icons
```
Expand Down
6 changes: 4 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ function makeResultsTable (results) {
)
return ui.toString()
}

function removeFromName(name) {
return name.replace(config.removeFromName, '')
}
function exportIcons () {
getFigmaFile()
.then((res) => {
Expand All @@ -288,7 +290,7 @@ function exportIcons () {
.then(() => {
deleteIcons().then(() => {
spinner.start('Downloading')
const AllIcons = icons.map(icon => downloadImage(icon.image, icon.name))
const AllIcons = icons.map(icon => downloadImage(icon.image, removeFromName(icon.name)))
// const AllIcons = []
Promise.all(AllIcons).then((res) => {
spinner.succeed(chalk.cyan.bold('Download Finished!\n'))
Expand Down
3 changes: 2 additions & 1 deletion src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const defaults = {
configFileName: 'icons-config.json',
page: 'Identity',
frame: 'Icons',
iconsPath: 'assets/svg/icons'
iconsPath: 'assets/svg/icons',
removeFromName: 'Icon='
}

module.exports = defaults

0 comments on commit e99e368

Please sign in to comment.