scenv 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 +14 -17
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +12 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -25,24 +25,24 @@ __export(index_exports, {
|
|
|
25
25
|
getCallbacks: () => getCallbacks,
|
|
26
26
|
getContextValues: () => getContextValues,
|
|
27
27
|
loadConfig: () => loadConfig,
|
|
28
|
-
|
|
28
|
+
parseScenvArgs: () => parseScenvArgs,
|
|
29
29
|
resetConfig: () => resetConfig,
|
|
30
|
-
|
|
30
|
+
scenv: () => scenv
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(index_exports);
|
|
33
33
|
|
|
34
34
|
// src/config.ts
|
|
35
35
|
var import_node_fs = require("fs");
|
|
36
36
|
var import_node_path = require("path");
|
|
37
|
-
var CONFIG_FILENAME = "
|
|
37
|
+
var CONFIG_FILENAME = "scenv.config.json";
|
|
38
38
|
var envKeyMap = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
SCENV_CONTEXT: "contexts",
|
|
40
|
+
SCENV_ADD_CONTEXTS: "addContexts",
|
|
41
|
+
SCENV_PROMPT: "prompt",
|
|
42
|
+
SCENV_IGNORE_ENV: "ignoreEnv",
|
|
43
|
+
SCENV_IGNORE_CONTEXT: "ignoreContext",
|
|
44
|
+
SCENV_SAVE_PROMPT: "savePrompt",
|
|
45
|
+
SCENV_SAVE_CONTEXT_TO: "saveContextTo"
|
|
46
46
|
};
|
|
47
47
|
var programmaticConfig = {};
|
|
48
48
|
var programmaticCallbacks = {};
|
|
@@ -269,7 +269,7 @@ function normalizeValidatorResult(result) {
|
|
|
269
269
|
if (result.success === true) return result;
|
|
270
270
|
return result;
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function scenv(name, options = {}) {
|
|
273
273
|
const key = options.key ?? defaultKeyFromName(name);
|
|
274
274
|
const envKey = options.env ?? defaultEnvFromKey(key);
|
|
275
275
|
const validator = options.validator;
|
|
@@ -286,9 +286,6 @@ function senv(name, options = {}) {
|
|
|
286
286
|
const ctx = getContextValues();
|
|
287
287
|
if (ctx[key] !== void 0) return ctx[key];
|
|
288
288
|
}
|
|
289
|
-
if (defaultValue !== void 0) {
|
|
290
|
-
return String(defaultValue);
|
|
291
|
-
}
|
|
292
289
|
return void 0;
|
|
293
290
|
}
|
|
294
291
|
function shouldPrompt(config, hadValue, hadEnv) {
|
|
@@ -394,7 +391,7 @@ function senv(name, options = {}) {
|
|
|
394
391
|
}
|
|
395
392
|
|
|
396
393
|
// src/cli-args.ts
|
|
397
|
-
function
|
|
394
|
+
function parseScenvArgs(argv) {
|
|
398
395
|
const config = {};
|
|
399
396
|
let i = 0;
|
|
400
397
|
while (i < argv.length) {
|
|
@@ -445,7 +442,7 @@ function parseSenvArgs(argv) {
|
|
|
445
442
|
getCallbacks,
|
|
446
443
|
getContextValues,
|
|
447
444
|
loadConfig,
|
|
448
|
-
|
|
445
|
+
parseScenvArgs,
|
|
449
446
|
resetConfig,
|
|
450
|
-
|
|
447
|
+
scenv
|
|
451
448
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type PromptMode = "always" | "never" | "fallback" | "no-env";
|
|
2
2
|
type SavePromptMode = "always" | "never" | "ask";
|
|
3
|
-
interface
|
|
3
|
+
interface ScenvConfig {
|
|
4
4
|
/** Replace all contexts with this list (CLI: --context a,b,c) */
|
|
5
5
|
contexts?: string[];
|
|
6
6
|
/** Merge these contexts with existing (CLI: --add-context a,b,c) */
|
|
@@ -20,22 +20,22 @@ interface SenvConfig {
|
|
|
20
20
|
/** Root directory for config/context search (default: cwd) */
|
|
21
21
|
root?: string;
|
|
22
22
|
}
|
|
23
|
-
interface
|
|
23
|
+
interface ScenvCallbacks {
|
|
24
24
|
/** When user was just prompted for a value and savePrompt is ask/always: (variableName, value, contextNames) => context name to save to, or null to skip */
|
|
25
25
|
onAskSaveAfterPrompt?: (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
|
|
26
26
|
/** When saveContextTo is "ask": (variableName, contextNames) => context name to save to */
|
|
27
27
|
onAskContext?: (name: string, contextNames: string[]) => Promise<string>;
|
|
28
28
|
}
|
|
29
|
-
declare function getCallbacks():
|
|
29
|
+
declare function getCallbacks(): ScenvCallbacks;
|
|
30
30
|
/**
|
|
31
31
|
* Load full config: file (from root or cwd) <- env <- programmatic. Precedence: programmatic > env > file.
|
|
32
32
|
*/
|
|
33
|
-
declare function loadConfig(root?: string):
|
|
33
|
+
declare function loadConfig(root?: string): ScenvConfig;
|
|
34
34
|
/**
|
|
35
35
|
* Set programmatic config (e.g. from CLI flags). Merged on top of env and file in loadConfig().
|
|
36
36
|
*/
|
|
37
|
-
declare function configure(partial: Partial<
|
|
38
|
-
callbacks?:
|
|
37
|
+
declare function configure(partial: Partial<ScenvConfig> & {
|
|
38
|
+
callbacks?: ScenvCallbacks;
|
|
39
39
|
}): void;
|
|
40
40
|
/**
|
|
41
41
|
* Reset programmatic config (mainly for tests).
|
|
@@ -59,14 +59,14 @@ type ValidatorResult<T> = boolean | {
|
|
|
59
59
|
error?: unknown;
|
|
60
60
|
};
|
|
61
61
|
type PromptFn<T> = (name: string, defaultValue: T) => T | Promise<T>;
|
|
62
|
-
interface
|
|
62
|
+
interface ScenvVariableOptions<T> {
|
|
63
63
|
key?: string;
|
|
64
64
|
env?: string;
|
|
65
65
|
default?: T;
|
|
66
66
|
validator?: (val: T) => ValidatorResult<T>;
|
|
67
67
|
prompt?: PromptFn<T>;
|
|
68
68
|
}
|
|
69
|
-
interface
|
|
69
|
+
interface ScenvVariable<T> {
|
|
70
70
|
get(): Promise<T>;
|
|
71
71
|
safeGet(): Promise<{
|
|
72
72
|
success: true;
|
|
@@ -77,13 +77,13 @@ interface SenvVariable<T> {
|
|
|
77
77
|
}>;
|
|
78
78
|
save(value?: T): Promise<void>;
|
|
79
79
|
}
|
|
80
|
-
declare function
|
|
80
|
+
declare function scenv<T>(name: string, options?: ScenvVariableOptions<T>): ScenvVariable<T>;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Parse argv (e.g. process.argv.slice(2)) into
|
|
83
|
+
* Parse argv (e.g. process.argv.slice(2)) into ScenvConfig for configure().
|
|
84
84
|
* Supports: --context a,b,c --add-context x,y --prompt fallback --ignore-env --ignore-context
|
|
85
85
|
* --set key=value --save-prompt ask --save-context-to prod
|
|
86
86
|
*/
|
|
87
|
-
declare function
|
|
87
|
+
declare function parseScenvArgs(argv: string[]): Partial<ScenvConfig>;
|
|
88
88
|
|
|
89
|
-
export { type PromptMode, type SavePromptMode, type
|
|
89
|
+
export { type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type PromptMode = "always" | "never" | "fallback" | "no-env";
|
|
2
2
|
type SavePromptMode = "always" | "never" | "ask";
|
|
3
|
-
interface
|
|
3
|
+
interface ScenvConfig {
|
|
4
4
|
/** Replace all contexts with this list (CLI: --context a,b,c) */
|
|
5
5
|
contexts?: string[];
|
|
6
6
|
/** Merge these contexts with existing (CLI: --add-context a,b,c) */
|
|
@@ -20,22 +20,22 @@ interface SenvConfig {
|
|
|
20
20
|
/** Root directory for config/context search (default: cwd) */
|
|
21
21
|
root?: string;
|
|
22
22
|
}
|
|
23
|
-
interface
|
|
23
|
+
interface ScenvCallbacks {
|
|
24
24
|
/** When user was just prompted for a value and savePrompt is ask/always: (variableName, value, contextNames) => context name to save to, or null to skip */
|
|
25
25
|
onAskSaveAfterPrompt?: (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
|
|
26
26
|
/** When saveContextTo is "ask": (variableName, contextNames) => context name to save to */
|
|
27
27
|
onAskContext?: (name: string, contextNames: string[]) => Promise<string>;
|
|
28
28
|
}
|
|
29
|
-
declare function getCallbacks():
|
|
29
|
+
declare function getCallbacks(): ScenvCallbacks;
|
|
30
30
|
/**
|
|
31
31
|
* Load full config: file (from root or cwd) <- env <- programmatic. Precedence: programmatic > env > file.
|
|
32
32
|
*/
|
|
33
|
-
declare function loadConfig(root?: string):
|
|
33
|
+
declare function loadConfig(root?: string): ScenvConfig;
|
|
34
34
|
/**
|
|
35
35
|
* Set programmatic config (e.g. from CLI flags). Merged on top of env and file in loadConfig().
|
|
36
36
|
*/
|
|
37
|
-
declare function configure(partial: Partial<
|
|
38
|
-
callbacks?:
|
|
37
|
+
declare function configure(partial: Partial<ScenvConfig> & {
|
|
38
|
+
callbacks?: ScenvCallbacks;
|
|
39
39
|
}): void;
|
|
40
40
|
/**
|
|
41
41
|
* Reset programmatic config (mainly for tests).
|
|
@@ -59,14 +59,14 @@ type ValidatorResult<T> = boolean | {
|
|
|
59
59
|
error?: unknown;
|
|
60
60
|
};
|
|
61
61
|
type PromptFn<T> = (name: string, defaultValue: T) => T | Promise<T>;
|
|
62
|
-
interface
|
|
62
|
+
interface ScenvVariableOptions<T> {
|
|
63
63
|
key?: string;
|
|
64
64
|
env?: string;
|
|
65
65
|
default?: T;
|
|
66
66
|
validator?: (val: T) => ValidatorResult<T>;
|
|
67
67
|
prompt?: PromptFn<T>;
|
|
68
68
|
}
|
|
69
|
-
interface
|
|
69
|
+
interface ScenvVariable<T> {
|
|
70
70
|
get(): Promise<T>;
|
|
71
71
|
safeGet(): Promise<{
|
|
72
72
|
success: true;
|
|
@@ -77,13 +77,13 @@ interface SenvVariable<T> {
|
|
|
77
77
|
}>;
|
|
78
78
|
save(value?: T): Promise<void>;
|
|
79
79
|
}
|
|
80
|
-
declare function
|
|
80
|
+
declare function scenv<T>(name: string, options?: ScenvVariableOptions<T>): ScenvVariable<T>;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Parse argv (e.g. process.argv.slice(2)) into
|
|
83
|
+
* Parse argv (e.g. process.argv.slice(2)) into ScenvConfig for configure().
|
|
84
84
|
* Supports: --context a,b,c --add-context x,y --prompt fallback --ignore-env --ignore-context
|
|
85
85
|
* --set key=value --save-prompt ask --save-context-to prod
|
|
86
86
|
*/
|
|
87
|
-
declare function
|
|
87
|
+
declare function parseScenvArgs(argv: string[]): Partial<ScenvConfig>;
|
|
88
88
|
|
|
89
|
-
export { type PromptMode, type SavePromptMode, type
|
|
89
|
+
export { type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/config.ts
|
|
2
2
|
import { readFileSync, existsSync } from "fs";
|
|
3
3
|
import { dirname, join } from "path";
|
|
4
|
-
var CONFIG_FILENAME = "
|
|
4
|
+
var CONFIG_FILENAME = "scenv.config.json";
|
|
5
5
|
var envKeyMap = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
SCENV_CONTEXT: "contexts",
|
|
7
|
+
SCENV_ADD_CONTEXTS: "addContexts",
|
|
8
|
+
SCENV_PROMPT: "prompt",
|
|
9
|
+
SCENV_IGNORE_ENV: "ignoreEnv",
|
|
10
|
+
SCENV_IGNORE_CONTEXT: "ignoreContext",
|
|
11
|
+
SCENV_SAVE_PROMPT: "savePrompt",
|
|
12
|
+
SCENV_SAVE_CONTEXT_TO: "saveContextTo"
|
|
13
13
|
};
|
|
14
14
|
var programmaticConfig = {};
|
|
15
15
|
var programmaticCallbacks = {};
|
|
@@ -242,7 +242,7 @@ function normalizeValidatorResult(result) {
|
|
|
242
242
|
if (result.success === true) return result;
|
|
243
243
|
return result;
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function scenv(name, options = {}) {
|
|
246
246
|
const key = options.key ?? defaultKeyFromName(name);
|
|
247
247
|
const envKey = options.env ?? defaultEnvFromKey(key);
|
|
248
248
|
const validator = options.validator;
|
|
@@ -259,9 +259,6 @@ function senv(name, options = {}) {
|
|
|
259
259
|
const ctx = getContextValues();
|
|
260
260
|
if (ctx[key] !== void 0) return ctx[key];
|
|
261
261
|
}
|
|
262
|
-
if (defaultValue !== void 0) {
|
|
263
|
-
return String(defaultValue);
|
|
264
|
-
}
|
|
265
262
|
return void 0;
|
|
266
263
|
}
|
|
267
264
|
function shouldPrompt(config, hadValue, hadEnv) {
|
|
@@ -367,7 +364,7 @@ function senv(name, options = {}) {
|
|
|
367
364
|
}
|
|
368
365
|
|
|
369
366
|
// src/cli-args.ts
|
|
370
|
-
function
|
|
367
|
+
function parseScenvArgs(argv) {
|
|
371
368
|
const config = {};
|
|
372
369
|
let i = 0;
|
|
373
370
|
while (i < argv.length) {
|
|
@@ -417,7 +414,7 @@ export {
|
|
|
417
414
|
getCallbacks,
|
|
418
415
|
getContextValues,
|
|
419
416
|
loadConfig,
|
|
420
|
-
|
|
417
|
+
parseScenvArgs,
|
|
421
418
|
resetConfig,
|
|
422
|
-
|
|
419
|
+
scenv
|
|
423
420
|
};
|