@intlayer/config 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/cjs/configFile/buildConfigurationFields.cjs +253 -38
  2. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  3. package/dist/cjs/configFile/buildConfigurationFields.d.ts +3 -0
  4. package/dist/cjs/configFile/getConfiguration.cjs.map +1 -1
  5. package/dist/cjs/configFile/getConfiguration.d.ts +3 -0
  6. package/dist/cjs/configFile/index.cjs +3 -1
  7. package/dist/cjs/configFile/index.cjs.map +1 -1
  8. package/dist/cjs/configFile/index.d.ts +1 -0
  9. package/dist/cjs/configFile/loadConfigurationFile.cjs +8 -1
  10. package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
  11. package/dist/cjs/configFile/loadConfigurationFile.d.ts +6 -0
  12. package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
  13. package/dist/cjs/configFile/searchConfigurationFile.d.ts +11 -0
  14. package/dist/cjs/defaultValues/internationalization.cjs +1 -5
  15. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  16. package/dist/cjs/defaultValues/internationalization.d.ts +1 -1
  17. package/dist/cjs/defaultValues/server.cjs +0 -6
  18. package/dist/cjs/defaultValues/server.cjs.map +1 -1
  19. package/dist/cjs/defaultValues/server.d.ts +1 -3
  20. package/dist/cjs/envVariables/detectPlatform.cjs +53 -0
  21. package/dist/cjs/envVariables/detectPlatform.cjs.map +1 -0
  22. package/dist/cjs/envVariables/detectPlatform.d.ts +11 -0
  23. package/dist/cjs/envVariables/extractEnvVariable.cjs +211 -0
  24. package/dist/cjs/envVariables/extractEnvVariable.cjs.map +1 -0
  25. package/dist/cjs/envVariables/extractEnvVariable.d.ts +13 -0
  26. package/dist/cjs/envVariables/formatEnvVariable.cjs +6 -4
  27. package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
  28. package/dist/cjs/envVariables/formatEnvVariable.d.ts +6 -1
  29. package/dist/cjs/envVariables/getConfiguration.cjs +37 -38
  30. package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
  31. package/dist/cjs/envVariables/getConfiguration.d.ts +5 -0
  32. package/dist/cjs/envVariables/index.d.ts +1 -0
  33. package/dist/cjs/envVariables/utils.cjs +7 -6
  34. package/dist/cjs/envVariables/utils.cjs.map +1 -1
  35. package/dist/cjs/envVariables/utils.d.ts +5 -5
  36. package/dist/cjs/index.d.ts +1 -0
  37. package/dist/cjs/types/config.cjs.map +1 -1
  38. package/dist/cjs/types/config.d.ts +212 -6
  39. package/dist/cjs/types/locales.cjs.map +1 -1
  40. package/dist/cjs/types/locales.d.ts +233 -0
  41. package/dist/esm/configFile/buildConfigurationFields.d.mts +3 -0
  42. package/dist/esm/configFile/buildConfigurationFields.mjs +253 -40
  43. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  44. package/dist/esm/configFile/getConfiguration.d.mts +3 -0
  45. package/dist/esm/configFile/getConfiguration.mjs.map +1 -1
  46. package/dist/esm/configFile/index.d.mts +1 -0
  47. package/dist/esm/configFile/index.mjs +1 -0
  48. package/dist/esm/configFile/index.mjs.map +1 -1
  49. package/dist/esm/configFile/loadConfigurationFile.d.mts +6 -0
  50. package/dist/esm/configFile/loadConfigurationFile.mjs +8 -1
  51. package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
  52. package/dist/esm/configFile/searchConfigurationFile.d.mts +11 -0
  53. package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
  54. package/dist/esm/defaultValues/internationalization.d.mts +1 -1
  55. package/dist/esm/defaultValues/internationalization.mjs +1 -5
  56. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  57. package/dist/esm/defaultValues/server.d.mts +1 -3
  58. package/dist/esm/defaultValues/server.mjs +0 -4
  59. package/dist/esm/defaultValues/server.mjs.map +1 -1
  60. package/dist/esm/envVariables/detectPlatform.d.mts +11 -0
  61. package/dist/esm/envVariables/detectPlatform.mjs +27 -0
  62. package/dist/esm/envVariables/detectPlatform.mjs.map +1 -0
  63. package/dist/esm/envVariables/extractEnvVariable.d.mts +13 -0
  64. package/dist/esm/envVariables/extractEnvVariable.mjs +186 -0
  65. package/dist/esm/envVariables/extractEnvVariable.mjs.map +1 -0
  66. package/dist/esm/envVariables/formatEnvVariable.d.mts +6 -1
  67. package/dist/esm/envVariables/formatEnvVariable.mjs +6 -4
  68. package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
  69. package/dist/esm/envVariables/getConfiguration.d.mts +5 -0
  70. package/dist/esm/envVariables/getConfiguration.mjs +37 -38
  71. package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
  72. package/dist/esm/envVariables/index.d.mts +1 -0
  73. package/dist/esm/envVariables/utils.d.mts +5 -5
  74. package/dist/esm/envVariables/utils.mjs +7 -6
  75. package/dist/esm/envVariables/utils.mjs.map +1 -1
  76. package/dist/esm/index.d.mts +1 -0
  77. package/dist/esm/types/config.d.mts +212 -6
  78. package/dist/esm/types/locales.d.mts +233 -0
  79. package/dist/esm/types/locales.mjs.map +1 -1
  80. package/package.json +7 -7
  81. package/src/configFile/buildConfigurationFields.ts +258 -47
  82. package/src/configFile/getConfiguration.ts +3 -0
  83. package/src/configFile/index.ts +1 -0
  84. package/src/configFile/loadConfigurationFile.ts +19 -1
  85. package/src/configFile/searchConfigurationFile.ts +11 -0
  86. package/src/defaultValues/server.ts +0 -4
  87. package/src/envVariables/detectPlatform.ts +37 -0
  88. package/src/envVariables/extractEnvVariable.ts +224 -0
  89. package/src/envVariables/formatEnvVariable.ts +17 -11
  90. package/src/envVariables/getConfiguration.ts +40 -41
  91. package/src/envVariables/utils.ts +30 -14
  92. package/src/types/config.ts +237 -65
  93. package/src/types/locales.ts +233 -233
