scenv-inquirer 0.1.0 → 0.2.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/dist/index.cjs +67 -0
- package/dist/index.d.cts +24 -3
- package/dist/index.d.ts +24 -3
- package/dist/index.js +64 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,9 @@ 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
|
+
callbacks: () => callbacks,
|
|
33
36
|
prompt: () => prompt
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -48,7 +51,71 @@ function prompt() {
|
|
|
48
51
|
return value;
|
|
49
52
|
};
|
|
50
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
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function callbacks() {
|
|
108
|
+
return {
|
|
109
|
+
callbacks: {
|
|
110
|
+
onAskSaveAfterPrompt: askSaveAfterPrompt(),
|
|
111
|
+
onAskContext: askContext()
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
51
115
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
116
|
0 && (module.exports = {
|
|
117
|
+
askContext,
|
|
118
|
+
askSaveAfterPrompt,
|
|
119
|
+
callbacks,
|
|
53
120
|
prompt
|
|
54
121
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns a prompt function for use with
|
|
3
|
-
*
|
|
2
|
+
* Returns a prompt function for use with scenv(): (name, defaultValue) => Promise<T>.
|
|
3
|
+
* Scenv passes the variable name and default (from env/context/default); this uses inquirer to ask for input.
|
|
4
4
|
* Returns string; use a validator (e.g. scenv-zod) for type/coercion.
|
|
5
5
|
*/
|
|
6
6
|
declare function prompt<T = string>(): (name: string, defaultValue: T) => Promise<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a function suitable for scenv's onAskSaveAfterPrompt callback.
|
|
9
|
+
* Asks "Save '{name}' for next time?" and, if yes, "Which context?" (from contextNames or new).
|
|
10
|
+
* @returns Context name to save to, or null to skip saving
|
|
11
|
+
*/
|
|
12
|
+
declare function askSaveAfterPrompt(): (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
|
|
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.
|
|
16
|
+
*/
|
|
17
|
+
declare function askContext(): (name: string, contextNames: string[]) => Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns an object suitable for scenv's configure(): { callbacks: { onAskSaveAfterPrompt, onAskContext } }.
|
|
20
|
+
* Use as configure(callbacks()) or configure({ ...config, ...callbacks() }) to wire both save-after-prompt and ask-context via inquirer.
|
|
21
|
+
*/
|
|
22
|
+
declare function callbacks(): {
|
|
23
|
+
callbacks: {
|
|
24
|
+
onAskSaveAfterPrompt: ReturnType<typeof askSaveAfterPrompt>;
|
|
25
|
+
onAskContext: ReturnType<typeof askContext>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
7
28
|
|
|
8
|
-
export { prompt };
|
|
29
|
+
export { askContext, askSaveAfterPrompt, callbacks, prompt };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns a prompt function for use with
|
|
3
|
-
*
|
|
2
|
+
* Returns a prompt function for use with scenv(): (name, defaultValue) => Promise<T>.
|
|
3
|
+
* Scenv passes the variable name and default (from env/context/default); this uses inquirer to ask for input.
|
|
4
4
|
* Returns string; use a validator (e.g. scenv-zod) for type/coercion.
|
|
5
5
|
*/
|
|
6
6
|
declare function prompt<T = string>(): (name: string, defaultValue: T) => Promise<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a function suitable for scenv's onAskSaveAfterPrompt callback.
|
|
9
|
+
* Asks "Save '{name}' for next time?" and, if yes, "Which context?" (from contextNames or new).
|
|
10
|
+
* @returns Context name to save to, or null to skip saving
|
|
11
|
+
*/
|
|
12
|
+
declare function askSaveAfterPrompt(): (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
|
|
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.
|
|
16
|
+
*/
|
|
17
|
+
declare function askContext(): (name: string, contextNames: string[]) => Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns an object suitable for scenv's configure(): { callbacks: { onAskSaveAfterPrompt, onAskContext } }.
|
|
20
|
+
* Use as configure(callbacks()) or configure({ ...config, ...callbacks() }) to wire both save-after-prompt and ask-context via inquirer.
|
|
21
|
+
*/
|
|
22
|
+
declare function callbacks(): {
|
|
23
|
+
callbacks: {
|
|
24
|
+
onAskSaveAfterPrompt: ReturnType<typeof askSaveAfterPrompt>;
|
|
25
|
+
onAskContext: ReturnType<typeof askContext>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
7
28
|
|
|
8
|
-
export { prompt };
|
|
29
|
+
export { askContext, askSaveAfterPrompt, callbacks, prompt };
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,70 @@ function prompt() {
|
|
|
14
14
|
return value;
|
|
15
15
|
};
|
|
16
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
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function callbacks() {
|
|
71
|
+
return {
|
|
72
|
+
callbacks: {
|
|
73
|
+
onAskSaveAfterPrompt: askSaveAfterPrompt(),
|
|
74
|
+
onAskContext: askContext()
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
17
78
|
export {
|
|
79
|
+
askContext,
|
|
80
|
+
askSaveAfterPrompt,
|
|
81
|
+
callbacks,
|
|
18
82
|
prompt
|
|
19
83
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scenv-inquirer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Inquirer prompt for scenv variables",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
],
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"inquirer": "^8.0.0 || ^9.0.0",
|
|
30
|
-
"scenv": "0.
|
|
30
|
+
"scenv": "0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/inquirer": "^8.2.0",
|
|
34
34
|
"inquirer": "^9.2.0",
|
|
35
35
|
"tsup": "^8.0.0",
|
|
36
36
|
"typescript": "^5.3.0",
|
|
37
|
-
"scenv": "0.
|
|
37
|
+
"scenv": "0.2.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean"
|