@intlayer/config 8.4.10 → 8.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/built.browser.cjs +21 -0
- package/dist/cjs/built.browser.cjs.map +1 -0
- package/dist/cjs/client.cjs +7 -0
- package/dist/cjs/configFile/buildBrowserConfiguration.cjs +170 -0
- package/dist/cjs/configFile/buildBrowserConfiguration.cjs.map +1 -0
- package/dist/cjs/configFile/buildConfigurationFields.cjs +79 -53
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
- package/dist/cjs/configFile/index.cjs +7 -0
- package/dist/cjs/defaultValues/index.cjs +1 -1
- package/dist/cjs/node.cjs +7 -0
- package/dist/cjs/utils/alias.cjs +1 -1
- package/dist/cjs/utils/alias.cjs.map +1 -1
- package/dist/cjs/utils/cacheDisk.cjs +2 -2
- package/dist/esm/built.browser.mjs +20 -0
- package/dist/esm/built.browser.mjs.map +1 -0
- package/dist/esm/client.mjs +2 -1
- package/dist/esm/configFile/buildBrowserConfiguration.mjs +162 -0
- package/dist/esm/configFile/buildBrowserConfiguration.mjs.map +1 -0
- package/dist/esm/configFile/buildConfigurationFields.mjs +73 -52
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
- package/dist/esm/configFile/index.mjs +2 -1
- package/dist/esm/defaultValues/index.mjs +1 -1
- package/dist/esm/node.mjs +2 -1
- package/dist/esm/utils/alias.mjs +1 -1
- package/dist/esm/utils/alias.mjs.map +1 -1
- package/dist/esm/utils/cacheDisk.mjs +1 -1
- package/dist/types/built.browser.d.ts +13 -0
- package/dist/types/built.browser.d.ts.map +1 -0
- package/dist/types/client.d.ts +2 -1
- package/dist/types/configFile/buildBrowserConfiguration.d.ts +94 -0
- package/dist/types/configFile/buildBrowserConfiguration.d.ts.map +1 -0
- package/dist/types/configFile/buildConfigurationFields.d.ts +18 -2
- package/dist/types/configFile/buildConfigurationFields.d.ts.map +1 -1
- package/dist/types/configFile/index.d.ts +2 -1
- package/dist/types/node.d.ts +2 -1
- package/package.json +3 -2
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_configFile_buildBrowserConfiguration = require('./buildBrowserConfiguration.cjs');
|
|
2
3
|
const require_configFile_configurationSchema = require('./configurationSchema.cjs');
|
|
3
4
|
const require_configFile_buildConfigurationFields = require('./buildConfigurationFields.cjs');
|
|
4
5
|
const require_configFile_searchConfigurationFile = require('./searchConfigurationFile.cjs');
|
|
5
6
|
const require_configFile_getConfiguration = require('./getConfiguration.cjs');
|
|
6
7
|
|
|
7
8
|
exports.aiSchema = require_configFile_configurationSchema.aiSchema;
|
|
9
|
+
exports.buildBrowserConfiguration = require_configFile_buildBrowserConfiguration.buildBrowserConfiguration;
|
|
8
10
|
exports.buildConfigurationFields = require_configFile_buildConfigurationFields.buildConfigurationFields;
|
|
11
|
+
exports.buildEditorFields = require_configFile_buildBrowserConfiguration.buildEditorFields;
|
|
12
|
+
exports.buildInternationalizationFields = require_configFile_buildBrowserConfiguration.buildInternationalizationFields;
|
|
13
|
+
exports.buildLogFields = require_configFile_buildBrowserConfiguration.buildLogFields;
|
|
14
|
+
exports.buildRoutingFields = require_configFile_buildBrowserConfiguration.buildRoutingFields;
|
|
9
15
|
exports.buildSchema = require_configFile_configurationSchema.buildSchema;
|
|
10
16
|
exports.compilerSchema = require_configFile_configurationSchema.compilerSchema;
|
|
11
17
|
exports.configurationFilesCandidates = require_configFile_searchConfigurationFile.configurationFilesCandidates;
|
|
@@ -13,6 +19,7 @@ exports.contentSchema = require_configFile_configurationSchema.contentSchema;
|
|
|
13
19
|
exports.cookiesAttributesSchema = require_configFile_configurationSchema.cookiesAttributesSchema;
|
|
14
20
|
exports.dictionarySchema = require_configFile_configurationSchema.dictionarySchema;
|
|
15
21
|
exports.editorSchema = require_configFile_configurationSchema.editorSchema;
|
|
22
|
+
exports.extractBrowserConfiguration = require_configFile_buildBrowserConfiguration.extractBrowserConfiguration;
|
|
16
23
|
exports.getConfiguration = require_configFile_getConfiguration.getConfiguration;
|
|
17
24
|
exports.getConfigurationAndFilePath = require_configFile_getConfiguration.getConfigurationAndFilePath;
|
|
18
25
|
exports.internationalizationSchema = require_configFile_configurationSchema.internationalizationSchema;
|
|
@@ -3,11 +3,11 @@ const require_defaultValues_build = require('./build.cjs');
|
|
|
3
3
|
const require_defaultValues_compiler = require('./compiler.cjs');
|
|
4
4
|
const require_defaultValues_content = require('./content.cjs');
|
|
5
5
|
const require_defaultValues_dictionary = require('./dictionary.cjs');
|
|
6
|
+
const require_defaultValues_system = require('./system.cjs');
|
|
6
7
|
const require_defaultValues_editor = require('./editor.cjs');
|
|
7
8
|
const require_defaultValues_internationalization = require('./internationalization.cjs');
|
|
8
9
|
const require_defaultValues_log = require('./log.cjs');
|
|
9
10
|
const require_defaultValues_routing = require('./routing.cjs');
|
|
10
|
-
const require_defaultValues_system = require('./system.cjs');
|
|
11
11
|
|
|
12
12
|
exports.APPLICATION_URL = require_defaultValues_editor.APPLICATION_URL;
|
|
13
13
|
exports.BACKEND_URL = require_defaultValues_editor.BACKEND_URL;
|
package/dist/cjs/node.cjs
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_configFile_buildBrowserConfiguration = require('./configFile/buildBrowserConfiguration.cjs');
|
|
2
3
|
const require_configFile_configurationSchema = require('./configFile/configurationSchema.cjs');
|
|
3
4
|
const require_configFile_buildConfigurationFields = require('./configFile/buildConfigurationFields.cjs');
|
|
4
5
|
const require_configFile_searchConfigurationFile = require('./configFile/searchConfigurationFile.cjs');
|
|
5
6
|
const require_configFile_getConfiguration = require('./configFile/getConfiguration.cjs');
|
|
6
7
|
|
|
7
8
|
exports.aiSchema = require_configFile_configurationSchema.aiSchema;
|
|
9
|
+
exports.buildBrowserConfiguration = require_configFile_buildBrowserConfiguration.buildBrowserConfiguration;
|
|
8
10
|
exports.buildConfigurationFields = require_configFile_buildConfigurationFields.buildConfigurationFields;
|
|
11
|
+
exports.buildEditorFields = require_configFile_buildBrowserConfiguration.buildEditorFields;
|
|
12
|
+
exports.buildInternationalizationFields = require_configFile_buildBrowserConfiguration.buildInternationalizationFields;
|
|
13
|
+
exports.buildLogFields = require_configFile_buildBrowserConfiguration.buildLogFields;
|
|
14
|
+
exports.buildRoutingFields = require_configFile_buildBrowserConfiguration.buildRoutingFields;
|
|
9
15
|
exports.buildSchema = require_configFile_configurationSchema.buildSchema;
|
|
10
16
|
exports.compilerSchema = require_configFile_configurationSchema.compilerSchema;
|
|
11
17
|
exports.configurationFilesCandidates = require_configFile_searchConfigurationFile.configurationFilesCandidates;
|
|
@@ -13,6 +19,7 @@ exports.contentSchema = require_configFile_configurationSchema.contentSchema;
|
|
|
13
19
|
exports.cookiesAttributesSchema = require_configFile_configurationSchema.cookiesAttributesSchema;
|
|
14
20
|
exports.dictionarySchema = require_configFile_configurationSchema.dictionarySchema;
|
|
15
21
|
exports.editorSchema = require_configFile_configurationSchema.editorSchema;
|
|
22
|
+
exports.extractBrowserConfiguration = require_configFile_buildBrowserConfiguration.extractBrowserConfiguration;
|
|
16
23
|
exports.getConfiguration = require_configFile_getConfiguration.getConfiguration;
|
|
17
24
|
exports.getConfigurationAndFilePath = require_configFile_getConfiguration.getConfigurationAndFilePath;
|
|
18
25
|
exports.internationalizationSchema = require_configFile_configurationSchema.internationalizationSchema;
|
package/dist/cjs/utils/alias.cjs
CHANGED
|
@@ -14,7 +14,7 @@ const getAlias = ({ configuration, format, formatter = (value) => value }) => {
|
|
|
14
14
|
const fixedRemoteDictionariesPath = formatter(require_utils_normalizePath.normalizePath((0, node_path.relative)(baseDir, (0, node_path.join)(mainDir, `remote_dictionaries.${extension}`))));
|
|
15
15
|
const fixedDynamicDictionariesPath = formatter(require_utils_normalizePath.normalizePath((0, node_path.relative)(baseDir, (0, node_path.join)(mainDir, `dynamic_dictionaries.${extension}`))));
|
|
16
16
|
const fixedFetchDictionariesPath = formatter(require_utils_normalizePath.normalizePath((0, node_path.relative)(baseDir, (0, node_path.join)(mainDir, `fetch_dictionaries.${extension}`))));
|
|
17
|
-
const fixedConfigurationPath = formatter(require_utils_normalizePath.normalizePath((0, node_path.relative)(baseDir, (0, node_path.join)(configDir, `configuration
|
|
17
|
+
const fixedConfigurationPath = formatter(require_utils_normalizePath.normalizePath((0, node_path.relative)(baseDir, (0, node_path.join)(configDir, `configuration.${extension}`))));
|
|
18
18
|
return {
|
|
19
19
|
"@intlayer/dictionaries-entry": fixedDictionariesPath,
|
|
20
20
|
"@intlayer/unmerged-dictionaries-entry": fixedUnmergedDictionariesPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alias.cjs","names":["getExtension","normalizePath"],"sources":["../../../src/utils/alias.ts"],"sourcesContent":["import { join, relative } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getExtension } from './getExtension';\nimport { normalizePath } from './normalizePath';\n\nexport type GetAliasOptions = {\n configuration: IntlayerConfig;\n format?: 'esm' | 'cjs';\n formatter?: (value: string) => string;\n};\n\nexport const getAlias = ({\n configuration,\n format,\n formatter = (value: string) => value,\n}: GetAliasOptions) => {\n const extension = getExtension(\n configuration,\n format ?? configuration.build.outputFormat[0] ?? 'esm'\n );\n\n const { baseDir } = configuration.system;\n const { mainDir, configDir } = configuration.system;\n\n /**\n * Dictionaries\n */\n const dictionariesPath = join(mainDir, `dictionaries.${extension}`);\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n const fixedDictionariesPath = formatter(\n normalizePath(relativeDictionariesPath)\n );\n\n /**\n * Unmerged dictionaries\n */\n const unmergedDictionariesPath = join(\n mainDir,\n `unmerged_dictionaries.${extension}`\n );\n const relativeUnmergedDictionariesPath = relative(\n baseDir,\n unmergedDictionariesPath\n );\n const fixedUnmergedDictionariesPath = formatter(\n normalizePath(relativeUnmergedDictionariesPath)\n );\n\n /**\n * Remote dictionaries\n */\n const remoteDictionariesPath = join(\n mainDir,\n `remote_dictionaries.${extension}`\n );\n const relativeRemoteDictionariesPath = relative(\n baseDir,\n remoteDictionariesPath\n );\n const fixedRemoteDictionariesPath = formatter(\n normalizePath(relativeRemoteDictionariesPath)\n );\n\n /**\n * Dynamic dictionaries\n */\n const dynamicDictionariesPath = join(\n mainDir,\n `dynamic_dictionaries.${extension}`\n );\n const relativeDynamicDictionariesPath = relative(\n baseDir,\n dynamicDictionariesPath\n );\n const fixedDynamicDictionariesPath = formatter(\n normalizePath(relativeDynamicDictionariesPath)\n );\n\n /**\n * Fetch dictionaries\n */\n const fetchDictionariesPath = join(\n mainDir,\n `fetch_dictionaries.${extension}`\n );\n const relativeFetchDictionariesPath = relative(\n baseDir,\n fetchDictionariesPath\n );\n const fixedFetchDictionariesPath = formatter(\n normalizePath(relativeFetchDictionariesPath)\n );\n\n /**\n * Configuration\n */\n const configurationPath = join(configDir, `configuration
|
|
1
|
+
{"version":3,"file":"alias.cjs","names":["getExtension","normalizePath"],"sources":["../../../src/utils/alias.ts"],"sourcesContent":["import { join, relative } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getExtension } from './getExtension';\nimport { normalizePath } from './normalizePath';\n\nexport type GetAliasOptions = {\n configuration: IntlayerConfig;\n format?: 'esm' | 'cjs';\n formatter?: (value: string) => string;\n};\n\nexport const getAlias = ({\n configuration,\n format,\n formatter = (value: string) => value,\n}: GetAliasOptions) => {\n const extension = getExtension(\n configuration,\n format ?? configuration.build.outputFormat[0] ?? 'esm'\n );\n\n const { baseDir } = configuration.system;\n const { mainDir, configDir } = configuration.system;\n\n /**\n * Dictionaries\n */\n const dictionariesPath = join(mainDir, `dictionaries.${extension}`);\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n const fixedDictionariesPath = formatter(\n normalizePath(relativeDictionariesPath)\n );\n\n /**\n * Unmerged dictionaries\n */\n const unmergedDictionariesPath = join(\n mainDir,\n `unmerged_dictionaries.${extension}`\n );\n const relativeUnmergedDictionariesPath = relative(\n baseDir,\n unmergedDictionariesPath\n );\n const fixedUnmergedDictionariesPath = formatter(\n normalizePath(relativeUnmergedDictionariesPath)\n );\n\n /**\n * Remote dictionaries\n */\n const remoteDictionariesPath = join(\n mainDir,\n `remote_dictionaries.${extension}`\n );\n const relativeRemoteDictionariesPath = relative(\n baseDir,\n remoteDictionariesPath\n );\n const fixedRemoteDictionariesPath = formatter(\n normalizePath(relativeRemoteDictionariesPath)\n );\n\n /**\n * Dynamic dictionaries\n */\n const dynamicDictionariesPath = join(\n mainDir,\n `dynamic_dictionaries.${extension}`\n );\n const relativeDynamicDictionariesPath = relative(\n baseDir,\n dynamicDictionariesPath\n );\n const fixedDynamicDictionariesPath = formatter(\n normalizePath(relativeDynamicDictionariesPath)\n );\n\n /**\n * Fetch dictionaries\n */\n const fetchDictionariesPath = join(\n mainDir,\n `fetch_dictionaries.${extension}`\n );\n const relativeFetchDictionariesPath = relative(\n baseDir,\n fetchDictionariesPath\n );\n const fixedFetchDictionariesPath = formatter(\n normalizePath(relativeFetchDictionariesPath)\n );\n\n /**\n * Configuration\n */\n const configurationPath = join(configDir, `configuration.${extension}`);\n const relativeConfigurationPath = relative(baseDir, configurationPath);\n const fixedConfigurationPath = formatter(\n normalizePath(relativeConfigurationPath)\n );\n\n return {\n '@intlayer/dictionaries-entry': fixedDictionariesPath,\n '@intlayer/unmerged-dictionaries-entry': fixedUnmergedDictionariesPath,\n '@intlayer/remote-dictionaries-entry': fixedRemoteDictionariesPath,\n '@intlayer/dynamic-dictionaries-entry': fixedDynamicDictionariesPath,\n '@intlayer/fetch-dictionaries-entry': fixedFetchDictionariesPath,\n '@intlayer/config/built': fixedConfigurationPath,\n } as const;\n};\n"],"mappings":";;;;;;;AAWA,MAAa,YAAY,EACvB,eACA,QACA,aAAa,UAAkB,YACV;CACrB,MAAM,YAAYA,wCAChB,eACA,UAAU,cAAc,MAAM,aAAa,MAAM,MAClD;CAED,MAAM,EAAE,YAAY,cAAc;CAClC,MAAM,EAAE,SAAS,cAAc,cAAc;CAO7C,MAAM,wBAAwB,UAC5BC,kEAFwC,6BADZ,SAAS,gBAAgB,YAAY,CACC,CAE3B,CACxC;CAaD,MAAM,gCAAgC,UACpCA,kEAJA,6BAJA,SACA,yBAAyB,YAC1B,CAIA,CAEgD,CAChD;CAaD,MAAM,8BAA8B,UAClCA,kEAJA,6BAJA,SACA,uBAAuB,YACxB,CAIA,CAE8C,CAC9C;CAaD,MAAM,+BAA+B,UACnCA,kEAJA,6BAJA,SACA,wBAAwB,YACzB,CAIA,CAE+C,CAC/C;CAaD,MAAM,6BAA6B,UACjCA,kEAJA,6BAJA,SACA,sBAAsB,YACvB,CAIA,CAE6C,CAC7C;CAOD,MAAM,yBAAyB,UAC7BA,kEAFyC,6BADZ,WAAW,iBAAiB,YAAY,CACD,CAE5B,CACzC;AAED,QAAO;EACL,gCAAgC;EAChC,yCAAyC;EACzC,uCAAuC;EACvC,wCAAwC;EACxC,sCAAsC;EACtC,0BAA0B;EAC3B"}
|
|
@@ -2,11 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_utils_cacheMemory = require('./cacheMemory.cjs');
|
|
4
4
|
let node_path = require("node:path");
|
|
5
|
-
let _intlayer_types_package_json = require("@intlayer/types/package.json");
|
|
6
|
-
_intlayer_types_package_json = require_runtime.__toESM(_intlayer_types_package_json);
|
|
7
5
|
let node_fs_promises = require("node:fs/promises");
|
|
8
6
|
let node_v8 = require("node:v8");
|
|
9
7
|
let node_zlib = require("node:zlib");
|
|
8
|
+
let _intlayer_types_package_json = require("@intlayer/types/package.json");
|
|
9
|
+
_intlayer_types_package_json = require_runtime.__toESM(_intlayer_types_package_json);
|
|
10
10
|
|
|
11
11
|
//#region src/utils/cacheDisk.ts
|
|
12
12
|
const DEFAULTS = { compress: true };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/built.browser.ts
|
|
2
|
+
/**
|
|
3
|
+
* Proxy that reads each top-level key from `window.INTLAYER_CONFIG` lazily.
|
|
4
|
+
* This avoids the module-evaluation timing issue: the proxy is safe to import
|
|
5
|
+
* at the top of any file because the actual `window.INTLAYER_CONFIG` value is
|
|
6
|
+
* only read when a property is first accessed.
|
|
7
|
+
*/
|
|
8
|
+
const configuration = new Proxy({}, {
|
|
9
|
+
get(_target, prop) {
|
|
10
|
+
return (typeof window !== "undefined" ? window.INTLAYER_CONFIG : void 0)?.[prop];
|
|
11
|
+
},
|
|
12
|
+
has(_target, prop) {
|
|
13
|
+
const config = typeof window !== "undefined" ? window.INTLAYER_CONFIG : void 0;
|
|
14
|
+
return config != null && prop in config;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { configuration as default };
|
|
20
|
+
//# sourceMappingURL=built.browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"built.browser.mjs","names":[],"sources":["../../src/built.browser.ts"],"sourcesContent":["/**\n * @intlayer/config/built — browser build\n *\n * In browser bundles this module is selected automatically via the `browser`\n * export condition in package.json (supported by Vite, webpack, Rollup, etc.).\n *\n * Configuration is resolved at *access time* (lazy) from `window.INTLAYER_CONFIG`\n * so that it works both when:\n *\n * - A build plugin (vite-intlayer / withIntlayer) injects the value via\n * bundler `define` (static replacement at build time), OR\n * - The application calls `installIntlayer(config)` at runtime before any\n * config field is first accessed.\n */\nimport type { IntlayerConfig } from '@intlayer/types/config';\n// This import brings in the `declare global { interface Window { INTLAYER_CONFIG } }` augmentation\nimport type {} from './configFile/buildBrowserConfiguration';\n\n/**\n * Proxy that reads each top-level key from `window.INTLAYER_CONFIG` lazily.\n * This avoids the module-evaluation timing issue: the proxy is safe to import\n * at the top of any file because the actual `window.INTLAYER_CONFIG` value is\n * only read when a property is first accessed.\n */\nconst configuration = new Proxy({} as IntlayerConfig, {\n get(_target, prop: string) {\n const config =\n typeof window !== 'undefined' ? window.INTLAYER_CONFIG : undefined;\n return (config as Record<string, unknown> | undefined)?.[prop];\n },\n has(_target, prop: string) {\n const config =\n typeof window !== 'undefined' ? window.INTLAYER_CONFIG : undefined;\n return config != null && prop in config;\n },\n});\n\nexport default configuration;\n"],"mappings":";;;;;;;AAwBA,MAAM,gBAAgB,IAAI,MAAM,EAAE,EAAoB;CACpD,IAAI,SAAS,MAAc;AAGzB,UADE,OAAO,WAAW,cAAc,OAAO,kBAAkB,UACF;;CAE3D,IAAI,SAAS,MAAc;EACzB,MAAM,SACJ,OAAO,WAAW,cAAc,OAAO,kBAAkB;AAC3D,SAAO,UAAU,QAAQ,QAAQ;;CAEpC,CAAC"}
|
package/dist/esm/client.mjs
CHANGED
|
@@ -5,5 +5,6 @@ import { camelCaseToKebabCase } from "./utils/stringFormatter/camelCaseToKebabCa
|
|
|
5
5
|
import { camelCaseToSentence } from "./utils/stringFormatter/camelCaseToSentence.mjs";
|
|
6
6
|
import { kebabCaseToCamelCase } from "./utils/stringFormatter/kebabCaseToCamelCase.mjs";
|
|
7
7
|
import { toLowerCamelCase } from "./utils/stringFormatter/toLowerCamelCase.mjs";
|
|
8
|
+
import { buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration } from "./configFile/buildBrowserConfiguration.mjs";
|
|
8
9
|
|
|
9
|
-
export { camelCaseToKebabCase, camelCaseToSentence, extractErrorMessage, kebabCaseToCamelCase, logStack, normalizePath, toLowerCamelCase };
|
|
10
|
+
export { buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, camelCaseToKebabCase, camelCaseToSentence, extractBrowserConfiguration, extractErrorMessage, kebabCaseToCamelCase, logStack, normalizePath, toLowerCamelCase };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { APPLICATION_URL, BACKEND_URL, CMS_URL, DICTIONARY_PRIORITY_STRATEGY, EDITOR_URL, IS_ENABLED, LIVE_SYNC, LIVE_SYNC_PORT, PORT } from "../defaultValues/editor.mjs";
|
|
2
|
+
import { DEFAULT_LOCALE, LOCALES, REQUIRED_LOCALES, STRICT_MODE } from "../defaultValues/internationalization.mjs";
|
|
3
|
+
import { MODE, PREFIX } from "../defaultValues/log.mjs";
|
|
4
|
+
import { BASE_PATH, ROUTING_MODE, STORAGE } from "../defaultValues/routing.mjs";
|
|
5
|
+
import packageJson from "@intlayer/types/package.json" with { type: "json" };
|
|
6
|
+
|
|
7
|
+
//#region src/configFile/buildBrowserConfiguration.ts
|
|
8
|
+
/**
|
|
9
|
+
* Build the internationalization section of the Intlayer configuration.
|
|
10
|
+
*
|
|
11
|
+
* @param customConfiguration - Partial user-supplied internationalization config.
|
|
12
|
+
* @returns A fully-defaulted {@link InternationalizationConfig}.
|
|
13
|
+
*/
|
|
14
|
+
const buildInternationalizationFields = (customConfiguration) => ({
|
|
15
|
+
locales: customConfiguration?.locales ?? LOCALES,
|
|
16
|
+
requiredLocales: customConfiguration?.requiredLocales ?? customConfiguration?.locales ?? REQUIRED_LOCALES,
|
|
17
|
+
strictMode: customConfiguration?.strictMode ?? "inclusive",
|
|
18
|
+
defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Build the routing section of the Intlayer configuration.
|
|
22
|
+
*
|
|
23
|
+
* @param customConfiguration - Partial user-supplied routing config.
|
|
24
|
+
* @returns A fully-defaulted {@link RoutingConfig}.
|
|
25
|
+
*/
|
|
26
|
+
const buildRoutingFields = (customConfiguration) => ({
|
|
27
|
+
mode: customConfiguration?.mode ?? "prefix-no-default",
|
|
28
|
+
storage: customConfiguration?.storage ?? STORAGE,
|
|
29
|
+
basePath: customConfiguration?.basePath ?? "",
|
|
30
|
+
rewrite: customConfiguration?.rewrite
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Build the editor section of the Intlayer configuration.
|
|
34
|
+
*
|
|
35
|
+
* Returns the **full** {@link EditorConfig} including sensitive fields
|
|
36
|
+
* (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}
|
|
37
|
+
* omits those fields when exposing config to the client.
|
|
38
|
+
*
|
|
39
|
+
* @param customConfiguration - Partial user-supplied editor config.
|
|
40
|
+
* @returns A fully-defaulted {@link EditorConfig}.
|
|
41
|
+
*/
|
|
42
|
+
const buildEditorFields = (customConfiguration) => {
|
|
43
|
+
const liveSyncPort = customConfiguration?.liveSyncPort ?? 4e3;
|
|
44
|
+
return {
|
|
45
|
+
applicationURL: customConfiguration?.applicationURL || void 0,
|
|
46
|
+
editorURL: customConfiguration?.editorURL || "http://localhost:8000",
|
|
47
|
+
cmsURL: customConfiguration?.cmsURL || "https://app.intlayer.org",
|
|
48
|
+
backendURL: customConfiguration?.backendURL || "https://back.intlayer.org",
|
|
49
|
+
port: customConfiguration?.port ?? 8e3,
|
|
50
|
+
enabled: customConfiguration?.enabled ?? false,
|
|
51
|
+
clientId: customConfiguration?.clientId ?? void 0,
|
|
52
|
+
clientSecret: customConfiguration?.clientSecret ?? void 0,
|
|
53
|
+
dictionaryPriorityStrategy: customConfiguration?.dictionaryPriorityStrategy ?? "local_first",
|
|
54
|
+
liveSync: customConfiguration?.liveSync ?? true,
|
|
55
|
+
liveSyncPort,
|
|
56
|
+
liveSyncURL: customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Build the log section of the Intlayer configuration.
|
|
61
|
+
*
|
|
62
|
+
* @param customConfiguration - Partial user-supplied log config.
|
|
63
|
+
* @param logFunctions - Optional custom log function overrides (server-only).
|
|
64
|
+
* @returns A fully-defaulted {@link LogConfig}.
|
|
65
|
+
*/
|
|
66
|
+
const buildLogFields = (customConfiguration, logFunctions) => ({
|
|
67
|
+
mode: customConfiguration?.mode ?? "default",
|
|
68
|
+
prefix: customConfiguration?.prefix ?? PREFIX,
|
|
69
|
+
error: logFunctions?.error,
|
|
70
|
+
log: logFunctions?.log,
|
|
71
|
+
info: logFunctions?.info,
|
|
72
|
+
warn: logFunctions?.warn
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.
|
|
76
|
+
*
|
|
77
|
+
* Applies defaults for every field and strips all server-only or sensitive
|
|
78
|
+
* information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,
|
|
79
|
+
* `editor.clientId`, `editor.clientSecret`).
|
|
80
|
+
*
|
|
81
|
+
* This is the browser counterpart of `buildConfigurationFields`. It is safe
|
|
82
|
+
* to call in browser environments because it has no Node.js dependencies.
|
|
83
|
+
*
|
|
84
|
+
* @param customConfig - Optional partial user-supplied Intlayer config.
|
|
85
|
+
* @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { buildBrowserConfiguration } from '@intlayer/config/client';
|
|
90
|
+
*
|
|
91
|
+
* window.INTLAYER_CONFIG = buildBrowserConfiguration({
|
|
92
|
+
* internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
const buildBrowserConfiguration = (customConfig) => {
|
|
97
|
+
const { locales, defaultLocale } = buildInternationalizationFields(customConfig?.internationalization);
|
|
98
|
+
const routing = buildRoutingFields(customConfig?.routing);
|
|
99
|
+
const { clientId: _clientId, clientSecret: _clientSecret, ...editorPublic } = buildEditorFields(customConfig?.editor);
|
|
100
|
+
const { mode, prefix } = buildLogFields(customConfig?.log);
|
|
101
|
+
return {
|
|
102
|
+
internationalization: {
|
|
103
|
+
locales,
|
|
104
|
+
defaultLocale
|
|
105
|
+
},
|
|
106
|
+
routing,
|
|
107
|
+
editor: editorPublic,
|
|
108
|
+
log: {
|
|
109
|
+
mode,
|
|
110
|
+
prefix
|
|
111
|
+
},
|
|
112
|
+
metadata: {
|
|
113
|
+
name: "Intlayer",
|
|
114
|
+
version: packageJson.version,
|
|
115
|
+
doc: "https://intlayer.org/docs"
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Extract a {@link BrowserIntlayerConfig} from an already-built full
|
|
121
|
+
* {@link IntlayerConfig}.
|
|
122
|
+
*
|
|
123
|
+
* Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold
|
|
124
|
+
* the full server-side config and need to inject the browser-safe subset at
|
|
125
|
+
* compile time via a bundler `define`.
|
|
126
|
+
*
|
|
127
|
+
* @param config - A fully-built server-side Intlayer configuration.
|
|
128
|
+
* @returns The browser-safe subset of that configuration.
|
|
129
|
+
*/
|
|
130
|
+
const extractBrowserConfiguration = (config) => ({
|
|
131
|
+
internationalization: {
|
|
132
|
+
locales: config.internationalization.locales,
|
|
133
|
+
defaultLocale: config.internationalization.defaultLocale
|
|
134
|
+
},
|
|
135
|
+
routing: {
|
|
136
|
+
mode: config.routing.mode,
|
|
137
|
+
storage: config.routing.storage,
|
|
138
|
+
basePath: config.routing.basePath,
|
|
139
|
+
rewrite: config.routing.rewrite
|
|
140
|
+
},
|
|
141
|
+
editor: {
|
|
142
|
+
applicationURL: config.editor.applicationURL,
|
|
143
|
+
editorURL: config.editor.editorURL,
|
|
144
|
+
cmsURL: config.editor.cmsURL,
|
|
145
|
+
backendURL: config.editor.backendURL,
|
|
146
|
+
port: config.editor.port,
|
|
147
|
+
enabled: config.editor.enabled,
|
|
148
|
+
dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,
|
|
149
|
+
liveSync: config.editor.liveSync,
|
|
150
|
+
liveSyncPort: config.editor.liveSyncPort,
|
|
151
|
+
liveSyncURL: config.editor.liveSyncURL
|
|
152
|
+
},
|
|
153
|
+
log: {
|
|
154
|
+
mode: config.log.mode,
|
|
155
|
+
prefix: config.log.prefix
|
|
156
|
+
},
|
|
157
|
+
metadata: config.metadata
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
export { buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration };
|
|
162
|
+
//# sourceMappingURL=buildBrowserConfiguration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildBrowserConfiguration.mjs","names":[],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n EditorConfig,\n InternationalizationConfig,\n IntlayerConfig,\n LogConfig,\n LogFunctions,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport packageJson from '@intlayer/types/package.json' with { type: 'json' };\nimport {\n APPLICATION_URL,\n BACKEND_URL,\n CMS_URL,\n DICTIONARY_PRIORITY_STRATEGY,\n EDITOR_URL,\n IS_ENABLED,\n LIVE_SYNC,\n LIVE_SYNC_PORT,\n PORT,\n} from '../defaultValues/editor';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n REQUIRED_LOCALES,\n STRICT_MODE,\n} from '../defaultValues/internationalization';\nimport { MODE, PREFIX } from '../defaultValues/log';\nimport { BASE_PATH, ROUTING_MODE, STORAGE } from '../defaultValues/routing';\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * Browser-safe subset of {@link IntlayerConfig}.\n *\n * Excludes server-only fields (`system`, `content`, `build`, `compiler`,\n * `dictionary`, `ai`) and sensitive editor credentials (`clientId`,\n * `clientSecret`) that must never be shipped to the browser.\n */\nexport type BrowserIntlayerConfig = {\n internationalization: Pick<\n InternationalizationConfig,\n 'locales' | 'defaultLocale'\n >;\n routing: RoutingConfig;\n editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;\n log: Pick<LogConfig, 'mode' | 'prefix'>;\n metadata: IntlayerConfig['metadata'];\n};\n\ndeclare global {\n interface Window {\n /** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */\n INTLAYER_CONFIG?: BrowserIntlayerConfig;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared field builders (browser-safe — no Node.js APIs)\n//\n// These functions are re-used by both `buildBrowserConfiguration` (browser)\n// and `buildConfigurationFields` (server) to avoid duplication.\n// ---------------------------------------------------------------------------\n\n/**\n * Build the internationalization section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied internationalization config.\n * @returns A fully-defaulted {@link InternationalizationConfig}.\n */\nexport const buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.\n *\n * Default: []\n *\n * If empty, all locales are required in `strict` mode.\n *\n * Ensure required locales are also defined in the `locales` field.\n */\n requiredLocales:\n customConfiguration?.requiredLocales ??\n customConfiguration?.locales ??\n REQUIRED_LOCALES,\n\n /**\n * Ensure strong implementations of internationalized content using typescript.\n * - If set to \"strict\", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.\n * - If set to \"inclusive\", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.\n * - If set to \"loose\", the translation `t` function will accept any existing locale.\n *\n * Default: \"inclusive\"\n */\n strictMode: customConfiguration?.strictMode ?? STRICT_MODE,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\n/**\n * Build the routing section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied routing config.\n * @returns A fully-defaulted {@link RoutingConfig}.\n */\nexport const buildRoutingFields = (\n customConfiguration?: Partial<RoutingConfig>\n): RoutingConfig => ({\n /**\n * URL routing mode for locale handling\n *\n * Controls how locales are represented in application URLs:\n * - 'prefix-no-default': Prefix all locales except the default locale (default)\n * - en → /dashboard\n * - fr → /fr/dashboard\n *\n * - 'prefix-all': Prefix all locales including the default locale\n * - en → /en/dashboard\n * - fr → /fr/dashboard\n *\n * - 'search-params': Use search parameters for locale handling\n * - en → /dashboard?locale=en\n * - fr → /fr/dashboard?locale=fr\n *\n * - 'no-prefix': No locale prefixing in URLs\n * - en → /dashboard\n * - fr → /dashboard\n *\n * Default: 'prefix-no-default'\n */\n mode: customConfiguration?.mode ?? ROUTING_MODE,\n\n /**\n * Configuration for storing the locale in the client (localStorage or sessionStorage)\n *\n * If false, the locale will not be stored by the middleware.\n * If true, the locale storage will consider all default values. (cookie and header)\n *\n * Default: ['cookie', 'header']\n *\n */\n storage: customConfiguration?.storage ?? STORAGE,\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Custom URL rewriting rules that override the default routing mode for specific paths.\n * Allows you to define locale-specific paths that differ from the standard routing behavior.\n * Supports dynamic route parameters using `[param]` syntax.\n *\n * Default: undefined\n *\n * Example:\n * ```typescript\n * rewrite: {\n * \"/about\": {\n * en: \"/about\",\n * fr: \"/a-propos\",\n * },\n * \"/product/[slug]\": {\n * en: \"/product/[slug]\",\n * fr: \"/produit/[slug]\",\n * },\n * }\n * ```\n *\n * Note:\n * - The rewrite rules take precedence over the default `mode` behavior.\n * - If a path matches a rewrite rule, the localized path from the rewrite configuration will be used.\n * - Dynamic route parameters are supported using bracket notation (e.g., `[slug]`, `[id]`).\n * - Works with both Next.js and Vite applications.\n */\n rewrite: customConfiguration?.rewrite,\n});\n\n/**\n * Build the editor section of the Intlayer configuration.\n *\n * Returns the **full** {@link EditorConfig} including sensitive fields\n * (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}\n * omits those fields when exposing config to the client.\n *\n * @param customConfiguration - Partial user-supplied editor config.\n * @returns A fully-defaulted {@link EditorConfig}.\n */\nexport const buildEditorFields = (\n customConfiguration?: Partial<EditorConfig>\n): EditorConfig => {\n const liveSyncPort = customConfiguration?.liveSyncPort ?? LIVE_SYNC_PORT;\n return {\n /**\n * URL of the application. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n applicationURL: customConfiguration?.applicationURL || APPLICATION_URL,\n\n /**\n * URL of the editor server. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n editorURL: customConfiguration?.editorURL || EDITOR_URL,\n\n /**\n * URL of the CMS server. Used to restrict the origin of the editor for security reasons.\n */\n cmsURL: customConfiguration?.cmsURL || CMS_URL,\n\n /**\n * URL of the editor server\n *\n * Default: 'https://back.intlayer.org'\n */\n backendURL: customConfiguration?.backendURL || BACKEND_URL,\n\n /** Port of the editor server\n *\n * Default: 8000\n */\n port: customConfiguration?.port ?? PORT,\n\n /**\n * Indicates if the application interact with the visual editor\n *\n * Default: false;\n *\n * If true, the editor will be able to interact with the application.\n * If false, the editor will not be able to interact with the application.\n * In any case, the editor can only be enabled by the visual editor.\n * Disabling the editor for specific environments is a way to enforce the security.\n *\n * Usage:\n * ```js\n * {\n * // Other configurations\n * editor: {\n * enabled: process.env.NODE_ENV !== 'production',\n * }\n * };\n * ```\n */\n enabled: customConfiguration?.enabled ?? IS_ENABLED,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientId: customConfiguration?.clientId ?? undefined,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientSecret: customConfiguration?.clientSecret ?? undefined,\n\n /**\n * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.\n * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.\n *\n * Default: 'local_first'\n *\n * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.\n * - 'local_first': The first dictionary found in the locale is used.\n * - 'distant_first': The first dictionary found in the distant locales is used.\n */\n dictionaryPriorityStrategy:\n customConfiguration?.dictionaryPriorityStrategy ??\n DICTIONARY_PRIORITY_STRATEGY,\n\n /**\n * Indicates if the application should hot reload the locale configurations when a change is detected.\n * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.\n *\n * The hot reload is only available for clients of the `enterprise` plan.\n *\n * Default: false\n */\n liveSync: customConfiguration?.liveSync ?? LIVE_SYNC,\n\n /**\n * Port of the live sync server\n *\n * Default: 4000\n */\n liveSyncPort,\n\n /**\n * URL of the live sync server in case of remote live sync server\n *\n * Default: `http://localhost:${LIVE_SYNC_PORT}`\n */\n liveSyncURL:\n customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`,\n };\n};\n\n/**\n * Build the log section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied log config.\n * @param logFunctions - Optional custom log function overrides (server-only).\n * @returns A fully-defaulted {@link LogConfig}.\n */\nexport const buildLogFields = (\n customConfiguration?: Partial<LogConfig>,\n logFunctions?: LogFunctions\n): LogConfig => ({\n /**\n * Indicates if the logger is enabled\n *\n * Default: 'prefix-no-default'\n *\n * If 'default', the logger is enabled and can be used.\n * If 'verbose', the logger will be enabled and can be used, but will log more information.\n * If 'disabled', the logger is disabled and cannot be used.\n */\n mode: customConfiguration?.mode ?? MODE,\n\n /**\n * Prefix of the logger\n *\n * Default: '[intlayer]'\n *\n * The prefix of the logger.\n */\n prefix: customConfiguration?.prefix ?? PREFIX,\n\n /**\n * Functions to log\n */\n error: logFunctions?.error,\n log: logFunctions?.log,\n info: logFunctions?.info,\n warn: logFunctions?.warn,\n});\n\n// ---------------------------------------------------------------------------\n// Browser configuration builders\n// ---------------------------------------------------------------------------\n\n/**\n * Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.\n *\n * Applies defaults for every field and strips all server-only or sensitive\n * information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,\n * `editor.clientId`, `editor.clientSecret`).\n *\n * This is the browser counterpart of `buildConfigurationFields`. It is safe\n * to call in browser environments because it has no Node.js dependencies.\n *\n * @param customConfig - Optional partial user-supplied Intlayer config.\n * @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.\n *\n * @example\n * ```ts\n * import { buildBrowserConfiguration } from '@intlayer/config/client';\n *\n * window.INTLAYER_CONFIG = buildBrowserConfiguration({\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n * ```\n */\nexport const buildBrowserConfiguration = (\n customConfig?: CustomIntlayerConfig\n): BrowserIntlayerConfig => {\n const { locales, defaultLocale } = buildInternationalizationFields(\n customConfig?.internationalization\n );\n const routing = buildRoutingFields(customConfig?.routing);\n const {\n clientId: _clientId,\n clientSecret: _clientSecret,\n ...editorPublic\n } = buildEditorFields(customConfig?.editor);\n const { mode, prefix } = buildLogFields(customConfig?.log);\n\n return {\n internationalization: { locales, defaultLocale },\n routing,\n editor: editorPublic,\n log: { mode, prefix },\n metadata: {\n name: 'Intlayer',\n version: packageJson.version,\n doc: 'https://intlayer.org/docs',\n },\n };\n};\n\n/**\n * Extract a {@link BrowserIntlayerConfig} from an already-built full\n * {@link IntlayerConfig}.\n *\n * Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold\n * the full server-side config and need to inject the browser-safe subset at\n * compile time via a bundler `define`.\n *\n * @param config - A fully-built server-side Intlayer configuration.\n * @returns The browser-safe subset of that configuration.\n */\nexport const extractBrowserConfiguration = (\n config: IntlayerConfig\n): BrowserIntlayerConfig => ({\n internationalization: {\n locales: config.internationalization.locales,\n defaultLocale: config.internationalization.defaultLocale,\n },\n routing: {\n mode: config.routing.mode,\n storage: config.routing.storage,\n basePath: config.routing.basePath,\n rewrite: config.routing.rewrite,\n },\n editor: {\n applicationURL: config.editor.applicationURL,\n editorURL: config.editor.editorURL,\n cmsURL: config.editor.cmsURL,\n backendURL: config.editor.backendURL,\n port: config.editor.port,\n enabled: config.editor.enabled,\n dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,\n liveSync: config.editor.liveSync,\n liveSyncPort: config.editor.liveSyncPort,\n liveSyncURL: config.editor.liveSyncURL,\n },\n log: {\n mode: config.log.mode,\n prefix: config.log.prefix,\n },\n metadata: config.metadata,\n});\n"],"mappings":";;;;;;;;;;;;;AAwEA,MAAa,mCACX,yBACgC;CAOhC,SAAS,qBAAqB,WAAW;CAWzC,iBACE,qBAAqB,mBACrB,qBAAqB,WACrB;CAUF,YAAY,qBAAqB;CAOjC,eAAe,qBAAqB,iBAAiB;CACtD;;;;;;;AAQD,MAAa,sBACX,yBACmB;CAuBnB,MAAM,qBAAqB;CAW3B,SAAS,qBAAqB,WAAW;CAazC,UAAU,qBAAqB;CA6B/B,SAAS,qBAAqB;CAC/B;;;;;;;;;;;AAYD,MAAa,qBACX,wBACiB;CACjB,MAAM,eAAe,qBAAqB;AAC1C,QAAO;EAQL,gBAAgB,qBAAqB;EASrC,WAAW,qBAAqB;EAKhC,QAAQ,qBAAqB;EAO7B,YAAY,qBAAqB;EAMjC,MAAM,qBAAqB;EAsB3B,SAAS,qBAAqB;EAW9B,UAAU,qBAAqB,YAAY;EAW3C,cAAc,qBAAqB,gBAAgB;EAYnD,4BACE,qBAAqB;EAWvB,UAAU,qBAAqB;EAO/B;EAOA,aACE,qBAAqB,eAAe,oBAAoB;EAC3D;;;;;;;;;AAUH,MAAa,kBACX,qBACA,kBACe;CAUf,MAAM,qBAAqB;CAS3B,QAAQ,qBAAqB,UAAU;CAKvC,OAAO,cAAc;CACrB,KAAK,cAAc;CACnB,MAAM,cAAc;CACpB,MAAM,cAAc;CACrB;;;;;;;;;;;;;;;;;;;;;;;AA4BD,MAAa,6BACX,iBAC0B;CAC1B,MAAM,EAAE,SAAS,kBAAkB,gCACjC,cAAc,qBACf;CACD,MAAM,UAAU,mBAAmB,cAAc,QAAQ;CACzD,MAAM,EACJ,UAAU,WACV,cAAc,eACd,GAAG,iBACD,kBAAkB,cAAc,OAAO;CAC3C,MAAM,EAAE,MAAM,WAAW,eAAe,cAAc,IAAI;AAE1D,QAAO;EACL,sBAAsB;GAAE;GAAS;GAAe;EAChD;EACA,QAAQ;EACR,KAAK;GAAE;GAAM;GAAQ;EACrB,UAAU;GACR,MAAM;GACN,SAAS,YAAY;GACrB,KAAK;GACN;EACF;;;;;;;;;;;;;AAcH,MAAa,+BACX,YAC2B;CAC3B,sBAAsB;EACpB,SAAS,OAAO,qBAAqB;EACrC,eAAe,OAAO,qBAAqB;EAC5C;CACD,SAAS;EACP,MAAM,OAAO,QAAQ;EACrB,SAAS,OAAO,QAAQ;EACxB,UAAU,OAAO,QAAQ;EACzB,SAAS,OAAO,QAAQ;EACzB;CACD,QAAQ;EACN,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACtB,YAAY,OAAO,OAAO;EAC1B,MAAM,OAAO,OAAO;EACpB,SAAS,OAAO,OAAO;EACvB,4BAA4B,OAAO,OAAO;EAC1C,UAAU,OAAO,OAAO;EACxB,cAAc,OAAO,OAAO;EAC5B,aAAa,OAAO,OAAO;EAC5B;CACD,KAAK;EACH,MAAM,OAAO,IAAI;EACjB,QAAQ,OAAO,IAAI;EACpB;CACD,UAAU,OAAO;CAClB"}
|
|
@@ -3,31 +3,26 @@ import { BUILD_MODE, CACHE, OUTPUT_FORMAT, TRAVERSE_PATTERN, TYPE_CHECKING } fro
|
|
|
3
3
|
import { COMPILER_DICTIONARY_KEY_PREFIX, COMPILER_ENABLED, COMPILER_NO_METADATA, COMPILER_SAVE_COMPONENTS } from "../defaultValues/compiler.mjs";
|
|
4
4
|
import { CODE_DIR, CONTENT_DIR, EXCLUDED_PATHS, FILE_EXTENSIONS, WATCH } from "../defaultValues/content.mjs";
|
|
5
5
|
import { CONTENT_AUTO_TRANSFORMATION, FILL, IMPORT_MODE, LOCATION } from "../defaultValues/dictionary.mjs";
|
|
6
|
-
import { APPLICATION_URL, BACKEND_URL, CMS_URL, DICTIONARY_PRIORITY_STRATEGY, EDITOR_URL, IS_ENABLED, LIVE_SYNC, LIVE_SYNC_PORT, PORT } from "../defaultValues/editor.mjs";
|
|
7
|
-
import { DEFAULT_LOCALE, LOCALES, REQUIRED_LOCALES, STRICT_MODE } from "../defaultValues/internationalization.mjs";
|
|
8
|
-
import { MODE, PREFIX } from "../defaultValues/log.mjs";
|
|
9
|
-
import { BASE_PATH, ROUTING_MODE, STORAGE } from "../defaultValues/routing.mjs";
|
|
10
6
|
import { CACHE_DIR, CONFIG_DIR, DICTIONARIES_DIR, DYNAMIC_DICTIONARIES_DIR, FETCH_DICTIONARIES_DIR, MAIN_DIR, MODULE_AUGMENTATION_DIR, REMOTE_DICTIONARIES_DIR, TEMP_DIR, TYPES_DIR, UNMERGED_DICTIONARIES_DIR } from "../defaultValues/system.mjs";
|
|
11
7
|
import { getProjectRequire } from "../utils/ESMxCJSHelpers.mjs";
|
|
8
|
+
import { buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration } from "./buildBrowserConfiguration.mjs";
|
|
12
9
|
import { intlayerConfigSchema } from "./configurationSchema.mjs";
|
|
13
10
|
import { statSync } from "node:fs";
|
|
14
11
|
import { dirname, isAbsolute, join } from "node:path";
|
|
15
|
-
import packageJson from "@intlayer/types/package.json" with { type: "json" };
|
|
16
12
|
|
|
17
13
|
//#region src/configFile/buildConfigurationFields.ts
|
|
18
14
|
let storedConfiguration;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
15
|
+
/**
|
|
16
|
+
* Build the `system` section of the Intlayer configuration.
|
|
17
|
+
*
|
|
18
|
+
* Resolves all directory paths (dictionaries, types, cache, …) relative to
|
|
19
|
+
* the project base directory, using Node.js `require.resolve` where available
|
|
20
|
+
* and falling back to `path.join` otherwise.
|
|
21
|
+
*
|
|
22
|
+
* @param baseDir - Project root directory. Defaults to `process.cwd()`.
|
|
23
|
+
* @param customConfiguration - Partial user-supplied system config.
|
|
24
|
+
* @returns A fully-resolved {@link SystemConfig}.
|
|
25
|
+
*/
|
|
31
26
|
const buildSystemFields = (baseDir, customConfiguration) => {
|
|
32
27
|
const projectBaseDir = baseDir ?? process.cwd();
|
|
33
28
|
const optionalJoinBaseDir = (pathInput) => {
|
|
@@ -60,6 +55,16 @@ const buildSystemFields = (baseDir, customConfiguration) => {
|
|
|
60
55
|
tempDir: optionalJoinBaseDir(customConfiguration?.tempDir ?? ".intlayer/tmp")
|
|
61
56
|
};
|
|
62
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Build the `content` section of the Intlayer configuration.
|
|
60
|
+
*
|
|
61
|
+
* Resolves content and code directories relative to the project base using
|
|
62
|
+
* `require.resolve`, falling back to `path.join`.
|
|
63
|
+
*
|
|
64
|
+
* @param systemConfig - Already-built system configuration (provides `baseDir`).
|
|
65
|
+
* @param customConfiguration - Partial user-supplied content config.
|
|
66
|
+
* @returns A fully-resolved {@link ContentConfig}.
|
|
67
|
+
*/
|
|
63
68
|
const buildContentFields = (systemConfig, customConfiguration) => {
|
|
64
69
|
const fileExtensions = customConfiguration?.fileExtensions ?? FILE_EXTENSIONS;
|
|
65
70
|
const optionalJoinBaseDir = (pathInput) => {
|
|
@@ -89,28 +94,12 @@ const buildContentFields = (systemConfig, customConfiguration) => {
|
|
|
89
94
|
formatCommand: customConfiguration?.formatCommand
|
|
90
95
|
};
|
|
91
96
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
enabled: customConfiguration?.enabled ?? false,
|
|
99
|
-
clientId: customConfiguration?.clientId ?? void 0,
|
|
100
|
-
clientSecret: customConfiguration?.clientSecret ?? void 0,
|
|
101
|
-
dictionaryPriorityStrategy: customConfiguration?.dictionaryPriorityStrategy ?? "local_first",
|
|
102
|
-
liveSync: customConfiguration?.liveSync ?? true,
|
|
103
|
-
liveSyncPort: customConfiguration?.liveSyncPort ?? 4e3,
|
|
104
|
-
liveSyncURL: customConfiguration?.liveSyncURL ?? `http://localhost:${customConfiguration?.liveSyncPort ?? 4e3}`
|
|
105
|
-
});
|
|
106
|
-
const buildLogFields = (customConfiguration, logFunctions) => ({
|
|
107
|
-
mode: customConfiguration?.mode ?? "default",
|
|
108
|
-
prefix: customConfiguration?.prefix ?? PREFIX,
|
|
109
|
-
error: logFunctions?.error,
|
|
110
|
-
log: logFunctions?.log,
|
|
111
|
-
info: logFunctions?.info,
|
|
112
|
-
warn: logFunctions?.warn
|
|
113
|
-
});
|
|
97
|
+
/**
|
|
98
|
+
* Build the `ai` section of the Intlayer configuration.
|
|
99
|
+
*
|
|
100
|
+
* @param customConfiguration - Partial user-supplied AI config.
|
|
101
|
+
* @returns A fully-defaulted {@link AiConfig}.
|
|
102
|
+
*/
|
|
114
103
|
const buildAiFields = (customConfiguration) => ({
|
|
115
104
|
provider: customConfiguration?.provider,
|
|
116
105
|
apiKey: customConfiguration?.apiKey,
|
|
@@ -120,6 +109,12 @@ const buildAiFields = (customConfiguration) => ({
|
|
|
120
109
|
baseURL: customConfiguration?.baseURL,
|
|
121
110
|
dataSerialization: customConfiguration?.dataSerialization
|
|
122
111
|
});
|
|
112
|
+
/**
|
|
113
|
+
* Build the `build` section of the Intlayer configuration.
|
|
114
|
+
*
|
|
115
|
+
* @param customConfiguration - Partial user-supplied build config.
|
|
116
|
+
* @returns A fully-defaulted {@link BuildConfig}.
|
|
117
|
+
*/
|
|
123
118
|
const buildBuildFields = (customConfiguration) => ({
|
|
124
119
|
mode: customConfiguration?.mode ?? "auto",
|
|
125
120
|
optimize: customConfiguration?.optimize,
|
|
@@ -130,6 +125,12 @@ const buildBuildFields = (customConfiguration) => ({
|
|
|
130
125
|
require: customConfiguration?.require,
|
|
131
126
|
checkTypes: customConfiguration?.checkTypes ?? false
|
|
132
127
|
});
|
|
128
|
+
/**
|
|
129
|
+
* Build the `compiler` section of the Intlayer configuration.
|
|
130
|
+
*
|
|
131
|
+
* @param customConfiguration - Partial user-supplied compiler config.
|
|
132
|
+
* @returns A fully-defaulted {@link CompilerConfig}.
|
|
133
|
+
*/
|
|
133
134
|
const buildCompilerFields = (customConfiguration) => ({
|
|
134
135
|
enabled: customConfiguration?.enabled ?? true,
|
|
135
136
|
dictionaryKeyPrefix: customConfiguration?.dictionaryKeyPrefix ?? "",
|
|
@@ -139,6 +140,12 @@ const buildCompilerFields = (customConfiguration) => ({
|
|
|
139
140
|
noMetadata: customConfiguration?.noMetadata ?? false,
|
|
140
141
|
saveComponents: customConfiguration?.saveComponents ?? false
|
|
141
142
|
});
|
|
143
|
+
/**
|
|
144
|
+
* Build the `dictionary` section of the Intlayer configuration.
|
|
145
|
+
*
|
|
146
|
+
* @param customConfiguration - Partial user-supplied dictionary config.
|
|
147
|
+
* @returns A fully-defaulted {@link DictionaryConfig}.
|
|
148
|
+
*/
|
|
142
149
|
const buildDictionaryFields = (customConfiguration) => {
|
|
143
150
|
const contentAutoTransformation = customConfiguration?.contentAutoTransformation ?? false;
|
|
144
151
|
return {
|
|
@@ -158,7 +165,22 @@ const buildDictionaryFields = (customConfiguration) => {
|
|
|
158
165
|
};
|
|
159
166
|
};
|
|
160
167
|
/**
|
|
161
|
-
* Build the configuration
|
|
168
|
+
* Build the complete Intlayer configuration by merging user-supplied values
|
|
169
|
+
* with defaults.
|
|
170
|
+
*
|
|
171
|
+
* Internally this function:
|
|
172
|
+
* 1. Calls {@link buildBrowserConfiguration} to produce the browser-safe
|
|
173
|
+
* subset (internationalization, routing, editor public fields, log, metadata).
|
|
174
|
+
* 2. Extends the result with full server-side fields:
|
|
175
|
+
* - `internationalization` — adds `requiredLocales` and `strictMode`.
|
|
176
|
+
* - `editor` — adds `clientId` and `clientSecret`.
|
|
177
|
+
* - `log` — adds custom log functions.
|
|
178
|
+
* - `system`, `content`, `ai`, `build`, `compiler`, `dictionary`.
|
|
179
|
+
*
|
|
180
|
+
* @param customConfiguration - Optional user-supplied configuration object.
|
|
181
|
+
* @param baseDir - Project root directory. Defaults to `process.cwd()`.
|
|
182
|
+
* @param logFunctions - Optional custom logging functions.
|
|
183
|
+
* @returns A fully-built {@link IntlayerConfig}.
|
|
162
184
|
*/
|
|
163
185
|
const buildConfigurationFields = (customConfiguration, baseDir, logFunctions) => {
|
|
164
186
|
if (customConfiguration) {
|
|
@@ -168,31 +190,30 @@ const buildConfigurationFields = (customConfiguration, baseDir, logFunctions) =>
|
|
|
168
190
|
for (const issue of result.error.issues) logError(`${issue.path.join(".")}: ${issue.message}`);
|
|
169
191
|
}
|
|
170
192
|
}
|
|
193
|
+
const browserConfig = buildBrowserConfiguration(customConfiguration);
|
|
171
194
|
const internationalizationConfig = buildInternationalizationFields(customConfiguration?.internationalization);
|
|
172
|
-
const
|
|
195
|
+
const editorConfig = buildEditorFields(customConfiguration?.editor);
|
|
196
|
+
const logConfig = buildLogFields(customConfiguration?.log, logFunctions);
|
|
173
197
|
const systemConfig = buildSystemFields(baseDir, customConfiguration?.system);
|
|
198
|
+
const contentConfig = buildContentFields(systemConfig, customConfiguration?.content);
|
|
174
199
|
storedConfiguration = {
|
|
200
|
+
routing: browserConfig.routing,
|
|
201
|
+
metadata: browserConfig.metadata,
|
|
175
202
|
internationalization: internationalizationConfig,
|
|
176
|
-
|
|
177
|
-
|
|
203
|
+
editor: editorConfig,
|
|
204
|
+
log: logConfig,
|
|
178
205
|
system: systemConfig,
|
|
179
|
-
|
|
180
|
-
log: buildLogFields(customConfiguration?.log, logFunctions),
|
|
206
|
+
content: contentConfig,
|
|
181
207
|
ai: buildAiFields(customConfiguration?.ai),
|
|
182
208
|
build: buildBuildFields(customConfiguration?.build),
|
|
183
209
|
compiler: buildCompilerFields(customConfiguration?.compiler),
|
|
184
210
|
dictionary: buildDictionaryFields(customConfiguration?.dictionary),
|
|
185
211
|
plugins: customConfiguration?.plugins,
|
|
186
|
-
schemas: customConfiguration?.schemas
|
|
187
|
-
metadata: {
|
|
188
|
-
name: "Intlayer",
|
|
189
|
-
version: packageJson.version,
|
|
190
|
-
doc: `https://intlayer.org/docs`
|
|
191
|
-
}
|
|
212
|
+
schemas: customConfiguration?.schemas
|
|
192
213
|
};
|
|
193
214
|
return storedConfiguration;
|
|
194
215
|
};
|
|
195
216
|
|
|
196
217
|
//#endregion
|
|
197
|
-
export { buildConfigurationFields };
|
|
218
|
+
export { buildBrowserConfiguration, buildConfigurationFields, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration };
|
|
198
219
|
//# sourceMappingURL=buildConfigurationFields.mjs.map
|