Skip to content

Commit

Permalink
Merge pull request #3 from rdimascio/master
Browse files Browse the repository at this point in the history
handle custom config file paths
  • Loading branch information
tsimenis authored Jul 12, 2020
2 parents b9a54ce + aaee46f commit 478e4f2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
## Features

- Wizard to generate config, you will be prompted for any missing key
- icons-config.json is automatically added to .gitignore
- 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 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

Expand Down
22 changes: 13 additions & 9 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const axios = require('axios')
const prompts = require('prompts')
const promptsList = require('./src/prompts')
const mkdirp = require('mkdirp')
const argv = require('minimist')(process.argv.slice(2))
let config = {}
let figmaClient
const spinner = ora()
Expand All @@ -25,20 +26,23 @@ function deleteConfig () {

function updateGitIgnore () {
const ignorePath = '.gitignore'
const configPath = argv.config || defaults.configFileName
const ignoreCompletePath = path.resolve(ignorePath)
const ignoreContent = '\n#figma-export-icons\nicons-config.json'
const ignore = fs.existsSync(ignoreCompletePath)
? fs.readFileSync(ignoreCompletePath, 'utf-8')
: ''
if(!ignore.includes(ignoreContent)) {
fs.writeFileSync(ignoreCompletePath, ignore + ignoreContent)
console.log(`Updated ${ignorePath} : ${ignoreContent}`)
if (fs.existsSync(configPath)) {
const ignoreContent = `\n#figma-export-icons\n${configPath}`
const ignore = fs.existsSync(ignoreCompletePath)
? fs.readFileSync(ignoreCompletePath, 'utf-8')
: ''
if(!ignore.includes(ignoreContent)) {
fs.writeFileSync(ignoreCompletePath, ignore + ignoreContent)
console.log(`Updated ${ignorePath} : ${ignoreContent}`)
}
}
}

function getConfig () {
return new Promise((resolve) => {
const configFile = path.resolve(defaults.configFileName)
const configFile = path.resolve(argv.config || defaults.configFileName)
if (fs.existsSync(configFile)) {
config = JSON.parse(fs.readFileSync(configFile, 'utf-8'))
const missingConfig = promptsList.filter((q) => !config[q.name])
Expand Down Expand Up @@ -296,7 +300,7 @@ function exportIcons () {

function run () {
updateGitIgnore()
if (process.argv[2] && process.argv[2] === '-c') {
if (argv.c) {
deleteConfig()
}
getConfig().then(() => {
Expand Down
15 changes: 11 additions & 4 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "figma-export-icons",
"version": "1.1.0",
"version": "1.2.0",
"description": "Script to generate and download icons from a figma file",
"bin": {
"export-icons": "cli.js"
Expand All @@ -27,6 +27,7 @@
"axios": "^0.19.0",
"chalk": "^2.4.2",
"cliui": "^5.0.0",
"minimist": "^1.2.5",
"mkdirp": "^0.5.1",
"ora": "^3.4.0",
"prompts": "^2.1.0"
Expand Down

0 comments on commit 478e4f2

Please sign in to comment.