diff --git a/package-lock.json b/package-lock.json index cb8a037..1af1716 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,8 @@ "@nightwatch/setup-tools": "^3.3.1", "ansi-colors": "^4.1.3", "axios": "^0.27.2", + "didyoumean2": "^6.0.1", + "didyoumean3": "^1.2.5", "inquirer": "^8.2.4", "minimist": "^1.2.6" }, @@ -2926,6 +2928,25 @@ "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==", "dev": true }, + "node_modules/didyoumean2": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/didyoumean2/-/didyoumean2-6.0.1.tgz", + "integrity": "sha512-PSy0zQwMg5O+LjT5Mz7vnKC8I7DfWLPF6M7oepqW7WP5mn2CY3hz46xZOa1GJY+KVfyXhdmz6+tdgXwrHlZc5g==", + "hasInstallScript": true, + "dependencies": { + "@babel/runtime": "^7.19.0", + "fastest-levenshtein": "^1.0.12", + "lodash.deburr": "^4.1.0" + }, + "engines": { + "node": "^16.14.0 || >=18.12.0" + } + }, + "node_modules/didyoumean3": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/didyoumean3/-/didyoumean3-1.2.5.tgz", + "integrity": "sha512-ROol2k9IQ04NjrCiB98knunQ1cOmoXdYaGFjMfDIcXl9PuaxNVHxAZrG163aWkrRq5jIL+LatmqCgPasOvRwSQ==" + }, "node_modules/diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", @@ -3511,6 +3532,14 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "node_modules/fastest-levenshtein": { + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz", + "integrity": "sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg==", + "engines": { + "node": ">= 4.9.1" + } + }, "node_modules/fastq": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", @@ -5197,6 +5226,11 @@ "lodash._isiterateecall": "^3.0.0" } }, + "node_modules/lodash.deburr": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/lodash.deburr/-/lodash.deburr-4.1.0.tgz", + "integrity": "sha512-m/M1U1f3ddMCs6Hq2tAsYThTBDaAKFDX3dwDo97GEYzamXi9SqUpjWi/Rrj/gf3X2n8ktwgZrlP1z6E3v/IExQ==" + }, "node_modules/lodash.defaults": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", @@ -10412,6 +10446,21 @@ "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==", "dev": true }, + "didyoumean2": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/didyoumean2/-/didyoumean2-6.0.1.tgz", + "integrity": "sha512-PSy0zQwMg5O+LjT5Mz7vnKC8I7DfWLPF6M7oepqW7WP5mn2CY3hz46xZOa1GJY+KVfyXhdmz6+tdgXwrHlZc5g==", + "requires": { + "@babel/runtime": "^7.19.0", + "fastest-levenshtein": "^1.0.12", + "lodash.deburr": "^4.1.0" + } + }, + "didyoumean3": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/didyoumean3/-/didyoumean3-1.2.5.tgz", + "integrity": "sha512-ROol2k9IQ04NjrCiB98knunQ1cOmoXdYaGFjMfDIcXl9PuaxNVHxAZrG163aWkrRq5jIL+LatmqCgPasOvRwSQ==" + }, "diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", @@ -10856,6 +10905,11 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "fastest-levenshtein": { + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz", + "integrity": "sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg==" + }, "fastq": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", @@ -12144,6 +12198,11 @@ "lodash._isiterateecall": "^3.0.0" } }, + "lodash.deburr": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/lodash.deburr/-/lodash.deburr-4.1.0.tgz", + "integrity": "sha512-m/M1U1f3ddMCs6Hq2tAsYThTBDaAKFDX3dwDo97GEYzamXi9SqUpjWi/Rrj/gf3X2n8ktwgZrlP1z6E3v/IExQ==" + }, "lodash.defaults": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", diff --git a/package.json b/package.json index 3147ca5..b35e237 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@nightwatch/setup-tools": "^3.3.1", "ansi-colors": "^4.1.3", "axios": "^0.27.2", + "didyoumean2": "^6.0.1", "inquirer": "^8.2.4", "minimist": "^1.2.6" }, diff --git a/src/index.ts b/src/index.ts index 00b0806..7c2cb31 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import {NightwatchInitiator} from '@nightwatch/setup-tools'; import {NIGHTWATCH_TITLE, AVAILABLE_CONFIG_FLAGS} from './constants'; import Logger from './logger'; import minimist from 'minimist'; -import suggestSimilarOption from './utils/suggestSimilar'; +import DidYouMean from 'didyoumean2'; import {isNodeProject} from './utils'; import {CURRENT_VERSION} from './utils/version'; import axios, {AxiosResponse} from 'axios'; @@ -34,12 +34,12 @@ export const run = async () => { const wrongUserFlags = Object.keys(options).filter((word) => !AVAILABLE_CONFIG_FLAGS.includes(word)); if (wrongUserFlags.length > 0) { - const findAndSuggestSimilarOption = suggestSimilarOption(wrongUserFlags[0], AVAILABLE_CONFIG_FLAGS); - if (findAndSuggestSimilarOption !== '') { - Logger.error(`error: unknown option '${wrongUserFlags[0]}'${findAndSuggestSimilarOption}`); + const findAndSuggestSimilarOption = DidYouMean(wrongUserFlags[0], AVAILABLE_CONFIG_FLAGS); + const result = `Flag ${colors.red('--'+wrongUserFlags[0])} is not valid, did you mean ${colors.green('--'+findAndSuggestSimilarOption)}`; + Logger.error(result); - return; - } + // Exit Nightwatch setup process + process.exit(0); } let rootDir = path.resolve(process.cwd(), args[0] || '');