@karmaniverous/get-dotenv 2.4.0 → 2.4.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 +2 -3
- package/bin/getdotenv/index.js +11 -8
- package/dist/default/lib/getDotenv/getDotenv.js +0 -12
- package/lib/getDotenv/getDotenv.js +0 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ dotenv files. You can:
|
|
|
77
77
|
* Load variables for a specific environment or none.
|
|
78
78
|
* Specify a default environment, override the default with an existing
|
|
79
79
|
environment variable, and override both with a direct setting.
|
|
80
|
-
*
|
|
80
|
+
* Derive the default environment from the current git branch
|
|
81
81
|
* Exclude public, private, global, environment-specific, or dynamic variables.
|
|
82
82
|
* Execute a &&-delimited series of shell commands after loading variables,
|
|
83
83
|
optionally ignoring errors.
|
|
@@ -90,8 +90,8 @@ Options:
|
|
|
90
90
|
-p, --paths <strings...> space-delimited paths to dotenv directory (default './')
|
|
91
91
|
-y, --dynamic-path <string> dynamic variables path
|
|
92
92
|
-o, --output-path <string> consolidated output file (follows dotenv-expand rules using loaded env vars)
|
|
93
|
-
-b, --git-branch <string> environment variable to populate with current git branch
|
|
94
93
|
-d, --default-environment <string> default environment (prefix with $ to use environment variable)
|
|
94
|
+
-b, --branch-to-default derive default environment from the current git branch (default: false)
|
|
95
95
|
-e, --environment <string> designated environment (prefix with $ to use environment variable)
|
|
96
96
|
-n, --exclude-env exclude environment-specific variables (default: false)
|
|
97
97
|
-g, --exclude-global exclude global & dynamic variables (default: false)
|
|
@@ -169,7 +169,6 @@ get-dotenv options type
|
|
|
169
169
|
| [excludeGlobal] | <code>bool</code> | exclude global & dynamic variables (default: false) |
|
|
170
170
|
| [excludePrivate] | <code>bool</code> | exclude private variables (default: false) |
|
|
171
171
|
| [excludePublic] | <code>bool</code> | exclude public variables (default: false) |
|
|
172
|
-
| [gitBranch] | <code>string</code> | environment variable to populate with current git branch |
|
|
173
172
|
| [loadProcess] | <code>bool</code> | load dotenv to process.env (default: false) |
|
|
174
173
|
| [log] | <code>bool</code> | log result to console (default: false) |
|
|
175
174
|
| [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)) |
|
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 branch from 'git-branch';
|
|
5
6
|
import _ from 'lodash';
|
|
6
7
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
7
8
|
|
|
@@ -32,7 +33,7 @@ program
|
|
|
32
33
|
`* Load variables for a specific environment or none.`,
|
|
33
34
|
`* Specify a default environment, override the default with an existing`,
|
|
34
35
|
` environment variable, and override both with a direct setting.`,
|
|
35
|
-
`*
|
|
36
|
+
`* Derive the default environment from the current git branch`,
|
|
36
37
|
`* Exclude public, private, global, environment-specific, or dynamic variables.`,
|
|
37
38
|
`* Execute a &&-delimited series of shell commands after loading variables,`,
|
|
38
39
|
` optionally ignoring errors.`,
|
|
@@ -55,13 +56,13 @@ program
|
|
|
55
56
|
'consolidated output file (follows dotenv-expand rules using loaded env vars)'
|
|
56
57
|
)
|
|
57
58
|
.option(
|
|
58
|
-
'-
|
|
59
|
-
'environment
|
|
59
|
+
'-d, --default-environment <string>',
|
|
60
|
+
'default environment (prefix with $ to use environment variable)',
|
|
60
61
|
envMerge
|
|
61
62
|
)
|
|
62
63
|
.option(
|
|
63
|
-
'-
|
|
64
|
-
'default environment
|
|
64
|
+
'-b, --branch-to-default',
|
|
65
|
+
'derive default environment from the current git branch (default: false)',
|
|
65
66
|
envMerge
|
|
66
67
|
)
|
|
67
68
|
.option(
|
|
@@ -98,6 +99,7 @@ program
|
|
|
98
99
|
// Parse CLI options from command line.
|
|
99
100
|
program.parse();
|
|
100
101
|
const {
|
|
102
|
+
branchToDefault,
|
|
101
103
|
command,
|
|
102
104
|
defaultEnvironment,
|
|
103
105
|
dotenvToken,
|
|
@@ -107,7 +109,6 @@ const {
|
|
|
107
109
|
excludeGlobal,
|
|
108
110
|
excludePrivate,
|
|
109
111
|
excludePublic,
|
|
110
|
-
gitBranch,
|
|
111
112
|
log,
|
|
112
113
|
outputPath,
|
|
113
114
|
paths,
|
|
@@ -118,7 +119,10 @@ const {
|
|
|
118
119
|
if (command && program.args.length) program.error('command specified twice');
|
|
119
120
|
|
|
120
121
|
// Get environment.
|
|
121
|
-
const env =
|
|
122
|
+
const env =
|
|
123
|
+
environment ??
|
|
124
|
+
defaultEnvironment ??
|
|
125
|
+
(branchToDefault ? branch.sync() : undefined);
|
|
122
126
|
|
|
123
127
|
// Load dotenvs.
|
|
124
128
|
await getDotenv({
|
|
@@ -128,7 +132,6 @@ await getDotenv({
|
|
|
128
132
|
excludeGlobal,
|
|
129
133
|
excludePrivate,
|
|
130
134
|
excludePublic,
|
|
131
|
-
gitBranch,
|
|
132
135
|
loadProcess: true,
|
|
133
136
|
dynamicPath,
|
|
134
137
|
log,
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getDotenvSync = exports.getDotenv = void 0;
|
|
7
7
|
var _dotenvExpand = require("dotenv-expand");
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
|
-
var _gitBranch = _interopRequireDefault(require("git-branch"));
|
|
10
9
|
var _path = _interopRequireDefault(require("path"));
|
|
11
10
|
var _uuid = require("uuid");
|
|
12
11
|
var _readDotenv = require("../readDotEnv/readDotenv.js");
|
|
@@ -28,7 +27,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
28
27
|
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
29
28
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
30
29
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
31
|
-
* @property {string} [gitBranch] - environment variable to populate with current git branch
|
|
32
30
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
33
31
|
* @property {bool} [log] - log result to console (default: false)
|
|
34
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})
|
|
@@ -56,7 +54,6 @@ const getDotenv = async function () {
|
|
|
56
54
|
excludeGlobal = false,
|
|
57
55
|
excludePrivate = false,
|
|
58
56
|
excludePublic = false,
|
|
59
|
-
gitBranch,
|
|
60
57
|
loadProcess = false,
|
|
61
58
|
log = false,
|
|
62
59
|
outputPath,
|
|
@@ -88,9 +85,6 @@ const getDotenv = async function () {
|
|
|
88
85
|
}
|
|
89
86
|
});
|
|
90
87
|
|
|
91
|
-
// Add git branch.
|
|
92
|
-
if (gitBranch) dotenv[gitBranch] = await (0, _gitBranch.default)();
|
|
93
|
-
|
|
94
88
|
// Process dynamic variables.
|
|
95
89
|
if (dynamicPath && !excludeDynamic) {
|
|
96
90
|
const dynamic = new Function(`return ${(await _fsExtra.default.readFile(dynamicPath)).toString()}`)()(dotenv);
|
|
@@ -127,7 +121,6 @@ const getDotenv = async function () {
|
|
|
127
121
|
excludeGlobal,
|
|
128
122
|
excludePrivate,
|
|
129
123
|
excludePublic,
|
|
130
|
-
gitBranch,
|
|
131
124
|
loadProcess,
|
|
132
125
|
log,
|
|
133
126
|
outputPath,
|
|
@@ -158,7 +151,6 @@ const getDotenvSync = function () {
|
|
|
158
151
|
excludeGlobal = false,
|
|
159
152
|
excludePrivate = false,
|
|
160
153
|
excludePublic = false,
|
|
161
|
-
gitBranch,
|
|
162
154
|
loadProcess = false,
|
|
163
155
|
log = false,
|
|
164
156
|
outputPath,
|
|
@@ -190,9 +182,6 @@ const getDotenvSync = function () {
|
|
|
190
182
|
}
|
|
191
183
|
});
|
|
192
184
|
|
|
193
|
-
// Add git branch.
|
|
194
|
-
if (gitBranch) dotenv[gitBranch] = _gitBranch.default.sync();
|
|
195
|
-
|
|
196
185
|
// Process dynamic variables.
|
|
197
186
|
if (dynamicPath && !excludeDynamic) {
|
|
198
187
|
const dynamic = new Function(`return ${_fsExtra.default.readFileSync(dynamicPath).toString()}`)()(dotenv);
|
|
@@ -229,7 +218,6 @@ const getDotenvSync = function () {
|
|
|
229
218
|
excludeGlobal,
|
|
230
219
|
excludePrivate,
|
|
231
220
|
excludePublic,
|
|
232
|
-
gitBranch,
|
|
233
221
|
loadProcess,
|
|
234
222
|
log,
|
|
235
223
|
outputPath,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// npm imports
|
|
2
2
|
import { expand } from 'dotenv-expand';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
|
-
import branch from 'git-branch';
|
|
5
4
|
import path from 'path';
|
|
6
5
|
import { v4 as uuid } from 'uuid';
|
|
7
6
|
|
|
@@ -21,7 +20,6 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
|
21
20
|
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
22
21
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
23
22
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
24
|
-
* @property {string} [gitBranch] - environment variable to populate with current git branch
|
|
25
23
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
26
24
|
* @property {bool} [log] - log result to console (default: false)
|
|
27
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})
|
|
@@ -48,7 +46,6 @@ export const getDotenv = async ({
|
|
|
48
46
|
excludeGlobal = false,
|
|
49
47
|
excludePrivate = false,
|
|
50
48
|
excludePublic = false,
|
|
51
|
-
gitBranch,
|
|
52
49
|
loadProcess = false,
|
|
53
50
|
log = false,
|
|
54
51
|
outputPath,
|
|
@@ -96,9 +93,6 @@ export const getDotenv = async ({
|
|
|
96
93
|
},
|
|
97
94
|
});
|
|
98
95
|
|
|
99
|
-
// Add git branch.
|
|
100
|
-
if (gitBranch) dotenv[gitBranch] = await branch();
|
|
101
|
-
|
|
102
96
|
// Process dynamic variables.
|
|
103
97
|
if (dynamicPath && !excludeDynamic) {
|
|
104
98
|
const dynamic = new Function(
|
|
@@ -146,7 +140,6 @@ export const getDotenv = async ({
|
|
|
146
140
|
excludeGlobal,
|
|
147
141
|
excludePrivate,
|
|
148
142
|
excludePublic,
|
|
149
|
-
gitBranch,
|
|
150
143
|
loadProcess,
|
|
151
144
|
log,
|
|
152
145
|
outputPath,
|
|
@@ -176,7 +169,6 @@ export const getDotenvSync = ({
|
|
|
176
169
|
excludeGlobal = false,
|
|
177
170
|
excludePrivate = false,
|
|
178
171
|
excludePublic = false,
|
|
179
|
-
gitBranch,
|
|
180
172
|
loadProcess = false,
|
|
181
173
|
log = false,
|
|
182
174
|
outputPath,
|
|
@@ -224,9 +216,6 @@ export const getDotenvSync = ({
|
|
|
224
216
|
},
|
|
225
217
|
});
|
|
226
218
|
|
|
227
|
-
// Add git branch.
|
|
228
|
-
if (gitBranch) dotenv[gitBranch] = branch.sync();
|
|
229
|
-
|
|
230
219
|
// Process dynamic variables.
|
|
231
220
|
if (dynamicPath && !excludeDynamic) {
|
|
232
221
|
const dynamic = new Function(
|
|
@@ -274,7 +263,6 @@ export const getDotenvSync = ({
|
|
|
274
263
|
excludeGlobal,
|
|
275
264
|
excludePrivate,
|
|
276
265
|
excludePublic,
|
|
277
|
-
gitBranch,
|
|
278
266
|
loadProcess,
|
|
279
267
|
log,
|
|
280
268
|
outputPath,
|