@@ -0,0 +1,224 @@
1
+ import type {
2
+ InternationalizationConfig,
3
+ MiddlewareConfig,
4
+ ContentConfig,
5
+ } from '../types/config';
6
+ import { type ViteEnvVar, getPlatform } from './detectPlatform';
7
+
8
+ // Utility type that replaces all values of a given type with another type
9
+ type ReplaceValue<T> = {
10
+ [K in keyof T]: string | undefined;
11
+ };
12
+
13
+ const extractNextEnvVariable = () => {
14
+ if (typeof process === 'undefined') {
15
+ return extractEmptyEnvVariable();
16
+ }
17
+
18
+ const env = process.env;
19
+
20
+ const intlayerIntlConfiguration: ReplaceValue<InternationalizationConfig> = {
21
+ locales: env.NEXT_PUBLIC_INTLAYER_LOCALES,
22
+ defaultLocale: env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE,
23
+ };
24
+
25
+ const intlayerMiddlewareConfiguration: ReplaceValue<MiddlewareConfig> = {
26
+ headerName: env.NEXT_PUBLIC_INTLAYER_HEADER_NAME,
27
+ cookieName: env.NEXT_PUBLIC_INTLAYER_COOKIE_NAME,
28
+ prefixDefault: env.NEXT_PUBLIC_INTLAYER_PREFIX_DEFAULT,
29
+ basePath: env.NEXT_PUBLIC_INTLAYER_BASE_PATH,
30
+ serverSetCookie: env.NEXT_PUBLIC_INTLAYER_SERVER_SET_COOKIE,
31
+ noPrefix: env.NEXT_PUBLIC_INTLAYER_NO_PREFIX,
32
+ };
33
+
34
+ const intlayerContentConfiguration: ReplaceValue<ContentConfig> = {
35
+ fileExtensions: env.NEXT_PUBLIC_INTLAYER_FILE_EXTENSIONS,
36
+ baseDir: env.NEXT_PUBLIC_INTLAYER_BASE_DIR,
37
+ contentDirName: env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR_NAME,
38
+ contentDir: env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR,
39
+ excludedPath: env.NEXT_PUBLIC_INTLAYER_EXCLUDED_PATH,
40
+ resultDirName: env.NEXT_PUBLIC_INTLAYER_RESULT_DIR_NAME,
41
+ moduleAugmentationDirName:
42
+ env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
43
+ dictionariesDirName: env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR_NAME,
44
+ typeDirName: env.NEXT_PUBLIC_INTLAYER_TYPE_DIR_NAME,
45
+ mainDirName: env.NEXT_PUBLIC_INTLAYER_MAIN_DIR_NAME,
46
+ resultDir: env.NEXT_PUBLIC_INTLAYER_RESULT_DIR,
47
+ moduleAugmentationDir: env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR,
48
+ dictionariesDir: env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR,
49
+ typesDir: env.NEXT_PUBLIC_INTLAYER_TYPE_DIR,
50
+ mainDir: env.NEXT_PUBLIC_INTLAYER_MAIN_DIR,
51
+ watchedFilesPattern: env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN,
52
+ watchedFilesPatternWithPath:
53
+ env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
54
+ outputFilesPatternWithPath:
55
+ env.NEXT_PUBLIC_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
56
+ };
57
+
58
+ return {
59
+ intlayerIntlConfiguration,
60
+ intlayerMiddlewareConfiguration,
61
+ intlayerContentConfiguration,
62
+ };
63
+ };
64
+
65
+ const extractReactAppEnvVariable = () => {
66
+ if (typeof process === 'undefined') {
67
+ return extractEmptyEnvVariable();
68
+ }
69
+
70
+ const env = process.env;
71
+
72
+ const intlayerIntlConfiguration: ReplaceValue<InternationalizationConfig> = {
73
+ locales: env.REACT_APP_INTLAYER_LOCALES,
74
+ defaultLocale: env.REACT_APP_INTLAYER_DEFAULT_LOCALE,
75
+ };
76
+
77
+ const intlayerMiddlewareConfiguration: ReplaceValue<MiddlewareConfig> = {
78
+ headerName: env.REACT_APP_INTLAYER_HEADER_NAME,
79
+ cookieName: env.REACT_APP_INTLAYER_COOKIE_NAME,
80
+ prefixDefault: env.REACT_APP_INTLAYER_PREFIX_DEFAULT,
81
+ basePath: env.REACT_APP_INTLAYER_BASE_PATH,
82
+ serverSetCookie: env.REACT_APP_INTLAYER_SERVER_SET_COOKIE,
83
+ noPrefix: env.REACT_APP_INTLAYER_NO_PREFIX,
84
+ };
85
+
86
+ const intlayerContentConfiguration: ReplaceValue<ContentConfig> = {
87
+ fileExtensions: env.REACT_APP_INTLAYER_FILE_EXTENSIONS,
88
+ baseDir: env.REACT_APP_INTLAYER_BASE_DIR,
89
+ contentDirName: env.REACT_APP_INTLAYER_CONTENT_DIR_NAME,
90
+ contentDir: env.REACT_APP_INTLAYER_CONTENT_DIR,
91
+ excludedPath: env.REACT_APP_INTLAYER_EXCLUDED_PATH,
92
+ resultDirName: env.REACT_APP_INTLAYER_RESULT_DIR_NAME,
93
+ moduleAugmentationDirName:
94
+ env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
95
+ dictionariesDirName: env.REACT_APP_INTLAYER_DICTIONARIES_DIR_NAME,
96
+ typeDirName: env.REACT_APP_INTLAYER_TYPE_DIR_NAME,
97
+ mainDirName: env.REACT_APP_INTLAYER_MAIN_DIR_NAME,
98
+ resultDir: env.REACT_APP_INTLAYER_RESULT_DIR,
99
+ moduleAugmentationDir: env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR,
100
+ dictionariesDir: env.REACT_APP_INTLAYER_DICTIONARIES_DIR,
101
+ typesDir: env.REACT_APP_INTLAYER_TYPE_DIR,
102
+ mainDir: env.REACT_APP_INTLAYER_MAIN_DIR,
103
+ watchedFilesPattern: env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN,
104
+ watchedFilesPatternWithPath:
105
+ env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
106
+ outputFilesPatternWithPath:
107
+ env.REACT_APP_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
108
+ };
109
+
110
+ return {
111
+ intlayerIntlConfiguration,
112
+ intlayerMiddlewareConfiguration,
113
+ intlayerContentConfiguration,
114
+ };
115
+ };
116
+
117
+ const extractViteEnvVariable = () => {
118
+ const env = (import.meta as unknown as ViteEnvVar).env;
119
+
120
+ if (typeof env === 'undefined') {
121
+ return extractEmptyEnvVariable();
122
+ }
123
+
124
+ const intlayerIntlConfiguration: ReplaceValue<InternationalizationConfig> = {
125
+ locales: env.VITE_INTLAYER_LOCALES,
126
+ defaultLocale: env.VITE_INTLAYER_DEFAULT_LOCALE,
127
+ };
128
+
129
+ const intlayerMiddlewareConfiguration: ReplaceValue<MiddlewareConfig> = {
130
+ headerName: env.VITE_INTLAYER_HEADER_NAME,
131
+ cookieName: env.VITE_INTLAYER_COOKIE_NAME,
132
+ prefixDefault: env.VITE_INTLAYER_PREFIX_DEFAULT,
133
+ basePath: env.VITE_INTLAYER_BASE_PATH,
134
+ serverSetCookie: env.VITE_INTLAYER_SERVER_SET_COOKIE,
135
+ noPrefix: env.VITE_INTLAYER_NO_PREFIX,
136
+ };
137
+
138
+ const intlayerContentConfiguration: ReplaceValue<ContentConfig> = {
139
+ fileExtensions: env.VITE_INTLAYER_FILE_EXTENSIONS,
140
+ baseDir: env.VITE_INTLAYER_BASE_DIR,
141
+ contentDirName: env.VITE_INTLAYER_CONTENT_DIR_NAME,
142
+ contentDir: env.VITE_INTLAYER_CONTENT_DIR,
143
+ excludedPath: env.VITE_INTLAYER_EXCLUDED_PATH,
144
+ resultDirName: env.VITE_INTLAYER_RESULT_DIR_NAME,
145
+ moduleAugmentationDirName: env.VITE_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
146
+ dictionariesDirName: env.VITE_INTLAYER_DICTIONARIES_DIR_NAME,
147
+ typeDirName: env.VITE_INTLAYER_TYPE_DIR_NAME,
148
+ mainDirName: env.VITE_INTLAYER_MAIN_DIR_NAME,
149
+ resultDir: env.VITE_INTLAYER_RESULT_DIR,
150
+ moduleAugmentationDir: env.VITE_INTLAYER_MODULE_AUGMENTATION_DIR,
151
+ dictionariesDir: env.VITE_INTLAYER_DICTIONARIES_DIR,
152
+ typesDir: env.VITE_INTLAYER_TYPE_DIR,
153
+ mainDir: env.VITE_INTLAYER_MAIN_DIR,
154
+ watchedFilesPattern: env.VITE_INTLAYER_WATCHED_FILES_PATTERN,
155
+ watchedFilesPatternWithPath:
156
+ env.VITE_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
157
+ outputFilesPatternWithPath:
158
+ env.VITE_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
159
+ };
160
+
161
+ return {
162
+ intlayerIntlConfiguration,
163
+ intlayerMiddlewareConfiguration,
164
+ intlayerContentConfiguration,
165
+ };
166
+ };
167
+
168
+ const extractEmptyEnvVariable = () => {
169
+ const intlayerIntlConfiguration: ReplaceValue<InternationalizationConfig> = {
170
+ locales: undefined,
171
+ defaultLocale: undefined,
172
+ };
173
+
174
+ const intlayerMiddlewareConfiguration: ReplaceValue<MiddlewareConfig> = {
175
+ headerName: undefined,
176
+ cookieName: undefined,
177
+ prefixDefault: undefined,
178
+ basePath: undefined,
179
+ serverSetCookie: undefined,
180
+ noPrefix: undefined,
181
+ };
182
+
183
+ const intlayerContentConfiguration: ReplaceValue<ContentConfig> = {
184
+ fileExtensions: undefined,
185
+ baseDir: undefined,
186
+ contentDirName: undefined,
187
+ contentDir: undefined,
188
+ excludedPath: undefined,
189
+ resultDirName: undefined,
190
+ moduleAugmentationDirName: undefined,
191
+ dictionariesDirName: undefined,
192
+ typeDirName: undefined,
193
+ mainDirName: undefined,
194
+ resultDir: undefined,
195
+ moduleAugmentationDir: undefined,
196
+ dictionariesDir: undefined,
197
+ typesDir: undefined,
198
+ mainDir: undefined,
199
+ watchedFilesPattern: undefined,
200
+ watchedFilesPatternWithPath: undefined,
201
+ outputFilesPatternWithPath: undefined,
202
+ };
203
+
204
+ return {
205
+ intlayerIntlConfiguration,
206
+ intlayerMiddlewareConfiguration,
207
+ intlayerContentConfiguration,
208
+ };
209
+ };
210
+
211
+ export const extractEnvVariable = () => {
212
+ const platform = getPlatform();
213
+
214
+ switch (platform) {
215
+ case 'next':
216
+ return extractNextEnvVariable();
217
+ case 'vite':
218
+ return extractViteEnvVariable();
219
+ case 'react_app':
220
+ return extractReactAppEnvVariable();
221
+ default:
222
+ return extractEmptyEnvVariable();
223
+ }
224
+ };
@@ -1,18 +1,24 @@
1
1
  import { getConfiguration } from '../configFile/getConfiguration';
