@inquirer/demo 0.9.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/demos/checkbox.d.ts +2 -0
- package/dist/esm/demos/checkbox.js +60 -0
- package/dist/esm/demos/confirm.d.ts +2 -0
- package/dist/esm/demos/confirm.js +24 -0
- package/dist/esm/demos/editor.d.ts +2 -0
- package/dist/esm/demos/editor.js +25 -0
- package/dist/esm/demos/expand.d.ts +2 -0
- package/dist/esm/demos/expand.js +92 -0
- package/dist/esm/demos/input.d.ts +2 -0
- package/dist/esm/demos/input.js +36 -0
- package/dist/esm/demos/loader.d.ts +2 -0
- package/dist/esm/demos/loader.js +21 -0
- package/dist/esm/demos/number.d.ts +2 -0
- package/dist/esm/demos/number.js +23 -0
- package/dist/esm/demos/password.d.ts +2 -0
- package/dist/esm/demos/password.js +18 -0
- package/dist/esm/demos/rawlist.d.ts +2 -0
- package/dist/esm/demos/rawlist.js +62 -0
- package/dist/esm/demos/search.d.ts +2 -0
- package/dist/esm/demos/search.js +72 -0
- package/dist/esm/demos/select.d.ts +2 -0
- package/dist/esm/demos/select.js +76 -0
- package/dist/esm/demos/timeout.d.ts +2 -0
- package/dist/esm/demos/timeout.js +18 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +85 -0
- package/dist/esm/package.json +3 -0
- package/package.json +55 -24
- package/demos/checkbox.mjs +0 -65
- package/demos/confirm.mjs +0 -42
- package/demos/editor.mjs +0 -36
- package/demos/expand.mjs +0 -98
- package/demos/input.mjs +0 -48
- package/demos/loader.mjs +0 -27
- package/demos/number.mjs +0 -37
- package/demos/password.mjs +0 -28
- package/demos/rawlist.mjs +0 -67
- package/demos/search.mjs +0 -91
- package/demos/select.mjs +0 -83
- package/demos/timeout.mjs +0 -25
- package/index.mjs +0 -96
package/package.json
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/demo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"engines": {
|
|
5
|
-
"node": ">=18"
|
|
6
|
-
},
|
|
7
|
-
"type": "module",
|
|
3
|
+
"version": "1.0.1",
|
|
8
4
|
"description": "Inquirer demos",
|
|
9
|
-
"main": "index.mjs",
|
|
10
|
-
"bin": {
|
|
11
|
-
"inquirer-demo": "index.mjs"
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"index.mjs",
|
|
15
|
-
"demos/"
|
|
16
|
-
],
|
|
17
|
-
"repository": {
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
20
|
-
},
|
|
21
5
|
"keywords": [
|
|
22
6
|
"answer",
|
|
23
7
|
"answers",
|
|
@@ -57,18 +41,65 @@
|
|
|
57
41
|
"yo",
|
|
58
42
|
"zsh"
|
|
59
43
|
],
|
|
60
|
-
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
|
61
|
-
"license": "MIT",
|
|
62
44
|
"homepage": "https://github.com/SBoudrias/Inquirer.js",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
48
|
+
},
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
|
51
|
+
"sideEffects": false,
|
|
52
|
+
"type": "module",
|
|
53
|
+
"exports": {
|
|
54
|
+
"./package.json": "./package.json",
|
|
55
|
+
".": {
|
|
56
|
+
"import": {
|
|
57
|
+
"types": "./dist/esm/index.d.ts",
|
|
58
|
+
"default": "./dist/esm/index.js"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"module": "./dist/esm/index.js",
|
|
63
|
+
"bin": {
|
|
64
|
+
"inquirer-demo": "./dist/esm/index.js"
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
"dist"
|
|
68
|
+
],
|
|
69
|
+
"scripts": {
|
|
70
|
+
"tsc": "tshy"
|
|
71
|
+
},
|
|
63
72
|
"dependencies": {
|
|
64
|
-
"@inquirer/core": "^
|
|
65
|
-
"@inquirer/figures": "^1.0.
|
|
66
|
-
"@inquirer/prompts": "^
|
|
73
|
+
"@inquirer/core": "^10.0.1",
|
|
74
|
+
"@inquirer/figures": "^1.0.7",
|
|
75
|
+
"@inquirer/prompts": "^7.0.1",
|
|
67
76
|
"yoctocolors-cjs": "^2.1.2"
|
|
68
77
|
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@repo/tsconfig": "workspace:*",
|
|
80
|
+
"@types/node": "^22.8.0",
|
|
81
|
+
"tshy": "^3.0.2"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">=18"
|
|
85
|
+
},
|
|
69
86
|
"publishConfig": {
|
|
70
87
|
"access": "public"
|
|
71
88
|
},
|
|
72
|
-
"
|
|
73
|
-
|
|
89
|
+
"tshy": {
|
|
90
|
+
"dialects": [
|
|
91
|
+
"esm"
|
|
92
|
+
],
|
|
93
|
+
"exclude": [
|
|
94
|
+
"src/**/*.test.ts"
|
|
95
|
+
],
|
|
96
|
+
"exports": {
|
|
97
|
+
"./package.json": "./package.json",
|
|
98
|
+
".": "./src/index.ts"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"peerDependencies": {
|
|
102
|
+
"@types/node": ">=18"
|
|
103
|
+
},
|
|
104
|
+
"gitHead": "da3dd749325495266025f2dbdb339a812da468f8"
|
|
74
105
|
}
|
package/demos/checkbox.mjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { checkbox, Separator } from '@inquirer/prompts';
|
|
3
|
-
|
|
4
|
-
const demo = async () => {
|
|
5
|
-
let answer;
|
|
6
|
-
|
|
7
|
-
answer = await checkbox({
|
|
8
|
-
message: 'Select a package manager',
|
|
9
|
-
choices: [
|
|
10
|
-
{ name: 'npm', value: 'npm' },
|
|
11
|
-
{ name: 'yarn', value: 'yarn' },
|
|
12
|
-
new Separator(),
|
|
13
|
-
{ name: 'jspm', value: 'jspm', disabled: true },
|
|
14
|
-
{
|
|
15
|
-
name: 'pnpm',
|
|
16
|
-
value: 'pnpm',
|
|
17
|
-
disabled: '(pnpm is not available)',
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
});
|
|
21
|
-
console.log('Answer:', answer);
|
|
22
|
-
|
|
23
|
-
answer = await checkbox({
|
|
24
|
-
message: 'Select your favorite letters',
|
|
25
|
-
choices: [
|
|
26
|
-
new Separator('== Alphabet (choices cycle as you scroll through) =='),
|
|
27
|
-
{ value: 'A', checked: true },
|
|
28
|
-
{ value: 'B' },
|
|
29
|
-
{ value: 'C', checked: true },
|
|
30
|
-
{ value: 'D' },
|
|
31
|
-
{ value: 'E' },
|
|
32
|
-
{ value: 'F' },
|
|
33
|
-
{ value: 'G' },
|
|
34
|
-
{ value: 'H' },
|
|
35
|
-
{ value: 'I' },
|
|
36
|
-
{ value: 'J' },
|
|
37
|
-
{ value: 'K' },
|
|
38
|
-
{ value: 'L' },
|
|
39
|
-
{ value: 'M' },
|
|
40
|
-
{ value: 'N' },
|
|
41
|
-
{ value: 'O' },
|
|
42
|
-
{ value: 'P' },
|
|
43
|
-
{ value: 'Q' },
|
|
44
|
-
{ value: 'R' },
|
|
45
|
-
{ value: 'S' },
|
|
46
|
-
{ value: 'T' },
|
|
47
|
-
{ value: 'U' },
|
|
48
|
-
{ value: 'V' },
|
|
49
|
-
{ value: 'W' },
|
|
50
|
-
{ value: 'X' },
|
|
51
|
-
{ value: 'Y' },
|
|
52
|
-
{ value: 'Z' },
|
|
53
|
-
],
|
|
54
|
-
});
|
|
55
|
-
console.log('Answer:', answer);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
if (import.meta.url.startsWith('file:')) {
|
|
59
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
60
|
-
if (process.argv[1] === modulePath) {
|
|
61
|
-
demo();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default demo;
|
package/demos/confirm.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { confirm } from '@inquirer/prompts';
|
|
3
|
-
|
|
4
|
-
const demo = async () => {
|
|
5
|
-
console.log(
|
|
6
|
-
'Answer:',
|
|
7
|
-
await confirm({
|
|
8
|
-
message: 'Confirm?',
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
console.log(
|
|
13
|
-
'Answer:',
|
|
14
|
-
await confirm({
|
|
15
|
-
message: 'Confirm with default to no?',
|
|
16
|
-
default: false,
|
|
17
|
-
}),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
console.log(
|
|
21
|
-
'Answer:',
|
|
22
|
-
await confirm({
|
|
23
|
-
message: 'Confirm with your custom transformer function?',
|
|
24
|
-
transformer: (answer) => (answer ? '👍' : '👎'),
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
console.log('This next prompt will be cleared on exit');
|
|
29
|
-
console.log(
|
|
30
|
-
'Cleared prompt answer:',
|
|
31
|
-
await confirm({ message: 'Confirm?' }, { clearPromptOnDone: true }),
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
if (import.meta.url.startsWith('file:')) {
|
|
36
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
37
|
-
if (process.argv[1] === modulePath) {
|
|
38
|
-
demo();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default demo;
|
package/demos/editor.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { editor } from '@inquirer/prompts';
|
|
3
|
-
|
|
4
|
-
const demo = async () => {
|
|
5
|
-
console.log(
|
|
6
|
-
'Answer:',
|
|
7
|
-
await editor({
|
|
8
|
-
message: 'Please write a short bio of at least 3 lines.',
|
|
9
|
-
validate(text) {
|
|
10
|
-
if (text.trim().split('\n').length < 3) {
|
|
11
|
-
return 'Must be at least 3 lines.';
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return true;
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
console.log(
|
|
20
|
-
'Answer:',
|
|
21
|
-
await editor({
|
|
22
|
-
message: 'Automatically opened editor',
|
|
23
|
-
default: '# This prompt was automatically opened. You can write anything:\n\n',
|
|
24
|
-
waitForUseInput: false,
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
if (import.meta.url.startsWith('file:')) {
|
|
30
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
31
|
-
if (process.argv[1] === modulePath) {
|
|
32
|
-
demo();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default demo;
|
package/demos/expand.mjs
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { expand } from '@inquirer/prompts';
|
|
3
|
-
|
|
4
|
-
const demo = async () => {
|
|
5
|
-
let answer;
|
|
6
|
-
|
|
7
|
-
answer = await expand({
|
|
8
|
-
message: 'Conflict on `file.js`:',
|
|
9
|
-
choices: [
|
|
10
|
-
{
|
|
11
|
-
key: 'y',
|
|
12
|
-
name: 'Overwrite',
|
|
13
|
-
value: 'overwrite',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
key: 'a',
|
|
17
|
-
name: 'Overwrite this one and all next',
|
|
18
|
-
value: 'overwrite_all',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
key: 'd',
|
|
22
|
-
name: 'Show diff',
|
|
23
|
-
value: 'diff',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
key: 'x',
|
|
27
|
-
name: 'Abort',
|
|
28
|
-
value: 'abort',
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
});
|
|
32
|
-
console.log('Answer:', answer);
|
|
33
|
-
|
|
34
|
-
answer = await expand({
|
|
35
|
-
message: '(With default) Conflict on `file.js`:',
|
|
36
|
-
default: 'y',
|
|
37
|
-
choices: [
|
|
38
|
-
{
|
|
39
|
-
key: 'y',
|
|
40
|
-
name: 'Overwrite',
|
|
41
|
-
value: 'overwrite',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
key: 'a',
|
|
45
|
-
name: 'Overwrite this one and all next',
|
|
46
|
-
value: 'overwrite_all',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
key: 'd',
|
|
50
|
-
name: 'Show diff',
|
|
51
|
-
value: 'diff',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
key: 'x',
|
|
55
|
-
name: 'Abort',
|
|
56
|
-
value: 'abort',
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
});
|
|
60
|
-
console.log('Answer:', answer);
|
|
61
|
-
|
|
62
|
-
answer = await expand({
|
|
63
|
-
expanded: true,
|
|
64
|
-
message: '(Auto-expand) Conflict on `file.js`:',
|
|
65
|
-
choices: [
|
|
66
|
-
{
|
|
67
|
-
key: 'y',
|
|
68
|
-
name: 'Overwrite',
|
|
69
|
-
value: 'overwrite',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
key: 'a',
|
|
73
|
-
name: 'Overwrite this one and all next',
|
|
74
|
-
value: 'overwrite_all',
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
key: 'd',
|
|
78
|
-
name: 'Show diff',
|
|
79
|
-
value: 'diff',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
key: 'x',
|
|
83
|
-
name: 'Abort',
|
|
84
|
-
value: 'abort',
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
});
|
|
88
|
-
console.log('Answer:', answer);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
if (import.meta.url.startsWith('file:')) {
|
|
92
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
93
|
-
if (process.argv[1] === modulePath) {
|
|
94
|
-
demo();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export default demo;
|
package/demos/input.mjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import colors from 'yoctocolors-cjs';
|
|
3
|
-
import { input } from '@inquirer/prompts';
|
|
4
|
-
|
|
5
|
-
const hexRegEx = /(\d|[a-f])/gim;
|
|
6
|
-
const isHex = (value) =>
|
|
7
|
-
(value.match(hexRegEx) || []).length === value.length &&
|
|
8
|
-
(value.length === 3 || value.length === 6);
|
|
9
|
-
|
|
10
|
-
const demo = async () => {
|
|
11
|
-
let answer;
|
|
12
|
-
|
|
13
|
-
answer = await input({
|
|
14
|
-
message: "What's your favorite food?",
|
|
15
|
-
default: 'Croissant',
|
|
16
|
-
});
|
|
17
|
-
console.log('Answer:', answer);
|
|
18
|
-
|
|
19
|
-
answer = await input({
|
|
20
|
-
message: 'Enter an hex color?',
|
|
21
|
-
transformer(value = '', { isFinal }) {
|
|
22
|
-
return isFinal ? colors.underline(value) : value;
|
|
23
|
-
},
|
|
24
|
-
validate: (value = '') => isHex(value) || 'Pass a valid hex value',
|
|
25
|
-
});
|
|
26
|
-
console.log('Answer:', answer);
|
|
27
|
-
|
|
28
|
-
answer = await input({
|
|
29
|
-
message: '(Slow validation) provide a number:',
|
|
30
|
-
validate: (value) =>
|
|
31
|
-
new Promise((resolve) => {
|
|
32
|
-
setTimeout(
|
|
33
|
-
() => resolve(!Number.isNaN(Number(value)) || 'You must provide a number'),
|
|
34
|
-
3000,
|
|
35
|
-
);
|
|
36
|
-
}),
|
|
37
|
-
});
|
|
38
|
-
console.log('Answer:', answer);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
if (import.meta.url.startsWith('file:')) {
|
|
42
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
43
|
-
if (process.argv[1] === modulePath) {
|
|
44
|
-
demo();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default demo;
|
package/demos/loader.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { createPrompt, useKeypress, usePrefix, isEnterKey } from '@inquirer/core';
|
|
3
|
-
|
|
4
|
-
const loader = createPrompt((config, done) => {
|
|
5
|
-
const prefix = usePrefix({ status: 'loading' });
|
|
6
|
-
|
|
7
|
-
useKeypress((key) => {
|
|
8
|
-
if (isEnterKey(key)) {
|
|
9
|
-
done();
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return `${prefix} Press enter to exit`;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const demo = async () => {
|
|
17
|
-
await loader({}, { clearPromptOnDone: true });
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
if (import.meta.url.startsWith('file:')) {
|
|
21
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
22
|
-
if (process.argv[1] === modulePath) {
|
|
23
|
-
demo();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default demo;
|
package/demos/number.mjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { number } from '@inquirer/prompts';
|
|
3
|
-
|
|
4
|
-
const demo = async () => {
|
|
5
|
-
console.log(
|
|
6
|
-
'Answer:',
|
|
7
|
-
await number({
|
|
8
|
-
message: 'Enter your age?',
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
console.log(
|
|
13
|
-
'Answer:',
|
|
14
|
-
await number({
|
|
15
|
-
message: 'Enter an integer or a decimal number?',
|
|
16
|
-
step: 'any',
|
|
17
|
-
}),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
console.log(
|
|
21
|
-
'Answer:',
|
|
22
|
-
await number({
|
|
23
|
-
message: 'Enter a number between 5 and 8?',
|
|
24
|
-
min: 5,
|
|
25
|
-
max: 8,
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if (import.meta.url.startsWith('file:')) {
|
|
31
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
32
|
-
if (process.argv[1] === modulePath) {
|
|
33
|
-
demo();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default demo;
|
package/demos/password.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { password } from '@inquirer/prompts';
|
|
3
|
-
|
|
4
|
-
const demo = async () => {
|
|
5
|
-
console.log(
|
|
6
|
-
'Answer:',
|
|
7
|
-
await password({
|
|
8
|
-
message: 'Enter a silent password?',
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
console.log(
|
|
13
|
-
'Answer:',
|
|
14
|
-
await password({
|
|
15
|
-
message: 'Enter a masked password?',
|
|
16
|
-
mask: '*',
|
|
17
|
-
}),
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
if (import.meta.url.startsWith('file:')) {
|
|
22
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
23
|
-
if (process.argv[1] === modulePath) {
|
|
24
|
-
demo();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default demo;
|
package/demos/rawlist.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import * as url from 'node:url';
|
|
2
|
-
import { rawlist, Separator } from '@inquirer/prompts';
|
|
3
|
-
|
|
4
|
-
const demo = async () => {
|
|
5
|
-
let answer;
|
|
6
|
-
|
|
7
|
-
answer = await rawlist({
|
|
8
|
-
message: '(no keys) Conflict on `file.js`:',
|
|
9
|
-
choices: [
|
|
10
|
-
{
|
|
11
|
-
name: 'Overwrite',
|
|
12
|
-
value: 'overwrite',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: 'Overwrite this one and all next',
|
|
16
|
-
value: 'overwrite_all',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: 'Show diff',
|
|
20
|
-
value: 'diff',
|
|
21
|
-
},
|
|
22
|
-
new Separator(),
|
|
23
|
-
{
|
|
24
|
-
name: 'Abort',
|
|
25
|
-
value: 'abort',
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
});
|
|
29
|
-
console.log('Answer:', answer);
|
|
30
|
-
|
|
31
|
-
answer = await rawlist({
|
|
32
|
-
message: '(with keys) Conflict on `file.js`:',
|
|
33
|
-
choices: [
|
|
34
|
-
{
|
|
35
|
-
key: 'y',
|
|
36
|
-
name: 'Overwrite',
|
|
37
|
-
value: 'overwrite',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
key: 'a',
|
|
41
|
-
name: 'Overwrite this one and all next',
|
|
42
|
-
value: 'overwrite_all',
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
key: 'd',
|
|
46
|
-
name: 'Show diff',
|
|
47
|
-
value: 'diff',
|
|
48
|
-
},
|
|
49
|
-
new Separator(),
|
|
50
|
-
{
|
|
51
|
-
key: 'x',
|
|
52
|
-
name: 'Abort',
|
|
53
|
-
value: 'abort',
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
});
|
|
57
|
-
console.log('Answer:', answer);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (import.meta.url.startsWith('file:')) {
|
|
61
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
62
|
-
if (process.argv[1] === modulePath) {
|
|
63
|
-
demo();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default demo;
|
package/demos/search.mjs
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import * as url from 'node:url';
|
|
4
|
-
import { search } from '@inquirer/prompts';
|
|
5
|
-
|
|
6
|
-
async function fileExists(filepath) {
|
|
7
|
-
return fs.access(filepath).then(
|
|
8
|
-
() => true,
|
|
9
|
-
() => false,
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async function isDirectory(path) {
|
|
14
|
-
if (await fileExists(path)) {
|
|
15
|
-
const stats = await fs.stat(path);
|
|
16
|
-
return stats.isDirectory();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const root = path.dirname(path.join(url.fileURLToPath(import.meta.url), '../../..'));
|
|
23
|
-
|
|
24
|
-
const demo = async () => {
|
|
25
|
-
let answer;
|
|
26
|
-
|
|
27
|
-
// Demo: Search results from an API
|
|
28
|
-
answer = await search({
|
|
29
|
-
message: 'Select an npm package',
|
|
30
|
-
source: async (input = 'inquirer', { signal }) => {
|
|
31
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
32
|
-
const response = await fetch(
|
|
33
|
-
`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(input)}&size=20`,
|
|
34
|
-
{ signal },
|
|
35
|
-
);
|
|
36
|
-
const data = await response.json();
|
|
37
|
-
|
|
38
|
-
return data.objects.map((pkg) => ({
|
|
39
|
-
name: pkg.package.name,
|
|
40
|
-
value: pkg.package.name,
|
|
41
|
-
description: pkg.package.description,
|
|
42
|
-
}));
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
console.log('Answer:', answer);
|
|
46
|
-
|
|
47
|
-
// Demo: Using the search prompt as an autocomplete tool.
|
|
48
|
-
answer = await search({
|
|
49
|
-
message: 'Select a file',
|
|
50
|
-
source: async (term = '') => {
|
|
51
|
-
let dirPath = path.join(root, term);
|
|
52
|
-
while (!(await isDirectory(dirPath)) && dirPath !== root) {
|
|
53
|
-
dirPath = path.dirname(dirPath);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const files = await fs.readdir(dirPath, { withFileTypes: true });
|
|
57
|
-
return files
|
|
58
|
-
.sort((a, b) => {
|
|
59
|
-
if (a.isDirectory() === b.isDirectory()) {
|
|
60
|
-
return a.name.localeCompare(b.name);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Sort dir first
|
|
64
|
-
return a.isDirectory() ? -1 : 1;
|
|
65
|
-
})
|
|
66
|
-
.map((file) => ({
|
|
67
|
-
name:
|
|
68
|
-
path.relative(root, path.join(dirPath, file.name)) +
|
|
69
|
-
(file.isDirectory() ? '/' : ''),
|
|
70
|
-
value: path.join(file.parentPath, file.name),
|
|
71
|
-
}))
|
|
72
|
-
.filter(({ value }) => value.includes(term));
|
|
73
|
-
},
|
|
74
|
-
validate: async (filePath) => {
|
|
75
|
-
if (!(await fileExists(filePath)) || (await isDirectory(filePath))) {
|
|
76
|
-
return 'You must select a file';
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
console.log('Answer:', answer);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (import.meta.url.startsWith('file:')) {
|
|
85
|
-
const modulePath = url.fileURLToPath(import.meta.url);
|
|
86
|
-
if (process.argv[1] === modulePath) {
|
|
87
|
-
demo();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default demo;
|