Skip to content

Commit

Permalink
Feat(inquirer): Replace core prompts with the new @inquirer/prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jul 7, 2024
1 parent 6ec598b commit 22ae264
Show file tree
Hide file tree
Showing 73 changed files with 531 additions and 5,372 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
44 changes: 16 additions & 28 deletions packages/inquirer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,25 @@ inquirer
});
```

If you're using Typescript, you'll also want to [add `@types/inquirer`](https://www.npmjs.com/package/@types/inquirer).

<a name="examples"></a>

### Examples (Run it and see it)

Check out the [`packages/inquirer/examples/`](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/inquirer/examples) folder for code and interface examples.

```shell
node packages/inquirer/examples/pizza.js
node packages/inquirer/examples/checkbox.js
yarn node packages/inquirer/examples/pizza.js
yarn node packages/inquirer/examples/checkbox.js
# etc...
```

### Methods

<a name="methods"></a>

> [!WARNING]
> Those interfaces are not necessary for modern Javascript, while still maintained, they're depreciated. We highly encourage you to adopt the more ergonomic and modern API with [@inquirer/prompts](https://www.npmjs.com/package/@inquirer/prompts). Both `inquirer` and `@inquirer/prompts` are usable at the same time, so you can progressively migrate.
#### `inquirer.prompt(questions, answers) -> promise`

Launch the prompt interface (inquiry session)
Expand Down Expand Up @@ -323,29 +324,6 @@ The `postfix` property is useful if you want to provide an extension.

`prompt()` requires that it is run in an interactive environment. (I.e. [One where `process.stdin.isTTY` is `true`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_a_note_on_process_i_o)). If `prompt()` is invoked outside of such an environment, then `prompt()` will return a rejected promise with an error. For convenience, the error will have a `isTtyError` property to programmatically indicate the cause.

## User Interfaces and layouts

Along with the prompts, Inquirer offers some basic text UI.

#### Bottom Bar - `inquirer.ui.BottomBar`

This UI present a fixed text at the bottom of a free text zone. This is useful to keep a message to the bottom of the screen while outputting command outputs on the higher section.

```javascript
const ui = new inquirer.ui.BottomBar();

// pipe a Stream to the log zone
outputStream.pipe(ui.log);

// Or simply write output
ui.log.write('something just happened.');
ui.log.write('Almost over, standby!');

// During processing, update the bottom bar content to display a loader
// or output a progress bar, etc
ui.updateBottomBar('new bottom bar content');
```

<a name="reactive"></a>

## Reactive interface
Expand Down Expand Up @@ -422,7 +400,7 @@ Please refer to the [GitHub releases section for the changelog](https://github.c
<a name="contributing"></a>

**Unit test**
Please add a unit test for every new feature or bug fix. `npm test` to run the test suite.
Please add a unit test for every new feature or bug fix. `yarn test` to run the test suite.

**Documentation**
Add documentation for every API change. Feel free to send typo fixes and better docs!
Expand All @@ -443,6 +421,16 @@ Licensed under the MIT license.

<a name="plugins"></a>

You can build custom prompts, or use open sourced ones. See [`@inquirer/core` documentation for building custom prompts](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/core).

You can either call the custom prompts directly, or you can register them:

```js
import CustomPrompt from '$$$/custom-prompt';

inquirer.registerPrompt('custom', CustomPrompt);
```

### Prompts

[**autocomplete**](https://github.com/mokkabonna/inquirer-autocomplete-prompt)<br>
Expand Down
20 changes: 0 additions & 20 deletions packages/inquirer/examples/bottom-bar.mts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Checkbox list examples
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Editor prompt example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Expand list examples
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Filter and validate progress example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Heirarchical conversation example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const directionsPrompt = {
type: 'list',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Input prompt example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* List prompt example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Paginated list
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const choices = Array.apply(0, Array.from({ length: 26 })).map((x, y) =>
String.fromCodePoint(y + 65),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nested Inquirer call
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

inquirer
.prompt({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Password prompt example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const requireLetterAndNumber = (value) => {
if (/\w/.test(value) && /\d/.test(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* run example by writing `node pizza.mjs` in your console
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

console.log('Hi, welcome to Node Pizza');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Raw List prompt example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Allows user to choose when to exit prompt
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const questions = [
{
Expand All @@ -20,7 +20,7 @@ const questions = [
];

function ask() {
const output: string[] = [];
const output = [];

inquirer.prompt(questions).then((answers) => {
output.push(answers.tvShow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Filter and validate progress example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { from } from 'rxjs';
import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable } from 'rxjs';
import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const observe = new Observable((subscriber) => {
subscriber.next({
Expand Down
File renamed without changes.
35 changes: 0 additions & 35 deletions packages/inquirer/examples/terminal-link.mts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* When example
*/

import inquirer from '../src/index.mjs';
import inquirer from '../dist/esm/index.mjs';

const questions = [
{
Expand Down
33 changes: 16 additions & 17 deletions packages/inquirer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,40 @@
"engines": {
"node": ">=18"
},
"devDependencies": {
"terminal-link": "^3.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/SBoudrias/Inquirer.js.git"
},
"license": "MIT",
"dependencies": {
"@inquirer/figures": "^1.0.3",
"@inquirer/prompts": "^5.1.2",
"@inquirer/type": "^1.3.3",
"@types/mute-stream": "^0.0.4",
"ansi-escapes": "^4.3.2",
"cli-width": "^4.1.0",
"external-editor": "^3.1.0",
"mute-stream": "1.0.0",
"ora": "^5.4.1",
"mute-stream": "^1.0.0",
"run-async": "^3.0.0",
"rxjs": "^7.8.1",
"string-width": "^4.2.3",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^6.2.0",
"yoctocolors-cjs": "^2.1.2"
"rxjs": "^7.8.1"
},
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/inquirer/README.md",
"sideEffects": false,
"scripts": {
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
"tsc:esm": "rm -rf dist/esm && tsc -p ./tsconfig.json",
"tsc:cjs": "rm -rf dist/cjs && tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs",
"dev": "tsc -p ./tsconfig.json --watch"
"dev": "tsc -p ./tsconfig.json --watch",
"attw": "attw --pack"
},
"exports": {
".": {
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.js"
"import": {
"types": "./dist/esm/types/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
}
},
"typings": "./dist/cjs/types/index.d.ts"
}
Loading

0 comments on commit 22ae264

Please sign in to comment.