This commit is contained in:
Tutur33
2023-11-24 23:58:26 +01:00
parent 25395c0ee1
commit 938ad9d309
4191 changed files with 41 additions and 518781 deletions
-21
View File
@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2016-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-1839
View File
File diff suppressed because it is too large Load Diff
-156
View File
@@ -1,156 +0,0 @@
import { EventEmitter } from "events";
interface BasePromptOptions {
name: string | (() => string)
type: string | (() => string)
message: string | (() => string) | (() => Promise<string>)
prefix?: string
initial?: any
required?: boolean
enabled?: boolean | string
disabled?: boolean | string
format?(value: string): string | Promise<string>
result?(value: string): string | Promise<string>
skip?: ((state: object) => boolean | Promise<boolean>) | boolean
validate?(value: string): boolean | string | Promise<boolean | string>
onSubmit?(name: string, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
onCancel?(name: string, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
stdin?: NodeJS.ReadStream
stdout?: NodeJS.WriteStream
}
interface Choice {
name: string
message?: string
value?: unknown
hint?: string
role?: string
enabled?: boolean
disabled?: boolean | string
}
interface ArrayPromptOptions extends BasePromptOptions {
type:
| 'autocomplete'
| 'editable'
| 'form'
| 'multiselect'
| 'select'
| 'survey'
| 'list'
| 'scale'
choices: (string | Choice)[]
maxChoices?: number
multiple?: boolean
initial?: number
delay?: number
separator?: boolean
sort?: boolean
linebreak?: boolean
edgeLength?: number
align?: 'left' | 'right'
scroll?: boolean
}
interface BooleanPromptOptions extends BasePromptOptions {
type: 'confirm'
initial?: boolean
}
interface StringPromptOptions extends BasePromptOptions {
type: 'input' | 'invisible' | 'list' | 'password' | 'text'
initial?: string
multiline?: boolean
}
interface NumberPromptOptions extends BasePromptOptions {
type: 'numeral'
min?: number
max?: number
delay?: number
float?: boolean
round?: boolean
major?: number
minor?: number
initial?: number
}
interface SnippetPromptOptions extends BasePromptOptions {
type: 'snippet'
newline?: string
template?: string
}
interface SortPromptOptions extends BasePromptOptions {
type: 'sort'
hint?: string
drag?: boolean
numbered?: boolean
}
type PromptOptions =
| BasePromptOptions
| ArrayPromptOptions
| BooleanPromptOptions
| StringPromptOptions
| NumberPromptOptions
| SnippetPromptOptions
| SortPromptOptions
declare class BasePrompt extends EventEmitter {
constructor(options?: PromptOptions);
render(): void;
run(): Promise<any>;
}
declare class Enquirer<T = object> extends EventEmitter {
constructor(options?: object, answers?: T);
/**
* Register a custom prompt type.
*
* @param type
* @param fn `Prompt` class, or a function that returns a `Prompt` class.
*/
register(type: string, fn: typeof BasePrompt | (() => typeof BasePrompt)): this;
/**
* Register a custom prompt type.
*/
register(type: { [key: string]: typeof BasePrompt | (() => typeof BasePrompt) }): this;
/**
* Prompt function that takes a "question" object or array of question objects,
* and returns an object with responses from the user.
*
* @param questions Options objects for one or more prompts to run.
*/
prompt(
questions:
| PromptOptions
| ((this: Enquirer) => PromptOptions)
| (PromptOptions | ((this: Enquirer) => PromptOptions))[]
): Promise<T>;
/**
* Use an enquirer plugin.
*
* @param plugin Plugin function that takes an instance of Enquirer.
*/
use(plugin: (this: this, enquirer: this) => void): this;
}
declare namespace Enquirer {
function prompt<T = object>(
questions:
| PromptOptions
| ((this: Enquirer) => PromptOptions)
| (PromptOptions | ((this: Enquirer) => PromptOptions))[]
): Promise<T>;
class Prompt extends BasePrompt {}
}
export = Enquirer;
-254
View File
@@ -1,254 +0,0 @@
'use strict';
const assert = require('assert');
const Events = require('events');
const utils = require('./lib/utils');
/**
* Create an instance of `Enquirer`.
*
* ```js
* const Enquirer = require('enquirer');
* const enquirer = new Enquirer();
* ```
* @name Enquirer
* @param {Object} `options` (optional) Options to use with all prompts.
* @param {Object} `answers` (optional) Answers object to initialize with.
* @api public
*/
class Enquirer extends Events {
constructor(options, answers) {
super();
this.options = utils.merge({}, options);
this.answers = { ...answers };
}
/**
* Register a custom prompt type.
*
* ```js
* const Enquirer = require('enquirer');
* const enquirer = new Enquirer();
* enquirer.register('customType', require('./custom-prompt'));
* ```
* @name register()
* @param {String} `type`
* @param {Function|Prompt} `fn` `Prompt` class, or a function that returns a `Prompt` class.
* @return {Object} Returns the Enquirer instance
* @api public
*/
register(type, fn) {
if (utils.isObject(type)) {
for (let key of Object.keys(type)) this.register(key, type[key]);
return this;
}
assert.equal(typeof fn, 'function', 'expected a function');
const name = type.toLowerCase();
if (fn.prototype instanceof this.Prompt) {
this.prompts[name] = fn;
} else {
this.prompts[name] = fn(this.Prompt, this);
}
return this;
}
/**
* Prompt function that takes a "question" object or array of question objects,
* and returns an object with responses from the user.
*
* ```js
* const Enquirer = require('enquirer');
* const enquirer = new Enquirer();
*
* const response = await enquirer.prompt({
* type: 'input',
* name: 'username',
* message: 'What is your username?'
* });
* console.log(response);
* ```
* @name prompt()
* @param {Array|Object} `questions` Options objects for one or more prompts to run.
* @return {Promise} Promise that returns an "answers" object with the user's responses.
* @api public
*/
async prompt(questions = []) {
for (let question of [].concat(questions)) {
try {
if (typeof question === 'function') question = await question.call(this);
await this.ask(utils.merge({}, this.options, question));
} catch (err) {
return Promise.reject(err);
}
}
return this.answers;
}
async ask(question) {
if (typeof question === 'function') {
question = await question.call(this);
}
let opts = utils.merge({}, this.options, question);
let { type, name } = question;
let { set, get } = utils;
if (typeof type === 'function') {
type = await type.call(this, question, this.answers);
}
if (!type) return this.answers[name];
if (type === 'number') type = 'numeral';
assert(this.prompts[type], `Prompt "${type}" is not registered`);
let prompt = new this.prompts[type](opts);
let value = get(this.answers, name);
prompt.state.answers = this.answers;
prompt.enquirer = this;
if (name) {
prompt.on('submit', value => {
this.emit('answer', name, value, prompt);
set(this.answers, name, value);
});
}
// bubble events
let emit = prompt.emit.bind(prompt);
prompt.emit = (...args) => {
this.emit.call(this, ...args);
return emit(...args);
};
this.emit('prompt', prompt, this);
if (opts.autofill && value != null) {
prompt.value = prompt.input = value;
// if "autofill=show" render the prompt, otherwise stay "silent"
if (opts.autofill === 'show') {
await prompt.submit();
}
} else {
value = prompt.value = await prompt.run();
}
return value;
}
/**
* Use an enquirer plugin.
*
* ```js
* const Enquirer = require('enquirer');
* const enquirer = new Enquirer();
* const plugin = enquirer => {
* // do stuff to enquire instance
* };
* enquirer.use(plugin);
* ```
* @name use()
* @param {Function} `plugin` Plugin function that takes an instance of Enquirer.
* @return {Object} Returns the Enquirer instance.
* @api public
*/
use(plugin) {
plugin.call(this, this);
return this;
}
set Prompt(value) {
this._Prompt = value;
}
get Prompt() {
return this._Prompt || this.constructor.Prompt;
}
get prompts() {
return this.constructor.prompts;
}
static set Prompt(value) {
this._Prompt = value;
}
static get Prompt() {
return this._Prompt || require('./lib/prompt');
}
static get prompts() {
return require('./lib/prompts');
}
static get types() {
return require('./lib/types');
}
/**
* Prompt function that takes a "question" object or array of question objects,
* and returns an object with responses from the user.
*
* ```js
* const { prompt } = require('enquirer');
* const response = await prompt({
* type: 'input',
* name: 'username',
* message: 'What is your username?'
* });
* console.log(response);
* ```
* @name Enquirer#prompt
* @param {Array|Object} `questions` Options objects for one or more prompts to run.
* @return {Promise} Promise that returns an "answers" object with the user's responses.
* @api public
*/
static get prompt() {
const fn = (questions, ...rest) => {
let enquirer = new this(...rest);
let emit = enquirer.emit.bind(enquirer);
enquirer.emit = (...args) => {
fn.emit(...args);
return emit(...args);
};
return enquirer.prompt(questions);
};
utils.mixinEmitter(fn, new Events());
return fn;
}
}
utils.mixinEmitter(Enquirer, new Events());
const prompts = Enquirer.prompts;
for (let name of Object.keys(prompts)) {
let key = name.toLowerCase();
let run = options => new prompts[name](options).run();
Enquirer.prompt[key] = run;
Enquirer[key] = run;
if (!Enquirer[name]) {
Reflect.defineProperty(Enquirer, name, { get: () => prompts[name] });
}
}
const define = name => {
utils.defineExport(Enquirer, name, () => Enquirer.types[name]);
};
define('ArrayPrompt');
define('AuthPrompt');
define('BooleanPrompt');
define('NumberPrompt');
define('StringPrompt');
module.exports = Enquirer;
-112
View File
@@ -1,112 +0,0 @@
{
"name": "enquirer",
"description": "Stylish, intuitive and user-friendly prompt system. Fast and lightweight enough for small projects, powerful and extensible enough for the most advanced use cases.",
"version": "2.4.1",
"homepage": "https://github.com/enquirer/enquirer",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Brian Woodward (https://twitter.com/doowb)",
"Jon Schlinkert (http://twitter.com/jonschlinkert)"
],
"repository": "enquirer/enquirer",
"bugs": {
"url": "https://github.com/enquirer/enquirer/issues"
},
"license": "MIT",
"files": [
"index.js",
"index.d.ts",
"lib"
],
"main": "index.js",
"engines": {
"node": ">=8.6"
},
"scripts": {
"test": "mocha && tsc -p ./test/types",
"cover": "nyc --reporter=text --reporter=html mocha"
},
"dependencies": {
"ansi-colors": "^4.1.1",
"strip-ansi": "^6.0.1"
},
"devDependencies": {
"@types/node": "^8",
"gulp-format-md": "^2.0.0",
"inquirer": "^6.2.0",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"prompts": "^1.2.1",
"time-require": "github:jonschlinkert/time-require",
"typescript": "^3.1.6"
},
"keywords": [
"answer",
"answers",
"ask",
"base",
"cli",
"command",
"command-line",
"confirm",
"enquirer",
"generator",
"generate",
"hyper",
"input",
"inquire",
"inquirer",
"interface",
"iterm",
"javascript",
"node",
"nodejs",
"prompt",
"prompts",
"promptly",
"question",
"readline",
"scaffold",
"scaffolding",
"scaffolder",
"stdin",
"stdout",
"terminal",
"tty",
"ui",
"yeoman",
"yo",
"zsh"
],
"lintDeps": {
"devDependencies": {
"files": {
"patterns": [
"examples/**/*.js",
"perf/*.js",
"recipes/*.js"
]
}
}
},
"verb": {
"toc": false,
"layout": false,
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"helpers": [
"./docs/helpers.js"
],
"lint": {
"reflinks": true
},
"reflinks": [
"inquirer",
"prompt-skeleton"
]
}
}