@karmaniverous/get-dotenv 0.1.2 → 0.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.
@@ -0,0 +1 @@
1
+ ENV_SECRET=root_dev_secret
package/.env.secret ADDED
@@ -0,0 +1 @@
1
+ APP_SECRET=root_app_secret
package/README.md CHANGED
@@ -49,7 +49,7 @@ Usage: getdotenv [options] [-- [command]]
49
49
  Load environment variables with a cascade of environment-aware
50
50
  dotenv files. You can:
51
51
 
52
- * Specify the directory containing your dotenv files.
52
+ * Specify the directories containing your dotenv files.
53
53
  * Specify the token that identifies dotenv files (e.g. '.env').
54
54
  * Specify the token that identifies private vatiables (e.g. '.local').
55
55
  * Specify a default environment, override the default with an existing
@@ -60,7 +60,7 @@ dotenv files. You can:
60
60
  arguments for other options.
61
61
 
62
62
  Options:
63
- -p, --path <string> path to dotenv directory (default './')
63
+ -p, --paths <strings...> space-delimited paths to dotenv directory (default './')
64
64
  -t, --dotenv-token <string> token indicating a dotenv file (default: '.env')
65
65
  -i, --private-token <string> token indicating private variables (default: 'local')
66
66
  -d, --defaultEnvironment <string> default environment
@@ -134,7 +134,7 @@ get-dotenv options type
134
134
  | [excludePublic] | <code>bool</code> | exclude public variables (default: false) |
135
135
  | [loadProcess] | <code>bool</code> | load dotenv to process.env (default: false) |
136
136
  | [log] | <code>bool</code> | log result to console (default: false) |
137
- | [path] | <code>string</code> | path to target directory (default './') |
137
+ | [paths] | <code>Array.&lt;string&gt;</code> | array of target directory paths (default ['./']) |
138
138
  | [privateToken] | <code>string</code> | token indicating private variables (default: 'local'). |
139
139
 
140
140
 
@@ -19,7 +19,7 @@ program
19
19
  `Load environment variables with a cascade of environment-aware`,
20
20
  `dotenv files. You can:`,
21
21
  ``,
22
- `* Specify the directory containing your dotenv files.`,
22
+ `* Specify the directories containing your dotenv files.`,
23
23
  `* Specify the token that identifies dotenv files (e.g. '.env').`,
24
24
  `* Specify the token that identifies private vatiables (e.g. '.local').`,
25
25
  `* Specify a default environment, override the default with an existing`,
@@ -33,7 +33,10 @@ program
33
33
 
34
34
  // CLI options.
35
35
  program
