@candlerip/shared3 0.0.108 → 0.0.109
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/backend/environment/index.d.ts +1 -0
- package/src/backend/environment/index.js +1 -0
- package/src/backend/environment/load-env-file/index.d.ts +1 -0
- package/src/backend/environment/load-env-file/index.js +1 -0
- package/src/backend/environment/load-env-file/util.d.ts +6 -0
- package/src/backend/environment/load-env-file/util.js +27 -0
- package/src/backend/index.d.ts +1 -0
- package/src/backend/index.js +1 -0
package/package.json
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './load-env-file/index.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './load-env-file/index.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { CustomError, EnvironmentMode, EnvironmentVariables } from '@candlerip/shared3';
|
2
|
+
export declare const loadEnvFile: <P extends keyof EnvironmentVariables, D = EnvironmentVariables[P]>(environmentMode: EnvironmentMode, projectName: P) => {
|
3
|
+
data: D;
|
4
|
+
} | {
|
5
|
+
customError: CustomError;
|
6
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { customErrorWorker, ENVIRONMENT_VARIABLES_CONFIG, ENVIRONMENT_VARIABLE_CONFIG, } from '@candlerip/shared3';
|
2
|
+
import * as dotenv from 'dotenv';
|
3
|
+
export const loadEnvFile = (environmentMode, projectName) => {
|
4
|
+
const { composeCustomError } = customErrorWorker({ environmentMode });
|
5
|
+
const fileName = `.env.${environmentMode}`;
|
6
|
+
const envFile = dotenv.config({ path: `./${fileName}` });
|
7
|
+
const { error: err, parsed } = envFile;
|
8
|
+
if (err || !parsed) {
|
9
|
+
return composeCustomError(`Error loading ${fileName}`, { err });
|
10
|
+
}
|
11
|
+
const environmentVariables = ENVIRONMENT_VARIABLES_CONFIG[projectName];
|
12
|
+
return {
|
13
|
+
data: environmentVariables.reduce((acc, key) => {
|
14
|
+
const data = {};
|
15
|
+
if (ENVIRONMENT_VARIABLE_CONFIG[key] === 'boolean') {
|
16
|
+
data[key] = Boolean(parsed[key] === 'true');
|
17
|
+
}
|
18
|
+
else if (ENVIRONMENT_VARIABLE_CONFIG[key] === 'number') {
|
19
|
+
data[key] = parseInt(parsed[key]);
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
data[key] = parsed[key];
|
23
|
+
}
|
24
|
+
return { ...acc, ...data };
|
25
|
+
}, {}),
|
26
|
+
};
|
27
|
+
};
|
package/src/backend/index.d.ts
CHANGED
package/src/backend/index.js
CHANGED