2
+ import { getPrefix, type Platform } from './detectPlatform';
2
3
 
4
+ /**
5
+ * Format a key to corresponding environment variable name
6
+ *
7
+ * Example:
8
+ * toEnvVariable('mainDir') => 'INTLAYER_MAIN_DIR'
9
+ */
10
+ const formatEnvName = (key: string, prefix: string): string =>
11
+ prefix + key.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toUpperCase();
12
+
13
+ /**
14
+ * Format all configuration values as environment variables
15
+ */
3
16
  export const formatEnvVariable = (
4
- prefix = 'NEXT_PUBLIC_INTLAYER_'
17
+ platform: Platform
5
18
  ): Record<string, string> => {
6
19
  const intlayerConfig = getConfiguration();
7
20
 
8
- /**
9
- * Format a key to corresponding environment variable name
10
- *
11
- * Example:
12
- * toEnvVariable('mainDir') => 'INTLAYER_MAIN_DIR'
13
- */
14
- const formatEnvName = (key: string): string =>
15
- prefix + key.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toUpperCase();
21
+ const prefix = getPrefix(platform);
16
22
 
17
23
  // Set all configuration values as environment variables
18
24
  const env: Record<string, string> = {};
@@ -22,9 +28,9 @@ export const formatEnvVariable = (
22
28
  ...intlayerConfig.middleware,
23
29
  })) {
24
30
  if (typeof value === 'string') {
25
- env[formatEnvName(key)] = value;
31
+ env[formatEnvName(key, prefix)] = value;
26
32
  } else {
27
- env[formatEnvName(key)] = JSON.stringify(value);
33
+ env[formatEnvName(key, prefix)] = JSON.stringify(value);
28
34
  }
29
35
  }
