@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
|
@@ -0,0 +1,21 @@
|
|
|
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 __toCommonJS = (mod) =>
|
|
18
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var types_exports = {};
|
|
20
|
+
module.exports = __toCommonJS(types_exports);
|
|
21
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["import type { Locales } from '../defaultValues/locales';\n\nexport type InternationalizationConfig = {\n // Available languages in the app\n locales: Locales[]; // default [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH]\n\n // Default language\n defaultLocale: Locales; // default Locales.ENGLISH\n};\n\nexport type ServerSetCookieRule = 'always' | 'never';\nexport type MiddlewareConfig = {\n // Header name to get the language\n headerName: string; // default 'x-intlayer-locale'\n\n // Cookie name to get the language\n cookieName: string; // default 'NEXT_LOCALE'\n\n // Prefix the default language in the URL\n prefixDefault: boolean; // default false\n\n // Base path\n basePath: string; // default ''\n\n // Set cookie on server\n serverSetCookie: ServerSetCookieRule; // default 'always'\n\n // No prefix\n noPrefix: boolean; // default false;\n};\n\nexport type CustomIntlayerConfig = {\n /**\n * Internationalization configuration\n */\n\n internationalization?: Partial<InternationalizationConfig>;\n\n /**\n * Middleware configuration\n */\n\n middleware?: Partial<MiddlewareConfig>;\n\n /**\n * Content configuration\n */\n content?: Partial<ContentConfig>;\n};\n\nexport type IntlayerConfig = {\n /**\n * Internationalization configuration\n */\n\n internationalization: InternationalizationConfig;\n\n /**\n * Middleware configuration\n */\n\n middleware: MiddlewareConfig;\n\n /**\n * Content configuration\n */\n content: ContentConfig;\n};\n\nexport type BaseContentConfig = {\n // File extensions of content to look for\n fileExtensions: string[]; // default ['.content.ts', '.content.js', '.content.json']\n\n // Directory of the project\n baseDir: string; // default process.cwd()\n\n // Directory name where the content is stored\n contentDirName: string; // default 'src'\n\n // Directories to exclude\n excludedPath: string[]; // default ['node_modules']\n\n // Result directory name\n resultDirName: string; // default '.intlayer'\n\n // Module augmentation directory name\n moduleAugmentationDirName: string; // default 'types'\n\n // Bundle directory name\n bundleDirName: string; // default 'bundle'\n\n // Bundle file extension\n bundleFileExtension: string; // default '.bundle.js'\n\n // Dictionary directory name\n dictionariesDirName: string; // default 'dictionary'\n\n // Types directory name\n typeDirName: string; // default 'types'\n\n // Main directory name\n mainDirName: string; // default 'main'\n};\n\nexport type BaseDerivedConfig = {\n // Directory to watch - emplacement where the content is stored\n contentDir: string; // default {{baseDir}} / {{contentDirName}}\n\n // Result directory\n resultDir: string; // default {{baseDir}} / {{resultDirName}}\n\n // Result directory\n moduleAugmentationDir: string; // default {{baseDir}} / {{moduleAugmentationDirName}}\n};\n\nexport type ResultDirDerivedConfig = {\n // Bundle directory\n bundleDir: string; // default {{resultDir}} / {{bundleDirName}}\n\n // Dictionary directory\n dictionariesDir: string; // default {{resultDir}} / {{dictionaryDirName}}\n\n // Types directory\n typesDir: string; // default {{resultDir}} / {{typeDirName}}\n\n // Main directory\n mainDir: string; // default {{resultDir}} / {{mainDirName}}\n};\n\nexport type PatternsContentConfig = {\n // Pattern of files to watch\n watchedFilesPattern: string[];\n\n // Pattern of files to watch including the relative path\n watchedFilesPatternWithPath: string[];\n\n // Pattern of files to output\n outputFilesPatternWithPath: string;\n};\n\nexport type ContentConfig = BaseContentConfig &\n BaseDerivedConfig &\n ResultDirDerivedConfig &\n PatternsContentConfig;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Locales } from "../defaultValues/locales.js";
|
|
2
|
+
|
|
3
|
+
type InternationalizationConfig = {
|
|
4
|
+
locales: Locales[];
|
|
5
|
+
defaultLocale: Locales;
|
|
6
|
+
};
|
|
7
|
+
type ServerSetCookieRule = "always" | "never";
|
|
8
|
+
type MiddlewareConfig = {
|
|
9
|
+
headerName: string;
|
|
10
|
+
cookieName: string;
|
|
11
|
+
prefixDefault: boolean;
|
|
12
|
+
basePath: string;
|
|
13
|
+
serverSetCookie: ServerSetCookieRule;
|
|
14
|
+
noPrefix: boolean;
|
|
15
|
+
};
|
|
16
|
+
type CustomIntlayerConfig = {
|
|
17
|
+
/**
|
|
18
|
+
* Internationalization configuration
|
|
19
|
+
*/
|
|
20
|
+
internationalization?: Partial<InternationalizationConfig>;
|
|
21
|
+
/**
|
|
22
|
+
* Middleware configuration
|
|
23
|
+
*/
|
|
24
|
+
middleware?: Partial<MiddlewareConfig>;
|
|
25
|
+
/**
|
|
26
|
+
* Content configuration
|
|
27
|
+
*/
|
|
28
|
+
content?: Partial<ContentConfig>;
|
|
29
|
+
};
|
|
30
|
+
type IntlayerConfig = {
|
|
31
|
+
/**
|
|
32
|
+
* Internationalization configuration
|
|
33
|
+
*/
|
|
34
|
+
internationalization: InternationalizationConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Middleware configuration
|
|
37
|
+
*/
|
|
38
|
+
middleware: MiddlewareConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Content configuration
|
|
41
|
+
*/
|
|
42
|
+
content: ContentConfig;
|
|
43
|
+
};
|
|
44
|
+
type BaseContentConfig = {
|
|
45
|
+
fileExtensions: string[];
|
|
46
|
+
baseDir: string;
|
|
47
|
+
contentDirName: string;
|
|
48
|
+
excludedPath: string[];
|
|
49
|
+
resultDirName: string;
|
|
50
|
+
moduleAugmentationDirName: string;
|
|
51
|
+
bundleDirName: string;
|
|
52
|
+
bundleFileExtension: string;
|
|
53
|
+
dictionariesDirName: string;
|
|
54
|
+
typeDirName: string;
|
|
55
|
+
mainDirName: string;
|
|
56
|
+
};
|
|
57
|
+
type BaseDerivedConfig = {
|
|
58
|
+
contentDir: string;
|
|
59
|
+
resultDir: string;
|
|
60
|
+
moduleAugmentationDir: string;
|
|
61
|
+
};
|
|
62
|
+
type ResultDirDerivedConfig = {
|
|
63
|
+
bundleDir: string;
|
|
64
|
+
dictionariesDir: string;
|
|
65
|
+
typesDir: string;
|
|
66
|
+
mainDir: string;
|
|
67
|
+
};
|
|
68
|
+
type PatternsContentConfig = {
|
|
69
|
+
watchedFilesPattern: string[];
|
|
70
|
+
watchedFilesPatternWithPath: string[];
|
|
71
|
+
outputFilesPatternWithPath: string;
|
|
72
|
+
};
|
|
73
|
+
type ContentConfig = BaseContentConfig &
|
|
74
|
+
BaseDerivedConfig &
|
|
75
|
+
ResultDirDerivedConfig &
|
|
76
|
+
PatternsContentConfig;
|
|
77
|
+
|
|
78
|
+
export type {
|
|
79
|
+
BaseContentConfig,
|
|
80
|
+
BaseDerivedConfig,
|
|
81
|
+
ContentConfig,
|
|
82
|
+
CustomIntlayerConfig,
|
|
83
|
+
InternationalizationConfig,
|
|
84
|
+
IntlayerConfig,
|
|
85
|
+
MiddlewareConfig,
|
|
86
|
+
PatternsContentConfig,
|
|
87
|
+
ResultDirDerivedConfig,
|
|
88
|
+
ServerSetCookieRule,
|
|
89
|
+
};
|
|
@@ -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.mjs";
|
|
9
|
+
export { Locales } from "./defaultValues/locales.mjs";
|
|
10
|
+
export {
|
|
11
|
+
getConfiguration,
|
|
12
|
+
intlayerConfiguration,
|
|
13
|
+
intlayerContentConfiguration,
|
|
14
|
+
intlayerIntlConfiguration,
|
|
15
|
+
intlayerMiddlewareConfiguration,
|
|
16
|
+
} from "./envVariables/getConfiguration.mjs";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Locales } from "./defaultValues/locales.mjs";
|
|
2
|
+
import {
|
|
3
|
+
getConfiguration,
|
|
4
|
+
intlayerConfiguration,
|
|
5
|
+
intlayerContentConfiguration,
|
|
6
|
+
intlayerIntlConfiguration,
|
|
7
|
+
intlayerMiddlewareConfiguration,
|
|
8
|
+
} from "./envVariables/getConfiguration.mjs";
|
|
9
|
+
export {
|
|
10
|
+
Locales,
|
|
11
|
+
getConfiguration,
|
|
12
|
+
intlayerConfiguration,
|
|
13
|
+
intlayerContentConfiguration,
|
|
14
|
+
intlayerIntlConfiguration,
|
|
15
|
+
intlayerMiddlewareConfiguration,
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=client.mjs.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":"AAQA,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CustomIntlayerConfig, IntlayerConfig } from "../types/index.mjs";
|
|
2
|
+
import { GetConfigurationOptions } from "./getConfiguration.mjs";
|
|
3
|
+
import "../defaultValues/locales.mjs";
|
|
4
|
+
|
|
5
|
+
declare const buildConfigurationFields: (
|
|
6
|
+
options: GetConfigurationOptions,
|
|
7
|
+
customConfiguration?: CustomIntlayerConfig
|
|
8
|
+
) => IntlayerConfig;
|
|
9
|
+
|
|
10
|
+
export { buildConfigurationFields };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_LOCALE,
|
|
4
|
+
LOCALES,
|
|
5
|
+
} from "../defaultValues/internationalization.mjs";
|
|
6
|
+
import {
|
|
7
|
+
BASE_PATH,
|
|
8
|
+
COOKIE_NAME,
|
|
9
|
+
HEADER_NAME,
|
|
10
|
+
NO_PREFIX,
|
|
11
|
+
PREFIX_DEFAULT,
|
|
12
|
+
SERVER_SET_COOKIE,
|
|
13
|
+
} from "../defaultValues/middleware.mjs";
|
|
14
|
+
import {
|
|
15
|
+
BUNDLE_DIR_NAME,
|
|
16
|
+
CONTENT_DIR_NAME,
|
|
17
|
+
DICTIONARIES_DIR_NAME,
|
|
18
|
+
FILE_EXTENSIONS,
|
|
19
|
+
RESULT_DIR_NAME,
|
|
20
|
+
EXCLUDED_PATHS,
|
|
21
|
+
BUNDLE_FILE_EXTENSION,
|
|
22
|
+
TYPES_DIR_NAME,
|
|
23
|
+
MAIN_DIR_NAME,
|
|
24
|
+
MODULE_AUGMENTATION_DIR_NAME,
|
|
25
|
+
} from "../defaultValues/server.mjs";
|
|
26
|
+
let storedConfiguration;
|
|
27
|
+
const buildInternationalizationFields = (customConfiguration) => ({
|
|
28
|
+
/**
|
|
29
|
+
* Internationalization configuration
|
|
30
|
+
*/
|
|
31
|
+
// Locales available in the application
|
|
32
|
+
locales: customConfiguration?.locales ?? LOCALES,
|
|
33
|
+
// Default locale of the application for fallback
|
|
34
|
+
defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,
|
|
35
|
+
});
|
|
36
|
+
const buildMiddlewareFields = (customConfiguration) => ({
|
|
37
|
+
/**
|
|
38
|
+
* Middleware configuration
|
|
39
|
+
*/
|
|
40
|
+
// Header name to get the locale
|
|
41
|
+
headerName: customConfiguration?.headerName ?? HEADER_NAME,
|
|
42
|
+
// Cookie name to get the locale
|
|
43
|
+
cookieName: customConfiguration?.cookieName ?? COOKIE_NAME,
|
|
44
|
+
// Prefix the default locale in the URL
|
|
45
|
+
prefixDefault: customConfiguration?.prefixDefault ?? PREFIX_DEFAULT,
|
|
46
|
+
// Base path
|
|
47
|
+
basePath: customConfiguration?.basePath ?? BASE_PATH,
|
|
48
|
+
// Set cookie on server
|
|
49
|
+
serverSetCookie: customConfiguration?.serverSetCookie ?? SERVER_SET_COOKIE,
|
|
50
|
+
// No prefix
|
|
51
|
+
noPrefix: customConfiguration?.noPrefix ?? NO_PREFIX,
|
|
52
|
+
});
|
|
53
|
+
const buildContentFields = (customConfiguration) => {
|
|
54
|
+
const notDerivedContentConfig = {
|
|
55
|
+
/**
|
|
56
|
+
* Content configurations
|
|
57
|
+
*/
|
|
58
|
+
// File extensions of content to look for
|
|
59
|
+
fileExtensions: customConfiguration?.fileExtensions ?? FILE_EXTENSIONS,
|
|
60
|
+
// Directory name of the project
|
|
61
|
+
baseDir: customConfiguration?.baseDir ?? process.cwd(),
|
|
62
|
+
// Directory name where the content is stored
|
|
63
|
+
contentDirName: customConfiguration?.contentDirName ?? CONTENT_DIR_NAME,
|
|
64
|
+
// Result directory name
|
|
65
|
+
resultDirName: customConfiguration?.resultDirName ?? RESULT_DIR_NAME,
|
|
66
|
+
// Module augmentation directory name
|
|
67
|
+
moduleAugmentationDirName:
|
|
68
|
+
customConfiguration?.moduleAugmentationDirName ??
|
|
69
|
+
MODULE_AUGMENTATION_DIR_NAME,
|
|
70
|
+
// Bundle directory name
|
|
71
|
+
bundleDirName: customConfiguration?.bundleDirName ?? BUNDLE_DIR_NAME,
|
|
72
|
+
// Bundle file extension
|
|
73
|
+
bundleFileExtension:
|
|
74
|
+
customConfiguration?.bundleFileExtension ?? BUNDLE_FILE_EXTENSION,
|
|
75
|
+
// Dictionary directory name
|
|
76
|
+
dictionariesDirName:
|
|
77
|
+
customConfiguration?.dictionariesDirName ?? DICTIONARIES_DIR_NAME,
|
|
78
|
+
// Types directory name
|
|
79
|
+
typeDirName: customConfiguration?.typeDirName ?? TYPES_DIR_NAME,
|
|
80
|
+
// Main directory name
|
|
81
|
+
mainDirName: customConfiguration?.mainDirName ?? MAIN_DIR_NAME,
|
|
82
|
+
// Directories to exclude
|
|
83
|
+
excludedPath: customConfiguration?.excludedPath ?? EXCLUDED_PATHS,
|
|
84
|
+
};
|
|
85
|
+
const baseDirDerivedConfiguration = {
|
|
86
|
+
// Directory where the content is stored
|
|
87
|
+
contentDir: join(
|
|
88
|
+
notDerivedContentConfig.baseDir,
|
|
89
|
+
notDerivedContentConfig.contentDirName
|
|
90
|
+
),
|
|
91
|
+
// Directory where the result will be stored
|
|
92
|
+
resultDir: join(
|
|
93
|
+
notDerivedContentConfig.baseDir,
|
|
94
|
+
notDerivedContentConfig.resultDirName
|
|
95
|
+
),
|
|
96
|
+
// Directory where the module augmentation will be stored
|
|
97
|
+
moduleAugmentationDir: join(
|
|
98
|
+
notDerivedContentConfig.baseDir,
|
|
99
|
+
notDerivedContentConfig.moduleAugmentationDirName
|
|
100
|
+
),
|
|
101
|
+
};
|
|
102
|
+
const resultDirDerivedConfiguration = {
|
|
103
|
+
// Directory where the bundle will be stored
|
|
104
|
+
bundleDir: join(
|
|
105
|
+
baseDirDerivedConfiguration.resultDir,
|
|
106
|
+
notDerivedContentConfig.bundleDirName
|
|
107
|
+
),
|
|
108
|
+
// Directory where the dictionaries will be stored
|
|
109
|
+
dictionariesDir: join(
|
|
110
|
+
baseDirDerivedConfiguration.resultDir,
|
|
111
|
+
notDerivedContentConfig.dictionariesDirName
|
|
112
|
+
),
|
|
113
|
+
// Directory where the types will be stored
|
|
114
|
+
typesDir: join(
|
|
115
|
+
baseDirDerivedConfiguration.resultDir,
|
|
116
|
+
notDerivedContentConfig.typeDirName
|
|
117
|
+
),
|
|
118
|
+
// Directory where the main files will be stored
|
|
119
|
+
mainDir: join(
|
|
120
|
+
baseDirDerivedConfiguration.resultDir,
|
|
121
|
+
notDerivedContentConfig.mainDirName
|
|
122
|
+
),
|
|
123
|
+
};
|
|
124
|
+
const patternsConfiguration = {
|
|
125
|
+
// Pattern of files to watch
|
|
126
|
+
watchedFilesPattern: notDerivedContentConfig.fileExtensions.map(
|
|
127
|
+
(ext) => `/**/*${ext}`
|
|
128
|
+
),
|
|
129
|
+
// Pattern of files to watch including the relative path
|
|
130
|
+
watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.map(
|
|
131
|
+
(ext) => `${baseDirDerivedConfiguration.contentDir}/**/*${ext}`
|
|
132
|
+
),
|
|
133
|
+
// Pattern of files to output
|
|
134
|
+
outputFilesPatternWithPath: `${resultDirDerivedConfiguration.dictionariesDir}/**/*.json`,
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
...notDerivedContentConfig,
|
|
138
|
+
...baseDirDerivedConfiguration,
|
|
139
|
+
...resultDirDerivedConfiguration,
|
|
140
|
+
...patternsConfiguration,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const buildConfigurationFields = (options, customConfiguration) => {
|
|
144
|
+
const internationalizationConfig = buildInternationalizationFields(
|
|
145
|
+
customConfiguration?.internationalization
|
|
146
|
+
);
|
|
147
|
+
const middlewareConfig = buildMiddlewareFields(
|
|
148
|
+
customConfiguration?.middleware
|
|
149
|
+
);
|
|
150
|
+
const contentConfig = buildContentFields(customConfiguration?.content);
|
|
151
|
+
storedConfiguration = {
|
|
152
|
+
internationalization: internationalizationConfig,
|
|
153
|
+
middleware: middlewareConfig,
|
|
154
|
+
content: contentConfig,
|
|
155
|
+
};
|
|
156
|
+
return storedConfiguration;
|
|
157
|
+
};
|
|
158
|
+
export { buildConfigurationFields };
|
|
159
|
+
//# sourceMappingURL=buildConfigurationFields.mjs.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,12 @@
|
|
|
1
|
+
import { IntlayerConfig } from "../types/index.mjs";
|
|
2
|
+
import "../defaultValues/locales.mjs";
|
|
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,52 @@
|
|
|
1
|
+
import { relative } from "path";
|
|
2
|
+
import { buildConfigurationFields } from "./buildConfigurationFields.mjs";
|
|
3
|
+
import { loadConfigurationFile } from "./loadConfigurationFile.mjs";
|
|
4
|
+
import { searchConfigurationFile } from "./searchConfigurationFile.mjs";
|
|
5
|
+
let storedConfiguration;
|
|
6
|
+
let storedConfigurationFilePath;
|
|
7
|
+
let storedNumCustomConfiguration;
|
|
8
|
+
const BASE_DIR_PATH = process.env.INTLAYER_BASE_DIR_PATH ?? process.cwd();
|
|
9
|
+
const defaultOptions = {
|
|
10
|
+
baseDir: BASE_DIR_PATH,
|
|
11
|
+
verbose: false,
|
|
12
|
+
};
|
|
13
|
+
const getConfiguration = (options) => {
|
|
14
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
15
|
+
const { baseDir, verbose } = mergedOptions;
|
|
16
|
+
if (!storedConfiguration) {
|
|
17
|
+
const { configurationFilePath, numCustomConfiguration } =
|
|
18
|
+
searchConfigurationFile(baseDir);
|
|
19
|
+
let customConfiguration;
|
|
20
|
+
if (configurationFilePath) {
|
|
21
|
+
customConfiguration = loadConfigurationFile(configurationFilePath);
|
|
22
|
+
}
|
|
23
|
+
storedConfiguration = buildConfigurationFields(
|
|
24
|
+
mergedOptions,
|
|
25
|
+
customConfiguration
|
|
26
|
+
);
|
|
27
|
+
storedConfigurationFilePath = configurationFilePath;
|
|
28
|
+
storedNumCustomConfiguration = numCustomConfiguration;
|
|
29
|
+
}
|
|
30
|
+
if (verbose)
|
|
31
|
+
logConfigFileResult(
|
|
32
|
+
storedNumCustomConfiguration,
|
|
33
|
+
storedConfigurationFilePath
|
|
34
|
+
);
|
|
35
|
+
return storedConfiguration;
|
|
36
|
+
};
|
|
37
|
+
const logConfigFileResult = (numCustomConfiguration, configurationFilePath) => {
|
|
38
|
+
if (numCustomConfiguration === 0) {
|
|
39
|
+
console.info("Configuration file not found, using default configuration.");
|
|
40
|
+
} else {
|
|
41
|
+
const relativeOutputPath = relative(BASE_DIR_PATH, configurationFilePath);
|
|
42
|
+
if (numCustomConfiguration === 1) {
|
|
43
|
+
console.info(`Configuration file found: ${relativeOutputPath}.`);
|
|
44
|
+
} else {
|
|
45
|
+
console.warn(
|
|
46
|
+
`Multiple configuration files found, using ${relativeOutputPath}.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export { getConfiguration };
|
|
52
|
+
//# sourceMappingURL=getConfiguration.mjs.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,SAAS,gBAAgB;AAEzB,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AAExC,IAAI;AACJ,IAAI;AACJ,IAAI;AAOJ,MAAM,gBAAgB,QAAQ,IAAI,0BAA0B,QAAQ,IAAI;AACxE,MAAM,iBAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AACX;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,IACpD,wBAAwB,OAAO;AAGjC,QAAI;AACJ,QAAI,uBAAuB;AACzB,4BAAsB,sBAAsB,qBAAqB;AAAA,IACnE;AAGA,0BAAsB;AAAA,MACpB;AAAA,MACA;AAAA,IACF;AACA,kCAA8B;AAC9B,mCAA+B;AAAA,EACjC;AAGA,MAAI;AACF;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAEF,SAAO;AACT;AAEA,MAAM,sBAAsB,CAC1B,wBACA,0BACG;AACH,MAAI,2BAA2B,GAAG;AAChC,YAAQ,KAAK,4DAA4D;AAAA,EAC3E,OAAO;AACL,UAAM,qBAAqB,SAAS,eAAe,qBAAsB;AAEzE,QAAI,2BAA2B,GAAG;AAChC,cAAQ,KAAK,6BAA6B,kBAAkB,GAAG;AAAA,IACjE,OAAO;AACL,cAAQ;AAAA,QACN,6CAA6C,kBAAkB;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/index.ts"],"sourcesContent":["export * from './getConfiguration';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import { runInNewContext } from "vm";
|
|
3
|
+
import { buildSync } from "esbuild";
|
|
4
|
+
const isESModule = typeof import.meta.url === "string";
|
|
5
|
+
const sandboxContext = {
|
|
6
|
+
exports: {
|
|
7
|
+
default: {},
|
|
8
|
+
},
|
|
9
|
+
module: {
|
|
10
|
+
exports: {},
|
|
11
|
+
},
|
|
12
|
+
console,
|
|
13
|
+
require: isESModule ? createRequire(import.meta.url) : require,
|
|
14
|
+
};
|
|
15
|
+
const transformationOption = {
|
|
16
|
+
loader: {
|
|
17
|
+
".js": "js",
|
|
18
|
+
".jsx": "jsx",
|
|
19
|
+
".mjs": "js",
|
|
20
|
+
".ts": "ts",
|
|
21
|
+
".tsx": "tsx",
|
|
22
|
+
".cjs": "js",
|
|
23
|
+
".json": "json",
|
|
24
|
+
},
|
|
25
|
+
format: "cjs",
|
|
26
|
+
// Output format as commonjs
|
|
27
|
+
target: "es2017",
|
|
28
|
+
packages: "external",
|
|
29
|
+
write: false,
|
|
30
|
+
bundle: true,
|
|
31
|
+
};
|
|
32
|
+
const loadConfigurationFile = (configFilePath) => {
|
|
33
|
+
let customConfiguration = void 0;
|
|
34
|
+
const configFileExtension = configFilePath.split(".").pop() ?? "";
|
|
35
|
+
try {
|
|
36
|
+
if (configFileExtension === "json") {
|
|
37
|
+
return require(configFilePath);
|
|
38
|
+
}
|
|
39
|
+
const moduleResult = buildSync({
|
|
40
|
+
entryPoints: [configFilePath],
|
|
41
|
+
...transformationOption,
|
|
42
|
+
});
|
|
43
|
+
const moduleResultString = moduleResult.outputFiles?.[0].text;
|
|
44
|
+
if (!moduleResultString) {
|
|
45
|
+
console.error("Configuration file could not be loaded.");
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
runInNewContext(moduleResultString, sandboxContext);
|
|
49
|
+
if (
|
|
50
|
+
sandboxContext.exports.default &&
|
|
51
|
+
Object.keys(sandboxContext.exports.default).length > 0
|
|
52
|
+
) {
|
|
53
|
+
customConfiguration = sandboxContext.exports.default;
|
|
54
|
+
} else if (
|
|
55
|
+
sandboxContext.module.exports.defaults &&
|
|
56
|
+
Object.keys(sandboxContext.module.exports.defaults).length > 0
|
|
57
|
+
) {
|
|
58
|
+
customConfiguration = sandboxContext.module.exports.default;
|
|
59
|
+
} else if (
|
|
60
|
+
sandboxContext.module.exports.default &&
|
|
61
|
+
Object.keys(sandboxContext.module.exports.default).length > 0
|
|
62
|
+
) {
|
|
63
|
+
customConfiguration = sandboxContext.module.exports.default;
|
|
64
|
+
} else if (
|
|
65
|
+
sandboxContext.module.exports &&
|
|
66
|
+
Object.keys(sandboxContext.module.exports).length > 0
|
|
67
|
+
) {
|
|
68
|
+
customConfiguration = sandboxContext.module.exports;
|
|
69
|
+
}
|
|
70
|
+
return customConfiguration;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error("Error:", error);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export { loadConfigurationFile };
|
|
76
|
+
//# sourceMappingURL=loadConfigurationFile.mjs.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":"AACA,SAAS,qBAAqB;AAC9B,SAAuB,uBAAuB;AAC9C,SAA4B,iBAAmC;AAG/D,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS,aAAa,cAAc,YAAY,GAAG,IAAI;AACzD;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;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,eAA4B,UAAU;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,oBAAgB,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,32 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
const EXTENSION = ["ts", "js", "json", "cjs", "mjs", ""];
|
|
4
|
+
const CONFIGURATION_FILE_NAME_1 = "intlayer.config";
|
|
5
|
+
const CONFIGURATION_FILE_NAME_2 = ".intlayerrc";
|
|
6
|
+
const intLayerConfigFiles = EXTENSION.filter(
|
|
7
|
+
(extension) => extension !== ""
|
|
8
|
+
).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);
|
|
9
|
+
const configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];
|
|
10
|
+
const searchConfigurationFile = (configFilePath) => {
|
|
11
|
+
let configurationFilePath = void 0;
|
|
12
|
+
let numCustomConfiguration = 0;
|
|
13
|
+
for (const fileName of configurationFiles) {
|
|
14
|
+
try {
|
|
15
|
+
const filePath = resolve(configFilePath, fileName);
|
|
16
|
+
if (!existsSync(filePath)) {
|
|
17
|
+
continue;
|
|
18
|
+
} else {
|
|
19
|
+
numCustomConfiguration += 1;
|
|
20
|
+
if (!configurationFilePath) {
|
|
21
|
+
configurationFilePath = filePath;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error(`${fileName}: ${error}`);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { configurationFilePath, numCustomConfiguration };
|
|
30
|
+
};
|
|
31
|
+
export { searchConfigurationFile };
|
|
32
|
+
//# sourceMappingURL=searchConfigurationFile.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/configFile/searchConfigurationFile.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { resolve } from 'path';\n\nconst EXTENSION = ['ts', 'js', 'json', 'cjs', 'mjs', ''];\nconst CONFIGURATION_FILE_NAME_1 = 'intlayer.config';\nconst CONFIGURATION_FILE_NAME_2 = '.intlayerrc';\n\nconst intLayerConfigFiles = EXTENSION.filter(\n (extension) => extension !== ''\n).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);\n\nconst configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];\n\ntype SearchConfigurationFileResult = {\n configurationFilePath?: string;\n numCustomConfiguration: number;\n};\n\nexport const searchConfigurationFile = (\n configFilePath: string\n): SearchConfigurationFileResult => {\n let configurationFilePath: string | undefined = undefined;\n let numCustomConfiguration = 0;\n\n for (const fileName of configurationFiles) {\n try {\n const filePath = resolve(configFilePath, fileName);\n\n // Check if the file exists\n if (!existsSync(filePath)) {\n continue;\n } else {\n numCustomConfiguration += 1;\n\n if (!configurationFilePath) {\n configurationFilePath = filePath;\n }\n }\n } catch (error) {\n // Return \"Cannot use import statement outside a module\"\n console.error(`${fileName}: ${error as string}`);\n\n continue;\n }\n }\n\n return { configurationFilePath, numCustomConfiguration };\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAExB,MAAM,YAAY,CAAC,MAAM,MAAM,QAAQ,OAAO,OAAO,EAAE;AACvD,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAElC,MAAM,sBAAsB,UAAU;AAAA,EACpC,CAAC,cAAc,cAAc;AAC/B,EAAE,IAAI,CAAC,QAAQ,GAAG,yBAAyB,IAAI,GAAG,EAAE;AAEpD,MAAM,qBAAqB,CAAC,GAAG,qBAAqB,yBAAyB;AAOtE,MAAM,0BAA0B,CACrC,mBACkC;AAClC,MAAI,wBAA4C;AAChD,MAAI,yBAAyB;AAE7B,aAAW,YAAY,oBAAoB;AACzC,QAAI;AACF,YAAM,WAAW,QAAQ,gBAAgB,QAAQ;AAGjD,UAAI,CAAC,WAAW,QAAQ,GAAG;AACzB;AAAA,MACF,OAAO;AACL,kCAA0B;AAE1B,YAAI,CAAC,uBAAuB;AAC1B,kCAAwB;AAAA,QAC1B;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AAEd,cAAQ,MAAM,GAAG,QAAQ,KAAK,KAAe,EAAE;AAE/C;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,uBAAuB,uBAAuB;AACzD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/defaultValues/internationalization.ts"],"sourcesContent":["import { Locales } from './locales';\n\nexport const LOCALES: Locales[] = [\n Locales.ENGLISH,\n Locales.FRENCH,\n Locales.SPANISH,\n];\n\nexport const DEFAULT_LOCALE = Locales.ENGLISH;\n"],"mappings":"AAAA,SAAS,eAAe;AAEjB,MAAM,UAAqB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AACV;AAEO,MAAM,iBAAiB,QAAQ;","names":[]}
|