-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Set demo to only run automatically if they're the entrypoint. …
…Otherwise, export a demo function.
- Loading branch information
Showing
12 changed files
with
252 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as url from 'node:url'; | ||
import { editor } from '@inquirer/prompts'; | ||
|
||
const demo = async () => { | ||
const answer = await editor({ | ||
message: 'Please write a short bio of at least 3 lines.', | ||
validate(text) { | ||
if (text.trim().split('\n').length < 3) { | ||
return 'Must be at least 3 lines.'; | ||
} | ||
|
||
return true; | ||
}, | ||
}); | ||
console.log('Answer:', answer); | ||
}; | ||
|
||
if (import.meta.url.startsWith('file:')) { | ||
const modulePath = url.fileURLToPath(import.meta.url); | ||
if (process.argv[1] === modulePath) { | ||
demo(); | ||
} | ||
} | ||
|
||
export default demo; |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as url from 'node:url'; | ||
import { password } from '@inquirer/prompts'; | ||
|
||
const demo = async () => { | ||
console.log( | ||
'Answer:', | ||
await password({ | ||
message: 'Enter a silent password?', | ||
}) | ||
); | ||
|
||
console.log( | ||
'Answer:', | ||
await password({ | ||
message: 'Enter a masked password?', | ||
mask: '*', | ||
}) | ||
); | ||
}; | ||
|
||
if (import.meta.url.startsWith('file:')) { | ||
const modulePath = url.fileURLToPath(import.meta.url); | ||
if (process.argv[1] === modulePath) { | ||
demo(); | ||
} | ||
} | ||
|
||
export default demo; |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable no-await-in-loop */ | ||
|
||
import { select } from '@inquirer/prompts'; | ||
import checkboxDemo from './demos/checkbox.mjs'; | ||
import confirmDemo from './demos/confirm.mjs'; | ||
import editorDemo from './demos/editor.mjs'; | ||
import expandDemo from './demos/expand.mjs'; | ||
import inputDemo from './demos/input.mjs'; | ||
import passwordDemo from './demos/password.mjs'; | ||
import rawlistDemo from './demos/rawlist.mjs'; | ||
import selectDemo from './demos/select.mjs'; | ||
|
||
const demos = { | ||
checkbox: checkboxDemo, | ||
confirm: confirmDemo, | ||
editor: editorDemo, | ||
expand: expandDemo, | ||
input: inputDemo, | ||
password: passwordDemo, | ||
rawlist: rawlistDemo, | ||
select: selectDemo, | ||
}; | ||
|
||
function askNextDemo() { | ||
return select({ | ||
message: 'Which prompt demo do you want to run?', | ||
choices: [ | ||
{ name: 'Input', value: 'input' }, | ||
{ name: 'Password', value: 'password' }, | ||
{ name: 'Confirm', value: 'confirm' }, | ||
{ name: 'Select', value: 'select' }, | ||
{ name: 'Checkbox', value: 'checkbox' }, | ||
{ name: 'Expand', value: 'expand' }, | ||
{ name: 'Rawlist', value: 'rawlist' }, | ||
{ name: 'Editor', value: 'editor' }, | ||
{ name: "Exit (I'm done)", value: 'exit' }, | ||
], | ||
}); | ||
} | ||
|
||
(async () => { | ||
let nextDemo = await askNextDemo(); | ||
while (nextDemo !== 'exit') { | ||
await demos[nextDemo](); | ||
nextDemo = await askNextDemo(); | ||
} | ||
})(); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"name": "@inquirer/demo", | ||
"version": "0.0.0", | ||
"engines": { | ||
"node": ">=14.18.0" | ||
}, | ||
"type": "module", | ||
"description": "Inquirer demos", | ||
"main": "index.mjs", | ||
"bin": { | ||
"inquirer-demo": "index.mjs" | ||
}, | ||
"files": [ | ||
"index.mjs", | ||
"demos/" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "/~https://github.com/SBoudrias/Inquirer.js.git" | ||
}, | ||
"keywords": [ | ||
"answer", | ||
"answers", | ||
"ask", | ||
"base", | ||
"cli", | ||
"command", | ||
"command-line", | ||
"confirm", | ||
"enquirer", | ||
"generate", | ||
"generator", | ||
"hyper", | ||
"input", | ||
"inquire", | ||
"inquirer", | ||
"interface", | ||
"iterm", | ||
"javascript", | ||
"menu", | ||
"node", | ||
"nodejs", | ||
"prompt", | ||
"promptly", | ||
"prompts", | ||
"question", | ||
"readline", | ||
"scaffold", | ||
"scaffolder", | ||
"scaffolding", | ||
"stdin", | ||
"stdout", | ||
"terminal", | ||
"tty", | ||
"ui", | ||
"yeoman", | ||
"yo", | ||
"zsh" | ||
], | ||
"author": "Simon Boudrias <admin@simonboudrias.com>", | ||
"license": "MIT", | ||
"homepage": "/~https://github.com/SBoudrias/Inquirer.js", | ||
"dependencies": { | ||
"chalk": "^4.1.2", | ||
"@inquirer/prompts": "^1.2.2" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.