@intlayer/config 1.2.1 → 2.0.1
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.map +1 -1
- package/dist/cjs/client.d.ts +1 -1
- package/dist/cjs/configFile/buildConfigurationFields.cjs +40 -1
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
- package/dist/cjs/defaultValues/editor.cjs +32 -0
- package/dist/cjs/defaultValues/editor.cjs.map +1 -0
- package/dist/cjs/defaultValues/editor.d.ts +4 -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/envVariables/extractEnvVariable/next.cjs +7 -1
- package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -1
- package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +7 -1
- package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -1
- package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +7 -1
- package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -1
- package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +7 -1
- package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -1
- package/dist/cjs/envVariables/formatEnvVariable.cjs +2 -1
- package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
- package/dist/cjs/envVariables/getConfiguration.cjs +10 -1
- package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/types/config.cjs.map +1 -1
- package/dist/cjs/types/config.d.ts +52 -1
- package/dist/esm/client.d.mts +1 -1
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/configFile/buildConfigurationFields.mjs +45 -2
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
- package/dist/esm/defaultValues/editor.d.mts +4 -0
- package/dist/esm/defaultValues/editor.mjs +7 -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/envVariables/extractEnvVariable/next.mjs +7 -1
- package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +7 -1
- package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +7 -1
- package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -1
- package/dist/esm/envVariables/extractEnvVariable/vite.mjs +7 -1
- package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -1
- package/dist/esm/envVariables/formatEnvVariable.mjs +2 -1
- package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
- package/dist/esm/envVariables/getConfiguration.mjs +10 -1
- package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types/config.d.mts +52 -1
- package/package.json +2 -3
- package/src/index.ts +1 -0
- package/src/client.ts +0 -11
- package/src/configFile/buildConfigurationFields.ts +0 -474
- package/src/configFile/getConfiguration.ts +0 -78
- package/src/configFile/index.ts +0 -2
- package/src/configFile/loadConfigurationFile.ts +0 -115
- package/src/configFile/searchConfigurationFile.ts +0 -59
- package/src/defaultValues/internationalization.ts +0 -5
- package/src/defaultValues/middleware.ts +0 -11
- package/src/defaultValues/server.ts +0 -28
- package/src/envVariables/detectPlatform.ts +0 -41
- package/src/envVariables/extractEnvVariable/index.ts +0 -20
- package/src/envVariables/extractEnvVariable/next.ts +0 -57
- package/src/envVariables/extractEnvVariable/react_app.ts +0 -57
- package/src/envVariables/extractEnvVariable/types.ts +0 -10
- package/src/envVariables/extractEnvVariable/undefined_platform.ts +0 -52
- package/src/envVariables/extractEnvVariable/vite.ts +0 -65
- package/src/envVariables/extractEnvVariable/vite_env.d.ts +0 -9
- package/src/envVariables/formatEnvVariable.ts +0 -38
- package/src/envVariables/getConfiguration.ts +0 -99
- package/src/envVariables/index.ts +0 -2
- package/src/envVariables/utils.ts +0 -64
- package/src/types/config.ts +0 -360
- package/src/types/locales.ts +0 -469
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Locales } from './locales.mjs';
|
|
2
2
|
|
|
3
|
+
type StrictMode = 'strict' | 'required_only' | 'loose';
|
|
3
4
|
/**
|
|
4
5
|
* Configuration for internationalization settings
|
|
5
6
|
*/
|
|
@@ -12,6 +13,15 @@ type InternationalizationConfig = {
|
|
|
12
13
|
* You can define a list of available locales to support in the application.
|
|
13
14
|
*/
|
|
14
15
|
locales: Locales[];
|
|
16
|
+
/**
|
|
17
|
+
* Ensure strong implementations of internationalized content using typescript.
|
|
18
|
+
* - 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.
|
|
19
|
+
* - 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.
|
|
20
|
+
* - If set to "loose", the translation `t` function will accept any existing locale.
|
|
21
|
+
*
|
|
22
|
+
* Default: "required_only"
|
|
23
|
+
*/
|
|
24
|
+
strictMode: StrictMode;
|
|
15
25
|
/**
|
|
16
26
|
* Default locale of the application for fallback
|
|
17
27
|
*
|
|
@@ -75,6 +85,39 @@ type MiddlewareConfig = {
|
|
|
75
85
|
*/
|
|
76
86
|
noPrefix: boolean;
|
|
77
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Configuration for intlayer editor
|
|
90
|
+
*/
|
|
91
|
+
type EditorConfig = {
|
|
92
|
+
/**
|
|
93
|
+
* Port number for the editor server
|
|
94
|
+
*
|
|
95
|
+
* Default: 4000
|
|
96
|
+
*
|
|
97
|
+
* The port number where the editor server runs.
|
|
98
|
+
*/
|
|
99
|
+
port: number;
|
|
100
|
+
/**
|
|
101
|
+
* Indicates if the editor is active
|
|
102
|
+
*
|
|
103
|
+
* Default: true;
|
|
104
|
+
*
|
|
105
|
+
* If true, the editor is active and can be accessed.
|
|
106
|
+
* If false, the editor is inactive and cannot be accessed.
|
|
107
|
+
*
|
|
108
|
+
* Usage:
|
|
109
|
+
* ```js
|
|
110
|
+
* {
|
|
111
|
+
* // Other configurations
|
|
112
|
+
* editor: {
|
|
113
|
+
* enabled: process.env.NODE_ENV === 'development',
|
|
114
|
+
* }
|
|
115
|
+
* };
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
enabled: boolean;
|
|
120
|
+
};
|
|
78
121
|
/**
|
|
79
122
|
* Custom configuration that can be provided to override default settings
|
|
80
123
|
*/
|
|
@@ -91,6 +134,10 @@ type CustomIntlayerConfig = {
|
|
|
91
134
|
* Custom content configuration
|
|
92
135
|
*/
|
|
93
136
|
content?: Partial<ContentConfig>;
|
|
137
|
+
/**
|
|
138
|
+
* Custom editor configuration
|
|
139
|
+
*/
|
|
140
|
+
editor?: Partial<EditorConfig>;
|
|
94
141
|
};
|
|
95
142
|
/**
|
|
96
143
|
* Combined configuration for internationalization, middleware, and content
|
|
@@ -108,6 +155,10 @@ type IntlayerConfig = {
|
|
|
108
155
|
* Content configuration
|
|
109
156
|
*/
|
|
110
157
|
content: ContentConfig;
|
|
158
|
+
/**
|
|
159
|
+
* Intlayer editor configuration
|
|
160
|
+
*/
|
|
161
|
+
editor: EditorConfig;
|
|
111
162
|
};
|
|
112
163
|
/**
|
|
113
164
|
* Base configuration for content handling
|
|
@@ -318,4 +369,4 @@ type PatternsContentConfig = {
|
|
|
318
369
|
*/
|
|
319
370
|
type ContentConfig = BaseContentConfig & BaseDerivedConfig & ResultDirDerivedConfig & PatternsContentConfig;
|
|
320
371
|
|
|
321
|
-
export type { BaseContentConfig, BaseDerivedConfig, ContentConfig, CustomIntlayerConfig, DictionaryOutput, InternationalizationConfig, IntlayerConfig, MiddlewareConfig, PatternsContentConfig, ResultDirDerivedConfig, ServerSetCookieRule };
|
|
372
|
+
export type { BaseContentConfig, BaseDerivedConfig, ContentConfig, CustomIntlayerConfig, DictionaryOutput, EditorConfig, InternationalizationConfig, IntlayerConfig, MiddlewareConfig, PatternsContentConfig, ResultDirDerivedConfig, ServerSetCookieRule, StrictMode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared configuration package for IntLayer - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
|
|
6
6
|
"keywords": [
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
50
|
"./dist",
|
|
51
|
-
"./src",
|
|
52
51
|
"./package.json"
|
|
53
52
|
],
|
|
54
53
|
"dependencies": {
|
|
@@ -57,7 +56,7 @@
|
|
|
57
56
|
"@types/node": "^20.12.7",
|
|
58
57
|
"esbuild": "^0.20.2",
|
|
59
58
|
"swc-loader": "^0.2.6",
|
|
60
|
-
"intlayer": "^
|
|
59
|
+
"intlayer": "^2.0.1"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
63
62
|
"rimraf": "5.0.5",
|
package/src/index.ts
CHANGED
package/src/client.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
CustomIntlayerConfig,
|
|
3
|
-
PatternsContentConfig as FixedIntlayerConfig,
|
|
4
|
-
IntlayerConfig,
|
|
5
|
-
BaseContentConfig as NotDerivedConfiguration,
|
|
6
|
-
BaseDerivedConfig as BaseDirDerivedConfiguration,
|
|
7
|
-
ResultDirDerivedConfig as ResultDirDerivedConfiguration,
|
|
8
|
-
} from './types/config';
|
|
9
|
-
export type { LocalesValues } from './types/locales';
|
|
10
|
-
export { Locales } from './types/locales';
|
|
11
|
-
export { getConfiguration } from './envVariables/getConfiguration';
|
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import { DEFAULT_LOCALE, LOCALES } from '../defaultValues/internationalization';
|
|
3
|
-
import {
|
|
4
|
-
BASE_PATH,
|
|
5
|
-
COOKIE_NAME,
|
|
6
|
-
HEADER_NAME,
|
|
7
|
-
NO_PREFIX,
|
|
8
|
-
PREFIX_DEFAULT,
|
|
9
|
-
SERVER_SET_COOKIE,
|
|
10
|
-
} from '../defaultValues/middleware';
|
|
11
|
-
import {
|
|
12
|
-
CONTENT_DIR_NAME,
|
|
13
|
-
DICTIONARIES_DIR_NAME,
|
|
14
|
-
FILE_EXTENSIONS,
|
|
15
|
-
RESULT_DIR_NAME,
|
|
16
|
-
EXCLUDED_PATHS,
|
|
17
|
-
TYPES_DIR_NAME,
|
|
18
|
-
MAIN_DIR_NAME,
|
|
19
|
-
MODULE_AUGMENTATION_DIR_NAME,
|
|
20
|
-
I18N_DICTIONARIES_DIR_NAME,
|
|
21
|
-
DICTIONARY_OUTPUT,
|
|
22
|
-
} from '../defaultValues/server';
|
|
23
|
-
import type {
|
|
24
|
-
BaseDerivedConfig,
|
|
25
|
-
ContentConfig,
|
|
26
|
-
CustomIntlayerConfig,
|
|
27
|
-
PatternsContentConfig,
|
|
28
|
-
InternationalizationConfig,
|
|
29
|
-
IntlayerConfig,
|
|
30
|
-
MiddlewareConfig,
|
|
31
|
-
BaseContentConfig,
|
|
32
|
-
ResultDirDerivedConfig,
|
|
33
|
-
} from '../types/config';
|
|
34
|
-
import type { GetConfigurationOptions } from './getConfiguration';
|
|
35
|
-
|
|
36
|
-
let storedConfiguration: IntlayerConfig;
|
|
37
|
-
|
|
38
|
-
// @TODO - Add possibility of directories configurations to be arrays to allow multiple packages management
|
|
39
|
-
|
|
40
|
-
const buildInternationalizationFields = (
|
|
41
|
-
customConfiguration?: Partial<InternationalizationConfig>
|
|
42
|
-
): InternationalizationConfig => ({
|
|
43
|
-
/**
|
|
44
|
-
* Locales available in the application
|
|
45
|
-
*
|
|
46
|
-
* Default: ['en']
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
locales: customConfiguration?.locales ?? LOCALES,
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Default locale of the application for fallback
|
|
53
|
-
*
|
|
54
|
-
* Default: 'en'
|
|
55
|
-
*/
|
|
56
|
-
defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const buildMiddlewareFields = (
|
|
60
|
-
customConfiguration?: Partial<MiddlewareConfig>
|
|
61
|
-
): MiddlewareConfig => ({
|
|
62
|
-
/**
|
|
63
|
-
* Header name to get the locale
|
|
64
|
-
*
|
|
65
|
-
* Default: 'x-intlayer-locale'
|
|
66
|
-
*/
|
|
67
|
-
headerName: customConfiguration?.headerName ?? HEADER_NAME,
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Cookie name to get the locale
|
|
71
|
-
*
|
|
72
|
-
* Default: 'intlayer-locale'
|
|
73
|
-
*/
|
|
74
|
-
cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Prefix the default locale in the URL
|
|
78
|
-
*
|
|
79
|
-
* Default: true
|
|
80
|
-
*/
|
|
81
|
-
prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Base path of the application URL
|
|
85
|
-
*
|
|
86
|
-
* Default: ''
|
|
87
|
-
*
|
|
88
|
-
* Example:
|
|
89
|
-
* - If the application is hosted at https://example.com/my-app
|
|
90
|
-
* - The base path is '/my-app'
|
|
91
|
-
* - The URL will be https://example.com/my-app/en
|
|
92
|
-
* - If the base path is not set, the URL will be https://example.com/en
|
|
93
|
-
*/
|
|
94
|
-
basePath: customConfiguration?.basePath ?? BASE_PATH,
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Rule to set the cookie on the server
|
|
98
|
-
* - 'always': Set the cookie on every request
|
|
99
|
-
* - 'never': Never set the cookie
|
|
100
|
-
*/
|
|
101
|
-
serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* No prefix in the URL
|
|
105
|
-
* - true: No prefix in the URL
|
|
106
|
-
* - false: Prefix in the URL
|
|
107
|
-
*
|
|
108
|
-
* Example:
|
|
109
|
-
* - If the application is hosted at https://example.com/my-app
|
|
110
|
-
* - The base path is '/my-app'
|
|
111
|
-
* - The URL will be https://example.com/my-app/en
|
|
112
|
-
* - If the base path is not set, the URL will be https://example.com/en
|
|
113
|
-
* - If no prefix is set, the URL will be https://example.com/en
|
|
114
|
-
* - If the no prefix is set to true, the URL will be https://example.com
|
|
115
|
-
*
|
|
116
|
-
* Default: false
|
|
117
|
-
*/
|
|
118
|
-
noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const buildContentFields = (
|
|
122
|
-
customConfiguration?: Partial<ContentConfig>
|
|
123
|
-
): ContentConfig => {
|
|
124
|
-
const notDerivedContentConfig: BaseContentConfig = {
|
|
125
|
-
/**
|
|
126
|
-
* File extensions of content to look for to build the dictionaries
|
|
127
|
-
*
|
|
128
|
-
* - Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
|
|
129
|
-
*
|
|
130
|
-
* - Example: ['.data.ts', '.data.js', '.data.json']
|
|
131
|
-
*
|
|
132
|
-
* Note:
|
|
133
|
-
* - Can exclude unused file extensions to improve performance
|
|
134
|
-
* - Avoid using common file extensions like '.ts', '.js', '.json' to avoid conflicts
|
|
135
|
-
*/
|
|
136
|
-
fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Absolute path of the directory of the project
|
|
140
|
-
* - Default: process.cwd()
|
|
141
|
-
* - Example: '/path/to/project'
|
|
142
|
-
*
|
|
143
|
-
* Will be used to resolve all intlayer directories
|
|
144
|
-
*
|
|
145
|
-
* Note:
|
|
146
|
-
* - The base directory should be the root of the project
|
|
147
|
-
* - Can be changed to a custom directory to externalize either the content used in the project, or the intlayer application from the project
|
|
148
|
-
*/
|
|
149
|
-
baseDir: customConfiguration?.baseDir ?? process.cwd(),
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Directory name where the content is stored
|
|
153
|
-
*
|
|
154
|
-
* Default: 'src'
|
|
155
|
-
*
|
|
156
|
-
* Example:
|
|
157
|
-
* - 'data' -> '/path/to/project/data'
|
|
158
|
-
* - 'content' -> '/path/to/project/content'
|
|
159
|
-
* - 'locales' -> '/path/to/project/locales'
|
|
160
|
-
*
|
|
161
|
-
* Note: If this directory is not at the base directory level, update the contentDir field instead
|
|
162
|
-
*/
|
|
163
|
-
contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Directory name where the result will be stored
|
|
167
|
-
*
|
|
168
|
-
* Default: '.intlayer'
|
|
169
|
-
*
|
|
170
|
-
* Example:
|
|
171
|
-
* - '.next'
|
|
172
|
-
* - 'outputOFIntlayer'
|
|
173
|
-
*
|
|
174
|
-
* Note: If this directory is not at the base directory level, update the resultDir field instead
|
|
175
|
-
*/
|
|
176
|
-
resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
*
|
|
180
|
-
* Directory name where the module augmentation will be stored
|
|
181
|
-
*
|
|
182
|
-
* Module augmentation allow better IDE suggestions and type checking
|
|
183
|
-
*
|
|
184
|
-
* Default: 'types'
|
|
185
|
-
*
|
|
186
|
-
* Example: 'intlayer-types'
|
|
187
|
-
*
|
|
188
|
-
* Note:
|
|
189
|
-
* - If this path changed, be sure to include it from the tsconfig.json file
|
|
190
|
-
* - If this directory is not at the base directory level, update the moduleAugmentationDir field instead
|
|
191
|
-
*/
|
|
192
|
-
moduleAugmentationDirName:
|
|
193
|
-
customConfiguration?.moduleAugmentationDirName ??
|
|
194
|
-
MODULE_AUGMENTATION_DIR_NAME,
|
|
195
|
-
// @TODO: Make Module Augmentation optional by adding a flag in the configuration
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Related to the intlayer result directory
|
|
199
|
-
*
|
|
200
|
-
* Directory name where the dictionaries will be stored
|
|
201
|
-
*
|
|
202
|
-
* Default: 'dictionary'
|
|
203
|
-
*
|
|
204
|
-
* Example: 'translations'
|
|
205
|
-
*
|
|
206
|
-
* Note:
|
|
207
|
-
* - If this directory is not at the result directory level, update the dictionariesDir field instead
|
|
208
|
-
*
|
|
209
|
-
*/
|
|
210
|
-
dictionariesDirName:
|
|
211
|
-
customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Related to the intlayer result directory
|
|
215
|
-
*
|
|
216
|
-
* Directory name where the dictionaries will be stored
|
|
217
|
-
*
|
|
218
|
-
* Default: 'dictionary'
|
|
219
|
-
*
|
|
220
|
-
* Example: 'translations'
|
|
221
|
-
*
|
|
222
|
-
* Note:
|
|
223
|
-
* - If this directory is not at the result directory level, update the dictionariesDir field instead
|
|
224
|
-
*
|
|
225
|
-
*/
|
|
226
|
-
i18nDictionariesDirName:
|
|
227
|
-
customConfiguration?.i18nDictionariesDirName ??
|
|
228
|
-
I18N_DICTIONARIES_DIR_NAME,
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Related to the intlayer result directory
|
|
232
|
-
*
|
|
233
|
-
* Directory name where the dictionaries types will be stored
|
|
234
|
-
*
|
|
235
|
-
* Default: 'types'
|
|
236
|
-
*
|
|
237
|
-
* Example: 'intlayer-types'
|
|
238
|
-
*
|
|
239
|
-
* Note:
|
|
240
|
-
* - If this directory is not at the result directory level, update the typesDir field instead
|
|
241
|
-
*
|
|
242
|
-
*/
|
|
243
|
-
typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Related to the intlayer result directory
|
|
247
|
-
*
|
|
248
|
-
* Directory name where the main files will be stored
|
|
249
|
-
*
|
|
250
|
-
* Default: 'main'
|
|
251
|
-
*
|
|
252
|
-
* Example: 'intlayer-main'
|
|
253
|
-
*
|
|
254
|
-
* Note:
|
|
255
|
-
* - If this directory is not at the result directory level, update the mainDir field instead
|
|
256
|
-
*/
|
|
257
|
-
mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Should exclude some directories from the content search
|
|
261
|
-
*
|
|
262
|
-
* Default: ['node_modules']
|
|
263
|
-
*
|
|
264
|
-
* Not used yet
|
|
265
|
-
* @TODO Implement the exclusion or remove it
|
|
266
|
-
*/
|
|
267
|
-
excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const baseDirDerivedConfiguration: BaseDerivedConfig = {
|
|
271
|
-
/**
|
|
272
|
-
* Directory where the content is stored
|
|
273
|
-
*
|
|
274
|
-
* Relative to the base directory of the project
|
|
275
|
-
*
|
|
276
|
-
* Default: {{baseDir}} / {{contentDirName}}
|
|
277
|
-
*
|
|
278
|
-
* Example: '/path/to/project/src'
|
|
279
|
-
*
|
|
280
|
-
* Note:
|
|
281
|
-
* - Can be changed to a custom directory to externalize the content used in the project
|
|
282
|
-
* - If the content is not at the base directory level, update the contentDirName field instead
|
|
283
|
-
*/
|
|
284
|
-
contentDir: join(
|
|
285
|
-
notDerivedContentConfig.baseDir,
|
|
286
|
-
notDerivedContentConfig.contentDirName
|
|
287
|
-
),
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Directory where the result will be stored
|
|
291
|
-
*
|
|
292
|
-
* Relative to the base directory of the project
|
|
293
|
-
*
|
|
294
|
-
* Default: {{baseDir}} / {{resultDirName}}
|
|
295
|
-
*
|
|
296
|
-
* Example: '/path/to/project/.intlayer'
|
|
297
|
-
*
|
|
298
|
-
* Note:
|
|
299
|
-
* - Can be changed to a custom directory to externalize the intlayer application from the project
|
|
300
|
-
* - If the result is not at the base directory level, update the resultDirName field instead
|
|
301
|
-
*/
|
|
302
|
-
resultDir: join(
|
|
303
|
-
notDerivedContentConfig.baseDir,
|
|
304
|
-
notDerivedContentConfig.resultDirName
|
|
305
|
-
),
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Directory where the module augmentation will be stored
|
|
309
|
-
*
|
|
310
|
-
* Module augmentation allow better IDE suggestions and type checking
|
|
311
|
-
*
|
|
312
|
-
* Relative to the base directory of the project
|
|
313
|
-
*
|
|
314
|
-
* Default: {{baseDir}} / {{moduleAugmentationDirName}}
|
|
315
|
-
*
|
|
316
|
-
* Example: '/path/to/project/types'
|
|
317
|
-
*
|
|
318
|
-
* Note:
|
|
319
|
-
* - If this path changed, be sure to include it from the tsconfig.json file
|
|
320
|
-
* - If the module augmentation is not at the base directory level, update the moduleAugmentationDirName field instead
|
|
321
|
-
*
|
|
322
|
-
*/
|
|
323
|
-
moduleAugmentationDir: join(
|
|
324
|
-
notDerivedContentConfig.baseDir,
|
|
325
|
-
notDerivedContentConfig.moduleAugmentationDirName
|
|
326
|
-
),
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Output format of the dictionary
|
|
330
|
-
*
|
|
331
|
-
* Default: ['intlayer']
|
|
332
|
-
*
|
|
333
|
-
* Note:
|
|
334
|
-
* - 'i18next' is not yet ensure a 1:1 mapping with the i18next library.
|
|
335
|
-
* - Removing 'intlayer' will break the compatibility with react-intlayer or next-intlayer
|
|
336
|
-
*/
|
|
337
|
-
dictionaryOutput:
|
|
338
|
-
customConfiguration?.dictionaryOutput ?? DICTIONARY_OUTPUT,
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const resultDirDerivedConfiguration: ResultDirDerivedConfig = {
|
|
342
|
-
/**
|
|
343
|
-
* Directory where the dictionaries will be stored
|
|
344
|
-
*
|
|
345
|
-
* Relative to the result directory
|
|
346
|
-
*
|
|
347
|
-
* Default: {{resultDir}} / {{dictionariesDirName}}
|
|
348
|
-
*
|
|
349
|
-
* Example: '/path/to/project/.intlayer/dictionary'
|
|
350
|
-
*
|
|
351
|
-
* Note:
|
|
352
|
-
* - If the types are not at the result directory level, update the dictionariesDirName field instead
|
|
353
|
-
* - The dictionaries are stored in JSON format
|
|
354
|
-
* - The dictionaries are used to translate the content
|
|
355
|
-
* - The dictionaries are built from the content files
|
|
356
|
-
*/
|
|
357
|
-
dictionariesDir: join(
|
|
358
|
-
baseDirDerivedConfiguration.resultDir,
|
|
359
|
-
notDerivedContentConfig.dictionariesDirName
|
|
360
|
-
),
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Directory where the 18n dictionaries will be stored
|
|
364
|
-
*
|
|
365
|
-
* Relative to the result directory
|
|
366
|
-
*
|
|
367
|
-
* Default: {{resultDir}} / {{i18nDictionariesDirName}}
|
|
368
|
-
*
|
|
369
|
-
* Example: '/path/to/project/.intlayer/dictionary/i18n'
|
|
370
|
-
*
|
|
371
|
-
* Note:
|
|
372
|
-
* - If the types are not at the result directory level, update the i18nDictionariesDirName field instead
|
|
373
|
-
*/
|
|
374
|
-
i18nDictionariesDir: join(
|
|
375
|
-
baseDirDerivedConfiguration.resultDir,
|
|
376
|
-
notDerivedContentConfig.i18nDictionariesDirName
|
|
377
|
-
),
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Directory where the dictionaries types will be stored
|
|
381
|
-
*
|
|
382
|
-
* Relative to the result directory
|
|
383
|
-
*
|
|
384
|
-
* Default: {{resultDir}} / {{typeDirName}}
|
|
385
|
-
*
|
|
386
|
-
* Example: '/path/to/project/.intlayer/types'
|
|
387
|
-
*
|
|
388
|
-
* Note:
|
|
389
|
-
* - If the types are not at the result directory level, update the typesDirName field instead
|
|
390
|
-
*/
|
|
391
|
-
typesDir: join(
|
|
392
|
-
baseDirDerivedConfiguration.resultDir,
|
|
393
|
-
notDerivedContentConfig.typeDirName
|
|
394
|
-
),
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Directory where the main files will be stored
|
|
398
|
-
*
|
|
399
|
-
* Relative to the result directory
|
|
400
|
-
*
|
|
401
|
-
* Default: {{resultDir}} / {{mainDirName}}
|
|
402
|
-
*
|
|
403
|
-
* Example: '/path/to/project/.intlayer/main'
|
|
404
|
-
*
|
|
405
|
-
* Note:
|
|
406
|
-
*
|
|
407
|
-
* - If the main files are not at the result directory level, update the mainDirName field instead
|
|
408
|
-
*/
|
|
409
|
-
mainDir: join(
|
|
410
|
-
baseDirDerivedConfiguration.resultDir,
|
|
411
|
-
notDerivedContentConfig.mainDirName
|
|
412
|
-
),
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
const patternsConfiguration: PatternsContentConfig = {
|
|
416
|
-
/**
|
|
417
|
-
* Pattern of files to watch
|
|
418
|
-
*
|
|
419
|
-
* Default: ['/**\/*.content.ts', '/**\/*.content.js', '/**\/*.content.json', '/**\/*.content.cjs', '/**\/*.content.mjs', '/**\/*.content.tsx', '/**\/*.content.jsx']
|
|
420
|
-
*/
|
|
421
|
-
watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
|
|
422
|
-
(ext) => `/**/*${ext}`
|
|
423
|
-
),
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Pattern of files to watch including the relative path
|
|
427
|
-
*
|
|
428
|
-
* Default: ['{{contentDir}}/**\/*.content.ts', '{{contentDir}}/**\/*.content.js', '{{contentDir}}/**\/*.content.json', '{{contentDir}}/**\/*.content.cjs', '{{contentDir}}/**\/*.content.mjs', '{{contentDir}}/**\/*.content.tsx', '{{contentDir}}/**\/*.content.jsx']
|
|
429
|
-
*/
|
|
430
|
-
watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
|
|
431
|
-
(ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
|
|
432
|
-
),
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Pattern of dictionary to interpret
|
|
436
|
-
*
|
|
437
|
-
* Default: '{{dictionariesDir}}/**\/*.json'
|
|
438
|
-
*/
|
|
439
|
-
outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
return {
|
|
443
|
-
...notDerivedContentConfig,
|
|
444
|
-
...baseDirDerivedConfiguration,
|
|
445
|
-
...resultDirDerivedConfiguration,
|
|
446
|
-
...patternsConfiguration,
|
|
447
|
-
};
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Build the configuration fields by merging the default values with the custom configuration
|
|
452
|
-
*/
|
|
453
|
-
export const buildConfigurationFields = (
|
|
454
|
-
options: GetConfigurationOptions,
|
|
455
|
-
customConfiguration?: CustomIntlayerConfig
|
|
456
|
-
): IntlayerConfig => {
|
|
457
|
-
const internationalizationConfig = buildInternationalizationFields(
|
|
458
|
-
customConfiguration?.internationalization
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
const middlewareConfig = buildMiddlewareFields(
|
|
462
|
-
customConfiguration?.middleware
|
|
463
|
-
);
|
|
464
|
-
|
|
465
|
-
const contentConfig = buildContentFields(customConfiguration?.content);
|
|
466
|
-
|
|
467
|
-
storedConfiguration = {
|
|
468
|
-
internationalization: internationalizationConfig,
|
|
469
|
-
middleware: middlewareConfig,
|
|
470
|
-
content: contentConfig,
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
return storedConfiguration;
|
|
474
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { relative } from 'path';
|
|
2
|
-
import type { CustomIntlayerConfig, IntlayerConfig } from '../types/config';
|
|
3
|
-
import { buildConfigurationFields } from './buildConfigurationFields';
|
|
4
|
-
import { loadConfigurationFile } from './loadConfigurationFile';
|
|
5
|
-
import { searchConfigurationFile } from './searchConfigurationFile';
|
|
6
|
-
|
|
7
|
-
let storedConfiguration: IntlayerConfig | undefined;
|
|
8
|
-
let storedConfigurationFilePath: string | undefined;
|
|
9
|
-
let storedNumCustomConfiguration: number | undefined;
|
|
10
|
-
|
|
11
|
-
export type GetConfigurationOptions = {
|
|
12
|
-
baseDir: string;
|
|
13
|
-
verbose: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();
|
|
17
|
-
const defaultOptions: GetConfigurationOptions = {
|
|
18
|
-
baseDir: BASE_DIR_PATH,
|
|
19
|
-
verbose: false,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get the configuration for the intlayer by reading the configuration file (e.g. intlayer.config.js)
|
|
24
|
-
*/
|
|
25
|
-
export const getConfiguration = (
|
|
26
|
-
options?: Partial<GetConfigurationOptions>
|
|
27
|
-
): IntlayerConfig => {
|
|
28
|
-
const mergedOptions = { ...defaultOptions, ...options };
|
|
29
|
-
const { baseDir, verbose } = mergedOptions;
|
|
30
|
-
|
|
31
|
-
if (!storedConfiguration) {
|
|
32
|
-
// Search for configuration files
|
|
33
|
-
const { configurationFilePath, numCustomConfiguration } =
|
|
34
|
-
searchConfigurationFile(baseDir);
|
|
35
|
-
|
|
36
|
-
// Load the custom configuration
|
|
37
|
-
let customConfiguration: CustomIntlayerConfig | undefined;
|
|
38
|
-
if (configurationFilePath) {
|
|
39
|
-
customConfiguration = loadConfigurationFile(configurationFilePath);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Save the configuration to avoid reading the file again
|
|
43
|
-
storedConfiguration = buildConfigurationFields(
|
|
44
|
-
mergedOptions,
|
|
45
|
-
customConfiguration
|
|
46
|
-
);
|
|
47
|
-
storedConfigurationFilePath = configurationFilePath;
|
|
48
|
-
storedNumCustomConfiguration = numCustomConfiguration;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Log warning if multiple configuration files are found
|
|
52
|
-
if (verbose)
|
|
53
|
-
logConfigFileResult(
|
|
54
|
-
storedNumCustomConfiguration,
|
|
55
|
-
storedConfigurationFilePath
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return storedConfiguration;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const logConfigFileResult = (
|
|
62
|
-
numCustomConfiguration?: number,
|
|
63
|
-
configurationFilePath?: string
|
|
64
|
-
) => {
|
|
65
|
-
if (numCustomConfiguration === 0) {
|
|
66
|
-
console.info('Configuration file not found, using default configuration.');
|
|
67
|
-
} else {
|
|
68
|
-
const relativeOutputPath = relative(BASE_DIR_PATH, configurationFilePath!);
|
|
69
|
-
|
|
70
|
-
if (numCustomConfiguration === 1) {
|
|
71
|
-
console.info(`Configuration file found: ${relativeOutputPath}.`);
|
|
72
|
-
} else {
|
|
73
|
-
console.warn(
|
|
74
|
-
`Multiple configuration files found, using ${relativeOutputPath}.`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
package/src/configFile/index.ts
DELETED