@candlerip/shared3 0.0.61 → 0.0.62
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -4
- package/src/environment/environment-variables/singletons/environment-variables-singleton/index.js +4 -10
- package/src/environment/environment-variables/singletons/environment-variables-singleton/types.d.ts +1 -6
- package/src/environment/index.d.ts +0 -1
- package/src/environment/index.js +0 -1
- package/src/project/project-name/configs/index.d.ts +1 -1
- package/src/project/project-name/configs/index.js +2 -0
- package/src/environment/env-file/index.d.ts +0 -1
- package/src/environment/env-file/index.js +0 -1
- package/src/environment/env-file/utils/index.d.ts +0 -1
- package/src/environment/env-file/utils/index.js +0 -1
- package/src/environment/env-file/utils/load-env-file/index.d.ts +0 -8
- package/src/environment/env-file/utils/load-env-file/index.js +0 -29
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@candlerip/shared3",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.62",
|
4
4
|
"type": "module",
|
5
5
|
"main": "src/index.js",
|
6
6
|
"bin": {
|
@@ -28,8 +28,5 @@
|
|
28
28
|
"tsc-alias": "^1.8.10",
|
29
29
|
"typescript": "^5.6.2",
|
30
30
|
"typescript-eslint": "^8.8.0"
|
31
|
-
},
|
32
|
-
"dependencies": {
|
33
|
-
"dotenv": "^16.4.5"
|
34
31
|
}
|
35
32
|
}
|
package/src/environment/environment-variables/singletons/environment-variables-singleton/index.js
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
import { isDevelopment as isDev, isProduction as isProd } from '../../../environment-mode/index.js';
|
2
|
-
import { loadEnvFile } from '../../../env-file/index.js';
|
3
2
|
export const EnvironmentVariablesSingleton = (() => {
|
4
3
|
const NODE_ENV = process.env.NODE_ENV;
|
5
|
-
let
|
6
|
-
const get = () =>
|
7
|
-
const init = (
|
8
|
-
|
9
|
-
if ('customError' in resp) {
|
10
|
-
return resp;
|
11
|
-
}
|
12
|
-
envs = resp.data;
|
13
|
-
return resp;
|
4
|
+
let _envs;
|
5
|
+
const get = () => _envs;
|
6
|
+
const init = (envs) => {
|
7
|
+
_envs = envs;
|
14
8
|
};
|
15
9
|
const isDevelopment = () => isDev(NODE_ENV);
|
16
10
|
const isProduction = () => isProd(NODE_ENV);
|
package/src/environment/environment-variables/singletons/environment-variables-singleton/types.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { CustomError } from '../../../../error/index.js';
|
2
1
|
import { EnvironmentVariables } from '../../domains/index.js';
|
3
2
|
export type IEnvironmentVariablesSingleton = {
|
4
3
|
get: Get;
|
@@ -7,10 +6,6 @@ export type IEnvironmentVariablesSingleton = {
|
|
7
6
|
isProduction: IsProduction;
|
8
7
|
};
|
9
8
|
export type Get = <T extends keyof EnvironmentVariables = never>() => EnvironmentVariables[T];
|
10
|
-
export type Init = <T extends keyof EnvironmentVariables>(
|
11
|
-
data: EnvironmentVariables[T];
|
12
|
-
} | {
|
13
|
-
customError: CustomError;
|
14
|
-
};
|
9
|
+
export type Init = <T extends keyof EnvironmentVariables>(envs: EnvironmentVariables[T]) => void;
|
15
10
|
export type IsDevelopment = () => boolean;
|
16
11
|
export type IsProduction = () => boolean;
|
package/src/environment/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare const PROJECT_NAMES: readonly ["app", "cache-service", "config", "images", "images-init", "logger-service", "nginx", "rabbitmq", "redis", "server", "server-init", "shared", "shared-aws", "shared-backend"];
|
1
|
+
export declare const PROJECT_NAMES: readonly ["app", "backend", "cache-service", "config", "frontend", "images", "images-init", "logger-service", "nginx", "rabbitmq", "redis", "server", "server-init", "shared", "shared-aws", "shared-backend"];
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './utils/index.js';
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './utils/index.js';
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './load-env-file/index.js';
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './load-env-file/index.js';
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { CustomError } from '../../../../error/index.js';
|
2
|
-
import { EnvironmentMode } from '../../../environment-mode/index.js';
|
3
|
-
import { EnvironmentVariables } from '../../../environment-variables/index.js';
|
4
|
-
export declare const loadEnvFile: <P extends keyof EnvironmentVariables, D = EnvironmentVariables[P]>(environmentMode: EnvironmentMode, projectName: P) => {
|
5
|
-
data: D;
|
6
|
-
} | {
|
7
|
-
customError: CustomError;
|
8
|
-
};
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import * as dotenv from 'dotenv';
|
2
|
-
import { customErrorWorker } from '../../../../error/index.js';
|
3
|
-
import { ENVIRONMENT_VARIABLES } from '../../../environment-variables/index.js';
|
4
|
-
import { ENVIRONMENT_VARIABLE } from '../../../environment-variable/index.js';
|
5
|
-
export const loadEnvFile = (environmentMode, projectName) => {
|
6
|
-
const { composeCustomError } = customErrorWorker({ environmentMode });
|
7
|
-
const fileName = `.env.${environmentMode}`;
|
8
|
-
const envFile = dotenv.config({ path: `./${fileName}` });
|
9
|
-
const { error: err, parsed } = envFile;
|
10
|
-
if (err || !parsed) {
|
11
|
-
return composeCustomError(`Error loading ${fileName}`, { err });
|
12
|
-
}
|
13
|
-
const environmentVariables = ENVIRONMENT_VARIABLES[projectName];
|
14
|
-
return {
|
15
|
-
data: environmentVariables.reduce((acc, key) => {
|
16
|
-
const data = {};
|
17
|
-
if (ENVIRONMENT_VARIABLE[key] === 'boolean') {
|
18
|
-
data[key] = Boolean(parsed[key] === 'true');
|
19
|
-
}
|
20
|
-
else if (ENVIRONMENT_VARIABLE[key] === 'number') {
|
21
|
-
data[key] = parseInt(parsed[key]);
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
data[key] = parsed[key];
|
25
|
-
}
|
26
|
-
return { ...acc, ...data };
|
27
|
-
}, {}),
|
28
|
-
};
|
29
|
-
};
|