@intlayer/config 1.2.0 → 2.0.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/client.cjs +2 -10
- package/dist/cjs/client.cjs.map +1 -1
- package/dist/cjs/client.d.ts +2 -2
- package/dist/cjs/configFile/buildConfigurationFields.cjs +65 -5
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
- package/dist/cjs/defaultValues/editor.cjs +29 -0
- package/dist/cjs/defaultValues/editor.cjs.map +1 -0
- package/dist/cjs/defaultValues/editor.d.ts +3 -0
- package/dist/cjs/defaultValues/internationalization.cjs +5 -2
- package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
- package/dist/cjs/defaultValues/internationalization.d.ts +3 -1
- package/dist/cjs/defaultValues/server.cjs +15 -1
- package/dist/cjs/defaultValues/server.cjs.map +1 -1
- package/dist/cjs/defaultValues/server.d.ts +6 -1
- package/dist/cjs/envVariables/detectPlatform.cjs +7 -4
- package/dist/cjs/envVariables/detectPlatform.cjs.map +1 -1
- package/dist/cjs/envVariables/detectPlatform.d.ts +1 -4
- package/dist/cjs/envVariables/extractEnvVariable/index.cjs +44 -0
- package/dist/cjs/envVariables/extractEnvVariable/index.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable/index.d.ts +7 -0
- package/dist/cjs/envVariables/extractEnvVariable/next.cjs +75 -0
- package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable/next.d.ts +7 -0
- package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +75 -0
- package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable/react_app.d.ts +7 -0
- package/dist/cjs/envVariables/extractEnvVariable/types.cjs +17 -0
- package/dist/cjs/envVariables/extractEnvVariable/types.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable/types.d.ts +11 -0
- package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +75 -0
- package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.d.ts +7 -0
- package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +83 -0
- package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable/vite.d.ts +7 -0
- package/dist/cjs/envVariables/extractEnvVariable/vite_env.d.cjs +2 -0
- package/dist/cjs/envVariables/extractEnvVariable/vite_env.d.cjs.map +1 -0
- package/dist/cjs/envVariables/extractEnvVariable/vite_env.d.d.ts +2 -0
- package/dist/cjs/envVariables/formatEnvVariable.cjs +2 -1
- package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
- package/dist/cjs/envVariables/getConfiguration.cjs +87 -115
- package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
- package/dist/cjs/envVariables/getConfiguration.d.ts +2 -6
- package/dist/cjs/envVariables/index.cjs +2 -10
- package/dist/cjs/envVariables/index.cjs.map +1 -1
- package/dist/cjs/envVariables/index.d.ts +1 -1
- package/dist/cjs/index.cjs +2 -10
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/types/config.cjs.map +1 -1
- package/dist/cjs/types/config.d.ts +75 -4
- package/dist/esm/client.d.mts +2 -2
- package/dist/esm/client.mjs +2 -12
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/configFile/buildConfigurationFields.mjs +73 -7
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
- package/dist/esm/defaultValues/editor.d.mts +3 -0
- package/dist/esm/defaultValues/editor.mjs +5 -0
- package/dist/esm/defaultValues/editor.mjs.map +1 -0
- package/dist/esm/defaultValues/internationalization.d.mts +3 -1
- package/dist/esm/defaultValues/internationalization.mjs +3 -1
- package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
- package/dist/esm/defaultValues/server.d.mts +6 -1
- package/dist/esm/defaultValues/server.mjs +13 -1
- package/dist/esm/defaultValues/server.mjs.map +1 -1
- package/dist/esm/envVariables/detectPlatform.d.mts +1 -4
- package/dist/esm/envVariables/detectPlatform.mjs +7 -4
- package/dist/esm/envVariables/detectPlatform.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/index.d.mts +7 -0
- package/dist/esm/envVariables/extractEnvVariable/index.mjs +20 -0
- package/dist/esm/envVariables/extractEnvVariable/index.mjs.map +1 -0
- package/dist/esm/envVariables/extractEnvVariable/next.d.mts +7 -0
- package/dist/esm/envVariables/extractEnvVariable/next.mjs +51 -0
- package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -0
- package/dist/esm/envVariables/extractEnvVariable/react_app.d.mts +7 -0
- package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +51 -0
- package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -0
- package/dist/esm/envVariables/extractEnvVariable/types.d.mts +11 -0
- package/dist/esm/envVariables/extractEnvVariable/types.mjs +1 -0
- package/dist/esm/envVariables/extractEnvVariable/types.mjs.map +1 -0
- package/dist/esm/envVariables/extractEnvVariable/undefined_platform.d.mts +7 -0
- package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +51 -0
- package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -0
- package/dist/esm/envVariables/extractEnvVariable/vite.d.mts +7 -0
- package/dist/esm/envVariables/extractEnvVariable/vite.mjs +58 -0
- package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -0
- package/dist/esm/envVariables/extractEnvVariable/vite_env.d.d.mts +2 -0
- package/dist/esm/envVariables/extractEnvVariable/vite_env.d.mjs +1 -0
- package/dist/esm/envVariables/extractEnvVariable/vite_env.d.mjs.map +1 -0
- package/dist/esm/envVariables/formatEnvVariable.mjs +2 -1
- package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
- package/dist/esm/envVariables/getConfiguration.d.mts +2 -6
- package/dist/esm/envVariables/getConfiguration.mjs +86 -110
- package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
- package/dist/esm/envVariables/index.d.mts +1 -1
- package/dist/esm/envVariables/index.mjs +2 -12
- package/dist/esm/envVariables/index.mjs.map +1 -1
- package/dist/esm/index.d.mts +2 -2
- package/dist/esm/index.mjs +1 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types/config.d.mts +75 -4
- package/package.json +2 -2
- package/src/client.ts +5 -11
- package/src/configFile/buildConfigurationFields.ts +82 -4
- package/src/defaultValues/editor.ts +1 -0
- package/src/defaultValues/internationalization.ts +3 -0
- package/src/defaultValues/server.ts +15 -1
- package/src/envVariables/detectPlatform.ts +12 -8
- package/src/envVariables/extractEnvVariable/index.ts +20 -0
- package/src/envVariables/extractEnvVariable/next.ts +64 -0
- package/src/envVariables/extractEnvVariable/react_app.ts +64 -0
- package/src/envVariables/extractEnvVariable/types.ts +10 -0
- package/src/envVariables/extractEnvVariable/undefined_platform.ts +59 -0
- package/src/envVariables/extractEnvVariable/vite.ts +72 -0
- package/src/envVariables/extractEnvVariable/vite_env.d.ts +9 -0
- package/src/envVariables/formatEnvVariable.ts +1 -0
- package/src/envVariables/getConfiguration.ts +94 -111
- package/src/envVariables/index.ts +1 -7
- package/src/index.ts +1 -4
- package/src/types/config.ts +82 -3
- package/dist/cjs/envVariables/extractEnvVariable.cjs +0 -211
- package/dist/cjs/envVariables/extractEnvVariable.cjs.map +0 -1
- package/dist/cjs/envVariables/extractEnvVariable.d.ts +0 -13
- package/dist/esm/envVariables/extractEnvVariable.d.mts +0 -13
- package/dist/esm/envVariables/extractEnvVariable.mjs +0 -186
- package/dist/esm/envVariables/extractEnvVariable.mjs.map +0 -1
- package/src/envVariables/extractEnvVariable.ts +0 -224
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_LOCALE,
|
|
4
|
+
LOCALES,
|
|
5
|
+
STRICT_MODE,
|
|
6
|
+
} from '../defaultValues/internationalization';
|
|
3
7
|
import {
|
|
4
8
|
BASE_PATH,
|
|
5
9
|
COOKIE_NAME,
|
|
@@ -17,6 +21,8 @@ import {
|
|
|
17
21
|
TYPES_DIR_NAME,
|
|
18
22
|
MAIN_DIR_NAME,
|
|
19
23
|
MODULE_AUGMENTATION_DIR_NAME,
|
|
24
|
+
I18N_DICTIONARIES_DIR_NAME,
|
|
25
|
+
DICTIONARY_OUTPUT,
|
|
20
26
|
} from '../defaultValues/server';
|
|
21
27
|
import type {
|
|
22
28
|
BaseDerivedConfig,
|
|
@@ -28,6 +34,7 @@ import type {
|
|
|
28
34
|
MiddlewareConfig,
|
|
29
35
|
BaseContentConfig,
|
|
30
36
|
ResultDirDerivedConfig,
|
|
37
|
+
EditorConfig,
|
|
31
38
|
} from '../types/config';
|
|
32
39
|
import type { GetConfigurationOptions } from './getConfiguration';
|
|
33
40
|
|
|
@@ -42,9 +49,20 @@ const buildInternationalizationFields = (
|
|
|
42
49
|
* Locales available in the application
|
|
43
50
|
*
|
|
44
51
|
* Default: ['en']
|
|
52
|
+
*
|
|
45
53
|
*/
|
|
46
54
|
locales: customConfiguration?.locales ?? LOCALES,
|
|
47
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Ensure strong implementations of internationalized content using typescript.
|
|
58
|
+
* - If set to "strict", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.
|
|
59
|
+
* - If set to "required_only", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.
|
|
60
|
+
* - If set to "loose", the translation `t` function will accept any existing locale.
|
|
61
|
+
*
|
|
62
|
+
* Default: "required_only"
|
|
63
|
+
*/
|
|
64
|
+
strictMode: customConfiguration?.strictMode ?? STRICT_MODE,
|
|
65
|
+
|
|
48
66
|
/**
|
|
49
67
|
* Default locale of the application for fallback
|
|
50
68
|
*
|
|
@@ -122,7 +140,7 @@ const buildContentFields = (
|
|
|
122
140
|
/**
|
|
123
141
|
* File extensions of content to look for to build the dictionaries
|
|
124
142
|
*
|
|
125
|
-
* - Default: ['.content.ts', '.content.js', '.content.json']
|
|
143
|
+
* - Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
|
|
126
144
|
*
|
|
127
145
|
* - Example: ['.data.ts', '.data.js', '.data.json']
|
|
128
146
|
*
|
|
@@ -207,6 +225,23 @@ const buildContentFields = (
|
|
|
207
225
|
dictionariesDirName:
|
|
208
226
|
customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,
|
|
209
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Related to the intlayer result directory
|
|
230
|
+
*
|
|
231
|
+
* Directory name where the dictionaries will be stored
|
|
232
|
+
*
|
|
233
|
+
* Default: 'dictionary'
|
|
234
|
+
*
|
|
235
|
+
* Example: 'translations'
|
|
236
|
+
*
|
|
237
|
+
* Note:
|
|
238
|
+
* - If this directory is not at the result directory level, update the dictionariesDir field instead
|
|
239
|
+
*
|
|
240
|
+
*/
|
|
241
|
+
i18nDictionariesDirName:
|
|
242
|
+
customConfiguration?.i18nDictionariesDirName ??
|
|
243
|
+
I18N_DICTIONARIES_DIR_NAME,
|
|
244
|
+
|
|
210
245
|
/**
|
|
211
246
|
* Related to the intlayer result directory
|
|
212
247
|
*
|
|
@@ -304,6 +339,18 @@ const buildContentFields = (
|
|
|
304
339
|
notDerivedContentConfig.baseDir,
|
|
305
340
|
notDerivedContentConfig.moduleAugmentationDirName
|
|
306
341
|
),
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Output format of the dictionary
|
|
345
|
+
*
|
|
346
|
+
* Default: ['intlayer']
|
|
347
|
+
*
|
|
348
|
+
* Note:
|
|
349
|
+
* - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.
|
|
350
|
+
* - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer
|
|
351
|
+
*/
|
|
352
|
+
dictionaryOutput:
|
|
353
|
+
customConfiguration?.dictionaryOutput ?? DICTIONARY_OUTPUT,
|
|
307
354
|
};
|
|
308
355
|
|
|
309
356
|
const resultDirDerivedConfiguration: ResultDirDerivedConfig = {
|
|
@@ -327,6 +374,23 @@ const buildContentFields = (
|
|
|
327
374
|
notDerivedContentConfig.dictionariesDirName
|
|
328
375
|
),
|
|
329
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Directory where the 18n dictionaries will be stored
|
|
379
|
+
*
|
|
380
|
+
* Relative to the result directory
|
|
381
|
+
*
|
|
382
|
+
* Default: {{resultDir}} / {{i18nDictionariesDirName}}
|
|
383
|
+
*
|
|
384
|
+
* Example: '/path/to/project/.intlayer/dictionary/i18n'
|
|
385
|
+
*
|
|
386
|
+
* Note:
|
|
387
|
+
* - If the types are not at the result directory level, update the i18nDictionariesDirName field instead
|
|
388
|
+
*/
|
|
389
|
+
i18nDictionariesDir: join(
|
|
390
|
+
baseDirDerivedConfiguration.resultDir,
|
|
391
|
+
notDerivedContentConfig.i18nDictionariesDirName
|
|
392
|
+
),
|
|
393
|
+
|
|
330
394
|
/**
|
|
331
395
|
* Directory where the dictionaries types will be stored
|
|
332
396
|
*
|
|
@@ -367,7 +431,7 @@ const buildContentFields = (
|
|
|
367
431
|
/**
|
|
368
432
|
* Pattern of files to watch
|
|
369
433
|
*
|
|
370
|
-
* Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json']
|
|
434
|
+
* Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json', '/**\/*.content.cjs', '/**\/*.content.mjs', '/**\/*.content.tsx', '/**\/*.content.jsx']
|
|
371
435
|
*/
|
|
372
436
|
watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
|
|
373
437
|
(ext) => `/**/*${ext}`
|
|
@@ -376,7 +440,7 @@ const buildContentFields = (
|
|
|
376
440
|
/**
|
|
377
441
|
* Pattern of files to watch including the relative path
|
|
378
442
|
*
|
|
379
|
-
* Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json']
|
|
443
|
+
* Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json', '{{contentDir}}/**\/*.content.cjs', '{{contentDir}}/**\/*.content.mjs', '{{contentDir}}/**\/*.content.tsx', '{{contentDir}}/**\/*.content.jsx']
|
|
380
444
|
*/
|
|
381
445
|
watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
|
|
382
446
|
(ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
|
|
@@ -398,6 +462,17 @@ const buildContentFields = (
|
|
|
398
462
|
};
|
|
399
463
|
};
|
|
400
464
|
|
|
465
|
+
const buildEditorFields = (
|
|
466
|
+
customConfiguration?: Partial<EditorConfig>
|
|
467
|
+
): EditorConfig => ({
|
|
468
|
+
/**
|
|
469
|
+
* Port of the editor server
|
|
470
|
+
*
|
|
471
|
+
* Default: 4000
|
|
472
|
+
*/
|
|
473
|
+
port: customConfiguration?.port ?? 4000,
|
|
474
|
+
});
|
|
475
|
+
|
|
401
476
|
/**
|
|
402
477
|
* Build the configuration fields by merging the default values with the custom configuration
|
|
403
478
|
*/
|
|
@@ -415,10 +490,13 @@ export const buildConfigurationFields = (
|
|
|
415
490
|
|
|
416
491
|
const contentConfig = buildContentFields(customConfiguration?.content);
|
|
417
492
|
|
|
493
|
+
const editorConfig = buildEditorFields(customConfiguration?.editor);
|
|
494
|
+
|
|
418
495
|
storedConfiguration = {
|
|
419
496
|
internationalization: internationalizationConfig,
|
|
420
497
|
middleware: middlewareConfig,
|
|
421
498
|
content: contentConfig,
|
|
499
|
+
editor: editorConfig,
|
|
422
500
|
};
|
|
423
501
|
|
|
424
502
|
return storedConfiguration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PORT = 4000;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { StrictMode } from '../types/config';
|
|
1
2
|
import { Locales } from '../types/locales';
|
|
2
3
|
|
|
3
4
|
export const LOCALES: Locales[] = [Locales.ENGLISH];
|
|
4
5
|
|
|
5
6
|
export const DEFAULT_LOCALE: Locales = Locales.ENGLISH;
|
|
7
|
+
|
|
8
|
+
export const STRICT_MODE: StrictMode = 'required_only';
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import type { DictionaryOutput } from '../types/config';
|
|
2
|
+
|
|
3
|
+
export const FILE_EXTENSIONS = [
|
|
4
|
+
'.content.ts',
|
|
5
|
+
'.content.js',
|
|
6
|
+
'.content.cjs',
|
|
7
|
+
'.content.mjs',
|
|
8
|
+
'.content.json',
|
|
9
|
+
'.content.tsx',
|
|
10
|
+
'.content.jsx',
|
|
11
|
+
];
|
|
2
12
|
export const EXCLUDED_PATHS = ['node_modules'];
|
|
3
13
|
|
|
4
14
|
export const CONTENT_DIR_NAME = 'src';
|
|
@@ -7,8 +17,12 @@ export const RESULT_DIR_NAME = '.intlayer';
|
|
|
7
17
|
|
|
8
18
|
export const MODULE_AUGMENTATION_DIR_NAME = 'types';
|
|
9
19
|
|
|
20
|
+
export const DICTIONARY_OUTPUT: DictionaryOutput[] = ['intlayer'];
|
|
21
|
+
|
|
10
22
|
export const DICTIONARIES_DIR_NAME = 'dictionary';
|
|
11
23
|
|
|
24
|
+
export const I18N_DICTIONARIES_DIR_NAME = 'i18n_dictionary';
|
|
25
|
+
|
|
12
26
|
export const TYPES_DIR_NAME = 'types';
|
|
13
27
|
|
|
14
28
|
export const MAIN_DIR_NAME = 'main';
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
export type Platform = 'next' | 'vite' | 'react_app' | 'unknown';
|
|
2
|
-
export type ViteEnvVar = { env: Record<string, string> };
|
|
3
2
|
|
|
4
3
|
export const getPlatform = (): Platform => {
|
|
5
|
-
if (
|
|
4
|
+
if (
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
typeof import.meta !== 'undefined' &&
|
|
7
|
+
typeof import.meta.env !== 'undefined' &&
|
|
8
|
+
typeof import.meta.env.VITE_INTLAYER_DEFAULT_LOCALE !== 'undefined'
|
|
9
|
+
) {
|
|
10
|
+
// Likely Vite
|
|
11
|
+
return 'vite';
|
|
12
|
+
} else if (
|
|
13
|
+
typeof process.env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE !== 'undefined'
|
|
14
|
+
) {
|
|
6
15
|
// Likely Next.js
|
|
7
16
|
return 'next';
|
|
8
17
|
} else if (
|
|
9
|
-
typeof process.env.REACT_APP_INTLAYER_DEFAULT_LOCALE
|
|
18
|
+
typeof process.env.REACT_APP_INTLAYER_DEFAULT_LOCALE !== 'undefined'
|
|
10
19
|
) {
|
|
11
20
|
// Likely Create React App
|
|
12
21
|
return 'react_app';
|
|
13
|
-
} else if (
|
|
14
|
-
(import.meta as unknown as ViteEnvVar)?.env?.VITE_INTLAYER_DEFAULT_LOCALE
|
|
15
|
-
) {
|
|
16
|
-
// Likely Vite
|
|
17
|
-
return 'vite';
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
return 'unknown';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Platform, getPlatform } from '../detectPlatform';
|
|
2
|
+
import { extractNextEnvVariable } from './next';
|
|
3
|
+
import { extractReactAppEnvVariable } from './react_app';
|
|
4
|
+
import type { IntlayerConfigEnvVariable } from './types';
|
|
5
|
+
import { extractEmptyEnvVariable } from './undefined_platform';
|
|
6
|
+
import { extractViteEnvVariable } from './vite';
|
|
7
|
+
|
|
8
|
+
export const extractEnvVariable = (): IntlayerConfigEnvVariable => {
|
|
9
|
+
const platform: Platform = getPlatform();
|
|
10
|
+
|
|
11
|
+
if (platform === 'vite') {
|
|
12
|
+
return extractViteEnvVariable();
|
|
13
|
+
} else if (platform === 'next') {
|
|
14
|
+
return extractNextEnvVariable();
|
|
15
|
+
} else if (platform === 'react_app') {
|
|
16
|
+
return extractReactAppEnvVariable();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return extractEmptyEnvVariable();
|
|
20
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InternationalizationConfig,
|
|
3
|
+
MiddlewareConfig,
|
|
4
|
+
ContentConfig,
|
|
5
|
+
EditorConfig,
|
|
6
|
+
} from '../../types/config';
|
|
7
|
+
import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
|
|
8
|
+
|
|
9
|
+
export const extractNextEnvVariable = (): IntlayerConfigEnvVariable => {
|
|
10
|
+
const internationalization: ReplaceValue<InternationalizationConfig> = {
|
|
11
|
+
locales: process.env.NEXT_PUBLIC_INTLAYER_LOCALES,
|
|
12
|
+
strictMode: process.env.NEXT_PUBLIC_INTLAYER_STRICT_MODE,
|
|
13
|
+
defaultLocale: process.env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const middleware: ReplaceValue<MiddlewareConfig> = {
|
|
17
|
+
headerName: process.env.NEXT_PUBLIC_INTLAYER_HEADER_NAME,
|
|
18
|
+
cookieName: process.env.NEXT_PUBLIC_INTLAYER_COOKIE_NAME,
|
|
19
|
+
prefixDefault: process.env.NEXT_PUBLIC_INTLAYER_PREFIX_DEFAULT,
|
|
20
|
+
basePath: process.env.NEXT_PUBLIC_INTLAYER_BASE_PATH,
|
|
21
|
+
serverSetCookie: process.env.NEXT_PUBLIC_INTLAYER_SERVER_SET_COOKIE,
|
|
22
|
+
noPrefix: process.env.NEXT_PUBLIC_INTLAYER_NO_PREFIX,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const content: ReplaceValue<ContentConfig> = {
|
|
26
|
+
fileExtensions: process.env.NEXT_PUBLIC_INTLAYER_FILE_EXTENSIONS,
|
|
27
|
+
baseDir: process.env.NEXT_PUBLIC_INTLAYER_BASE_DIR,
|
|
28
|
+
contentDirName: process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR_NAME,
|
|
29
|
+
contentDir: process.env.NEXT_PUBLIC_INTLAYER_CONTENT_DIR,
|
|
30
|
+
excludedPath: process.env.NEXT_PUBLIC_INTLAYER_EXCLUDED_PATH,
|
|
31
|
+
resultDirName: process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR_NAME,
|
|
32
|
+
moduleAugmentationDirName:
|
|
33
|
+
process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
|
|
34
|
+
dictionariesDirName: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR_NAME,
|
|
35
|
+
i18nDictionariesDir: process.env.NEXT_PUBLIC_INTLAYER_I18N_DICTIONARIES_DIR,
|
|
36
|
+
typeDirName: process.env.NEXT_PUBLIC_INTLAYER_TYPE_DIR_NAME,
|
|
37
|
+
mainDirName: process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR_NAME,
|
|
38
|
+
resultDir: process.env.NEXT_PUBLIC_INTLAYER_RESULT_DIR,
|
|
39
|
+
moduleAugmentationDir:
|
|
40
|
+
process.env.NEXT_PUBLIC_INTLAYER_MODULE_AUGMENTATION_DIR,
|
|
41
|
+
dictionariesDir: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARIES_DIR,
|
|
42
|
+
i18nDictionariesDirName:
|
|
43
|
+
process.env.NEXT_PUBLIC_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
|
|
44
|
+
typesDir: process.env.NEXT_PUBLIC_INTLAYER_TYPE_DIR,
|
|
45
|
+
mainDir: process.env.NEXT_PUBLIC_INTLAYER_MAIN_DIR,
|
|
46
|
+
watchedFilesPattern: process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN,
|
|
47
|
+
watchedFilesPatternWithPath:
|
|
48
|
+
process.env.NEXT_PUBLIC_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
|
|
49
|
+
outputFilesPatternWithPath:
|
|
50
|
+
process.env.NEXT_PUBLIC_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
|
|
51
|
+
dictionaryOutput: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARY_OUTPUT,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const editor: ReplaceValue<EditorConfig> = {
|
|
55
|
+
port: process.env.NEXT_PUBLIC_INTLAYER_PORT,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
internationalization,
|
|
60
|
+
middleware,
|
|
61
|
+
content,
|
|
62
|
+
editor,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InternationalizationConfig,
|
|
3
|
+
MiddlewareConfig,
|
|
4
|
+
ContentConfig,
|
|
5
|
+
EditorConfig,
|
|
6
|
+
} from '../../types/config';
|
|
7
|
+
import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
|
|
8
|
+
|
|
9
|
+
export const extractReactAppEnvVariable = (): IntlayerConfigEnvVariable => {
|
|
10
|
+
const internationalization: ReplaceValue<InternationalizationConfig> = {
|
|
11
|
+
locales: process.env.REACT_APP_INTLAYER_LOCALES,
|
|
12
|
+
strictMode: process.env.REACT_APP_INTLAYER_STRICT_MODE,
|
|
13
|
+
defaultLocale: process.env.REACT_APP_INTLAYER_DEFAULT_LOCALE,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const middleware: ReplaceValue<MiddlewareConfig> = {
|
|
17
|
+
headerName: process.env.REACT_APP_INTLAYER_HEADER_NAME,
|
|
18
|
+
cookieName: process.env.REACT_APP_INTLAYER_COOKIE_NAME,
|
|
19
|
+
prefixDefault: process.env.REACT_APP_INTLAYER_PREFIX_DEFAULT,
|
|
20
|
+
basePath: process.env.REACT_APP_INTLAYER_BASE_PATH,
|
|
21
|
+
serverSetCookie: process.env.REACT_APP_INTLAYER_SERVER_SET_COOKIE,
|
|
22
|
+
noPrefix: process.env.REACT_APP_INTLAYER_NO_PREFIX,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const content: ReplaceValue<ContentConfig> = {
|
|
26
|
+
fileExtensions: process.env.REACT_APP_INTLAYER_FILE_EXTENSIONS,
|
|
27
|
+
baseDir: process.env.REACT_APP_INTLAYER_BASE_DIR,
|
|
28
|
+
contentDirName: process.env.REACT_APP_INTLAYER_CONTENT_DIR_NAME,
|
|
29
|
+
contentDir: process.env.REACT_APP_INTLAYER_CONTENT_DIR,
|
|
30
|
+
excludedPath: process.env.REACT_APP_INTLAYER_EXCLUDED_PATH,
|
|
31
|
+
resultDirName: process.env.REACT_APP_INTLAYER_RESULT_DIR_NAME,
|
|
32
|
+
moduleAugmentationDirName:
|
|
33
|
+
process.env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
|
|
34
|
+
dictionariesDirName: process.env.REACT_APP_INTLAYER_DICTIONARIES_DIR_NAME,
|
|
35
|
+
i18nDictionariesDirName:
|
|
36
|
+
process.env.REACT_APP_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
|
|
37
|
+
typeDirName: process.env.REACT_APP_INTLAYER_TYPE_DIR_NAME,
|
|
38
|
+
mainDirName: process.env.REACT_APP_INTLAYER_MAIN_DIR_NAME,
|
|
39
|
+
resultDir: process.env.REACT_APP_INTLAYER_RESULT_DIR,
|
|
40
|
+
moduleAugmentationDir:
|
|
41
|
+
process.env.REACT_APP_INTLAYER_MODULE_AUGMENTATION_DIR,
|
|
42
|
+
dictionariesDir: process.env.REACT_APP_INTLAYER_DICTIONARIES_DIR,
|
|
43
|
+
i18nDictionariesDir: process.env.REACT_APP_INTLAYER_I18N_DICTIONARIES_DIR,
|
|
44
|
+
typesDir: process.env.REACT_APP_INTLAYER_TYPE_DIR,
|
|
45
|
+
mainDir: process.env.REACT_APP_INTLAYER_MAIN_DIR,
|
|
46
|
+
watchedFilesPattern: process.env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN,
|
|
47
|
+
watchedFilesPatternWithPath:
|
|
48
|
+
process.env.REACT_APP_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
|
|
49
|
+
outputFilesPatternWithPath:
|
|
50
|
+
process.env.REACT_APP_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
|
|
51
|
+
dictionaryOutput: process.env.REACT_APP_INTLAYER_DICTIONARY_OUTPUT,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const editor: ReplaceValue<EditorConfig> = {
|
|
55
|
+
port: process.env.REACT_APP_INTLAYER_PORT,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
internationalization,
|
|
60
|
+
middleware,
|
|
61
|
+
content,
|
|
62
|
+
editor,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IntlayerConfig } from '../../client';
|
|
2
|
+
|
|
3
|
+
// Utility type that replaces all values of a given type with another type
|
|
4
|
+
export type ReplaceValue<T> = {
|
|
5
|
+
[K in keyof T]: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type IntlayerConfigEnvVariable = {
|
|
9
|
+
[K in keyof IntlayerConfig]: ReplaceValue<IntlayerConfig[K]>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InternationalizationConfig,
|
|
3
|
+
MiddlewareConfig,
|
|
4
|
+
ContentConfig,
|
|
5
|
+
EditorConfig,
|
|
6
|
+
} from '../../types/config';
|
|
7
|
+
import type { ReplaceValue, IntlayerConfigEnvVariable } from './types';
|
|
8
|
+
|
|
9
|
+
export const extractEmptyEnvVariable = (): IntlayerConfigEnvVariable => {
|
|
10
|
+
const internationalization: ReplaceValue<InternationalizationConfig> = {
|
|
11
|
+
locales: undefined,
|
|
12
|
+
strictMode: undefined,
|
|
13
|
+
defaultLocale: undefined,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const middleware: ReplaceValue<MiddlewareConfig> = {
|
|
17
|
+
headerName: undefined,
|
|
18
|
+
cookieName: undefined,
|
|
19
|
+
prefixDefault: undefined,
|
|
20
|
+
basePath: undefined,
|
|
21
|
+
serverSetCookie: undefined,
|
|
22
|
+
noPrefix: undefined,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const content: ReplaceValue<ContentConfig> = {
|
|
26
|
+
fileExtensions: undefined,
|
|
27
|
+
baseDir: undefined,
|
|
28
|
+
contentDirName: undefined,
|
|
29
|
+
contentDir: undefined,
|
|
30
|
+
excludedPath: undefined,
|
|
31
|
+
resultDirName: undefined,
|
|
32
|
+
moduleAugmentationDirName: undefined,
|
|
33
|
+
dictionariesDirName: undefined,
|
|
34
|
+
i18nDictionariesDirName: undefined,
|
|
35
|
+
typeDirName: undefined,
|
|
36
|
+
mainDirName: undefined,
|
|
37
|
+
resultDir: undefined,
|
|
38
|
+
moduleAugmentationDir: undefined,
|
|
39
|
+
dictionariesDir: undefined,
|
|
40
|
+
i18nDictionariesDir: undefined,
|
|
41
|
+
typesDir: undefined,
|
|
42
|
+
mainDir: undefined,
|
|
43
|
+
watchedFilesPattern: undefined,
|
|
44
|
+
watchedFilesPatternWithPath: undefined,
|
|
45
|
+
outputFilesPatternWithPath: undefined,
|
|
46
|
+
dictionaryOutput: undefined,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const editor: ReplaceValue<EditorConfig> = {
|
|
50
|
+
port: undefined,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
internationalization,
|
|
55
|
+
middleware,
|
|
56
|
+
content,
|
|
57
|
+
editor,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InternationalizationConfig,
|
|
3
|
+
MiddlewareConfig,
|
|
4
|
+
ContentConfig,
|
|
5
|
+
EditorConfig,
|
|
6
|
+
} from '../../types/config';
|
|
7
|
+
import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
|
|
8
|
+
import { extractEmptyEnvVariable } from './undefined_platform';
|
|
9
|
+
|
|
10
|
+
export const extractViteEnvVariable = (): IntlayerConfigEnvVariable => {
|
|
11
|
+
if (!import.meta.env) {
|
|
12
|
+
console.error(
|
|
13
|
+
'Vite env variables cannot be loaded on a commonjs environment.'
|
|
14
|
+
);
|
|
15
|
+
return extractEmptyEnvVariable();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const internationalization: ReplaceValue<InternationalizationConfig> = {
|
|
19
|
+
locales: import.meta.env.VITE_INTLAYER_LOCALES,
|
|
20
|
+
strictMode: import.meta.env.VITE_INTLAYER_STRICT_MODE,
|
|
21
|
+
defaultLocale: import.meta.env.VITE_INTLAYER_DEFAULT_LOCALE,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const middleware: ReplaceValue<MiddlewareConfig> = {
|
|
25
|
+
headerName: import.meta.env.VITE_INTLAYER_HEADER_NAME,
|
|
26
|
+
cookieName: import.meta.env.VITE_INTLAYER_COOKIE_NAME,
|
|
27
|
+
prefixDefault: import.meta.env.VITE_INTLAYER_PREFIX_DEFAULT,
|
|
28
|
+
basePath: import.meta.env.VITE_INTLAYER_BASE_PATH,
|
|
29
|
+
serverSetCookie: import.meta.env.VITE_INTLAYER_SERVER_SET_COOKIE,
|
|
30
|
+
noPrefix: import.meta.env.VITE_INTLAYER_NO_PREFIX,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const content: ReplaceValue<ContentConfig> = {
|
|
34
|
+
fileExtensions: import.meta.env.VITE_INTLAYER_FILE_EXTENSIONS,
|
|
35
|
+
baseDir: import.meta.env.VITE_INTLAYER_BASE_DIR,
|
|
36
|
+
contentDirName: import.meta.env.VITE_INTLAYER_CONTENT_DIR_NAME,
|
|
37
|
+
contentDir: import.meta.env.VITE_INTLAYER_CONTENT_DIR,
|
|
38
|
+
excludedPath: import.meta.env.VITE_INTLAYER_EXCLUDED_PATH,
|
|
39
|
+
resultDirName: import.meta.env.VITE_INTLAYER_RESULT_DIR_NAME,
|
|
40
|
+
moduleAugmentationDirName: import.meta.env
|
|
41
|
+
.VITE_INTLAYER_MODULE_AUGMENTATION_DIR_NAME,
|
|
42
|
+
dictionariesDirName: import.meta.env.VITE_INTLAYER_DICTIONARIES_DIR_NAME,
|
|
43
|
+
i18nDictionariesDirName: import.meta.env
|
|
44
|
+
.VITE_INTLAYER_I18N_DICTIONARIES_DIR_NAME,
|
|
45
|
+
typeDirName: import.meta.env.VITE_INTLAYER_TYPE_DIR_NAME,
|
|
46
|
+
mainDirName: import.meta.env.VITE_INTLAYER_MAIN_DIR_NAME,
|
|
47
|
+
resultDir: import.meta.env.VITE_INTLAYER_RESULT_DIR,
|
|
48
|
+
moduleAugmentationDir: import.meta.env
|
|
49
|
+
.VITE_INTLAYER_MODULE_AUGMENTATION_DIR,
|
|
50
|
+
dictionariesDir: import.meta.env.VITE_INTLAYER_DICTIONARIES_DIR,
|
|
51
|
+
i18nDictionariesDir: import.meta.env.VITE_INTLAYER_I18N_DICTIONARIES_DIR,
|
|
52
|
+
typesDir: import.meta.env.VITE_INTLAYER_TYPE_DIR,
|
|
53
|
+
mainDir: import.meta.env.VITE_INTLAYER_MAIN_DIR,
|
|
54
|
+
watchedFilesPattern: import.meta.env.VITE_INTLAYER_WATCHED_FILES_PATTERN,
|
|
55
|
+
watchedFilesPatternWithPath: import.meta.env
|
|
56
|
+
.VITE_INTLAYER_WATCHED_FILES_PATTERN_WITH_PATH,
|
|
57
|
+
outputFilesPatternWithPath: import.meta.env
|
|
58
|
+
.VITE_INTLAYER_OUTPUT_FILES_PATTERN_WITH_PATH,
|
|
59
|
+
dictionaryOutput: import.meta.env.VITE_INTLAYER_DICTIONARY_OUTPUT,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const editor: ReplaceValue<EditorConfig> = {
|
|
63
|
+
port: import.meta.env.VITE_INTLAYER_PORT,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
internationalization,
|
|
68
|
+
middleware,
|
|
69
|
+
content,
|
|
70
|
+
editor,
|
|
71
|
+
};
|
|
72
|
+
};
|