@candlerip/shared3 0.0.61 → 0.0.63

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.61",
3
+ "version": "0.0.63",
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
  }
@@ -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 envs;
6
- const get = () => envs;
7
- const init = (projectName) => {
8
- const resp = loadEnvFile(NODE_ENV, projectName);
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);
@@ -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>(projectName: T) => {
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;
@@ -1,4 +1,4 @@
1
- export * from './env-file/index.js';
2
1
  export * from './environment-mode/index.js';
2
+ export * from './environment-variable/index.js';
3
3
  export * from './environment-variable-name/index.js';
4
4
  export * from './environment-variables/index.js';
@@ -1,4 +1,4 @@
1
- export * from './env-file/index.js';
2
1
  export * from './environment-mode/index.js';
2
+ export * from './environment-variable/index.js';
3
3
  export * from './environment-variable-name/index.js';
4
4
  export * from './environment-variables/index.js';
@@ -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,7 +1,9 @@
1
1
  export const PROJECT_NAMES = [
2
2
  'app',
3
+ 'backend',
3
4
  'cache-service',
4
5
  'config',
6
+ 'frontend',
5
7
  'images',
6
8
  'images-init',
7
9
  'logger-service',
@@ -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
- };