@karmaniverous/get-dotenv 2.3.4 → 2.4.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 +23 -12
- package/bin/getdotenv/index.js +10 -2
- package/dist/default/lib/getDotenv/getDotenv.js +12 -0
- package/lib/getDotenv/getDotenv.js +12 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -77,23 +77,33 @@ 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
|
+
* Drive the current git branch to an environment variable.
|
|
80
81
|
* Exclude public, private, global, environment-specific, or dynamic variables.
|
|
81
82
|
* Execute a &&-delimited series of shell commands after loading variables,
|
|
82
83
|
optionally ignoring errors.
|
|
83
84
|
* Place the shell commands inside the invocation to support npm script
|
|
84
85
|
arguments for other options.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
86
|
+
* Specify the token that identifies dotenv files (e.g. '.env').
|
|
87
|
+
* Specify the token that identifies private vatiables (e.g. '.local').
|
|
88
|
+
|
|
89
|
+
Options:
|
|
90
|
+
-p, --paths <strings...> space-delimited paths to dotenv directory (default './')
|
|
91
|
+
-y, --dynamic-path <string> dynamic variables path
|
|
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
|
+
-d, --default-environment <string> default environment (prefix with $ to use environment variable)
|
|
95
|
+
-e, --environment <string> designated environment (prefix with $ to use environment variable)
|
|
96
|
+
-n, --exclude-env exclude environment-specific variables (default: false)
|
|
97
|
+
-g, --exclude-global exclude global & dynamic variables (default: false)
|
|
98
|
+
-r, --exclude-private exclude private variables (default: false)
|
|
99
|
+
-u, --exclude-public exclude public variables (default: false)
|
|
100
|
+
-z, --exclude-dynamic exclude dynamic variables (default: false)
|
|
101
|
+
-c, --command <string> shell command string
|
|
102
|
+
-l, --log log extracted variables (default: false)
|
|
103
|
+
-t, --dotenv-token <string> token indicating a dotenv file (default: '.env')
|
|
104
|
+
-i, --private-token <string> token indicating private variables (default: 'local')
|
|
105
|
+
-q, --quit-on-error terminate sequential process on error (default: false)
|
|
106
|
+
-h, --help display help for command
|
|
97
107
|
```
|
|
98
108
|
|
|
99
109
|
# API Documentation
|
|
@@ -159,6 +169,7 @@ get-dotenv options type
|
|
|
159
169
|
| [excludeGlobal] | <code>bool</code> | exclude global & dynamic variables (default: false) |
|
|
160
170
|
| [excludePrivate] | <code>bool</code> | exclude private variables (default: false) |
|
|
161
171
|
| [excludePublic] | <code>bool</code> | exclude public variables (default: false) |
|
|
172
|
+
| [gitBranch] | <code>string</code> | environment variable to populate with current git branch |
|
|
162
173
|
| [loadProcess] | <code>bool</code> | load dotenv to process.env (default: false) |
|
|
163
174
|
| [log] | <code>bool</code> | log result to console (default: false) |
|
|
164
175
|
| [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
|
@@ -32,6 +32,7 @@ program
|
|
|
32
32
|
`* Load variables for a specific environment or none.`,
|
|
33
33
|
`* Specify a default environment, override the default with an existing`,
|
|
34
34
|
` environment variable, and override both with a direct setting.`,
|
|
35
|
+
`* Drive the current git branch to an environment variable.`,
|
|
35
36
|
`* Exclude public, private, global, environment-specific, or dynamic variables.`,
|
|
36
37
|
`* Execute a &&-delimited series of shell commands after loading variables,`,
|
|
37
38
|
` optionally ignoring errors.`,
|
|
@@ -54,7 +55,12 @@ program
|
|
|
54
55
|
'consolidated output file (follows dotenv-expand rules using loaded env vars)'
|
|
55
56
|
)
|
|
56
57
|
.option(
|
|
57
|
-
'-
|
|
58
|
+
'-b, --git-branch <string>',
|
|
59
|
+
'environment variable to populate with current git branch',
|
|
60
|
+
envMerge
|
|
61
|
+
)
|
|
62
|
+
.option(
|
|
63
|
+
'-d, --default-environment <string>',
|
|
58
64
|
'default environment (prefix with $ to use environment variable)',
|
|
59
65
|
envMerge
|
|
60
66
|
)
|
|
@@ -95,12 +101,13 @@ const {
|
|
|
95
101
|
command,
|
|
96
102
|
defaultEnvironment,
|
|
97
103
|
dotenvToken,
|
|
104
|
+
dynamicPath,
|
|
98
105
|
environment,
|
|
99
106
|
excludeEnv,
|
|
100
107
|
excludeGlobal,
|
|
101
108
|
excludePrivate,
|
|
102
109
|
excludePublic,
|
|
103
|
-
|
|
110
|
+
gitBranch,
|
|
104
111
|
log,
|
|
105
112
|
outputPath,
|
|
106
113
|
paths,
|
|
@@ -121,6 +128,7 @@ await getDotenv({
|
|
|
121
128
|
excludeGlobal,
|
|
122
129
|
excludePrivate,
|
|
123
130
|
excludePublic,
|
|
131
|
+
gitBranch,
|
|
124
132
|
loadProcess: true,
|
|
125
133
|
dynamicPath,
|
|
126
134
|
log,
|
|
@@ -6,6 +6,7 @@ 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"));
|
|
9
10
|
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
var _uuid = require("uuid");
|
|
11
12
|
var _readDotenv = require("../readDotEnv/readDotenv.js");
|
|
@@ -27,6 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
27
28
|
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
28
29
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
29
30
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
31
|
+
* @property {string} [gitBranch] - environment variable to populate with current git branch
|
|
30
32
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
31
33
|
* @property {bool} [log] - log result to console (default: false)
|
|
32
34
|
* @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})
|
|
@@ -54,6 +56,7 @@ const getDotenv = async function () {
|
|
|
54
56
|
excludeGlobal = false,
|
|
55
57
|
excludePrivate = false,
|
|
56
58
|
excludePublic = false,
|
|
59
|
+
gitBranch,
|
|
57
60
|
loadProcess = false,
|
|
58
61
|
log = false,
|
|
59
62
|
outputPath,
|
|
@@ -85,6 +88,9 @@ const getDotenv = async function () {
|
|
|
85
88
|
}
|
|
86
89
|
});
|
|
87
90
|
|
|
91
|
+
// Add git branch.
|
|
92
|
+
if (gitBranch) dotenv[gitBranch] = await (0, _gitBranch.default)();
|
|
93
|
+
|
|
88
94
|
// Process dynamic variables.
|
|
89
95
|
if (dynamicPath && !excludeDynamic) {
|
|
90
96
|
const dynamic = new Function(`return ${(await _fsExtra.default.readFile(dynamicPath)).toString()}`)()(dotenv);
|
|
@@ -121,6 +127,7 @@ const getDotenv = async function () {
|
|
|
121
127
|
excludeGlobal,
|
|
122
128
|
excludePrivate,
|
|
123
129
|
excludePublic,
|
|
130
|
+
gitBranch,
|
|
124
131
|
loadProcess,
|
|
125
132
|
log,
|
|
126
133
|
outputPath,
|
|
@@ -151,6 +158,7 @@ const getDotenvSync = function () {
|
|
|
151
158
|
excludeGlobal = false,
|
|
152
159
|
excludePrivate = false,
|
|
153
160
|
excludePublic = false,
|
|
161
|
+
gitBranch,
|
|
154
162
|
loadProcess = false,
|
|
155
163
|
log = false,
|
|
156
164
|
outputPath,
|
|
@@ -182,6 +190,9 @@ const getDotenvSync = function () {
|
|
|
182
190
|
}
|
|
183
191
|
});
|
|
184
192
|
|
|
193
|
+
// Add git branch.
|
|
194
|
+
if (gitBranch) dotenv[gitBranch] = _gitBranch.default.sync();
|
|
195
|
+
|
|
185
196
|
// Process dynamic variables.
|
|
186
197
|
if (dynamicPath && !excludeDynamic) {
|
|
187
198
|
const dynamic = new Function(`return ${_fsExtra.default.readFileSync(dynamicPath).toString()}`)()(dotenv);
|
|
@@ -218,6 +229,7 @@ const getDotenvSync = function () {
|
|
|
218
229
|
excludeGlobal,
|
|
219
230
|
excludePrivate,
|
|
220
231
|
excludePublic,
|
|
232
|
+
gitBranch,
|
|
221
233
|
loadProcess,
|
|
222
234
|
log,
|
|
223
235
|
outputPath,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// npm imports
|
|
2
2
|
import { expand } from 'dotenv-expand';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
|
+
import branch from 'git-branch';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import { v4 as uuid } from 'uuid';
|
|
6
7
|
|
|
@@ -20,6 +21,7 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
|
20
21
|
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
21
22
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
22
23
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
24
|
+
* @property {string} [gitBranch] - environment variable to populate with current git branch
|
|
23
25
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
24
26
|
* @property {bool} [log] - log result to console (default: false)
|
|
25
27
|
* @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})
|
|
@@ -46,6 +48,7 @@ export const getDotenv = async ({
|
|
|
46
48
|
excludeGlobal = false,
|
|
47
49
|
excludePrivate = false,
|
|
48
50
|
excludePublic = false,
|
|
51
|
+
gitBranch,
|
|
49
52
|
loadProcess = false,
|
|
50
53
|
log = false,
|
|
51
54
|
outputPath,
|
|
@@ -93,6 +96,9 @@ export const getDotenv = async ({
|
|
|
93
96
|
},
|
|
94
97
|
});
|
|
95
98
|
|
|
99
|
+
// Add git branch.
|
|
100
|
+
if (gitBranch) dotenv[gitBranch] = await branch();
|
|
101
|
+
|
|
96
102
|
// Process dynamic variables.
|
|
97
103
|
if (dynamicPath && !excludeDynamic) {
|
|
98
104
|
const dynamic = new Function(
|
|
@@ -140,6 +146,7 @@ export const getDotenv = async ({
|
|
|
140
146
|
excludeGlobal,
|
|
141
147
|
excludePrivate,
|
|
142
148
|
excludePublic,
|
|
149
|
+
gitBranch,
|
|
143
150
|
loadProcess,
|
|
144
151
|
log,
|
|
145
152
|
outputPath,
|
|
@@ -169,6 +176,7 @@ export const getDotenvSync = ({
|
|
|
169
176
|
excludeGlobal = false,
|
|
170
177
|
excludePrivate = false,
|
|
171
178
|
excludePublic = false,
|
|
179
|
+
gitBranch,
|
|
172
180
|
loadProcess = false,
|
|
173
181
|
log = false,
|
|
174
182
|
outputPath,
|
|
@@ -216,6 +224,9 @@ export const getDotenvSync = ({
|
|
|
216
224
|
},
|
|
217
225
|
});
|
|
218
226
|
|
|
227
|
+
// Add git branch.
|
|
228
|
+
if (gitBranch) dotenv[gitBranch] = branch.sync();
|
|
229
|
+
|
|
219
230
|
// Process dynamic variables.
|
|
220
231
|
if (dynamicPath && !excludeDynamic) {
|
|
221
232
|
const dynamic = new Function(
|
|
@@ -263,6 +274,7 @@ export const getDotenvSync = ({
|
|
|
263
274
|
excludeGlobal,
|
|
264
275
|
excludePrivate,
|
|
265
276
|
excludePublic,
|
|
277
|
+
gitBranch,
|
|
266
278
|
loadProcess,
|
|
267
279
|
log,
|
|
268
280
|
outputPath,
|
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.4.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dotenv": "^16.0.3",
|
|
37
37
|
"dotenv-expand": "^10.0.0",
|
|
38
38
|
"fs-extra": "^11.1.1",
|
|
39
|
+
"git-branch": "^2.0.1",
|
|
39
40
|
"string-argv": "^0.3.2",
|
|
40
41
|
"uuid": "^9.0.0"
|
|
41
42
|
},
|
|
@@ -46,10 +47,10 @@
|
|
|
46
47
|
"@babel/plugin-syntax-import-assertions": "^7.20.0",
|
|
47
48
|
"@babel/preset-env": "^7.21.5",
|
|
48
49
|
"@babel/register": "^7.21.0",
|
|
49
|
-
"@types/node": "^20.
|
|
50
|
+
"@types/node": "^20.2.1",
|
|
50
51
|
"chai": "^4.3.7",
|
|
51
52
|
"concat-md": "^0.5.1",
|
|
52
|
-
"eslint": "^8.
|
|
53
|
+
"eslint": "^8.41.0",
|
|
53
54
|
"eslint-config-standard": "^17.0.0",
|
|
54
55
|
"eslint-plugin-mocha": "^10.1.0",
|
|
55
56
|
"jsdoc-to-markdown": "^8.0.0",
|