@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.
- package/dist/cjs/configFile/buildConfigurationFields.cjs +253 -38
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
- package/dist/cjs/configFile/buildConfigurationFields.d.ts +3 -0
- package/dist/cjs/configFile/getConfiguration.cjs.map +1 -1
- package/dist/cjs/configFile/getConfiguration.d.ts +3 -0
- package/dist/cjs/configFile/index.cjs +3 -1
- package/dist/cjs/configFile/index.cjs.map +1 -1
- package/dist/cjs/configFile/index.d.ts +1 -0
- package/dist/cjs/configFile/loadConfigurationFile.cjs +8 -1
- package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
- package/dist/cjs/configFile/loadConfigurationFile.d.ts +6 -0
- package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
- package/dist/cjs/configFile/searchConfigurationFile.d.ts +11 -0
- package/dist/cjs/defaultValues/internationalization.cjs +1 -5
- package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
- package/dist/cjs/defaultValues/internationalization.d.ts +1 -1
- package/dist/cjs/defaultValues/server.cjs +0 -6
- package/dist/cjs/defaultValues/server.cjs.map +1 -1
- package/dist/cjs/defaultValues/server.d.ts +1 -3
- package/dist/cjs/envVariables/detectPlatform.cjs +53 -0
- package/dist/cjs/envVariables/detectPlatform.cjs.map +1 -0
- package/dist/cjs/envVariables/detectPlatform.d.ts +11 -0
- package/dist/cjs/envVariables/extractEnvVariable.cjs +211 -0
- package/dist/cjs/envVariables/extractEnvVariable.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable.d.ts +13 -0
- package/dist/cjs/envVariables/formatEnvVariable.cjs +6 -4
- package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
- package/dist/cjs/envVariables/formatEnvVariable.d.ts +6 -1
- package/dist/cjs/envVariables/getConfiguration.cjs +37 -38
- package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
- package/dist/cjs/envVariables/getConfiguration.d.ts +5 -0
- package/dist/cjs/envVariables/index.d.ts +1 -0
- package/dist/cjs/envVariables/utils.cjs +7 -6
- package/dist/cjs/envVariables/utils.cjs.map +1 -1
- package/dist/cjs/envVariables/utils.d.ts +5 -5
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/types/config.cjs.map +1 -1
- package/dist/cjs/types/config.d.ts +212 -6
- package/dist/cjs/types/locales.cjs.map +1 -1
- package/dist/cjs/types/locales.d.ts +233 -0
- package/dist/esm/configFile/buildConfigurationFields.d.mts +3 -0
- package/dist/esm/configFile/buildConfigurationFields.mjs +253 -40
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
- package/dist/esm/configFile/getConfiguration.d.mts +3 -0
- package/dist/esm/configFile/getConfiguration.mjs.map +1 -1
- package/dist/esm/configFile/index.d.mts +1 -0
- package/dist/esm/configFile/index.mjs +1 -0
- package/dist/esm/configFile/index.mjs.map +1 -1
- package/dist/esm/configFile/loadConfigurationFile.d.mts +6 -0
- package/dist/esm/configFile/loadConfigurationFile.mjs +8 -1
- package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
- package/dist/esm/configFile/searchConfigurationFile.d.mts +11 -0
- package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
- package/dist/esm/defaultValues/internationalization.d.mts +1 -1
- package/dist/esm/defaultValues/internationalization.mjs +1 -5
- package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
- package/dist/esm/defaultValues/server.d.mts +1 -3
- package/dist/esm/defaultValues/server.mjs +0 -4
- package/dist/esm/defaultValues/server.mjs.map +1 -1
- package/dist/esm/envVariables/detectPlatform.d.mts +11 -0
- package/dist/esm/envVariables/detectPlatform.mjs +27 -0
- package/dist/esm/envVariables/detectPlatform.mjs.map +1 -0
- package/dist/esm/envVariables/extractEnvVariable.d.mts +13 -0
- package/dist/esm/envVariables/extractEnvVariable.mjs +186 -0
- package/dist/esm/envVariables/extractEnvVariable.mjs.map +1 -0
- package/dist/esm/envVariables/formatEnvVariable.d.mts +6 -1
- package/dist/esm/envVariables/formatEnvVariable.mjs +6 -4
- package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
- package/dist/esm/envVariables/getConfiguration.d.mts +5 -0
- package/dist/esm/envVariables/getConfiguration.mjs +37 -38
- package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
- package/dist/esm/envVariables/index.d.mts +1 -0
- package/dist/esm/envVariables/utils.d.mts +5 -5
- package/dist/esm/envVariables/utils.mjs +7 -6
- package/dist/esm/envVariables/utils.mjs.map +1 -1
- package/dist/esm/index.d.mts +1 -0
- package/dist/esm/types/config.d.mts +212 -6
- package/dist/esm/types/locales.d.mts +233 -0
- package/dist/esm/types/locales.mjs.map +1 -1
- package/package.json +7 -7
- package/src/configFile/buildConfigurationFields.ts +258 -47
- package/src/configFile/getConfiguration.ts +3 -0
- package/src/configFile/index.ts +1 -0
- package/src/configFile/loadConfigurationFile.ts +19 -1
- package/src/configFile/searchConfigurationFile.ts +11 -0
- package/src/defaultValues/server.ts +0 -4
- package/src/envVariables/detectPlatform.ts +37 -0
- package/src/envVariables/extractEnvVariable.ts +224 -0
- package/src/envVariables/formatEnvVariable.ts +17 -11
- package/src/envVariables/getConfiguration.ts +40 -41
- package/src/envVariables/utils.ts +30 -14
- package/src/types/config.ts +237 -65
- package/src/types/locales.ts +233 -233
|
@@ -9,13 +9,11 @@ import {
|
|
|
9
9
|
SERVER_SET_COOKIE
|
|
10
10
|
} from '../defaultValues/middleware.mjs';
|
|
11
11
|
import {
|
|
12
|
-
BUNDLE_DIR_NAME,
|
|
13
12
|
CONTENT_DIR_NAME,
|
|
14
13
|
DICTIONARIES_DIR_NAME,
|
|
15
14
|
FILE_EXTENSIONS,
|
|
16
15
|
RESULT_DIR_NAME,
|
|
17
16
|
EXCLUDED_PATHS,
|
|
18
|
-
BUNDLE_FILE_EXTENSION,
|
|
19
17
|
TYPES_DIR_NAME,
|
|
20
18
|
MAIN_DIR_NAME,
|
|
21
19
|
MODULE_AUGMENTATION_DIR_NAME
|
|
@@ -23,107 +21,322 @@ import {
|
|
|
23
21
|
let storedConfiguration;
|
|
24
22
|
const buildInternationalizationFields = (customConfiguration) => ({
|
|
25
23
|
/**
|
|
26
|
-
*
|
|
24
|
+
* Locales available in the application
|
|
25
|
+
*
|
|
26
|
+
* Default: ['en']
|
|
27
27
|
*/
|
|
28
|
-
// Locales available in the application
|
|
29
28
|
locales: customConfiguration?.locales ?? LOCALES,
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Default locale of the application for fallback
|
|
31
|
+
*
|
|
32
|
+
* Default: 'en'
|
|
33
|
+
*/
|
|
31
34
|
defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE
|
|
32
35
|
});
|
|
33
36
|
const buildMiddlewareFields = (customConfiguration) => ({
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
38
|
+
* Header name to get the locale
|
|
39
|
+
*
|
|
40
|
+
* Default: 'x-intlayer-locale'
|
|
36
41
|
*/
|
|
37
|
-
// Header name to get the locale
|
|
38
42
|
headerName: customConfiguration?.headerName ?? HEADER_NAME,
|
|
39
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Cookie name to get the locale
|
|
45
|
+
*
|
|
46
|
+
* Default: 'intlayer-locale'
|
|
47
|
+
*/
|
|
40
48
|
cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,
|
|
41
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Prefix the default locale in the URL
|
|
51
|
+
*
|
|
52
|
+
* Default: true
|
|
53
|
+
*/
|
|
42
54
|
prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,
|
|
43
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Base path of the application URL
|
|
57
|
+
*
|
|
58
|
+
* Default: ''
|
|
59
|
+
*
|
|
60
|
+
* Example:
|
|
61
|
+
* - If the application is hosted at https://example.com/my-app
|
|
62
|
+
* - The base path is '/my-app'
|
|
63
|
+
* - The URL will be https://example.com/my-app/en
|
|
64
|
+
* - If the base path is not set, the URL will be https://example.com/en
|
|
65
|
+
*/
|
|
44
66
|
basePath: customConfiguration?.basePath ?? BASE_PATH,
|
|
45
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Rule to set the cookie on the server
|
|
69
|
+
* - 'always': Set the cookie on every request
|
|
70
|
+
* - 'never': Never set the cookie
|
|
71
|
+
*/
|
|
46
72
|
serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,
|
|
47
|
-
|
|
73
|
+
/**
|
|
74
|
+
* No prefix in the URL
|
|
75
|
+
* - true: No prefix in the URL
|
|
76
|
+
* - false: Prefix in the URL
|
|
77
|
+
*
|
|
78
|
+
* Example:
|
|
79
|
+
* - If the application is hosted at https://example.com/my-app
|
|
80
|
+
* - The base path is '/my-app'
|
|
81
|
+
* - The URL will be https://example.com/my-app/en
|
|
82
|
+
* - If the base path is not set, the URL will be https://example.com/en
|
|
83
|
+
* - If no prefix is set, the URL will be https://example.com/en
|
|
84
|
+
* - If the no prefix is set to true, the URL will be https://example.com
|
|
85
|
+
*
|
|
86
|
+
* Default: false
|
|
87
|
+
*/
|
|
48
88
|
noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX
|
|
49
89
|
});
|
|
50
90
|
const buildContentFields = (customConfiguration) => {
|
|
51
91
|
const notDerivedContentConfig = {
|
|
52
92
|
/**
|
|
53
|
-
*
|
|
93
|
+
* File extensions of content to look for to build the dictionaries
|
|
94
|
+
*
|
|
95
|
+
* - Default: ['.content.ts', '.content.js', '.content.json']
|
|
96
|
+
*
|
|
97
|
+
* - Example: ['.data.ts', '.data.js', '.data.json']
|
|
98
|
+
*
|
|
99
|
+
* Note:
|
|
100
|
+
* - Can exclude unused file extensions to improve performance
|
|
101
|
+
* - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts
|
|
54
102
|
*/
|
|
55
|
-
// File extensions of content to look for
|
|
56
103
|
fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,
|
|
57
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Absolute path of the directory of the project
|
|
106
|
+
* - Default: process.cwd()
|
|
107
|
+
* - Example: '/path/to/project'
|
|
108
|
+
*
|
|
109
|
+
* Will be used to resolve all intlayer directories
|
|
110
|
+
*
|
|
111
|
+
* Note:
|
|
112
|
+
* - The base directory should be the root of the project
|
|
113
|
+
* - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project
|
|
114
|
+
*/
|
|
58
115
|
baseDir: customConfiguration?.baseDir ?? process.cwd(),
|
|
59
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Directory name where the content is stored
|
|
118
|
+
*
|
|
119
|
+
* Default: 'src'
|
|
120
|
+
*
|
|
121
|
+
* Example:
|
|
122
|
+
* - 'data' -> '/path/to/project/data'
|
|
123
|
+
* - 'content' -> '/path/to/project/content'
|
|
124
|
+
* - 'locales' -> '/path/to/project/locales'
|
|
125
|
+
*
|
|
126
|
+
* Note: If this directory is not at the base directory level, update the contentDir field instead
|
|
127
|
+
*/
|
|
60
128
|
contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,
|
|
61
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Directory name where the result will be stored
|
|
131
|
+
*
|
|
132
|
+
* Default: '.intlayer'
|
|
133
|
+
*
|
|
134
|
+
* Example:
|
|
135
|
+
* - '.next'
|
|
136
|
+
* - 'outputOFIntlayer'
|
|
137
|
+
*
|
|
138
|
+
* Note: If this directory is not at the base directory level, update the resultDir field instead
|
|
139
|
+
*/
|
|
62
140
|
resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,
|
|
63
|
-
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
* Directory name where the module augmentation will be stored
|
|
144
|
+
*
|
|
145
|
+
* Module augmentation allow better IDE suggestions and type checking
|
|
146
|
+
*
|
|
147
|
+
* Default: 'types'
|
|
148
|
+
*
|
|
149
|
+
* Example: 'intlayer-types'
|
|
150
|
+
*
|
|
151
|
+
* Note:
|
|
152
|
+
* - If this path changed, be sure to include it from the tsconfig.json file
|
|
153
|
+
* - If this directory is not at the base directory level, update the moduleAugmentationDir field instead
|
|
154
|
+
*/
|
|
64
155
|
moduleAugmentationDirName: customConfiguration?.moduleAugmentationDirName ?? MODULE_AUGMENTATION_DIR_NAME,
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
156
|
+
// @TODO: Make Module Augmentation optional by adding a flag in the configuration
|
|
157
|
+
/**
|
|
158
|
+
* Related to the intlayer result directory
|
|
159
|
+
*
|
|
160
|
+
* Directory name where the dictionaries will be stored
|
|
161
|
+
*
|
|
162
|
+
* Default: 'dictionary'
|
|
163
|
+
*
|
|
164
|
+
* Example: 'translations'
|
|
165
|
+
*
|
|
166
|
+
* Note:
|
|
167
|
+
* - If this directory is not at the result directory level, update the dictionariesDir field instead
|
|
168
|
+
*
|
|
169
|
+
*/
|
|
70
170
|
dictionariesDirName: customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,
|
|
71
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Related to the intlayer result directory
|
|
173
|
+
*
|
|
174
|
+
* Directory name where the dictionaries types will be stored
|
|
175
|
+
*
|
|
176
|
+
* Default: 'types'
|
|
177
|
+
*
|
|
178
|
+
* Example: 'intlayer-types'
|
|
179
|
+
*
|
|
180
|
+
* Note:
|
|
181
|
+
* - If this directory is not at the result directory level, update the typesDir field instead
|
|
182
|
+
*
|
|
183
|
+
*/
|
|
72
184
|
typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,
|
|
73
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Related to the intlayer result directory
|
|
187
|
+
*
|
|
188
|
+
* Directory name where the main files will be stored
|
|
189
|
+
*
|
|
190
|
+
* Default: 'main'
|
|
191
|
+
*
|
|
192
|
+
* Example: 'intlayer-main'
|
|
193
|
+
*
|
|
194
|
+
* Note:
|
|
195
|
+
* - If this directory is not at the result directory level, update the mainDir field instead
|
|
196
|
+
*/
|
|
74
197
|
mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,
|
|
75
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Should exclude some directories from the content search
|
|
200
|
+
*
|
|
201
|
+
* Default: ['node_modules']
|
|
202
|
+
*
|
|
203
|
+
* Not used yet
|
|
204
|
+
* @TODO Implement the exclusion or remove it
|
|
205
|
+
*/
|
|
76
206
|
excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS
|
|
77
207
|
};
|
|
78
208
|
const baseDirDerivedConfiguration = {
|
|
79
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Directory where the content is stored
|
|
211
|
+
*
|
|
212
|
+
* Relative to the base directory of the project
|
|
213
|
+
*
|
|
214
|
+
* Default: {{baseDir}} / {{contentDirName}}
|
|
215
|
+
*
|
|
216
|
+
* Example: '/path/to/project/src'
|
|
217
|
+
*
|
|
218
|
+
* Note:
|
|
219
|
+
* - Can be changed to a custom directory to externalize the content used in the project
|
|
220
|
+
* - If the content is not at the base directory level, update the contentDirName field instead
|
|
221
|
+
*/
|
|
80
222
|
contentDir: join(
|
|
81
223
|
notDerivedContentConfig.baseDir,
|
|
82
224
|
notDerivedContentConfig.contentDirName
|
|
83
225
|
),
|
|
84
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Directory where the result will be stored
|
|
228
|
+
*
|
|
229
|
+
* Relative to the base directory of the project
|
|
230
|
+
*
|
|
231
|
+
* Default: {{baseDir}} / {{resultDirName}}
|
|
232
|
+
*
|
|
233
|
+
* Example: '/path/to/project/.intlayer'
|
|
234
|
+
*
|
|
235
|
+
* Note:
|
|
236
|
+
* - Can be changed to a custom directory to externalize the intlayer application from the project
|
|
237
|
+
* - If the result is not at the base directory level, update the resultDirName field instead
|
|
238
|
+
*/
|
|
85
239
|
resultDir: join(
|
|
86
240
|
notDerivedContentConfig.baseDir,
|
|
87
241
|
notDerivedContentConfig.resultDirName
|
|
88
242
|
),
|
|
89
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Directory where the module augmentation will be stored
|
|
245
|
+
*
|
|
246
|
+
* Module augmentation allow better IDE suggestions and type checking
|
|
247
|
+
*
|
|
248
|
+
* Relative to the base directory of the project
|
|
249
|
+
*
|
|
250
|
+
* Default: {{baseDir}} / {{moduleAugmentationDirName}}
|
|
251
|
+
*
|
|
252
|
+
* Example: '/path/to/project/types'
|
|
253
|
+
*
|
|
254
|
+
* Note:
|
|
255
|
+
* - If this path changed, be sure to include it from the tsconfig.json file
|
|
256
|
+
* - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead
|
|
257
|
+
*
|
|
258
|
+
*/
|
|
90
259
|
moduleAugmentationDir: join(
|
|
91
260
|
notDerivedContentConfig.baseDir,
|
|
92
261
|
notDerivedContentConfig.moduleAugmentationDirName
|
|
93
262
|
)
|
|
94
263
|
};
|
|
95
264
|
const resultDirDerivedConfiguration = {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Directory where the dictionaries will be stored
|
|
267
|
+
*
|
|
268
|
+
* Relative to the result directory
|
|
269
|
+
*
|
|
270
|
+
* Default: {{resultDir}} / {{dictionariesDirName}}
|
|
271
|
+
*
|
|
272
|
+
* Example: '/path/to/project/.intlayer/dictionary'
|
|
273
|
+
*
|
|
274
|
+
* Note:
|
|
275
|
+
* - If the types are not at the result directory level, update the dictionariesDirName field instead
|
|
276
|
+
* - The dictionaries are stored in JSON format
|
|
277
|
+
* - The dictionaries are used to translate the content
|
|
278
|
+
* - The dictionaries are built from the content files
|
|
279
|
+
*/
|
|
102
280
|
dictionariesDir: join(
|
|
103
281
|
baseDirDerivedConfiguration.resultDir,
|
|
104
282
|
notDerivedContentConfig.dictionariesDirName
|
|
105
283
|
),
|
|
106
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Directory where the dictionaries types will be stored
|
|
286
|
+
*
|
|
287
|
+
* Relative to the result directory
|
|
288
|
+
*
|
|
289
|
+
* Default: {{resultDir}} / {{typeDirName}}
|
|
290
|
+
*
|
|
291
|
+
* Example: '/path/to/project/.intlayer/types'
|
|
292
|
+
*
|
|
293
|
+
* Note:
|
|
294
|
+
* - If the types are not at the result directory level, update the typesDirName field instead
|
|
295
|
+
*/
|
|
107
296
|
typesDir: join(
|
|
108
297
|
baseDirDerivedConfiguration.resultDir,
|
|
109
298
|
notDerivedContentConfig.typeDirName
|
|
110
299
|
),
|
|
111
|
-
|
|
300
|
+
/**
|
|
301
|
+
* Directory where the main files will be stored
|
|
302
|
+
*
|
|
303
|
+
* Relative to the result directory
|
|
304
|
+
*
|
|
305
|
+
* Default: {{resultDir}} / {{mainDirName}}
|
|
306
|
+
*
|
|
307
|
+
* Example: '/path/to/project/.intlayer/main'
|
|
308
|
+
*
|
|
309
|
+
* Note:
|
|
310
|
+
*
|
|
311
|
+
* - If the main files are not at the result directory level, update the mainDirName field instead
|
|
312
|
+
*/
|
|
112
313
|
mainDir: join(
|
|
113
314
|
baseDirDerivedConfiguration.resultDir,
|
|
114
315
|
notDerivedContentConfig.mainDirName
|
|
115
316
|
)
|
|
116
317
|
};
|
|
117
318
|
const patternsConfiguration = {
|
|
118
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Pattern of files to watch
|
|
321
|
+
*
|
|
322
|
+
* Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json']
|
|
323
|
+
*/
|
|
119
324
|
watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
|
|
120
325
|
(ext) => `/**/*${ext}`
|
|
121
326
|
),
|
|
122
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Pattern of files to watch including the relative path
|
|
329
|
+
*
|
|
330
|
+
* Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json']
|
|
331
|
+
*/
|
|
123
332
|
watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
|
|
124
333
|
(ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
|
|
125
334
|
),
|
|
126
|
-
|
|
335
|
+
/**
|
|
336
|
+
* Pattern of dictionary to interpret
|
|
337
|
+
*
|
|
338
|
+
* Default: '{{dictionariesDir}}/**\/*.json'
|
|
339
|
+
*/
|
|
127
340
|
outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`
|
|
128
341
|
};
|
|
129
342
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/configFile/buildConfigurationFields.ts"],"sourcesContent":["import { join } from 'path';\nimport { DEFAULT_LOCALE, LOCALES } from '../defaultValues/internationalization';\nimport {\n BASE_PATH,\n COOKIE_NAME,\n HEADER_NAME,\n NO_PREFIX,\n PREFIX_DEFAULT,\n SERVER_SET_COOKIE,\n} from '../defaultValues/middleware';\nimport {\n BUNDLE_DIR_NAME,\n CONTENT_DIR_NAME,\n DICTIONARIES_DIR_NAME,\n FILE_EXTENSIONS,\n RESULT_DIR_NAME,\n EXCLUDED_PATHS,\n BUNDLE_FILE_EXTENSION,\n TYPES_DIR_NAME,\n MAIN_DIR_NAME,\n MODULE_AUGMENTATION_DIR_NAME,\n} from '../defaultValues/server';\nimport type {\n BaseDerivedConfig,\n ContentConfig,\n CustomIntlayerConfig,\n PatternsContentConfig,\n InternationalizationConfig,\n IntlayerConfig,\n MiddlewareConfig,\n BaseContentConfig,\n ResultDirDerivedConfig,\n} from '../types/config';\nimport type { GetConfigurationOptions } from './getConfiguration';\n\nlet storedConfiguration: IntlayerConfig;\n\nconst buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Internationalization configuration\n */\n\n // Locales available in the application\n locales: customConfiguration?.locales ?? LOCALES,\n\n // Default locale of the application for fallback\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\nconst buildMiddlewareFields = (\n customConfiguration?: Partial<MiddlewareConfig>\n): MiddlewareConfig => ({\n /**\n * Middleware configuration\n */\n\n // Header name to get the locale\n headerName: customConfiguration?.headerName ?? HEADER_NAME,\n\n // Cookie name to get the locale\n cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,\n\n // Prefix the default locale in the URL\n prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,\n\n // Base path\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n // Set cookie on server\n serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,\n\n // No prefix\n noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,\n});\n\nconst buildContentFields = (\n customConfiguration?: Partial<ContentConfig>\n): ContentConfig => {\n const notDerivedContentConfig: BaseContentConfig = {\n /**\n * Content configurations\n */\n\n // File extensions of content to look for\n fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,\n\n // Directory name of the project\n baseDir: customConfiguration?.baseDir ?? process.cwd(),\n\n // Directory name where the content is stored\n contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,\n\n // Result directory name\n resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,\n\n // Module augmentation directory name\n moduleAugmentationDirName:\n customConfiguration?.moduleAugmentationDirName ??\n MODULE_AUGMENTATION_DIR_NAME,\n\n // Bundle directory name\n bundleDirName: customConfiguration?.bundleDirName ?? BUNDLE_DIR_NAME,\n\n // Bundle file extension\n bundleFileExtension:\n customConfiguration?.bundleFileExtension ?? BUNDLE_FILE_EXTENSION,\n\n // Dictionary directory name\n dictionariesDirName:\n customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,\n\n // Types directory name\n typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,\n\n // Main directory name\n mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,\n\n // Directories to exclude\n excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,\n };\n\n const baseDirDerivedConfiguration: BaseDerivedConfig = {\n // Directory where the content is stored\n contentDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.contentDirName\n ),\n\n // Directory where the result will be stored\n resultDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.resultDirName\n ),\n\n // Directory where the module augmentation will be stored\n moduleAugmentationDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.moduleAugmentationDirName\n ),\n };\n\n const resultDirDerivedConfiguration: ResultDirDerivedConfig = {\n // Directory where the bundle will be stored\n bundleDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.bundleDirName\n ),\n\n // Directory where the dictionaries will be stored\n dictionariesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.dictionariesDirName\n ),\n\n // Directory where the types will be stored\n typesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.typeDirName\n ),\n\n // Directory where the main files will be stored\n mainDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.mainDirName\n ),\n };\n\n const patternsConfiguration: PatternsContentConfig = {\n // Pattern of files to watch\n watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(\n (ext) => `/**/*${ext}`\n ),\n\n // Pattern of files to watch including the relative path\n watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(\n (ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`\n ),\n\n // Pattern of files to output\n outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,\n };\n\n return {\n ...notDerivedContentConfig,\n ...baseDirDerivedConfiguration,\n ...resultDirDerivedConfiguration,\n ...patternsConfiguration,\n };\n};\n\nexport const buildConfigurationFields = (\n options: GetConfigurationOptions,\n customConfiguration?: CustomIntlayerConfig\n): IntlayerConfig => {\n const internationalizationConfig = buildInternationalizationFields(\n customConfiguration?.internationalization\n );\n\n const middlewareConfig = buildMiddlewareFields(\n customConfiguration?.middleware\n );\n\n const contentConfig = buildContentFields(customConfiguration?.content);\n\n storedConfiguration = {\n internationalization: internationalizationConfig,\n middleware: middlewareConfig,\n content: contentConfig,\n };\n\n return storedConfiguration;\n};\n"],"mappings":"AAAA,SAAS,YAAY;AACrB,SAAS,gBAAgB,eAAe;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,IAAI;AAEJ,MAAM,kCAAkC,CACtC,yBACgC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhC,SAAS,qBAAqB,WAAW;AAAA;AAAA,EAGzC,eAAe,qBAAqB,iBAAiB;AACvD;AAEA,MAAM,wBAAwB,CAC5B,yBACsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,YAAY,qBAAqB,cAAc;AAAA;AAAA,EAG/C,YAAY,qBAAqB,cAAc;AAAA;AAAA,EAG/C,eAAe,qBAAqB,iBAAiB;AAAA;AAAA,EAGrD,UAAU,qBAAqB,YAAY;AAAA;AAAA,EAG3C,iBAAiB,qBAAqB,mBAAmB;AAAA;AAAA,EAGzD,UAAU,qBAAqB,YAAY;AAC7C;AAEA,MAAM,qBAAqB,CACzB,wBACkB;AAClB,QAAM,0BAA6C;AAAA;AAAA;AAAA;AAAA;AAAA,IAMjD,gBAAgB,qBAAqB,kBAAkB;AAAA;AAAA,IAGvD,SAAS,qBAAqB,WAAW,QAAQ,IAAI;AAAA;AAAA,IAGrD,gBAAgB,qBAAqB,kBAAkB;AAAA;AAAA,IAGvD,eAAe,qBAAqB,iBAAiB;AAAA;AAAA,IAGrD,2BACE,qBAAqB,6BACrB;AAAA;AAAA,IAGF,eAAe,qBAAqB,iBAAiB;AAAA;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C,SACA,wBACmB;AACnB,QAAM,6BAA6B;AAAA,IACjC,qBAAqB;AAAA,EACvB;AAEA,QAAM,mBAAmB;AAAA,IACvB,qBAAqB;AAAA,EACvB;AAEA,QAAM,gBAAgB,mBAAmB,qBAAqB,OAAO;AAErE,wBAAsB;AAAA,IACpB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,SAAS;AAAA,EACX;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/buildConfigurationFields.ts"],"sourcesContent":["import { join } from 'path';\nimport { DEFAULT_LOCALE, LOCALES } from '../defaultValues/internationalization';\nimport {\n BASE_PATH,\n COOKIE_NAME,\n HEADER_NAME,\n NO_PREFIX,\n PREFIX_DEFAULT,\n SERVER_SET_COOKIE,\n} from '../defaultValues/middleware';\nimport {\n CONTENT_DIR_NAME,\n DICTIONARIES_DIR_NAME,\n FILE_EXTENSIONS,\n RESULT_DIR_NAME,\n EXCLUDED_PATHS,\n TYPES_DIR_NAME,\n MAIN_DIR_NAME,\n MODULE_AUGMENTATION_DIR_NAME,\n} from '../defaultValues/server';\nimport type {\n BaseDerivedConfig,\n ContentConfig,\n CustomIntlayerConfig,\n PatternsContentConfig,\n InternationalizationConfig,\n IntlayerConfig,\n MiddlewareConfig,\n BaseContentConfig,\n ResultDirDerivedConfig,\n} from '../types/config';\nimport type { GetConfigurationOptions } from './getConfiguration';\n\nlet storedConfiguration: IntlayerConfig;\n\n// @TODO - Add possibility of directories configurations to be arrays to allow multiple packages management\n\nconst buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\nconst buildMiddlewareFields = (\n customConfiguration?: Partial<MiddlewareConfig>\n): MiddlewareConfig => ({\n /**\n * Header name to get the locale\n *\n * Default: 'x-intlayer-locale'\n */\n headerName: customConfiguration?.headerName ?? HEADER_NAME,\n\n /**\n * Cookie name to get the locale\n *\n * Default: 'intlayer-locale'\n */\n cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,\n\n /**\n * Prefix the default locale in the URL\n *\n * Default: true\n */\n prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Rule to set the cookie on the server\n * - 'always': Set the cookie on every request\n * - 'never': Never set the cookie\n */\n serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,\n\n /**\n * No prefix in the URL\n * - true: No prefix in the URL\n * - false: Prefix in the URL\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n * - If no prefix is set, the URL will be https://example.com/en\n * - If the no prefix is set to true, the URL will be https://example.com\n *\n * Default: false\n */\n noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,\n});\n\nconst buildContentFields = (\n customConfiguration?: Partial<ContentConfig>\n): ContentConfig => {\n const notDerivedContentConfig: BaseContentConfig = {\n /**\n * File extensions of content to look for to build the dictionaries\n *\n * - Default: ['.content.ts', '.content.js', '.content.json']\n *\n * - Example: ['.data.ts', '.data.js', '.data.json']\n *\n * Note:\n * - Can exclude unused file extensions to improve performance\n * - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts\n */\n fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,\n\n /**\n * Absolute path of the directory of the project\n * - Default: process.cwd()\n * - Example: '/path/to/project'\n *\n * Will be used to resolve all intlayer directories\n *\n * Note:\n * - The base directory should be the root of the project\n * - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project\n */\n baseDir: customConfiguration?.baseDir ?? process.cwd(),\n\n /**\n * Directory name where the content is stored\n *\n * Default: 'src'\n *\n * Example:\n * - 'data' -> '/path/to/project/data'\n * - 'content' -> '/path/to/project/content'\n * - 'locales' -> '/path/to/project/locales'\n *\n * Note: If this directory is not at the base directory level, update the contentDir field instead\n */\n contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,\n\n /**\n * Directory name where the result will be stored\n *\n * Default: '.intlayer'\n *\n * Example:\n * - '.next'\n * - 'outputOFIntlayer'\n *\n * Note: If this directory is not at the base directory level, update the resultDir field instead\n */\n resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,\n\n /**\n *\n * Directory name where the module augmentation will be stored\n *\n * Module augmentation allow better IDE suggestions and type checking\n *\n * Default: 'types'\n *\n * Example: 'intlayer-types'\n *\n * Note:\n * - If this path changed, be sure to include it from the tsconfig.json file\n * - If this directory is not at the base directory level, update the moduleAugmentationDir field instead\n */\n moduleAugmentationDirName:\n customConfiguration?.moduleAugmentationDirName ??\n MODULE_AUGMENTATION_DIR_NAME,\n // @TODO: Make Module Augmentation optional by adding a flag in the configuration\n\n /**\n * Related to the intlayer result directory\n *\n * Directory name where the dictionaries will be stored\n *\n * Default: 'dictionary'\n *\n * Example: 'translations'\n *\n * Note:\n * - If this directory is not at the result directory level, update the dictionariesDir field instead\n *\n */\n dictionariesDirName:\n customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,\n\n /**\n * Related to the intlayer result directory\n *\n * Directory name where the dictionaries types will be stored\n *\n * Default: 'types'\n *\n * Example: 'intlayer-types'\n *\n * Note:\n * - If this directory is not at the result directory level, update the typesDir field instead\n *\n */\n typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,\n\n /**\n * Related to the intlayer result directory\n *\n * Directory name where the main files will be stored\n *\n * Default: 'main'\n *\n * Example: 'intlayer-main'\n *\n * Note:\n * - If this directory is not at the result directory level, update the mainDir field instead\n */\n mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,\n\n /**\n * Should exclude some directories from the content search\n *\n * Default: ['node_modules']\n *\n * Not used yet\n * @TODO Implement the exclusion or remove it\n */\n excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,\n };\n\n const baseDirDerivedConfiguration: BaseDerivedConfig = {\n /**\n * Directory where the content is stored\n *\n * Relative to the base directory of the project\n *\n * Default: {{baseDir}} / {{contentDirName}}\n *\n * Example: '/path/to/project/src'\n *\n * Note:\n * - Can be changed to a custom directory to externalize the content used in the project\n * - If the content is not at the base directory level, update the contentDirName field instead\n */\n contentDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.contentDirName\n ),\n\n /**\n * Directory where the result will be stored\n *\n * Relative to the base directory of the project\n *\n * Default: {{baseDir}} / {{resultDirName}}\n *\n * Example: '/path/to/project/.intlayer'\n *\n * Note:\n * - Can be changed to a custom directory to externalize the intlayer application from the project\n * - If the result is not at the base directory level, update the resultDirName field instead\n */\n resultDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.resultDirName\n ),\n\n /**\n * Directory where the module augmentation will be stored\n *\n * Module augmentation allow better IDE suggestions and type checking\n *\n * Relative to the base directory of the project\n *\n * Default: {{baseDir}} / {{moduleAugmentationDirName}}\n *\n * Example: '/path/to/project/types'\n *\n * Note:\n * - If this path changed, be sure to include it from the tsconfig.json file\n * - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead\n *\n */\n moduleAugmentationDir: join(\n notDerivedContentConfig.baseDir,\n notDerivedContentConfig.moduleAugmentationDirName\n ),\n };\n\n const resultDirDerivedConfiguration: ResultDirDerivedConfig = {\n /**\n * Directory where the dictionaries will be stored\n *\n * Relative to the result directory\n *\n * Default: {{resultDir}} / {{dictionariesDirName}}\n *\n * Example: '/path/to/project/.intlayer/dictionary'\n *\n * Note:\n * - If the types are not at the result directory level, update the dictionariesDirName field instead\n * - The dictionaries are stored in JSON format\n * - The dictionaries are used to translate the content\n * - The dictionaries are built from the content files\n */\n dictionariesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.dictionariesDirName\n ),\n\n /**\n * Directory where the dictionaries types will be stored\n *\n * Relative to the result directory\n *\n * Default: {{resultDir}} / {{typeDirName}}\n *\n * Example: '/path/to/project/.intlayer/types'\n *\n * Note:\n * - If the types are not at the result directory level, update the typesDirName field instead\n */\n typesDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.typeDirName\n ),\n\n /**\n * Directory where the main files will be stored\n *\n * Relative to the result directory\n *\n * Default: {{resultDir}} / {{mainDirName}}\n *\n * Example: '/path/to/project/.intlayer/main'\n *\n * Note:\n *\n * - If the main files are not at the result directory level, update the mainDirName field instead\n */\n mainDir: join(\n baseDirDerivedConfiguration.resultDir,\n notDerivedContentConfig.mainDirName\n ),\n };\n\n const patternsConfiguration: PatternsContentConfig = {\n /**\n * Pattern of files to watch\n *\n * Default: ['/**\\/*.content.ts', '/**\\/*.content.js', '/**\\/*.content.json']\n */\n watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(\n (ext) => `/**/*${ext}`\n ),\n\n /**\n * Pattern of files to watch including the relative path\n *\n * Default: ['{{contentDir}}/**\\/*.content.ts', '{{contentDir}}/**\\/*.content.js', '{{contentDir}}/**\\/*.content.json']\n */\n watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(\n (ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`\n ),\n\n /**\n * Pattern of dictionary to interpret\n *\n * Default: '{{dictionariesDir}}/**\\/*.json'\n */\n outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,\n };\n\n return {\n ...notDerivedContentConfig,\n ...baseDirDerivedConfiguration,\n ...resultDirDerivedConfiguration,\n ...patternsConfiguration,\n };\n};\n\n/**\n * Build the configuration fields by merging the default values with the custom configuration\n */\nexport const buildConfigurationFields = (\n options: GetConfigurationOptions,\n customConfiguration?: CustomIntlayerConfig\n): IntlayerConfig => {\n const internationalizationConfig = buildInternationalizationFields(\n customConfiguration?.internationalization\n );\n\n const middlewareConfig = buildMiddlewareFields(\n customConfiguration?.middleware\n );\n\n const contentConfig = buildContentFields(customConfiguration?.content);\n\n storedConfiguration = {\n internationalization: internationalizationConfig,\n middleware: middlewareConfig,\n content: contentConfig,\n };\n\n return storedConfiguration;\n};\n"],"mappings":"AAAA,SAAS,YAAY;AACrB,SAAS,gBAAgB,eAAe;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,IAAI;AAIJ,MAAM,kCAAkC,CACtC,yBACgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhC,SAAS,qBAAqB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzC,eAAe,qBAAqB,iBAAiB;AACvD;AAEA,MAAM,wBAAwB,CAC5B,yBACsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,YAAY,qBAAqB,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO/C,YAAY,qBAAqB,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO/C,eAAe,qBAAqB,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAarD,UAAU,qBAAqB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO3C,iBAAiB,qBAAqB,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBzD,UAAU,q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,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAKO,MAAM,2BAA2B,CACtC,SACA,wBACmB;AACnB,QAAM,6BAA6B;AAAA,IACjC,qBAAqB;AAAA,EACvB;AAEA,QAAM,mBAAmB;AAAA,IACvB,qBAAqB;AAAA,EACvB;AAEA,QAAM,gBAAgB,mBAAmB,qBAAqB,OAAO;AAErE,wBAAsB;AAAA,IACpB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,SAAS;AAAA,EACX;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -5,6 +5,9 @@ type GetConfigurationOptions = {
|
|
|
5
5
|
baseDir: string;
|
|
6
6
|
verbose: boolean;
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
|
|
10
|
+
*/
|
|
8
11
|
declare const getConfiguration: (options?: Partial<GetConfigurationOptions>) => IntlayerConfig;
|
|
9
12
|
|
|
10
13
|
export { type GetConfigurationOptions, getConfiguration };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { CustomIntlayerConfig, IntlayerConfig } from '../types/config';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nlet storedConfiguration: IntlayerConfig | undefined;\nlet storedConfigurationFilePath: string | undefined;\nlet storedNumCustomConfiguration: number | undefined;\n\nexport type GetConfigurationOptions = {\n baseDir: string;\n verbose: boolean;\n};\n\nconst BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();\nconst defaultOptions: GetConfigurationOptions = {\n baseDir: BASE_DIR_PATH,\n verbose: false,\n};\n\nexport const getConfiguration = (\n options?: Partial<GetConfigurationOptions>\n): IntlayerConfig => {\n const mergedOptions = { ...defaultOptions, ...options };\n const { baseDir, verbose } = mergedOptions;\n\n if (!storedConfiguration) {\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n // Load the custom configuration\n let customConfiguration: CustomIntlayerConfig | undefined;\n if (configurationFilePath) {\n customConfiguration = loadConfigurationFile(configurationFilePath);\n }\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n mergedOptions,\n customConfiguration\n );\n storedConfigurationFilePath = configurationFilePath;\n storedNumCustomConfiguration = numCustomConfiguration;\n }\n\n // Log warning if multiple configuration files are found\n if (verbose)\n logConfigFileResult(\n storedNumCustomConfiguration,\n storedConfigurationFilePath\n );\n\n return storedConfiguration;\n};\n\nconst logConfigFileResult = (\n numCustomConfiguration?: number,\n configurationFilePath?: string\n) => {\n if (numCustomConfiguration === 0) {\n console.info('Configuration file not found, using default configuration.');\n } else {\n const relativeOutputPath = relative(BASE_DIR_PATH, configurationFilePath!);\n\n if (numCustomConfiguration === 1) {\n console.info(`Configuration file found: ${relativeOutputPath}.`);\n } else {\n console.warn(\n `Multiple configuration files found, using ${relativeOutputPath}.`\n );\n }\n }\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AAEzB,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AAExC,IAAI;AACJ,IAAI;AACJ,IAAI;AAOJ,MAAM,gBAAgB,QAAQ,IAAI,0BAA0B,QAAQ,IAAI;AACxE,MAAM,iBAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AACX;
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { CustomIntlayerConfig, IntlayerConfig } from '../types/config';\nimport { buildConfigurationFields } from './buildConfigurationFields';\nimport { loadConfigurationFile } from './loadConfigurationFile';\nimport { searchConfigurationFile } from './searchConfigurationFile';\n\nlet storedConfiguration: IntlayerConfig | undefined;\nlet storedConfigurationFilePath: string | undefined;\nlet storedNumCustomConfiguration: number | undefined;\n\nexport type GetConfigurationOptions = {\n baseDir: string;\n verbose: boolean;\n};\n\nconst BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();\nconst defaultOptions: GetConfigurationOptions = {\n baseDir: BASE_DIR_PATH,\n verbose: false,\n};\n\n/**\n * Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)\n */\nexport const getConfiguration = (\n options?: Partial<GetConfigurationOptions>\n): IntlayerConfig => {\n const mergedOptions = { ...defaultOptions, ...options };\n const { baseDir, verbose } = mergedOptions;\n\n if (!storedConfiguration) {\n // Search for configuration files\n const { configurationFilePath, numCustomConfiguration } =\n searchConfigurationFile(baseDir);\n\n // Load the custom configuration\n let customConfiguration: CustomIntlayerConfig | undefined;\n if (configurationFilePath) {\n customConfiguration = loadConfigurationFile(configurationFilePath);\n }\n\n // Save the configuration to avoid reading the file again\n storedConfiguration = buildConfigurationFields(\n mergedOptions,\n customConfiguration\n );\n storedConfigurationFilePath = configurationFilePath;\n storedNumCustomConfiguration = numCustomConfiguration;\n }\n\n // Log warning if multiple configuration files are found\n if (verbose)\n logConfigFileResult(\n storedNumCustomConfiguration,\n storedConfigurationFilePath\n );\n\n return storedConfiguration;\n};\n\nconst logConfigFileResult = (\n numCustomConfiguration?: number,\n configurationFilePath?: string\n) => {\n if (numCustomConfiguration === 0) {\n console.info('Configuration file not found, using default configuration.');\n } else {\n const relativeOutputPath = relative(BASE_DIR_PATH, configurationFilePath!);\n\n if (numCustomConfiguration === 1) {\n console.info(`Configuration file found: ${relativeOutputPath}.`);\n } else {\n console.warn(\n `Multiple configuration files found, using ${relativeOutputPath}.`\n );\n }\n }\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AAEzB,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AAExC,IAAI;AACJ,IAAI;AACJ,IAAI;AAOJ,MAAM,gBAAgB,QAAQ,IAAI,0BAA0B,QAAQ,IAAI;AACxE,MAAM,iBAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AACX;AAKO,MAAM,mBAAmB,CAC9B,YACmB;AACnB,QAAM,gBAAgB,EAAE,GAAG,gBAAgB,GAAG,QAAQ;AACtD,QAAM,EAAE,SAAS,QAAQ,IAAI;AAE7B,MAAI,CAAC,qBAAqB;AAExB,UAAM,EAAE,uBAAuB,uBAAuB,IACpD,wBAAwB,OAAO;AAGjC,QAAI;AACJ,QAAI,uBAAuB;AACzB,4BAAsB,sBAAsB,qBAAqB;AAAA,IACnE;AAGA,0BAAsB;AAAA,MACpB;AAAA,MACA;AAAA,IACF;AACA,kCAA8B;AAC9B,mCAA+B;AAAA,EACjC;AAGA,MAAI;AACF;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAEF,SAAO;AACT;AAEA,MAAM,sBAAsB,CAC1B,wBACA,0BACG;AACH,MAAI,2BAA2B,GAAG;AAChC,YAAQ,KAAK,4DAA4D;AAAA,EAC3E,OAAO;AACL,UAAM,qBAAqB,SAAS,eAAe,qBAAsB;AAEzE,QAAI,2BAA2B,GAAG;AAChC,cAAQ,KAAK,6BAA6B,kBAAkB,GAAG;AAAA,IACjE,OAAO;AACL,cAAQ;AAAA,QACN,6CAA6C,kBAAkB;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\nexport * from './searchConfigurationFile';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { CustomIntlayerConfig } from '../types/config.mjs';
|
|
2
2
|
import '../types/locales.mjs';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Load the configuration file from the given path
|
|
6
|
+
* Example of configuration file: intlayer.config.js
|
|
7
|
+
*
|
|
8
|
+
* Accepts JSON, JS, MJS and TS files as configuration
|
|
9
|
+
*/
|
|
4
10
|
declare const loadConfigurationFile: (configFilePath: string) => CustomIntlayerConfig | undefined;
|
|
5
11
|
|
|
6
12
|
export { loadConfigurationFile };
|
|
@@ -29,6 +29,9 @@ const transformationOption = {
|
|
|
29
29
|
write: false,
|
|
30
30
|
bundle: true
|
|
31
31
|
};
|
|
32
|
+
const filterValidConfiguration = (configuration) => {
|
|
33
|
+
return configuration;
|
|
34
|
+
};
|
|
32
35
|
const loadConfigurationFile = (configFilePath) => {
|
|
33
36
|
let customConfiguration = void 0;
|
|
34
37
|
const configFileExtension = configFilePath.split(".").pop() ?? "";
|
|
@@ -55,7 +58,11 @@ const loadConfigurationFile = (configFilePath) => {
|
|
|
55
58
|
} else if (sandboxContext.module.exports && Object.keys(sandboxContext.module.exports).length > 0) {
|
|
56
59
|
customConfiguration = sandboxContext.module.exports;
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
if (typeof customConfiguration === "undefined") {
|
|
62
|
+
console.error("Configuration file could not be loaded.");
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
return filterValidConfiguration(customConfiguration);
|
|
59
66
|
} catch (error) {
|
|
60
67
|
console.error("Error:", error);
|
|
61
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport type { CustomIntlayerConfig } from '../types/config';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: isESModule ? createRequire(import.meta.url) : require,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nexport const loadConfigurationFile = (\n configFilePath: string\n): CustomIntlayerConfig | undefined => {\n let customConfiguration: CustomIntlayerConfig | undefined = undefined;\n\n const configFileExtension = configFilePath.split('.').pop() ?? '';\n\n try {\n if (configFileExtension === 'json') {\n // Assume JSON\n return require(configFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [configFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n customConfiguration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n customConfiguration = sandboxContext.module.exports;\n }\n\n return customConfiguration;\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAuB,uBAAuB;AAC9C,SAA4B,iBAAmC;AAG/D,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS,aAAa,cAAc,YAAY,GAAG,IAAI;AACzD;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/loadConfigurationFile.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport type { CustomIntlayerConfig } from '../types/config';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: isESModule ? createRequire(import.meta.url) : require,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nconst filterValidConfiguration = (\n configuration: CustomIntlayerConfig\n): CustomIntlayerConfig => {\n // @TODO Implement filtering of valid configuration\n return configuration;\n};\n\n/**\n * Load the configuration file from the given path\n * Example of configuration file: intlayer.config.js\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadConfigurationFile = (\n configFilePath: string\n): CustomIntlayerConfig | undefined => {\n let customConfiguration: CustomIntlayerConfig | undefined = undefined;\n\n const configFileExtension = configFilePath.split('.').pop() ?? '';\n\n try {\n if (configFileExtension === 'json') {\n // Assume JSON\n return require(configFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [configFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n customConfiguration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n customConfiguration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n customConfiguration = sandboxContext.module.exports;\n }\n\n if (typeof customConfiguration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidConfiguration(customConfiguration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAuB,uBAAuB;AAC9C,SAA4B,iBAAmC;AAG/D,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS,aAAa,cAAc,YAAY,GAAG,IAAI;AACzD;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AA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AC/B;AACF;","names":[]}
|
|
@@ -2,6 +2,17 @@ type SearchConfigurationFileResult = {
|
|
|
2
2
|
configurationFilePath?: string;
|
|
3
3
|
numCustomConfiguration: number;
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* Search for the configuration file in the given path
|
|
7
|
+
*
|
|
8
|
+
* List of detected configuration files:
|
|
9
|
+
* - intlayer.config.ts
|
|
10
|
+
* - intlayer.config.js
|
|
11
|
+
* - intlayer.config.json
|
|
12
|
+
* - intlayer.config.cjs
|
|
13
|
+
* - intlayer.config.mjs
|
|
14
|
+
* - .intlayerrc
|
|
15
|
+
*/
|
|
5
16
|
declare const searchConfigurationFile: (configFilePath: string) => SearchConfigurationFileResult;
|
|
6
17
|
|
|
7
18
|
export { searchConfigurationFile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { resolve } from 'path';\n\nconst EXTENSION = ['ts', 'js', 'json', 'cjs', 'mjs', ''];\nconst CONFIGURATION_FILE_NAME_1 = 'intlayer.config';\nconst CONFIGURATION_FILE_NAME_2 = '.intlayerrc';\n\nconst intLayerConfigFiles = EXTENSION.filter(\n (extension) => extension !== ''\n).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);\n\nconst configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\nexport const searchConfigurationFile = (\n configFilePath: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined = undefined;\n let numCustomConfiguration = 0;\n\n for (const fileName of configurationFiles) {\n try {\n const filePath = resolve(configFilePath, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n continue;\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n console.error(`${fileName}: ${error as string}`);\n\n continue;\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAExB,MAAM,YAAY,CAAC,MAAM,MAAM,QAAQ,OAAO,OAAO,EAAE;AACvD,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAElC,MAAM,sBAAsB,UAAU;AAAA,EACpC,CAAC,cAAc,cAAc;AAC/B,EAAE,IAAI,CAAC,QAAQ,GAAG,yBAAyB,IAAI,GAAG,EAAE;AAEpD,MAAM,qBAAqB,CAAC,GAAG,qBAAqB,yBAAyB;
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { resolve } from 'path';\n\nconst EXTENSION = ['ts', 'js', 'json', 'cjs', 'mjs', ''];\nconst CONFIGURATION_FILE_NAME_1 = 'intlayer.config';\nconst CONFIGURATION_FILE_NAME_2 = '.intlayerrc';\n\nconst intLayerConfigFiles = EXTENSION.filter(\n (extension) => extension !== ''\n).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);\n\nconst configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\n/**\n * Search for the configuration file in the given path\n *\n * List of detected configuration files:\n * - intlayer.config.ts\n * - intlayer.config.js\n * - intlayer.config.json\n * - intlayer.config.cjs\n * - intlayer.config.mjs\n * - .intlayerrc\n */\nexport const searchConfigurationFile = (\n configFilePath: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined = undefined;\n let numCustomConfiguration = 0;\n\n for (const fileName of configurationFiles) {\n try {\n const filePath = resolve(configFilePath, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n continue;\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n console.error(`${fileName}: ${error as string}`);\n\n continue;\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAExB,MAAM,YAAY,CAAC,MAAM,MAAM,QAAQ,OAAO,OAAO,EAAE;AACvD,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAElC,MAAM,sBAAsB,UAAU;AAAA,EACpC,CAAC,cAAc,cAAc;AAC/B,EAAE,IAAI,CAAC,QAAQ,GAAG,yBAAyB,IAAI,GAAG,EAAE;AAEpD,MAAM,qBAAqB,CAAC,GAAG,qBAAqB,yBAAyB;AAkBtE,MAAM,0BAA0B,CACrC,mBACkC;AAClC,MAAI,wBAA4C;AAChD,MAAI,yBAAyB;AAE7B,aAAW,YAAY,oBAAoB;AACzC,QAAI;AACF,YAAM,WAAW,QAAQ,gBAAgB,QAAQ;AAGjD,UAAI,CAAC,WAAW,QAAQ,GAAG;AACzB;AAAA,MACF,OAAO;AACL,kCAA0B;AAE1B,YAAI,CAAC,uBAAuB;AAC1B,kCAAwB;AAAA,QAC1B;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AAEd,cAAQ,MAAM,GAAG,QAAQ,KAAK,KAAe,EAAE;AAE/C;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,uBAAuB,uBAAuB;AACzD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/defaultValues/internationalization.ts"],"sourcesContent":["import { Locales } from '../types/locales';\n\nexport const LOCALES: Locales[] = [
|
|
1
|
+
{"version":3,"sources":["../../../src/defaultValues/internationalization.ts"],"sourcesContent":["import { Locales } from '../types/locales';\n\nexport const LOCALES: Locales[] = [Locales.ENGLISH];\n\nexport const DEFAULT_LOCALE: Locales = Locales.ENGLISH;\n"],"mappings":"AAAA,SAAS,eAAe;AAEjB,MAAM,UAAqB,CAAC,QAAQ,OAAO;AAE3C,MAAM,iBAA0B,QAAQ;","names":[]}
|
|
@@ -3,10 +3,8 @@ declare const EXCLUDED_PATHS: string[];
|
|
|
3
3
|
declare const CONTENT_DIR_NAME = "src";
|
|
4
4
|
declare const RESULT_DIR_NAME = ".intlayer";
|
|
5
5
|
declare const MODULE_AUGMENTATION_DIR_NAME = "types";
|
|
6
|
-
declare const BUNDLE_DIR_NAME = "bundle";
|
|
7
|
-
declare const BUNDLE_FILE_EXTENSION = ".bundle.js";
|
|
8
6
|
declare const DICTIONARIES_DIR_NAME = "dictionary";
|
|
9
7
|
declare const TYPES_DIR_NAME = "types";
|
|
10
8
|
declare const MAIN_DIR_NAME = "main";
|
|
11
9
|
|
|
12
|
-
export {
|
|
10
|
+
export { CONTENT_DIR_NAME, DICTIONARIES_DIR_NAME, EXCLUDED_PATHS, FILE_EXTENSIONS, MAIN_DIR_NAME, MODULE_AUGMENTATION_DIR_NAME, RESULT_DIR_NAME, TYPES_DIR_NAME };
|
|
@@ -3,14 +3,10 @@ const EXCLUDED_PATHS = ["node_modules"];
|
|
|
3
3
|
const CONTENT_DIR_NAME = "src";
|
|
4
4
|
const RESULT_DIR_NAME = ".intlayer";
|
|
5
5
|
const MODULE_AUGMENTATION_DIR_NAME = "types";
|
|
6
|
-
const BUNDLE_DIR_NAME = "bundle";
|
|
7
|
-
const BUNDLE_FILE_EXTENSION = ".bundle.js";
|
|
8
6
|
const DICTIONARIES_DIR_NAME = "dictionary";
|
|
9
7
|
const TYPES_DIR_NAME = "types";
|
|
10
8
|
const MAIN_DIR_NAME = "main";
|
|
11
9
|
export {
|
|
12
|
-
BUNDLE_DIR_NAME,
|
|
13
|
-
BUNDLE_FILE_EXTENSION,
|
|
14
10
|
CONTENT_DIR_NAME,
|
|
15
11
|
DICTIONARIES_DIR_NAME,
|
|
16
12
|
EXCLUDED_PATHS,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/defaultValues/server.ts"],"sourcesContent":["export const FILE_EXTENSIONS = ['.content.ts', '.content.js', '.content.json'];\nexport const EXCLUDED_PATHS = ['node_modules'];\n\nexport const CONTENT_DIR_NAME = 'src';\n\nexport const RESULT_DIR_NAME = '.intlayer';\n\nexport const MODULE_AUGMENTATION_DIR_NAME = 'types';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../src/defaultValues/server.ts"],"sourcesContent":["export const FILE_EXTENSIONS = ['.content.ts', '.content.js', '.content.json'];\nexport const EXCLUDED_PATHS = ['node_modules'];\n\nexport const CONTENT_DIR_NAME = 'src';\n\nexport const RESULT_DIR_NAME = '.intlayer';\n\nexport const MODULE_AUGMENTATION_DIR_NAME = 'types';\n\nexport const DICTIONARIES_DIR_NAME = 'dictionary';\n\nexport const TYPES_DIR_NAME = 'types';\n\nexport const MAIN_DIR_NAME = 'main';\n"],"mappings":"AAAO,MAAM,kBAAkB,CAAC,eAAe,eAAe,eAAe;AACtE,MAAM,iBAAiB,CAAC,cAAc;AAEtC,MAAM,mBAAmB;AAEzB,MAAM,kBAAkB;AAExB,MAAM,+BAA+B;AAErC,MAAM,wBAAwB;AAE9B,MAAM,iBAAiB;AAEvB,MAAM,gBAAgB;","names":[]}
|