@candlerip/shared3 0.0.39 → 0.0.41
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -2,13 +2,13 @@ import * as dotenv from 'dotenv';
|
|
2
2
|
import { NUMBER_ENVIRONMENT_VARIABLE_NAMES } from '../../../environment-variable-name/index.js';
|
3
3
|
import { CustomErrorWorker } from '../../../../error/index.js';
|
4
4
|
export const loadEnvFile = (environmentMode) => {
|
5
|
-
CustomErrorWorker.
|
5
|
+
const { composeCustomError } = CustomErrorWorker.getInstance({ environmentMode });
|
6
6
|
const fileName = `.env.${environmentMode}`;
|
7
7
|
const envFile = dotenv.config({ path: `./${fileName}` });
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
9
9
|
const { error, parsed } = envFile;
|
10
10
|
if (error || !parsed) {
|
11
|
-
return
|
11
|
+
return composeCustomError(`Error loading ${fileName}`, { error });
|
12
12
|
}
|
13
13
|
NUMBER_ENVIRONMENT_VARIABLE_NAMES.forEach((it) => {
|
14
14
|
if (parsed[it]) {
|
@@ -19,3 +19,4 @@ export const loadEnvFile = (environmentMode) => {
|
|
19
19
|
data: parsed,
|
20
20
|
};
|
21
21
|
};
|
22
|
+
loadEnvFile('development');
|
@@ -1,29 +1,34 @@
|
|
1
1
|
export const CustomErrorWorker = (() => {
|
2
2
|
let projectName;
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
...infoInput,
|
8
|
-
};
|
9
|
-
};
|
10
|
-
const compose = (message, infoInput) => ({
|
11
|
-
customError: {
|
12
|
-
id: Math.random().toString(16).slice(2).toUpperCase(),
|
13
|
-
info: {
|
3
|
+
const getInstance = (infoInput) => {
|
4
|
+
let info = infoInput;
|
5
|
+
const addInfo = (infoInput) => {
|
6
|
+
info = {
|
14
7
|
...info,
|
15
8
|
...infoInput,
|
9
|
+
};
|
10
|
+
};
|
11
|
+
const composeCustomError = (message, infoInput) => ({
|
12
|
+
customError: {
|
13
|
+
id: Math.random().toString(16).slice(2).toUpperCase(),
|
14
|
+
info: {
|
15
|
+
...info,
|
16
|
+
...infoInput,
|
17
|
+
},
|
18
|
+
message,
|
19
|
+
projectName,
|
16
20
|
},
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
});
|
22
|
+
return {
|
23
|
+
addInfo,
|
24
|
+
composeCustomError,
|
25
|
+
};
|
26
|
+
};
|
21
27
|
const init = (projectNameInput) => {
|
22
28
|
projectName = projectNameInput;
|
23
29
|
};
|
24
30
|
return {
|
25
|
-
|
26
|
-
compose,
|
31
|
+
getInstance,
|
27
32
|
init,
|
28
33
|
};
|
29
34
|
})();
|
@@ -1,11 +1,15 @@
|
|
1
1
|
import { CustomError } from '../../domains/index.js';
|
2
2
|
export interface ICustomErrorWorker {
|
3
|
-
|
4
|
-
compose: Compose;
|
3
|
+
getInstance: GetInstance;
|
5
4
|
init: Init;
|
6
5
|
}
|
7
6
|
export type AddInfo = (props: CustomError['info']) => void;
|
8
|
-
export type
|
7
|
+
export type ComposeCustomError = (message: CustomError['message'], info?: CustomError['info']) => {
|
9
8
|
customError: CustomError;
|
10
9
|
};
|
10
|
+
export type GetInstance = (info: CustomError['info']) => CustomErrorWorkerInstance;
|
11
11
|
export type Init = (projectName: CustomError['projectName']) => void;
|
12
|
+
export type CustomErrorWorkerInstance = {
|
13
|
+
addInfo: AddInfo;
|
14
|
+
composeCustomError: ComposeCustomError;
|
15
|
+
};
|