From 4c78ff94065ab25afb03df2194a3c95855f411ae Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Sun, 2 Feb 2020 14:50:48 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20apply=20requested=20cha?= =?UTF-8?q?nges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/cli.js | 6 +-- lib/parseArgs.js | 117 ++++++++++++++++++----------------------------- package.json | 6 +-- yarn.lock | 83 +-------------------------------- 4 files changed, 53 insertions(+), 159 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index cf3eb7cb..f2965a07 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -29,7 +29,7 @@ const main = async () => { try { const state = createState(); - const {cliAnswers, cliOptions, cliOtherParams} = parseArgs(); + const {cliAnswers, cliOptions, passThroughParams} = parseArgs(); if (cliOptions.dryRun) { // eslint-disable-next-line no-console @@ -59,8 +59,8 @@ const main = async () => { const appendedArgs = []; // eslint-disable-next-line guard-for-in - for (const key in cliOtherParams) { - const value = cliOtherParams[key]; + for (const key in passThroughParams) { + const value = passThroughParams[key]; if (key.length === 1) { appendedArgs.push('-' + key); diff --git a/lib/parseArgs.js b/lib/parseArgs.js index 38084fa3..258f9f25 100644 --- a/lib/parseArgs.js +++ b/lib/parseArgs.js @@ -1,80 +1,36 @@ -const meow = require('meow'); +/* eslint-disable no-process-exit */ +/* eslint-disable no-console */ +/* eslint-disable id-length */ +const minimist = require('minimist'); +const pkg = require('../package.json'); -const cliOptionFlags = { - dryRun: { - type: 'boolean' - }, - help: { - alias: 'h', - type: 'boolean' - }, - hook: { - type: 'boolean' - }, - nonInteractive: { - type: 'boolean' - }, - version: { - alias: 'v', - type: 'boolean' - } -}; +const helpScreen = ` + ${pkg.description} -const cliAnswerFlags = { - body: { - type: 'string' - }, - breaking: { - type: 'string' - }, - issues: { - type: 'string' - }, - lerna: { - type: 'string' - }, - scope: { - type: 'string' - }, - subject: { - type: 'string' - }, - type: { - type: 'string' - } -}; + Usage: git-cz [options] -const options = { - flags: { - ...cliOptionFlags, - ...cliAnswerFlags - }, - help: ` - Usage: git-cz [options] + options: + -h, --help show usage information + -v, --version print version info and exit + --non-interactive run git-cz in non-interactive mode - options: - -h, --help show usage information - -v, --version print version info and exit - --non-interactive run git-cz in non-interactive mode - - non-interactive mode options: - --type type of the commit, defaults to "chore" - --subject message of the commit, defaults to "automated commit" - --scope semantic commit scope - --body extended description of the commit - --breaking description of breaking changes, if any - --issues GitHub issues this commit closed, e.g "#123" - --lerna Lerna mono-repo packages this commit affects - ` -}; + non-interactive mode options: + --type type of the commit, defaults to "chore" + --subject message of the commit, defaults to "automated commit" + --scope semantic commit scope + --body extended description of the commit + --breaking description of breaking changes, if any + --issues GitHub issues this commit closed, e.g "#123" + --lerna Lerna mono-repo packages this commit affects +`; const parseArgs = () => { - const {flags} = meow(options); - const { - dryRun, + // eslint-disable-next-line no-unused-vars + _: inputs, + 'dry-run': dryRun, hook, - nonInteractive, + 'non-interactive': nonInteractive, body, breaking, issues, @@ -84,8 +40,25 @@ const parseArgs = () => { type, help, version, - ...cliOtherParams - } = flags; + ...passThroughParams + } = minimist(process.argv.slice(2), { + alias: { + h: 'help', + v: 'version' + }, + boolean: ['version', 'help', 'non-interactive', 'hook', 'dry-run'], + string: ['type', 'subject', 'scope', 'body', 'breaking', 'issues', 'learna'] + }); + + if (help) { + console.log(helpScreen); + process.exit(); + } + + if (version) { + console.log(pkg.version); + process.exit(); + } const cliOptions = { dryRun, @@ -108,7 +81,7 @@ const parseArgs = () => { return { cliAnswers, cliOptions, - cliOtherParams + passThroughParams }; }; diff --git a/package.json b/package.json index e665f828..d292abda 100644 --- a/package.json +++ b/package.json @@ -36,17 +36,17 @@ "eslint": "4.19.1", "eslint-config-mailonline": "9.0.0", "fuzzy": "0.1.3", + "global": "^4.3.2", "husky": "4.2.1", "inquirer": "6.5.2", "inquirer-list-search-prompt": "1.0.2", + "minimist": "^1.2.0", "mocha": "6.2.2", "pkg": "4.4.2", "rimraf": "3.0.1", "semantic-release": "16.0.4", "signale": "1.4.0", - "word-wrap": "1.2.3", - "global": "^4.3.2", - "meow": "^6.0.0" + "word-wrap": "1.2.3" }, "husky": { "hooks": { diff --git a/yarn.lock b/yarn.lock index ba05f0a5..9313ad14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -316,11 +316,6 @@ resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== -"@types/minimist@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6" - integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY= - "@types/node@*", "@types/node@>= 8": version "13.1.7" resolved "https://registry.yarnpkg.com/@types/node/-/node-13.1.7.tgz#db51d28b8dfacfe4fb2d0da88f5eb0a2eca00675" @@ -1135,21 +1130,12 @@ camelcase-keys@^4.0.0: map-obj "^2.0.0" quick-lru "^1.0.0" -camelcase-keys@^6.1.1: - version "6.1.2" - resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-6.1.2.tgz#531a289aeea93249b63ec1249db9265f305041f7" - integrity sha512-QfFrU0CIw2oltVvpndW32kuJ/9YOJwUnmWrjlXt1nnJZHCaS9i6bfOpg9R4Lw8aZjStkJWM+jc0cdXjWBgVJSw== - dependencies: - camelcase "^5.3.1" - map-obj "^4.0.0" - quick-lru "^4.0.1" - camelcase@^4.0.0, camelcase@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" integrity sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0= -camelcase@^5.0.0, camelcase@^5.3.1: +camelcase@^5.0.0: version "5.3.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== @@ -1811,7 +1797,7 @@ debuglog@^1.0.1: resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI= -decamelize-keys@^1.0.0, decamelize-keys@^1.1.0: +decamelize-keys@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.0.tgz#d171a87933252807eb3cb61dc1c1445d078df2d9" integrity sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk= @@ -3241,11 +3227,6 @@ har-validator@~5.1.0: ajv "^6.5.5" har-schema "^2.0.0" -hard-rejection@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/hard-rejection/-/hard-rejection-2.1.0.tgz#1c6eda5c1685c63942766d79bb40ae773cecd883" - integrity sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA== - has-ansi@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" @@ -4769,11 +4750,6 @@ map-obj@^2.0.0: resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-2.0.0.tgz#a65cd29087a92598b8791257a523e021222ac1f9" integrity sha1-plzSkIepJZi4eRJXpSPgISIqwfk= -map-obj@^4.0.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-4.1.0.tgz#b91221b542734b9f14256c0132c897c5d7256fd5" - integrity sha512-glc9y00wgtwcDmp7GaE/0b0OnxpNJsVf3ael/An6Fe2Q51LLwN1er6sdomLRzz5h0+yMpiYLhWYF5R7HeqVd4g== - map-visit@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f" @@ -4846,23 +4822,6 @@ meow@^5.0.0: trim-newlines "^2.0.0" yargs-parser "^10.0.0" -meow@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/meow/-/meow-6.0.0.tgz#949196fdf21d979379e3bdccb0411e60f8cffd93" - integrity sha512-x4rYsjigPBDAxY+BGuK83YLhUIqui5wYyZoqb6QJCUOs+0fiYq+i/NV4Jt8OgIfObZFxG9iTyvLDu4UTohGTFw== - dependencies: - "@types/minimist" "^1.2.0" - camelcase-keys "^6.1.1" - decamelize-keys "^1.1.0" - hard-rejection "^2.0.0" - minimist-options "^4.0.1" - normalize-package-data "^2.5.0" - read-pkg-up "^7.0.0" - redent "^3.0.0" - trim-newlines "^3.0.0" - type-fest "^0.8.1" - yargs-parser "^16.1.0" - merge-stream@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" @@ -4966,11 +4925,6 @@ min-document@^2.19.0: dependencies: dom-walk "^0.1.0" -min-indent@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.0.tgz#cfc45c37e9ec0d8f0a0ec3dd4ef7f7c3abe39256" - integrity sha1-z8RcN+nsDY8KDsPdTvf3w6vjklY= - minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" @@ -4996,14 +4950,6 @@ minimist-options@^3.0.1: arrify "^1.0.1" is-plain-obj "^1.1.0" -minimist-options@^4.0.1: - version "4.0.2" - resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.0.2.tgz#29c4021373ded40d546186725e57761e4b1984a7" - integrity sha512-seq4hpWkYSUh1y7NXxzucwAN9yVlBc3Upgdjz8vLCP97jG8kaOmzYrVH/m7tQ1NYD1wdtZbSLfdy4zFmRWuc/w== - dependencies: - arrify "^1.0.1" - is-plain-obj "^1.1.0" - minimist@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" @@ -6414,11 +6360,6 @@ quick-lru@^1.0.0: resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8" integrity sha1-Q2CxfGETatOAeDl/8RQW4Ybc+7g= -quick-lru@^4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f" - integrity sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g== - qw@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/qw/-/qw-1.0.1.tgz#efbfdc740f9ad054304426acb183412cc8b996d4" @@ -6634,14 +6575,6 @@ redent@^2.0.0: indent-string "^3.0.0" strip-indent "^2.0.0" -redent@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f" - integrity sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg== - dependencies: - indent-string "^4.0.0" - strip-indent "^3.0.0" - redeyed@~2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/redeyed/-/redeyed-2.1.1.tgz#8984b5815d99cb220469c99eeeffe38913e6cc0b" @@ -7555,13 +7488,6 @@ strip-indent@^2.0.0: resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-2.0.0.tgz#5ef8db295d01e6ed6cbf7aab96998d7822527b68" integrity sha1-XvjbKV0B5u1sv3qrlpmNeCJSe2g= -strip-indent@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-3.0.0.tgz#c32e1cee940b6b3432c771bc2c54bcce73cd3001" - integrity sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ== - dependencies: - min-indent "^1.0.0" - strip-json-comments@2.0.1, strip-json-comments@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" @@ -7799,11 +7725,6 @@ trim-newlines@^2.0.0: resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-2.0.0.tgz#b403d0b91be50c331dfc4b82eeceb22c3de16d20" integrity sha1-tAPQuRvlDDMd/EuC7s6yLD3hbSA= -trim-newlines@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.0.tgz#79726304a6a898aa8373427298d54c2ee8b1cb30" - integrity sha512-C4+gOpvmxaSMKuEf9Qc134F1ZuOHVXKRbtEflf4NTtuuJDEIJ9p5PXsalL8SkeRw+qit1Mo+yuvMPAKwWg/1hA== - trim-off-newlines@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3"