@intlayer/chokidar 5.8.1 → 6.0.0-canary.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 +15 -20
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +18 -37
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/{fetchDistantDictionaryKeys.cjs → fetchDistantDictionaryKeysAndUpdateTimestamp.cjs} +10 -10
- package/dist/cjs/fetchDistantDictionaryKeysAndUpdateTimestamp.cjs.map +1 -0
- package/dist/cjs/filterInvalidDictionaries.cjs +70 -0
- package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -0
- package/dist/cjs/getBuiltFetchDictionariesPath.cjs +52 -0
- package/dist/cjs/getBuiltFetchDictionariesPath.cjs.map +1 -0
- package/dist/cjs/getBuiltRemoteDictionariesPath.cjs +51 -0
- package/dist/cjs/getBuiltRemoteDictionariesPath.cjs.map +1 -0
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/index.cjs +4 -4
- package/dist/cjs/loadDictionaries/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +57 -17
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +128 -53
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +101 -0
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/log.cjs +144 -0
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -0
- package/dist/cjs/mergeDictionaries.cjs +18 -22
- package/dist/cjs/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/orderDictionaries.cjs +71 -0
- package/dist/cjs/orderDictionaries.cjs.map +1 -0
- package/dist/cjs/prepareContentDeclaration.cjs +4 -1
- package/dist/cjs/prepareContentDeclaration.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +9 -4
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +22 -8
- 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/writeDynamicDictionary.cjs +44 -42
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs +83 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs +29 -21
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs +52 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs +44 -29
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +39 -34
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +4 -6
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +17 -16
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
- package/dist/cjs/utils/formatter.cjs +50 -0
- package/dist/cjs/utils/formatter.cjs.map +1 -0
- package/dist/cjs/utils/parallelize.cjs +43 -0
- package/dist/cjs/utils/parallelize.cjs.map +1 -0
- package/dist/cjs/utils/runOnce.cjs +2 -1
- package/dist/cjs/utils/runOnce.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/formatCode.cjs +7 -4
- package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +5 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +43 -25
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +16 -21
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +24 -28
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/{fetchDistantDictionaryKeys.mjs → fetchDistantDictionaryKeysAndUpdateTimestamp.mjs} +6 -6
- package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +1 -0
- package/dist/esm/filterInvalidDictionaries.mjs +40 -0
- package/dist/esm/filterInvalidDictionaries.mjs.map +1 -0
- package/dist/esm/getBuiltFetchDictionariesPath.mjs +18 -0
- package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +1 -0
- package/dist/esm/getBuiltRemoteDictionariesPath.mjs +17 -0
- package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +1 -0
- package/dist/esm/index.mjs +8 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/index.mjs +2 -2
- package/dist/esm/loadDictionaries/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -18
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +132 -53
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +66 -0
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -0
- package/dist/esm/loadDictionaries/log.mjs +125 -0
- package/dist/esm/loadDictionaries/log.mjs.map +1 -0
- package/dist/esm/mergeDictionaries.mjs +19 -23
- package/dist/esm/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/orderDictionaries.mjs +37 -0
- package/dist/esm/orderDictionaries.mjs.map +1 -0
- package/dist/esm/prepareContentDeclaration.mjs +4 -1
- package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +9 -4
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/processPerLocaleDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +25 -9
- 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/writeDynamicDictionary.mjs +45 -43
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs +58 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +29 -21
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs +28 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +45 -30
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +39 -34
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -6
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +17 -16
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
- package/dist/esm/utils/formatter.mjs +15 -0
- package/dist/esm/utils/formatter.mjs.map +1 -0
- package/dist/esm/utils/parallelize.mjs +9 -0
- package/dist/esm/utils/parallelize.mjs.map +1 -0
- package/dist/esm/utils/runOnce.mjs +2 -1
- package/dist/esm/utils/runOnce.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/formatCode.mjs +8 -5
- package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +5 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +40 -22
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaries.d.ts +2 -1
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +3 -0
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +1 -0
- package/dist/types/filterInvalidDictionaries.d.ts +3 -0
- package/dist/types/filterInvalidDictionaries.d.ts.map +1 -0
- package/dist/types/getBuiltFetchDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +1 -0
- package/dist/types/getBuiltRemoteDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/index.d.ts +2 -2
- package/dist/types/loadDictionaries/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +4 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +11 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +6 -0
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/log.d.ts +19 -0
- package/dist/types/loadDictionaries/log.d.ts.map +1 -0
- package/dist/types/mergeDictionaries.d.ts +1 -1
- package/dist/types/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/orderDictionaries.d.ts +10 -0
- package/dist/types/orderDictionaries.d.ts.map +1 -0
- package/dist/types/prepareContentDeclaration.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/processPerLocaleDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -0
- 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 +4 -3
- 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/writeDynamicDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts +23 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts +19 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.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 +1 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
- package/dist/types/utils/formatter.d.ts +4 -0
- package/dist/types/utils/formatter.d.ts.map +1 -0
- package/dist/types/utils/parallelize.d.ts +2 -0
- package/dist/types/utils/parallelize.d.ts.map +1 -0
- package/dist/types/utils/runOnce.d.ts +1 -1
- package/dist/types/utils/runOnce.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
- package/package.json +19 -17
- package/dist/cjs/checkDictionaryChanges.cjs +0 -58
- package/dist/cjs/checkDictionaryChanges.cjs.map +0 -1
- package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +0 -1
- package/dist/cjs/getFilteredLocalesContent.cjs +0 -70
- package/dist/cjs/getFilteredLocalesContent.cjs.map +0 -1
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +0 -44
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +0 -1
- package/dist/cjs/log.cjs +0 -296
- package/dist/cjs/log.cjs.map +0 -1
- package/dist/esm/checkDictionaryChanges.mjs +0 -37
- package/dist/esm/checkDictionaryChanges.mjs.map +0 -1
- package/dist/esm/fetchDistantDictionaryKeys.mjs.map +0 -1
- package/dist/esm/getFilteredLocalesContent.mjs +0 -49
- package/dist/esm/getFilteredLocalesContent.mjs.map +0 -1
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +0 -20
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +0 -1
- package/dist/esm/log.mjs +0 -262
- package/dist/esm/log.mjs.map +0 -1
- package/dist/types/checkDictionaryChanges.d.ts +0 -3
- package/dist/types/checkDictionaryChanges.d.ts.map +0 -1
- package/dist/types/fetchDistantDictionaryKeys.d.ts +0 -3
- package/dist/types/fetchDistantDictionaryKeys.d.ts.map +0 -1
- package/dist/types/getFilteredLocalesContent.d.ts +0 -4
- package/dist/types/getFilteredLocalesContent.d.ts.map +0 -1
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +0 -8
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +0 -1
- package/dist/types/log.d.ts +0 -45
- package/dist/types/log.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { parallelize } from '../../../utils/parallelize';\nimport type {\n LocalizedDictionaryOutput,\n LocalizedDictionaryResult,\n} from './writeDynamicDictionary';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryEntryPoint = (\n localedDictionariesPathsRecord: LocalizedDictionaryResult,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { fetchDictionariesDir } = configuration.content;\n const { liveSyncURL } = configuration.editor;\n\n let content = '';\n\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(fetchDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return await import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)}})()`;\n }\n\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return Promise.resolve(require('./${relativePath}'))}})()`;\n })\n .join(',\\n');\n\n content += `const content = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n if (format === 'esm') content += `export default content;\\n`;\n if (format === 'cjs') content += `module.exports = content;\\n`;\n\n return content;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/fetch_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeFetchDictionary = async (\n dynamicDictionaries: LocalizedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { fetchDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(fetchDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Write entry points for each dictionary in parallel\n await parallelize(\n Object.entries(dynamicDictionaries),\n async ([key, localedDictionariesPathsRecord]) => {\n if (key === 'undefined') return;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFile(\n resolve(fetchDictionariesDir, `${key}.${extension}`),\n content\n );\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgD;AAChD,sBAAiC;AACjC,kBAAkC;AAClC,yBAA4B;AASrB,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,qBAAqB,IAAI,cAAc;AAC/C,QAAM,EAAE,YAAY,IAAI,cAAc;AAEtC,MAAI,UAAU;AAEd,QAAM,yBAAiC,OAAO;AAAA,IAC5C;AAAA,EACF,EACG,IAAI,CAAC,CAAC,QAAQ,UAAU,MAAM;AAC7B,UAAM,mBAAe;AAAA,UACnB,sBAAS,sBAAsB,WAAW,cAAc;AAAA,IAC1D;AAEA,QAAI,WAAW,OAAO;AACpB,aAAO,MAAM,MAAM,oDAAoD,WAAW,iBAAiB,WAAW,WAAW,GAAG,IAAI,MAAM,sEAAsE,YAAY;AAAA,IAC1N;AAEA,WAAO,MAAM,MAAM,oDAAoD,WAAW,iBAAiB,WAAW,WAAW,GAAG,IAAI,MAAM,iFAAiF,YAAY;AAAA,EACrO,CAAC,EACA,KAAK,KAAK;AAEb,aAAW;AAAA,EAAsB,sBAAsB;AAAA;AAAA;AAEvD,MAAI,WAAW,MAAO,YAAW;AAAA;AACjC,MAAI,WAAW,MAAO,YAAW;AAAA;AAEjC,SAAO;AACT;AAkBO,MAAM,uBAAuB,OAClC,qBACA,oBAAgB,gCAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACH;AACvC,QAAM,EAAE,qBAAqB,IAAI,cAAc;AAG/C,YAAM,2BAAM,qBAAQ,oBAAoB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE9D,MAAI,0BAAqD,CAAC;AAG1D,YAAM;AAAA,IACJ,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAK,8BAA8B,MAAM;AAC/C,UAAI,QAAQ,YAAa;AAEzB,gBAAM,gCAAY,SAAS,OAAO,WAAW;AAC3C,cAAM,YAAY,WAAW,QAAQ,QAAQ;AAC7C,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,kBAAM;AAAA,cACJ,qBAAQ,sBAAsB,GAAG,GAAG,IAAI,SAAS,EAAE;AAAA,UACnD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -26,31 +26,39 @@ var import_promises = require("fs/promises");
|
|
|
26
26
|
var import_path = require("path");
|
|
27
27
|
var import_mergeDictionaries = require('../../../mergeDictionaries.cjs');
|
|
28
28
|
var import_processPerLocaleDictionary = require('../../../processPerLocaleDictionary.cjs');
|
|
29
|
+
var import_parallelize = require('../../../utils/parallelize.cjs');
|
|
29
30
|
var import_formatDictionaryText = require('./formatDictionaryText.cjs');
|
|
30
31
|
const writeMergedDictionaries = async (groupedDictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
31
32
|
const { dictionariesDir } = configuration.content;
|
|
32
33
|
await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), { recursive: true });
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
const results = await (0, import_parallelize.parallelize)(
|
|
35
|
+
Object.entries(groupedDictionaries),
|
|
36
|
+
async ([key, dictionariesEntry]) => {
|
|
37
|
+
if (key === "undefined") {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(
|
|
41
|
+
(dictionary) => (0, import_processPerLocaleDictionary.processPerLocaleDictionary)(dictionary)
|
|
42
|
+
);
|
|
43
|
+
const mergedDictionary = (0, import_mergeDictionaries.mergeDictionaries)(multiLocaleDictionaries);
|
|
44
|
+
const contentString = (0, import_formatDictionaryText.formatDictionaryText)(mergedDictionary);
|
|
45
|
+
const outputFileName = `${key}.json`;
|
|
46
|
+
const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
|
|
47
|
+
await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
|
|
48
|
+
console.error(`Error creating merged ${outputFileName}:`, err);
|
|
49
|
+
});
|
|
50
|
+
return [
|
|
51
|
+
key,
|
|
52
|
+
{
|
|
53
|
+
dictionaryPath: resultFilePath,
|
|
54
|
+
dictionary: mergedDictionary
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
return Object.fromEntries(
|
|
60
|
+
results.filter(Boolean)
|
|
61
|
+
);
|
|
54
62
|
};
|
|
55
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
64
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../../../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../../../processPerLocaleDictionary';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { UnmergedDictionaryOutput } from './writeUnmergedDictionary';\n\nexport type MergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;\n\n/**\n * Write the merged dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The merged dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../../../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../../../processPerLocaleDictionary';\nimport { parallelize } from '../../../utils/parallelize';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { UnmergedDictionaryOutput } from './writeUnmergedDictionary';\n\nexport type MergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;\n\n/**\n * Write the merged dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The merged dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dictionary/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeMergedDictionaries = async (\n groupedDictionaries: UnmergedDictionaryOutput,\n configuration = getConfiguration()\n): Promise<MergedDictionaryOutput> => {\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 results = await parallelize(\n Object.entries(groupedDictionaries),\n async ([key, dictionariesEntry]) => {\n if (key === 'undefined') {\n return undefined as unknown as readonly [\n string,\n MergedDictionaryResult,\n ];\n }\n\n const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(\n (dictionary) => processPerLocaleDictionary(dictionary)\n );\n\n const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);\n\n const contentString = formatDictionaryText(mergedDictionary);\n\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n\n return [\n key,\n {\n dictionaryPath: resultFilePath,\n dictionary: mergedDictionary,\n } as MergedDictionaryResult,\n ] as const;\n }\n );\n\n return Object.fromEntries(\n results.filter(Boolean) as Array<readonly [string, MergedDictionaryResult]>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,+BAAkC;AAClC,wCAA2C;AAC3C,yBAA4B;AAC5B,kCAAqC;AA0B9B,MAAM,0BAA0B,OACrC,qBACA,oBAAgB,gCAAiB,MACG;AACpC,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,UAAU,UAAM;AAAA,IACpB,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAK,iBAAiB,MAAM;AAClC,UAAI,QAAQ,aAAa;AACvB,eAAO;AAAA,MAIT;AAEA,YAAM,0BAA0B,kBAAkB,aAAa;AAAA,QAC7D,CAAC,mBAAe,8DAA2B,UAAU;AAAA,MACvD;AAEA,YAAM,uBAAmB,4CAAkB,uBAAuB;AAElE,YAAM,oBAAgB,kDAAqB,gBAAgB;AAE3D,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,MAC/D,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE,gBAAgB;AAAA,UAChB,YAAY;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO;AAAA,IACZ,QAAQ,OAAO,OAAO;AAAA,EACxB;AACF;","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var writeRemoteDictionary_exports = {};
|
|
20
|
+
__export(writeRemoteDictionary_exports, {
|
|
21
|
+
writeRemoteDictionary: () => writeRemoteDictionary
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(writeRemoteDictionary_exports);
|
|
24
|
+
var import_config = require("@intlayer/config");
|
|
25
|
+
var import_promises = require("fs/promises");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
var import_filterInvalidDictionaries = require('../../../filterInvalidDictionaries.cjs');
|
|
28
|
+
var import_loadDictionaries = require('../../../loadDictionaries/index.cjs');
|
|
29
|
+
var import_parallelize = require('../../../utils/parallelize.cjs');
|
|
30
|
+
var import_formatDictionaryText = require('./formatDictionaryText.cjs');
|
|
31
|
+
const writeRemoteDictionary = async (remoteDictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
32
|
+
const { remoteDictionariesDir } = configuration.content;
|
|
33
|
+
await (0, import_promises.mkdir)((0, import_path.resolve)(remoteDictionariesDir), { recursive: true });
|
|
34
|
+
const filteredDictionaries = (0, import_filterInvalidDictionaries.filterInvalidDictionaries)(remoteDictionaries);
|
|
35
|
+
await (0, import_parallelize.parallelize)(
|
|
36
|
+
filteredDictionaries.filter((dictionary) => dictionary.key !== "undefined"),
|
|
37
|
+
async (dictionary) => {
|
|
38
|
+
const outputFileName = `${dictionary.key}.json`;
|
|
39
|
+
const resultFilePath = (0, import_path.resolve)(remoteDictionariesDir, outputFileName);
|
|
40
|
+
const contentString = (0, import_formatDictionaryText.formatDictionaryText)(dictionary);
|
|
41
|
+
await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
|
|
42
|
+
console.error(`Error creating merged ${outputFileName}:`, err);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
return (0, import_loadDictionaries.formatDistantDictionaries)(remoteDictionaries);
|
|
47
|
+
};
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
writeRemoteDictionary
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=writeRemoteDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { filterInvalidDictionaries } from '../../../filterInvalidDictionaries';\nimport { formatDistantDictionaries } from '../../../loadDictionaries';\nimport { parallelize } from '../../../utils/parallelize';\nimport { formatDictionaryText } from './formatDictionaryText';\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/fetch_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeRemoteDictionary = async (\n remoteDictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<Dictionary[]> => {\n const { remoteDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(remoteDictionariesDir), { recursive: true });\n\n const filteredDictionaries = filterInvalidDictionaries(remoteDictionaries);\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n filteredDictionaries.filter((dictionary) => dictionary.key !== 'undefined'),\n async (dictionary) => {\n const outputFileName = `${dictionary.key}.json`;\n const resultFilePath = resolve(remoteDictionariesDir, outputFileName);\n\n const contentString = formatDictionaryText(dictionary);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n }\n );\n\n return formatDistantDictionaries(remoteDictionaries);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,uCAA0C;AAC1C,8BAA0C;AAC1C,yBAA4B;AAC5B,kCAAqC;AAkB9B,MAAM,wBAAwB,OACnC,oBACA,oBAAgB,gCAAiB,MACP;AAC1B,QAAM,EAAE,sBAAsB,IAAI,cAAc;AAGhD,YAAM,2BAAM,qBAAQ,qBAAqB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE/D,QAAM,2BAAuB,4DAA0B,kBAAkB;AAGzE,YAAM;AAAA,IACJ,qBAAqB,OAAO,CAAC,eAAe,WAAW,QAAQ,WAAW;AAAA,IAC1E,OAAO,eAAe;AACpB,YAAM,iBAAiB,GAAG,WAAW,GAAG;AACxC,YAAM,qBAAiB,qBAAQ,uBAAuB,cAAc;AAEpE,YAAM,oBAAgB,kDAAqB,UAAU;AAGrD,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,MAC/D,CAAC;AAAA,IACH;AAAA,EACF;AAEA,aAAO,mDAA0B,kBAAkB;AACrD;","names":[]}
|
|
@@ -24,39 +24,54 @@ module.exports = __toCommonJS(writeUnmergedDictionary_exports);
|
|
|
24
24
|
var import_config = require("@intlayer/config");
|
|
25
25
|
var import_promises = require("fs/promises");
|
|
26
26
|
var import_path = require("path");
|
|
27
|
+
var import_filterInvalidDictionaries = require('../../../filterInvalidDictionaries.cjs');
|
|
28
|
+
var import_orderDictionaries = require('../../../orderDictionaries.cjs');
|
|
29
|
+
var import_parallelize = require('../../../utils/parallelize.cjs');
|
|
27
30
|
var import_formatDictionaryText = require('./formatDictionaryText.cjs');
|
|
28
|
-
const groupDictionariesByKey = (dictionaries) =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
40
|
-
};
|
|
31
|
+
const groupDictionariesByKey = (dictionaries) => dictionaries.reduce(
|
|
32
|
+
(acc, dictionary) => {
|
|
33
|
+
const key = dictionary.key;
|
|
34
|
+
if (!acc[key]) {
|
|
35
|
+
acc[key] = [];
|
|
36
|
+
}
|
|
37
|
+
acc[key].push(dictionary);
|
|
38
|
+
return acc;
|
|
39
|
+
},
|
|
40
|
+
{}
|
|
41
|
+
);
|
|
41
42
|
const writeUnmergedDictionaries = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
42
43
|
const { unmergedDictionariesDir } = configuration.content;
|
|
43
44
|
await (0, import_promises.mkdir)((0, import_path.resolve)(unmergedDictionariesDir), { recursive: true });
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
const filteredDictionaries = (0, import_filterInvalidDictionaries.filterInvalidDictionaries)(dictionaries);
|
|
46
|
+
const groupedDictionaries = groupDictionariesByKey(filteredDictionaries);
|
|
47
|
+
const results = await (0, import_parallelize.parallelize)(
|
|
48
|
+
Object.entries(groupedDictionaries),
|
|
49
|
+
async ([key, dictionaries2]) => {
|
|
50
|
+
if (key === "undefined") {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
const orderedDictionaries = (0, import_orderDictionaries.orderDictionaries)(
|
|
54
|
+
dictionaries2,
|
|
55
|
+
configuration
|
|
56
|
+
);
|
|
57
|
+
const contentString = (0, import_formatDictionaryText.formatDictionaryText)(orderedDictionaries);
|
|
58
|
+
const outputFileName = `${key}.json`;
|
|
59
|
+
const unmergedFilePath = (0, import_path.resolve)(unmergedDictionariesDir, outputFileName);
|
|
60
|
+
await (0, import_promises.writeFile)(unmergedFilePath, contentString, "utf8").catch((err) => {
|
|
61
|
+
console.error(`${import_config.x} Error creating unmerged ${outputFileName}:`, err);
|
|
62
|
+
});
|
|
63
|
+
return [
|
|
64
|
+
key,
|
|
65
|
+
{
|
|
66
|
+
dictionaryPath: unmergedFilePath,
|
|
67
|
+
dictionaries: dictionaries2
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
return Object.fromEntries(
|
|
73
|
+
results.filter(Boolean)
|
|
74
|
+
);
|
|
60
75
|
};
|
|
61
76
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
77
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { formatDictionaryText } from './formatDictionaryText';\n\nconst groupDictionariesByKey = (\n dictionaries: Dictionary[]\n): Record<string, Dictionary[]>
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.ts"],"sourcesContent":["import { getConfiguration, x } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { filterInvalidDictionaries } from '../../../filterInvalidDictionaries';\nimport { orderDictionaries } from '../../../orderDictionaries';\nimport { parallelize } from '../../../utils/parallelize';\nimport { formatDictionaryText } from './formatDictionaryText';\n\nconst groupDictionariesByKey = (\n dictionaries: Dictionary[]\n): Record<string, Dictionary[]> =>\n dictionaries.reduce(\n (acc, dictionary) => {\n const key = dictionary.key;\n if (!acc[key]) {\n acc[key] = [];\n }\n acc[key].push(dictionary);\n return acc;\n },\n {} as Record<string, Dictionary[]>\n );\n\nexport type UnmergedDictionaryResult = {\n dictionaryPath: string;\n dictionaries: Dictionary[];\n};\n\nexport type UnmergedDictionaryOutput = Record<string, UnmergedDictionaryResult>;\n\n/**\n * Write the unmerged dictionaries to the unmergedDictionariesDir\n * @param dictionaries - The dictionaries to write\n * @param configuration - The configuration\n * @returns The grouped dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * console.log(unmergedDictionaries);\n *\n * // .intlayer/unmerged_dictionaries/home.json\n * // {\n * // [\n * // { key: 'home', content: { ... } },\n * // { key: 'home', content: { ... } },\n * // ],\n * // }\n * ```\n */\nexport const writeUnmergedDictionaries = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<UnmergedDictionaryOutput> => {\n const { unmergedDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(unmergedDictionariesDir), { recursive: true });\n\n const filteredDictionaries = filterInvalidDictionaries(dictionaries);\n\n // Group dictionaries by key and write to unmergedDictionariesDir\n const groupedDictionaries = groupDictionariesByKey(filteredDictionaries);\n\n const results = await parallelize(\n Object.entries(groupedDictionaries),\n async ([key, dictionaries]) => {\n if (key === 'undefined') {\n return undefined as unknown as readonly [\n string,\n UnmergedDictionaryResult,\n ];\n }\n\n const orderedDictionaries = orderDictionaries(\n dictionaries,\n configuration\n );\n const contentString = formatDictionaryText(orderedDictionaries);\n\n const outputFileName = `${key}.json`;\n const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);\n\n // Write the grouped dictionaries\n await writeFile(unmergedFilePath, contentString, 'utf8').catch((err) => {\n console.error(`${x} Error creating unmerged ${outputFileName}:`, err);\n });\n\n return [\n key,\n {\n dictionaryPath: unmergedFilePath,\n dictionaries: dictionaries,\n } as UnmergedDictionaryResult,\n ] as const;\n }\n );\n\n return Object.fromEntries(\n results.filter(Boolean) as Array<\n readonly [string, UnmergedDictionaryResult]\n >\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAEpC,sBAAiC;AACjC,kBAAwB;AACxB,uCAA0C;AAC1C,+BAAkC;AAClC,yBAA4B;AAC5B,kCAAqC;AAErC,MAAM,yBAAyB,CAC7B,iBAEA,aAAa;AAAA,EACX,CAAC,KAAK,eAAe;AACnB,UAAM,MAAM,WAAW;AACvB,QAAI,CAAC,IAAI,GAAG,GAAG;AACb,UAAI,GAAG,IAAI,CAAC;AAAA,IACd;AACA,QAAI,GAAG,EAAE,KAAK,UAAU;AACxB,WAAO;AAAA,EACT;AAAA,EACA,CAAC;AACH;AA6BK,MAAM,4BAA4B,OACvC,cACA,oBAAgB,gCAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,YAAM,2BAAM,qBAAQ,uBAAuB,GAAG,EAAE,WAAW,KAAK,CAAC;AAEjE,QAAM,2BAAuB,4DAA0B,YAAY;AAGnE,QAAM,sBAAsB,uBAAuB,oBAAoB;AAEvE,QAAM,UAAU,UAAM;AAAA,IACpB,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAKA,aAAY,MAAM;AAC7B,UAAI,QAAQ,aAAa;AACvB,eAAO;AAAA,MAIT;AAEA,YAAM,0BAAsB;AAAA,QAC1BA;AAAA,QACA;AAAA,MACF;AACA,YAAM,oBAAgB,kDAAqB,mBAAmB;AAE9D,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,uBAAmB,qBAAQ,yBAAyB,cAAc;AAGxE,gBAAM,2BAAU,kBAAkB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACtE,gBAAQ,MAAM,GAAG,eAAC,4BAA4B,cAAc,KAAK,GAAG;AAAA,MACtE,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE,gBAAgB;AAAA,UAChB,cAAcA;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO;AAAA,IACZ,QAAQ,OAAO,OAAO;AAAA,EAGxB;AACF;","names":["dictionaries"]}
|
|
@@ -22,11 +22,14 @@ __export(createDictionaryEntryPoint_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(createDictionaryEntryPoint_exports);
|
|
24
24
|
var import_config = require("@intlayer/config");
|
|
25
|
-
var
|
|
25
|
+
var import_promises = require("fs/promises");
|
|
26
26
|
var import_path = require("path");
|
|
27
27
|
var import_getBuiltDictionariesPath = require('../../getBuiltDictionariesPath.cjs');
|
|
28
28
|
var import_getBuiltDynamicDictionariesPath = require('../../getBuiltDynamicDictionariesPath.cjs');
|
|
29
|
+
var import_getBuiltFetchDictionariesPath = require('../../getBuiltFetchDictionariesPath.cjs');
|
|
30
|
+
var import_getBuiltRemoteDictionariesPath = require('../../getBuiltRemoteDictionariesPath.cjs');
|
|
29
31
|
var import_getBuiltUnmergedDictionariesPath = require('../../getBuiltUnmergedDictionariesPath.cjs');
|
|
32
|
+
var import_parallelize = require('../../utils/parallelize.cjs');
|
|
30
33
|
var import_generateDictionaryListContent = require('./generateDictionaryListContent.cjs');
|
|
31
34
|
const filterDictionaries = (paths, keys) => {
|
|
32
35
|
if (!keys) return paths;
|
|
@@ -34,50 +37,52 @@ const filterDictionaries = (paths, keys) => {
|
|
|
34
37
|
(path) => keys.some((key) => path.endsWith(`${key}.json`))
|
|
35
38
|
);
|
|
36
39
|
};
|
|
37
|
-
const writeDictionaryFiles = (paths, fileName, format, configuration = (0, import_config.getConfiguration)()) => {
|
|
40
|
+
const writeDictionaryFiles = async (paths, fileName, format, configuration = (0, import_config.getConfiguration)()) => {
|
|
38
41
|
const content = (0, import_generateDictionaryListContent.generateDictionaryListContent)(paths, format, configuration);
|
|
39
42
|
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
40
43
|
const { mainDir } = configuration.content;
|
|
41
|
-
(0,
|
|
44
|
+
await (0, import_promises.writeFile)((0, import_path.resolve)(mainDir, `${fileName}.${extension}`), content);
|
|
42
45
|
};
|
|
43
|
-
const createDictionaryEntryPoint = (configuration = (0, import_config.getConfiguration)(), dictionariesKeys, formats = ["cjs", "esm"]) => {
|
|
46
|
+
const createDictionaryEntryPoint = async (configuration = (0, import_config.getConfiguration)(), dictionariesKeys, formats = ["cjs", "esm"]) => {
|
|
44
47
|
const { mainDir } = configuration.content;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
+
await (0, import_promises.mkdir)(mainDir, { recursive: true });
|
|
49
|
+
const remoteDictionariesPath = (0, import_getBuiltRemoteDictionariesPath.getBuiltRemoteDictionariesPath)(configuration);
|
|
48
50
|
const dictionariesPath = filterDictionaries(
|
|
49
51
|
(0, import_getBuiltDictionariesPath.getBuiltDictionariesPath)(configuration),
|
|
50
52
|
dictionariesKeys
|
|
51
53
|
);
|
|
52
|
-
for (const format of formats) {
|
|
53
|
-
writeDictionaryFiles(
|
|
54
|
-
dictionariesPath,
|
|
55
|
-
"dictionaries",
|
|
56
|
-
format,
|
|
57
|
-
configuration
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
54
|
const unmergedDictionariesPath = (0, import_getBuiltUnmergedDictionariesPath.getBuiltUnmergedDictionariesPath)(configuration);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
format,
|
|
66
|
-
configuration
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
for (const format of formats) {
|
|
70
|
-
const dynamicDictionariesPathCJS = (0, import_getBuiltDynamicDictionariesPath.getBuiltDynamicDictionariesPath)(
|
|
71
|
-
configuration,
|
|
55
|
+
const writeOperations = [
|
|
56
|
+
...formats.map((format) => ({
|
|
57
|
+
paths: remoteDictionariesPath,
|
|
58
|
+
fileName: "remote_dictionaries",
|
|
72
59
|
format
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
format
|
|
78
|
-
|
|
79
|
-
)
|
|
80
|
-
|
|
60
|
+
})),
|
|
61
|
+
...formats.map((format) => ({
|
|
62
|
+
paths: dictionariesPath,
|
|
63
|
+
fileName: "dictionaries",
|
|
64
|
+
format
|
|
65
|
+
})),
|
|
66
|
+
...formats.map((format) => ({
|
|
67
|
+
paths: unmergedDictionariesPath,
|
|
68
|
+
fileName: "unmerged_dictionaries",
|
|
69
|
+
format
|
|
70
|
+
})),
|
|
71
|
+
...formats.map((format) => ({
|
|
72
|
+
paths: (0, import_getBuiltDynamicDictionariesPath.getBuiltDynamicDictionariesPath)(configuration, format),
|
|
73
|
+
fileName: "dynamic_dictionaries",
|
|
74
|
+
format
|
|
75
|
+
})),
|
|
76
|
+
...formats.map((format) => ({
|
|
77
|
+
paths: (0, import_getBuiltFetchDictionariesPath.getBuiltFetchDictionariesPath)(configuration, format),
|
|
78
|
+
fileName: "fetch_dictionaries",
|
|
79
|
+
format
|
|
80
|
+
}))
|
|
81
|
+
];
|
|
82
|
+
await (0, import_parallelize.parallelize)(
|
|
83
|
+
writeOperations,
|
|
84
|
+
async ({ paths, fileName, format }) => writeDictionaryFiles(paths, fileName, format, configuration)
|
|
85
|
+
);
|
|
81
86
|
};
|
|
82
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
88
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from '../../getBuiltDynamicDictionariesPath';\nimport { getBuiltFetchDictionariesPath } from '../../getBuiltFetchDictionariesPath';\nimport { getBuiltRemoteDictionariesPath } from '../../getBuiltRemoteDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { parallelize } from '../../utils/parallelize';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\nconst filterDictionaries = (paths: string[], keys?: string[]) => {\n if (!keys) return paths;\n return paths.filter((path) =>\n keys.some((key) => path.endsWith(`${key}.json`))\n );\n};\n\nconst writeDictionaryFiles = async (\n paths: string[],\n fileName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(paths, format, configuration);\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n await writeFile(resolve(mainDir, `${fileName}.${extension}`), content);\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = async (\n configuration = getConfiguration(),\n dictionariesKeys?: string[],\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { mainDir } = configuration.content;\n\n await mkdir(mainDir, { recursive: true });\n\n const remoteDictionariesPath = getBuiltRemoteDictionariesPath(configuration);\n const dictionariesPath = filterDictionaries(\n getBuiltDictionariesPath(configuration),\n dictionariesKeys\n );\n const unmergedDictionariesPath =\n getBuiltUnmergedDictionariesPath(configuration);\n\n const writeOperations = [\n ...formats.map((format) => ({\n paths: remoteDictionariesPath,\n fileName: 'remote_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: dictionariesPath,\n fileName: 'dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: unmergedDictionariesPath,\n fileName: 'unmerged_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltDynamicDictionariesPath(configuration, format),\n fileName: 'dynamic_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltFetchDictionariesPath(configuration, format),\n fileName: 'fetch_dictionaries' as const,\n format,\n })),\n ];\n\n await parallelize(writeOperations, async ({ paths, fileName, format }) =>\n writeDictionaryFiles(paths, fileName, format, configuration)\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,sBAAiC;AACjC,kBAAwB;AACxB,sCAAyC;AACzC,6CAAgD;AAChD,2CAA8C;AAC9C,4CAA+C;AAC/C,8CAAiD;AACjD,yBAA4B;AAC5B,2CAA8C;AAE9C,MAAM,qBAAqB,CAAC,OAAiB,SAAoB;AAC/D,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,MAAM;AAAA,IAAO,CAAC,SACnB,KAAK,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,GAAG,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,MAAM,uBAAuB,OAC3B,OACA,UACA,QACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,cAAU,oEAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,YAAM,+BAAU,qBAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACvE;AAKO,MAAM,6BAA6B,OACxC,oBAAgB,gCAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,YAAM,uBAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAExC,QAAM,6BAAyB,sEAA+B,aAAa;AAC3E,QAAM,mBAAmB;AAAA,QACvB,0DAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AACA,QAAM,+BACJ,0EAAiC,aAAa;AAEhD,QAAM,kBAAkB;AAAA,IACtB,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,WAAO,wEAAgC,eAAe,MAAM;AAAA,MAC5D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,WAAO,oEAA8B,eAAe,MAAM;AAAA,MAC1D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,YAAM;AAAA,IAAY;AAAA,IAAiB,OAAO,EAAE,OAAO,UAAU,OAAO,MAClE,qBAAqB,OAAO,UAAU,QAAQ,aAAa;AAAA,EAC7D;AACF;","names":[]}
|
|
@@ -34,7 +34,7 @@ __export(createModuleAugmentation_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(createModuleAugmentation_exports);
|
|
35
35
|
var import_config = require("@intlayer/config");
|
|
36
36
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
37
|
-
var
|
|
37
|
+
var import_promises = require("fs/promises");
|
|
38
38
|
var import_path = require("path");
|
|
39
39
|
var import_getFileHash = require('../../utils/getFileHash.cjs');
|
|
40
40
|
var import_kebabCaseToCamelCase = require('../../utils/kebabCaseToCamelCase.cjs');
|
|
@@ -90,11 +90,9 @@ ${formattedDictionaryMap}
|
|
|
90
90
|
fileContent += `}`;
|
|
91
91
|
return fileContent;
|
|
92
92
|
};
|
|
93
|
-
const createModuleAugmentation = (configuration = (0, import_config.getConfiguration)()) => {
|
|
93
|
+
const createModuleAugmentation = async (configuration = (0, import_config.getConfiguration)()) => {
|
|
94
94
|
const { moduleAugmentationDir, typesDir } = configuration.content;
|
|
95
|
-
|
|
96
|
-
(0, import_fs.mkdirSync)(moduleAugmentationDir, { recursive: true });
|
|
97
|
-
}
|
|
95
|
+
await (0, import_promises.mkdir)(moduleAugmentationDir, { recursive: true });
|
|
98
96
|
const dictionariesTypesDefinitions = import_fast_glob.default.sync(
|
|
99
97
|
(0, import_config.normalizePath)(`${typesDir}/*.ts`),
|
|
100
98
|
{
|
|
@@ -102,7 +100,7 @@ const createModuleAugmentation = (configuration = (0, import_config.getConfigura
|
|
|
102
100
|
}
|
|
103
101
|
);
|
|
104
102
|
const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);
|
|
105
|
-
(0,
|
|
103
|
+
await (0, import_promises.writeFile)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
|
|
106
104
|
};
|
|
107
105
|
// Annotate the CommonJS export names for ESM import in node:
|
|
108
106
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../../utils/kebabCaseToCamelCase';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration = getConfiguration()\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent =\n \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n fileContent += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n fileContent += `declare module 'intlayer' {\\n`;\n fileContent += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n fileContent += ` type DeclaredLocales = ${formattedLocales};\\n`;\n fileContent += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n fileContent += ` ${strictModeRecord}\\n`;\n fileContent += `}`;\n\n return fileContent;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = async (\n configuration = getConfiguration()\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n await mkdir(moduleAugmentationDir, { recursive: true });\n\n const dictionariesTypesDefinitions: string[] = fg.sync(\n normalizePath(`${typesDir}/*.ts`),\n {\n ignore: ['**/*.d.ts'],\n }\n );\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n await writeFile(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyD;AACzD,uBAAe;AACf,sBAAiC;AACjC,kBAAkD;AAClD,yBAA4B;AAC5B,kCAAqC;AAE9B,MAAM,cAAc,CAAC,QAC1B,OAAG,kDAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,uBAAS;AACzB,QAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,SAAS,qBAAqB,IAAI;AAC1C,QAAM,EAAE,sBAAsB,IAAI;AAClC,QAAM,EAAE,SAAS,iBAAiB,WAAW,IAAI;AAEjD,MAAI,cACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAK,sBAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,gCAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,mBAAe,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EAC3E,CAAC;AAED,iBAAe;AAGf,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,wBACJ,gBAAgB,SAAS,IACrB,gBAAgB;AAAA,IAAO,CAAC,WACtB,QAAQ,IAAI,CAACA,YAAW,OAAOA,OAAM,CAAC,EAAE,SAAS,OAAO,MAAM,CAAC;AAAA,EACjE,IACA;AAEN,QAAM,mBAAmB,cAAc,OAAO;AAC9C,QAAM,2BAA2B,cAAc,qBAAqB;AAEpE,QAAM,mBACJ,eAAe,WACX,kFACA,eAAe,cACb,8HACA;AAsBR,iBAAe;AAAA;AACf,iBAAe;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACxF,iBAAe,4BAA4B,gBAAgB;AAAA;AAC3D,iBAAe,4BAA4B,wBAAwB;AAAA;AACnE,iBAAe;AAAA;AACf,iBAAe;AAAA;AACf,iBAAe,KAAK,gBAAgB;AAAA;AACpC,iBAAe;AAEf,SAAO;AACT;AAKO,MAAM,2BAA2B,OACtC,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,YAAM,uBAAM,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAEtD,QAAM,+BAAyC,iBAAAC,QAAG;AAAA,QAChD,6BAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,YAAM,+BAAU,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACzE;","names":["locale","fg"]}
|
|
@@ -23,8 +23,9 @@ __export(createType_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(createType_exports);
|
|
25
25
|
var import_config = require("@intlayer/config");
|
|
26
|
-
var
|
|
26
|
+
var import_promises = require("fs/promises");
|
|
27
27
|
var import_path = require("path");
|
|
28
|
+
var import_parallelize = require('../../utils/parallelize.cjs');
|
|
28
29
|
const requireUncached = (module2) => {
|
|
29
30
|
delete import_config.ESMxCJSRequire.cache[import_config.ESMxCJSRequire.resolve(module2)];
|
|
30
31
|
return (0, import_config.ESMxCJSRequire)(module2);
|
|
@@ -35,23 +36,23 @@ const generateTypeScriptType = (dictionary) => {
|
|
|
35
36
|
export default ${jsonString} as const;
|
|
36
37
|
`;
|
|
37
38
|
};
|
|
38
|
-
const createTypes = (dictionariesPaths, configuration = (0, import_config.getConfiguration)()) => {
|
|
39
|
+
const createTypes = async (dictionariesPaths, configuration = (0, import_config.getConfiguration)()) => {
|
|
39
40
|
const { typesDir } = configuration.content;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
await (0, import_promises.mkdir)(typesDir, { recursive: true });
|
|
42
|
+
const results = await (0, import_parallelize.parallelize)(
|
|
43
|
+
dictionariesPaths,
|
|
44
|
+
async (dictionaryPath) => {
|
|
45
|
+
const dictionary = requireUncached(dictionaryPath);
|
|
46
|
+
if (!dictionary.key) {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
const typeDefinition = generateTypeScriptType(dictionary);
|
|
50
|
+
const outputPath = (0, import_path.resolve)(typesDir, `${dictionary.key}.ts`);
|
|
51
|
+
await (0, import_promises.writeFile)(outputPath, typeDefinition);
|
|
52
|
+
return outputPath;
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(0, import_fs.writeFileSync)(outputPath, typeDefinition);
|
|
52
|
-
resultTypesPaths.push(outputPath);
|
|
53
|
-
}
|
|
54
|
-
return resultTypesPaths;
|
|
54
|
+
);
|
|
55
|
+
return results.filter(Boolean);
|
|
55
56
|
};
|
|
56
57
|
// Annotate the CommonJS export names for ESM import in node:
|
|
57
58
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { parallelize } from '../../utils/parallelize';\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[],\n configuration: IntlayerConfig = getConfiguration()\n): Promise<string[]> => {\n const { typesDir } = configuration.content;\n\n // Create type folders if they don't exist\n await mkdir(typesDir, { recursive: true });\n\n const results = await parallelize(\n dictionariesPaths,\n async (dictionaryPath): Promise<string | undefined> => {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n return undefined;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n await writeFile(outputPath, typeDefinition);\n\n return outputPath;\n }\n );\n\n return results.filter(Boolean) as string[];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAIO;AAEP,sBAAiC;AACjC,kBAAwB;AACxB,yBAA4B;AAE5B,MAAM,kBAAkB,CAACA,YAAmB;AAC1C,SAAO,6BAAe,MAAM,6BAAe,QAAQA,OAAM,CAAC;AAC1D,aAAO,8BAAeA,OAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC;AAErD,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,OACzB,mBACA,oBAAgC,gCAAiB,MAC3B;AACtB,QAAM,EAAE,SAAS,IAAI,cAAc;AAGnC,YAAM,uBAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AAEzC,QAAM,UAAU,UAAM;AAAA,IACpB;AAAA,IACA,OAAO,mBAAgD;AACrD,YAAM,aAAyB,gBAAgB,cAAc;AAE7D,UAAI,CAAC,WAAW,KAAK;AACnB,eAAO;AAAA,MACT;AAEA,YAAM,iBAAyB,uBAAuB,UAAU;AAEhE,YAAM,iBAAqB,qBAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,gBAAM,2BAAU,YAAY,cAAc;AAE1C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,OAAO;AAC/B;","names":["module"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var formatter_exports = {};
|
|
30
|
+
__export(formatter_exports, {
|
|
31
|
+
formatLocale: () => formatLocale,
|
|
32
|
+
formatPath: () => formatPath
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(formatter_exports);
|
|
35
|
+
var import_config = require("@intlayer/config");
|
|
36
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
37
|
+
var import_core = require("@intlayer/core");
|
|
38
|
+
var import_path = require("path");
|
|
39
|
+
const formatPath = (path, color) => [path].flat().map(
|
|
40
|
+
(path2) => path2.startsWith("/") ? (0, import_path.relative)(import_built.default.content.baseDir, path2) : path2
|
|
41
|
+
).map(
|
|
42
|
+
(relativePath) => color === false ? relativePath : (0, import_config.colorizePath)(relativePath, color)
|
|
43
|
+
).join(`, `);
|
|
44
|
+
const formatLocale = (locale, color = import_config.ANSIColors.GREEN) => [locale].flat().map((locale2) => `${(0, import_core.getLocaleName)(locale2, import_config.Locales.ENGLISH)} (${locale2})`).map((text) => color === false ? text : (0, import_config.colorize)(text, color)).join(`, `);
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
formatLocale,
|
|
48
|
+
formatPath
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=formatter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/formatter.ts"],"sourcesContent":["import { ANSIColors, colorize, colorizePath, Locales } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { getLocaleName } from '@intlayer/core';\nimport { relative } from 'path';\n\nexport const formatPath = (\n path: string | string[],\n color?: ANSIColors | false\n) =>\n [path]\n .flat()\n .map((path) =>\n path.startsWith('/')\n ? relative(configuration.content.baseDir, path)\n : path\n )\n .map((relativePath) =>\n color === false ? relativePath : colorizePath(relativePath, color)\n )\n .join(`, `);\n\nexport const formatLocale = (\n locale: Locales | Locales[],\n color: ANSIColors | false = ANSIColors.GREEN\n) =>\n [locale]\n .flat()\n .map((locale) => `${getLocaleName(locale, Locales.ENGLISH)} (${locale})`)\n .map((text) => (color === false ? text : colorize(text, color)))\n .join(`, `);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4D;AAC5D,mBAA0B;AAC1B,kBAA8B;AAC9B,kBAAyB;AAElB,MAAM,aAAa,CACxB,MACA,UAEA,CAAC,IAAI,EACF,KAAK,EACL;AAAA,EAAI,CAACA,UACJA,MAAK,WAAW,GAAG,QACf,sBAAS,aAAAC,QAAc,QAAQ,SAASD,KAAI,IAC5CA;AACN,EACC;AAAA,EAAI,CAAC,iBACJ,UAAU,QAAQ,mBAAe,4BAAa,cAAc,KAAK;AACnE,EACC,KAAK,IAAI;AAEP,MAAM,eAAe,CAC1B,QACA,QAA4B,yBAAW,UAEvC,CAAC,MAAM,EACJ,KAAK,EACL,IAAI,CAACE,YAAW,OAAG,2BAAcA,SAAQ,sBAAQ,OAAO,CAAC,KAAKA,OAAM,GAAG,EACvE,IAAI,CAAC,SAAU,UAAU,QAAQ,WAAO,wBAAS,MAAM,KAAK,CAAE,EAC9D,KAAK,IAAI;","names":["path","configuration","locale"]}
|