@karmaniverous/get-dotenv 1.2.0 → 2.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/README.md +7 -6
- package/bin/getdotenv/index.js +24 -11
- package/dist/default/lib/getDotenv/getDotenv.js +14 -5
- package/lib/getDotenv/getDotenv.js +12 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,18 +86,18 @@ dotenv files. You can:
|
|
|
86
86
|
|
|
87
87
|
Options:
|
|
88
88
|
-p, --paths <strings...> space-delimited paths to dotenv directory (default './')
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-e, --environment <string> designated environment
|
|
93
|
-
-v, --variable <string> environment from variable
|
|
89
|
+
-y, --dynamic-path <string> dynamic variables path
|
|
90
|
+
-d, --defaultEnvironment <string> default environment (prefix with $ to use environment variable)
|
|
91
|
+
-e, --environment <string> designated environment (prefix with $ to use environment variable)
|
|
94
92
|
-n, --exclude-env exclude environment-specific variables (default: false)
|
|
95
93
|
-g, --exclude-global exclude global & dynamic variables (default: false)
|
|
96
94
|
-r, --exclude-private exclude private variables (default: false)
|
|
97
95
|
-u, --exclude-public exclude public variables (default: false)
|
|
98
|
-
-
|
|
96
|
+
-z, --exclude-dynamic exclude dynamic variables (default: false)
|
|
99
97
|
-c, --command <string> shell command string
|
|
100
98
|
-l, --log log extracted variables (default: false)
|
|
99
|
+
-t, --dotenv-token <string> token indicating a dotenv file (default: '.env')
|
|
100
|
+
-i, --private-token <string> token indicating private variables (default: 'local')
|
|
101
101
|
-h, --help display help for command
|
|
102
102
|
```
|
|
103
103
|
|
|
@@ -159,6 +159,7 @@ get-dotenv options type
|
|
|
159
159
|
| [dotenvToken] | <code>string</code> | token indicating a dotenv file (default: '.env') |
|
|
160
160
|
| [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
|
|
161
161
|
| [env] | <code>string</code> | target environment |
|
|
162
|
+
| [excludeDynamic] | <code>bool</code> | exclude dynamic variables (default: false) |
|
|
162
163
|
| [excludeEnv] | <code>bool</code> | exclude environment-specific variables (default: false) |
|
|
163
164
|
| [excludeGlobal] | <code>bool</code> | exclude global & dynamic variables (default: false) |
|
|
164
165
|
| [excludePrivate] | <code>bool</code> | exclude private variables (default: false) |
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// Import npm packages.
|
|
4
4
|
import spawn from 'cross-spawn';
|
|
5
|
+
import _ from 'lodash';
|
|
5
6
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
6
7
|
|
|
7
8
|
// Import package exports.
|
|
@@ -10,6 +11,11 @@ import { getDotenv } from '@karmaniverous/get-dotenv';
|
|
|
10
11
|
// Create CLI.
|
|
11
12
|
import { program } from 'commander';
|
|
12
13
|
|
|
14
|
+
const envMerge = (value) =>
|
|
15
|
+
!_.isUndefined(value) && value.startsWith('$')
|
|
16
|
+
? process.env[value.slice(1)]
|
|
17
|
+
: value;
|
|
18
|
+
|
|
13
19
|
// CLI description.
|
|
14
20
|
program
|
|
15
21
|
.name('getdotenv')
|
|
@@ -41,17 +47,17 @@ program
|
|
|
41
47
|
'-p, --paths <strings...>',
|
|
42
48
|
"space-delimited paths to dotenv directory (default './')"
|
|
43
49
|
)
|
|
50
|
+
.option('-y, --dynamic-path <string>', 'dynamic variables path')
|
|
44
51
|
.option(
|
|
45
|
-
'-
|
|
46
|
-
|
|
52
|
+
'-d, --defaultEnvironment <string>',
|
|
53
|
+
'default environment (prefix with $ to use environment variable)',
|
|
54
|
+
envMerge
|
|
47
55
|
)
|
|
48
56
|
.option(
|
|
49
|
-
'-
|
|
50
|
-
|
|
57
|
+
'-e, --environment <string>',
|
|
58
|
+
'designated environment (prefix with $ to use environment variable)',
|
|
59
|
+
envMerge
|
|
51
60
|
)
|
|
52
|
-
.option('-d, --defaultEnvironment <string>', 'default environment')
|
|
53
|
-
.option('-e, --environment <string>', 'designated environment')
|
|
54
|
-
.option('-v, --variable <string>', 'environment from variable')
|
|
55
61
|
.option(
|
|
56
62
|
'-n, --exclude-env',
|
|
57
63
|
'exclude environment-specific variables (default: false)'
|
|
@@ -62,9 +68,17 @@ program
|
|
|
62
68
|
)
|
|
63
69
|
.option('-r, --exclude-private', 'exclude private variables (default: false)')
|
|
64
70
|
.option('-u, --exclude-public', 'exclude public variables (default: false)')
|
|
65
|
-
.option('-
|
|
71
|
+
.option('-z, --exclude-dynamic', 'exclude dynamic variables (default: false)')
|
|
66
72
|
.option('-c, --command <string>', 'shell command string')
|
|
67
|
-
.option('-l, --log', 'log extracted variables (default: false)')
|
|
73
|
+
.option('-l, --log', 'log extracted variables (default: false)')
|
|
74
|
+
.option(
|
|
75
|
+
'-t, --dotenv-token <string>',
|
|
76
|
+
"token indicating a dotenv file (default: '.env')"
|
|
77
|
+
)
|
|
78
|
+
.option(
|
|
79
|
+
'-i, --private-token <string>',
|
|
80
|
+
"token indicating private variables (default: 'local')"
|
|
81
|
+
);
|
|
68
82
|
|
|
69
83
|
// Parse CLI options from command line.
|
|
70
84
|
program.parse();
|
|
@@ -81,13 +95,12 @@ const {
|
|
|
81
95
|
log,
|
|
82
96
|
paths,
|
|
83
97
|
privateToken,
|
|
84
|
-
variable,
|
|
85
98
|
} = program.opts();
|
|
86
99
|
|
|
87
100
|
if (command && program.args.length) program.error('command specified twice');
|
|
88
101
|
|
|
89
102
|
// Get environment.
|
|
90
|
-
const env = environment ??
|
|
103
|
+
const env = environment ?? defaultEnvironment;
|
|
91
104
|
|
|
92
105
|
// Load dotenvs.
|
|
93
106
|
await getDotenv({
|
|
@@ -21,6 +21,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
21
|
* @property {string} [dotenvToken] - token indicating a dotenv file (default: '.env')
|
|
22
22
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
23
23
|
* @property {string} [env] - target environment
|
|
24
|
+
* @property {bool} [excludeDynamic] - exclude dynamic variables (default: false)
|
|
24
25
|
* @property {bool} [excludeEnv] - exclude environment-specific variables (default: false)
|
|
25
26
|
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
26
27
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
@@ -46,6 +47,7 @@ const getDotenv = async function () {
|
|
|
46
47
|
dotenvToken = '.env',
|
|
47
48
|
env,
|
|
48
49
|
dynamicPath,
|
|
50
|
+
excludeDynamic = false,
|
|
49
51
|
excludeEnv = false,
|
|
50
52
|
excludeGlobal = false,
|
|
51
53
|
excludePrivate = false,
|
|
@@ -77,12 +79,18 @@ const getDotenv = async function () {
|
|
|
77
79
|
if (error) throw new Error(error);
|
|
78
80
|
|
|
79
81
|
// Process dynamic variables.
|
|
80
|
-
if (
|
|
82
|
+
if (dynamicPath && !excludeDynamic) {
|
|
81
83
|
const dynamic = new Function(`return ${(await _fsExtra.default.readFile(dynamicPath)).toString()}`)()(dotenv);
|
|
82
84
|
Object.keys(dynamic).forEach(key => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
try {
|
|
86
|
+
Object.assign(dotenv, {
|
|
87
|
+
[key]: dynamic[key](dotenv)
|
|
88
|
+
});
|
|
89
|
+
} catch ({
|
|
90
|
+
message
|
|
91
|
+
}) {
|
|
92
|
+
throw new Error(`Dynamic processing failed for variable '${key}' with message '${message}'`);
|
|
93
|
+
}
|
|
86
94
|
});
|
|
87
95
|
}
|
|
88
96
|
|
|
@@ -109,6 +117,7 @@ const getDotenvSync = function () {
|
|
|
109
117
|
dotenvToken = '.env',
|
|
110
118
|
dynamicPath,
|
|
111
119
|
env,
|
|
120
|
+
excludeDynamic = false,
|
|
112
121
|
excludeEnv = false,
|
|
113
122
|
excludeGlobal = false,
|
|
114
123
|
excludePrivate = false,
|
|
@@ -140,7 +149,7 @@ const getDotenvSync = function () {
|
|
|
140
149
|
if (error) throw new Error(error);
|
|
141
150
|
|
|
142
151
|
// Process dynamic variables.
|
|
143
|
-
if (
|
|
152
|
+
if (dynamicPath && !excludeDynamic) {
|
|
144
153
|
const dynamic = new Function(`return ${_fsExtra.default.readFileSync(dynamicPath).toString()}`)()(dotenv);
|
|
145
154
|
Object.keys(dynamic).forEach(key => {
|
|
146
155
|
Object.assign(dotenv, {
|
|
@@ -14,6 +14,7 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
|
14
14
|
* @property {string} [dotenvToken] - token indicating a dotenv file (default: '.env')
|
|
15
15
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
16
16
|
* @property {string} [env] - target environment
|
|
17
|
+
* @property {bool} [excludeDynamic] - exclude dynamic variables (default: false)
|
|
17
18
|
* @property {bool} [excludeEnv] - exclude environment-specific variables (default: false)
|
|
18
19
|
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
19
20
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
@@ -38,6 +39,7 @@ export const getDotenv = async ({
|
|
|
38
39
|
dotenvToken = '.env',
|
|
39
40
|
env,
|
|
40
41
|
dynamicPath,
|
|
42
|
+
excludeDynamic = false,
|
|
41
43
|
excludeEnv = false,
|
|
42
44
|
excludeGlobal = false,
|
|
43
45
|
excludePrivate = false,
|
|
@@ -87,12 +89,18 @@ export const getDotenv = async ({
|
|
|
87
89
|
if (error) throw new Error(error);
|
|
88
90
|
|
|
89
91
|
// Process dynamic variables.
|
|
90
|
-
if (
|
|
92
|
+
if (dynamicPath && !excludeDynamic) {
|
|
91
93
|
const dynamic = new Function(
|
|
92
94
|
`return ${(await fs.readFile(dynamicPath)).toString()}`
|
|
93
95
|
)()(dotenv);
|
|
94
96
|
Object.keys(dynamic).forEach((key) => {
|
|
95
|
-
|
|
97
|
+
try {
|
|
98
|
+
Object.assign(dotenv, { [key]: dynamic[key](dotenv) });
|
|
99
|
+
} catch ({ message }) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Dynamic processing failed for variable '${key}' with message '${message}'`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
96
104
|
});
|
|
97
105
|
}
|
|
98
106
|
|
|
@@ -118,6 +126,7 @@ export const getDotenvSync = ({
|
|
|
118
126
|
dotenvToken = '.env',
|
|
119
127
|
dynamicPath,
|
|
120
128
|
env,
|
|
129
|
+
excludeDynamic = false,
|
|
121
130
|
excludeEnv = false,
|
|
122
131
|
excludeGlobal = false,
|
|
123
132
|
excludePrivate = false,
|
|
@@ -167,7 +176,7 @@ export const getDotenvSync = ({
|
|
|
167
176
|
if (error) throw new Error(error);
|
|
168
177
|
|
|
169
178
|
// Process dynamic variables.
|
|
170
|
-
if (
|
|
179
|
+
if (dynamicPath && !excludeDynamic) {
|
|
171
180
|
const dynamic = new Function(
|
|
172
181
|
`return ${fs.readFileSync(dynamicPath).toString()}`
|
|
173
182
|
)()(dotenv);
|