30
36
 
@@ -6,114 +6,108 @@ import type {
6
6
  ServerSetCookieRule,
7
7
  } from '../types/config';
8
8
  import type { Locales } from '../types/locales';
9
+ import { extractEnvVariable } from './extractEnvVariable';
9
10
  import { getEnvValue } from './utils';
10
11
 
12
+ const env = extractEnvVariable();
13
+
11
14
  export const intlayerIntlConfiguration: InternationalizationConfig = {
12
15
  locales: getEnvValue<Locales>(
13
- process.env.NEXT_PUBLIC_INTLAYER_LOCALES,
16
+ env.intlayerIntlConfiguration.locales,
14
17
  'array'
15
18
  )!,
16
19
  defaultLocale: getEnvValue<Locales>(
17
- process.env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE,
20
+ env.intlayerIntlConfiguration.defaultLocale,
18
21
  'string'
19
22
  )!,
20
23
  };
21
24
 
22
25
  export const intlayerMiddlewareConfiguration: MiddlewareConfig = {
23
26
  headerName: getEnvValue(
24
- process.env.NEXT_PUBLIC_INTLAYER_HEADER_NAME,
27
+ env.intlayerMiddlewareConfiguration.headerName,
25
28
  'string'
26
29
  )!,
27
30
  cookieName: getEnvValue(
28
- process.env.NEXT_PUBLIC_INTLAYER_COOKIE_NAME,
31
+ env.intlayerMiddlewareConfiguration.cookieName,
29
32
  'string'
30
33
  )!,
31
34
  prefixDefault: getEnvValue(
32
- process.env.NEXT_PUBLIC_INTLAYER_PREFIX_DEFAULT,
35
+ env.intlayerMiddlewareConfiguration.prefixDefault,
33
36
  'boolean'
34
37
  )!,
35
- basePath: getEnvValue(process.env.NEXT_PUBLIC_INTLAYER_BASE_PATH, 'string')!,
38
+ basePath: getEnvValue(
39
+ env.intlayerMiddlewareConfiguration.basePath,
40
+ 'string'
41
+ )!,
36
42
  serverSetCookie: getEnvValue<ServerSetCookieRule>(
37
- process.env.NEXT_PUBLIC_INTLAYER_SERVER_SET_COOKIE,
43
+ env.intlayerMiddlewareConfiguration.serverSetCookie,
38
44
  'string'
39
45
  )!,
40
- noPrefix: getEnvValue(process.env.NEXT_PUBLIC_INTLAYER_NO_PREFIX, 'boolean')!,
46
+ noPrefix: getEnvValue(
47
+ env.intlayerMiddlewareConfiguration.noPrefix,
48
+ 'boolean'
49
+ )!,
41
50
  };
