@candlerip/shared3 0.0.52 → 0.0.54

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared3",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  import { CustomError } from '../../../../error/index.js';
2
2
  import { EnvironmentMode } from '../../../environment-mode/index.js';
3
3
  import { EnvironmentVariables } from '../../../environment-variables/index.js';
4
- export declare const loadEnvFile: <T extends keyof EnvironmentVariables = never, D = EnvironmentVariables[T]>(environmentMode: EnvironmentMode) => {
4
+ export declare const loadEnvFile: <P extends keyof EnvironmentVariables, D = EnvironmentVariables[P]>(environmentMode: EnvironmentMode, projectName: P) => {
5
5
  data: D;
6
6
  } | {
7
7
  customError: CustomError;
@@ -1,7 +1,8 @@
1
1
  import * as dotenv from 'dotenv';
2
2
  import { customErrorWorker } from '../../../../error/index.js';
3
+ import { ENVIRONMENT_VARIABLES } from '../../../environment-variables/index.js';
3
4
  import { ENVIRONMENT_VARIABLE } from '../../../environment-variable/index.js';
4
- export const loadEnvFile = (environmentMode) => {
5
+ export const loadEnvFile = (environmentMode, projectName) => {
5
6
  const { composeCustomError } = customErrorWorker({ environmentMode });
6
7
  const fileName = `.env.${environmentMode}`;
7
8
  const envFile = dotenv.config({ path: `./${fileName}` });
@@ -9,17 +10,20 @@ export const loadEnvFile = (environmentMode) => {
9
10
  if (err || !parsed) {
10
11
  return composeCustomError(`Error loading ${fileName}`, { err });
11
12
  }
12
- const data = {};
13
- Object.keys(parsed).forEach((key) => {
14
- if (ENVIRONMENT_VARIABLE[key] === 'boolean') {
15
- return (data[key] = Boolean(parsed[key] === 'true'));
16
- }
17
- if (ENVIRONMENT_VARIABLE[key] === 'number') {
18
- return (data[key] = parseInt(parsed[key]));
19
- }
20
- data[key] = parsed[key];
21
- });
13
+ const environmentVariables = ENVIRONMENT_VARIABLES[projectName];
22
14
  return {
23
- data: data,
15
+ data: Object.keys(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
+ }, {}),
24
28
  };
25
29
  };
@@ -1,2 +1,3 @@
1
+ export * from './configs/index.js';
1
2
  export * from './domains/index.js';
2
3
  export * from './workers/index.js';
@@ -1,2 +1,3 @@
1
+ export * from './configs/index.js';
1
2
  export * from './domains/index.js';
2
3
  export * from './workers/index.js';
@@ -4,8 +4,8 @@ export const EnvironmentVariablesWorker = (() => {
4
4
  const NODE_ENV = process.env.NODE_ENV;
5
5
  let envs;
6
6
  const get = () => envs;
7
- const init = () => {
8
- const resp = loadEnvFile(NODE_ENV);
7
+ const init = (projectName) => {
8
+ const resp = loadEnvFile(NODE_ENV, projectName);
9
9
  if ('customError' in resp) {
10
10
  return resp;
11
11
  }
@@ -7,7 +7,7 @@ export type IEnvironmentVariablesWorker = {
7
7
  isProduction: IsProduction;
8
8
  };
9
9
  export type Get = <T extends keyof EnvironmentVariables = never>() => EnvironmentVariables[T];
10
- export type Init = <T extends keyof EnvironmentVariables = never>() => {
10
+ export type Init = <T extends keyof EnvironmentVariables>(projectName: T) => {
11
11
  data: EnvironmentVariables[T];
12
12
  } | {
13
13
  customError: CustomError;