-
-
Notifications
You must be signed in to change notification settings - Fork 205
chore(deps): replace inquirer with @inquirer/select
#1136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1cc99a9
chore(deps): replace inquirer with `@inquirer/select`
ikeyan 5d4daeb
chore(deps): downgrade @inquirer/select to ^1.3.3
ikeyan 5244f82
chore: fix unit test version-manager.controller.spec.ts
ikeyan 2d55f90
Merge branch 'master' into inquirer-select
wing328 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,58 @@ | ||
| // import ora from 'ora' | ||
| import {Injectable} from '@nestjs/common'; | ||
| import {prompt, Separator} from 'inquirer'; | ||
| import {getTable} from 'console.table' | ||
| import { Injectable } from '@nestjs/common'; | ||
| import select, { Separator } from '@inquirer/select'; | ||
| import { getTable } from 'console.table'; | ||
| import { styleText } from 'util'; | ||
|
|
||
| @Injectable() | ||
| export class UIService { | ||
|
|
||
| public async table<T>(config: { | ||
| name: string, | ||
| message: string, | ||
| printColNum?: boolean, | ||
| rows: Array<{ row: Record<string, unknown>, short: string, value: T }>, | ||
| message: string; | ||
| printColNum?: boolean; | ||
| rows: Array<{ row: Record<string, string>; short: string; value: T }>; | ||
| }): Promise<T> { | ||
|
|
||
|
|
||
| const table = getTable(config.rows.map(({row}, index: number) => { | ||
| return config.printColNum === false ? row : ({'#': index + 1, ...row}); | ||
| })) | ||
|
|
||
| const [header, separator, ...rows] = table.trim().split('\n') | ||
| const table: string = getTable( | ||
| config.rows.map(({ row }, index: number) => { | ||
| return config.printColNum === false ? row : { '#': index + 1, ...row }; | ||
| }), | ||
| ); | ||
|
|
||
| const [header, separator, ...rows] = table.trim().split('\n'); | ||
| const dim = (text: string) => styleText('dim', text); | ||
| return this.list({ | ||
| name: config.name, | ||
| message: config.message, | ||
| choices: [ | ||
| new Separator(header), | ||
| new Separator(separator), | ||
| ...rows.map((name: string, index: number) => ({ | ||
| new Separator(dim(header)), | ||
| new Separator(dim(separator)), | ||
| ...rows.map((name, index) => ({ | ||
| name, | ||
| short: config.rows[index].short, | ||
| value: config.rows[index].value, | ||
| })), | ||
| new Separator(separator), | ||
| new Separator(' '.repeat(separator.length)), | ||
| new Separator(dim(separator)), | ||
| new Separator(dim(' '.repeat(separator.length))), | ||
| ], | ||
| }) | ||
| }); | ||
| } | ||
|
|
||
| public async list<T>(config: { | ||
| name: string, | ||
| message: string, | ||
| choices: Array<{ name: Record<string, unknown>, short?: string, value: T }>, | ||
| message: string; | ||
| choices: Array<{ name: string; short?: string; value: T } | Separator>; | ||
| }): Promise<T> { | ||
|
|
||
| const separatorCount = config | ||
| .choices | ||
| .filter((c) => c instanceof Separator) | ||
| .length | ||
|
|
||
| const res = await prompt([{ | ||
| type: 'list', | ||
| name: config.name, | ||
| pageSize: process.stdout.rows - separatorCount - 1, | ||
| message: config.message, | ||
| choices: config.choices, | ||
| }]) | ||
|
|
||
| return res[config.name] as T | ||
|
|
||
| const pageSize = Math.max(1, process.stdout.rows - 3); | ||
| try { | ||
| const res = await select({ | ||
| pageSize, | ||
| message: config.message, | ||
| choices: config.choices, | ||
| }); | ||
|
|
||
| return res; | ||
| } catch (err) { | ||
| if (err instanceof Error && err.name === 'ExitPromptError') { | ||
| process.exit(0); | ||
| } | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.