@karmaniverous/get-dotenv 2.1.1 → 2.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/README.md +2 -2
- package/bin/getdotenv/index.js +4 -1
- package/dist/default/lib/getDotenv/getDotenv.js +42 -25
- package/lib/getDotenv/getDotenv.js +38 -25
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ dotenv files. You can:
|
|
|
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
|
+
-o, --output-path <string> consolidated output file (follows dotenv-expand rules using loaded env vars)
|
|
91
91
|
-d, --defaultEnvironment <string> default environment (prefix with $ to use environment variable)
|
|
92
92
|
-e, --environment <string> designated environment (prefix with $ to use environment variable)
|
|
93
93
|
-n, --exclude-env exclude environment-specific variables (default: false)
|
|
@@ -167,7 +167,7 @@ get-dotenv options type
|
|
|
167
167
|
| [excludePublic] | <code>bool</code> | exclude public variables (default: false) |
|
|
168
168
|
| [loadProcess] | <code>bool</code> | load dotenv to process.env (default: false) |
|
|
169
169
|
| [log] | <code>bool</code> | log result to console (default: false) |
|
|
170
|
-
| [outputPath] | <code>string</code> | if populated, writes consolidated .env file to this path |
|
|
170
|
+
| [outputPath] | <code>string</code> | if populated, writes consolidated .env file to this path (follows [dotenv-expand rules](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env)) |
|
|
171
171
|
| [paths] | <code>Array.<string></code> | array of input directory paths (default ['./']) |
|
|
172
172
|
| [privateToken] | <code>string</code> | token indicating private variables (default: 'local'). |
|
|
173
173
|
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -48,7 +48,10 @@ program
|
|
|
48
48
|
"space-delimited paths to dotenv directory (default './')"
|
|
49
49
|
)
|
|
50
50
|
.option('-y, --dynamic-path <string>', 'dynamic variables path')
|
|
51
|
-
.option(
|
|
51
|
+
.option(
|
|
52
|
+
'-o, --output-path <string>',
|
|
53
|
+
'consolidated output file (follows dotenv-expand rules using loaded env vars)'
|
|
54
|
+
)
|
|
52
55
|
.option(
|
|
53
56
|
'-d, --defaultEnvironment <string>',
|
|
54
57
|
'default environment (prefix with $ to use environment variable)',
|
|
@@ -7,6 +7,7 @@ exports.getDotenvSync = exports.getDotenv = void 0;
|
|
|
7
7
|
var _dotenvExpand = require("dotenv-expand");
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _uuid = require("uuid");
|
|
10
11
|
var _readDotenv = require("../readDotEnv/readDotenv.js");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
// npm imports
|
|
@@ -28,7 +29,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
28
29
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
29
30
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
30
31
|
* @property {bool} [log] - log result to console (default: false)
|
|
31
|
-
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path
|
|
32
|
+
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path (follows {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expand rules})
|
|
32
33
|
* @property {string[]} [paths] - array of input directory paths (default ['./'])
|
|
33
34
|
* @property {string} [privateToken] - token indicating private variables (default: 'local').
|
|
34
35
|
*/
|
|
@@ -70,15 +71,19 @@ const getDotenv = async function () {
|
|
|
70
71
|
...(excludeGlobal ? {} : await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
|
|
71
72
|
...(env && !excludeEnv ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
|
|
72
73
|
})
|
|
73
|
-
}),
|
|
74
|
+
}), {});
|
|
75
|
+
const outputKey = (0, _uuid.v4)();
|
|
74
76
|
const {
|
|
75
|
-
error,
|
|
76
77
|
parsed: dotenv
|
|
77
78
|
} = (0, _dotenvExpand.expand)({
|
|
78
79
|
ignoreProcessEnv: true,
|
|
79
|
-
parsed
|
|
80
|
+
parsed: {
|
|
81
|
+
...parsed,
|
|
82
|
+
...(outputPath ? {
|
|
83
|
+
[outputKey]: outputPath
|
|
84
|
+
} : {})
|
|
85
|
+
}
|
|
80
86
|
});
|
|
81
|
-
if (error) throw new Error(error);
|
|
82
87
|
|
|
83
88
|
// Process dynamic variables.
|
|
84
89
|
if (dynamicPath && !excludeDynamic) {
|
|
@@ -98,19 +103,23 @@ const getDotenv = async function () {
|
|
|
98
103
|
});
|
|
99
104
|
}
|
|
100
105
|
|
|
106
|
+
// Write output file.
|
|
107
|
+
if (outputPath) {
|
|
108
|
+
outputPath = dotenv[outputKey];
|
|
109
|
+
delete dotenv[outputKey];
|
|
110
|
+
await _fsExtra.default.writeFile(outputPath, Object.keys(dotenv).reduce((contents, key) => {
|
|
111
|
+
const value = dotenv[key] ?? '';
|
|
112
|
+
return `${contents}${key}=${value.includes('\n') ? `"${value}"` : value}\n`;
|
|
113
|
+
}, ''), {
|
|
114
|
+
encoding: 'utf-8'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
101
118
|
// Log result.
|
|
102
119
|
if (log) console.log(dotenv);
|
|
103
120
|
|
|
104
121
|
// Load process.env.
|
|
105
122
|
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
|
-
}, ''), {
|
|
112
|
-
encoding: 'utf-8'
|
|
113
|
-
});
|
|
114
123
|
return dotenv;
|
|
115
124
|
};
|
|
116
125
|
|
|
@@ -151,15 +160,19 @@ const getDotenvSync = function () {
|
|
|
151
160
|
...(excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
|
|
152
161
|
...(env && !excludeEnv ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
|
|
153
162
|
})
|
|
154
|
-
}),
|
|
163
|
+
}), {});
|
|
164
|
+
const outputKey = (0, _uuid.v4)();
|
|
155
165
|
const {
|
|
156
|
-
error,
|
|
157
166
|
parsed: dotenv
|
|
158
167
|
} = (0, _dotenvExpand.expand)({
|
|
159
168
|
ignoreProcessEnv: true,
|
|
160
|
-
parsed
|
|
169
|
+
parsed: {
|
|
170
|
+
...parsed,
|
|
171
|
+
...(outputPath ? {
|
|
172
|
+
[outputKey]: outputPath
|
|
173
|
+
} : {})
|
|
174
|
+
}
|
|
161
175
|
});
|
|
162
|
-
if (error) throw new Error(error);
|
|
163
176
|
|
|
164
177
|
// Process dynamic variables.
|
|
165
178
|
if (dynamicPath && !excludeDynamic) {
|
|
@@ -171,19 +184,23 @@ const getDotenvSync = function () {
|
|
|
171
184
|
});
|
|
172
185
|
}
|
|
173
186
|
|
|
187
|
+
// Write output file.
|
|
188
|
+
if (outputPath) {
|
|
189
|
+
outputPath = dotenv[outputKey];
|
|
190
|
+
delete dotenv[outputKey];
|
|
191
|
+
_fsExtra.default.writeFileSync(outputPath, Object.keys(dotenv).reduce((contents, key) => {
|
|
192
|
+
const value = dotenv[key] ?? '';
|
|
193
|
+
return `${contents}${key}=${value.includes('\n') ? `"${value}"` : value}\n`;
|
|
194
|
+
}, ''), {
|
|
195
|
+
encoding: 'utf-8'
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
174
199
|
// Log result.
|
|
175
200
|
if (log) console.log(dotenv);
|
|
176
201
|
|
|
177
202
|
// Load process.env.
|
|
178
203
|
if (loadProcess) Object.assign(process.env, dotenv);
|
|
179
|
-
|
|
180
|
-
// Write output file.
|
|
181
|
-
if (outputPath) _fsExtra.default.writeFileSync(outputPath, Object.keys(dotenv).reduce((contents, key) => {
|
|
182
|
-
const value = dotenv[key] ?? '';
|
|
183
|
-
return `${contents}${key}=${value.includes('\n') ? `"${value}"` : value}\n`;
|
|
184
|
-
}, ''), {
|
|
185
|
-
encoding: 'utf-8'
|
|
186
|
-
});
|
|
187
204
|
return dotenv;
|
|
188
205
|
};
|
|
189
206
|
exports.getDotenvSync = getDotenvSync;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { expand } from 'dotenv-expand';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import path from 'path';
|
|
5
|
+
import { v4 as uuid } from 'uuid';
|
|
5
6
|
|
|
6
7
|
// lib imports
|
|
7
8
|
import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
@@ -21,7 +22,7 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
|
21
22
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
22
23
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
23
24
|
* @property {bool} [log] - log result to console (default: false)
|
|
24
|
-
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path
|
|
25
|
+
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path (follows {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expand rules})
|
|
25
26
|
* @property {string[]} [paths] - array of input directory paths (default ['./'])
|
|
26
27
|
* @property {string} [privateToken] - token indicating private variables (default: 'local').
|
|
27
28
|
*/
|
|
@@ -80,16 +81,18 @@ export const getDotenv = async ({
|
|
|
80
81
|
: {}),
|
|
81
82
|
}),
|
|
82
83
|
}),
|
|
83
|
-
|
|
84
|
+
{}
|
|
84
85
|
);
|
|
85
86
|
|
|
86
|
-
const
|
|
87
|
+
const outputKey = uuid();
|
|
88
|
+
const { parsed: dotenv } = expand({
|
|
87
89
|
ignoreProcessEnv: true,
|
|
88
|
-
parsed
|
|
90
|
+
parsed: {
|
|
91
|
+
...parsed,
|
|
92
|
+
...(outputPath ? { [outputKey]: outputPath } : {}),
|
|
93
|
+
},
|
|
89
94
|
});
|
|
90
95
|
|
|
91
|
-
if (error) throw new Error(error);
|
|
92
|
-
|
|
93
96
|
// Process dynamic variables.
|
|
94
97
|
if (dynamicPath && !excludeDynamic) {
|
|
95
98
|
const dynamic = new Function(
|
|
@@ -104,14 +107,11 @@ export const getDotenv = async ({
|
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
// Log result.
|
|
108
|
-
if (log) console.log(dotenv);
|
|
109
|
-
|
|
110
|
-
// Load process.env.
|
|
111
|
-
if (loadProcess) Object.assign(process.env, dotenv);
|
|
112
|
-
|
|
113
110
|
// Write output file.
|
|
114
|
-
if (outputPath)
|
|
111
|
+
if (outputPath) {
|
|
112
|
+
outputPath = dotenv[outputKey];
|
|
113
|
+
delete dotenv[outputKey];
|
|
114
|
+
|
|
115
115
|
await fs.writeFile(
|
|
116
116
|
outputPath,
|
|
117
117
|
Object.keys(dotenv).reduce((contents, key) => {
|
|
@@ -122,6 +122,13 @@ export const getDotenv = async ({
|
|
|
122
122
|
}, ''),
|
|
123
123
|
{ encoding: 'utf-8' }
|
|
124
124
|
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Log result.
|
|
128
|
+
if (log) console.log(dotenv);
|
|
129
|
+
|
|
130
|
+
// Load process.env.
|
|
131
|
+
if (loadProcess) Object.assign(process.env, dotenv);
|
|
125
132
|
|
|
126
133
|
return dotenv;
|
|
127
134
|
};
|
|
@@ -179,16 +186,18 @@ export const getDotenvSync = ({
|
|
|
179
186
|
: {}),
|
|
180
187
|
}),
|
|
181
188
|
}),
|
|
182
|
-
|
|
189
|
+
{}
|
|
183
190
|
);
|
|
184
191
|
|
|
185
|
-
const
|
|
192
|
+
const outputKey = uuid();
|
|
193
|
+
const { parsed: dotenv } = expand({
|
|
186
194
|
ignoreProcessEnv: true,
|
|
187
|
-
parsed
|
|
195
|
+
parsed: {
|
|
196
|
+
...parsed,
|
|
197
|
+
...(outputPath ? { [outputKey]: outputPath } : {}),
|
|
198
|
+
},
|
|
188
199
|
});
|
|
189
200
|
|
|
190
|
-
if (error) throw new Error(error);
|
|
191
|
-
|
|
192
201
|
// Process dynamic variables.
|
|
193
202
|
if (dynamicPath && !excludeDynamic) {
|
|
194
203
|
const dynamic = new Function(
|
|
@@ -204,14 +213,11 @@ export const getDotenvSync = ({
|
|
|
204
213
|
});
|
|
205
214
|
}
|
|
206
215
|
|
|
207
|
-
// Log result.
|
|
208
|
-
if (log) console.log(dotenv);
|
|
209
|
-
|
|
210
|
-
// Load process.env.
|
|
211
|
-
if (loadProcess) Object.assign(process.env, dotenv);
|
|
212
|
-
|
|
213
216
|
// Write output file.
|
|
214
|
-
if (outputPath)
|
|
217
|
+
if (outputPath) {
|
|
218
|
+
outputPath = dotenv[outputKey];
|
|
219
|
+
delete dotenv[outputKey];
|
|
220
|
+
|
|
215
221
|
fs.writeFileSync(
|
|
216
222
|
outputPath,
|
|
217
223
|
Object.keys(dotenv).reduce((contents, key) => {
|
|
@@ -222,6 +228,13 @@ export const getDotenvSync = ({
|
|
|
222
228
|
}, ''),
|
|
223
229
|
{ encoding: 'utf-8' }
|
|
224
230
|
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Log result.
|
|
234
|
+
if (log) console.log(dotenv);
|
|
235
|
+
|
|
236
|
+
// Load process.env.
|
|
237
|
+
if (loadProcess) Object.assign(process.env, dotenv);
|
|
225
238
|
|
|
226
239
|
return dotenv;
|
|
227
240
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"bin": {
|
|
4
4
|
"getdotenv": "bin/getdotenv/index.js"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.2.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"dotenv": "^16.0.3",
|
|
37
37
|
"dotenv-expand": "^10.0.0",
|
|
38
38
|
"fs-extra": "^11.1.0",
|
|
39
|
-
"string-argv": "^0.3.1"
|
|
39
|
+
"string-argv": "^0.3.1",
|
|
40
|
+
"uuid": "^9.0.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@babel/cli": "^7.21.0",
|