42
51
 
43
52
  export const intlayerContentConfiguration: ContentConfig = {
44
53
  fileExtensions: getEnvValue<string>(
45
- process.env.NEXT_PUBLIC_INTLAYER_FILE_EXTENSIONS,
54
+ env.intlayerContentConfiguration.fileExtensions,
46
55
  'array'
47
56
  )!,
48
- baseDir: getEnvValue(process.env.NEXT_PUBLIC_INTLAYER_BASE_DIR, 'string')!,
57
+ baseDir: getEnvValue(env.intlayerContentConfiguration.baseDir, 'string')!,
49
58
  contentDirName: getEnvValue(
50
- process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR_NAME,
59
+ env.intlayerContentConfiguration.contentDirName,
51
60
  'string'
52
61
  )!,
53
62
  contentDir: getEnvValue(
54
- process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR,
63
+ env.intlayerContentConfiguration.contentDir,
55
64
  'string'
56
65
  )!,
57
66
  excludedPath: getEnvValue<string>(
58
- process.env.NEXT_PUBLIC_INTLAYER_EXCLUDED_PATH,
67
+ env.intlayerContentConfiguration.excludedPath,
59
68
  'array'
60
69
  )!,
61
70
  resultDirName: getEnvValue(
62
- process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR_NAME,
63
- 'string'
64
- )!,
65
- resultDir: getEnvValue(
66
- process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR,
71
+ env.intlayerContentConfiguration.resultDirName,
67
72
  'string'
68
73
  )!,
74
+ resultDir: getEnvValue(env.intlayerContentConfiguration.resultDir, 'string')!,
69
75
  moduleAugmentationDirName: getEnvValue(
70
- process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
76
+ env.intlayerContentConfiguration.moduleAugmentationDirName,
71
77
  'string'
72
78
  )!,
73
79
  moduleAugmentationDir: getEnvValue(
74
- process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR,
75
- 'string'
76
- )!,
77
- bundleDirName: getEnvValue(
78
- process.env.NEXT_PUBLIC_INTLAYER_BUNDLE_DIR_NAME,
79
- 'string'
80
- )!,
81
- bundleDir: getEnvValue(
82
- process.env.NEXT_PUBLIC_INTLAYER_BUNDLE_DIR,
83
- 'string'
84
- )!,
85
- bundleFileExtension: getEnvValue(
86
- process.env.NEXT_PUBLIC_INTLAYER_BUNDLE_FILE_EXTENSION,
80
+ env.intlayerContentConfiguration.moduleAugmentationDir,
87
81
  'string'
88
82
  )!,
89
83
  dictionariesDirName: getEnvValue(
90
- process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR_NAME,
84
+ env.intlayerContentConfiguration.dictionariesDirName,
91
85
  'string'
92
86
  )!,
93
87
  dictionariesDir: getEnvValue(
94
- process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR,
88
+ env.intlayerContentConfiguration.dictionariesDir,
95
89
  'string'
96
90
  )!,
97
91
  typeDirName: getEnvValue(
98
- process.env.NEXT_PUBLIC_INTLAYER_TYPES_DIR_NAME,
92
+ env.intlayerContentConfiguration.typeDirName,
99
93
  'string'
100
94
  )!,
101
- typesDir: getEnvValue(process.env.NEXT_PUBLIC_INTLAYER_TYPES_DIR, 'string')!,
95
+ typesDir: getEnvValue(env.intlayerContentConfiguration.typesDir, 'string')!,
102
96
  mainDirName: getEnvValue(
103
- process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR_NAME,
97
+ env.intlayerContentConfiguration.mainDirName,
104
98
  'string'
105
99
  )!,
106
- mainDir: getEnvValue(process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR, 'string')!,
100
+ mainDir: getEnvValue(env.intlayerContentConfiguration.mainDir, 'string')!,
107
101
  watchedFilesPattern: getEnvValue<string>(
108
- process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN,
102
+ env.intlayerContentConfiguration.watchedFilesPattern,
109
103
  'array'
110
104
  )!,
111
105
  watchedFilesPatternWithPath: getEnvValue<string>(
112
- process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
106
+ env.intlayerContentConfiguration.watchedFilesPatternWithPath,
113
107
  'array'
114
108
  )!,
115
109
  outputFilesPatternWithPath: getEnvValue(
116
- process.env.NEXT_PUBLIC_INTLAYER_OUTPUT_FILES_PATTERN,
110
+ env.intlayerContentConfiguration.outputFilesPatternWithPath,
117
111
  'string'
118
112
  )!,
119
113
  };
