@karmaniverous/get-dotenv 2.0.3 → 2.1.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 +9 -7
- package/bin/getdotenv/index.js +9 -6
- package/dist/default/lib/getDotenv/getDotenv.js +16 -1
- package/lib/getDotenv/getDotenv.js +28 -1
- package/package.json +1 -1
- package/test.env +7 -0
package/README.md
CHANGED
|
@@ -71,22 +71,23 @@ Load environment variables with a cascade of environment-aware
|
|
|
71
71
|
dotenv files. You can:
|
|
72
72
|
|
|
73
73
|
* Specify the directories containing your dotenv files.
|
|
74
|
-
*
|
|
75
|
-
|
|
74
|
+
* Define dynamic variables progressively in terms of other variables and
|
|
75
|
+
other logic.
|
|
76
|
+
* Specify a consolidated output file path.
|
|
76
77
|
* Load variables for a specific environment or none.
|
|
77
78
|
* Specify a default environment, override the default with an existing
|
|
78
79
|
environment variable, and override both with a direct setting.
|
|
79
|
-
* Exclude public or
|
|
80
|
-
* Exclude global & dynamic or environment-specific variables.
|
|
81
|
-
* Define dynamic variables progressively in terms of other variables and
|
|
82
|
-
other logic.
|
|
80
|
+
* Exclude public, private, global, environment-specific, or dynamic variables.
|
|
83
81
|
* Execute a &&-delimited series of shell commands after loading variables.
|
|
84
82
|
* Place the shell commands inside the invocation to support npm script
|
|
85
83
|
arguments for other options.
|
|
84
|
+
* Specify the token that identifies dotenv files (e.g. '.env').
|
|
85
|
+
* Specify the token that identifies private vatiables (e.g. '.local').
|
|
86
86
|
|
|
87
87
|
Options:
|
|
88
88
|
-p, --paths <strings...> space-delimited paths to dotenv directory (default './')
|
|
89
89
|
-y, --dynamic-path <string> dynamic variables path
|
|
90
|
+
-o, --output-path <string> consolidated output file
|
|
90
91
|
-d, --defaultEnvironment <string> default environment (prefix with $ to use environment variable)
|
|
91
92
|
-e, --environment <string> designated environment (prefix with $ to use environment variable)
|
|
92
93
|
-n, --exclude-env exclude environment-specific variables (default: false)
|
|
@@ -166,7 +167,8 @@ get-dotenv options type
|
|
|
166
167
|
| [excludePublic] | <code>bool</code> | exclude public variables (default: false) |
|
|
167
168
|
| [loadProcess] | <code>bool</code> | load dotenv to process.env (default: false) |
|
|
168
169
|
| [log] | <code>bool</code> | log result to console (default: false) |
|
|
169
|
-
| [
|
|
170
|
+
| [outputPath] | <code>string</code> | if populated, writes consolidated .env file to this path |
|
|
171
|
+
| [paths] | <code>Array.<string></code> | array of input directory paths (default ['./']) |
|
|
170
172
|
| [privateToken] | <code>string</code> | token indicating private variables (default: 'local'). |
|
|
171
173
|
|
|
172
174
|
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -26,18 +26,18 @@ program
|
|
|
26
26
|
`dotenv files. You can:`,
|
|
27
27
|
``,
|
|
28
28
|
`* Specify the directories containing your dotenv files.`,
|
|
29
|
-
`*
|
|
30
|
-
|
|
29
|
+
`* Define dynamic variables progressively in terms of other variables and`,
|
|
30
|
+
` other logic.`,
|
|
31
|
+
`* Specify a consolidated output file path.`,
|
|
31
32
|
`* Load variables for a specific environment or none.`,
|
|
32
33
|
`* Specify a default environment, override the default with an existing`,
|
|
33
34
|
` environment variable, and override both with a direct setting.`,
|
|
34
|
-
`* Exclude public or
|
|
35
|
-
`* Exclude global & dynamic or environment-specific variables.`,
|
|
36
|
-
`* Define dynamic variables progressively in terms of other variables and`,
|
|
37
|
-
` other logic.`,
|
|
35
|
+
`* Exclude public, private, global, environment-specific, or dynamic variables.`,
|
|
38
36
|
`* Execute a &&-delimited series of shell commands after loading variables.`,
|
|
39
37
|
`* Place the shell commands inside the invocation to support npm script`,
|
|
40
38
|
` arguments for other options.`,
|
|
39
|
+
`* Specify the token that identifies dotenv files (e.g. '.env').`,
|
|
40
|
+
`* Specify the token that identifies private vatiables (e.g. '.local').`,
|
|
41
41
|
].join('\n')
|
|
42
42
|
);
|
|
43
43
|
|
|
@@ -48,6 +48,7 @@ program
|
|
|
48
48
|
"space-delimited paths to dotenv directory (default './')"
|
|
49
49
|
)
|
|
50
50
|
.option('-y, --dynamic-path <string>', 'dynamic variables path')
|
|
51
|
+
.option('-o, --output-path <string>', 'consolidated output file')
|
|
51
52
|
.option(
|
|
52
53
|
'-d, --defaultEnvironment <string>',
|
|
53
54
|
'default environment (prefix with $ to use environment variable)',
|
|
@@ -93,6 +94,7 @@ const {
|
|
|
93
94
|
excludePublic,
|
|
94
95
|
dynamicPath,
|
|
95
96
|
log,
|
|
97
|
+
outputPath,
|
|
96
98
|
paths,
|
|
97
99
|
privateToken,
|
|
98
100
|
} = program.opts();
|
|
@@ -113,6 +115,7 @@ await getDotenv({
|
|
|
113
115
|
loadProcess: true,
|
|
114
116
|
dynamicPath,
|
|
115
117
|
log,
|
|
118
|
+
outputPath,
|
|
116
119
|
paths,
|
|
117
120
|
privateToken,
|
|
118
121
|
});
|
|
@@ -28,7 +28,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
28
28
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
29
29
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
30
30
|
* @property {bool} [log] - log result to console (default: false)
|
|
31
|
-
* @property {string
|
|
31
|
+
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path
|
|
32
|
+
* @property {string[]} [paths] - array of input directory paths (default ['./'])
|
|
32
33
|
* @property {string} [privateToken] - token indicating private variables (default: 'local').
|
|
33
34
|
*/
|
|
34
35
|
|
|
@@ -54,6 +55,7 @@ const getDotenv = async function () {
|
|
|
54
55
|
excludePublic = false,
|
|
55
56
|
loadProcess = false,
|
|
56
57
|
log = false,
|
|
58
|
+
outputPath,
|
|
57
59
|
paths = ['./'],
|
|
58
60
|
privateToken = 'local'
|
|
59
61
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -101,6 +103,12 @@ const getDotenv = async function () {
|
|
|
101
103
|
|
|
102
104
|
// Load process.env.
|
|
103
105
|
if (loadProcess) Object.assign(process.env, dotenv);
|
|
106
|
+
|
|
107
|
+
// Write output file.
|
|
108
|
+
if (outputPath) await _fsExtra.default.writeFile(outputPath, Object.keys(dotenv).reduce((contents, key) => {
|
|
109
|
+
const value = dotenv[key] ?? '';
|
|
110
|
+
return `${contents}${key}=${value.includes('\n') ? `"${value}"` : value}\n`;
|
|
111
|
+
}, ''));
|
|
104
112
|
return dotenv;
|
|
105
113
|
};
|
|
106
114
|
|
|
@@ -126,6 +134,7 @@ const getDotenvSync = function () {
|
|
|
126
134
|
excludePublic = false,
|
|
127
135
|
loadProcess = false,
|
|
128
136
|
log = false,
|
|
137
|
+
outputPath,
|
|
129
138
|
paths = ['./'],
|
|
130
139
|
privateToken = 'local'
|
|
131
140
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -165,6 +174,12 @@ const getDotenvSync = function () {
|
|
|
165
174
|
|
|
166
175
|
// Load process.env.
|
|
167
176
|
if (loadProcess) Object.assign(process.env, dotenv);
|
|
177
|
+
|
|
178
|
+
// Write output file.
|
|
179
|
+
if (outputPath) _fsExtra.default.writeFileSync(outputPath, Object.keys(dotenv).reduce((contents, key) => {
|
|
180
|
+
const value = dotenv[key] ?? '';
|
|
181
|
+
return `${contents}${key}=${value.includes('\n') ? `"${value}"` : value}\n`;
|
|
182
|
+
}, ''));
|
|
168
183
|
return dotenv;
|
|
169
184
|
};
|
|
170
185
|
exports.getDotenvSync = getDotenvSync;
|
|
@@ -21,7 +21,8 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
|
21
21
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
22
22
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
23
23
|
* @property {bool} [log] - log result to console (default: false)
|
|
24
|
-
* @property {string
|
|
24
|
+
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path
|
|
25
|
+
* @property {string[]} [paths] - array of input directory paths (default ['./'])
|
|
25
26
|
* @property {string} [privateToken] - token indicating private variables (default: 'local').
|
|
26
27
|
*/
|
|
27
28
|
|
|
@@ -46,6 +47,7 @@ export const getDotenv = async ({
|
|
|
46
47
|
excludePublic = false,
|
|
47
48
|
loadProcess = false,
|
|
48
49
|
log = false,
|
|
50
|
+
outputPath,
|
|
49
51
|
paths = ['./'],
|
|
50
52
|
privateToken = 'local',
|
|
51
53
|
} = {}) => {
|
|
@@ -108,6 +110,18 @@ export const getDotenv = async ({
|
|
|
108
110
|
// Load process.env.
|
|
109
111
|
if (loadProcess) Object.assign(process.env, dotenv);
|
|
110
112
|
|
|
113
|
+
// Write output file.
|
|
114
|
+
if (outputPath)
|
|
115
|
+
await fs.writeFile(
|
|
116
|
+
outputPath,
|
|
117
|
+
Object.keys(dotenv).reduce((contents, key) => {
|
|
118
|
+
const value = dotenv[key] ?? '';
|
|
119
|
+
return `${contents}${key}=${
|
|
120
|
+
value.includes('\n') ? `"${value}"` : value
|
|
121
|
+
}\n`;
|
|
122
|
+
}, '')
|
|
123
|
+
);
|
|
124
|
+
|
|
111
125
|
return dotenv;
|
|
112
126
|
};
|
|
113
127
|
|
|
@@ -131,6 +145,7 @@ export const getDotenvSync = ({
|
|
|
131
145
|
excludePublic = false,
|
|
132
146
|
loadProcess = false,
|
|
133
147
|
log = false,
|
|
148
|
+
outputPath,
|
|
134
149
|
paths = ['./'],
|
|
135
150
|
privateToken = 'local',
|
|
136
151
|
} = {}) => {
|
|
@@ -194,5 +209,17 @@ export const getDotenvSync = ({
|
|
|
194
209
|
// Load process.env.
|
|
195
210
|
if (loadProcess) Object.assign(process.env, dotenv);
|
|
196
211
|
|
|
212
|
+
// Write output file.
|
|
213
|
+
if (outputPath)
|
|
214
|
+
fs.writeFileSync(
|
|
215
|
+
outputPath,
|
|
216
|
+
Object.keys(dotenv).reduce((contents, key) => {
|
|
217
|
+
const value = dotenv[key] ?? '';
|
|
218
|
+
return `${contents}${key}=${
|
|
219
|
+
value.includes('\n') ? `"${value}"` : value
|
|
220
|
+
}\n`;
|
|
221
|
+
}, '')
|
|
222
|
+
);
|
|
223
|
+
|
|
197
224
|
return dotenv;
|
|
198
225
|
};
|
package/package.json
CHANGED