@intlayer/chokidar 2.0.12 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chokidar/watcher.cjs +18 -26
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +101 -0
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -0
- package/dist/cjs/fetchDistantDictionaryKeys.cjs +50 -0
- package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +1 -0
- package/dist/cjs/index.cjs +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/index.cjs +29 -0
- package/dist/cjs/loadDictionaries/index.cjs.map +1 -0
- package/dist/cjs/{transpiler/declaration_file_to_dictionary/intlayer_dictionary → loadDictionaries}/loadContentDeclaration.cjs +23 -7
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +86 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -0
- package/dist/cjs/{transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs → loadDictionaries/loadDistantDictionaries.cjs} +15 -22
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +51 -0
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -0
- package/dist/cjs/log.cjs +255 -0
- package/dist/cjs/log.cjs.map +1 -0
- package/dist/cjs/mergeDictionaries.cjs +62 -0
- package/dist/cjs/mergeDictionaries.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs +13 -49
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.cjs +52 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +1 -1
- 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 -37
- 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/index.cjs +0 -2
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs +8 -10
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +46 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +8 -9
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +18 -16
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +67 -0
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -0
- package/dist/esm/fetchDistantDictionaryKeys.mjs +26 -0
- package/dist/esm/fetchDistantDictionaryKeys.mjs.map +1 -0
- package/dist/esm/index.mjs +10 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/index.mjs +5 -0
- package/dist/esm/loadDictionaries/index.mjs.map +1 -0
- package/dist/esm/{transpiler/declaration_file_to_dictionary/intlayer_dictionary → loadDictionaries}/loadContentDeclaration.mjs +22 -5
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +52 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +14 -0
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +27 -0
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -0
- package/dist/esm/log.mjs +221 -0
- package/dist/esm/log.mjs.map +1 -0
- package/dist/esm/mergeDictionaries.mjs +28 -0
- package/dist/esm/mergeDictionaries.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs +15 -54
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs +28 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +1 -1
- 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 +5 -38
- 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/index.mjs +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs +8 -10
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +22 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +9 -9
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
- package/dist/types/chokidar/index.d.ts +2 -0
- package/dist/types/chokidar/index.d.ts.map +1 -0
- package/dist/types/chokidar/watcher.d.ts +4 -0
- package/dist/types/chokidar/watcher.d.ts.map +1 -0
- package/dist/types/fetchDistantDictionaries.d.ts +12 -0
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -0
- package/dist/types/fetchDistantDictionaryKeys.d.ts +2 -0
- package/dist/types/fetchDistantDictionaryKeys.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/loadDictionaries/index.d.ts +5 -0
- package/dist/types/loadDictionaries/index.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +3 -0
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +3 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +8 -0
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +3 -0
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts.map +1 -0
- package/dist/types/log.d.ts +40 -0
- package/dist/types/log.d.ts.map +1 -0
- package/dist/types/mergeDictionaries.d.ts +5 -0
- package/dist/types/mergeDictionaries.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +6 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +7 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +2 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +2 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.d.ts +7 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +3 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +6 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +3 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts +6 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +3 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_main/createDictionaryList.d.ts +5 -0
- package/dist/types/transpiler/dictionary_to_main/createDictionaryList.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_main/index.d.ts +2 -0
- package/dist/types/transpiler/dictionary_to_main/index.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +6 -0
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts +6 -0
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_type/index.d.ts +3 -0
- package/dist/types/transpiler/dictionary_to_type/index.d.ts.map +1 -0
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +32 -16
- package/dist/cjs/chokidar/index.d.ts +0 -2
- package/dist/cjs/chokidar/watcher.d.ts +0 -5
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +0 -6
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +0 -8
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +0 -3
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.d.ts +0 -3
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +0 -6
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.d.ts +0 -44
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +0 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.d.ts +0 -10
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts +0 -8
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +0 -6
- package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +0 -7
- package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +0 -7
- package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +0 -2
- package/dist/cjs/utils.d.ts +0 -4
- package/dist/esm/chokidar/index.d.mts +0 -2
- package/dist/esm/chokidar/watcher.d.mts +0 -5
- package/dist/esm/index.d.mts +0 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.mts +0 -6
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.mts +0 -8
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.mts +0 -3
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.mts +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.d.mts +0 -3
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.mts +0 -6
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.d.mts +0 -44
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs +0 -21
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.mts +0 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.d.mts +0 -10
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.mts +0 -8
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -7
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -2
- package/dist/esm/utils.d.mts +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import { type Context, runInNewContext } from 'vm';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport type { DeclarationContent, Dictionary } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: ESMxCJSRequire,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nconst filterValidContentDeclaration = (\n contentDeclaration: DeclarationContent\n): DeclarationContent => {\n // @TODO Implement filtering of valid content declaration\n return contentDeclaration as unknown as DeclarationContent;\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nconst loadContentDeclaration = (\n contentDeclarationFilePath: string\n): DeclarationContent | undefined => {\n let contentDeclaration: DeclarationContent | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return ESMxCJSRequire(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidContentDeclaration(contentDeclaration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[]\n): Promise<Dictionary[]> => {\n const contentDeclarations = contentDeclarationFilePath.map(\n loadContentDeclaration\n );\n const resultDictionariesPaths: Dictionary[] = [];\n\n for await (const contentDeclaration of contentDeclarations) {\n if (!contentDeclaration) {\n continue;\n }\n\n const processedContentDeclaration =\n await processContentDeclaration(contentDeclaration);\n\n if (!processedContentDeclaration) {\n continue;\n }\n\n resultDictionariesPaths.push(processedContentDeclaration);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAuB,uBAAuB;AAC9C,SAAS,sBAAsB;AAE/B,SAA4B,iBAAmC;AAC/D,SAAS,iCAAiC;AAE1C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS;AACX;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;AAEA,MAAM,gCAAgC,CACpC,uBACuB;AAEvB,SAAO;AACT;AAOA,MAAM,yBAAyB,CAC7B,+BACmC;AACnC,MAAI,qBAAqD;AAEzD,QAAM,gBAAgB,2BAA2B,MAAM,GAAG,EAAE,IAAI,KAAK;AAErE,MAAI;AACF,QAAI,kBAAkB,QAAQ;AAE5B,aAAO,eAAe,0BAA0B;AAAA,IAClD;AAIA,UAAM,eAA4B,UAAU;AAAA,MAC1C,aAAa,CAAC,0BAA0B;AAAA,MAExC,GAAG;AAAA,IACL,CAAC;AAED,UAAM,qBAAqB,aAAa,cAAc,CAAC,EAAE;AAEzD,QAAI,CAAC,oBAAoB;AACvB,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,oBAAgB,oBAAoB,cAAc;AAElD,QACE,eAAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,2BAAqB,eAAe,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,2BAAqB,eAAe,OAAO;AAAA,IAC7C;AAEA,QAAI,OAAO,uBAAuB,aAAa;AAC7C,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,WAAO,8BAA8B,kBAAkB;AAAA,EACzD,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;AAEO,MAAM,0BAA0B,OACrC,+BAC0B;AAC1B,QAAM,sBAAsB,2BAA2B;AAAA,IACrD;AAAA,EACF;AACA,QAAM,0BAAwC,CAAC;AAE/C,mBAAiB,sBAAsB,qBAAqB;AAC1D,QAAI,CAAC,oBAAoB;AACvB;AAAA,IACF;AAEA,UAAM,8BACJ,MAAM,0BAA0B,kBAAkB;AAEpD,QAAI,CAAC,6BAA6B;AAChC;AAAA,IACF;AAEA,4BAAwB,KAAK,2BAA2B;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import merge from "deepmerge";
|
|
3
|
+
import { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys.mjs';
|
|
4
|
+
import { logger } from '../log.mjs';
|
|
5
|
+
import { mergeByKey } from '../mergeDictionaries.mjs';
|
|
6
|
+
import { loadContentDeclarations } from './loadContentDeclaration.mjs';
|
|
7
|
+
import { loadDistantDictionaries } from './loadDistantDictionaries.mjs';
|
|
8
|
+
const LOG_PREFIX = "[intlayer] ";
|
|
9
|
+
const loadDictionaries = async (contentDeclarationsPaths) => {
|
|
10
|
+
try {
|
|
11
|
+
const { editor } = getConfiguration({
|
|
12
|
+
verbose: true
|
|
13
|
+
});
|
|
14
|
+
console.info(`${LOG_PREFIX}Dictionaries:`);
|
|
15
|
+
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
|
|
16
|
+
const localDictionaries = await loadContentDeclarations(files);
|
|
17
|
+
const localDictionaryKeys = localDictionaries.map((dict) => dict.key);
|
|
18
|
+
logger.init(localDictionaryKeys, []);
|
|
19
|
+
for (const dict of localDictionaries) {
|
|
20
|
+
logger.updateStatus(dict.key, "local", { status: "built" });
|
|
21
|
+
}
|
|
22
|
+
let distantDictionaries = [];
|
|
23
|
+
let distantDictionaryKeys = [];
|
|
24
|
+
let mergedDictionaries = localDictionaries;
|
|
25
|
+
if (editor.clientId && editor.clientSecret) {
|
|
26
|
+
distantDictionaryKeys = await fetchDistantDictionaryKeys();
|
|
27
|
+
logger.addDictionaryKeys("distant", distantDictionaryKeys);
|
|
28
|
+
distantDictionaries = await loadDistantDictionaries({
|
|
29
|
+
dictionaryKeys: distantDictionaryKeys
|
|
30
|
+
});
|
|
31
|
+
if (editor.dictionaryPriorityStrategy === "distant_first") {
|
|
32
|
+
mergedDictionaries = merge(localDictionaries, distantDictionaries, {
|
|
33
|
+
arrayMerge: mergeByKey("key")
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
mergedDictionaries = merge(distantDictionaries, localDictionaries, {
|
|
37
|
+
arrayMerge: mergeByKey("key")
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
logger.stop();
|
|
42
|
+
return mergedDictionaries;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(error);
|
|
45
|
+
logger.stop();
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
loadDictionaries
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=loadDictionaries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration({\n verbose: true,\n });\n\n console.info(`${LOG_PREFIX}Dictionaries:`);\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] =\n await loadContentDeclarations(files);\n const localDictionaryKeys = localDictionaries.map((dict) => dict.key);\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n for (const dict of localDictionaries) {\n logger.updateStatus(dict.key, 'local', { status: 'built' });\n }\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', distantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: distantDictionaryKeys,\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 }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n console.error(error);\n // Ensure the logger is stopped\n logger.stop();\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,OAAO,WAAW;AAClB,SAAS,kCAAkC;AAC3C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AAExC,MAAM,aAAa;AAEZ,MAAM,mBAAmB,OAC9B,6BAC0B;AAC1B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,iBAAiB;AAAA,MAClC,SAAS;AAAA,IACX,CAAC;AAED,YAAQ,KAAK,GAAG,UAAU,eAAe;AAEzC,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBACJ,MAAM,wBAAwB,KAAK;AACrC,UAAM,sBAAsB,kBAAkB,IAAI,CAAC,SAAS,KAAK,GAAG;AAGpE,WAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,eAAW,QAAQ,mBAAmB;AACpC,aAAO,aAAa,KAAK,KAAK,SAAS,EAAE,QAAQ,QAAQ,CAAC;AAAA,IAC5D;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AACvC,QAAI,qBAAqB;AAEzB,QAAI,OAAO,YAAY,OAAO,cAAc;AAE1C,8BAAwB,MAAM,2BAA2B;AAGzD,aAAO,kBAAkB,WAAW,qBAAqB;AAGzD,4BAAsB,MAAM,wBAAwB;AAAA,QAClD,gBAAgB;AAAA,MAClB,CAAC;AACD,UAAI,OAAO,+BAA+B,iBAAiB;AAEzD,6BAAqB,MAAM,mBAAmB,qBAAqB;AAAA,UACjE,YAAY,WAAW,KAAK;AAAA,QAC9B,CAAC;AAAA,MACH,OAAO;AAEL,6BAAqB,MAAM,qBAAqB,mBAAmB;AAAA,UACjE,YAAY,WAAW,KAAK;AAAA,QAC9B,CAAC;AAAA,MACH;AAAA,IACF;AAGA,WAAO,KAAK;AAEZ,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAEnB,WAAO,KAAK;AACZ,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fetchDistantDictionaries } from '../fetchDistantDictionaries.mjs';
|
|
2
|
+
const loadDistantDictionaries = async (options) => {
|
|
3
|
+
try {
|
|
4
|
+
const distantDictionaries = await fetchDistantDictionaries(options);
|
|
5
|
+
return distantDictionaries;
|
|
6
|
+
} catch (error) {
|
|
7
|
+
console.error(error);
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
loadDistantDictionaries
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=loadDistantDictionaries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { fetchDistantDictionaries } from '../fetchDistantDictionaries';\n\ntype LoadDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n};\n\nexport const loadDistantDictionaries = async (\n options: LoadDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const distantDictionaries = await fetchDistantDictionaries(options);\n\n return distantDictionaries;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,gCAAgC;AAOlC,MAAM,0BAA0B,OACrC,YAC6B;AAC7B,MAAI;AACF,UAAM,sBAAsB,MAAM,yBAAyB,OAAO;AAElE,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mkdir } from "fs/promises";
|
|
2
|
+
import { resolve, relative } from "path";
|
|
3
|
+
import { getConfiguration } from "@intlayer/config";
|
|
4
|
+
import { loadContentDeclarations } from './loadContentDeclaration.mjs';
|
|
5
|
+
const loadLocalDictionaries = async (contentDeclarationsPaths) => {
|
|
6
|
+
const { content } = getConfiguration();
|
|
7
|
+
const { dictionariesDir, baseDir } = content;
|
|
8
|
+
if (typeof contentDeclarationsPaths === "string") {
|
|
9
|
+
contentDeclarationsPaths = [contentDeclarationsPaths];
|
|
10
|
+
}
|
|
11
|
+
await mkdir(resolve(dictionariesDir), { recursive: true });
|
|
12
|
+
const result = [];
|
|
13
|
+
for await (const contentDeclarationPath of contentDeclarationsPaths) {
|
|
14
|
+
const dictionary = await loadContentDeclarations([contentDeclarationPath]);
|
|
15
|
+
const relativeFilePath = relative(baseDir, contentDeclarationPath);
|
|
16
|
+
const dictionaryWithPath = {
|
|
17
|
+
...dictionary[0],
|
|
18
|
+
filePath: relativeFilePath
|
|
19
|
+
};
|
|
20
|
+
result.push(dictionaryWithPath);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
loadLocalDictionaries
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=loadLocalDictionaries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadLocalDictionaries.ts"],"sourcesContent":["import { mkdir } from 'fs/promises';\nimport { resolve, relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { loadContentDeclarations } from './loadContentDeclaration';\n\nexport const loadLocalDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n const { content } = getConfiguration();\n const { dictionariesDir, baseDir } = content;\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const result: Dictionary[] = [];\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const dictionary = await loadContentDeclarations([contentDeclarationPath]);\n\n const relativeFilePath = relative(baseDir, contentDeclarationPath);\n\n const dictionaryWithPath: Dictionary = {\n ...dictionary[0],\n filePath: relativeFilePath,\n };\n\n result.push(dictionaryWithPath);\n }\n\n return result;\n};\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,SAAS,gBAAgB;AAClC,SAAS,wBAAwB;AAEjC,SAAS,+BAA+B;AAEjC,MAAM,wBAAwB,OACnC,6BAC0B;AAC1B,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,QAAM,EAAE,iBAAiB,QAAQ,IAAI;AAErC,MAAI,OAAO,6BAA6B,UAAU;AAChD,+BAA2B,CAAC,wBAAwB;AAAA,EACtD;AAGA,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,SAAuB,CAAC;AAE9B,mBAAiB,0BAA0B,0BAA0B;AACnE,UAAM,aAAa,MAAM,wBAAwB,CAAC,sBAAsB,CAAC;AAEzE,UAAM,mBAAmB,SAAS,SAAS,sBAAsB;AAEjE,UAAM,qBAAiC;AAAA,MACrC,GAAG,WAAW,CAAC;AAAA,MACf,UAAU;AAAA,IACZ;AAEA,WAAO,KAAK,kBAAkB;AAAA,EAChC;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/log.mjs
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import * as readline from "readline";
|
|
2
|
+
class Logger {
|
|
3
|
+
dictionariesStatuses = [];
|
|
4
|
+
spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
5
|
+
spinnerTimer = null;
|
|
6
|
+
maxDictionaryKeyLength = 0;
|
|
7
|
+
// ANSI color codes
|
|
8
|
+
RESET = "\x1B[0m";
|
|
9
|
+
GREEN = "\x1B[32m";
|
|
10
|
+
RED = "\x1B[31m";
|
|
11
|
+
BLUE = "\x1B[34m";
|
|
12
|
+
GREY = "\x1B[90m";
|
|
13
|
+
GREY_DARK = "\x1B[90m";
|
|
14
|
+
// Singleton instance
|
|
15
|
+
static instance;
|
|
16
|
+
constructor() {
|
|
17
|
+
}
|
|
18
|
+
static getInstance() {
|
|
19
|
+
if (!Logger.instance) {
|
|
20
|
+
Logger.instance = new Logger();
|
|
21
|
+
}
|
|
22
|
+
return Logger.instance;
|
|
23
|
+
}
|
|
24
|
+
init(localDictionariesKeys, distantDictionariesKeys) {
|
|
25
|
+
const allKeys = Array.from(
|
|
26
|
+
/* @__PURE__ */ new Set([...localDictionariesKeys, ...distantDictionariesKeys])
|
|
27
|
+
);
|
|
28
|
+
this.maxDictionaryKeyLength = allKeys.reduce(
|
|
29
|
+
(max, key) => key.length > max ? key.length : max,
|
|
30
|
+
0
|
|
31
|
+
);
|
|
32
|
+
this.dictionariesStatuses = allKeys.map((dictionaryKey) => {
|
|
33
|
+
const states = [];
|
|
34
|
+
if (localDictionariesKeys.includes(dictionaryKey)) {
|
|
35
|
+
states.push({
|
|
36
|
+
type: "local",
|
|
37
|
+
status: "pending",
|
|
38
|
+
spinnerFrameIndex: 0
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (distantDictionariesKeys.includes(dictionaryKey)) {
|
|
42
|
+
states.push({
|
|
43
|
+
type: "distant",
|
|
44
|
+
status: "pending",
|
|
45
|
+
spinnerFrameIndex: 0
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
dictionaryKey,
|
|
50
|
+
state: states
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
for (const statusObj of this.dictionariesStatuses) {
|
|
54
|
+
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
55
|
+
}
|
|
56
|
+
this.startSpinner();
|
|
57
|
+
}
|
|
58
|
+
// New method to add dictionary keys after initialization
|
|
59
|
+
addDictionaryKeys(type, dictionaryKeys) {
|
|
60
|
+
for (const dictionaryKey of dictionaryKeys) {
|
|
61
|
+
if (dictionaryKey.length > this.maxDictionaryKeyLength) {
|
|
62
|
+
this.maxDictionaryKeyLength = dictionaryKey.length;
|
|
63
|
+
}
|
|
64
|
+
let statusObj = this.dictionariesStatuses.find(
|
|
65
|
+
(ds) => ds.dictionaryKey === dictionaryKey
|
|
66
|
+
);
|
|
67
|
+
if (!statusObj) {
|
|
68
|
+
statusObj = {
|
|
69
|
+
dictionaryKey,
|
|
70
|
+
state: []
|
|
71
|
+
};
|
|
72
|
+
this.dictionariesStatuses.push(statusObj);
|
|
73
|
+
const newState = {
|
|
74
|
+
type,
|
|
75
|
+
status: "pending",
|
|
76
|
+
spinnerFrameIndex: 0
|
|
77
|
+
};
|
|
78
|
+
statusObj.state.push(newState);
|
|
79
|
+
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
80
|
+
} else {
|
|
81
|
+
const existingState = statusObj.state.find((s) => s.type === type);
|
|
82
|
+
if (!existingState) {
|
|
83
|
+
const newState = {
|
|
84
|
+
type,
|
|
85
|
+
status: "pending",
|
|
86
|
+
spinnerFrameIndex: 0
|
|
87
|
+
};
|
|
88
|
+
statusObj.state.push(newState);
|
|
89
|
+
const lineIndex = this.dictionariesStatuses.indexOf(statusObj);
|
|
90
|
+
readline.moveCursor(
|
|
91
|
+
process.stdout,
|
|
92
|
+
0,
|
|
93
|
+
-(this.dictionariesStatuses.length - lineIndex)
|
|
94
|
+
);
|
|
95
|
+
readline.clearLine(process.stdout, 0);
|
|
96
|
+
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
97
|
+
readline.moveCursor(
|
|
98
|
+
process.stdout,
|
|
99
|
+
0,
|
|
100
|
+
this.dictionariesStatuses.length - lineIndex - 1
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
startSpinner() {
|
|
107
|
+
if (!this.spinnerTimer) {
|
|
108
|
+
this.spinnerTimer = setInterval(() => {
|
|
109
|
+
this.updateAllStatusLines();
|
|
110
|
+
}, 100);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
stopSpinner() {
|
|
114
|
+
if (this.spinnerTimer) {
|
|
115
|
+
clearInterval(this.spinnerTimer);
|
|
116
|
+
this.spinnerTimer = null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
stop() {
|
|
120
|
+
this.stopSpinner();
|
|
121
|
+
this.updateAllStatusLines();
|
|
122
|
+
}
|
|
123
|
+
updateStatus(dictionaryKey, type, status) {
|
|
124
|
+
const statusObj = this.dictionariesStatuses.find(
|
|
125
|
+
(ds) => ds.dictionaryKey === dictionaryKey
|
|
126
|
+
);
|
|
127
|
+
if (statusObj) {
|
|
128
|
+
const state = statusObj.state.find((s) => s.type === type);
|
|
129
|
+
if (state) {
|
|
130
|
+
Object.assign(state, status);
|
|
131
|
+
} else {
|
|
132
|
+
if (status.status === void 0) {
|
|
133
|
+
status.status = "pending";
|
|
134
|
+
}
|
|
135
|
+
const newState = {
|
|
136
|
+
type,
|
|
137
|
+
status: status.status,
|
|
138
|
+
icon: status.icon ?? "",
|
|
139
|
+
error: status.error,
|
|
140
|
+
errorMessage: status.errorMessage,
|
|
141
|
+
spinnerFrameIndex: status.spinnerFrameIndex ?? 0
|
|
142
|
+
};
|
|
143
|
+
statusObj.state.push(newState);
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
const newState = {
|
|
147
|
+
type,
|
|
148
|
+
status: status.status ?? "pending",
|
|
149
|
+
icon: status.icon ?? "",
|
|
150
|
+
error: status.error,
|
|
151
|
+
errorMessage: status.errorMessage,
|
|
152
|
+
spinnerFrameIndex: status.spinnerFrameIndex ?? 0
|
|
153
|
+
};
|
|
154
|
+
this.dictionariesStatuses.push({
|
|
155
|
+
dictionaryKey,
|
|
156
|
+
state: [newState]
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Rest of the Logger class remains the same...
|
|
161
|
+
getStatusIcon(status) {
|
|
162
|
+
const statusIcons = {
|
|
163
|
+
pending: "\u23F2",
|
|
164
|
+
fetching: "",
|
|
165
|
+
// Spinner handled separately
|
|
166
|
+
built: "\u2714",
|
|
167
|
+
imported: "\u2714",
|
|
168
|
+
error: "\u2716"
|
|
169
|
+
};
|
|
170
|
+
return statusIcons[status] ?? "";
|
|
171
|
+
}
|
|
172
|
+
getStatusLine(statusObj) {
|
|
173
|
+
const keyPadding = this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;
|
|
174
|
+
const paddedKey = statusObj.dictionaryKey + " ".repeat(keyPadding);
|
|
175
|
+
const states = statusObj.state.map((state) => {
|
|
176
|
+
let colorStart = "";
|
|
177
|
+
let colorEnd = "";
|
|
178
|
+
let icon = this.getStatusIcon(state.status);
|
|
179
|
+
if (state.status === "fetching") {
|
|
180
|
+
icon = this.spinnerFrames[state.spinnerFrameIndex % this.spinnerFrames.length];
|
|
181
|
+
colorStart = this.BLUE;
|
|
182
|
+
colorEnd = this.RESET;
|
|
183
|
+
} else if (state.status === "error") {
|
|
184
|
+
colorStart = this.RED;
|
|
185
|
+
colorEnd = this.RESET;
|
|
186
|
+
} else if (state.status === "imported" || state.status === "built") {
|
|
187
|
+
colorStart = this.GREEN;
|
|
188
|
+
colorEnd = this.RESET;
|
|
189
|
+
} else {
|
|
190
|
+
colorStart = this.GREY;
|
|
191
|
+
colorEnd = this.RESET;
|
|
192
|
+
}
|
|
193
|
+
const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;
|
|
194
|
+
return `${colorStart}${statusBlock}${colorEnd}`;
|
|
195
|
+
});
|
|
196
|
+
return `- ${paddedKey} ${states.join(" ")}`;
|
|
197
|
+
}
|
|
198
|
+
updateAllStatusLines() {
|
|
199
|
+
readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);
|
|
200
|
+
for (const statusObj of this.dictionariesStatuses) {
|
|
201
|
+
readline.clearLine(process.stdout, 0);
|
|
202
|
+
if (typeof statusObj?.state === "undefined") {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
statusObj.state.forEach((state) => {
|
|
206
|
+
if (state.status === "fetching") {
|
|
207
|
+
state.spinnerFrameIndex = (state.spinnerFrameIndex + 1) % this.spinnerFrames.length;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
getStatuses() {
|
|
214
|
+
return this.dictionariesStatuses;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const logger = Logger.getInstance();
|
|
218
|
+
export {
|
|
219
|
+
logger
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=log.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import * as readline from 'readline';\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\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\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 ) {\n const allKeys = Array.from(\n new Set([...localDictionariesKeys, ...distantDictionariesKeys])\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 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 return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Output initial statuses\n for (const statusObj of this.dictionariesStatuses) {\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n this.startSpinner();\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 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\n // Output the new status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Update the existing line\n const lineIndex = this.dictionariesStatuses.indexOf(statusObj);\n // Move cursor up to the lineIndex from the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n -(this.dictionariesStatuses.length - lineIndex)\n );\n readline.clearLine(process.stdout, 0);\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n // Move cursor back to the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n this.dictionariesStatuses.length - lineIndex - 1\n );\n }\n }\n }\n // No need to redraw all status lines\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 public stop() {\n this.stopSpinner();\n // Update statuses one last time\n this.updateAllStatusLines();\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\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 // Rest of the Logger class remains the same...\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 =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);\n\n for (const statusObj of this.dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (typeof statusObj?.state === 'undefined') {\n return;\n }\n\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n\n // Write the status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":"AAAA,YAAY,cAAc;AAgB1B,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAAA,EACjE,eAAsC;AAAA,EACtC,yBAAiC;AAAA;AAAA,EAGjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA;AAAA,EAGpB,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;AACA,UAAM,UAAU,MAAM;AAAA,MACpB,oBAAI,IAAI,CAAC,GAAG,uBAAuB,GAAG,uBAAuB,CAAC;AAAA,IAChE;AAEA,SAAK,yBAAyB,QAAQ;AAAA,MACpC,CAAC,KAAK,QAAS,IAAI,SAAS,MAAM,IAAI,SAAS;AAAA,MAC/C;AAAA,IACF;AAEA,SAAK,uBAAuB,QAAQ,IAAI,CAAC,kBAAkB;AACzD,YAAM,SAAkB,CAAC;AACzB,UAAI,sBAAsB,SAAS,aAAa,GAAG;AACjD,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,mBAAmB;AAAA,QACrB,CAAC;AAAA,MACH;AACA,UAAI,wBAAwB,SAAS,aAAa,GAAG;AACnD,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,mBAAmB;AAAA,QACrB,CAAC;AAAA,MACH;AACA,aAAO;AAAA,QACL;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAGD,eAAW,aAAa,KAAK,sBAAsB;AACjD,cAAQ,OAAO,MAAM,KAAK,cAAc,SAAS,IAAI,IAAI;AAAA,IAC3D;AAGA,SAAK,aAAa;AAAA,EACpB;AAAA;AAAA,EAGO,kBACL,MACA,gBACA;AACA,eAAW,iBAAiB,gBAAgB;AAE1C,UAAI,cAAc,SAAS,KAAK,wBAAwB;AACtD,aAAK,yBAAyB,cAAc;AAAA,MAC9C;AAEA,UAAI,YAAY,KAAK,qBAAqB;AAAA,QACxC,CAAC,OAAO,GAAG,kBAAkB;AAAA,MAC/B;AAEA,UAAI,CAAC,WAAW;AAEd,oBAAY;AAAA,UACV;AAAA,UACA,OAAO,CAAC;AAAA,QACV;AACA,aAAK,qBAAqB,KAAK,SAAS;AAExC,cAAM,WAAkB;AAAA,UACtB;AAAA,UACA,QAAQ;AAAA,UACR,mBAAmB;AAAA,QACrB;AACA,kBAAU,MAAM,KAAK,QAAQ;AAG7B,gBAAQ,OAAO,MAAM,KAAK,cAAc,SAAS,IAAI,IAAI;AAAA,MAC3D,OAAO;AACL,cAAM,gBAAgB,UAAU,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AACjE,YAAI,CAAC,eAAe;AAElB,gBAAM,WAAkB;AAAA,YACtB;AAAA,YACA,QAAQ;AAAA,YACR,mBAAmB;AAAA,UACrB;AACA,oBAAU,MAAM,KAAK,QAAQ;AAG7B,gBAAM,YAAY,KAAK,qBAAqB,QAAQ,SAAS;AAE7D,mBAAS;AAAA,YACP,QAAQ;AAAA,YACR;AAAA,YACA,EAAE,KAAK,qBAAqB,SAAS;AAAA,UACvC;AACA,mBAAS,UAAU,QAAQ,QAAQ,CAAC;AACpC,kBAAQ,OAAO,MAAM,KAAK,cAAc,SAAS,IAAI,IAAI;AAEzD,mBAAS;AAAA,YACP,QAAQ;AAAA,YACR;AAAA,YACA,KAAK,qBAAqB,SAAS,YAAY;AAAA,UACjD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EAEF;AAAA,EAEQ,eAAe;AACrB,QAAI,CAAC,KAAK,cAAc;AACtB,WAAK,eAAe,YAAY,MAAM;AACpC,aAAK,qBAAqB;AAAA,MAC5B,GAAG,GAAG;AAAA,IACR;AAAA,EACF;AAAA,EAEQ,cAAc;AACpB,QAAI,KAAK,cAAc;AACrB,oBAAc,KAAK,YAAY;AAC/B,WAAK,eAAe;AAAA,IACtB;AAAA,EACF;AAAA,EAEO,OAAO;AACZ,SAAK,YAAY;AAEjB,SAAK,qBAAqB;AAAA,EAC5B;AAAA,EAEO,aACL,eACA,MACA,QACA;AACA,UAAM,YAAY,KAAK,qBAAqB;AAAA,MAC1C,CAAC,OAAO,GAAG,kBAAkB;AAAA,IAC/B;AACA,QAAI,WAAW;AACb,YAAM,QAAQ,UAAU,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AACzD,UAAI,OAAO;AAET,eAAO,OAAO,OAAO,MAAM;AAAA,MAC7B,OAAO;AAEL,YAAI,OAAO,WAAW,QAAW;AAC/B,iBAAO,SAAS;AAAA,QAClB;AACA,cAAM,WAAkB;AAAA,UACtB;AAAA,UACA,QAAQ,OAAO;AAAA,UACf,MAAM,OAAO,QAAQ;AAAA,UACrB,OAAO,OAAO;AAAA,UACd,cAAc,OAAO;AAAA,UACrB,mBAAmB,OAAO,qBAAqB;AAAA,QACjD;AACA,kBAAU,MAAM,KAAK,QAAQ;AAAA,MAC/B;AAAA,IACF,OAAO;AAEL,YAAM,WAAkB;AAAA,QACtB;AAAA,QACA,QAAQ,OAAO,UAAU;AAAA,QACzB,MAAM,OAAO,QAAQ;AAAA,QACrB,OAAO,OAAO;AAAA,QACd,cAAc,OAAO;AAAA,QACrB,mBAAmB,OAAO,qBAAqB;AAAA,MACjD;AACA,WAAK,qBAAqB,KAAK;AAAA,QAC7B;AAAA,QACA,OAAO,CAAC,QAAQ;AAAA,MAClB,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA,EAIQ,cAAc,QAAwB;AAC5C,UAAM,cAAsC;AAAA,MAC1C,SAAS;AAAA,MACT,UAAU;AAAA;AAAA,MACV,OAAO;AAAA,MACP,UAAU;AAAA,MACV,OAAO;AAAA,IACT;AACA,WAAO,YAAY,MAAM,KAAK;AAAA,EAChC;AAAA,EAEQ,cAAc,WAAuC;AAC3D,UAAM,aACJ,KAAK,yBAAyB,UAAU,cAAc;AACxD,UAAM,YAAY,UAAU,gBAAgB,IAAI,OAAO,UAAU;AAEjE,UAAM,SAAS,UAAU,MAAM,IAAI,CAAC,UAAU;AAC5C,UAAI,aAAa;AACjB,UAAI,WAAW;AACf,UAAI,OAAO,KAAK,cAAc,MAAM,MAAM;AAC1C,UAAI,MAAM,WAAW,YAAY;AAE/B,eACE,KAAK,cACH,MAAM,oBAAqB,KAAK,cAAc,MAChD;AACF,qBAAa,KAAK;AAClB,mBAAW,KAAK;AAAA,MAClB,WAAW,MAAM,WAAW,SAAS;AACnC,qBAAa,KAAK;AAClB,mBAAW,KAAK;AAAA,MAClB,WAAW,MAAM,WAAW,cAAc,MAAM,WAAW,SAAS;AAClE,qBAAa,KAAK;AAClB,mBAAW,KAAK;AAAA,MAClB,OAAO;AACL,qBAAa,KAAK;AAClB,mBAAW,KAAK;AAAA,MAClB;AAGA,YAAM,cAAc,GAAG,KAAK,SAAS,IAAI,MAAM,IAAI,KAAK,UAAU,GAAG,IAAI,IAAI,MAAM,MAAM,GAAG,KAAK,SAAS,IAAI,QAAQ;AAEtH,aAAO,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ;AAAA,IAC/C,CAAC;AAED,WAAO,KAAK,SAAS,IAAI,OAAO,KAAK,GAAG,CAAC;AAAA,EAC3C;AAAA,EAEQ,uBAAuB;AAE7B,aAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC,KAAK,qBAAqB,MAAM;AAExE,eAAW,aAAa,KAAK,sBAAsB;AAEjD,eAAS,UAAU,QAAQ,QAAQ,CAAC;AAEpC,UAAI,OAAO,WAAW,UAAU,aAAa;AAC3C;AAAA,MACF;AAEA,gBAAU,MAAM,QAAQ,CAAC,UAAU;AACjC,YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,KAAK,cAAc;AAAA,QACxD;AAAA,MACF,CAAC;AAGD,cAAQ,OAAO,MAAM,KAAK,cAAc,SAAS,IAAI,IAAI;AAAA,IAC3D;AAAA,EACF;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import merge from "deepmerge";
|
|
2
|
+
const mergeByKey = (key) => {
|
|
3
|
+
return (target, source, options) => {
|
|
4
|
+
const destination = [];
|
|
5
|
+
const sourceMap = /* @__PURE__ */ new Map();
|
|
6
|
+
source.forEach((item) => {
|
|
7
|
+
sourceMap.set(item[key], item);
|
|
8
|
+
});
|
|
9
|
+
target.forEach((targetItem) => {
|
|
10
|
+
const sourceItem = sourceMap.get(targetItem[key]);
|
|
11
|
+
if (sourceItem) {
|
|
12
|
+
const mergedItem = merge(targetItem, sourceItem, options);
|
|
13
|
+
destination.push(mergedItem);
|
|
14
|
+
sourceMap.delete(targetItem[key]);
|
|
15
|
+
} else {
|
|
16
|
+
destination.push(targetItem);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
sourceMap.forEach((item) => {
|
|
20
|
+
destination.push(item);
|
|
21
|
+
});
|
|
22
|
+
return destination;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
mergeByKey
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=mergeDictionaries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import merge, { Options } from 'deepmerge';\n\n// Custom array merge function that merges objects by 'key'\nexport const mergeByKey = <T extends { key: string }>(key: keyof T) => {\n return (target: T[], source: T[], options?: Options): T[] => {\n const destination: T[] = [];\n\n // Create a map for quick lookup\n const sourceMap = new Map<string, T>();\n source.forEach((item) => {\n sourceMap.set(item[key] as string, item);\n });\n\n target.forEach((targetItem) => {\n const sourceItem = sourceMap.get(targetItem[key] as string);\n if (sourceItem) {\n // Merge the two items and assert the type\n const mergedItem = merge(targetItem, sourceItem, options) as T;\n destination.push(mergedItem);\n // Remove the item from the source map to avoid duplicates\n sourceMap.delete(targetItem[key] as string);\n } else {\n destination.push(targetItem);\n }\n });\n\n // Add remaining items from source\n sourceMap.forEach((item) => {\n destination.push(item);\n });\n\n return destination;\n };\n};\n"],"mappings":"AAAA,OAAO,WAAwB;AAGxB,MAAM,aAAa,CAA4B,QAAiB;AACrE,SAAO,CAAC,QAAa,QAAa,YAA2B;AAC3D,UAAM,cAAmB,CAAC;AAG1B,UAAM,YAAY,oBAAI,IAAe;AACrC,WAAO,QAAQ,CAAC,SAAS;AACvB,gBAAU,IAAI,KAAK,GAAG,GAAa,IAAI;AAAA,IACzC,CAAC;AAED,WAAO,QAAQ,CAAC,eAAe;AAC7B,YAAM,aAAa,UAAU,IAAI,WAAW,GAAG,CAAW;AAC1D,UAAI,YAAY;AAEd,cAAM,aAAa,MAAM,YAAY,YAAY,OAAO;AACxD,oBAAY,KAAK,UAAU;AAE3B,kBAAU,OAAO,WAAW,GAAG,CAAW;AAAA,MAC5C,OAAO;AACL,oBAAY,KAAK,UAAU;AAAA,MAC7B;AAAA,IACF,CAAC;AAGD,cAAU,QAAQ,CAAC,SAAS;AAC1B,kBAAY,KAAK,IAAI;AAAA,IACvB,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs
CHANGED
|
@@ -1,59 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { getConfiguration } from "@intlayer/config";
|
|
1
|
+
import { createI18nDictionaries } from './convertContentDeclarationInto18nDictionaries.mjs';
|
|
4
2
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
writeDictionary
|
|
4
|
+
} from './writeDictionary.mjs';
|
|
5
|
+
const buildI18nDictionary = async (contentDeclarations) => {
|
|
6
|
+
const dictionariesDeclaration = contentDeclarations.reduce((acc, dictionary) => {
|
|
7
|
+
const { key, content } = dictionary;
|
|
8
|
+
const i18Content = createI18nDictionaries(content);
|
|
9
|
+
return {
|
|
10
|
+
...acc,
|
|
11
|
+
[key]: i18Content
|
|
12
|
+
};
|
|
13
|
+
}, {});
|
|
14
|
+
const dictionariesPaths = await writeDictionary(
|
|
16
15
|
dictionariesDeclaration
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
const contentString = JSON.stringify(content2);
|
|
20
|
-
const outputFileName = `${nameSpace}.json`;
|
|
21
|
-
const resultDirPath = resolve(i18nDictionariesDir, locale);
|
|
22
|
-
const resultFilePath = resolve(resultDirPath, outputFileName);
|
|
23
|
-
await mkdir(resultDirPath, { recursive: true });
|
|
24
|
-
await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
|
|
25
|
-
console.error(`Error creating ${outputFileName}:`, err);
|
|
26
|
-
});
|
|
27
|
-
resultDictionariesPaths.push(resultFilePath);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return resultDictionariesPaths;
|
|
31
|
-
};
|
|
32
|
-
const buildI18nDictionary = async (contentDeclarationsPaths) => {
|
|
33
|
-
const resultDictionariesPaths = [];
|
|
34
|
-
if (typeof contentDeclarationsPaths === "string") {
|
|
35
|
-
contentDeclarationsPaths = [contentDeclarationsPaths];
|
|
36
|
-
}
|
|
37
|
-
for await (const contentDeclarationPath of contentDeclarationsPaths) {
|
|
38
|
-
const result = await processContentDeclaration(contentDeclarationPath);
|
|
39
|
-
if (!result) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
const nestedContent = extractObjectsWithId(result);
|
|
43
|
-
const dictionariesDeclaration = nestedContent.reduce((acc, content2) => {
|
|
44
|
-
const id = content2.id;
|
|
45
|
-
const i18Content = createI18nDictionaries(content2);
|
|
46
|
-
return {
|
|
47
|
-
...acc,
|
|
48
|
-
[id]: i18Content
|
|
49
|
-
};
|
|
50
|
-
}, {});
|
|
51
|
-
const dictionariesPaths = await writeDictionary(
|
|
52
|
-
dictionariesDeclaration
|
|
53
|
-
);
|
|
54
|
-
resultDictionariesPaths.push(...dictionariesPaths);
|
|
55
|
-
}
|
|
56
|
-
return resultDictionariesPaths;
|
|
16
|
+
);
|
|
17
|
+
return dictionariesPaths;
|
|
57
18
|
};
|
|
58
19
|
export {
|
|
59
20
|
buildI18nDictionary
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { createI18nDictionaries } 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 = createI18nDictionaries(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":"AACA,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,OAEK;AAKA,MAAM,sBAAsB,OACjC,wBACG;AAEH,QAAM,0BACJ,oBAAoB,OAAO,CAAC,KAAK,eAAe;AAC9C,UAAM,EAAE,KAAK,QAAQ,IAAI;AACzB,UAAM,aAAa,uBAAuB,OAAO;AAEjD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG;AAAA,IACT;AAAA,EACF,GAAG,CAAC,CAAC;AAGP,QAAM,oBAA8B,MAAM;AAAA,IACxC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type TypedNode,\n type EnumerationContent,\n DictionaryValue,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\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 = (\n content: DictionaryValue,\n locale: Locales\n): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const result = (content as TranslationContent<unknown>)[\n NodeType.Translation\n ][locale];\n\n return buildDictionary(result as DictionaryValue, 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 DictionaryValue,\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 ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content).forEach((dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content[dictionaryValue as keyof typeof content] as DictionaryValue,\n locale\n );\n });\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nDictionaries = (\n content: DictionaryValue\n): I18nDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":"AAAA,SAAS,wBAAsC;AAC/C;AAAA,EACE;AAAA,OAKK;AACP,SAAS,4BAA4B;AAKrC,MAAM;AAAA,EACJ,sBAAsB,EAAE,QAAQ;AAClC,IAAI,iBAAiB;AAErB,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eACrB,OAAO,MAAM,UAAU,eACvB,OAAO,MAAM,SAAS;AAGxB,MAAM,kBAAkB,CACtB,SACA,WACY;AACZ;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,SAAS;AAAA,IAC7C;AACA,UAAM,SAAU,QACd,SAAS,WACX,EAAE,MAAM;AAER,WAAO,gBAAgB,QAA2B,MAAM;AAAA,EAC1D;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,SAAS;AAAA,IAC7C;AACA,UAAM,UAAmC,CAAC;AAE1C,WAAO;AAAA,MACJ,QAAwC,SAAS,WAAW;AAAA,IAC/D,EAAE,QAAQ,CAAC,aAAa;AACtB,YAAM,eAAe,qBAAqB,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;AAAA,IACnB;AACA,UAAM,SAAkC,CAAC;AAEzC,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,oBAAoB;AAChD,aAAO,eAAe,IAAI;AAAA,QACxB,QAAQ,eAAuC;AAAA,QAC/C;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,yBAAyB,CACpC,YAC2B;AAE3B,QAAM,SAAiC,QAAQ;AAAA,IAC7C,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/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { getConfiguration } from "@intlayer/config";
|
|
4
|
+
const { content } = getConfiguration();
|
|
5
|
+
const { i18nDictionariesDir } = content;
|
|
6
|
+
const writeDictionary = async (dictionariesDeclaration) => {
|
|
7
|
+
const resultDictionariesPaths = [];
|
|
8
|
+
for (const [nameSpace, localContent] of Object.entries(
|
|
9
|
+
dictionariesDeclaration
|
|
10
|
+
)) {
|
|
11
|
+
for await (const [locale, content2] of Object.entries(localContent)) {
|
|
12
|
+
const contentString = JSON.stringify(content2);
|
|
13
|
+
const outputFileName = `${nameSpace}.json`;
|
|
14
|
+
const resultDirPath = resolve(i18nDictionariesDir, locale);
|
|
15
|
+
const resultFilePath = resolve(resultDirPath, outputFileName);
|
|
16
|
+
await mkdir(resultDirPath, { recursive: true });
|
|
17
|
+
await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
|
|
18
|
+
console.error(`Error creating ${outputFileName}:`, err);
|
|
19
|
+
});
|
|
20
|
+
resultDictionariesPaths.push(resultFilePath);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return resultDictionariesPaths;
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
writeDictionary
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=writeDictionary.mjs.map
|
package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { I18nDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\nconst { content } = getConfiguration();\nconst { i18nDictionariesDir } = content;\n\nexport type DictionariesDeclaration = Record<string, I18nDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration\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(i18nDictionariesDir, 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,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAGjC,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,oBAAoB,IAAI;AAOzB,MAAM,kBAAkB,OAC7B,4BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQA,QAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,gBAAgB,QAAQ,qBAAqB,MAAM;AACzD,YAAM,iBAAiB,QAAQ,eAAe,cAAc;AAG5D,YAAM,MAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAG9C,YAAM,UAAU,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":["content"]}
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
} = getConfiguration();
|
|
7
7
|
const buildDictionary = async (contentDeclarationsPaths) => {
|
|
8
8
|
if (dictionaryOutput.includes("i18next")) {
|
|
9
|
-
|
|
9
|
+
await buildI18nDictionary(contentDeclarationsPaths);
|
|
10
10
|
}
|
|
11
11
|
if (dictionaryOutput.includes("intlayer")) {
|
|
12
12
|
return await buildIntlayerDictionary(contentDeclarationsPaths);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { buildI18nDictionary } from './i18n_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nconst {\n content: { dictionaryOutput },\n} = getConfiguration();\n\nexport const buildDictionary = async (\n contentDeclarationsPaths:
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18n_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nconst {\n content: { dictionaryOutput },\n} = getConfiguration();\n\nexport const buildDictionary = async (\n contentDeclarationsPaths: Dictionary[]\n): Promise<string[]> => {\n if (dictionaryOutput.includes('i18next')) {\n await buildI18nDictionary(contentDeclarationsPaths);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(contentDeclarationsPaths);\n }\n\n return [];\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAExC,MAAM;AAAA,EACJ,SAAS,EAAE,iBAAiB;AAC9B,IAAI,iBAAiB;AAEd,MAAM,kBAAkB,OAC7B,6BACsB;AACtB,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,UAAM,oBAAoB,wBAAwB;AAAA,EACpD;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,MAAM,wBAAwB,wBAAwB;AAAA,EAC/D;AAEA,SAAO,CAAC;AACV;","names":[]}
|