From f21bded30b794d73b4b9653888012b8da85cda89 Mon Sep 17 00:00:00 2001 From: Benjamin Dean Date: Thu, 19 Jul 2018 02:30:34 -0700 Subject: [PATCH] Resolving issue #39 and Issue #40 --- package-lock.json | 102 ++++++++++++++++++++++++ package.json | 1 + src/commands/add/prompts/add-element.js | 10 ++- src/icons/appIcon.png | Bin 0 -> 902 bytes src/icons/dashboardCardIcon.png | Bin 0 -> 700 bytes src/icons/elementIcon.png | Bin 0 -> 777 bytes src/models/manifest.js | 24 ++++-- 7 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 src/icons/appIcon.png create mode 100644 src/icons/dashboardCardIcon.png create mode 100644 src/icons/elementIcon.png diff --git a/package-lock.json b/package-lock.json index 4b7b91a..63daf95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -121,6 +121,11 @@ "universalify": "0.1.1" } }, + "fuzzy": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/fuzzy/-/fuzzy-0.1.3.tgz", + "integrity": "sha1-THbsL/CsGjap3M+aAN+GIweNTtg=" + }, "graceful-fs": { "version": "4.1.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", @@ -157,6 +162,90 @@ "through": "2.3.8" } }, + "inquirer-autocomplete-prompt": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/inquirer-autocomplete-prompt/-/inquirer-autocomplete-prompt-0.12.2.tgz", + "integrity": "sha512-XbgPlnFdAboyUYWIrOkV8vh426BVZWzvbIKRkNY/aCvKhoCSWOO6ZQagAEOGA5ff2iOboNEaT1Wa/cM9ekj8jw==", + "requires": { + "ansi-escapes": "3.0.0", + "chalk": "2.3.0", + "figures": "2.0.0", + "inquirer": "3.2.0", + "run-async": "2.3.0" + }, + "dependencies": { + "inquirer": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.2.0.tgz", + "integrity": "sha512-4CyUYMP7lOBkiUU1rR24WGrfRX6SucwbY2Mqb1PdApU24wnTIk4TsnkQwV72dDdIKZ2ycLP+fWCV+tA7wwgoew==", + "requires": { + "ansi-escapes": "2.0.0", + "chalk": "2.3.0", + "cli-cursor": "2.1.0", + "cli-width": "2.2.0", + "external-editor": "2.1.0", + "figures": "2.0.0", + "lodash": "4.17.4", + "mute-stream": "0.0.7", + "run-async": "2.3.0", + "rx-lite": "4.0.8", + "rx-lite-aggregates": "4.0.8", + "string-width": "2.1.1", + "strip-ansi": "4.0.0", + "through": "2.3.8" + }, + "dependencies": { + "ansi-escapes": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-2.0.0.tgz", + "integrity": "sha1-W65SvkJIeN2Xg+iRDj/Cki6DyBs=" + } + } + } + } + }, + "inquirer-fuzzy-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/inquirer-fuzzy-path/-/inquirer-fuzzy-path-1.0.0.tgz", + "integrity": "sha512-FhovxoYXj5NqNHHewfrfLy1ay7roY3DsHlZQ9NPEmk0YiFbKqwCR6CwjUxYzoOSgRwjspjAVOHZFlzvjHmXU1w==", + "requires": { + "ansi-styles": "3.2.1", + "fuzzy": "0.1.3", + "inquirer": "5.2.0", + "inquirer-autocomplete-prompt": "0.12.2", + "strip-ansi": "4.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "1.9.1" + } + }, + "inquirer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-5.2.0.tgz", + "integrity": "sha512-E9BmnJbAKLPGonz0HeWHtbKf+EeSP93paWO3ZYoUpq/aowXvYGjjCSuashhXPpzbArIjBbji39THkxTz9ZeEUQ==", + "requires": { + "ansi-escapes": "3.0.0", + "chalk": "2.3.0", + "cli-cursor": "2.1.0", + "cli-width": "2.2.0", + "external-editor": "2.1.0", + "figures": "2.0.0", + "lodash": "4.17.4", + "mute-stream": "0.0.7", + "run-async": "2.3.0", + "rxjs": "5.5.11", + "string-width": "2.1.1", + "strip-ansi": "4.0.0", + "through": "2.3.8" + } + } + } + }, "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", @@ -238,6 +327,14 @@ "rx-lite": "4.0.8" } }, + "rxjs": { + "version": "5.5.11", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.11.tgz", + "integrity": "sha512-3bjO7UwWfA2CV7lmwYMBzj4fQ6Cq+ftHc2MvUe+WMS7wcdJ1LosDWmdjPQanYp2dBRj572p7PeU81JUxHKOcBA==", + "requires": { + "symbol-observable": "1.0.1" + } + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -268,6 +365,11 @@ "has-flag": "2.0.0" } }, + "symbol-observable": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.1.tgz", + "integrity": "sha1-g0D8RwLDEi310iKI+IKD9RPT/dQ=" + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/package.json b/package.json index d7d0026..00db58c 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "commander": "^2.12.2", "fs-extra": "^5.0.0", "inquirer": "^4.0.1", + "inquirer-fuzzy-path": "^1.0.0", "jsonfile": "^4.0.0", "lodash": "^4.17.4" }, diff --git a/src/commands/add/prompts/add-element.js b/src/commands/add/prompts/add-element.js index 9b2aaba..1723fa0 100644 --- a/src/commands/add/prompts/add-element.js +++ b/src/commands/add/prompts/add-element.js @@ -1,4 +1,6 @@ -const { prompt } = require('inquirer'); +const inquirer = require('inquirer'); +inquirer.registerPrompt('fuzzypath', require('inquirer-fuzzy-path')); +//const { prompt } = require('inquirer'); const _ = require('lodash'); const writer = require('../../../utils/writer'); @@ -37,8 +39,10 @@ const questions = [ } }, { - type: 'input', + type: 'fuzzypath', name: 'icon_path', + default: 'icon.svg', + rootPath: '../', message: 'Enter a path to a local directory where the icon is stored', when: (answers) => answers.has_element_icon === 'Yes', validate: value => iconValidator(value) @@ -68,7 +72,7 @@ generateElementPath = (name) => { } module.exports = async (manifestModel) => { - let answers = await prompt(questions); + let answers = await inquirer.prompt(questions); let settings; if (answers.element_native_settings === 'Yes') { diff --git a/src/icons/appIcon.png b/src/icons/appIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..e56c89cef55706dcb02e155d66b1be072406f73b GIT binary patch literal 902 zcmV;119|+3P)IX)FXItWbZ0F*H6cLO_aSZ)4g%FRP)n(!_Vv1q~nUc1_rz#vTi)@ z=xutMEr9-{4=INg2f?xLRR~}>T*z-`0iX*X=Y&6D&e>c5w}L&_3IIb^?xs>ebpZX< z$`u8Pp;`cwY)M(?8k1MD|))MbK2y36*3Q zg^7{Pwn)n0^z0S;TC(y|bR^AcRklqyx)bP}Y+pLCawti-#cYc>C&{}eI*nMFy5;`rj()*0M4yRHLnfkrPGjiy)DVp2GHy>Pz+#TG+T5c>&)91CQMB~fS3U|a$xO4 zLjqup_T`4b)jojK*fenDs^~;m%jPJB-moZ`-`Sf1I0EXX53Kd|#qxg6jjqqz+#?_W zcwweJ6VaiON!ijHKo{EI5>wpM-N%L|WlOjBf&S@k3Owlf@>D84A6U-z<$aEH3t>cb zdF>}N?FSJZ8=0h%E)4WfcRBFh=MElp4B@*7U+4(ntbbj|kuEv#9@>|)eC?!{3*p)4 czLNmJ2f^u^M)I#J>;M1&07*qoM6N<$f>tM?IRF3v literal 0 HcmV?d00001 diff --git a/src/icons/dashboardCardIcon.png b/src/icons/dashboardCardIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..4f741bcbddcce3ec94ef1246a3174bb90b1f5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Od6B*ta^>SzI!$SL`DWEjB%vh*|Zsx-HM*)~ssfrB^pQ zi(9kWw7*%(;{%e<9(FaYTF;k|xY|}+>L%s}-M7fKZ4JO*L_CFNsKRWw00000NkvXX Hu0mjf=pblp literal 0 HcmV?d00001 diff --git a/src/models/manifest.js b/src/models/manifest.js index be6540a..1687a2f 100644 --- a/src/models/manifest.js +++ b/src/models/manifest.js @@ -2,6 +2,7 @@ const _ = require('lodash'); const fs = require('fs'); const fse = require('fs-extra'); const jsonfile = require('jsonfile'); +const path = require('path'); // CONSTANTS // TODO: Implement these later to prevent bugs @@ -91,16 +92,21 @@ module.exports = { }, async moveIcon(iconPath, directory) { - if (!String.isString(iconPath) || !iconPath.endsWith('.svg')) { - throw 'ERROR: Icon must be an SVG.'; - } + if(null === iconPath) { + iconPath = `${path.dirname(require.main.filename)}/src/icons/elementIcon.png`; + await fs.copyFileSync(iconPath, directory + '/icon.svg'); + } else { + if (!_.isString(iconPath) || !iconPath.endsWith('.svg')) { + throw 'ERROR: Icon must be an SVG.'; + } - let iconExists = await fs.existsSync(iconPath); - if (!iconExists) { - throw 'ERROR: Icon does not exist at the given path.'; - } + let iconExists = await fs.existsSync(iconPath); + if (!iconExists) { + throw 'ERROR: Icon does not exist at the given path.'; + } - await fs.copyFileSync(iconPath, directory + '/icon.svg'); + await fs.copyFileSync(iconPath, directory + '/icon.svg'); + } }, async addElement(values, iconPath) { if (!_.isArray(this.data.elements)) { @@ -110,6 +116,8 @@ module.exports = { await this.createElementDirectory(values.path); if (_.isString(iconPath)) { await this.moveIcon(iconPath, values.path); + } else { + await this.moveIcon(null, values.path); } this.data.elements.push(values);