@intlayer/chokidar 5.3.5 → 5.3.7
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/cleanOutputDir.cjs +3 -4
- package/dist/cjs/cleanOutputDir.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaryKeys.cjs +3 -4
- package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +1 -1
- package/dist/cjs/getBuiltDictionariesPath.cjs +2 -3
- package/dist/cjs/getBuiltDictionariesPath.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +2 -2
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +7 -4
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/log.cjs +5 -5
- package/dist/cjs/log.cjs.map +1 -1
- package/dist/cjs/prepareContentDeclaration.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +11 -7
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.cjs +5 -3
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.cjs +2 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs +4 -5
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +4 -6
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +4 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +4 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +22 -14
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +19 -18
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +2 -3
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs +3 -4
- package/dist/esm/cleanOutputDir.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaryKeys.mjs +3 -4
- package/dist/esm/fetchDistantDictionaryKeys.mjs.map +1 -1
- package/dist/esm/getBuiltDictionariesPath.mjs +2 -3
- package/dist/esm/getBuiltDictionariesPath.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +3 -3
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +8 -5
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/log.mjs +5 -5
- package/dist/esm/log.mjs.map +1 -1
- package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +12 -7
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.mjs +5 -3
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.mjs +2 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs +4 -5
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +4 -6
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +4 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +4 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +22 -14
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +19 -18
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +6 -4
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
- package/dist/types/cleanOutputDir.d.ts +1 -1
- package/dist/types/cleanOutputDir.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaryKeys.d.ts +2 -1
- package/dist/types/fetchDistantDictionaryKeys.d.ts.map +1 -1
- package/dist/types/getBuiltDictionariesPath.d.ts +1 -1
- package/dist/types/getBuiltDictionariesPath.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +1 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/log.d.ts +3 -2
- package/dist/types/log.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts +2 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
- package/package.json +13 -13
|
@@ -24,9 +24,8 @@ module.exports = __toCommonJS(cleanOutputDir_exports);
|
|
|
24
24
|
var import_fs = require("fs");
|
|
25
25
|
var import_config = require("@intlayer/config");
|
|
26
26
|
var import_createDictionaryEntryPoint = require('./transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs');
|
|
27
|
-
const cleanOutputDir = () => {
|
|
28
|
-
const {
|
|
29
|
-
const { resultDir, typesDir, dictionariesDir } = content;
|
|
27
|
+
const cleanOutputDir = (configuration = (0, import_config.getConfiguration)()) => {
|
|
28
|
+
const { resultDir, typesDir, dictionariesDir } = configuration.content;
|
|
30
29
|
if ((0, import_fs.existsSync)(resultDir)) {
|
|
31
30
|
if ((0, import_fs.existsSync)(dictionariesDir)) {
|
|
32
31
|
(0, import_fs.rmSync)(dictionariesDir, { recursive: true });
|
|
@@ -35,7 +34,7 @@ const cleanOutputDir = () => {
|
|
|
35
34
|
(0, import_fs.rmSync)(typesDir, { recursive: true });
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
(0, import_createDictionaryEntryPoint.createDictionaryEntryPoint)();
|
|
37
|
+
(0, import_createDictionaryEntryPoint.createDictionaryEntryPoint)(configuration);
|
|
39
38
|
};
|
|
40
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
40
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cleanOutputDir.ts"],"sourcesContent":["import { existsSync, rmSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\n\nexport const cleanOutputDir = (
|
|
1
|
+
{"version":3,"sources":["../../src/cleanOutputDir.ts"],"sourcesContent":["import { existsSync, rmSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\n\nexport const cleanOutputDir = (configuration = getConfiguration()) => {\n const { resultDir, typesDir, dictionariesDir } = configuration.content;\n\n if (existsSync(resultDir)) {\n // Delete the dictionary directory\n if (existsSync(dictionariesDir)) {\n rmSync(dictionariesDir, { recursive: true });\n }\n\n // Delete the types directory\n if (existsSync(typesDir)) {\n rmSync(typesDir, { recursive: true });\n }\n }\n\n createDictionaryEntryPoint(configuration);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAmC;AACnC,oBAAiC;AACjC,wCAA2C;AAEpC,MAAM,iBAAiB,CAAC,oBAAgB,gCAAiB,MAAM;AACpE,QAAM,EAAE,WAAW,UAAU,gBAAgB,IAAI,cAAc;AAE/D,UAAI,sBAAW,SAAS,GAAG;AAEzB,YAAI,sBAAW,eAAe,GAAG;AAC/B,4BAAO,iBAAiB,EAAE,WAAW,KAAK,CAAC;AAAA,IAC7C;AAGA,YAAI,sBAAW,QAAQ,GAAG;AACxB,4BAAO,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,IACtC;AAAA,EACF;AAEA,oEAA2B,aAAa;AAC1C;","names":[]}
|
|
@@ -23,15 +23,14 @@ __export(fetchDistantDictionaryKeys_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(fetchDistantDictionaryKeys_exports);
|
|
24
24
|
var import_api = require("@intlayer/api");
|
|
25
25
|
var import_config = require("@intlayer/config");
|
|
26
|
-
const fetchDistantDictionaryKeys = async () => {
|
|
27
|
-
const
|
|
28
|
-
const { clientId, clientSecret } = config.editor;
|
|
26
|
+
const fetchDistantDictionaryKeys = async (configuration = (0, import_config.getConfiguration)()) => {
|
|
27
|
+
const { clientId, clientSecret } = configuration.editor;
|
|
29
28
|
if (!clientId || !clientSecret) {
|
|
30
29
|
throw new Error(
|
|
31
30
|
"Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
|
|
32
31
|
);
|
|
33
32
|
}
|
|
34
|
-
const intlayerAPI = (0, import_api.getIntlayerAPI)(void 0,
|
|
33
|
+
const intlayerAPI = (0, import_api.getIntlayerAPI)(void 0, configuration);
|
|
35
34
|
const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
|
|
36
35
|
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
37
36
|
const getDictionariesKeysResult = await intlayerAPI.dictionary.getDictionariesKeys({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetchDistantDictionaryKeys.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport { getConfiguration } from '@intlayer/config';\n\nexport const fetchDistantDictionaryKeys = async (): Promise<string[]> => {\n const
|
|
1
|
+
{"version":3,"sources":["../../src/fetchDistantDictionaryKeys.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport { getConfiguration, type IntlayerConfig } from '@intlayer/config';\n\nexport const fetchDistantDictionaryKeys = async (\n configuration: IntlayerConfig = getConfiguration()\n): Promise<string[]> => {\n const { clientId, clientSecret } = configuration.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, configuration);\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n const distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n // Apply any filtering if needed\n return distantDictionariesKeys;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAC/B,oBAAsD;AAE/C,MAAM,6BAA6B,OACxC,oBAAgC,gCAAiB,MAC3B;AACtB,QAAM,EAAE,UAAU,aAAa,IAAI,cAAc;AAEjD,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,kBAAc,2BAAe,QAAW,aAAa;AAE3D,QAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,WAAW,oBAAoB;AAAA,IAC/C,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC1D,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,0BAAoC,0BAA0B;AAGpE,SAAO;AACT;","names":[]}
|
|
@@ -34,9 +34,8 @@ module.exports = __toCommonJS(getBuiltDictionariesPath_exports);
|
|
|
34
34
|
var import_fs = require("fs");
|
|
35
35
|
var import_config = require("@intlayer/config");
|
|
36
36
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
37
|
-
const
|
|
38
|
-
const { dictionariesDir, mainDir } = content;
|
|
39
|
-
const getBuiltDictionariesPath = () => {
|
|
37
|
+
const getBuiltDictionariesPath = (configuration = (0, import_config.getConfiguration)()) => {
|
|
38
|
+
const { dictionariesDir, mainDir } = configuration.content;
|
|
40
39
|
if (!(0, import_fs.existsSync)(mainDir)) {
|
|
41
40
|
(0, import_fs.mkdirSync)(mainDir, { recursive: true });
|
|
42
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getBuiltDictionariesPath.ts"],"sourcesContent":["import { existsSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\n\
|
|
1
|
+
{"version":3,"sources":["../../src/getBuiltDictionariesPath.ts"],"sourcesContent":["import { existsSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltDictionariesPath = (\n configuration = getConfiguration()\n) => {\n const { dictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(`${dictionariesDir}/**/*.json`);\n\n return dictionariesPath;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAsC;AACtC,oBAAiC;AACjC,uBAAe;AAKR,MAAM,2BAA2B,CACtC,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,iBAAiB,QAAQ,IAAI,cAAc;AAGnD,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,iBAAAA,QAAG,KAAK,GAAG,eAAe,YAAY;AAEzE,SAAO;AACT;","names":["fg"]}
|
|
@@ -23,9 +23,9 @@ __export(loadContentDeclaration_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(loadContentDeclaration_exports);
|
|
24
24
|
var import_config = require("@intlayer/config");
|
|
25
25
|
var import_processContentDeclaration = require('../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs');
|
|
26
|
-
const loadContentDeclarations = async (contentDeclarationFilePath) => {
|
|
26
|
+
const loadContentDeclarations = async (contentDeclarationFilePath, projectRequire = import_config.ESMxCJSRequire) => {
|
|
27
27
|
const contentDeclarations = contentDeclarationFilePath.map((path) => ({
|
|
28
|
-
...(0, import_config.loadExternalFile)(path),
|
|
28
|
+
...(0, import_config.loadExternalFile)(path, void 0, projectRequire),
|
|
29
29
|
filePath: path
|
|
30
30
|
}));
|
|
31
31
|
const resultDictionariesPaths = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import { loadExternalFile } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[]\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map((path) => ({\n ...loadExternalFile(path),\n filePath: path,\n }));\n const resultDictionariesPaths: Dictionary[] = [];\n\n for await (const contentDeclaration of contentDeclarations) {\n if (!contentDeclaration) {\n continue;\n }\n\n const processedContentDeclaration = await processContentDeclaration(\n contentDeclaration as Dictionary\n );\n\n if (!processedContentDeclaration) {\n continue;\n }\n\n resultDictionariesPaths.push(processedContentDeclaration);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import { ESMxCJSRequire, loadExternalFile } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[],\n projectRequire = ESMxCJSRequire\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map((path) => ({\n ...loadExternalFile(path, undefined, projectRequire),\n filePath: path,\n }));\n const resultDictionariesPaths: Dictionary[] = [];\n\n for await (const contentDeclaration of contentDeclarations) {\n if (!contentDeclaration) {\n continue;\n }\n\n const processedContentDeclaration = await processContentDeclaration(\n contentDeclaration as Dictionary\n );\n\n if (!processedContentDeclaration) {\n continue;\n }\n\n resultDictionariesPaths.push(processedContentDeclaration);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiD;AAEjD,uCAA0C;AAEnC,MAAM,0BAA0B,OACrC,4BACA,iBAAiB,iCACS;AAC1B,QAAM,sBAAsB,2BAA2B,IAAI,CAAC,UAAU;AAAA,IACpE,OAAG,gCAAiB,MAAM,QAAW,cAAc;AAAA,IACnD,UAAU;AAAA,EACZ,EAAE;AACF,QAAM,0BAAwC,CAAC;AAE/C,mBAAiB,sBAAsB,qBAAqB;AAC1D,QAAI,CAAC,oBAAoB;AACvB;AAAA,IACF;AAEA,UAAM,8BAA8B,UAAM;AAAA,MACxC;AAAA,IACF;AAEA,QAAI,CAAC,6BAA6B;AAChC;AAAA,IACF;AAEA,4BAAwB,KAAK,2BAA2B;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -39,13 +39,16 @@ var import_mergeDictionaries = require('../mergeDictionaries.cjs');
|
|
|
39
39
|
var import_utils = require('../utils.cjs');
|
|
40
40
|
var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
|
|
41
41
|
var import_loadDistantDictionaries = require('./loadDistantDictionaries.cjs');
|
|
42
|
-
const loadDictionaries = async (contentDeclarationsPaths) => {
|
|
42
|
+
const loadDictionaries = async (contentDeclarationsPaths, configuration = (0, import_config.getConfiguration)(), projectRequire = import_config.ESMxCJSRequire) => {
|
|
43
43
|
try {
|
|
44
|
-
const { editor } =
|
|
44
|
+
const { editor } = configuration;
|
|
45
45
|
(0, import_config.appLogger)("Dictionaries:", { isVerbose: true });
|
|
46
46
|
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
|
|
47
|
-
const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(
|
|
48
|
-
|
|
47
|
+
const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(
|
|
48
|
+
files,
|
|
49
|
+
projectRequire
|
|
50
|
+
);
|
|
51
|
+
const localDictionaryKeys = localDictionaries.map((dict) => dict.key).filter(Boolean);
|
|
49
52
|
import_log.logger.init(localDictionaryKeys, []);
|
|
50
53
|
import_log.logger.updateStatus(
|
|
51
54
|
localDictionaries.map((dict) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { appLogger, getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } =
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { appLogger, ESMxCJSRequire, getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration = getConfiguration(),\n projectRequire = ESMxCJSRequire\n): Promise<Dictionary[]> => {\n try {\n const { editor } = configuration;\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n projectRequire\n );\n const localDictionaryKeys = localDictionaries\n .map((dict) => dict.key)\n .filter(Boolean); // Remove empty or undefined keys\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n logger.updateStatus(\n localDictionaries.map((dict) => ({\n dictionaryKey: dict.key,\n type: 'local',\n status: { status: 'built' },\n }))\n );\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n try {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n if (editor.dictionaryPriorityStrategy === 'distant_first') {\n // Merge the dictionaries\n mergedDictionaries = merge(localDictionaries, distantDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n } else {\n // Merge the dictionaries\n mergedDictionaries = merge(distantDictionaries, localDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n }\n } catch (_error) {\n appLogger('Error during fetching distant dictionaries', {\n level: 'error',\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA4D;AAE5D,uBAAkB;AAClB,wCAA2C;AAC3C,iBAAuB;AACvB,+BAA2B;AAC3B,mBAAmC;AACnC,oCAAwC;A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MACH;AAAA,IACF;AAGA,sBAAO,KAAK;AAEZ,WAAO;AAAA,EACT,SAAS,OAAO;AAEd,sBAAO,KAAK;AAEZ,UAAM;AAAA,EACR;AACF;","names":["merge"]}
|
package/dist/cjs/log.cjs
CHANGED
|
@@ -55,7 +55,6 @@ class Logger {
|
|
|
55
55
|
// Singleton instance
|
|
56
56
|
static instance;
|
|
57
57
|
constructor() {
|
|
58
|
-
this.config = (0, import_config.getConfiguration)();
|
|
59
58
|
}
|
|
60
59
|
static getInstance() {
|
|
61
60
|
if (!Logger.instance) {
|
|
@@ -63,7 +62,8 @@ class Logger {
|
|
|
63
62
|
}
|
|
64
63
|
return Logger.instance;
|
|
65
64
|
}
|
|
66
|
-
init(localDictionariesKeys, distantDictionariesKeys) {
|
|
65
|
+
init(localDictionariesKeys, distantDictionariesKeys, configuration = (0, import_config.getConfiguration)()) {
|
|
66
|
+
this.config = configuration;
|
|
67
67
|
const allKeys = Array.from(
|
|
68
68
|
new Set(
|
|
69
69
|
[...localDictionariesKeys, ...distantDictionariesKeys].sort(
|
|
@@ -149,7 +149,7 @@ class Logger {
|
|
|
149
149
|
}
|
|
150
150
|
// Method to update the terminal output
|
|
151
151
|
updateOutput(content) {
|
|
152
|
-
if (this.config
|
|
152
|
+
if (this.config?.log.mode !== "verbose") return;
|
|
153
153
|
if (!this.originalStdoutWrite) {
|
|
154
154
|
this.originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
155
155
|
this.extraLines = 0;
|
|
@@ -260,7 +260,7 @@ class Logger {
|
|
|
260
260
|
const statusBlock = `${GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${GREY_DARK}]${colorEnd}`;
|
|
261
261
|
return `${colorStart}${statusBlock}${colorEnd}`;
|
|
262
262
|
});
|
|
263
|
-
return `${this.config
|
|
263
|
+
return `${this.config?.log.prefix}- ${paddedKey} ${states.join(" ")}`;
|
|
264
264
|
}
|
|
265
265
|
// Replace logUpdate calls with your custom methods
|
|
266
266
|
updateAllStatusLines() {
|
|
@@ -277,7 +277,7 @@ class Logger {
|
|
|
277
277
|
let content;
|
|
278
278
|
if (lines.length > maxVisibleLines) {
|
|
279
279
|
const visibleLines = lines.slice(0, maxVisibleLines - 5);
|
|
280
|
-
const summary = `${this.config
|
|
280
|
+
const summary = `${this.config?.log.prefix}... and ${lines.length - visibleLines.length} more`;
|
|
281
281
|
content = LINE_DETECTOR + visibleLines.join("\n") + "\n" + summary;
|
|
282
282
|
} else {
|
|
283
283
|
content = lines.join("\n");
|
package/dist/cjs/log.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import readline from 'readline';\nimport { type IntlayerConfig, getConfiguration } from '@intlayer/config';\nimport { sortAlphabetically } from './utils';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nconst LINE_DETECTOR = '\\u200B\\u200B\\u200B'; // Three zero-width spaces\nconst SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n// ANSI color codes\nconst RESET = '\\x1b[0m';\nconst GREEN = '\\x1b[32m';\nconst RED = '\\x1b[31m';\nconst BLUE = '\\x1b[34m';\nconst GREY = '\\x1b[90m';\nconst GREY_DARK = '\\x1b[90m';\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n private previousLineCount: number = 0;\n private lineDifCounter: number = 0;\n private originalStdoutWrite:\n | ((\n chunk: string | Uint8Array, // `chunk` can be either a string or a Uint8Array\n encoding?: BufferEncoding, // `encoding` is optional and should be a BufferEncoding\n callback?: (err?: Error | null) => void // `callback` is optional and a function\n ) => boolean)\n | null = null;\n private extraLines: number = 0;\n private isUpdating: boolean = false;\n private config: IntlayerConfig;\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {\n this.config = getConfiguration();\n }\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set(\n [...localDictionariesKeys, ...distantDictionariesKeys].sort(\n sortAlphabetically\n )\n )\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Start spinner timer\n this.startSpinner();\n\n // Update all status lines (this will output the initial statuses)\n this.updateAllStatusLines();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n }\n }\n }\n\n // Call updateAllStatusLines() to refresh the output\n this.updateAllStatusLines();\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n // Method to update the terminal output\n private updateOutput(content: string) {\n if (this.config.log.mode !== 'verbose') return;\n\n // Monkey-patch process.stdout.write to keep track of extra lines\n if (!this.originalStdoutWrite) {\n this.originalStdoutWrite = process.stdout.write.bind(process.stdout);\n this.extraLines = 0;\n\n const write = (\n chunk: string | Uint8Array, // `chunk` can be either a string or a Uint8Array\n encoding?: BufferEncoding, // `encoding` is optional and should be a BufferEncoding\n callback?: (err?: Error | null) => void // `callback` is optional and a function\n ) => {\n const str = typeof chunk === 'string' ? chunk : chunk.toString();\n const newLines = (str.match(/\\n/g) ?? []).length;\n\n // If the write is not initiated by Logger's updateOutput method\n if (!this.isUpdating) {\n this.extraLines += newLines;\n }\n\n return this.originalStdoutWrite!(chunk, encoding, callback);\n };\n\n process.stdout.write = write as typeof process.stdout.write;\n }\n\n // Set a flag to indicate that updateOutput is running\n this.isUpdating = true;\n\n // Adjust lineDifCounter if LINE_DETECTOR is not the first line\n const contentLines = content.split('\\n');\n const indexOfLineDetector = contentLines.indexOf(LINE_DETECTOR.trim());\n\n if (indexOfLineDetector > 0) {\n // LINE_DETECTOR is not at the first line\n this.lineDifCounter = indexOfLineDetector;\n } else {\n this.lineDifCounter = 0;\n }\n\n // Calculate total lines to move up\n const totalLinesToMoveUp =\n this.previousLineCount + this.lineDifCounter + this.extraLines;\n\n // Move cursor up by totalLinesToMoveUp\n readline.moveCursor(process.stdout, 0, -totalLinesToMoveUp);\n\n // Clear all lines downwards\n readline.clearScreenDown(process.stdout);\n\n // Write the updated content\n contentLines.forEach((line) => {\n process.stdout.write(`${line}\\x1b[K\\n`);\n });\n\n // Update previousLineCount\n this.previousLineCount = contentLines.length;\n\n // Reset extraLines counter and updating flag\n this.extraLines = 0;\n this.isUpdating = false;\n }\n\n public stop() {\n this.stopSpinner();\n }\n\n public updateStatus(\n dictionaries: {\n dictionaryKey: string;\n type: 'local' | 'distant';\n status: Partial<State>;\n }[]\n ) {\n for (const { dictionaryKey, type, status } of dictionaries) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n }\n\n // Update the display after status change\n this.updateAllStatusLines();\n }\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = `${statusObj.dictionaryKey}${' '.repeat(keyPadding)}`;\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon = SPINNER_FRAMES[state.spinnerFrameIndex! % SPINNER_FRAMES.length];\n colorStart = BLUE;\n colorEnd = RESET;\n } else if (state.status === 'error') {\n colorStart = RED;\n colorEnd = RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = GREEN;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n // Format the status block\n const statusBlock = `${GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `${this.config.log.prefix}- ${paddedKey} ${states.join(' ')}`;\n }\n\n // Replace logUpdate calls with your custom methods\n private updateAllStatusLines() {\n const terminalHeight = process.stdout.rows;\n const maxVisibleLines = terminalHeight - 1;\n\n const lines = this.dictionariesStatuses.map((statusObj) => {\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % SPINNER_FRAMES.length;\n }\n });\n return this.getStatusLine(statusObj);\n });\n\n let content;\n\n if (lines.length > maxVisibleLines) {\n const visibleLines = lines.slice(0, maxVisibleLines - 5);\n const summary = `${this.config.log.prefix}... and ${lines.length - visibleLines.length} more`;\n content = LINE_DETECTOR + visibleLines.join('\\n') + '\\n' + summary;\n } else {\n content = lines.join('\\n');\n }\n\n this.updateOutput(content);\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAqB;AACrB,oBAAsD;AACtD,mBAAmC;AAgBnC,MAAM,gBAAgB;AACtB,MAAM,iBAAiB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAGxE,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,MAAM;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;AAAA,MACb,OAAO;AACL,qBAAa;AACb,mBAAW;AAAA,MACb;AAGA,YAAM,cAAc,GAAG,SAAS,IAAI,MAAM,IAAI,KAAK,UAAU,GAAG,IAAI,IAAI,MAAM,MAAM,GAAG,SAAS,IAAI,QAAQ;AAE5G,aAAO,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ;AAAA,IAC/C,CAAC;AAED,WAAO,GAAG,KAAK,OAAO,IAAI,MAAM,KAAK,SAAS,IAAI,OAAO,KAAK,GAAG,CAAC;AAAA,EACpE;AAAA;AAAA,EAGQ,uBAAuB;AAC7B,UAAM,iBAAiB,QAAQ,OAAO;AACtC,UAAM,kBAAkB,iBAAiB;AAEzC,UAAM,QAAQ,KAAK,qBAAqB,IAAI,CAAC,cAAc;AACzD,gBAAU,MAAM,QAAQ,CAAC,UAAU;AACjC,YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,eAAe;AAAA,QACpD;AAAA,MACF,CAAC;AACD,aAAO,KAAK,cAAc,SAAS;AAAA,IACrC,CAAC;AAED,QAAI;AAEJ,QAAI,MAAM,SAAS,iBAAiB;AAClC,YAAM,eAAe,MAAM,MAAM,GAAG,kBAAkB,CAAC;AACvD,YAAM,UAAU,GAAG,KAAK,OAAO,IAAI,MAAM,WAAW,MAAM,SAAS,aAAa,MAAM;AACtF,gBAAU,gBAAgB,aAAa,KAAK,IAAI,IAAI,OAAO;AAAA,IAC7D,OAAO;AACL,gBAAU,MAAM,KAAK,IAAI;AAAA,IAC3B;AAEA,SAAK,aAAa,OAAO;AAAA,EAC3B;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":["readline"]}
|
|
1
|
+
{"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import readline from 'readline';\nimport { type IntlayerConfig, getConfiguration } from '@intlayer/config';\nimport { sortAlphabetically } from './utils';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nconst LINE_DETECTOR = '\\u200B\\u200B\\u200B'; // Three zero-width spaces\nconst SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n// ANSI color codes\nconst RESET = '\\x1b[0m';\nconst GREEN = '\\x1b[32m';\nconst RED = '\\x1b[31m';\nconst BLUE = '\\x1b[34m';\nconst GREY = '\\x1b[90m';\nconst GREY_DARK = '\\x1b[90m';\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n private previousLineCount: number = 0;\n private lineDifCounter: number = 0;\n private originalStdoutWrite:\n | ((\n chunk: string | Uint8Array, // `chunk` can be either a string or a Uint8Array\n encoding?: BufferEncoding, // `encoding` is optional and should be a BufferEncoding\n callback?: (err?: Error | null) => void // `callback` is optional and a function\n ) => boolean)\n | null = null;\n private extraLines: number = 0;\n private isUpdating: boolean = false;\n private config?: IntlayerConfig;\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[],\n configuration: IntlayerConfig = getConfiguration()\n ) {\n this.config = configuration;\n\n const allKeys = Array.from(\n new Set(\n [...localDictionariesKeys, ...distantDictionariesKeys].sort(\n sortAlphabetically\n )\n )\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Start spinner timer\n this.startSpinner();\n\n // Update all status lines (this will output the initial statuses)\n this.updateAllStatusLines();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n }\n }\n }\n\n // Call updateAllStatusLines() to refresh the output\n this.updateAllStatusLines();\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n // Method to update the terminal output\n private updateOutput(content: string) {\n if (this.config?.log.mode !== 'verbose') return;\n\n // Monkey-patch process.stdout.write to keep track of extra lines\n if (!this.originalStdoutWrite) {\n this.originalStdoutWrite = process.stdout.write.bind(process.stdout);\n this.extraLines = 0;\n\n const write = (\n chunk: string | Uint8Array, // `chunk` can be either a string or a Uint8Array\n encoding?: BufferEncoding, // `encoding` is optional and should be a BufferEncoding\n callback?: (err?: Error | null) => void // `callback` is optional and a function\n ) => {\n const str = typeof chunk === 'string' ? chunk : chunk.toString();\n const newLines = (str.match(/\\n/g) ?? []).length;\n\n // If the write is not initiated by Logger's updateOutput method\n if (!this.isUpdating) {\n this.extraLines += newLines;\n }\n\n return this.originalStdoutWrite!(chunk, encoding, callback);\n };\n\n process.stdout.write = write as typeof process.stdout.write;\n }\n\n // Set a flag to indicate that updateOutput is running\n this.isUpdating = true;\n\n // Adjust lineDifCounter if LINE_DETECTOR is not the first line\n const contentLines = content.split('\\n');\n const indexOfLineDetector = contentLines.indexOf(LINE_DETECTOR.trim());\n\n if (indexOfLineDetector > 0) {\n // LINE_DETECTOR is not at the first line\n this.lineDifCounter = indexOfLineDetector;\n } else {\n this.lineDifCounter = 0;\n }\n\n // Calculate total lines to move up\n const totalLinesToMoveUp =\n this.previousLineCount + this.lineDifCounter + this.extraLines;\n\n // Move cursor up by totalLinesToMoveUp\n readline.moveCursor(process.stdout, 0, -totalLinesToMoveUp);\n\n // Clear all lines downwards\n readline.clearScreenDown(process.stdout);\n\n // Write the updated content\n contentLines.forEach((line) => {\n process.stdout.write(`${line}\\x1b[K\\n`);\n });\n\n // Update previousLineCount\n this.previousLineCount = contentLines.length;\n\n // Reset extraLines counter and updating flag\n this.extraLines = 0;\n this.isUpdating = false;\n }\n\n public stop() {\n this.stopSpinner();\n }\n\n public updateStatus(\n dictionaries: {\n dictionaryKey: string;\n type: 'local' | 'distant';\n status: Partial<State>;\n }[]\n ) {\n for (const { dictionaryKey, type, status } of dictionaries) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n }\n\n // Update the display after status change\n this.updateAllStatusLines();\n }\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = `${statusObj.dictionaryKey}${' '.repeat(keyPadding)}`;\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon = SPINNER_FRAMES[state.spinnerFrameIndex! % SPINNER_FRAMES.length];\n colorStart = BLUE;\n colorEnd = RESET;\n } else if (state.status === 'error') {\n colorStart = RED;\n colorEnd = RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = GREEN;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n // Format the status block\n const statusBlock = `${GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `${this.config?.log.prefix}- ${paddedKey} ${states.join(' ')}`;\n }\n\n // Replace logUpdate calls with your custom methods\n private updateAllStatusLines() {\n const terminalHeight = process.stdout.rows;\n const maxVisibleLines = terminalHeight - 1;\n\n const lines = this.dictionariesStatuses.map((statusObj) => {\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % SPINNER_FRAMES.length;\n }\n });\n return this.getStatusLine(statusObj);\n });\n\n let content;\n\n if (lines.length > maxVisibleLines) {\n const visibleLines = lines.slice(0, maxVisibleLines - 5);\n const summary = `${this.config?.log.prefix}... and ${lines.length - visibleLines.length} more`;\n content = LINE_DETECTOR + visibleLines.join('\\n') + '\\n' + summary;\n } else {\n content = lines.join('\\n');\n }\n\n this.updateOutput(content);\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAqB;AACrB,oBAAsD;AACtD,mBAAmC;AAgBnC,MAAM,gBAAgB;AACtB,MAAM,iBAAiB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAGxE,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,MAAM;AACZ,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,YAAY;AAElB,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,eAAsC;AAAA,EACtC,yBAAiC;AAAA,EACjC,oBAA4B;AAAA,EAC5B,iBAAyB;AAAA,EACzB,sBAMG;AAAA,EACH,aAAqB;AAAA,EACrB,aAAsB;AAAA,EACtB;AAAA;AAAA,EAGR,OAAe;AAAA,EAEP,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAc,cAAsB;AAClC,QAAI,CAAC,OAAO,UAAU;AACpB,aAAO,WAAW,IAAI,OAAO;AAAA,IAC/B;AACA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEO,KACL,uBACA,yBACA,oBAAgC,gCAAiB,GACjD;A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,CAAC,cAAc;AACzD,gBAAU,MAAM,QAAQ,CAAC,UAAU;AACjC,YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,eAAe;AAAA,QACpD;AAAA,MACF,CAAC;AACD,aAAO,KAAK,cAAc,SAAS;AAAA,IACrC,CAAC;AAED,QAAI;AAEJ,QAAI,MAAM,SAAS,iBAAiB;AAClC,YAAM,eAAe,MAAM,MAAM,GAAG,kBAAkB,CAAC;AACvD,YAAM,UAAU,GAAG,KAAK,QAAQ,IAAI,MAAM,WAAW,MAAM,SAAS,aAAa,MAAM;AACvF,gBAAU,gBAAgB,aAAa,KAAK,IAAI,IAAI,OAAO;AAAA,IAC7D,OAAO;AACL,gBAAU,MAAM,KAAK,IAAI;AAAA,IAC3B;AAEA,SAAK,aAAa,OAAO;AAAA,EAC3B;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":["readline"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/prepareContentDeclaration.ts"],"sourcesContent":["import {\n deepTransformNode,\n type Plugins,\n type Dictionary,\n NodeType,\n type FileContent,\n type
|
|
1
|
+
{"version":3,"sources":["../../src/prepareContentDeclaration.ts"],"sourcesContent":["import {\n deepTransformNode,\n type Plugins,\n type Dictionary,\n NodeType,\n type FileContent,\n type FileContentConstructor,\n type MarkdownContent,\n type InsertionContent,\n type MarkdownContentConstructor,\n type InsertionContentConstructor,\n} from '@intlayer/core';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { join } from 'path';\n\n/**\n * Write file plugin\n */\n\nconst writeFilePlugin: Plugins = {\n id: 'write-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent) => {\n const fileContent = node.content;\n const filePath = node.fixedPath;\n\n if (typeof fileContent !== 'string') {\n throw new Error('File content must be a string');\n }\n\n if (typeof filePath !== 'string') {\n throw new Error('File path must be a string');\n }\n\n // Write the file to the file system\n try {\n const abolsuteFilePath = join(process.cwd(), filePath);\n\n // Create the file directory if it doesn't exist\n const fileDirectory = join(process.cwd(), filePath);\n if (!fileDirectory.startsWith(process.cwd())) {\n throw new Error('File directory not found');\n }\n\n if (!existsSync(fileDirectory)) {\n mkdirSync(fileDirectory, { recursive: true });\n }\n\n // Write the file\n writeFileSync(abolsuteFilePath, fileContent);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n\n const transformedFileContent: FileContentConstructor = {\n nodeType: NodeType.File,\n [NodeType.File]: node.file,\n };\n\n return transformedFileContent;\n },\n};\n\n/**\n * Markdown file plugin\n */\n\nconst mardownFilePlugin: Plugins = {\n id: 'markdown-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const simplifiedMarkdownNode: MarkdownContentConstructor = {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: deepTransformNode(node.markdown, props),\n };\n\n return simplifiedMarkdownNode;\n },\n};\n\n/**\n * Injection file plugin\n */\n\nconst insertionFilePlugin: Plugins = {\n id: 'insertion-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const simplifiedInsertionNode: InsertionContentConstructor = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: deepTransformNode(node.insertion, props),\n };\n\n return simplifiedInsertionNode;\n },\n};\n\nexport const prepareContentDeclaration = async (dictionary: Dictionary) =>\n deepTransformNode(dictionary, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [writeFilePlugin, mardownFilePlugin, insertionFilePlugin],\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAWO;AACP,gBAAqD;AACrD,kBAAqB;AAMrB,MAAM,kBAA2B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AI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,qBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAOA,uBAAsB;AAC/D,UAAM,0BAAuD;AAAA,MAC3D,UAAU,qBAAS;AAAA,MACnB,CAAC,qBAAS,SAAS,GAAGA,mBAAkB,KAAK,WAAW,KAAK;AAAA,IAC/D;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,4BAA4B,OAAO,mBAC9C,+BAAkB,YAAY;AAAA,EAC5B,eAAe,WAAW;AAAA,EAC1B,SAAS,CAAC;AAAA,EACV,SAAS,CAAC,iBAAiB,mBAAmB,mBAAmB;AACnE,CAAC;","names":["deepTransformNode"]}
|
|
@@ -29,18 +29,22 @@ var import_createDictionaryEntryPoint = require('./transpiler/dictionary_to_main
|
|
|
29
29
|
var import_dictionary_to_type = require('./transpiler/dictionary_to_type/index.cjs');
|
|
30
30
|
var import_writeConfiguration = require('./writeConfiguration/index.cjs');
|
|
31
31
|
var import_listDictionariesPath = require('./listDictionariesPath.cjs');
|
|
32
|
-
const prepareIntlayer = async (configuration = (0, import_config.getConfiguration)()) => {
|
|
33
|
-
(0, import_cleanOutputDir.cleanOutputDir)();
|
|
32
|
+
const prepareIntlayer = async (configuration = (0, import_config.getConfiguration)(), projectRequire = import_config.ESMxCJSRequire) => {
|
|
33
|
+
(0, import_cleanOutputDir.cleanOutputDir)(configuration);
|
|
34
34
|
(0, import_config.appLogger)("Output directory cleaned", {
|
|
35
35
|
isVerbose: true
|
|
36
36
|
});
|
|
37
37
|
const files = (0, import_listDictionariesPath.listDictionaries)(configuration);
|
|
38
|
-
const dictionaries = await (0, import_loadDictionaries.loadDictionaries)(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const dictionaries = await (0, import_loadDictionaries.loadDictionaries)(
|
|
39
|
+
files,
|
|
40
|
+
configuration,
|
|
41
|
+
projectRequire
|
|
42
|
+
);
|
|
43
|
+
const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(dictionaries, configuration);
|
|
44
|
+
(0, import_dictionary_to_type.createTypes)(dictionariesPaths, configuration);
|
|
45
|
+
(0, import_createDictionaryEntryPoint.createDictionaryEntryPoint)(configuration);
|
|
42
46
|
(0, import_config.appLogger)("Dictionaries built");
|
|
43
|
-
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
47
|
+
(0, import_dictionary_to_type.createModuleAugmentation)(configuration);
|
|
44
48
|
(0, import_config.appLogger)("Module augmentation built", {
|
|
45
49
|
isVerbose: true
|
|
46
50
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\nimport { listDictionaries } from './listDictionariesPath';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration()\n) => {\n cleanOutputDir();\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\nimport { listDictionaries } from './listDictionariesPath';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n) => {\n cleanOutputDir(configuration);\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(\n files,\n configuration,\n projectRequire\n );\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries, configuration);\n\n createTypes(dictionariesPaths, configuration);\n\n createDictionaryEntryPoint(configuration);\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation(configuration);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AACP,4BAA+B;AAC/B,8BAAiC;AACjC,4CAAgC;AAChC,wCAA2C;AAC3C,gCAGO;AACP,gCAAmC;AACnC,kCAAiC;AAE1B,MAAM,kBAAkB,OAC7B,oBAAgC,gCAAiB,GACjD,iBAAiB,iCACd;AACH,4CAAe,aAAa;AAE5B,+BAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,YAAkB,8CAAiB,aAAa;AAEtD,QAAM,eAAe,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,oBAAoB,UAAM,uDAAgB,cAAc,aAAa;AAE3E,6CAAY,mBAAmB,aAAa;AAE5C,oEAA2B,aAAa;AAExC,+BAAU,oBAAoB;AAE9B,0DAAyB,aAAa;AAEtC,+BAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,oDAAmB,aAAa;AAEhC,+BAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -23,17 +23,19 @@ __export(buildI18nextDictionary_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(buildI18nextDictionary_exports);
|
|
24
24
|
var import_convertContentDeclarationInto18nDictionaries = require('./convertContentDeclarationInto18nDictionaries.cjs');
|
|
25
25
|
var import_writeDictionary = require('./writeDictionary.cjs');
|
|
26
|
-
|
|
26
|
+
var import_config = require("@intlayer/config");
|
|
27
|
+
const buildI18nDictionary = async (contentDeclarations, configuration = (0, import_config.getConfiguration)()) => {
|
|
27
28
|
const dictionariesDeclaration = contentDeclarations.reduce((acc, dictionary) => {
|
|
28
29
|
const { key, content } = dictionary;
|
|
29
|
-
const i18Content = (0, import_convertContentDeclarationInto18nDictionaries.createI18nextDictionaries)(content);
|
|
30
|
+
const i18Content = (0, import_convertContentDeclarationInto18nDictionaries.createI18nextDictionaries)(content, configuration);
|
|
30
31
|
return {
|
|
31
32
|
...acc,
|
|
32
33
|
[key]: i18Content
|
|
33
34
|
};
|
|
34
35
|
}, {});
|
|
35
36
|
const dictionariesPaths = await (0, import_writeDictionary.writeDictionary)(
|
|
36
|
-
dictionariesDeclaration
|
|
37
|
+
dictionariesDeclaration,
|
|
38
|
+
configuration
|
|
37
39
|
);
|
|
38
40
|
return dictionariesPaths;
|
|
39
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { createI18nextDictionaries } from './convertContentDeclarationInto18nDictionaries';\nimport {\n writeDictionary,\n type DictionariesDeclaration,\n} from './writeDictionary';\n\n/**\n * This function transpile content declaration to i18n dictionaries\n */\nexport const buildI18nDictionary = async (\n contentDeclarations: Dictionary[]\n) => {\n // Create dictionaries for each nested content and format them\n const dictionariesDeclaration: DictionariesDeclaration =\n contentDeclarations.reduce((acc, dictionary) => {\n const { key, content } = dictionary;\n const i18Content = createI18nextDictionaries(content);\n\n return {\n ...acc,\n [key]: i18Content,\n };\n }, {});\n\n // Write the dictionaries to the file system\n const dictionariesPaths: string[] = await writeDictionary(\n dictionariesDeclaration\n );\n\n return dictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0DAA0C;AAC1C,6BAGO;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { createI18nextDictionaries } from './convertContentDeclarationInto18nDictionaries';\nimport {\n writeDictionary,\n type DictionariesDeclaration,\n} from './writeDictionary';\nimport { getConfiguration } from '@intlayer/config';\n\n/**\n * This function transpile content declaration to i18n dictionaries\n */\nexport const buildI18nDictionary = async (\n contentDeclarations: Dictionary[],\n configuration = getConfiguration()\n) => {\n // Create dictionaries for each nested content and format them\n const dictionariesDeclaration: DictionariesDeclaration =\n contentDeclarations.reduce((acc, dictionary) => {\n const { key, content } = dictionary;\n const i18Content = createI18nextDictionaries(content, configuration);\n\n return {\n ...acc,\n [key]: i18Content,\n };\n }, {});\n\n // Write the dictionaries to the file system\n const dictionariesPaths: string[] = await writeDictionary(\n dictionariesDeclaration,\n configuration\n );\n\n return dictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0DAA0C;AAC1C,6BAGO;AACP,oBAAiC;AAK1B,MAAM,sBAAsB,OACjC,qBACA,oBAAgB,gCAAiB,MAC9B;AAEH,QAAM,0BACJ,oBAAoB,OAAO,CAAC,KAAK,eAAe;AAC9C,UAAM,EAAE,KAAK,QAAQ,IAAI;AACzB,UAAM,iBAAa,+EAA0B,SAAS,aAAa;AAEnE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG;AAAA,IACT;AAAA,EACF,GAAG,CAAC,CAAC;AAGP,QAAM,oBAA8B,UAAM;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -24,9 +24,6 @@ module.exports = __toCommonJS(convertContentDeclarationInto18nDictionaries_expor
|
|
|
24
24
|
var import_config = require("@intlayer/config");
|
|
25
25
|
var import_core = require("@intlayer/core");
|
|
26
26
|
var import_convertPluralsValues = require('./convertPluralsValues.cjs');
|
|
27
|
-
const {
|
|
28
|
-
internationalization: { locales }
|
|
29
|
-
} = (0, import_config.getConfiguration)();
|
|
30
27
|
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined" && typeof node?.type !== "undefined";
|
|
31
28
|
const buildDictionary = (content, locale) => {
|
|
32
29
|
if (
|
|
@@ -88,7 +85,8 @@ const buildDictionary = (content, locale) => {
|
|
|
88
85
|
}
|
|
89
86
|
return content;
|
|
90
87
|
};
|
|
91
|
-
const createI18nextDictionaries = (content) => {
|
|
88
|
+
const createI18nextDictionaries = (content, configuration = (0, import_config.getConfiguration)()) => {
|
|
89
|
+
const { locales } = configuration.internationalization;
|
|
92
90
|
const result = locales.reduce(
|
|
93
91
|
(acc, locale) => ({
|
|
94
92
|
...acc,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: ContentNode, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const contentState = (content as TranslationContent)[NodeType.Translation];\n const result = contentState[locale as keyof typeof contentState];\n\n return buildDictionary(result as ContentNode, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as ContentNode,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object' &&\n Array.isArray(content)\n ) {\n const result: unknown[] = [];\n\n Object.keys(content).forEach((dictionaryValue) => {\n result.push(\n buildDictionary(\n content[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n )\n );\n });\n\n return result;\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content as Record<string, unknown>).forEach(\n (dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content?.[\n dictionaryValue as keyof typeof content\n ] as unknown as ContentNode,\n locale\n );\n }\n );\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nextDictionaries = (\n content: ContentNode,\n configuration = getConfiguration()\n): I18nextDictionariesOutput => {\n const { locales } = configuration.internationalization;\n\n // Map dictionaries for each locale\n const result: I18nextDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAMO;AACP,kCAAqC;AAKrC,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eACrB,OAAO,MAAM,UAAU,eACvB,OAAO,MAAM,SAAS;AAGxB,MAAM,kBAAkB,CAAC,SAAsB,WAA6B;AAC1E;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,eAAgB,QAA+B,qBAAS,WAAW;AACzE,UAAM,SAAS,aAAa,MAAmC;AAE/D,WAAO,gBAAgB,QAAuB,MAAM;AAAA,EACtD;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,UAAmC,CAAC;AAE1C,WAAO;AAAA,MACJ,QAAwC,qBAAS,WAAW;AAAA,IAC/D,EAAE,QAAQ,CAAC,aAAa;AACtB,YAAM,mBAAe,kDAAqB,QAAQ;AAElD,YAAM,QAAS,QACb,QACF;AAEA,cAAQ,GAAG,YAAY,IAAI,YAAY,EAAE,IAAI;AAAA,QAC3C;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,YAAY,OAAkC;AAAA,IAC9C;AACA,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA;AAAA,IAEE,OAAO,YAAY,YACnB,MAAM,QAAQ,OAAO;AAAA,IACrB;AACA,UAAM,SAAoB,CAAC;AAE3B,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,oBAAoB;AAChD,aAAO;AAAA,QACL;AAAA,UACE,QAAQ,eAAuC;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,OAAO,YAAY;AAAA,IACnB;AACA,UAAM,SAAkC,CAAC;AAEzC,WAAO,KAAK,OAAkC,EAAE;AAAA,MAC9C,CAAC,oBAAoB;AACnB,eAAO,eAAe,IAAI;AAAA,UACxB,UACE,eACF;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,4BAA4B,CACvC,SACA,oBAAgB,gCAAiB,MACH;AAC9B,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,QAAM,SAAoC,QAAQ;AAAA,IAChD,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs
CHANGED
|
@@ -24,15 +24,14 @@ module.exports = __toCommonJS(writeDictionary_exports);
|
|
|
24
24
|
var import_promises = require("fs/promises");
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_config = require("@intlayer/config");
|
|
27
|
-
const
|
|
28
|
-
const { i18nextResourcesDir } = content;
|
|
29
|
-
const writeDictionary = async (dictionariesDeclaration) => {
|
|
27
|
+
const writeDictionary = async (dictionariesDeclaration, configuration = (0, import_config.getConfiguration)()) => {
|
|
28
|
+
const { i18nextResourcesDir } = configuration.content;
|
|
30
29
|
const resultDictionariesPaths = [];
|
|
31
30
|
for (const [nameSpace, localContent] of Object.entries(
|
|
32
31
|
dictionariesDeclaration
|
|
33
32
|
)) {
|
|
34
|
-
for await (const [locale,
|
|
35
|
-
const contentString = JSON.stringify(
|
|
33
|
+
for await (const [locale, content] of Object.entries(localContent)) {
|
|
34
|
+
const contentString = JSON.stringify(content);
|
|
36
35
|
const outputFileName = `${nameSpace}.json`;
|
|
37
36
|
const resultDirPath = (0, import_path.resolve)(i18nextResourcesDir, locale);
|
|
38
37
|
const resultFilePath = (0, import_path.resolve)(resultDirPath, outputFileName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { I18nextDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { I18nextDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\nexport type DictionariesDeclaration = Record<string, I18nextDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration,\n configuration = getConfiguration()\n) => {\n const { i18nextResourcesDir } = configuration.content;\n\n const resultDictionariesPaths: string[] = [];\n\n for (const [nameSpace, localContent] of Object.entries(\n dictionariesDeclaration\n )) {\n for await (const [locale, content] of Object.entries(localContent)) {\n const contentString = JSON.stringify(content);\n\n const outputFileName = `${nameSpace}.json`;\n const resultDirPath = resolve(i18nextResourcesDir, locale);\n const resultFilePath = resolve(resultDirPath, outputFileName);\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resultDirPath, { recursive: true });\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAQ1B,MAAM,kBAAkB,OAC7B,yBACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,oBAAoB,IAAI,cAAc;AAE9C,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQ,OAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAU,OAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,oBAAgB,qBAAQ,qBAAqB,MAAM;AACzD,YAAM,qBAAiB,qBAAQ,eAAe,cAAc;AAG5D,gBAAM,uBAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAG9C,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,MACxD,CAAC;AAED,8BAAwB,KAAK,cAAc;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -24,15 +24,13 @@ module.exports = __toCommonJS(declaration_file_to_dictionary_exports);
|
|
|
24
24
|
var import_config = require("@intlayer/config");
|
|
25
25
|
var import_i18next_dictionary = require('./i18next_dictionary/index.cjs');
|
|
26
26
|
var import_intlayer_dictionary = require('./intlayer_dictionary/index.cjs');
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
} = (0, import_config.getConfiguration)();
|
|
30
|
-
const buildDictionary = async (dictionaries) => {
|
|
27
|
+
const buildDictionary = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
28
|
+
const { dictionaryOutput } = configuration.content;
|
|
31
29
|
if (dictionaryOutput.includes("i18next")) {
|
|
32
|
-
await (0, import_i18next_dictionary.buildI18nDictionary)(dictionaries);
|
|
30
|
+
await (0, import_i18next_dictionary.buildI18nDictionary)(dictionaries, configuration);
|
|
33
31
|
}
|
|
34
32
|
if (dictionaryOutput.includes("intlayer")) {
|
|
35
|
-
return await (0, import_intlayer_dictionary.buildIntlayerDictionary)(dictionaries);
|
|
33
|
+
return await (0, import_intlayer_dictionary.buildIntlayerDictionary)(dictionaries, configuration);
|
|
36
34
|
}
|
|
37
35
|
return [];
|
|
38
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18next_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18next_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nexport const buildDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<string[]> => {\n const { dictionaryOutput } = configuration.content;\n\n if (dictionaryOutput.includes('i18next')) {\n await buildI18nDictionary(dictionaries, configuration);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(dictionaries, configuration);\n }\n\n return [];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,gCAAoC;AACpC,iCAAwC;AAEjC,MAAM,kBAAkB,OAC7B,cACA,oBAAgB,gCAAiB,MACX;AACtB,QAAM,EAAE,iBAAiB,IAAI,cAAc;AAE3C,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,cAAM,+CAAoB,cAAc,aAAa;AAAA,EACvD;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,UAAM,oDAAwB,cAAc,aAAa;AAAA,EAClE;AAEA,SAAO,CAAC;AACV;","names":[]}
|
|
@@ -25,12 +25,12 @@ var import_promises = require("fs/promises");
|
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_config = require("@intlayer/config");
|
|
27
27
|
var import_writeDictionary = require('./writeDictionary.cjs');
|
|
28
|
-
const
|
|
29
|
-
const { dictionariesDir } = content;
|
|
30
|
-
const buildIntlayerDictionary = async (contentDeclarations) => {
|
|
28
|
+
const buildIntlayerDictionary = async (contentDeclarations, configuration = (0, import_config.getConfiguration)()) => {
|
|
29
|
+
const { dictionariesDir } = configuration.content;
|
|
31
30
|
await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), { recursive: true });
|
|
32
31
|
const dictionariesPaths = await (0, import_writeDictionary.writeDictionary)(
|
|
33
|
-
contentDeclarations
|
|
32
|
+
contentDeclarations,
|
|
33
|
+
configuration
|
|
34
34
|
);
|
|
35
35
|
return dictionariesPaths;
|
|
36
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { writeDictionary } from './writeDictionary';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { writeDictionary } from './writeDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n contentDeclarations: (DictionaryAPI | Dictionary)[],\n configuration = getConfiguration()\n) => {\n const { dictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const dictionariesPaths: string[] = await writeDictionary(\n contentDeclarations as Dictionary[],\n configuration\n );\n\n return dictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsB;AACtB,kBAAwB;AAGxB,oBAAiC;AAEjC,6BAAgC;AAKzB,MAAM,0BAA0B,OACrC,qBACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,oBAA8B,UAAM;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs
CHANGED
|
@@ -24,12 +24,12 @@ module.exports = __toCommonJS(writeDictionary_exports);
|
|
|
24
24
|
var import_promises = require("fs/promises");
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_config = require("@intlayer/config");
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const writeDictionary = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
28
|
+
const { dictionariesDir } = configuration.content;
|
|
29
29
|
const resultDictionariesPaths = [];
|
|
30
30
|
for await (const dictionaryContent of dictionaries) {
|
|
31
|
-
const
|
|
32
|
-
const contentString =
|
|
31
|
+
const isDevelopment = process.env.NODE_ENV === "development";
|
|
32
|
+
const contentString = isDevelopment ? JSON.stringify(dictionaryContent, null, 2) : JSON.stringify(dictionaryContent);
|
|
33
33
|
const key = dictionaryContent.key;
|
|
34
34
|
const outputFileName = `${key}.json`;
|
|
35
35
|
const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nexport const writeDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n) => {\n const { dictionariesDir } = configuration.content;\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const isDevelopment = process.env.NODE_ENV === 'development';\n const contentString = isDevelopment\n ? JSON.stringify(dictionaryContent, null, 2)\n : JSON.stringify(dictionaryContent);\n\n const key = dictionaryContent.key;\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAC1B,kBAAwB;AACxB,oBAAiC;AAG1B,MAAM,kBAAkB,OAC7B,cACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAC1C,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,gBAAgB,QAAQ,IAAI,aAAa;AAC/C,UAAM,gBAAgB,gBAClB,KAAK,UAAU,mBAAmB,MAAM,CAAC,IACzC,KAAK,UAAU,iBAAiB;AAEpC,UAAM,MAAM,kBAAkB;AAC9B,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
|