scenv-inquirer 0.3.2 → 0.4.0
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/README.md +5 -15
- package/dist/index.cjs +3 -66
- package/dist/index.d.cts +26 -23
- package/dist/index.d.ts +26 -23
- package/dist/index.js +3 -64
- package/package.json +9 -12
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# scenv-inquirer
|
|
2
2
|
|
|
3
|
-
Inquirer-based prompts for [scenv](https://www.npmjs.com/package/scenv): variable prompts and
|
|
3
|
+
Inquirer-based prompts for [scenv](https://www.npmjs.com/package/scenv): variable prompts (and optional default prompt callback).
|
|
4
4
|
|
|
5
|
-
Use with scenv when you want interactive prompts for variable values
|
|
5
|
+
Use with scenv when you want interactive prompts for variable values. Saving is controlled by scenv's `saveContextTo` config (path or context name); there are no "save?" or "which context?" callbacks in scenv.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -45,11 +45,7 @@ configure({ callbacks: { defaultPrompt: prompt() } });
|
|
|
45
45
|
|
|
46
46
|
Variable-level `prompt` overrides this default.
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`askSaveAfterPrompt()` and `askContext()` return functions for scenv's `onAskSaveAfterPrompt` and `onAskContext` callbacks. Use them when `SCENV_SAVE_PROMPT=ask` or `saveContextTo: "ask"`.
|
|
51
|
-
|
|
52
|
-
**`callbacks()`** wires all of the above in one go:
|
|
48
|
+
**`callbacks()`** returns an object you can pass to `configure()` so all variables use inquirer when they need a value:
|
|
53
49
|
|
|
54
50
|
```ts
|
|
55
51
|
import { configure } from "scenv";
|
|
@@ -60,20 +56,14 @@ configure(callbacks());
|
|
|
60
56
|
configure({ ...yourConfig, ...callbacks() });
|
|
61
57
|
```
|
|
62
58
|
|
|
63
|
-
This sets
|
|
64
|
-
|
|
65
|
-
- **defaultPrompt** – inquirer for variable values when no value is resolved
|
|
66
|
-
- **onAskSaveAfterPrompt** – "Save '{name}' for next time?" then "Which context?"
|
|
67
|
-
- **onAskContext** – "Save to which context?" (list or new)
|
|
59
|
+
This sets **defaultPrompt** so variable values are prompted via inquirer when no value is resolved from set/env/context.
|
|
68
60
|
|
|
69
61
|
## API
|
|
70
62
|
|
|
71
63
|
| Export | Description |
|
|
72
64
|
|--------|-------------|
|
|
73
65
|
| `prompt()` | Returns `(name, defaultValue) => Promise<T>` for use as variable `prompt` or `callbacks.defaultPrompt`. |
|
|
74
|
-
| `
|
|
75
|
-
| `askContext()` | Returns `onAskContext`: asks which context to save to. |
|
|
76
|
-
| `callbacks()` | Returns `{ callbacks: { defaultPrompt, onAskSaveAfterPrompt, onAskContext } }`. |
|
|
66
|
+
| `callbacks()` | Returns `{ callbacks: { defaultPrompt } }` for use with `configure()`. |
|
|
77
67
|
|
|
78
68
|
## License
|
|
79
69
|
|
package/dist/index.cjs
CHANGED
|
@@ -30,15 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
askContext: () => askContext,
|
|
34
|
-
askSaveAfterPrompt: () => askSaveAfterPrompt,
|
|
35
33
|
callbacks: () => callbacks,
|
|
36
34
|
prompt: () => prompt
|
|
37
35
|
});
|
|
38
36
|
module.exports = __toCommonJS(index_exports);
|
|
39
37
|
var import_inquirer = __toESM(require("inquirer"), 1);
|
|
40
38
|
function prompt() {
|
|
41
|
-
return async (name, defaultValue) => {
|
|
39
|
+
return (async (name, defaultValue) => {
|
|
42
40
|
const defaultStr = defaultValue !== void 0 && defaultValue !== null ? String(defaultValue) : "";
|
|
43
41
|
const { value } = await import_inquirer.default.prompt([
|
|
44
42
|
{
|
|
@@ -49,74 +47,13 @@ function prompt() {
|
|
|
49
47
|
}
|
|
50
48
|
]);
|
|
51
49
|
return value;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function askSaveAfterPrompt() {
|
|
55
|
-
return async (name, _value, contextNames) => {
|
|
56
|
-
const { save } = await import_inquirer.default.prompt([
|
|
57
|
-
{
|
|
58
|
-
type: "confirm",
|
|
59
|
-
name: "save",
|
|
60
|
-
message: `Save "${name}" for next time?`,
|
|
61
|
-
default: true
|
|
62
|
-
}
|
|
63
|
-
]);
|
|
64
|
-
if (!save) return null;
|
|
65
|
-
const choices = [...contextNames];
|
|
66
|
-
if (choices.length === 0) choices.push("default");
|
|
67
|
-
choices.push("(new context)");
|
|
68
|
-
const { context } = await import_inquirer.default.prompt([
|
|
69
|
-
{
|
|
70
|
-
type: "list",
|
|
71
|
-
name: "context",
|
|
72
|
-
message: "Which context?",
|
|
73
|
-
choices
|
|
74
|
-
}
|
|
75
|
-
]);
|
|
76
|
-
if (context === "(new context)") {
|
|
77
|
-
const { newContext } = await import_inquirer.default.prompt([
|
|
78
|
-
{ type: "input", name: "newContext", message: "Context name:", default: "default" }
|
|
79
|
-
]);
|
|
80
|
-
return newContext.trim() || "default";
|
|
81
|
-
}
|
|
82
|
-
return context;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function askContext() {
|
|
86
|
-
return async (name, contextNames) => {
|
|
87
|
-
const choices = [...contextNames];
|
|
88
|
-
if (choices.length === 0) choices.push("default");
|
|
89
|
-
choices.push("(new context)");
|
|
90
|
-
const { context } = await import_inquirer.default.prompt([
|
|
91
|
-
{
|
|
92
|
-
type: "list",
|
|
93
|
-
name: "context",
|
|
94
|
-
message: `Save "${name}" to which context?`,
|
|
95
|
-
choices
|
|
96
|
-
}
|
|
97
|
-
]);
|
|
98
|
-
if (context === "(new context)") {
|
|
99
|
-
const { newContext } = await import_inquirer.default.prompt([
|
|
100
|
-
{ type: "input", name: "newContext", message: "Context name:", default: "default" }
|
|
101
|
-
]);
|
|
102
|
-
return newContext.trim() || "default";
|
|
103
|
-
}
|
|
104
|
-
return context;
|
|
105
|
-
};
|
|
50
|
+
});
|
|
106
51
|
}
|
|
107
52
|
function callbacks() {
|
|
108
|
-
return {
|
|
109
|
-
callbacks: {
|
|
110
|
-
defaultPrompt: prompt(),
|
|
111
|
-
onAskSaveAfterPrompt: askSaveAfterPrompt(),
|
|
112
|
-
onAskContext: askContext()
|
|
113
|
-
}
|
|
114
|
-
};
|
|
53
|
+
return { callbacks: { defaultPrompt: prompt() } };
|
|
115
54
|
}
|
|
116
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
117
56
|
0 && (module.exports = {
|
|
118
|
-
askContext,
|
|
119
|
-
askSaveAfterPrompt,
|
|
120
57
|
callbacks,
|
|
121
58
|
prompt
|
|
122
59
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
+
import { ScenvCallbacks, DefaultPromptFn } from 'scenv';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Returns
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Returns a function suitable for scenv's onAskContext callback.
|
|
15
|
-
* Asks user to choose a context from contextNames or enter a new one.
|
|
4
|
+
* Returns an inquirer-based prompt function for use with scenv variables. Use as the
|
|
5
|
+
* variable's `prompt` option or as `callbacks.defaultPrompt`. Scenv calls it with the
|
|
6
|
+
* variable name and default value when prompting; this shows an inquirer input prompt.
|
|
7
|
+
* Returned value is a string; use a validator (e.g. scenv-zod) for type coercion.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - Value type (default string). Cast or validate in your validator.
|
|
10
|
+
* @returns A function `(name, defaultValue) => Promise<T>` suitable for scenv's prompt or defaultPrompt.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const apiUrl = scenv("API URL", { default: "http://localhost:4000", prompt: prompt() });
|
|
14
|
+
* const url = await apiUrl.get(); // prompts via inquirer if no env/context
|
|
16
15
|
*/
|
|
17
|
-
declare function
|
|
16
|
+
declare function prompt<T = string>(): DefaultPromptFn;
|
|
18
17
|
/**
|
|
19
|
-
* Returns an object
|
|
20
|
-
*
|
|
18
|
+
* Returns an object with the defaultPrompt callback for scenv. Pass to {@link configure}
|
|
19
|
+
* to use inquirer for variable prompts. Variable-level `prompt` overrides defaultPrompt.
|
|
20
|
+
*
|
|
21
|
+
* @returns `{ callbacks: { defaultPrompt } }` – spread into configure() or merge with other config.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { configure } from "scenv";
|
|
25
|
+
* import { callbacks } from "scenv-inquirer";
|
|
26
|
+
* configure(callbacks());
|
|
27
|
+
* // or: configure({ ...parseScenvArgs(process.argv.slice(2)), ...callbacks() });
|
|
21
28
|
*/
|
|
22
29
|
declare function callbacks(): {
|
|
23
|
-
callbacks:
|
|
24
|
-
defaultPrompt: ReturnType<typeof prompt>;
|
|
25
|
-
onAskSaveAfterPrompt: ReturnType<typeof askSaveAfterPrompt>;
|
|
26
|
-
onAskContext: ReturnType<typeof askContext>;
|
|
27
|
-
};
|
|
30
|
+
callbacks: ScenvCallbacks;
|
|
28
31
|
};
|
|
29
32
|
|
|
30
|
-
export {
|
|
33
|
+
export { callbacks, prompt };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
+
import { ScenvCallbacks, DefaultPromptFn } from 'scenv';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Returns
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Returns a function suitable for scenv's onAskContext callback.
|
|
15
|
-
* Asks user to choose a context from contextNames or enter a new one.
|
|
4
|
+
* Returns an inquirer-based prompt function for use with scenv variables. Use as the
|
|
5
|
+
* variable's `prompt` option or as `callbacks.defaultPrompt`. Scenv calls it with the
|
|
6
|
+
* variable name and default value when prompting; this shows an inquirer input prompt.
|
|
7
|
+
* Returned value is a string; use a validator (e.g. scenv-zod) for type coercion.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - Value type (default string). Cast or validate in your validator.
|
|
10
|
+
* @returns A function `(name, defaultValue) => Promise<T>` suitable for scenv's prompt or defaultPrompt.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const apiUrl = scenv("API URL", { default: "http://localhost:4000", prompt: prompt() });
|
|
14
|
+
* const url = await apiUrl.get(); // prompts via inquirer if no env/context
|
|
16
15
|
*/
|
|
17
|
-
declare function
|
|
16
|
+
declare function prompt<T = string>(): DefaultPromptFn;
|
|
18
17
|
/**
|
|
19
|
-
* Returns an object
|
|
20
|
-
*
|
|
18
|
+
* Returns an object with the defaultPrompt callback for scenv. Pass to {@link configure}
|
|
19
|
+
* to use inquirer for variable prompts. Variable-level `prompt` overrides defaultPrompt.
|
|
20
|
+
*
|
|
21
|
+
* @returns `{ callbacks: { defaultPrompt } }` – spread into configure() or merge with other config.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { configure } from "scenv";
|
|
25
|
+
* import { callbacks } from "scenv-inquirer";
|
|
26
|
+
* configure(callbacks());
|
|
27
|
+
* // or: configure({ ...parseScenvArgs(process.argv.slice(2)), ...callbacks() });
|
|
21
28
|
*/
|
|
22
29
|
declare function callbacks(): {
|
|
23
|
-
callbacks:
|
|
24
|
-
defaultPrompt: ReturnType<typeof prompt>;
|
|
25
|
-
onAskSaveAfterPrompt: ReturnType<typeof askSaveAfterPrompt>;
|
|
26
|
-
onAskContext: ReturnType<typeof askContext>;
|
|
27
|
-
};
|
|
30
|
+
callbacks: ScenvCallbacks;
|
|
28
31
|
};
|
|
29
32
|
|
|
30
|
-
export {
|
|
33
|
+
export { callbacks, prompt };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
3
|
function prompt() {
|
|
4
|
-
return async (name, defaultValue) => {
|
|
4
|
+
return (async (name, defaultValue) => {
|
|
5
5
|
const defaultStr = defaultValue !== void 0 && defaultValue !== null ? String(defaultValue) : "";
|
|
6
6
|
const { value } = await inquirer.prompt([
|
|
7
7
|
{
|
|
@@ -12,73 +12,12 @@ function prompt() {
|
|
|
12
12
|
}
|
|
13
13
|
]);
|
|
14
14
|
return value;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function askSaveAfterPrompt() {
|
|
18
|
-
return async (name, _value, contextNames) => {
|
|
19
|
-
const { save } = await inquirer.prompt([
|
|
20
|
-
{
|
|
21
|
-
type: "confirm",
|
|
22
|
-
name: "save",
|
|
23
|
-
message: `Save "${name}" for next time?`,
|
|
24
|
-
default: true
|
|
25
|
-
}
|
|
26
|
-
]);
|
|
27
|
-
if (!save) return null;
|
|
28
|
-
const choices = [...contextNames];
|
|
29
|
-
if (choices.length === 0) choices.push("default");
|
|
30
|
-
choices.push("(new context)");
|
|
31
|
-
const { context } = await inquirer.prompt([
|
|
32
|
-
{
|
|
33
|
-
type: "list",
|
|
34
|
-
name: "context",
|
|
35
|
-
message: "Which context?",
|
|
36
|
-
choices
|
|
37
|
-
}
|
|
38
|
-
]);
|
|
39
|
-
if (context === "(new context)") {
|
|
40
|
-
const { newContext } = await inquirer.prompt([
|
|
41
|
-
{ type: "input", name: "newContext", message: "Context name:", default: "default" }
|
|
42
|
-
]);
|
|
43
|
-
return newContext.trim() || "default";
|
|
44
|
-
}
|
|
45
|
-
return context;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function askContext() {
|
|
49
|
-
return async (name, contextNames) => {
|
|
50
|
-
const choices = [...contextNames];
|
|
51
|
-
if (choices.length === 0) choices.push("default");
|
|
52
|
-
choices.push("(new context)");
|
|
53
|
-
const { context } = await inquirer.prompt([
|
|
54
|
-
{
|
|
55
|
-
type: "list",
|
|
56
|
-
name: "context",
|
|
57
|
-
message: `Save "${name}" to which context?`,
|
|
58
|
-
choices
|
|
59
|
-
}
|
|
60
|
-
]);
|
|
61
|
-
if (context === "(new context)") {
|
|
62
|
-
const { newContext } = await inquirer.prompt([
|
|
63
|
-
{ type: "input", name: "newContext", message: "Context name:", default: "default" }
|
|
64
|
-
]);
|
|
65
|
-
return newContext.trim() || "default";
|
|
66
|
-
}
|
|
67
|
-
return context;
|
|
68
|
-
};
|
|
15
|
+
});
|
|
69
16
|
}
|
|
70
17
|
function callbacks() {
|
|
71
|
-
return {
|
|
72
|
-
callbacks: {
|
|
73
|
-
defaultPrompt: prompt(),
|
|
74
|
-
onAskSaveAfterPrompt: askSaveAfterPrompt(),
|
|
75
|
-
onAskContext: askContext()
|
|
76
|
-
}
|
|
77
|
-
};
|
|
18
|
+
return { callbacks: { defaultPrompt: prompt() } };
|
|
78
19
|
}
|
|
79
20
|
export {
|
|
80
|
-
askContext,
|
|
81
|
-
askSaveAfterPrompt,
|
|
82
21
|
callbacks,
|
|
83
22
|
prompt
|
|
84
23
|
};
|
package/package.json
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scenv-inquirer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Inquirer prompt for scenv variables",
|
|
5
|
-
"repository": {
|
|
6
|
-
"publishConfig": {
|
|
5
|
+
"repository": {"type": "git", "url": "https://github.com/PKWadsy/scenv"},
|
|
6
|
+
"publishConfig": {"access": "public", "provenance": true},
|
|
7
7
|
"keywords": ["scenv", "inquirer", "prompt"],
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "dist/index.cjs",
|
|
10
10
|
"module": "dist/index.js",
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"import": "./dist/index.js",
|
|
15
|
-
"require": "./dist/index.cjs",
|
|
16
|
-
"types": "./dist/index.d.ts"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
12
|
+
"exports": {".": {"import": "./dist/index.js", "require": "./dist/index.cjs", "types": "./dist/index.d.ts"}},
|
|
19
13
|
"files": ["dist"],
|
|
20
14
|
"scripts": {
|
|
21
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --clean"
|
|
15
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest"
|
|
22
18
|
},
|
|
23
19
|
"peerDependencies": {
|
|
24
20
|
"inquirer": "^8.0.0 || ^9.0.0",
|
|
@@ -29,6 +25,7 @@
|
|
|
29
25
|
"inquirer": "^9.2.0",
|
|
30
26
|
"scenv": "workspace:*",
|
|
31
27
|
"tsup": "^8.0.0",
|
|
32
|
-
"typescript": "^5.3.0"
|
|
28
|
+
"typescript": "^5.3.0",
|
|
29
|
+
"vitest": "^2.0.0"
|
|
33
30
|
}
|
|
34
31
|
}
|