@intlayer/config 1.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/LICENSE +21 -0
- package/dist/cjs/client.cjs +48 -0
- package/dist/cjs/client.cjs.map +1 -0
- package/dist/cjs/client.d.ts +16 -0
- package/dist/cjs/configFile/buildConfigurationFields.cjs +182 -0
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -0
- package/dist/cjs/configFile/buildConfigurationFields.d.ts +10 -0
- package/dist/cjs/configFile/getConfiguration.cjs +90 -0
- package/dist/cjs/configFile/getConfiguration.cjs.map +1 -0
- package/dist/cjs/configFile/getConfiguration.d.ts +12 -0
- package/dist/cjs/configFile/index.cjs +35 -0
- package/dist/cjs/configFile/index.cjs.map +1 -0
- package/dist/cjs/configFile/index.d.ts +6 -0
- package/dist/cjs/configFile/loadConfigurationFile.cjs +110 -0
- package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -0
- package/dist/cjs/configFile/loadConfigurationFile.d.ts +8 -0
- package/dist/cjs/configFile/searchConfigurationFile.cjs +63 -0
- package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -0
- package/dist/cjs/configFile/searchConfigurationFile.d.ts +9 -0
- package/dist/cjs/defaultValues/internationalization.cjs +42 -0
- package/dist/cjs/defaultValues/internationalization.cjs.map +1 -0
- package/dist/cjs/defaultValues/internationalization.d.ts +6 -0
- package/dist/cjs/defaultValues/locales.cjs +266 -0
- package/dist/cjs/defaultValues/locales.cjs.map +1 -0
- package/dist/cjs/defaultValues/locales.d.ts +234 -0
- package/dist/cjs/defaultValues/middleware.cjs +49 -0
- package/dist/cjs/defaultValues/middleware.cjs.map +1 -0
- package/dist/cjs/defaultValues/middleware.d.ts +15 -0
- package/dist/cjs/defaultValues/server.cjs +61 -0
- package/dist/cjs/defaultValues/server.cjs.map +1 -0
- package/dist/cjs/defaultValues/server.d.ts +23 -0
- package/dist/cjs/envVariables/formatEnvVariable.cjs +52 -0
- package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -0
- package/dist/cjs/envVariables/formatEnvVariable.d.ts +3 -0
- package/dist/cjs/envVariables/getConfiguration.cjs +170 -0
- package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -0
- package/dist/cjs/envVariables/getConfiguration.d.ts +21 -0
- package/dist/cjs/envVariables/index.cjs +48 -0
- package/dist/cjs/envVariables/index.cjs.map +1 -0
- package/dist/cjs/envVariables/index.d.ts +10 -0
- package/dist/cjs/envVariables/utils.cjs +56 -0
- package/dist/cjs/envVariables/utils.cjs.map +1 -0
- package/dist/cjs/envVariables/utils.d.ts +16 -0
- package/dist/cjs/index.cjs +53 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/types/index.cjs +21 -0
- package/dist/cjs/types/index.cjs.map +1 -0
- package/dist/cjs/types/index.d.ts +89 -0
- package/dist/esm/client.d.mts +16 -0
- package/dist/esm/client.mjs +17 -0
- package/dist/esm/client.mjs.map +1 -0
- package/dist/esm/configFile/buildConfigurationFields.d.mts +10 -0
- package/dist/esm/configFile/buildConfigurationFields.mjs +159 -0
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -0
- package/dist/esm/configFile/getConfiguration.d.mts +12 -0
- package/dist/esm/configFile/getConfiguration.mjs +52 -0
- package/dist/esm/configFile/getConfiguration.mjs.map +1 -0
- package/dist/esm/configFile/index.d.mts +6 -0
- package/dist/esm/configFile/index.mjs +2 -0
- package/dist/esm/configFile/index.mjs.map +1 -0
- package/dist/esm/configFile/loadConfigurationFile.d.mts +8 -0
- package/dist/esm/configFile/loadConfigurationFile.mjs +76 -0
- package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -0
- package/dist/esm/configFile/searchConfigurationFile.d.mts +9 -0
- package/dist/esm/configFile/searchConfigurationFile.mjs +32 -0
- package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -0
- package/dist/esm/defaultValues/internationalization.d.mts +6 -0
- package/dist/esm/defaultValues/internationalization.mjs +5 -0
- package/dist/esm/defaultValues/internationalization.mjs.map +1 -0
- package/dist/esm/defaultValues/locales.d.mts +234 -0
- package/dist/esm/defaultValues/locales.mjs +235 -0
- package/dist/esm/defaultValues/locales.mjs.map +1 -0
- package/dist/esm/defaultValues/middleware.d.mts +15 -0
- package/dist/esm/defaultValues/middleware.mjs +15 -0
- package/dist/esm/defaultValues/middleware.mjs.map +1 -0
- package/dist/esm/defaultValues/server.d.mts +23 -0
- package/dist/esm/defaultValues/server.mjs +23 -0
- package/dist/esm/defaultValues/server.mjs.map +1 -0
- package/dist/esm/envVariables/formatEnvVariable.d.mts +3 -0
- package/dist/esm/envVariables/formatEnvVariable.mjs +21 -0
- package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -0
- package/dist/esm/envVariables/getConfiguration.d.mts +21 -0
- package/dist/esm/envVariables/getConfiguration.mjs +110 -0
- package/dist/esm/envVariables/getConfiguration.mjs.map +1 -0
- package/dist/esm/envVariables/index.d.mts +10 -0
- package/dist/esm/envVariables/index.mjs +17 -0
- package/dist/esm/envVariables/index.mjs.map +1 -0
- package/dist/esm/envVariables/utils.d.mts +16 -0
- package/dist/esm/envVariables/utils.mjs +25 -0
- package/dist/esm/envVariables/utils.mjs.map +1 -0
- package/dist/esm/index.d.mts +22 -0
- package/dist/esm/index.mjs +21 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/types/index.d.mts +89 -0
- package/dist/esm/types/index.mjs +1 -0
- package/dist/esm/types/index.mjs.map +1 -0
- package/package.json +88 -0
- package/src/client.ts +16 -0
- package/src/configFile/buildConfigurationFields.ts +214 -0
- package/src/configFile/getConfiguration.ts +75 -0
- package/src/configFile/index.ts +1 -0
- package/src/configFile/loadConfigurationFile.ts +97 -0
- package/src/configFile/searchConfigurationFile.ts +48 -0
- package/src/defaultValues/internationalization.ts +9 -0
- package/src/defaultValues/locales.ts +463 -0
- package/src/defaultValues/middleware.ts +11 -0
- package/src/defaultValues/server.ts +18 -0
- package/src/envVariables/formatEnvVariable.ts +32 -0
- package/src/envVariables/getConfiguration.ts +121 -0
- package/src/envVariables/index.ts +8 -0
- package/src/envVariables/utils.ts +47 -0
- package/src/index.ts +23 -0
- package/src/types/index.ts +144 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2021 Sébastien Vanvelthem
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var client_exports = {};
|
|
24
|
+
__export(client_exports, {
|
|
25
|
+
Locales: () => import_locales.Locales,
|
|
26
|
+
getConfiguration: () => import_getConfiguration.getConfiguration,
|
|
27
|
+
intlayerConfiguration: () => import_getConfiguration.intlayerConfiguration,
|
|
28
|
+
intlayerContentConfiguration: () =>
|
|
29
|
+
import_getConfiguration.intlayerContentConfiguration,
|
|
30
|
+
intlayerIntlConfiguration: () =>
|
|
31
|
+
import_getConfiguration.intlayerIntlConfiguration,
|
|
32
|
+
intlayerMiddlewareConfiguration: () =>
|
|
33
|
+
import_getConfiguration.intlayerMiddlewareConfiguration,
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(client_exports);
|
|
36
|
+
var import_locales = require("./defaultValues/locales.cjs");
|
|
37
|
+
var import_getConfiguration = require("./envVariables/getConfiguration.cjs");
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 &&
|
|
40
|
+
(module.exports = {
|
|
41
|
+
Locales,
|
|
42
|
+
getConfiguration,
|
|
43
|
+
intlayerConfiguration,
|
|
44
|
+
intlayerContentConfiguration,
|
|
45
|
+
intlayerIntlConfiguration,
|
|
46
|
+
intlayerMiddlewareConfiguration,
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client.ts"],"sourcesContent":["export type {\n CustomIntlayerConfig,\n PatternsContentConfig as FixedIntlayerConfig,\n IntlayerConfig,\n BaseContentConfig as NotDerivedConfiguration,\n BaseDerivedConfig as BaseDirDerivedConfiguration,\n ResultDirDerivedConfig as ResultDirDerivedConfiguration,\n} from './types';\nexport { Locales } from './defaultValues/locales';\nexport {\n getConfiguration,\n intlayerConfiguration,\n intlayerContentConfiguration,\n intlayerIntlConfiguration,\n intlayerMiddlewareConfiguration,\n} from './envVariables/getConfiguration';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAAwB;AACxB,8BAMO;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
BaseDerivedConfig as BaseDirDerivedConfiguration,
|
|
3
|
+
CustomIntlayerConfig,
|
|
4
|
+
PatternsContentConfig as FixedIntlayerConfig,
|
|
5
|
+
IntlayerConfig,
|
|
6
|
+
BaseContentConfig as NotDerivedConfiguration,
|
|
7
|
+
ResultDirDerivedConfig as ResultDirDerivedConfiguration,
|
|
8
|
+
} from "./types/index.js";
|
|
9
|
+
export { Locales } from "./defaultValues/locales.js";
|
|
10
|
+
export {
|
|
11
|
+
getConfiguration,
|
|
12
|
+
intlayerConfiguration,
|
|
13
|
+
intlayerContentConfiguration,
|
|
14
|
+
intlayerIntlConfiguration,
|
|
15
|
+
intlayerMiddlewareConfiguration,
|
|
16
|
+
} from "./envVariables/getConfiguration.js";
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var buildConfigurationFields_exports = {};
|
|
24
|
+
__export(buildConfigurationFields_exports, {
|
|
25
|
+
buildConfigurationFields: () => buildConfigurationFields,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(buildConfigurationFields_exports);
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var import_internationalization = require("../defaultValues/internationalization.cjs");
|
|
30
|
+
var import_middleware = require("../defaultValues/middleware.cjs");
|
|
31
|
+
var import_server = require("../defaultValues/server.cjs");
|
|
32
|
+
let storedConfiguration;
|
|
33
|
+
const buildInternationalizationFields = (customConfiguration) => ({
|
|
34
|
+
/**
|
|
35
|
+
* Internationalization configuration
|
|
36
|
+
*/
|
|
37
|
+
// Locales available in the application
|
|
38
|
+
locales: customConfiguration?.locales ?? import_internationalization.LOCALES,
|
|
39
|
+
// Default locale of the application for fallback
|
|
40
|
+
defaultLocale:
|
|
41
|
+
customConfiguration?.defaultLocale ??
|
|
42
|
+
import_internationalization.DEFAULT_LOCALE,
|
|
43
|
+
});
|
|
44
|
+
const buildMiddlewareFields = (customConfiguration) => ({
|
|
45
|
+
/**
|
|
46
|
+
* Middleware configuration
|
|
47
|
+
*/
|
|
48
|
+
// Header name to get the locale
|
|
49
|
+
headerName: customConfiguration?.headerName ?? import_middleware.HEADER_NAME,
|
|
50
|
+
// Cookie name to get the locale
|
|
51
|
+
cookieName: customConfiguration?.cookieName ?? import_middleware.COOKIE_NAME,
|
|
52
|
+
// Prefix the default locale in the URL
|
|
53
|
+
prefixDefault:
|
|
54
|
+
customConfiguration?.prefixDefault ?? import_middleware.PREFIX_DEFAULT,
|
|
55
|
+
// Base path
|
|
56
|
+
basePath: customConfiguration?.basePath ?? import_middleware.BASE_PATH,
|
|
57
|
+
// Set cookie on server
|
|
58
|
+
serverSetCookie:
|
|
59
|
+
customConfiguration?.serverSetCookie ?? import_middleware.SERVER_SET_COOKIE,
|
|
60
|
+
// No prefix
|
|
61
|
+
noPrefix: customConfiguration?.noPrefix ?? import_middleware.NO_PREFIX,
|
|
62
|
+
});
|
|
63
|
+
const buildContentFields = (customConfiguration) => {
|
|
64
|
+
const notDerivedContentConfig = {
|
|
65
|
+
/**
|
|
66
|
+
* Content configurations
|
|
67
|
+
*/
|
|
68
|
+
// File extensions of content to look for
|
|
69
|
+
fileExtensions:
|
|
70
|
+
customConfiguration?.fileExtensions ?? import_server.FILE_EXTENSIONS,
|
|
71
|
+
// Directory name of the project
|
|
72
|
+
baseDir: customConfiguration?.baseDir ?? process.cwd(),
|
|
73
|
+
// Directory name where the content is stored
|
|
74
|
+
contentDirName:
|
|
75
|
+
customConfiguration?.contentDirName ?? import_server.CONTENT_DIR_NAME,
|
|
76
|
+
// Result directory name
|
|
77
|
+
resultDirName:
|
|
78
|
+
customConfiguration?.resultDirName ?? import_server.RESULT_DIR_NAME,
|
|
79
|
+
// Module augmentation directory name
|
|
80
|
+
moduleAugmentationDirName:
|
|
81
|
+
customConfiguration?.moduleAugmentationDirName ??
|
|
82
|
+
import_server.MODULE_AUGMENTATION_DIR_NAME,
|
|
83
|
+
// Bundle directory name
|
|
84
|
+
bundleDirName:
|
|
85
|
+
customConfiguration?.bundleDirName ?? import_server.BUNDLE_DIR_NAME,
|
|
86
|
+
// Bundle file extension
|
|
87
|
+
bundleFileExtension:
|
|
88
|
+
customConfiguration?.bundleFileExtension ??
|
|
89
|
+
import_server.BUNDLE_FILE_EXTENSION,
|
|
90
|
+
// Dictionary directory name
|
|
91
|
+
dictionariesDirName:
|
|
92
|
+
customConfiguration?.dictionariesDirName ??
|
|
93
|
+
import_server.DICTIONARIES_DIR_NAME,
|
|
94
|
+
// Types directory name
|
|
95
|
+
typeDirName:
|
|
96
|
+
customConfiguration?.typeDirName ?? import_server.TYPES_DIR_NAME,
|
|
97
|
+
// Main directory name
|
|
98
|
+
mainDirName:
|
|
99
|
+
customConfiguration?.mainDirName ?? import_server.MAIN_DIR_NAME,
|
|
100
|
+
// Directories to exclude
|
|
101
|
+
excludedPath:
|
|
102
|
+
customConfiguration?.excludedPath ?? import_server.EXCLUDED_PATHS,
|
|
103
|
+
};
|
|
104
|
+
const baseDirDerivedConfiguration = {
|
|
105
|
+
// Directory where the content is stored
|
|
106
|
+
contentDir: (0, import_path.join)(
|
|
107
|
+
notDerivedContentConfig.baseDir,
|
|
108
|
+
notDerivedContentConfig.contentDirName
|
|
109
|
+
),
|
|
110
|
+
// Directory where the result will be stored
|
|
111
|
+
resultDir: (0, import_path.join)(
|
|
112
|
+
notDerivedContentConfig.baseDir,
|
|
113
|
+
notDerivedContentConfig.resultDirName
|
|
114
|
+
),
|
|
115
|
+
// Directory where the module augmentation will be stored
|
|
116
|
+
moduleAugmentationDir: (0, import_path.join)(
|
|
117
|
+
notDerivedContentConfig.baseDir,
|
|
118
|
+
notDerivedContentConfig.moduleAugmentationDirName
|
|
119
|
+
),
|
|
120
|
+
};
|
|
121
|
+
const resultDirDerivedConfiguration = {
|
|
122
|
+
// Directory where the bundle will be stored
|
|
123
|
+
bundleDir: (0, import_path.join)(
|
|
124
|
+
baseDirDerivedConfiguration.resultDir,
|
|
125
|
+
notDerivedContentConfig.bundleDirName
|
|
126
|
+
),
|
|
127
|
+
// Directory where the dictionaries will be stored
|
|
128
|
+
dictionariesDir: (0, import_path.join)(
|
|
129
|
+
baseDirDerivedConfiguration.resultDir,
|
|
130
|
+
notDerivedContentConfig.dictionariesDirName
|
|
131
|
+
),
|
|
132
|
+
// Directory where the types will be stored
|
|
133
|
+
typesDir: (0, import_path.join)(
|
|
134
|
+
baseDirDerivedConfiguration.resultDir,
|
|
135
|
+
notDerivedContentConfig.typeDirName
|
|
136
|
+
),
|
|
137
|
+
// Directory where the main files will be stored
|
|
138
|
+
mainDir: (0, import_path.join)(
|
|
139
|
+
baseDirDerivedConfiguration.resultDir,
|
|
140
|
+
notDerivedContentConfig.mainDirName
|
|
141
|
+
),
|
|
142
|
+
};
|
|
143
|
+
const patternsConfiguration = {
|
|
144
|
+
// Pattern of files to watch
|
|
145
|
+
watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
|
|
146
|
+
(ext) => `/**/*${ext}`
|
|
147
|
+
),
|
|
148
|
+
// Pattern of files to watch including the relative path
|
|
149
|
+
watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
|
|
150
|
+
(ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
|
|
151
|
+
),
|
|
152
|
+
// Pattern of files to output
|
|
153
|
+
outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
...notDerivedContentConfig,
|
|
157
|
+
...baseDirDerivedConfiguration,
|
|
158
|
+
...resultDirDerivedConfiguration,
|
|
159
|
+
...patternsConfiguration,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const buildConfigurationFields = (options, customConfiguration) => {
|
|
163
|
+
const internationalizationConfig = buildInternationalizationFields(
|
|
164
|
+
customConfiguration?.internationalization
|
|
165
|
+
);
|
|
166
|
+
const middlewareConfig = buildMiddlewareFields(
|
|
167
|
+
customConfiguration?.middleware
|
|
168
|
+
);
|
|
169
|
+
const contentConfig = buildContentFields(customConfiguration?.content);
|
|
170
|
+
storedConfiguration = {
|
|
171
|
+
internationalization: internationalizationConfig,
|
|
172
|
+
middleware: middlewareConfig,
|
|
173
|
+
content: contentConfig,
|
|
174
|
+
};
|
|
175
|
+
return storedConfiguration;
|
|
176
|
+
};
|
|
177
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
178
|
+
0 &&
|
|
179
|
+
(module.exports = {
|
|
180
|
+
buildConfigurationFields,
|
|
181
|
+
});
|
|
182
|
+
//# sourceMappingURL=buildConfigurationFields.cjs.map
|
|
@@ -0,0 +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';\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":"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","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CustomIntlayerConfig, IntlayerConfig } from "../types/index.js";
|
|
2
|
+
import { GetConfigurationOptions } from "./getConfiguration.js";
|
|
3
|
+
import "../defaultValues/locales.js";
|
|
4
|
+
|
|
5
|
+
declare const buildConfigurationFields: (
|
|
6
|
+
options: GetConfigurationOptions,
|
|
7
|
+
customConfiguration?: CustomIntlayerConfig
|
|
8
|
+
) => IntlayerConfig;
|
|
9
|
+
|
|
10
|
+
export { buildConfigurationFields };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var getConfiguration_exports = {};
|
|
24
|
+
__export(getConfiguration_exports, {
|
|
25
|
+
getConfiguration: () => getConfiguration,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(getConfiguration_exports);
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var import_buildConfigurationFields = require("./buildConfigurationFields.cjs");
|
|
30
|
+
var import_loadConfigurationFile = require("./loadConfigurationFile.cjs");
|
|
31
|
+
var import_searchConfigurationFile = require("./searchConfigurationFile.cjs");
|
|
32
|
+
let storedConfiguration;
|
|
33
|
+
let storedConfigurationFilePath;
|
|
34
|
+
let storedNumCustomConfiguration;
|
|
35
|
+
const BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();
|
|
36
|
+
const defaultOptions = {
|
|
37
|
+
baseDir: BASE_DIR_PATH,
|
|
38
|
+
verbose: false,
|
|
39
|
+
};
|
|
40
|
+
const getConfiguration = (options) => {
|
|
41
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
42
|
+
const { baseDir, verbose } = mergedOptions;
|
|
43
|
+
if (!storedConfiguration) {
|
|
44
|
+
const { configurationFilePath, numCustomConfiguration } = (0,
|
|
45
|
+
import_searchConfigurationFile.searchConfigurationFile)(baseDir);
|
|
46
|
+
let customConfiguration;
|
|
47
|
+
if (configurationFilePath) {
|
|
48
|
+
customConfiguration = (0,
|
|
49
|
+
import_loadConfigurationFile.loadConfigurationFile)(
|
|
50
|
+
configurationFilePath
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
storedConfiguration = (0,
|
|
54
|
+
import_buildConfigurationFields.buildConfigurationFields)(
|
|
55
|
+
mergedOptions,
|
|
56
|
+
customConfiguration
|
|
57
|
+
);
|
|
58
|
+
storedConfigurationFilePath = configurationFilePath;
|
|
59
|
+
storedNumCustomConfiguration = numCustomConfiguration;
|
|
60
|
+
}
|
|
61
|
+
if (verbose)
|
|
62
|
+
logConfigFileResult(
|
|
63
|
+
storedNumCustomConfiguration,
|
|
64
|
+
storedConfigurationFilePath
|
|
65
|
+
);
|
|
66
|
+
return storedConfiguration;
|
|
67
|
+
};
|
|
68
|
+
const logConfigFileResult = (numCustomConfiguration, configurationFilePath) => {
|
|
69
|
+
if (numCustomConfiguration === 0) {
|
|
70
|
+
console.info("Configuration file not found, using default configuration.");
|
|
71
|
+
} else {
|
|
72
|
+
const relativeOutputPath = (0, import_path.relative)(
|
|
73
|
+
BASE_DIR_PATH,
|
|
74
|
+
configurationFilePath
|
|
75
|
+
);
|
|
76
|
+
if (numCustomConfiguration === 1) {
|
|
77
|
+
console.info(`Configuration file found: ${relativeOutputPath}.`);
|
|
78
|
+
} else {
|
|
79
|
+
console.warn(
|
|
80
|
+
`Multiple configuration files found, using ${relativeOutputPath}.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 &&
|
|
87
|
+
(module.exports = {
|
|
88
|
+
getConfiguration,
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=getConfiguration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/getConfiguration.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { CustomIntlayerConfig, IntlayerConfig } from '../types';\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;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AAEzB,sCAAyC;AACzC,mCAAsC;AACtC,qCAAwC;AAExC,IAAI;AACJ,IAAI;AACJ,IAAI;AAOJ,MAAM,gBAAgB,QAAQ,IAAI,0BAA0B,QAAQ,IAAI;AACxE,MAAM,iBAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AACX;AAEO,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,QACpD,wDAAwB,OAAO;AAGjC,QAAI;AACJ,QAAI,uBAAuB;AACzB,gCAAsB,oDAAsB,qBAAqB;AAAA,IACnE;AAGA,8BAAsB;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,yBAAqB,sBAAS,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":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IntlayerConfig } from "../types/index.js";
|
|
2
|
+
import "../defaultValues/locales.js";
|
|
3
|
+
|
|
4
|
+
type GetConfigurationOptions = {
|
|
5
|
+
baseDir: string;
|
|
6
|
+
verbose: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const getConfiguration: (
|
|
9
|
+
options?: Partial<GetConfigurationOptions>
|
|
10
|
+
) => IntlayerConfig;
|
|
11
|
+
|
|
12
|
+
export { type GetConfigurationOptions, getConfiguration };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, {
|
|
11
|
+
get: () => from[key],
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (
|
|
18
|
+
__copyProps(target, mod, "default"),
|
|
19
|
+
secondTarget && __copyProps(secondTarget, mod, "default")
|
|
20
|
+
);
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var configFile_exports = {};
|
|
24
|
+
module.exports = __toCommonJS(configFile_exports);
|
|
25
|
+
__reExport(
|
|
26
|
+
configFile_exports,
|
|
27
|
+
require("./getConfiguration.cjs"),
|
|
28
|
+
module.exports
|
|
29
|
+
);
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 &&
|
|
32
|
+
(module.exports = {
|
|
33
|
+
...require("./getConfiguration.cjs"),
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,+BAAd;","names":[]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var loadConfigurationFile_exports = {};
|
|
24
|
+
__export(loadConfigurationFile_exports, {
|
|
25
|
+
loadConfigurationFile: () => loadConfigurationFile,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(loadConfigurationFile_exports);
|
|
28
|
+
var import_module = require("module");
|
|
29
|
+
var import_vm = require("vm");
|
|
30
|
+
var import_esbuild = require("esbuild");
|
|
31
|
+
const import_meta = {};
|
|
32
|
+
const isESModule = typeof import_meta.url === "string";
|
|
33
|
+
const sandboxContext = {
|
|
34
|
+
exports: {
|
|
35
|
+
default: {},
|
|
36
|
+
},
|
|
37
|
+
module: {
|
|
38
|
+
exports: {},
|
|
39
|
+
},
|
|
40
|
+
console,
|
|
41
|
+
require: isESModule
|
|
42
|
+
? (0, import_module.createRequire)(import_meta.url)
|
|
43
|
+
: require,
|
|
44
|
+
};
|
|
45
|
+
const transformationOption = {
|
|
46
|
+
loader: {
|
|
47
|
+
".js": "js",
|
|
48
|
+
".jsx": "jsx",
|
|
49
|
+
".mjs": "js",
|
|
50
|
+
".ts": "ts",
|
|
51
|
+
".tsx": "tsx",
|
|
52
|
+
".cjs": "js",
|
|
53
|
+
".json": "json",
|
|
54
|
+
},
|
|
55
|
+
format: "cjs",
|
|
56
|
+
// Output format as commonjs
|
|
57
|
+
target: "es2017",
|
|
58
|
+
packages: "external",
|
|
59
|
+
write: false,
|
|
60
|
+
bundle: true,
|
|
61
|
+
};
|
|
62
|
+
const loadConfigurationFile = (configFilePath) => {
|
|
63
|
+
let customConfiguration = void 0;
|
|
64
|
+
const configFileExtension = configFilePath.split(".").pop() ?? "";
|
|
65
|
+
try {
|
|
66
|
+
if (configFileExtension === "json") {
|
|
67
|
+
return require(configFilePath);
|
|
68
|
+
}
|
|
69
|
+
const moduleResult = (0, import_esbuild.buildSync)({
|
|
70
|
+
entryPoints: [configFilePath],
|
|
71
|
+
...transformationOption,
|
|
72
|
+
});
|
|
73
|
+
const moduleResultString = moduleResult.outputFiles?.[0].text;
|
|
74
|
+
if (!moduleResultString) {
|
|
75
|
+
console.error("Configuration file could not be loaded.");
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
(0, import_vm.runInNewContext)(moduleResultString, sandboxContext);
|
|
79
|
+
if (
|
|
80
|
+
sandboxContext.exports.default &&
|
|
81
|
+
Object.keys(sandboxContext.exports.default).length > 0
|
|
82
|
+
) {
|
|
83
|
+
customConfiguration = sandboxContext.exports.default;
|
|
84
|
+
} else if (
|
|
85
|
+
sandboxContext.module.exports.defaults &&
|
|
86
|
+
Object.keys(sandboxContext.module.exports.defaults).length > 0
|
|
87
|
+
) {
|
|
88
|
+
customConfiguration = sandboxContext.module.exports.default;
|
|
89
|
+
} else if (
|
|
90
|
+
sandboxContext.module.exports.default &&
|
|
91
|
+
Object.keys(sandboxContext.module.exports.default).length > 0
|
|
92
|
+
) {
|
|
93
|
+
customConfiguration = sandboxContext.module.exports.default;
|
|
94
|
+
} else if (
|
|
95
|
+
sandboxContext.module.exports &&
|
|
96
|
+
Object.keys(sandboxContext.module.exports).length > 0
|
|
97
|
+
) {
|
|
98
|
+
customConfiguration = sandboxContext.module.exports;
|
|
99
|
+
}
|
|
100
|
+
return customConfiguration;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("Error:", error);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 &&
|
|
107
|
+
(module.exports = {
|
|
108
|
+
loadConfigurationFile,
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=loadConfigurationFile.cjs.map
|
|
@@ -0,0 +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';\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,gBAA8C;AAC9C,qBAA+D;AAH/D;AAMA,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,iBAAa,6BAAc,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;AAEO,MAAM,wBAAwB,CACnC,mBACqC;AACrC,MAAI,sBAAwD;AAE5D,QAAM,sBAAsB,eAAe,MAAM,GAAG,EAAE,IAAI,KAAK;AAE/D,MAAI;AACF,QAAI,wBAAwB,QAAQ;AAElC,aAAO,QAAQ,cAAc;AAAA,IAC/B;AAIA,UAAM,mBAA4B,0BAAU;AAAA,MAC1C,aAAa,CAAC,cAAc;AAAA,MAE5B,GAAG;AAAA,IACL,CAAC;AAED,UAAM,qBAAqB,aAAa,cAAc,CAAC,EAAE;AAEzD,QAAI,CAAC,oBAAoB;AACvB,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,mCAAgB,oBAAoB,cAAc;AAElD,QACE,eAAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,4BAAsB,eAAe,QAAQ;AAAA,IAC/C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,4BAAsB,eAAe,OAAO,QAAQ;AAAA,IACtD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,4BAAsB,eAAe,OAAO;AAAA,IAC9C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var searchConfigurationFile_exports = {};
|
|
24
|
+
__export(searchConfigurationFile_exports, {
|
|
25
|
+
searchConfigurationFile: () => searchConfigurationFile,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(searchConfigurationFile_exports);
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
const EXTENSION = ["ts", "js", "json", "cjs", "mjs", ""];
|
|
31
|
+
const CONFIGURATION_FILE_NAME_1 = "intlayer.config";
|
|
32
|
+
const CONFIGURATION_FILE_NAME_2 = ".intlayerrc";
|
|
33
|
+
const intLayerConfigFiles = EXTENSION.filter(
|
|
34
|
+
(extension) => extension !== ""
|
|
35
|
+
).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);
|
|
36
|
+
const configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];
|
|
37
|
+
const searchConfigurationFile = (configFilePath) => {
|
|
38
|
+
let configurationFilePath = void 0;
|
|
39
|
+
let numCustomConfiguration = 0;
|
|
40
|
+
for (const fileName of configurationFiles) {
|
|
41
|
+
try {
|
|
42
|
+
const filePath = (0, import_path.resolve)(configFilePath, fileName);
|
|
43
|
+
if (!(0, import_fs.existsSync)(filePath)) {
|
|
44
|
+
continue;
|
|
45
|
+
} else {
|
|
46
|
+
numCustomConfiguration += 1;
|
|
47
|
+
if (!configurationFilePath) {
|
|
48
|
+
configurationFilePath = filePath;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`${fileName}: ${error}`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { configurationFilePath, numCustomConfiguration };
|
|
57
|
+
};
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 &&
|
|
60
|
+
(module.exports = {
|
|
61
|
+
searchConfigurationFile,
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=searchConfigurationFile.cjs.map
|