From f6685729aea21d0e3382b47f11f88b89024279f7 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Fri, 1 Sep 2017 21:40:40 +0200 Subject: [PATCH] Perfected code structure for .sh --- src/providers/sh/commands/alias.js | 8 +- src/providers/sh/commands/billing.js | 10 +- src/providers/sh/commands/billing/add.js | 16 +- src/providers/sh/commands/certs.js | 4 +- src/providers/sh/commands/dns.js | 4 +- src/providers/sh/commands/domains.js | 6 +- src/providers/sh/commands/domains/buy.js | 20 +- src/providers/sh/commands/list.js | 2 +- src/providers/sh/commands/logout.js | 2 +- src/providers/sh/commands/logs.js | 4 +- src/providers/sh/commands/remove.js | 4 +- src/providers/sh/commands/scale.js | 6 +- src/providers/sh/commands/secrets.js | 4 +- src/providers/sh/commands/teams.js | 6 +- src/providers/sh/commands/teams/add.js | 26 +- src/providers/sh/commands/teams/invite.js | 26 +- src/providers/sh/commands/teams/list.js | 10 +- src/providers/sh/commands/teams/switch.js | 14 +- src/providers/sh/commands/upgrade.js | 12 +- src/providers/sh/commands/whoami.js | 2 +- src/providers/sh/util/alias.js | 22 +- .../util/{etc => }/billing/card-brands.json | 0 .../util/{etc => }/billing/country-list.json | 0 .../sh/util/{etc => }/billing/geocode.js | 0 src/providers/sh/util/domains.js | 2 +- .../util/{etc => }/domains/treat-buy-error.js | 2 +- src/providers/sh/util/etc/input/list.js | 79 ------ .../sh/util/etc/input/patch-inquirer.js | 20 -- .../sh/util/etc/input/prompt-bool.js | 58 ---- src/providers/sh/util/etc/input/text.js | 262 ------------------ src/providers/sh/util/etc/output/chars.js | 3 - src/providers/sh/util/etc/output/cmd.js | 6 - .../sh/util/etc/output/erase-lines.js | 3 - src/providers/sh/util/etc/output/error.js | 9 - src/providers/sh/util/etc/output/info.js | 6 - src/providers/sh/util/etc/output/logo.js | 1 - src/providers/sh/util/etc/output/note.js | 6 - src/providers/sh/util/etc/output/param.js | 7 - src/providers/sh/util/etc/output/success.js | 6 - src/providers/sh/util/etc/output/wait.js | 15 - .../sh/util/etc => util}/check-path.js | 0 src/{providers/sh/util/etc => util}/exit.js | 0 .../sh/util/etc => util}/fatal-error.js | 0 .../util/etc => util}/input/prompt-options.js | 0 .../sh/util/etc => util}/input/regexes.js | 0 .../sh/util/etc => util}/output/code.js | 1 + .../sh/util/etc => util}/output/right-pad.js | 0 .../sh/util/etc => util}/output/stamp.js | 0 .../sh/util/etc => util}/output/table.js | 0 .../sh/util/etc => util}/output/uid.js | 0 .../sh/util/etc => util}/to-human-path.js | 0 src/{providers/sh/util/etc => util}/url.js | 0 52 files changed, 107 insertions(+), 587 deletions(-) rename src/providers/sh/util/{etc => }/billing/card-brands.json (100%) rename src/providers/sh/util/{etc => }/billing/country-list.json (100%) rename src/providers/sh/util/{etc => }/billing/geocode.js (100%) rename src/providers/sh/util/{etc => }/domains/treat-buy-error.js (91%) delete mode 100755 src/providers/sh/util/etc/input/list.js delete mode 100755 src/providers/sh/util/etc/input/patch-inquirer.js delete mode 100755 src/providers/sh/util/etc/input/prompt-bool.js delete mode 100755 src/providers/sh/util/etc/input/text.js delete mode 100755 src/providers/sh/util/etc/output/chars.js delete mode 100755 src/providers/sh/util/etc/output/cmd.js delete mode 100755 src/providers/sh/util/etc/output/erase-lines.js delete mode 100755 src/providers/sh/util/etc/output/error.js delete mode 100755 src/providers/sh/util/etc/output/info.js delete mode 100755 src/providers/sh/util/etc/output/logo.js delete mode 100755 src/providers/sh/util/etc/output/note.js delete mode 100755 src/providers/sh/util/etc/output/param.js delete mode 100755 src/providers/sh/util/etc/output/success.js delete mode 100755 src/providers/sh/util/etc/output/wait.js rename src/{providers/sh/util/etc => util}/check-path.js (100%) rename src/{providers/sh/util/etc => util}/exit.js (100%) rename src/{providers/sh/util/etc => util}/fatal-error.js (100%) rename src/{providers/sh/util/etc => util}/input/prompt-options.js (100%) rename src/{providers/sh/util/etc => util}/input/regexes.js (100%) rename src/{providers/sh/util/etc => util}/output/code.js (94%) mode change 100755 => 100644 rename src/{providers/sh/util/etc => util}/output/right-pad.js (100%) rename src/{providers/sh/util/etc => util}/output/stamp.js (100%) rename src/{providers/sh/util/etc => util}/output/table.js (100%) rename src/{providers/sh/util/etc => util}/output/uid.js (100%) rename src/{providers/sh/util/etc => util}/to-human-path.js (100%) rename src/{providers/sh/util/etc => util}/url.js (100%) diff --git a/src/providers/sh/commands/alias.js b/src/providers/sh/commands/alias.js index 42771ba..19ea043 100644 --- a/src/providers/sh/commands/alias.js +++ b/src/providers/sh/commands/alias.js @@ -16,10 +16,10 @@ const NowDomains = require('../util/domains') const { handleError, error } = require('../util/error') const toHost = require('../util/to-host') const { reAlias } = require('../util/re-alias') -const exit = require('../util/etc/exit') -const info = require('../util/etc/output/info') -const logo = require('../util/etc/output/logo') -const promptBool = require('../util/etc/input/prompt-bool') +const exit = require('../../../util/exit') +const info = require('../../../util/output/info') +const logo = require('../../../util/output/logo') +const promptBool = require('../../../util/input/prompt-bool') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/billing.js b/src/providers/sh/commands/billing.js index c422c9e..665d757 100644 --- a/src/providers/sh/commands/billing.js +++ b/src/providers/sh/commands/billing.js @@ -9,11 +9,11 @@ const ms = require('ms') const { handleError, error } = require('../util/error') const NowCreditCards = require('../util/credit-cards') const indent = require('../util/indent') -const listInput = require('../util/etc/input/list') -const success = require('../util/etc/output/success') -const promptBool = require('../util/etc/input/prompt-bool') -const info = require('../util/etc/output/info') -const logo = require('../util/etc/output/logo') +const listInput = require('../../../util/input/list') +const success = require('../../../util/output/success') +const promptBool = require('../../../util/input/prompt-bool') +const info = require('../../../util/output/info') +const logo = require('../../../util/output/logo') const addBilling = require('./billing/add') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/billing/add.js b/src/providers/sh/commands/billing/add.js index e5b0f0c..4965e77 100644 --- a/src/providers/sh/commands/billing/add.js +++ b/src/providers/sh/commands/billing/add.js @@ -6,14 +6,14 @@ const chalk = require('chalk') const ccValidator = require('credit-card') // Utilities -const textInput = require('../../util/etc/input/text') -const countries = require('../../util/etc/billing/country-list') -const cardBrands = require('../../util/etc/billing/card-brands') -const geocode = require('../../util/etc/billing/geocode') -const success = require('../../util/etc/output/success') -const wait = require('../../util/etc/output/wait') -const { tick } = require('../../util/etc/output/chars') -const rightPad = require('../../util/etc/output/right-pad') +const textInput = require('../../../../util/input/text') +const countries = require('../../util/billing/country-list') +const cardBrands = require('../../util/billing/card-brands') +const geocode = require('../../util/billing/geocode') +const success = require('../../../../util/output/success') +const wait = require('../../../../util/output/wait') +const { tick } = require('../../../../util/output/chars') +const rightPad = require('../../../../util/output/right-pad') function expDateMiddleware(data) { return data diff --git a/src/providers/sh/commands/certs.js b/src/providers/sh/commands/certs.js index f0fb938..f863160 100644 --- a/src/providers/sh/commands/certs.js +++ b/src/providers/sh/commands/certs.js @@ -16,8 +16,8 @@ const supportsColor = require('supports-color') // Utilities const { handleError, error } = require('../util/error') const NowCerts = require('../util/certs') -const exit = require('../util/etc/exit') -const logo = require('../util/etc/output/logo') +const exit = require('../../../util/exit') +const logo = require('../../../util/output/logo') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/dns.js b/src/providers/sh/commands/dns.js index 1d27a60..929e3ec 100644 --- a/src/providers/sh/commands/dns.js +++ b/src/providers/sh/commands/dns.js @@ -11,8 +11,8 @@ const DomainRecords = require('../util/domain-records') const indent = require('../util/indent') const strlen = require('../util/strlen') const { handleError, error } = require('../util/error') -const exit = require('../util/etc/exit') -const logo = require('../util/etc/output/logo') +const exit = require('../../../util/exit') +const logo = require('../../../util/output/logo') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/domains.js b/src/providers/sh/commands/domains.js index b6edbeb..e66fa17 100644 --- a/src/providers/sh/commands/domains.js +++ b/src/providers/sh/commands/domains.js @@ -9,9 +9,9 @@ const table = require('text-table') // Utilities const NowDomains = require('../util/domains') -const exit = require('../util/etc/exit') -const logo = require('../util/etc/output/logo') -const promptBool = require('../util/etc/input/prompt-bool') +const exit = require('../../../util/exit') +const logo = require('../../../util/output/logo') +const promptBool = require('../../../util/input/prompt-bool') const strlen = require('../util/strlen') const toHost = require('../util/to-host') const { handleError, error } = require('../util/error') diff --git a/src/providers/sh/commands/domains/buy.js b/src/providers/sh/commands/domains/buy.js index a858674..7e4d147 100644 --- a/src/providers/sh/commands/domains/buy.js +++ b/src/providers/sh/commands/domains/buy.js @@ -2,16 +2,16 @@ const { italic, bold } = require('chalk') // Utilities -const error = require('../../util/etc/output/error') -const wait = require('../../util/etc/output/wait') -const cmd = require('../../util/etc/output/cmd') -const param = require('../../util/etc/output/param') -const info = require('../../util/etc/output/info') -const success = require('../../util/etc/output/success') -const stamp = require('../../util/etc/output/stamp') -const promptBool = require('../../util/etc/input/prompt-bool') -const eraseLines = require('../../util/etc/output/erase-lines') -const treatBuyError = require('../../util/etc/domains/treat-buy-error') +const error = require('../../../../util/output/error') +const wait = require('../../../../util/output/wait') +const cmd = require('../../../../util/output/cmd') +const param = require('../../../../util/output/param') +const info = require('../../../../util/output/info') +const success = require('../../../../util/output/success') +const stamp = require('../../../../util/output/stamp') +const promptBool = require('../../../../util/input/prompt-bool') +const eraseLines = require('../../../../util/output/erase-lines') +const treatBuyError = require('../../util/domains/treat-buy-error') const NowCreditCards = require('../../util/credit-cards') const addBilling = require('../billing/add') diff --git a/src/providers/sh/commands/list.js b/src/providers/sh/commands/list.js index 035a4d6..1205b64 100644 --- a/src/providers/sh/commands/list.js +++ b/src/providers/sh/commands/list.js @@ -11,7 +11,7 @@ const supportsColor = require('supports-color') // Utilities const Now = require('../util') const { handleError, error } = require('../util/error') -const logo = require('../util/etc/output/logo') +const logo = require('../../../util/output/logo') const sort = require('../util/sort-deployments') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/logout.js b/src/providers/sh/commands/logout.js index c6f44e3..8c1d1b4 100644 --- a/src/providers/sh/commands/logout.js +++ b/src/providers/sh/commands/logout.js @@ -7,7 +7,7 @@ const fetch = require('node-fetch') const ora = require('ora') // Utilities -const logo = require('../util/etc/output/logo') +const logo = require('../../../util/output/logo') const { handleError } = require('../util/error') const { readConfigFile, diff --git a/src/providers/sh/commands/logs.js b/src/providers/sh/commands/logs.js index add61a2..258e49a 100644 --- a/src/providers/sh/commands/logs.js +++ b/src/providers/sh/commands/logs.js @@ -12,9 +12,9 @@ const io = require('socket.io-client') // Utilities const Now = require('../util') const { handleError, error } = require('../util/error') -const logo = require('../util/etc/output/logo') +const logo = require('../../../util/output/logo') const { compare, deserialize } = require('../util/logs') -const { maybeURL, normalizeURL, parseInstanceURL } = require('../util/etc/url') +const { maybeURL, normalizeURL, parseInstanceURL } = require('../../../util/url') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/remove.js b/src/providers/sh/commands/remove.js index 5d36214..fc21139 100644 --- a/src/providers/sh/commands/remove.js +++ b/src/providers/sh/commands/remove.js @@ -9,8 +9,8 @@ const table = require('text-table') // Utilities const Now = require('../util') const { handleError, error } = require('../util/error') -const logo = require('../util/etc/output/logo') -const { normalizeURL } = require('../util/etc/url') +const logo = require('../../../util/output/logo') +const { normalizeURL } = require('../../../util/url') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/scale.js b/src/providers/sh/commands/scale.js index 33caad0..a6e61b2 100644 --- a/src/providers/sh/commands/scale.js +++ b/src/providers/sh/commands/scale.js @@ -12,11 +12,11 @@ const supportsColor = require('supports-color') // Utilities const { handleError, error } = require('../util/error') const NowScale = require('../util/scale') -const exit = require('../util/etc/exit') -const logo = require('../util/etc/output/logo') +const exit = require('../../../util/exit') +const logo = require('../../../util/output/logo') const info = require('../util/scale-info') const sort = require('../util/sort-deployments') -const success = require('../util/etc/output/success') +const success = require('../../../util/output/success') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/secrets.js b/src/providers/sh/commands/secrets.js index 7221454..86fc2e6 100644 --- a/src/providers/sh/commands/secrets.js +++ b/src/providers/sh/commands/secrets.js @@ -10,8 +10,8 @@ const ms = require('ms') const strlen = require('../util/strlen') const { handleError, error } = require('../util/error') const NowSecrets = require('../util/secrets') -const exit = require('../util/etc/exit') -const logo = require('../util/etc/output/logo') +const exit = require('../../../util/exit') +const logo = require('../../../util/output/logo') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/teams.js b/src/providers/sh/commands/teams.js index cfdbfeb..60ede56 100644 --- a/src/providers/sh/commands/teams.js +++ b/src/providers/sh/commands/teams.js @@ -5,10 +5,10 @@ const chalk = require('chalk') const minimist = require('minimist') // Utilities -const error = require('../util/etc/output/error') +const error = require('../../../util/output/error') const NowTeams = require('../util/teams') -const logo = require('../util/etc/output/logo') -const exit = require('../util/etc/exit') +const logo = require('../../../util/output/logo') +const exit = require('../../../util/exit') const { handleError } = require('../util/error') const list = require('./teams/list') const add = require('./teams/add') diff --git a/src/providers/sh/commands/teams/add.js b/src/providers/sh/commands/teams/add.js index 6db6c01..e9c261a 100644 --- a/src/providers/sh/commands/teams/add.js +++ b/src/providers/sh/commands/teams/add.js @@ -2,19 +2,19 @@ const chalk = require('chalk') // Utilities -const stamp = require('../../util/etc/output/stamp') -const info = require('../../util/etc/output/info') -const error = require('../../util/etc/output/error') -const wait = require('../../util/etc/output/wait') -const rightPad = require('../../util/etc/output/right-pad') -const eraseLines = require('../../util/etc/output/erase-lines') -const { tick } = require('../../util/etc/output/chars') -const success = require('../../util/etc/output/success') -const cmd = require('../../util/etc/output/cmd') -const note = require('../../util/etc/output/note') -const uid = require('../../util/etc/output/uid') -const textInput = require('../../util/etc/input/text') -const exit = require('../../util/etc/exit') +const stamp = require('../../../../util/output/stamp') +const info = require('../../../../util/output/info') +const error = require('../../../../util/output/error') +const wait = require('../../../../util/output/wait') +const rightPad = require('../../../../util/output/right-pad') +const eraseLines = require('../../../../util/output/erase-lines') +const { tick } = require('../../../../util/output/chars') +const success = require('../../../../util/output/success') +const cmd = require('../../../../util/output/cmd') +const note = require('../../../../util/output/note') +const uid = require('../../../../util/output/uid') +const textInput = require('../../../../util/input/text') +const exit = require('../../../../util/exit') const cfg = require('../../util/cfg') const invite = require('./invite') diff --git a/src/providers/sh/commands/teams/invite.js b/src/providers/sh/commands/teams/invite.js index 054dd04..f5d1695 100644 --- a/src/providers/sh/commands/teams/invite.js +++ b/src/providers/sh/commands/teams/invite.js @@ -2,20 +2,20 @@ const chalk = require('chalk') // Utilities -const regexes = require('../../util/etc/input/regexes') -const wait = require('../../util/etc/output/wait') +const regexes = require('../../../../util/input/regexes') +const wait = require('../../../../util/output/wait') const cfg = require('../../util/cfg') -const fatalError = require('../../util/etc/fatal-error') -const cmd = require('../../util/etc/output/cmd') -const info = require('../../util/etc/output/info') -const stamp = require('../../util/etc/output/stamp') -const param = require('../../util/etc/output/param') -const { tick } = require('../../util/etc/output/chars') -const rightPad = require('../../util/etc/output/right-pad') -const textInput = require('../../util/etc/input/text') -const eraseLines = require('../../util/etc/output/erase-lines') -const success = require('../../util/etc/output/success') -const error = require('../../util/etc/output/error') +const fatalError = require('../../../../util/fatal-error') +const cmd = require('../../../../util/output/cmd') +const info = require('../../../../util/output/info') +const stamp = require('../../../../util/output/stamp') +const param = require('../../../../util/output/param') +const { tick } = require('../../../../util/output/chars') +const rightPad = require('../../../../util/output/right-pad') +const textInput = require('../../../../util/input/text') +const eraseLines = require('../../../../util/output/erase-lines') +const success = require('../../../../util/output/success') +const error = require('../../../../util/output/error') function validateEmail(data) { return regexes.email.test(data.trim()) || data.length === 0 diff --git a/src/providers/sh/commands/teams/list.js b/src/providers/sh/commands/teams/list.js index 65aead1..34e527a 100644 --- a/src/providers/sh/commands/teams/list.js +++ b/src/providers/sh/commands/teams/list.js @@ -2,12 +2,12 @@ const chalk = require('chalk') // Utilities -const wait = require('../../util/etc/output/wait') +const wait = require('../../../../util/output/wait') const cfg = require('../../util/cfg') -const info = require('../../util/etc/output/info') -const error = require('../../util/etc/output/error') -const { tick: tickChar } = require('../../util/etc/output/chars') -const table = require('../../util/etc/output/table') +const info = require('../../../../util/output/info') +const error = require('../../../../util/output/error') +const { tick: tickChar } = require('../../../../util/output/chars') +const table = require('../../../../util/output/table') module.exports = async function({ teams, token }) { const stopSpinner = wait('Fetching teams') diff --git a/src/providers/sh/commands/teams/switch.js b/src/providers/sh/commands/teams/switch.js index 6ed44e8..3e2a032 100644 --- a/src/providers/sh/commands/teams/switch.js +++ b/src/providers/sh/commands/teams/switch.js @@ -2,14 +2,14 @@ const chalk = require('chalk') // Utilities -const wait = require('../../util/etc/output/wait') -const listInput = require('../../util/etc/input/list') +const wait = require('../../../../util/output/wait') +const listInput = require('../../../../util/input/list') const cfg = require('../../util/cfg') -const exit = require('../../util/etc/exit') -const success = require('../../util/etc/output/success') -const info = require('../../util/etc/output/info') -const error = require('../../util/etc/output/error') -const param = require('../../util/etc/output/param') +const exit = require('../../../../util/exit') +const success = require('../../../../util/output/success') +const info = require('../../../../util/output/info') +const error = require('../../../../util/output/error') +const param = require('../../../../util/output/param') async function updateCurrentTeam({ cfg, newTeam } = {}) { delete newTeam.created diff --git a/src/providers/sh/commands/upgrade.js b/src/providers/sh/commands/upgrade.js index 8bc7615..9a52ba0 100644 --- a/src/providers/sh/commands/upgrade.js +++ b/src/providers/sh/commands/upgrade.js @@ -8,12 +8,12 @@ const ms = require('ms') // Utilities const NowPlans = require('../util/plans') const indent = require('../util/indent') -const listInput = require('../util/etc/input/list') -const code = require('../util/etc/output/code') -const error = require('../util/etc/output/error') -const success = require('../util/etc/output/success') -const cmd = require('../util/etc/output/cmd') -const logo = require('../util/etc/output/logo') +const listInput = require('../../../util/input/list') +const code = require('../../../util/output/code') +const error = require('../../../util/output/error') +const success = require('../../../util/output/success') +const cmd = require('../../../util/output/cmd') +const logo = require('../../../util/output/logo') const { handleError } = require('../util/error') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/commands/whoami.js b/src/providers/sh/commands/whoami.js index d6b96eb..9f07148 100644 --- a/src/providers/sh/commands/whoami.js +++ b/src/providers/sh/commands/whoami.js @@ -5,7 +5,7 @@ const minimist = require('minimist') const chalk = require('chalk') // Utilities -const logo = require('../util/etc/output/logo') +const logo = require('../../../util/output/logo') const { handleError } = require('../util/error') const getWelcome = require('../../../get-welcome') const providers = require('../../') diff --git a/src/providers/sh/util/alias.js b/src/providers/sh/util/alias.js index 8b3b8ce..552780a 100755 --- a/src/providers/sh/util/alias.js +++ b/src/providers/sh/util/alias.js @@ -7,22 +7,22 @@ const chalk = require('chalk') const { write: copy } = require('clipboardy') // Ours -const promptBool = require('./etc/input/prompt-bool') -const info = require('./etc/output/info') -const param = require('./etc/output/param') -const wait = require('./etc/output/wait') -const success = require('./etc/output/success') -const uid = require('./etc/output/uid') -const eraseLines = require('./etc/output/erase-lines') -const stamp = require('./etc/output/stamp') -const error = require('./etc/output/error') -const treatBuyError = require('./etc/domains/treat-buy-error') +const promptBool = require('../../../util/input/prompt-bool') +const info = require('../../../util/output/info') +const param = require('../../../util/output/param') +const wait = require('../../../util/output/wait') +const success = require('../../../util/output/success') +const uid = require('../../../util/output/uid') +const eraseLines = require('../../../util/output/erase-lines') +const stamp = require('../../../util/output/stamp') +const error = require('../../../util/output/error') +const treatBuyError = require('../util/domains/treat-buy-error') const scaleInfo = require('./scale-info') const { DOMAIN_VERIFICATION_ERROR } = require('./errors') const isZeitWorld = require('./is-zeit-world') const resolve4 = require('./dns') const toHost = require('./to-host') -const exit = require('./etc/exit') +const exit = require('../../../util/exit') const Now = require('./') const argv = minimist(process.argv.slice(2), { diff --git a/src/providers/sh/util/etc/billing/card-brands.json b/src/providers/sh/util/billing/card-brands.json similarity index 100% rename from src/providers/sh/util/etc/billing/card-brands.json rename to src/providers/sh/util/billing/card-brands.json diff --git a/src/providers/sh/util/etc/billing/country-list.json b/src/providers/sh/util/billing/country-list.json similarity index 100% rename from src/providers/sh/util/etc/billing/country-list.json rename to src/providers/sh/util/billing/country-list.json diff --git a/src/providers/sh/util/etc/billing/geocode.js b/src/providers/sh/util/billing/geocode.js similarity index 100% rename from src/providers/sh/util/etc/billing/geocode.js rename to src/providers/sh/util/billing/geocode.js diff --git a/src/providers/sh/util/domains.js b/src/providers/sh/util/domains.js index af8df48..6ccdef6 100755 --- a/src/providers/sh/util/domains.js +++ b/src/providers/sh/util/domains.js @@ -8,7 +8,7 @@ const chalk = require('chalk') const Now = require('.') const isZeitWorld = require('./is-zeit-world') const { DNS_VERIFICATION_ERROR } = require('./errors') -const cmd = require('./etc/output/param') +const cmd = require('../../../util/output/param') const domainRegex = /^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}$/ diff --git a/src/providers/sh/util/etc/domains/treat-buy-error.js b/src/providers/sh/util/domains/treat-buy-error.js similarity index 91% rename from src/providers/sh/util/etc/domains/treat-buy-error.js rename to src/providers/sh/util/domains/treat-buy-error.js index 2b9ff53..16c2b38 100755 --- a/src/providers/sh/util/etc/domains/treat-buy-error.js +++ b/src/providers/sh/util/domains/treat-buy-error.js @@ -1,4 +1,4 @@ -const error = require('../output/error') +const error = require('../../../../util/output/error') module.exports = function(err) { switch (err.code) { diff --git a/src/providers/sh/util/etc/input/list.js b/src/providers/sh/util/etc/input/list.js deleted file mode 100755 index d6bf72b..0000000 --- a/src/providers/sh/util/etc/input/list.js +++ /dev/null @@ -1,79 +0,0 @@ -const inquirer = require('inquirer') -const stripAnsi = require('strip-ansi') - -// eslint-disable-next-line import/no-unassigned-import -require('./patch-inquirer') - -function getLength(string) { - let biggestLength = 0 - string.split('\n').map(str => { - str = stripAnsi(str) - if (str.length > biggestLength) { - biggestLength = str.length - } - return undefined - }) - return biggestLength -} - -module.exports = async function({ - message = 'the question', - // eslint-disable-line no-unused-vars - choices = [ - { - name: 'something\ndescription\ndetails\netc', - value: 'something unique', - short: 'generally the first line of `name`' - } - ], - pageSize = 15, // Show 15 lines without scrolling (~4 credit cards) - separator = true, // Puts a blank separator between each choice - abort = 'end' // Wether the `abort` option will be at the `start` or the `end` -}) { - let biggestLength = 0 - - choices = choices.map(choice => { - if (choice.name) { - const length = getLength(choice.name) - if (length > biggestLength) { - biggestLength = length - } - return choice - } - throw new Error('Invalid choice') - }) - - if (separator === true) { - choices = choices.reduce( - (prev, curr) => prev.concat(new inquirer.Separator(' '), curr), - [] - ) - } - - const abortSeparator = new inquirer.Separator('─'.repeat(biggestLength)) - const _abort = { - name: 'Abort', - value: undefined - } - - if (abort === 'start') { - const blankSep = choices.shift() - choices.unshift(abortSeparator) - choices.unshift(_abort) - choices.unshift(blankSep) - } else { - choices.push(abortSeparator) - choices.push(_abort) - } - - const nonce = Date.now() - const answer = await inquirer.prompt({ - name: nonce, - type: 'list', - message, - choices, - pageSize - }) - - return answer[nonce] -} diff --git a/src/providers/sh/util/etc/input/patch-inquirer.js b/src/providers/sh/util/etc/input/patch-inquirer.js deleted file mode 100755 index a869c4f..0000000 --- a/src/providers/sh/util/etc/input/patch-inquirer.js +++ /dev/null @@ -1,20 +0,0 @@ -const inquirer = require('inquirer') -const chalk = require('chalk') - -// Here we patch inquirer to use a `>` instead of the ugly green `?` - -/* eslint-disable no-multiple-empty-lines, no-var, no-undef, no-eq-null, eqeqeq, semi */ -const getQuestion = function() { - var message = chalk.bold('> ' + this.opt.message) + ' ' - - // Append the default if available, and if question isn't answered - if (this.opt.default != null && this.status !== 'answered') { - message += chalk.dim('(' + this.opt.default + ') ') - } - - return message -} -/* eslint-enable */ - -inquirer.prompt.prompts.input.prototype.getQuestion = getQuestion -inquirer.prompt.prompts.list.prototype.getQuestion = getQuestion diff --git a/src/providers/sh/util/etc/input/prompt-bool.js b/src/providers/sh/util/etc/input/prompt-bool.js deleted file mode 100755 index 576b44f..0000000 --- a/src/providers/sh/util/etc/input/prompt-bool.js +++ /dev/null @@ -1,58 +0,0 @@ -const chalk = require('chalk') - -module.exports = ( - label, - { - defaultValue = false, - abortSequences = new Set(['\u0003']), - resolveChars = new Set(['\r']), - yesChar = 'y', - noChar = 'n', - stdin = process.stdin, - stdout = process.stdout, - trailing = '' - } = {} -) => { - return new Promise(resolve => { - const isRaw = stdin.isRaw - - stdin.setRawMode(true) - stdin.resume() - - function restore() { - stdout.write(trailing) - stdin.setRawMode(isRaw) - stdin.pause() - stdin.removeListener('data', onData) - } - - function onData(buffer) { - const data = buffer.toString() - - if (data[0].toLowerCase() === yesChar) { - restore() - resolve(true) - } else if (data[0].toLowerCase() === noChar) { - restore() - resolve(false) - } else if (abortSequences.has(data)) { - restore() - resolve(false) - } else if (resolveChars.has(data[0])) { - restore() - resolve(defaultValue) - } else { - // ignore extraneous input - } - } - - const defaultText = - defaultValue === null - ? `[${yesChar}|${noChar}]` - : defaultValue - ? `[${chalk.bold(yesChar.toUpperCase())}|${noChar}]` - : `[${yesChar}|${chalk.bold(noChar.toUpperCase())}]` - stdout.write(`${chalk.gray('>')} ${label} ${chalk.gray(defaultText)} `) - stdin.on('data', onData) - }) -} diff --git a/src/providers/sh/util/etc/input/text.js b/src/providers/sh/util/etc/input/text.js deleted file mode 100755 index f8d4540..0000000 --- a/src/providers/sh/util/etc/input/text.js +++ /dev/null @@ -1,262 +0,0 @@ -// Packages -const ansiEscapes = require('ansi-escapes') -const ansiRegex = require('ansi-regex') -const chalk = require('chalk') -const stripAnsi = require('strip-ansi') - -// Utilities -const eraseLines = require('../output/erase-lines') - -const ESCAPES = { - LEFT: '\u001B[D', - RIGHT: '\u001B[C', - CTRL_C: '\u0003', - BACKSPACE: '\u0008', - CTRL_H: '\u007F', - CARRIAGE: '\r' -} - -const formatCC = data => { - return data.replace(/\s/g, '').replace(/(.{4})/g, '$1 ').trim() -} - -module.exports = function( - { - label = '', - initialValue = '', - // If false, the `- label` will be printed as `✖ label` in red - // Until the first keypress - valid = true, - // Can be: - // - `false`, which does nothing - // - `cc`, for credit cards - // - `date`, for dates in the mm / yyyy format - mask = false, - placeholder = '', - abortSequences = new Set(['\x03']), - eraseSequences = new Set([ESCAPES.BACKSPACE, ESCAPES.CTRL_H]), - resolveChars = new Set([ESCAPES.CARRIAGE]), - stdin = process.stdin, - stdout = process.stdout, - // Char to print before resolving/rejecting the promise - // If `false`, nothing will be printed - trailing = ansiEscapes.eraseLines(1), - // Gets called on each keypress; - // `data` contains the current keypress; - // `futureValue` contains the current value + the - // Keypress in the correct place - validateKeypress = (data, futureValue) => true, // eslint-disable-line no-unused-vars - // Get's called before the promise is resolved - // Returning `false` here will prevent the user from submiting the value - validateValue = data => true, // eslint-disable-line no-unused-vars - // Receives the value of the input and should return a string - // Or false if no autocomplion is available - autoComplete = value => false, // eslint-disable-line no-unused-vars - // Tab - // Right arrow - autoCompleteChars = new Set(['\t', '\x1b[C']), - // If true, converts everything the user types to to lowercase - forceLowerCase = false - } = {} -) { - return new Promise((resolve, reject) => { - const isRaw = process.stdin.isRaw - - let value - let caretOffset = 0 - let regex - let suggestion = '' - - if (valid) { - stdout.write(label) - } else { - const _label = label.replace('-', '✖') - stdout.write(chalk.red(_label)) - } - - value = initialValue - stdout.write(initialValue) - - if (mask) { - if (!value) { - value = chalk.gray(placeholder) - caretOffset = 0 - stripAnsi(value).length - stdout.write(value) - stdout.write(ansiEscapes.cursorBackward(Math.abs(caretOffset))) - } - - regex = placeholder - .split('') - .reduce((prev, curr) => { - if (curr !== ' ' && !prev.includes(curr)) { - if (curr === '/') { - prev.push(' / ') - } else { - prev.push(curr) - } - } - return prev - }, []) - .join('|') - regex = new RegExp(`(${regex})`, 'g') - } - - stdin.setRawMode(true) - stdin.resume() - - function restore() { - stdin.setRawMode(isRaw) - stdin.pause() - stdin.removeListener('data', onData) - if (trailing) { - stdout.write(trailing) - } - } - - async function onData(buffer) { - let data = buffer.toString() - - value = stripAnsi(value) - - if (abortSequences.has(data)) { - restore() - return reject(new Error('USER_ABORT')) - } - - if (forceLowerCase) { - data = data.toLowerCase() - } - - if (suggestion !== '' && !caretOffset && autoCompleteChars.has(data)) { - value += stripAnsi(suggestion) - suggestion = '' - } else if (data === ESCAPES.LEFT) { - if (value.length > Math.abs(caretOffset)) { - caretOffset-- - } - } else if (data === ESCAPES.RIGHT) { - if (caretOffset < 0) { - caretOffset++ - } - } else if (eraseSequences.has(data)) { - let char - if (mask && value.length > Math.abs(caretOffset)) { - if (value[value.length + caretOffset - 1] === ' ') { - if (value[value.length + caretOffset - 2] === '/') { - caretOffset -= 1 - } - char = placeholder[value.length + caretOffset] - value = - value.substr(0, value.length + caretOffset - 2) + - char + - value.substr(value.length + caretOffset - 1) - caretOffset-- - } else { - char = placeholder[value.length + caretOffset - 1] - value = - value.substr(0, value.length + caretOffset - 1) + - char + - value.substr(value.length + caretOffset) - } - caretOffset-- - } else { - value = - value.substr(0, value.length + caretOffset - 1) + - value.substr(value.length + caretOffset) - } - suggestion = '' - } else if (resolveChars.has(data)) { - if (validateValue(value)) { - restore() - resolve(value) - } else { - if (mask === 'cc' || mask === 'ccv') { - value = formatCC(value) - value = value.replace(regex, chalk.gray('$1')) - } else if (mask === 'expDate') { - value = value.replace(regex, chalk.gray('$1')) - } - - const l = chalk.red(label.replace('-', '✖')) - eraseLines(1) - stdout.write(l + value + ansiEscapes.beep) - if (caretOffset) { - process.stdout.write( - ansiEscapes.cursorBackward(Math.abs(caretOffset)) - ) - } - } - return - } else if (!ansiRegex().test(data)) { - let tmp = - value.substr(0, value.length + caretOffset) + - data + - value.substr(value.length + caretOffset) - - if (mask) { - if (/\d/.test(data) && caretOffset !== 0) { - let formattedData = data - - if (mask === 'cc' || mask === 'ccv') { - formattedData = formatCC(data) - } - - if (value[value.length + caretOffset + 1] === ' ') { - tmp = - value.substr(0, value.length + caretOffset) + - formattedData + - value.substr(value.length + caretOffset + formattedData.length) - - caretOffset += formattedData.length + 1 - - if (value[value.length + caretOffset] === '/') { - caretOffset += formattedData.length + 1 - } - } else { - tmp = - value.substr(0, value.length + caretOffset) + - formattedData + - value.substr(value.length + caretOffset + formattedData.length) - - caretOffset += formattedData.length - } - } else if (/\s/.test(data) && caretOffset < 0) { - caretOffset++ - tmp = value - } else { - return stdout.write(ansiEscapes.beep) - } - value = tmp - } else if (validateKeypress(data, value)) { - value = tmp - if (caretOffset === 0) { - const completion = await autoComplete(value) - if (completion) { - suggestion = chalk.gray(completion) - suggestion += ansiEscapes.cursorBackward(completion.length) - } else { - suggestion = '' - } - } - } else { - return stdout.write(ansiEscapes.beep) - } - } - - if (mask === 'cc' || mask === 'ccv') { - value = formatCC(value) - value = value.replace(regex, chalk.gray('$1')) - } else if (mask === 'expDate') { - value = value.replace(regex, chalk.gray('$1')) - } - - eraseLines(1) - stdout.write(label + value + suggestion) - if (caretOffset) { - process.stdout.write(ansiEscapes.cursorBackward(Math.abs(caretOffset))) - } - } - - stdin.on('data', onData) - }) -} diff --git a/src/providers/sh/util/etc/output/chars.js b/src/providers/sh/util/etc/output/chars.js deleted file mode 100755 index bec8239..0000000 --- a/src/providers/sh/util/etc/output/chars.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - tick: '✓' -} diff --git a/src/providers/sh/util/etc/output/cmd.js b/src/providers/sh/util/etc/output/cmd.js deleted file mode 100755 index 024ab3c..0000000 --- a/src/providers/sh/util/etc/output/cmd.js +++ /dev/null @@ -1,6 +0,0 @@ -const chalk = require('chalk') - -// The equivalent of , for embedding a cmd -// eg: Please run ${cmd(woot)} - -module.exports = cmd => `${chalk.gray('`')}${chalk.cyan(cmd)}${chalk.gray('`')}` diff --git a/src/providers/sh/util/etc/output/erase-lines.js b/src/providers/sh/util/etc/output/erase-lines.js deleted file mode 100755 index a7cae20..0000000 --- a/src/providers/sh/util/etc/output/erase-lines.js +++ /dev/null @@ -1,3 +0,0 @@ -const ansiEscapes = require('ansi-escapes') - -module.exports = n => process.stdout.write(ansiEscapes.eraseLines(n)) diff --git a/src/providers/sh/util/etc/output/error.js b/src/providers/sh/util/etc/output/error.js deleted file mode 100755 index d5555c3..0000000 --- a/src/providers/sh/util/etc/output/error.js +++ /dev/null @@ -1,9 +0,0 @@ -const chalk = require('chalk') - -// Prints an error message -module.exports = msg => { - if (msg.message) { - msg = msg.message - } - console.error(`${chalk.red('> Error!')} ${msg}`) -} diff --git a/src/providers/sh/util/etc/output/info.js b/src/providers/sh/util/etc/output/info.js deleted file mode 100755 index 064ecf7..0000000 --- a/src/providers/sh/util/etc/output/info.js +++ /dev/null @@ -1,6 +0,0 @@ -const chalk = require('chalk') - -// Prints an informational message -module.exports = msg => { - console.log(`${chalk.gray('>')} ${msg}`) -} diff --git a/src/providers/sh/util/etc/output/logo.js b/src/providers/sh/util/etc/output/logo.js deleted file mode 100755 index 1b18411..0000000 --- a/src/providers/sh/util/etc/output/logo.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = process.platform === 'win32' ? 'Δ' : '𝚫' diff --git a/src/providers/sh/util/etc/output/note.js b/src/providers/sh/util/etc/output/note.js deleted file mode 100755 index 0c44ac8..0000000 --- a/src/providers/sh/util/etc/output/note.js +++ /dev/null @@ -1,6 +0,0 @@ -const chalk = require('chalk') - -// Prints a note -module.exports = msg => { - console.log(`${chalk.yellow('> NOTE:')} ${msg}`) -} diff --git a/src/providers/sh/util/etc/output/param.js b/src/providers/sh/util/etc/output/param.js deleted file mode 100755 index 7d4c4e7..0000000 --- a/src/providers/sh/util/etc/output/param.js +++ /dev/null @@ -1,7 +0,0 @@ -const chalk = require('chalk') - -// Returns a user param in a nice formatting -// e.g.: google.com -> "google.com" (in bold) - -module.exports = param => - chalk.bold(`${chalk.gray('"')}${chalk.bold(param)}${chalk.gray('"')}`) diff --git a/src/providers/sh/util/etc/output/success.js b/src/providers/sh/util/etc/output/success.js deleted file mode 100755 index b1d1550..0000000 --- a/src/providers/sh/util/etc/output/success.js +++ /dev/null @@ -1,6 +0,0 @@ -const chalk = require('chalk') - -// Prints a success message -module.exports = msg => { - console.log(`${chalk.cyan('> Success!')} ${msg}`) -} diff --git a/src/providers/sh/util/etc/output/wait.js b/src/providers/sh/util/etc/output/wait.js deleted file mode 100755 index e5f8c07..0000000 --- a/src/providers/sh/util/etc/output/wait.js +++ /dev/null @@ -1,15 +0,0 @@ -const ora = require('ora') -const chalk = require('chalk') -const { eraseLine } = require('ansi-escapes') - -// Prints a spinner followed by the given text -module.exports = msg => { - const spinner = ora(chalk.gray(msg)) - spinner.color = 'gray' - spinner.start() - - return () => { - spinner.stop() - process.stdout.write(eraseLine) - } -} diff --git a/src/providers/sh/util/etc/check-path.js b/src/util/check-path.js similarity index 100% rename from src/providers/sh/util/etc/check-path.js rename to src/util/check-path.js diff --git a/src/providers/sh/util/etc/exit.js b/src/util/exit.js similarity index 100% rename from src/providers/sh/util/etc/exit.js rename to src/util/exit.js diff --git a/src/providers/sh/util/etc/fatal-error.js b/src/util/fatal-error.js similarity index 100% rename from src/providers/sh/util/etc/fatal-error.js rename to src/util/fatal-error.js diff --git a/src/providers/sh/util/etc/input/prompt-options.js b/src/util/input/prompt-options.js similarity index 100% rename from src/providers/sh/util/etc/input/prompt-options.js rename to src/util/input/prompt-options.js diff --git a/src/providers/sh/util/etc/input/regexes.js b/src/util/input/regexes.js similarity index 100% rename from src/providers/sh/util/etc/input/regexes.js rename to src/util/input/regexes.js diff --git a/src/providers/sh/util/etc/output/code.js b/src/util/output/code.js old mode 100755 new mode 100644 similarity index 94% rename from src/providers/sh/util/etc/output/code.js rename to src/util/output/code.js index ed11ab2..5f0f1db --- a/src/providers/sh/util/etc/output/code.js +++ b/src/util/output/code.js @@ -1,3 +1,4 @@ +// Packages const chalk = require('chalk') // The equivalent of , for embedding anything diff --git a/src/providers/sh/util/etc/output/right-pad.js b/src/util/output/right-pad.js similarity index 100% rename from src/providers/sh/util/etc/output/right-pad.js rename to src/util/output/right-pad.js diff --git a/src/providers/sh/util/etc/output/stamp.js b/src/util/output/stamp.js similarity index 100% rename from src/providers/sh/util/etc/output/stamp.js rename to src/util/output/stamp.js diff --git a/src/providers/sh/util/etc/output/table.js b/src/util/output/table.js similarity index 100% rename from src/providers/sh/util/etc/output/table.js rename to src/util/output/table.js diff --git a/src/providers/sh/util/etc/output/uid.js b/src/util/output/uid.js similarity index 100% rename from src/providers/sh/util/etc/output/uid.js rename to src/util/output/uid.js diff --git a/src/providers/sh/util/etc/to-human-path.js b/src/util/to-human-path.js similarity index 100% rename from src/providers/sh/util/etc/to-human-path.js rename to src/util/to-human-path.js diff --git a/src/providers/sh/util/etc/url.js b/src/util/url.js similarity index 100% rename from src/providers/sh/util/etc/url.js rename to src/util/url.js