@karmaniverous/get-dotenv 2.1.0 → 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 -21
- package/lib/getDotenv/getDotenv.js +42 -27
- 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,17 +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
123
|
return dotenv;
|
|
113
124
|
};
|
|
114
125
|
|
|
@@ -149,15 +160,19 @@ const getDotenvSync = function () {
|
|
|
149
160
|
...(excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
|
|
150
161
|
...(env && !excludeEnv ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
|
|
151
162
|
})
|
|
152
|
-
}),
|
|
163
|
+
}), {});
|
|
164
|
+
const outputKey = (0, _uuid.v4)();
|
|
153
165
|
const {
|
|
154
|
-
error,
|
|
155
166
|
parsed: dotenv
|
|
156
167
|
} = (0, _dotenvExpand.expand)({
|
|
157
168
|
ignoreProcessEnv: true,
|
|
158
|
-
parsed
|
|
169
|
+
parsed: {
|
|
170
|
+
...parsed,
|
|
171
|
+
...(outputPath ? {
|
|
172
|
+
[outputKey]: outputPath
|
|
173
|
+
} : {})
|
|
174
|
+
}
|
|
159
175
|
});
|
|
160
|
-
if (error) throw new Error(error);
|
|
161
176
|
|
|
162
177
|
// Process dynamic variables.
|
|
163
178
|
if (dynamicPath && !excludeDynamic) {
|
|
@@ -169,17 +184,23 @@ const getDotenvSync = function () {
|
|
|
169
184
|
});
|
|
170
185
|
}
|
|
171
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
|
+
|
|
172
199
|
// Log result.
|
|
173
200
|
if (log) console.log(dotenv);
|
|
174
201
|
|
|
175
202
|
// Load process.env.
|
|
176
203
|
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
|
-
}, ''));
|
|
183
204
|
return dotenv;
|
|
184
205
|
};
|
|
185
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) => {
|
|
@@ -119,8 +119,16 @@ export const getDotenv = async ({
|
|
|
119
119
|
return `${contents}${key}=${
|
|
120
120
|
value.includes('\n') ? `"${value}"` : value
|
|
121
121
|
}\n`;
|
|
122
|
-
}, '')
|
|
122
|
+
}, ''),
|
|
123
|
+
{ encoding: 'utf-8' }
|
|
123
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);
|
|
124
132
|
|
|
125
133
|
return dotenv;
|
|
126
134
|
};
|
|
@@ -178,16 +186,18 @@ export const getDotenvSync = ({
|
|
|
178
186
|
: {}),
|
|
179
187
|
}),
|
|
180
188
|
}),
|
|
181
|
-
|
|
189
|
+
{}
|
|
182
190
|
);
|
|
183
191
|
|
|
184
|
-
const
|
|
192
|
+
const outputKey = uuid();
|
|
193
|
+
const { parsed: dotenv } = expand({
|
|
185
194
|
ignoreProcessEnv: true,
|
|
186
|
-
parsed
|
|
195
|
+
parsed: {
|
|
196
|
+
...parsed,
|
|
197
|
+
...(outputPath ? { [outputKey]: outputPath } : {}),
|
|
198
|
+
},
|
|
187
199
|
});
|
|
188
200
|
|
|
189
|
-
if (error) throw new Error(error);
|
|
190
|
-
|
|
191
201
|
// Process dynamic variables.
|
|
192
202
|
if (dynamicPath && !excludeDynamic) {
|
|
193
203
|
const dynamic = new Function(
|
|
@@ -203,14 +213,11 @@ export const getDotenvSync = ({
|
|
|
203
213
|
});
|
|
204
214
|
}
|
|
205
215
|
|
|
206
|
-
// Log result.
|
|
207
|
-
if (log) console.log(dotenv);
|
|
208
|
-
|
|
209
|
-
// Load process.env.
|
|
210
|
-
if (loadProcess) Object.assign(process.env, dotenv);
|
|
211
|
-
|
|
212
216
|
// Write output file.
|
|
213
|
-
if (outputPath)
|
|
217
|
+
if (outputPath) {
|
|
218
|
+
outputPath = dotenv[outputKey];
|
|
219
|
+
delete dotenv[outputKey];
|
|
220
|
+
|
|
214
221
|
fs.writeFileSync(
|
|
215
222
|
outputPath,
|
|
216
223
|
Object.keys(dotenv).reduce((contents, key) => {
|
|
@@ -218,8 +225,16 @@ export const getDotenvSync = ({
|
|
|
218
225
|
return `${contents}${key}=${
|
|
219
226
|
value.includes('\n') ? `"${value}"` : value
|
|
220
227
|
}\n`;
|
|
221
|
-
}, '')
|
|
228
|
+
}, ''),
|
|
229
|
+
{ encoding: 'utf-8' }
|
|
222
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);
|
|
223
238
|
|
|
224
239
|
return dotenv;
|
|
225
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",
|