@trenskow/reader 0.1.58 → 0.1.60
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/lib/interview.js +38 -18
- package/package.json +5 -4
package/lib/interview.js
CHANGED
|
@@ -6,31 +6,51 @@
|
|
|
6
6
|
// See license in LICENSE.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
import { default as isvalid, plugins, formalize, keyPaths } from 'isvalid';
|
|
10
|
-
import keyd from 'keyd';
|
|
11
9
|
import print from '@trenskow/print';
|
|
10
|
+
import keyd from 'keyd';
|
|
11
|
+
import Puqeue from 'puqeue';
|
|
12
12
|
|
|
13
13
|
import question from './question.js';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const queue = new Puqeue();
|
|
16
|
+
|
|
17
|
+
let _isvalid;
|
|
18
|
+
|
|
19
|
+
const isvalid = async () => {
|
|
20
|
+
return await queue.add(async () => {
|
|
21
|
+
|
|
22
|
+
if (typeof globalThis.isvalid === 'undefined') {
|
|
23
|
+
globalThis.isvalid = (await import('isvalid')).default;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof _isvalid === 'undefined') {
|
|
27
|
+
_isvalid = globalThis.isvalid;
|
|
28
|
+
_isvalid.plugins.use('readerInterview', () => ({
|
|
29
|
+
phase: 'pre',
|
|
30
|
+
supportsType: () => true,
|
|
31
|
+
validatorsForType: () => ({
|
|
32
|
+
label: ['string'],
|
|
33
|
+
description: ['string'],
|
|
34
|
+
silent: ['boolean']
|
|
35
|
+
}),
|
|
36
|
+
validate: (data) => data,
|
|
37
|
+
formalize: (schema) => schema
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return _isvalid;
|
|
43
|
+
|
|
44
|
+
});
|
|
45
|
+
};
|
|
26
46
|
|
|
27
47
|
const interview = async (schema, { spacing = 0, input = process.stdin, output = process.stdout, strings = {} } = {}) => {
|
|
28
48
|
|
|
29
|
-
schema = formalize(schema);
|
|
49
|
+
schema = (await isvalid()).formalize(schema);
|
|
30
50
|
|
|
31
51
|
if (schema.type === Object) {
|
|
32
52
|
|
|
33
|
-
const allKeyPaths = keyPaths(schema)
|
|
53
|
+
const allKeyPaths = (await isvalid()).keyPaths(schema)
|
|
34
54
|
.all({ maxDepth: 1 })
|
|
35
55
|
.filter((keyPath) => keyPath);
|
|
36
56
|
|
|
@@ -40,7 +60,7 @@ const interview = async (schema, { spacing = 0, input = process.stdin, output =
|
|
|
40
60
|
|
|
41
61
|
const keyPath = allKeyPaths[idx];
|
|
42
62
|
|
|
43
|
-
keyd(result).set(keyPath, await interview(keyPaths(schema).get(keyPath), { spacing, strings }));
|
|
63
|
+
keyd(result).set(keyPath, await interview((await isvalid()).keyPaths(schema).get(keyPath), { spacing, strings }));
|
|
44
64
|
|
|
45
65
|
if (idx < allKeyPaths.length - 1) {
|
|
46
66
|
for (let i = 0; i < spacing; i++) {
|
|
@@ -50,7 +70,7 @@ const interview = async (schema, { spacing = 0, input = process.stdin, output =
|
|
|
50
70
|
|
|
51
71
|
}
|
|
52
72
|
|
|
53
|
-
return await isvalid(result, schema);
|
|
73
|
+
return await (await isvalid())(result, schema);
|
|
54
74
|
|
|
55
75
|
}
|
|
56
76
|
|
|
@@ -84,7 +104,7 @@ const interview = async (schema, { spacing = 0, input = process.stdin, output =
|
|
|
84
104
|
print.tty.nn('\x1b[0m');
|
|
85
105
|
}
|
|
86
106
|
|
|
87
|
-
return await isvalid(await question(`${schema.label}${schema.required ? ` ${strings?.required || '(required)'}` : ''}: `, {
|
|
107
|
+
return await (await isvalid())(await question(`${schema.label}${schema.required ? ` ${strings?.required || '(required)'}` : ''}: `, {
|
|
88
108
|
defaultValue: schema.default,
|
|
89
109
|
input,
|
|
90
110
|
output,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trenskow/reader",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "A simple package to ask questions of a stream.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,12 +27,13 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@eslint/eslintrc": "^3.3.3",
|
|
29
29
|
"@eslint/js": "^9.17.0",
|
|
30
|
-
"eslint": "^9.39.
|
|
30
|
+
"eslint": "^9.39.2",
|
|
31
31
|
"globals": "^16.5.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@trenskow/print": "^0.1.
|
|
34
|
+
"@trenskow/print": "^0.1.36",
|
|
35
35
|
"isvalid": "^4.2.12",
|
|
36
|
-
"keyd": "^2.1.
|
|
36
|
+
"keyd": "^2.1.42",
|
|
37
|
+
"puqeue": "^1.1.24"
|
|
37
38
|
}
|
|
38
39
|
}
|