@karmaniverous/get-dotenv 1.1.1 → 1.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 +8 -2
- package/bin/getdotenv/index.js +13 -0
- package/dist/default/lib/getDotenv/getDotenv.js +15 -9
- package/lib/getDotenv/getDotenv.js +27 -13
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -73,13 +73,15 @@ dotenv files. You can:
|
|
|
73
73
|
* Specify the directories containing your dotenv files.
|
|
74
74
|
* Specify the token that identifies dotenv files (e.g. '.env').
|
|
75
75
|
* Specify the token that identifies private vatiables (e.g. '.local').
|
|
76
|
+
* Load variables for a specific environment or none.
|
|
76
77
|
* Specify a default environment, override the default with an existing
|
|
77
78
|
environment variable, and override both with a direct setting.
|
|
78
79
|
* Exclude public or private variables.
|
|
80
|
+
* Exclude global & dynamic or environment-specific variables.
|
|
79
81
|
* Define dynamic variables progressively in terms of other variables and
|
|
80
82
|
other logic.
|
|
81
|
-
* Execute a shell
|
|
82
|
-
* Place the shell
|
|
83
|
+
* Execute a &&-delimited series of shell commands after loading variables.
|
|
84
|
+
* Place the shell commands inside the invocation to support npm script
|
|
83
85
|
arguments for other options.
|
|
84
86
|
|
|
85
87
|
Options:
|
|
@@ -89,6 +91,8 @@ Options:
|
|
|
89
91
|
-d, --defaultEnvironment <string> default environment
|
|
90
92
|
-e, --environment <string> designated environment
|
|
91
93
|
-v, --variable <string> environment from variable
|
|
94
|
+
-n, --exclude-env exclude environment-specific variables (default: false)
|
|
95
|
+
-g, --exclude-global exclude global & dynamic variables (default: false)
|
|
92
96
|
-r, --exclude-private exclude private variables (default: false)
|
|
93
97
|
-u, --exclude-public exclude public variables (default: false)
|
|
94
98
|
-y, --dynamic-path <string> dynamic variables path
|
|
@@ -155,6 +159,8 @@ get-dotenv options type
|
|
|
155
159
|
| [dotenvToken] | <code>string</code> | token indicating a dotenv file (default: '.env') |
|
|
156
160
|
| [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
|
|
157
161
|
| [env] | <code>string</code> | target environment |
|
|
162
|
+
| [excludeEnv] | <code>bool</code> | exclude environment-specific variables (default: false) |
|
|
163
|
+
| [excludeGlobal] | <code>bool</code> | exclude global & dynamic variables (default: false) |
|
|
158
164
|
| [excludePrivate] | <code>bool</code> | exclude private variables (default: false) |
|
|
159
165
|
| [excludePublic] | <code>bool</code> | exclude public variables (default: false) |
|
|
160
166
|
| [loadProcess] | <code>bool</code> | load dotenv to process.env (default: false) |
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -26,6 +26,7 @@ program
|
|
|
26
26
|
`* Specify a default environment, override the default with an existing`,
|
|
27
27
|
` environment variable, and override both with a direct setting.`,
|
|
28
28
|
`* Exclude public or private variables.`,
|
|
29
|
+
`* Exclude global & dynamic or environment-specific variables.`,
|
|
29
30
|
`* Define dynamic variables progressively in terms of other variables and`,
|
|
30
31
|
` other logic.`,
|
|
31
32
|
`* Execute a &&-delimited series of shell commands after loading variables.`,
|
|
@@ -51,6 +52,14 @@ program
|
|
|
51
52
|
.option('-d, --defaultEnvironment <string>', 'default environment')
|
|
52
53
|
.option('-e, --environment <string>', 'designated environment')
|
|
53
54
|
.option('-v, --variable <string>', 'environment from variable')
|
|
55
|
+
.option(
|
|
56
|
+
'-n, --exclude-env',
|
|
57
|
+
'exclude environment-specific variables (default: false)'
|
|
58
|
+
)
|
|
59
|
+
.option(
|
|
60
|
+
'-g, --exclude-global',
|
|
61
|
+
'exclude global & dynamic variables (default: false)'
|
|
62
|
+
)
|
|
54
63
|
.option('-r, --exclude-private', 'exclude private variables (default: false)')
|
|
55
64
|
.option('-u, --exclude-public', 'exclude public variables (default: false)')
|
|
56
65
|
.option('-y, --dynamic-path <string>', 'dynamic variables path')
|
|
@@ -64,6 +73,8 @@ const {
|
|
|
64
73
|
defaultEnvironment,
|
|
65
74
|
dotenvToken,
|
|
66
75
|
environment,
|
|
76
|
+
excludeEnv,
|
|
77
|
+
excludeGlobal,
|
|
67
78
|
excludePrivate,
|
|
68
79
|
excludePublic,
|
|
69
80
|
dynamicPath,
|
|
@@ -82,6 +93,8 @@ const env = environment ?? process.env[variable] ?? defaultEnvironment;
|
|
|
82
93
|
await getDotenv({
|
|
83
94
|
dotenvToken,
|
|
84
95
|
env,
|
|
96
|
+
excludeEnv,
|
|
97
|
+
excludeGlobal,
|
|
85
98
|
excludePrivate,
|
|
86
99
|
excludePublic,
|
|
87
100
|
loadProcess: true,
|
|
@@ -21,6 +21,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
21
|
* @property {string} [dotenvToken] - token indicating a dotenv file (default: '.env')
|
|
22
22
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
23
23
|
* @property {string} [env] - target environment
|
|
24
|
+
* @property {bool} [excludeEnv] - exclude environment-specific variables (default: false)
|
|
25
|
+
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
24
26
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
25
27
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
26
28
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
@@ -44,6 +46,8 @@ const getDotenv = async function () {
|
|
|
44
46
|
dotenvToken = '.env',
|
|
45
47
|
env,
|
|
46
48
|
dynamicPath,
|
|
49
|
+
excludeEnv = false,
|
|
50
|
+
excludeGlobal = false,
|
|
47
51
|
excludePrivate = false,
|
|
48
52
|
excludePublic = false,
|
|
49
53
|
loadProcess = false,
|
|
@@ -55,12 +59,12 @@ const getDotenv = async function () {
|
|
|
55
59
|
const parsed = await paths.reduce(async (e, p) => ({
|
|
56
60
|
...(await e),
|
|
57
61
|
...(excludePublic ? {} : {
|
|
58
|
-
...(await (0, _readDotenv.readDotenv)(_path.default.resolve(p, dotenvToken))),
|
|
59
|
-
...(env ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}`)) : {})
|
|
62
|
+
...(excludeGlobal ? {} : await (0, _readDotenv.readDotenv)(_path.default.resolve(p, dotenvToken))),
|
|
63
|
+
...(env && !excludeEnv ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}`)) : {})
|
|
60
64
|
}),
|
|
61
65
|
...(excludePrivate ? {} : {
|
|
62
|
-
...(await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
|
|
63
|
-
...(env ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
|
|
66
|
+
...(excludeGlobal ? {} : await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
|
|
67
|
+
...(env && !excludeEnv ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
|
|
64
68
|
})
|
|
65
69
|
}), []);
|
|
66
70
|
const {
|
|
@@ -105,6 +109,8 @@ const getDotenvSync = function () {
|
|
|
105
109
|
dotenvToken = '.env',
|
|
106
110
|
dynamicPath,
|
|
107
111
|
env,
|
|
112
|
+
excludeEnv = false,
|
|
113
|
+
excludeGlobal = false,
|
|
108
114
|
excludePrivate = false,
|
|
109
115
|
excludePublic = false,
|
|
110
116
|
loadProcess = false,
|
|
@@ -116,12 +122,12 @@ const getDotenvSync = function () {
|
|
|
116
122
|
const parsed = paths.reduce((e, p) => ({
|
|
117
123
|
...e,
|
|
118
124
|
...(excludePublic ? {} : {
|
|
119
|
-
...(0, _readDotenv.readDotenvSync)(_path.default.resolve(p, dotenvToken)),
|
|
120
|
-
...(env ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}`)) : {})
|
|
125
|
+
...(excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, dotenvToken))),
|
|
126
|
+
...(env && !excludeEnv ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}`)) : {})
|
|
121
127
|
}),
|
|
122
128
|
...(excludePrivate ? {} : {
|
|
123
|
-
...(0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`)),
|
|
124
|
-
...(env ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
|
|
129
|
+
...(excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
|
|
130
|
+
...(env && !excludeEnv ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
|
|
125
131
|
})
|
|
126
132
|
}), []);
|
|
127
133
|
const {
|
|
@@ -134,7 +140,7 @@ const getDotenvSync = function () {
|
|
|
134
140
|
if (error) throw new Error(error);
|
|
135
141
|
|
|
136
142
|
// Process dynamic variables.
|
|
137
|
-
if (dynamicPath) {
|
|
143
|
+
if (!excludePublic && dynamicPath) {
|
|
138
144
|
const dynamic = new Function(`return ${_fsExtra.default.readFileSync(dynamicPath).toString()}`)()(dotenv);
|
|
139
145
|
Object.keys(dynamic).forEach(key => {
|
|
140
146
|
Object.assign(dotenv, {
|
|
@@ -14,6 +14,8 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
|
14
14
|
* @property {string} [dotenvToken] - token indicating a dotenv file (default: '.env')
|
|
15
15
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
16
16
|
* @property {string} [env] - target environment
|
|
17
|
+
* @property {bool} [excludeEnv] - exclude environment-specific variables (default: false)
|
|
18
|
+
* @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
|
|
17
19
|
* @property {bool} [excludePrivate] - exclude private variables (default: false)
|
|
18
20
|
* @property {bool} [excludePublic] - exclude public variables (default: false)
|
|
19
21
|
* @property {bool} [loadProcess] - load dotenv to process.env (default: false)
|
|
@@ -36,6 +38,8 @@ export const getDotenv = async ({
|
|
|
36
38
|
dotenvToken = '.env',
|
|
37
39
|
env,
|
|
38
40
|
dynamicPath,
|
|
41
|
+
excludeEnv = false,
|
|
42
|
+
excludeGlobal = false,
|
|
39
43
|
excludePrivate = false,
|
|
40
44
|
excludePublic = false,
|
|
41
45
|
loadProcess = false,
|
|
@@ -50,18 +54,22 @@ export const getDotenv = async ({
|
|
|
50
54
|
...(excludePublic
|
|
51
55
|
? {}
|
|
52
56
|
: {
|
|
53
|
-
...(
|
|
54
|
-
|
|
57
|
+
...(excludeGlobal
|
|
58
|
+
? {}
|
|
59
|
+
: await readDotenv(path.resolve(p, dotenvToken))),
|
|
60
|
+
...(env && !excludeEnv
|
|
55
61
|
? await readDotenv(path.resolve(p, `${dotenvToken}.${env}`))
|
|
56
62
|
: {}),
|
|
57
63
|
}),
|
|
58
64
|
...(excludePrivate
|
|
59
65
|
? {}
|
|
60
66
|
: {
|
|
61
|
-
...(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
...(excludeGlobal
|
|
68
|
+
? {}
|
|
69
|
+
: await readDotenv(
|
|
70
|
+
path.resolve(p, `${dotenvToken}.${privateToken}`)
|
|
71
|
+
)),
|
|
72
|
+
...(env && !excludeEnv
|
|
65
73
|
? await readDotenv(
|
|
66
74
|
path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
|
|
67
75
|
)
|
|
@@ -110,6 +118,8 @@ export const getDotenvSync = ({
|
|
|
110
118
|
dotenvToken = '.env',
|
|
111
119
|
dynamicPath,
|
|
112
120
|
env,
|
|
121
|
+
excludeEnv = false,
|
|
122
|
+
excludeGlobal = false,
|
|
113
123
|
excludePrivate = false,
|
|
114
124
|
excludePublic = false,
|
|
115
125
|
loadProcess = false,
|
|
@@ -124,18 +134,22 @@ export const getDotenvSync = ({
|
|
|
124
134
|
...(excludePublic
|
|
125
135
|
? {}
|
|
126
136
|
: {
|
|
127
|
-
...
|
|
128
|
-
|
|
137
|
+
...(excludeGlobal
|
|
138
|
+
? {}
|
|
139
|
+
: readDotenvSync(path.resolve(p, dotenvToken))),
|
|
140
|
+
...(env && !excludeEnv
|
|
129
141
|
? readDotenvSync(path.resolve(p, `${dotenvToken}.${env}`))
|
|
130
142
|
: {}),
|
|
131
143
|
}),
|
|
132
144
|
...(excludePrivate
|
|
133
145
|
? {}
|
|
134
146
|
: {
|
|
135
|
-
...
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
...(excludeGlobal
|
|
148
|
+
? {}
|
|
149
|
+
: readDotenvSync(
|
|
150
|
+
path.resolve(p, `${dotenvToken}.${privateToken}`)
|
|
151
|
+
)),
|
|
152
|
+
...(env && !excludeEnv
|
|
139
153
|
? readDotenvSync(
|
|
140
154
|
path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
|
|
141
155
|
)
|
|
@@ -153,7 +167,7 @@ export const getDotenvSync = ({
|
|
|
153
167
|
if (error) throw new Error(error);
|
|
154
168
|
|
|
155
169
|
// Process dynamic variables.
|
|
156
|
-
if (dynamicPath) {
|
|
170
|
+
if (!excludePublic && dynamicPath) {
|
|
157
171
|
const dynamic = new Function(
|
|
158
172
|
`return ${fs.readFileSync(dynamicPath).toString()}`
|
|
159
173
|
)()(dotenv);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"bin": {
|
|
4
4
|
"getdotenv": "bin/getdotenv/index.js"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.2.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
|
+
"cli": "node ./bin/getdotenv",
|
|
85
86
|
"lint": "eslint lib/** bin/**",
|
|
86
87
|
"test": "mocha",
|
|
87
88
|
"build": "babel lib -d dist/default/lib --delete-dir-on-start --config-file ./dist/default/.babelrc",
|