diff --git a/README.md b/README.md index fba362f..4fadb7a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cli.js b/cli.js index a134480..e08da0e 100755 --- a/cli.js +++ b/cli.js @@ -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() @@ -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]) @@ -296,7 +300,7 @@ function exportIcons () { function run () { updateGitIgnore() - if (process.argv[2] && process.argv[2] === '-c') { + if (argv.c) { deleteConfig() } getConfig().then(() => { diff --git a/package-lock.json b/package-lock.json index 78289d8..019f842 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "figma-export-icons", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -145,9 +145,9 @@ "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" }, "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "mkdirp": { "version": "0.5.1", @@ -155,6 +155,13 @@ "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + } } }, "ms": { diff --git a/package.json b/package.json index c6286c9..19ec446 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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"