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 0000000..e56c89c Binary files /dev/null and b/src/icons/appIcon.png differ diff --git a/src/icons/dashboardCardIcon.png b/src/icons/dashboardCardIcon.png new file mode 100644 index 0000000..4f741bc Binary files /dev/null and b/src/icons/dashboardCardIcon.png differ diff --git a/src/icons/elementIcon.png b/src/icons/elementIcon.png new file mode 100644 index 0000000..61403ac Binary files /dev/null and b/src/icons/elementIcon.png differ 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);