@@ -124,4 +118,9 @@ export const intlayerConfiguration: IntlayerConfig = {
124
118
  content: intlayerContentConfiguration,
125
119
  };
126
120
 
121
+ /**
122
+ * Get all configuration values using environment variables
123
+ * Can be used in the client side as the server side
124
+ * To use it, be sure to have the environment variables set
125
+ */
127
126
  export const getConfiguration = (): IntlayerConfig => intlayerConfiguration;
@@ -1,14 +1,32 @@
1
- function getEnvValue(value: unknown, type: 'boolean'): boolean | undefined;
2
- function getEnvValue(value: unknown, type: 'number'): number | undefined;
1
+ function getEnvValue(
2
+ value: unknown,
3
+ type: 'boolean',
4
+ verbose?: boolean
5
+ ): boolean | undefined;
6
+ function getEnvValue(
7
+ value: unknown,
8
+ type: 'number',
9
+ verbose?: boolean
10
+ ): number | undefined;
3
11
  function getEnvValue<T extends string>(
4
12
  value: unknown,
5
- type: 'string'
13
+ type: 'string',
14
+ verbose?: boolean
6
15
  ): T | undefined;
7
- function getEnvValue<T>(value: unknown, type: 'object'): T | undefined;
8
- function getEnvValue<T>(value: unknown, type: 'array'): T[] | undefined;
16
+ function getEnvValue<T>(
17
+ value: unknown,
18
+ type: 'object',
19
+ verbose?: boolean
20
+ ): T | undefined;
21
+ function getEnvValue<T>(
22
+ value: unknown,
23
+ type: 'array',
24
+ verbose?: boolean
25
+ ): T[] | undefined;
9
26
  function getEnvValue(
10
27
  value: unknown,
11
- type: 'string' | 'boolean' | 'number' | 'object' | 'array'
28
+ type: 'string' | 'boolean' | 'number' | 'object' | 'array',
29
+ verbose = false
12
30
  ) {
13
31
  try {
14
32
  switch (type) {
@@ -27,20 +45,18 @@ function getEnvValue(
27
45
  case 'object':
28
46
  case 'array':
29
47
  // Attempt to parse the value as JSON
30
- try {
31
- return JSON.parse(value as string);
32
- } catch (error) {
33
- // Log error and return undefined if any error occurs during parsing
34
- console.error(`Error parsing environment variable`);
35
- return undefined;
36
- }
48
+ return JSON.parse(value as string);
37
49
 
38
50
  default:
39
51
  return undefined;
40
52
  }
41
53
  } catch (error) {
42
54
  // Log error and return undefined if any error occurs during parsing
43
- console.error(`Error parsing environment variable`);
55
+ if (verbose) {
56
+ console.error(
57
+ `Error parsing environment variable, parsing : ${((value ?? '') as string).toString()}`
58
+ );
59
+ }
44
60
  return undefined;
45
61
  }
46
62
  }