Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Feb 7, 2023
1 parent 6ea2cd7 commit fc5332f
Show file tree
Hide file tree
Showing 22 changed files with 879 additions and 132 deletions.
15 changes: 7 additions & 8 deletions lib/utils/read-user-info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { promisify } = require('util')
const readAsync = promisify(require('read'))
const read = require('read')
const userValidate = require('npm-user-validate')
const log = require('./log-shim.js')

Expand All @@ -17,17 +16,17 @@ const passwordPrompt = 'npm password: '
const usernamePrompt = 'npm username: '
const emailPrompt = 'email (this IS public): '

function read (opts) {
function readWithProgress (opts) {
log.clearProgress()
return readAsync(opts).finally(() => log.showProgress())
return read(opts).finally(() => log.showProgress())
}

function readOTP (msg = otpPrompt, otp, isRetry) {
if (isRetry && otp && /^[\d ]+$|^[A-Fa-f0-9]{64,64}$/.test(otp)) {
return otp.replace(/\s+/g, '')
}

return read({ prompt: msg, default: otp || '' })
return readWithProgress({ prompt: msg, default: otp || '' })
.then((rOtp) => readOTP(msg, rOtp, true))
}

Expand All @@ -36,7 +35,7 @@ function readPassword (msg = passwordPrompt, password, isRetry) {
return password
}

return read({ prompt: msg, silent: true, default: password || '' })
return readWithProgress({ prompt: msg, silent: true, default: password || '' })
.then((rPassword) => readPassword(msg, rPassword, true))
}

Expand All @@ -50,7 +49,7 @@ function readUsername (msg = usernamePrompt, username, isRetry) {
}
}

return read({ prompt: msg, default: username || '' })
return readWithProgress({ prompt: msg, default: username || '' })
.then((rUsername) => readUsername(msg, rUsername, true))
}

Expand All @@ -64,6 +63,6 @@ function readEmail (msg = emailPrompt, email, isRetry) {
}
}

return read({ prompt: msg, default: email || '' })
return readWithProgress({ prompt: msg, default: email || '' })
.then((username) => readEmail(msg, username, true))
}
8 changes: 8 additions & 0 deletions node_modules/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
!/inherits
!/ini
!/init-package-json
!/init-package-json/node_modules/
/init-package-json/node_modules/*
!/init-package-json/node_modules/mute-stream
!/init-package-json/node_modules/read
!/ip-regex
!/ip
!/is-cidr
Expand Down Expand Up @@ -227,6 +231,10 @@
!/promise-inflight
!/promise-retry
!/promzard
!/promzard/node_modules/
/promzard/node_modules/*
!/promzard/node_modules/mute-stream
!/promzard/node_modules/read
!/qrcode-terminal
!/read-cmd-shim
!/read-package-json-fast
Expand Down
15 changes: 15 additions & 0 deletions node_modules/init-package-json/node_modules/mute-stream/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The ISC License

Copyright (c) Isaac Z. Schlueter and Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "mute-stream",
"version": "0.0.8",
"main": "mute.js",
"directories": {
"test": "test"
},
"devDependencies": {
"tap": "^12.1.1"
},
"scripts": {
"test": "tap test/*.js --cov"
},
"repository": {
"type": "git",
"url": "git://github.com/isaacs/mute-stream"
},
"keywords": [
"mute",
"stream",
"pipe"
],
"author": "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)",
"license": "ISC",
"description": "Bytes go in, but they don't come out (when muted).",
"files": [
"mute.js"
]
}
15 changes: 15 additions & 0 deletions node_modules/init-package-json/node_modules/read/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The ISC License

Copyright (c) Isaac Z. Schlueter and Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
113 changes: 113 additions & 0 deletions node_modules/init-package-json/node_modules/read/lib/read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

module.exports = read

var readline = require('readline')
var Mute = require('mute-stream')

function read (opts, cb) {
if (opts.num) {
throw new Error('read() no longer accepts a char number limit')
}

if (typeof opts.default !== 'undefined' &&
typeof opts.default !== 'string' &&
typeof opts.default !== 'number') {
throw new Error('default value must be string or number')
}

var input = opts.input || process.stdin
var output = opts.output || process.stdout
var prompt = (opts.prompt || '').trim() + ' '
var silent = opts.silent
var editDef = false
var timeout = opts.timeout

var def = opts.default || ''
if (def) {
if (silent) {
prompt += '(<default hidden>) '
} else if (opts.edit) {
editDef = true
} else {
prompt += '(' + def + ') '
}
}
var terminal = !!(opts.terminal || output.isTTY)

var m = new Mute({ replace: opts.replace, prompt: prompt })
m.pipe(output, {end: false})
output = m
var rlOpts = { input: input, output: output, terminal: terminal }

if (process.version.match(/^v0\.6/)) {
var rl = readline.createInterface(rlOpts.input, rlOpts.output)
} else {
var rl = readline.createInterface(rlOpts)
}


output.unmute()
rl.setPrompt(prompt)
rl.prompt()
if (silent) {
output.mute()
} else if (editDef) {
rl.line = def
rl.cursor = def.length
rl._refreshLine()
}

var called = false
rl.on('line', onLine)
rl.on('error', onError)

rl.on('SIGINT', function () {
rl.close()
onError(new Error('canceled'))
})

var timer
if (timeout) {
timer = setTimeout(function () {
onError(new Error('timed out'))
}, timeout)
}

function done () {
called = true
rl.close()

if (process.version.match(/^v0\.6/)) {
rl.input.removeAllListeners('data')
rl.input.removeAllListeners('keypress')
rl.input.pause()
}

clearTimeout(timer)
output.mute()
output.end()
}

function onError (er) {
if (called) return
done()
return cb(er)
}

function onLine (line) {
if (called) return
if (silent && terminal) {
output.unmute()
output.write('\r\n')
}
done()
// truncate the \n at the end.
line = line.replace(/\r?\n$/, '')
var isDefault = !!(editDef && line === def)
if (def && !line) {
isDefault = true
line = def
}
cb(null, line, isDefault)
}
}
27 changes: 27 additions & 0 deletions node_modules/init-package-json/node_modules/read/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "read",
"version": "1.0.7",
"main": "lib/read.js",
"dependencies": {
"mute-stream": "~0.0.4"
},
"devDependencies": {
"tap": "^1.2.0"
},
"engines": {
"node": ">=0.8"
},
"author": "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)",
"description": "read(1) for node programs",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/read.git"
},
"license": "ISC",
"scripts": {
"test": "tap test/*.js"
},
"files": [
"lib/read.js"
]
}
Loading

0 comments on commit fc5332f

Please sign in to comment.