@karmaniverous/get-dotenv 0.3.0 → 0.3.2
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
CHANGED
|
@@ -49,7 +49,8 @@ For the async form only (`getDotenv`, not `getDotenvSync), use the `dynamicPath`
|
|
|
49
49
|
```js
|
|
50
50
|
export default {
|
|
51
51
|
SOME_DYNAMIC_VARIABLE: (dotenv) => someLogic(dotenv),
|
|
52
|
-
ANOTHER_DYNAMIC_VARIABLE: (dotenv) =>
|
|
52
|
+
ANOTHER_DYNAMIC_VARIABLE: (dotenv) =>
|
|
53
|
+
someOtherLogic(dotenv.SOME_DYNAMIC_VARIABLE),
|
|
53
54
|
};
|
|
54
55
|
```
|
|
55
56
|
|
|
@@ -69,6 +70,8 @@ dotenv files. You can:
|
|
|
69
70
|
* Specify a default environment, override the default with an existing
|
|
70
71
|
environment variable, and override both with a direct setting.
|
|
71
72
|
* Exclude public or private variables.
|
|
73
|
+
* Define dynamic variables progressively in terms of other variables and
|
|
74
|
+
other logic.
|
|
72
75
|
* Execute a shell command after loading variables.
|
|
73
76
|
* Place the shell command inside the invocation to support npm script
|
|
74
77
|
arguments for other options.
|
|
@@ -82,6 +85,7 @@ Options:
|
|
|
82
85
|
-v, --variable <string> environment from variable
|
|
83
86
|
-r, --exclude-private exclude private variables (default: false)
|
|
84
87
|
-u, --exclude-public exclude public variables (default: false)
|
|
88
|
+
-y, --dynamic-path <string> dynamic variables path
|
|
85
89
|
-c, --command <string> shell command string
|
|
86
90
|
-l, --log log extracted variables (default: false)
|
|
87
91
|
-h, --help display help for command
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import spawn from 'cross-spawn';
|
|
|
5
5
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
6
6
|
|
|
7
7
|
// Import package exports.
|
|
8
|
-
import {
|
|
8
|
+
import { getDotenv } from '@karmaniverous/get-dotenv';
|
|
9
9
|
|
|
10
10
|
// Create CLI.
|
|
11
11
|
import { program } from 'commander';
|
|
@@ -25,6 +25,8 @@ program
|
|
|
25
25
|
`* Specify a default environment, override the default with an existing`,
|
|
26
26
|
` environment variable, and override both with a direct setting.`,
|
|
27
27
|
`* Exclude public or private variables.`,
|
|
28
|
+
`* Define dynamic variables progressively in terms of other variables and`,
|
|
29
|
+
` other logic.`,
|
|
28
30
|
`* Execute a shell command after loading variables.`,
|
|
29
31
|
`* Place the shell command inside the invocation to support npm script`,
|
|
30
32
|
` arguments for other options.`,
|
|
@@ -50,6 +52,7 @@ program
|
|
|
50
52
|
.option('-v, --variable <string>', 'environment from variable')
|
|
51
53
|
.option('-r, --exclude-private', 'exclude private variables (default: false)')
|
|
52
54
|
.option('-u, --exclude-public', 'exclude public variables (default: false)')
|
|
55
|
+
.option('-y, --dynamic-path <string>', 'dynamic variables path')
|
|
53
56
|
.option('-c, --command <string>', 'shell command string')
|
|
54
57
|
.option('-l, --log', 'log extracted variables (default: false)');
|
|
55
58
|
|
|
@@ -62,6 +65,7 @@ const {
|
|
|
62
65
|
environment,
|
|
63
66
|
excludePrivate,
|
|
64
67
|
excludePublic,
|
|
68
|
+
dynamicPath,
|
|
65
69
|
log,
|
|
66
70
|
paths,
|
|
67
71
|
privateToken,
|
|
@@ -74,12 +78,13 @@ if (command && program.args.length) program.error('command specified twice');
|
|
|
74
78
|
const env = environment ?? process.env[variable] ?? defaultEnvironment;
|
|
75
79
|
|
|
76
80
|
// Load dotenvs.
|
|
77
|
-
|
|
81
|
+
await getDotenv({
|
|
78
82
|
dotenvToken,
|
|
79
83
|
env,
|
|
80
84
|
excludePrivate,
|
|
81
85
|
excludePublic,
|
|
82
86
|
loadProcess: true,
|
|
87
|
+
dynamicPath,
|
|
83
88
|
log,
|
|
84
89
|
paths,
|
|
85
90
|
privateToken,
|
|
@@ -7,9 +7,12 @@ exports.getDotenvSync = exports.getDotenv = void 0;
|
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
var _dotenvExpand = require("dotenv-expand");
|
|
9
9
|
var _readDotenv = require("../readDotEnv/readDotenv.js");
|
|
10
|
+
var _url = require("url");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
const _dirname = (0, _url.fileURLToPath)(new _url.URL('.', import.meta.url));
|
|
15
|
+
|
|
13
16
|
/**
|
|
14
17
|
* get-dotenv options type
|
|
15
18
|
*
|
|
@@ -65,7 +68,7 @@ const getDotenv = async function () {
|
|
|
65
68
|
if (dynamicPath) {
|
|
66
69
|
const {
|
|
67
70
|
default: dynamic
|
|
68
|
-
} = await Promise.resolve(`${dynamicPath}`).then(s => _interopRequireWildcard(require(s)));
|
|
71
|
+
} = await Promise.resolve(`${_path.default.relative(_dirname, dynamicPath).replace(/\\/g, '/')}`).then(s => _interopRequireWildcard(require(s)));
|
|
69
72
|
Object.keys(dynamic).forEach(key => {
|
|
70
73
|
Object.assign(dotenv, {
|
|
71
74
|
[key]: dynamic[key](dotenv)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { expand } from 'dotenv-expand';
|
|
3
3
|
import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
|
|
4
|
+
import { URL, fileURLToPath } from 'url';
|
|
5
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* get-dotenv options type
|
|
@@ -71,7 +73,9 @@ export const getDotenv = async ({
|
|
|
71
73
|
|
|
72
74
|
// Process dynamic variables.
|
|
73
75
|
if (dynamicPath) {
|
|
74
|
-
const { default: dynamic } = await import(
|
|
76
|
+
const { default: dynamic } = await import(
|
|
77
|
+
path.relative(__dirname, dynamicPath).replace(/\\/g, '/')
|
|
78
|
+
);
|
|
75
79
|
|
|
76
80
|
Object.keys(dynamic).forEach((key) => {
|
|
77
81
|
Object.assign(dotenv, { [key]: dynamic[key](dotenv) });
|