36
- .option('-p, --path <string>', "path to dotenv directory (default './')")
36
+ .option(
37
+ '-p, --paths <strings...>',
38
+ "space-delimited paths to dotenv directory (default './')"
39
+ )
37
40
  .option(
38
41
  '-t, --dotenv-token <string>',
39
42
  "token indicating a dotenv file (default: '.env')"
@@ -60,12 +63,12 @@ const {
60
63
  excludePrivate,
61
64
  excludePublic,
62
65
  log,
63
- path,
66
+ paths,
64
67
  privateToken,
65
68
  variable,
66
69
  } = program.opts();
67
70
 
68
- if (command && program.args) program.error('command specified twice');
71
+ if (command && program.args.length) program.error('command specified twice');
69
72
 
70
73
  // Get environment.
71
74
  const env = environment ?? process.env[variable] ?? defaultEnvironment;
@@ -78,7 +81,7 @@ getDotenvSync({
78
81
  excludePublic,
79
82
  loadProcess: true,
80
83
  log,
81
- path,
84
+ paths,
82
85
  privateToken,
83
86
  });
84
87
 
@@ -19,7 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
  * @property {bool} [excludePublic] - exclude public variables (default: false)
20
20
  * @property {bool} [loadProcess] - load dotenv to process.env (default: false)
21
21
  * @property {bool} [log] - log result to console (default: false)
22
- * @property {string} [path] - path to target directory (default './')
22
+ * @property {string[]} [paths] - array of target directory paths (default ['./'])
23
23
  * @property {string} [privateToken] - token indicating private variables (default: 'local').
24
24
  */
25
25
 
@@ -41,20 +41,21 @@ const getDotenv = async function () {
41
41
  excludePublic = false,
42
42
  loadProcess = false,
43
43
  log = false,
44
- path: dotenvPath = './',
44
+ paths = ['./'],
45
45
  privateToken = 'local'
46
46
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
47
47
  // Read .env files.
48
- const dotenv = (0, _dotenvExpand.expand)({
48
+ const dotenv = (0, _dotenvExpand.expand)(await paths.reduce(async (e, p) => ({
49
+ ...(await e),
49
50
  ...(excludePublic ? {} : {
50
- ...(await (0, _readDotenv.readDotenv)(_path.default.resolve(dotenvPath, dotenvToken))),
51
- ...(env ? await (0, _readDotenv.readDotenv)(_path.default.resolve(dotenvPath, `${dotenvToken}.${env}`)) : {})
51
+ ...(await (0, _readDotenv.readDotenv)(_path.default.resolve(p, dotenvToken))),
52
+ ...(env ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}`)) : {})
52
53
  }),
53
54
  ...(excludePrivate ? {} : {
54
- ...(await (0, _readDotenv.readDotenv)(_path.default.resolve(dotenvPath, `${dotenvToken}.${privateToken}`))),
55
- ...(env ? await (0, _readDotenv.readDotenv)(_path.default.resolve(dotenvPath, `${dotenvToken}.${env}.${privateToken}`)) : {})
55
+ ...(await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
56
+ ...(env ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
56
57
  })
57
- });
58
+ }), []));
58
59
 
59
60
  // Log result.
60
61
  if (log) console.log(dotenv);
@@ -82,20 +83,21 @@ const getDotenvSync = function () {
82
83
  excludePublic = false,
83
84
  loadProcess = false,
84
85
  log = false,
85
- path: dotenvPath = './',
86
+ paths = ['./'],
86
87
  privateToken = 'local'
87
88
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
88
89
  // Read .env files.
89
- const dotenv = (0, _dotenvExpand.expand)({
90
+ const dotenv = (0, _dotenvExpand.expand)(paths.reduce((e, p) => ({
91
+ ...e,
90
92
  ...(excludePublic ? {} : {
91
- ...(0, _readDotenv.readDotenvSync)(_path.default.resolve(dotenvPath, dotenvToken)),
92
- ...(env ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(dotenvPath, `${dotenvToken}.${env}`)) : {})
93
+ ...(0, _readDotenv.readDotenvSync)(_path.default.resolve(p, dotenvToken)),
94
+ ...(env ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}`)) : {})
93
95
  }),
94
96
  ...(excludePrivate ? {} : {
95
- ...(0, _readDotenv.readDotenvSync)(_path.default.resolve(dotenvPath, `${dotenvToken}.${privateToken}`)),
96
- ...(env ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(dotenvPath, `${dotenvToken}.${env}.${privateToken}`)) : {})
97
+ ...(0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`)),
98
+ ...(env ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
97
99
  })
98
- });
100
+ }), []));
99
101
 
100
102
  // Log result.
101
103
  if (log) console.log(dotenv);
@@ -13,7 +13,7 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
13
13
  * @property {bool} [excludePublic] - exclude public variables (default: false)
14
14
  * @property {bool} [loadProcess] - load dotenv to process.env (default: false)
15
15
  * @property {bool} [log] - log result to console (default: false)
16
- * @property {string} [path] - path to target directory (default './')
16
+ * @property {string[]} [paths] - array of target directory paths (default ['./'])
17
17
  * @property {string} [privateToken] - token indicating private variables (default: 'local').
18
18
  */
19
19
 
@@ -34,37 +34,38 @@ export const getDotenv = async ({
34
34
  excludePublic = false,
35
35
  loadProcess = false,
36
36
  log = false,
37
- path: dotenvPath = './',
37
+ paths = ['./'],
38
38
  privateToken = 'local',
39
39
  } = {}) => {
40
40
  // Read .env files.
41
- const dotenv = expand({
42
- ...(excludePublic
43
- ? {}
44
- : {
45
- ...(await readDotenv(path.resolve(dotenvPath, dotenvToken))),
46
- ...(env
47
- ? await readDotenv(
48
- path.resolve(dotenvPath, `${dotenvToken}.${env}`)
49
- )
50
- : {}),
51
- }),
52
- ...(excludePrivate
53
- ? {}
54
- : {
55
- ...(await readDotenv(
56
- path.resolve(dotenvPath, `${dotenvToken}.${privateToken}`)
57
- )),
58
- ...(env
59
- ? await readDotenv(
60
- path.resolve(
61
- dotenvPath,
62
- `${dotenvToken}.${env}.${privateToken}`
63
- )
64
- )
65
- : {}),
66
- }),
67
- });
41
+ const dotenv = expand(
42
+ await paths.reduce(
43
+ async (e, p) => ({
44
+ ...(await e),
45
+ ...(excludePublic
46
+ ? {}
47
+ : {
48
+ ...(await readDotenv(path.resolve(p, dotenvToken))),
49
+ ...(env
50
+ ? await readDotenv(path.resolve(p, `${dotenvToken}.${env}`))
51
+ : {}),
52
+ }),
53
+ ...(excludePrivate
54
+ ? {}
55
+ : {
56
+ ...(await readDotenv(
57
+ path.resolve(p, `${dotenvToken}.${privateToken}`)
58
+ )),
59
+ ...(env
60
+ ? await readDotenv(
61
+ path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
62
+ )
63
+ : {}),
64
+ }),
65
+ }),
66
+ []
67
+ )
68
+ );
68
69
 
69
70
  // Log result.
70
71
  if (log) console.log(dotenv);
@@ -91,35 +92,38 @@ export const getDotenvSync = ({
91
92
  excludePublic = false,
92
93
  loadProcess = false,
93
94
  log = false,
94
- path: dotenvPath = './',
95
+ paths = ['./'],
95
96
  privateToken = 'local',
96
97
  } = {}) => {
97
98
  // Read .env files.
98
- const dotenv = expand({
99
- ...(excludePublic
100
- ? {}
101
- : {
102
- ...readDotenvSync(path.resolve(dotenvPath, dotenvToken)),
103
- ...(env
104
- ? readDotenvSync(path.resolve(dotenvPath, `${dotenvToken}.${env}`))
105
- : {}),
106
- }),
107
- ...(excludePrivate
108
- ? {}
109
- : {
110
- ...readDotenvSync(
111
- path.resolve(dotenvPath, `${dotenvToken}.${privateToken}`)
112
- ),
113
- ...(env
114
- ? readDotenvSync(
115
- path.resolve(
116
- dotenvPath,
117
- `${dotenvToken}.${env}.${privateToken}`
118
- )
119
- )
120
- : {}),
121
- }),
122
- });
99
+ const dotenv = expand(
100
+ paths.reduce(
101
+ (e, p) => ({
102
+ ...e,
103
+ ...(excludePublic
104
+ ? {}
105
+ : {
106
+ ...readDotenvSync(path.resolve(p, dotenvToken)),
107
+ ...(env
108
+ ? readDotenvSync(path.resolve(p, `${dotenvToken}.${env}`))
109
+ : {}),
110
+ }),
111
+ ...(excludePrivate
112
+ ? {}
113
+ : {
114
+ ...readDotenvSync(
115
+ path.resolve(p, `${dotenvToken}.${privateToken}`)
116
+ ),
117
+ ...(env
118
+ ? readDotenvSync(
119
+ path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
120
+ )
121
+ : {}),
122
+ }),
123
+ }),
124
+ []
125
+ )
126
+ );
123
127
 
124
128
  // Log result.
125
129
  if (log) console.log(dotenv);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bin": {
4
4
  "getdotenv": "bin/getdotenv/index.js"
5
5
  },
6
- "version": "0.1.2",
6
+ "version": "0.2.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -84,7 +84,7 @@
84
84
  "lint": "eslint lib/** bin/**",
85
85
  "test": "mocha",
86
86
  "build": "babel lib -d dist/default/lib --delete-dir-on-start --config-file ./dist/default/.babelrc",
87
- "doc": "jsdoc2md -c doc/jsdoc.config.json -f lib/**/*.* -t doc/api-template.hbs > doc/3-api.md && concat-md doc --hide-anchor-links > README.md",
87
+ "doc": "jsdoc2md -c doc/jsdoc.config.json -f lib/**/*.* -t doc/api-template.hbs > doc/3-api.jsdoc2.md && concat-md doc --hide-anchor-links > README.md",
88
88
  "package": "npm run lint && npm run test && npm run build && npm run doc",
89
89
  "release": "npm run package && node ./bin/getdotenv -- release-it"
90
90
  },