From 341e61f7603d099fcd9e4ce32097470f5b113674 Mon Sep 17 00:00:00 2001 From: Mohacyr Rojas Date: Thu, 5 Oct 2023 12:42:42 +0100 Subject: [PATCH] feat: add basic cli functionality with inquirer --- package-lock.json | 367 ++++++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- src/index.js | 22 --- src/index.mjs | 36 +++++ 4 files changed, 395 insertions(+), 32 deletions(-) delete mode 100644 src/index.js create mode 100644 src/index.mjs diff --git a/package-lock.json b/package-lock.json index 9281221..8ee9fff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "license": "MPL-2.0", "dependencies": { - "commander": "^11.0.0", + "@inquirer/prompts": "^3.1.2", "open-api-mocker": "github:adantoscano/open-api-mocker" } }, @@ -121,11 +121,204 @@ "npm": ">=6.14.13" } }, + "node_modules/@inquirer/checkbox": { + "version": "1.3.12", + "resolved": "https://registry.npmjs.org/@inquirer/checkbox/-/checkbox-1.3.12.tgz", + "integrity": "sha512-Jz2XAwN6R9ONtb7+QqmUhKtVL7lumunHhUoNuOzBj2mP/pe/sNZzJQKGbwiePPyKot64vzDAJ4qiBES0ubpb+A==", + "dependencies": { + "@inquirer/core": "^5.0.1", + "@inquirer/type": "^1.1.5", + "ansi-escapes": "^4.3.2", + "chalk": "^4.1.2", + "figures": "^3.2.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/confirm": { + "version": "2.0.13", + "resolved": "https://registry.npmjs.org/@inquirer/confirm/-/confirm-2.0.13.tgz", + "integrity": "sha512-MoobMgUxq0UCEcNm8O2zegEoSbf9DdYQfmW2csTcpIbLfrv3LfPTWoFcgY50cS8CXpP2o/Dog2GH03jWxzNIzg==", + "dependencies": { + "@inquirer/core": "^5.0.1", + "@inquirer/type": "^1.1.5", + "chalk": "^4.1.2" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/core": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-5.0.1.tgz", + "integrity": "sha512-mRf9YFdrSa3+nHA8n/SUF/sDJcK6C5KlXS5xYwIB2NWfESYYBM2KTpubJPBR0sJxsrsZZC2WgfYl8TURPvMm8g==", + "dependencies": { + "@inquirer/type": "^1.1.5", + "@types/mute-stream": "^0.0.1", + "@types/node": "^20.6.5", + "@types/wrap-ansi": "^3.0.0", + "ansi-escapes": "^4.3.2", + "chalk": "^4.1.2", + "cli-spinners": "^2.9.1", + "cli-width": "^4.1.0", + "figures": "^3.2.0", + "mute-stream": "^1.0.0", + "run-async": "^3.0.0", + "signal-exit": "^4.1.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^6.2.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/core/node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@inquirer/editor": { + "version": "1.2.11", + "resolved": "https://registry.npmjs.org/@inquirer/editor/-/editor-1.2.11.tgz", + "integrity": "sha512-5WcjiTZsr8utlmfOFcHIC0o2Mdg3nXUf1ij5IZtgJTFd8QOy7N/sfsZHW0p1wY+YSbX6Sxd+YyUCJ2t6xQiyqA==", + "dependencies": { + "@inquirer/core": "^5.0.1", + "@inquirer/type": "^1.1.5", + "chalk": "^4.1.2", + "external-editor": "^3.1.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/expand": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@inquirer/expand/-/expand-1.1.12.tgz", + "integrity": "sha512-xNDrp5TO3xclcSqlWClskQd11OyGjnW2lek/4xeWQUrNKO1nN9VAzRAaEAkSpxF5FXG38M9oIBq6SMCYtBx/zw==", + "dependencies": { + "@inquirer/core": "^5.0.1", + "@inquirer/type": "^1.1.5", + "chalk": "^4.1.2", + "figures": "^3.2.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/input": { + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@inquirer/input/-/input-1.2.12.tgz", + "integrity": "sha512-ruckbVn/Jv+Pkqod7ACKNOtiKkW/DKSmWn11TUsJweuUbQQMWX5V/9nUvbX/4mJV9bFX817rnJhRru3MwjU8jA==", + "dependencies": { + "@inquirer/core": "^5.0.1", + "@inquirer/type": "^1.1.5", + "chalk": "^4.1.2" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/password": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@inquirer/password/-/password-1.1.12.tgz", + "integrity": "sha512-vVNxEVbe+XltKZlLBFvo4IcKwGyqmnc5cQkoEOTDYs0Jazrxct3x8bu89FpRhT/e93gm/TnWpqdI47+B7n/sWw==", + "dependencies": { + "@inquirer/input": "^1.2.12", + "@inquirer/type": "^1.1.5", + "ansi-escapes": "^4.3.2", + "chalk": "^4.1.2" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/prompts": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@inquirer/prompts/-/prompts-3.1.2.tgz", + "integrity": "sha512-bAN7sjKdaen/1iT5Cr0pZvOt/OuS3feO0cZ9PLYblSxZ2vKfU5HkYR3kK4TTIy3IXrxW16/XNFN59TsGWIhjDw==", + "dependencies": { + "@inquirer/checkbox": "^1.3.12", + "@inquirer/confirm": "^2.0.13", + "@inquirer/core": "^5.0.1", + "@inquirer/editor": "^1.2.11", + "@inquirer/expand": "^1.1.12", + "@inquirer/input": "^1.2.12", + "@inquirer/password": "^1.1.12", + "@inquirer/rawlist": "^1.2.12", + "@inquirer/select": "^1.2.12" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/rawlist": { + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@inquirer/rawlist/-/rawlist-1.2.12.tgz", + "integrity": "sha512-j5n4TpK4YP/Wt+hREjzDsqALulOocAEl1e4l8Mt2+2DQ66hWrfBTazkEaQJSeaTLRbm9153NjuObRD1+mQqg7g==", + "dependencies": { + "@inquirer/core": "^5.0.1", + "@inquirer/type": "^1.1.5", + "chalk": "^4.1.2" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/select": { + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@inquirer/select/-/select-1.2.12.tgz", + "integrity": "sha512-+KeKbxjJ/qa1yUxwaD38fhhi1nzL2qGigdT/E/GwXLtoWLJ8Rl8hCe37xRB2gP8yK3vhhv6ll8C4bgJtu2hIWA==", + "dependencies": { + "@inquirer/core": "^5.0.1", + "@inquirer/type": "^1.1.5", + "ansi-escapes": "^4.3.2", + "chalk": "^4.1.2", + "figures": "^3.2.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/@inquirer/type": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-1.1.5.tgz", + "integrity": "sha512-wmwHvHozpPo4IZkkNtbYenem/0wnfI6hvOcGKmPEa0DwuaH5XUQzFqy6OpEpjEegZMhYIk8HDYITI16BPLtrRA==", + "engines": { + "node": ">=14.18.0" + } + }, "node_modules/@jsdevtools/ono": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==" }, + "node_modules/@types/mute-stream": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.1.tgz", + "integrity": "sha512-0yQLzYhCqGz7CQPE3iDmYjhb7KMBFOP+tBkyw+/Y2YyDI5wpS7itXXxneN1zSsUwWx3Ji6YiVYrhAnpQGS/vkw==", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "20.8.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz", + "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==" + }, + "node_modules/@types/wrap-ansi": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz", + "integrity": "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==" + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -161,6 +354,20 @@ "decimal.js": "^10.2.0" } }, + "node_modules/ansi-escapes": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", + "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==", + "dependencies": { + "type-fest": "^0.21.3" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -272,6 +479,26 @@ "resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.2.tgz", "integrity": "sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==" }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chardet": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", + "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==" + }, "node_modules/chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", @@ -298,6 +525,25 @@ "fsevents": "~2.3.2" } }, + "node_modules/cli-spinners": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.1.tgz", + "integrity": "sha512-jHgecW0pxkonBJdrKsqxgRX9AcG+u/5k0Q7WPDfi8AogLAdwxEkyYYNWwZ5GvVFoFx2uiY1eNcSK00fh+1+FyQ==", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-width": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz", + "integrity": "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==", + "engines": { + "node": ">= 12" + } + }, "node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -349,14 +595,6 @@ "node": ">=0.1.90" } }, - "node_modules/commander": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz", - "integrity": "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==", - "engines": { - "node": ">=16" - } - }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -474,6 +712,14 @@ "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" }, + "node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -580,6 +826,19 @@ "node": ">= 0.8" } }, + "node_modules/external-editor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", + "integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==", + "dependencies": { + "chardet": "^0.7.0", + "iconv-lite": "^0.4.24", + "tmp": "^0.0.33" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -590,6 +849,20 @@ "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" }, + "node_modules/figures": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", + "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", + "dependencies": { + "escape-string-regexp": "^1.0.5" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -715,6 +988,14 @@ "node": ">= 0.4.0" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/has-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", @@ -964,6 +1245,14 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/mute-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-1.0.0.tgz", + "integrity": "sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==", + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -1039,6 +1328,14 @@ "integrity": "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==", "peer": true }, + "node_modules/os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/parse-prefer-header": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/parse-prefer-header/-/parse-prefer-header-1.0.0.tgz", @@ -1154,6 +1451,14 @@ "node": ">=0.10.0" } }, + "node_modules/run-async": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-3.0.0.tgz", + "integrity": "sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1259,6 +1564,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -1305,6 +1621,28 @@ "kind-of": "^6.0.1" } }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dependencies": { + "os-tmpdir": "~1.0.2" + }, + "engines": { + "node": ">=0.6.0" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -1324,6 +1662,17 @@ "node": ">=0.6" } }, + "node_modules/type-fest": { + "version": "0.21.3", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", + "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", diff --git a/package.json b/package.json index ec09e7b..6b6b0f0 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "author": "", "license": "MPL-2.0", "dependencies": { - "commander": "^11.0.0", + "@inquirer/prompts": "^3.1.2", "open-api-mocker": "github:adantoscano/open-api-mocker" } } diff --git a/src/index.js b/src/index.js deleted file mode 100644 index 6c58778..0000000 --- a/src/index.js +++ /dev/null @@ -1,22 +0,0 @@ -const { program } = require("commander"); - -program - .requiredOption("-r,--repository-url ", "The URL of the repo or path") - .option( - "-s,--schemas-directory ", - "Path/name of the schemas directory" - ) - .option("-p, --port [number]", "Port to run the server on", 3000) - .option( - "-d,--delete-repo-directory", - "Delete the repo directory after cloning" - ) - .option("-a, --add-gitignore", "Add schemas repository to .gitignore"); - -const main = () => { - program.parse(process.argv); - const options = program.opts(); - console.table(options); -}; - -main(); diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 0000000..7d5ac3e --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,36 @@ +import { input, confirm } from "@inquirer/prompts"; +import * as fs from "node:fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); + +const __dirname = path.dirname(__filename); + +const run = async () => { + const config = { + repoUrl: await input({ message: "Enter the repo url" }), + dirPath: await input({ message: "Enter the directory path" }), + addToGitIgnore: await confirm({ + message: "Do you want to add .api-mock-runner to .gitignore?", + }), + saveConfig: await confirm({ message: "Do you want to save the config?" }), + }; + + console.table(config); + + if (config.saveConfig) { + // Save config + // create an .apimockrc file on the root of the project + const filePath = `${__dirname}/.apimockrc`; + fs.writeFile(filePath, JSON.stringify(config), (err) => { + if (err) { + console.log(err); + } else { + console.log("Config saved"); + } + }); + } +}; + +run();