@intlayer/chokidar 6.0.2 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -66
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/buildIntlayerDictionary.cjs +18 -2
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -0
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/index.cjs +4 -4
- package/dist/cjs/buildIntlayerDictionary/index.cjs.map +1 -0
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/processContentDeclaration.cjs +1 -1
- package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs.map +1 -0
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeDynamicDictionary.cjs +3 -3
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -0
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeFetchDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -0
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeMergedDictionary.cjs +4 -4
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs.map +1 -0
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeRemoteDictionary.cjs +4 -4
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs.map +1 -0
- package/dist/cjs/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeUnmergedDictionary.cjs +4 -4
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs.map +1 -0
- package/dist/cjs/{transpiler/dictionary_to_main → createDictionaryEntryPoint}/createDictionaryEntryPoint.cjs +7 -7
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs.map +1 -0
- package/dist/cjs/{transpiler/dictionary_to_main → createDictionaryEntryPoint}/generateDictionaryListContent.cjs +1 -1
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -0
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs.map +1 -0
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs.map +1 -0
- package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs.map +1 -0
- package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs.map +1 -0
- package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs.map +1 -0
- package/dist/cjs/createDictionaryEntryPoint/index.cjs +35 -0
- package/dist/cjs/createDictionaryEntryPoint/index.cjs.map +1 -0
- package/dist/cjs/{transpiler/dictionary_to_type → createType}/createModuleAugmentation.cjs +3 -3
- package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -0
- package/dist/cjs/{transpiler/dictionary_to_type → createType}/createType.cjs +1 -1
- package/dist/cjs/createType/createType.cjs.map +1 -0
- package/dist/cjs/{transpiler/dictionary_to_type → createType}/index.cjs +4 -4
- package/dist/cjs/createType/index.cjs.map +1 -0
- package/dist/cjs/filterInvalidDictionaries.cjs +32 -40
- package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -1
- package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +54 -0
- package/dist/cjs/handleAdditionalContentDeclarationFile.cjs.map +1 -0
- package/dist/cjs/handleContentDeclarationFileChange.cjs +59 -0
- package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -0
- package/dist/cjs/handleUnlikedContentDeclarationFile.cjs +57 -0
- package/dist/cjs/handleUnlikedContentDeclarationFile.cjs.map +1 -0
- package/dist/cjs/index.cjs +35 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/listDictionariesPath.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +6 -3
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +8 -4
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +10 -8
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +2 -2
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -1
- package/dist/cjs/utils/extractErrorMessage.cjs +22 -10
- package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -1
- package/dist/cjs/utils/parallelize.cjs +139 -12
- package/dist/cjs/utils/parallelize.cjs.map +1 -1
- package/dist/cjs/utils/runParallel.cjs +77 -0
- package/dist/cjs/utils/runParallel.cjs.map +1 -0
- package/dist/cjs/watcher.cjs +89 -0
- package/dist/cjs/watcher.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +770 -0
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +46 -55
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +12 -288
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/buildIntlayerDictionary.mjs +18 -2
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -0
- package/dist/esm/buildIntlayerDictionary/index.mjs.map +1 -0
- package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/processContentDeclaration.mjs +1 -1
- package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs.map +1 -0
- package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeDynamicDictionary.mjs +3 -3
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -0
- package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeFetchDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -0
- package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeMergedDictionary.mjs +4 -4
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs.map +1 -0
- package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeRemoteDictionary.mjs +4 -4
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs.map +1 -0
- package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeUnmergedDictionary.mjs +4 -4
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs.map +1 -0
- package/dist/esm/{transpiler/dictionary_to_main → createDictionaryEntryPoint}/createDictionaryEntryPoint.mjs +7 -7
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs.map +1 -0
- package/dist/esm/{transpiler/dictionary_to_main → createDictionaryEntryPoint}/generateDictionaryListContent.mjs +1 -1
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -0
- package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs.map +1 -0
- package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs.map +1 -0
- package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs.map +1 -0
- package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs.map +1 -0
- package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs.map +1 -0
- package/dist/esm/createDictionaryEntryPoint/index.mjs +8 -0
- package/dist/esm/createDictionaryEntryPoint/index.mjs.map +1 -0
- package/dist/esm/{transpiler/dictionary_to_type → createType}/createModuleAugmentation.mjs +3 -3
- package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -0
- package/dist/esm/{transpiler/dictionary_to_type → createType}/createType.mjs +1 -1
- package/dist/esm/createType/createType.mjs.map +1 -0
- package/dist/esm/createType/index.mjs.map +1 -0
- package/dist/esm/filterInvalidDictionaries.mjs +29 -28
- package/dist/esm/filterInvalidDictionaries.mjs.map +1 -1
- package/dist/esm/handleAdditionalContentDeclarationFile.mjs +30 -0
- package/dist/esm/handleAdditionalContentDeclarationFile.mjs.map +1 -0
- package/dist/esm/handleContentDeclarationFileChange.mjs +35 -0
- package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -0
- package/dist/esm/handleUnlikedContentDeclarationFile.mjs +33 -0
- package/dist/esm/handleUnlikedContentDeclarationFile.mjs.map +1 -0
- package/dist/esm/index.mjs +29 -14
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/listDictionariesPath.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +10 -4
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +12 -5
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +8 -9
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +2 -2
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -1
- package/dist/esm/utils/extractErrorMessage.mjs +22 -10
- package/dist/esm/utils/extractErrorMessage.mjs.map +1 -1
- package/dist/esm/utils/parallelize.mjs +137 -1
- package/dist/esm/utils/parallelize.mjs.map +1 -1
- package/dist/esm/utils/runParallel.mjs +43 -0
- package/dist/esm/utils/runParallel.mjs.map +1 -0
- package/dist/esm/watcher.mjs +67 -0
- package/dist/esm/watcher.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs +751 -0
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +47 -56
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +15 -279
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
- package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/buildIntlayerDictionary.d.ts +1 -1
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/index.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/index.d.ts +8 -0
- package/dist/types/createDictionaryEntryPoint/index.d.ts.map +1 -0
- package/dist/types/createType/createModuleAugmentation.d.ts.map +1 -0
- package/dist/types/createType/createType.d.ts.map +1 -0
- package/dist/types/createType/index.d.ts.map +1 -0
- package/dist/types/filterInvalidDictionaries.d.ts +3 -1
- package/dist/types/filterInvalidDictionaries.d.ts.map +1 -1
- package/dist/types/handleAdditionalContentDeclarationFile.d.ts +3 -0
- package/dist/types/handleAdditionalContentDeclarationFile.d.ts.map +1 -0
- package/dist/types/handleContentDeclarationFileChange.d.ts +3 -0
- package/dist/types/handleContentDeclarationFileChange.d.ts.map +1 -0
- package/dist/types/handleUnlikedContentDeclarationFile.d.ts +3 -0
- package/dist/types/handleUnlikedContentDeclarationFile.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/listDictionariesPath.d.ts +5 -0
- package/dist/types/listDictionariesPath.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +2 -1
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts +1 -1
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts.map +1 -1
- package/dist/types/utils/extractErrorMessage.d.ts.map +1 -1
- package/dist/types/utils/parallelize.d.ts +12 -0
- package/dist/types/utils/parallelize.d.ts.map +1 -1
- package/dist/types/utils/runParallel.d.ts +11 -0
- package/dist/types/utils/runParallel.d.ts.map +1 -0
- package/dist/types/watcher.d.ts +12 -0
- package/dist/types/watcher.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/transformJSFile.d.ts +9 -0
- package/dist/types/writeContentDeclaration/transformJSFile.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +3 -2
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
- package/package.json +24 -29
- package/dist/cjs/chokidar/index.cjs +0 -23
- package/dist/cjs/chokidar/index.cjs.map +0 -1
- package/dist/cjs/chokidar/watcher.cjs +0 -157
- package/dist/cjs/chokidar/watcher.cjs.map +0 -1
- package/dist/cjs/getBuiltDictionariesPath.cjs.map +0 -1
- package/dist/cjs/getBuiltDynamicDictionariesPath.cjs.map +0 -1
- package/dist/cjs/getBuiltFetchDictionariesPath.cjs.map +0 -1
- package/dist/cjs/getBuiltRemoteDictionariesPath.cjs.map +0 -1
- package/dist/cjs/getBuiltUnmergedDictionariesPath.cjs.map +0 -1
- package/dist/cjs/reduceDictionaryContent/buildMask.cjs +0 -49
- package/dist/cjs/reduceDictionaryContent/buildMask.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/generateDictionaryListContent.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +0 -25
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/buildIntlayerDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/processContentDeclaration.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/writeDynamicDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/writeFetchDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/writeMergedDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/writeRemoteDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/intlayer_dictionary/writeUnmergedDictionary.cjs.map +0 -1
- package/dist/esm/chokidar/index.mjs +0 -2
- package/dist/esm/chokidar/index.mjs.map +0 -1
- package/dist/esm/chokidar/watcher.mjs +0 -135
- package/dist/esm/chokidar/watcher.mjs.map +0 -1
- package/dist/esm/getBuiltDictionariesPath.mjs.map +0 -1
- package/dist/esm/getBuiltDynamicDictionariesPath.mjs.map +0 -1
- package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +0 -1
- package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +0 -1
- package/dist/esm/getBuiltUnmergedDictionariesPath.mjs.map +0 -1
- package/dist/esm/reduceDictionaryContent/buildMask.mjs +0 -24
- package/dist/esm/reduceDictionaryContent/buildMask.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/generateDictionaryListContent.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +0 -3
- package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/buildIntlayerDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/processContentDeclaration.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/writeDynamicDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/writeFetchDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/writeMergedDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/writeRemoteDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/intlayer_dictionary/writeUnmergedDictionary.mjs.map +0 -1
- package/dist/types/chokidar/index.d.ts +0 -2
- package/dist/types/chokidar/index.d.ts.map +0 -1
- package/dist/types/chokidar/watcher.d.ts +0 -14
- package/dist/types/chokidar/watcher.d.ts.map +0 -1
- package/dist/types/getBuiltDictionariesPath.d.ts.map +0 -1
- package/dist/types/getBuiltDynamicDictionariesPath.d.ts.map +0 -1
- package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +0 -1
- package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +0 -1
- package/dist/types/getBuiltUnmergedDictionariesPath.d.ts.map +0 -1
- package/dist/types/reduceDictionaryContent/buildMask.d.ts +0 -5
- package/dist/types/reduceDictionaryContent/buildMask.d.ts.map +0 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +0 -1
- package/dist/types/transpiler/dictionary_to_main/generateDictionaryListContent.d.ts.map +0 -1
- package/dist/types/transpiler/dictionary_to_main/index.d.ts +0 -3
- package/dist/types/transpiler/dictionary_to_main/index.d.ts.map +0 -1
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +0 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +0 -1
- package/dist/types/transpiler/dictionary_to_type/index.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/index.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/processContentDeclaration.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/writeDynamicDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/writeFetchDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/writeMergedDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/writeRemoteDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +0 -1
- /package/dist/cjs/{getBuiltDictionariesPath.cjs → createDictionaryEntryPoint/getBuiltDictionariesPath.cjs} +0 -0
- /package/dist/cjs/{getBuiltDynamicDictionariesPath.cjs → createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs} +0 -0
- /package/dist/cjs/{getBuiltFetchDictionariesPath.cjs → createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs} +0 -0
- /package/dist/cjs/{getBuiltRemoteDictionariesPath.cjs → createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs} +0 -0
- /package/dist/cjs/{getBuiltUnmergedDictionariesPath.cjs → createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs} +0 -0
- /package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/index.mjs +0 -0
- /package/dist/esm/{getBuiltDictionariesPath.mjs → createDictionaryEntryPoint/getBuiltDictionariesPath.mjs} +0 -0
- /package/dist/esm/{getBuiltDynamicDictionariesPath.mjs → createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs} +0 -0
- /package/dist/esm/{getBuiltFetchDictionariesPath.mjs → createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs} +0 -0
- /package/dist/esm/{getBuiltRemoteDictionariesPath.mjs → createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs} +0 -0
- /package/dist/esm/{getBuiltUnmergedDictionariesPath.mjs → createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs} +0 -0
- /package/dist/esm/{transpiler/dictionary_to_type → createType}/index.mjs +0 -0
- /package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/index.d.ts +0 -0
- /package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/processContentDeclaration.d.ts +0 -0
- /package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeDynamicDictionary.d.ts +0 -0
- /package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeFetchDictionary.d.ts +0 -0
- /package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeMergedDictionary.d.ts +0 -0
- /package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeRemoteDictionary.d.ts +0 -0
- /package/dist/types/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeUnmergedDictionary.d.ts +0 -0
- /package/dist/types/{transpiler/dictionary_to_main → createDictionaryEntryPoint}/createDictionaryEntryPoint.d.ts +0 -0
- /package/dist/types/{transpiler/dictionary_to_main → createDictionaryEntryPoint}/generateDictionaryListContent.d.ts +0 -0
- /package/dist/types/{getBuiltDictionariesPath.d.ts → createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts} +0 -0
- /package/dist/types/{getBuiltDynamicDictionariesPath.d.ts → createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts} +0 -0
- /package/dist/types/{getBuiltFetchDictionariesPath.d.ts → createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts} +0 -0
- /package/dist/types/{getBuiltRemoteDictionariesPath.d.ts → createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts} +0 -0
- /package/dist/types/{getBuiltUnmergedDictionariesPath.d.ts → createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts} +0 -0
- /package/dist/types/{transpiler/dictionary_to_type → createType}/createModuleAugmentation.d.ts +0 -0
- /package/dist/types/{transpiler/dictionary_to_type → createType}/createType.d.ts +0 -0
- /package/dist/types/{transpiler/dictionary_to_type → createType}/index.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import * as generate from '@babel/generator';\nimport * as babelParser from '@babel/parser';\nimport type { NodePath } from '@babel/traverse';\nimport * as babelTraverse from '@babel/traverse';\nimport * as t from '@babel/types';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport {\n Dictionary,\n NodeType,\n TranslationContent,\n TypedNode,\n} from '@intlayer/core';\nimport { existsSync } from 'fs';\nimport { readFile, writeFile } from 'fs/promises';\nimport { extname } from 'path';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport { formatCode } from './formatCode';\n\n/**\n * Updates a JavaScriptå/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary\n): Promise<void> => {\n // Ensure compatibility with various ESM/CJS interop shapes of @babel/traverse\n const normalizeTraverse = (mod: unknown) => {\n const candidate = mod as any;\n if (typeof candidate === 'function') return candidate;\n if (candidate?.default) {\n if (typeof candidate.default === 'function') return candidate.default;\n if (typeof candidate.default?.default === 'function')\n return candidate.default.default;\n if (typeof candidate.default?.traverse === 'function')\n return candidate.default.traverse;\n }\n if (typeof candidate?.traverse === 'function') return candidate.traverse;\n return candidate;\n };\n\n const traverse = normalizeTraverse(babelTraverse) as any;\n const appLogger = getAppLogger(configuration);\n\n const {\n key: dictionaryIdentifierKey,\n content: updatesToApply,\n locale,\n autoFilled,\n } = dictionary;\n const isPerLocaleDeclarationFile = typeof locale === 'string';\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath);\n\n let format = 'ts' as 'ts' | 'cjs' | 'esm';\n\n if (fileExtension === '.ts' || fileExtension === '.tsx') {\n format = 'ts';\n } else if (fileExtension === '.cjs' || fileExtension === '.cjsx') {\n format = 'cjs';\n } else {\n format = 'esm';\n }\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n dictionaryIdentifierKey,\n format,\n { locale, autoFilled }\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n let sourceCode: string;\n try {\n sourceCode = await readFile(filePath, 'utf-8');\n } catch (error) {\n const err = error as Error;\n appLogger(`Failed to read file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to read file ${filePath}: ${err.message}`);\n }\n\n const ast = babelParser.parse(sourceCode, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n tokens: true,\n });\n\n let dictionaryObjectPath: NodePath<t.ObjectExpression> | null = null;\n let dictionaryIdentifier: string | null = null;\n\n // First look for direct objects with the right key, regardless of variable assignments\n traverse(ast, {\n ObjectExpression(path: NodePath<t.ObjectExpression>) {\n if (dictionaryObjectPath) return; // Already found\n\n // Check if this object has a key property with the right value\n const keyProp = path.node.properties.find(\n (prop: t.ObjectProperty | t.SpreadElement | t.ObjectMethod) => {\n if (!t.isObjectProperty(prop)) return false;\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return false;\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n\n if (keyName !== 'key' || !t.isStringLiteral(prop.value)) return false;\n\n // Unescape the value for comparison\n const propValue = prop.value.value;\n // Compare actual string content, not just raw representation\n return propValue === dictionaryIdentifierKey;\n }\n );\n\n if (keyProp) {\n dictionaryObjectPath = path;\n path.stop();\n }\n },\n });\n\n // If not found directly, look for variable declarations and exports\n if (!dictionaryObjectPath) {\n appLogger(`Looking for variable declarations`, {\n isVerbose: true,\n });\n\n // Collect all variable declarations with objects\n const candidateVars: { id: string; path: NodePath<t.ObjectExpression> }[] =\n [];\n\n traverse(ast, {\n VariableDeclarator(path: NodePath<t.VariableDeclarator>) {\n const { node } = path;\n if (!t.isIdentifier(node.id)) return;\n\n let objPath: NodePath<t.ObjectExpression> | null = null;\n\n // Direct object assignment\n if (node.init && t.isObjectExpression(node.init)) {\n objPath = path.get('init') as NodePath<t.ObjectExpression>;\n }\n // Object with TS type assertion (satisfies/as)\n else if (\n node.init &&\n (t.isTSAsExpression(node.init) || t.isTSTypeAssertion(node.init)) &&\n t.isObjectExpression(node.init.expression)\n ) {\n objPath = path.get('init.expression') as NodePath<t.ObjectExpression>;\n }\n\n if (objPath) {\n candidateVars.push({ id: node.id.name, path: objPath });\n }\n },\n });\n\n appLogger(`Found ${candidateVars.length} candidate variables`, {\n isVerbose: true,\n });\n\n // Check each candidate for the key property\n for (const { id, path } of candidateVars) {\n const keyProp = path.node.properties.find((prop) => {\n if (!t.isObjectProperty(prop)) return false;\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return false;\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n return (\n keyName === 'key' &&\n t.isStringLiteral(prop.value) &&\n prop.value.value === dictionaryIdentifierKey\n );\n });\n\n if (keyProp) {\n appLogger(`Found match in variable: ${id}`);\n dictionaryObjectPath = path;\n dictionaryIdentifier = id;\n break;\n }\n }\n\n // If still not found, dump all object expressions for debugging\n if (!dictionaryObjectPath) {\n appLogger('Could not find dictionary object. Dumping all objects:', {\n isVerbose: true,\n });\n traverse(ast, {\n ObjectExpression(path: NodePath<t.ObjectExpression>) {\n const props = path.node.properties\n .map(\n (prop: t.ObjectProperty | t.SpreadElement | t.ObjectMethod) => {\n if (!t.isObjectProperty(prop)) return 'non-object-property';\n if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))\n return 'complex-key';\n\n const keyName = t.isIdentifier(prop.key)\n ? prop.key.name\n : prop.key.value;\n let valueDesc = 'unknown-value';\n\n if (t.isStringLiteral(prop.value)) {\n valueDesc = `\"${prop.value.value}\"`;\n }\n\n return `${keyName}: ${valueDesc}`;\n }\n )\n .join(', ');\n\n appLogger(`Object: { ${props} }`);\n },\n });\n }\n }\n\n if (!dictionaryObjectPath) {\n throw new Error(\n `Could not find dictionary object with key '${dictionaryIdentifierKey}' in ${filePath}`\n );\n }\n\n // Find the 'content' property within the identified dictionary object\n const contentPropertyPath = (\n (dictionaryObjectPath as any).get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === 'content';\n });\n\n if (\n !contentPropertyPath ||\n !contentPropertyPath.isObjectProperty() ||\n !(contentPropertyPath.get('value') as NodePath).isObjectExpression()\n ) {\n throw new Error(\n `Could not find 'content' object property, or it's not an object, in dictionary in ${filePath}`\n );\n }\n\n const contentObjectPath = contentPropertyPath.get(\n 'value'\n ) as NodePath<t.ObjectExpression>;\n\n /**\n * Build a Babel Expression for any JSON-serializable value or TypedNode.\n * - Translation nodes become t({...}) or string literal in per-locale files\n * - Objects recurse to ObjectExpression\n * - Arrays recurse to ArrayExpression\n * - Strings/numbers/booleans/null to corresponding literals\n */\n const buildValueNodeFromData = (data: any): t.Expression => {\n // Translation typed node\n if ((data as TypedNode)?.nodeType === NodeType.Translation) {\n const translationContent = data as TranslationContent;\n if (\n isPerLocaleDeclarationFile &&\n typeof locale === 'string' &&\n translationContent?.[NodeType.Translation]?.[locale] !== undefined\n ) {\n return buildValueNodeFromData(\n translationContent[NodeType.Translation][locale]\n );\n }\n const translationsObj = t.objectExpression(\n Object.entries(translationContent?.[NodeType.Translation] ?? {}).map(\n ([langKey, langValue]) => {\n const keyNode = t.isValidIdentifier(langKey)\n ? t.identifier(langKey)\n : t.stringLiteral(langKey);\n return t.objectProperty(keyNode, buildValueNodeFromData(langValue));\n }\n )\n );\n return t.callExpression(t.identifier('t'), [translationsObj]);\n }\n\n // Arrays\n if (Array.isArray(data)) {\n return t.arrayExpression(data.map((el) => buildValueNodeFromData(el)));\n }\n\n // Objects (plain)\n if (data && typeof data === 'object') {\n const props = Object.entries(data).map(([k, v]) => {\n const key = t.isValidIdentifier(k)\n ? t.identifier(k)\n : t.stringLiteral(k);\n return t.objectProperty(key, buildValueNodeFromData(v));\n });\n return t.objectExpression(props);\n }\n\n // Primitives\n switch (typeof data) {\n case 'string':\n return t.stringLiteral(data);\n case 'number':\n return t.numericLiteral(data);\n case 'boolean':\n return t.booleanLiteral(data);\n default:\n return t.nullLiteral();\n }\n };\n\n /** Ensure an object property exists on a given object expression path. */\n const ensureObjectProperty = (\n objPath: NodePath<t.ObjectExpression>,\n key: string\n ): NodePath<t.ObjectProperty> => {\n const existing = (\n objPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === key;\n }) as NodePath<t.ObjectProperty> | undefined;\n\n if (existing) return existing;\n\n const keyNode = t.isValidIdentifier(key)\n ? t.identifier(key)\n : t.stringLiteral(key);\n const newProp = t.objectProperty(keyNode, t.objectExpression([]));\n objPath.node.properties.push(newProp);\n\n // Return a fresh path for the newly pushed property\n const props = objPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[];\n return props[props.length - 1] as NodePath<t.ObjectProperty>;\n };\n\n /** Recursively merge a JSON-like value into an ObjectExpression property path. */\n const mergeValueIntoProperty = (\n propPath: NodePath<t.ObjectProperty>,\n value: any,\n propKeyForLogs: string\n ) => {\n const valuePath = propPath.get('value') as NodePath;\n\n // Translation typed node → either update t() args or replace value\n if ((value as TypedNode)?.nodeType === NodeType.Translation) {\n const translationContent = value as TranslationContent;\n if (\n valuePath.isCallExpression() &&\n t.isIdentifier(valuePath.node.callee) &&\n valuePath.node.callee.name === 't'\n ) {\n // Replace argument with the full translations object (simpler and robust)\n const translationsObj = t.objectExpression(\n Object.entries(translationContent?.[NodeType.Translation] ?? {}).map(\n ([langKey, langValue]) =>\n t.objectProperty(\n t.isValidIdentifier(langKey)\n ? t.identifier(langKey)\n : t.stringLiteral(langKey),\n buildValueNodeFromData(langValue)\n )\n )\n );\n\n if (isPerLocaleDeclarationFile && typeof locale === 'string') {\n const localized =\n translationContent?.[NodeType.Translation]?.[locale];\n if (localized !== undefined) {\n valuePath.replaceWith(buildValueNodeFromData(localized));\n return;\n }\n }\n\n (valuePath.node as t.CallExpression).arguments = [translationsObj];\n return;\n }\n\n // Otherwise, replace with a fresh node\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n }\n\n // Arrays → replace entirely\n if (Array.isArray(value)) {\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n }\n\n // Objects → ensure object expression and recurse into each key\n if (value && typeof value === 'object') {\n if (!valuePath.isObjectExpression()) {\n valuePath.replaceWith(t.objectExpression([]));\n }\n const objPath = valuePath as NodePath<t.ObjectExpression>;\n for (const [k, v] of Object.entries(value)) {\n const childProp = ensureObjectProperty(objPath, k);\n mergeValueIntoProperty(childProp, v, `${propKeyForLogs}.${k}`);\n }\n return;\n }\n\n // Primitives → replace\n valuePath.replaceWith(buildValueNodeFromData(value));\n return;\n };\n\n // Apply updates to each entry specified in the JSON (now supports deep nesting)\n for (const [entryKeyToUpdate, newEntryData] of Object.entries(\n updatesToApply\n )) {\n let targetPropertyPath = (\n contentObjectPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[]\n ).find((propPath) => {\n if (!propPath.isObjectProperty()) return false;\n const propNode = propPath.node;\n const keyName = t.isIdentifier(propNode.key)\n ? propNode.key.name\n : t.isStringLiteral(propNode.key)\n ? propNode.key.value\n : null;\n return keyName === entryKeyToUpdate;\n }) as NodePath<t.ObjectProperty> | undefined;\n\n if (!targetPropertyPath) {\n const keyNode = t.isValidIdentifier(entryKeyToUpdate)\n ? t.identifier(entryKeyToUpdate)\n : t.stringLiteral(entryKeyToUpdate);\n // By default create an empty object; merge will replace if needed\n const newProperty = t.objectProperty(keyNode, t.objectExpression([]));\n contentObjectPath.node.properties.push(newProperty);\n const props = contentObjectPath.get('properties') as NodePath<\n t.ObjectProperty | t.SpreadElement | t.ObjectMethod\n >[];\n targetPropertyPath = props[\n props.length - 1\n ] as NodePath<t.ObjectProperty>;\n }\n\n mergeValueIntoProperty(targetPropertyPath, newEntryData, entryKeyToUpdate);\n }\n\n // Generate JavaScript/TypeScript code from the modified AST\n const generatedCode = generate.generate(ast, {\n retainLines: true,\n comments: true,\n jsescOption: {\n minimal: true, // This ensures Unicode characters are not escaped\n },\n }).code;\n\n let finalCode = generatedCode;\n\n finalCode = await formatCode(filePath, finalCode);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAC1B,kBAA6B;AAE7B,oBAA+B;AAC/B,QAAmB;AACnB,oBAAqC;AACrC,mBAA0B;AAC1B,kBAKO;AACP,gBAA2B;AAC3B,sBAAoC;AACpC,kBAAwB;AACxB,+CAAkD;AAClD,wBAA2B;AAQpB,MAAM,cAAc,OACzB,UACA,eACkB;AAElB,QAAM,oBAAoB,CAAC,QAAiB;AAC1C,UAAM,YAAY;AAClB,QAAI,OAAO,cAAc,WAAY,QAAO;AAC5C,QAAI,WAAW,SAAS;AACtB,UAAI,OAAO,UAAU,YAAY,WAAY,QAAO,UAAU;AAC9D,UAAI,OAAO,UAAU,SAAS,YAAY;AACxC,eAAO,UAAU,QAAQ;AAC3B,UAAI,OAAO,UAAU,SAAS,aAAa;AACzC,eAAO,UAAU,QAAQ;AAAA,IAC7B;AACA,QAAI,OAAO,WAAW,aAAa,WAAY,QAAO,UAAU;AAChE,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,kBAAkB,aAAa;AAChD,QAAM,gBAAY,4BAAa,aAAAA,OAAa;AAE5C,QAAM;AAAA,IACJ,KAAK;AAAA,IACL,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,6BAA6B,OAAO,WAAW;AAGrD,MAAI,KAAC,s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,iBAAiB,EAAG,QAAO;AACzC,YAAM,WAAW,SAAS;AAC1B,YAAM,UAAU,EAAE,aAAa,SAAS,GAAG,IACvC,SAAS,IAAI,OACb,EAAE,gBAAgB,SAAS,GAAG,IAC5B,SAAS,IAAI,QACb;AACN,aAAO,YAAY;AAAA,IACrB,CAAC;AAED,QAAI,CAAC,oBAAoB;AACvB,YAAM,UAAU,EAAE,kBAAkB,gBAAgB,IAChD,EAAE,WAAW,gBAAgB,IAC7B,EAAE,cAAc,gBAAgB;AAEpC,YAAM,cAAc,EAAE,eAAe,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;AACpE,wBAAkB,KAAK,WAAW,KAAK,WAAW;AAClD,YAAM,QAAQ,kBAAkB,IAAI,YAAY;AAGhD,2BAAqB,MACnB,MAAM,SAAS,CACjB;AAAA,IACF;AAEA,2BAAuB,oBAAoB,cAAc,gBAAgB;AAAA,EAC3E;AAGA,QAAM,gBAAgB,SAAS,SAAS,KAAK;AAAA,IAC3C,aAAa;AAAA,IACb,UAAU;AAAA,IACV,aAAa;AAAA,MACX,SAAS;AAAA;AAAA,IACX;AAAA,EACF,CAAC,EAAE;AAEH,MAAI,YAAY;AAEhB,cAAY,UAAM,8BAAW,UAAU,SAAS;AAGhD,MAAI;AACF,cAAM,2BAAU,UAAU,WAAW,OAAO;AAC5C,8BAAO,wBAAwB,QAAQ,IAAI;AAAA,MACzC,OAAO;AAAA,MACP,WAAW;AAAA,IACb,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,MAAM;AACZ,8BAAO,iCAAiC,QAAQ,IAAI;AAAA,MAClD,OAAO;AAAA,IACT,CAAC;AACD,UAAM,IAAI,MAAM,gCAAgC,QAAQ,KAAK,IAAI,OAAO,EAAE;AAAA,EAC5E;AACF;","names":["configuration"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import {\n getAppLogger,\n getConfiguration,\n IntlayerConfig,\n logger,\n} from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { existsSync } from 'fs';\nimport { readFile, writeFile } from 'fs/promises';\nimport { extname } from 'path';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport { formatCode } from './formatCode';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig = getConfiguration()\n): Promise<void> => {\n const { key, locale, autoFilled } = dictionary;\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath);\n\n let format = 'ts' as 'ts' | 'cjs' | 'esm';\n\n if (fileExtension === '.ts' || fileExtension === '.tsx') {\n format = 'ts';\n } else if (fileExtension === '.cjs' || fileExtension === '.cjsx') {\n format = 'cjs';\n } else {\n format = 'esm';\n }\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(key, format, {\n locale,\n autoFilled,\n });\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n const fileContent = await readFile(filePath, 'utf-8');\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n const formattedCode = await formatCode(filePath, finalCode);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, formattedCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AAEP,gBAA2B;AAC3B,sBAAoC;AACpC,kBAAwB;AACxB,+CAAkD;AAClD,wBAA2B;AAC3B,6BAAgC;AAQzB,MAAM,cAAc,OACzB,UACA,YACA,oBAAgC,gCAAiB,MAC/B;AAClB,QAAM,EAAE,KAAK,QAAQ,WAAW,IAAI;AACpC,QAAM,gBAAY,4BAAa,aAAa;AAG5C,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,UAAM,oBAAgB,qBAAQ,QAAQ;AAEtC,QAAI,SAAS;AAEb,QAAI,kBAAkB,SAAS,kBAAkB,QAAQ;AACvD,eAAS;AAAA,IACX,WAAW,kBAAkB,UAAU,kBAAkB,SAAS;AAChE,eAAS;AAAA,IACX,OAAO;AACL,eAAS;AAAA,IACX;AAEA,cAAU,oCAAoC;AAAA,MAC5C,WAAW;AAAA,IACb,CAAC;AACD,UAAM,WAAW,UAAM,4EAAkC,KAAK,QAAQ;AAAA,MACpE;AAAA,MACA;AAAA,IACF,CAAC;AAED,cAAM,2BAAU,UAAU,UAAU,OAAO;AAAA,EAC7C;AAEA,QAAM,cAAc,UAAM,0BAAS,UAAU,OAAO;AAEpD,QAAM,YAAY,UAAM,wCAAgB,aAAa,UAAU;AAE/D,QAAM,gBAAgB,UAAM,8BAAW,UAAU,SAAS;AAG1D,MAAI;AACF,cAAM,2BAAU,UAAU,eAAe,OAAO;AAChD,8BAAO,wBAAwB,QAAQ,IAAI;AAAA,MACzC,OAAO;AAAA,MACP,WAAW;AAAA,IACb,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,MAAM;AACZ,8BAAO,iCAAiC,QAAQ,IAAI;AAAA,MAClD,OAAO;AAAA,IACT,CAAC;AACD,UAAM,IAAI,MAAM,gCAAgC,QAAQ,KAAK,IAAI,OAAO,EAAE;AAAA,EAC5E;AACF;","names":[]}
|
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import { getUnmergedDictionaries } from "@intlayer/unmerged-dictionaries-entry";
|
|
2
3
|
import {
|
|
3
4
|
writeDynamicDictionary
|
|
4
5
|
} from "./writeDynamicDictionary.mjs";
|
|
5
6
|
import { writeFetchDictionary } from "./writeFetchDictionary.mjs";
|
|
6
7
|
import { writeMergedDictionaries } from "./writeMergedDictionary.mjs";
|
|
7
8
|
import { writeUnmergedDictionaries } from "./writeUnmergedDictionary.mjs";
|
|
8
|
-
const buildDictionary = async (localDictionariesEntries, configuration = getConfiguration(), formats = ["cjs", "esm"]) => {
|
|
9
|
+
const buildDictionary = async (localDictionariesEntries, configuration = getConfiguration(), formats = ["cjs", "esm"], importOtherDictionaries = true) => {
|
|
9
10
|
const { importMode } = configuration.build;
|
|
11
|
+
let unmergedDictionariesToUpdate = [
|
|
12
|
+
...localDictionariesEntries
|
|
13
|
+
];
|
|
14
|
+
if (importOtherDictionaries) {
|
|
15
|
+
const prevUnmergedDictionaries = getUnmergedDictionaries(configuration);
|
|
16
|
+
for (const dictionaryToWrite of localDictionariesEntries) {
|
|
17
|
+
const allPrebuiltUnmergedDictionaries = prevUnmergedDictionaries[dictionaryToWrite.key];
|
|
18
|
+
if (allPrebuiltUnmergedDictionaries?.length > 0) {
|
|
19
|
+
const otherUnmergedDictionaries = allPrebuiltUnmergedDictionaries.filter(
|
|
20
|
+
(unmergedDictionary) => unmergedDictionary.localId !== dictionaryToWrite.localId
|
|
21
|
+
);
|
|
22
|
+
unmergedDictionariesToUpdate.push(...otherUnmergedDictionaries);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
10
26
|
const unmergedDictionaries = await writeUnmergedDictionaries(
|
|
11
|
-
|
|
27
|
+
unmergedDictionariesToUpdate,
|
|
12
28
|
configuration
|
|
13
29
|
);
|
|
14
30
|
const mergedDictionaries = await writeMergedDictionaries(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n LocalizedDictionaryOutput,\n writeDynamicDictionary,\n} from './writeDynamicDictionary';\nimport { writeFetchDictionary } from './writeFetchDictionary';\nimport { writeMergedDictionaries } from './writeMergedDictionary';\nimport { writeUnmergedDictionaries } from './writeUnmergedDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildDictionary = async (\n localDictionariesEntries: Dictionary[],\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm'],\n importOtherDictionaries = true\n) => {\n const { importMode } = configuration.build;\n\n let unmergedDictionariesToUpdate: Dictionary[] = [\n ...localDictionariesEntries,\n ];\n\n if (importOtherDictionaries) {\n const prevUnmergedDictionaries: Record<string, Dictionary[]> =\n getUnmergedDictionaries(configuration);\n\n // Reinsert other dictionaries with the same key to avoid merging errors\n for (const dictionaryToWrite of localDictionariesEntries) {\n const allPrebuiltUnmergedDictionaries =\n prevUnmergedDictionaries[dictionaryToWrite.key];\n\n if (allPrebuiltUnmergedDictionaries?.length > 0) {\n // Do not add the same dictionary again by filtering out the one with the same localId\n const otherUnmergedDictionaries =\n allPrebuiltUnmergedDictionaries.filter(\n (unmergedDictionary) =>\n unmergedDictionary.localId !== dictionaryToWrite.localId\n );\n\n unmergedDictionariesToUpdate.push(...otherUnmergedDictionaries);\n }\n }\n }\n\n const unmergedDictionaries = await writeUnmergedDictionaries(\n unmergedDictionariesToUpdate,\n configuration\n );\n\n const mergedDictionaries = await writeMergedDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n let dynamicDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'dynamic' || importMode === 'live') {\n dynamicDictionaries = await writeDynamicDictionary(\n mergedDictionaries,\n configuration,\n formats\n );\n }\n\n let fetchDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'live') {\n fetchDictionaries = await writeFetchDictionary(\n dynamicDictionaries!,\n configuration,\n formats\n );\n }\n\n return {\n unmergedDictionaries,\n mergedDictionaries,\n dynamicDictionaries,\n fetchDictionaries,\n };\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,+BAA+B;AACxC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AACxC,SAAS,iCAAiC;AAKnC,MAAM,kBAAkB,OAC7B,0BACA,gBAAgB,iBAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,GAC1C,0BAA0B,SACvB;AACH,QAAM,EAAE,WAAW,IAAI,cAAc;AAErC,MAAI,+BAA6C;AAAA,IAC/C,GAAG;AAAA,EACL;AAEA,MAAI,yBAAyB;AAC3B,UAAM,2BACJ,wBAAwB,aAAa;AAGvC,eAAW,qBAAqB,0BAA0B;AACxD,YAAM,kCACJ,yBAAyB,kBAAkB,GAAG;AAEhD,UAAI,iCAAiC,SAAS,GAAG;AAE/C,cAAM,4BACJ,gCAAgC;AAAA,UAC9B,CAAC,uBACC,mBAAmB,YAAY,kBAAkB;AAAA,QACrD;AAEF,qCAA6B,KAAK,GAAG,yBAAyB;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AAEA,QAAM,uBAAuB,MAAM;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AAEA,MAAI,sBAAwD;AAE5D,MAAI,eAAe,aAAa,eAAe,QAAQ;AACrD,0BAAsB,MAAM;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,oBAAsD;AAE1D,MAAI,eAAe,QAAQ;AACzB,wBAAoB,MAAM;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/index.ts"],"sourcesContent":["export * from './buildIntlayerDictionary';\nexport * from './processContentDeclaration';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from "@intlayer/config/client";
|
|
2
|
-
import { resolveObjectPromises } from "
|
|
2
|
+
import { resolveObjectPromises } from "../utils/resolveObjectPromises.mjs";
|
|
3
3
|
const processContentDeclaration = async (contentDeclaration) => {
|
|
4
4
|
try {
|
|
5
5
|
const content = await resolveObjectPromises(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/processContentDeclaration.ts"],"sourcesContent":["import { logger } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { resolveObjectPromises } from '../utils/resolveObjectPromises';\n\n/**\n * Function to load, process the module and return the Intlayer Dictionary from the module file\n */\nexport const processContentDeclaration = async (\n contentDeclaration: Dictionary\n): Promise<Dictionary | undefined> => {\n try {\n const content = (await resolveObjectPromises(\n contentDeclaration.content\n )) as Dictionary['content'];\n\n return {\n ...contentDeclaration,\n content,\n } as Dictionary;\n } catch (error) {\n logger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":"AAAA,SAAS,cAAc;AAEvB,SAAS,6BAA6B;AAK/B,MAAM,4BAA4B,OACvC,uBACoC;AACpC,MAAI;AACF,UAAM,UAAW,MAAM;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,WAAO,OAAO;AAAA,MACZ,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
import { getLocalisedContent } from "@intlayer/core";
|
|
7
7
|
import { mkdir } from "fs/promises";
|
|
8
8
|
import { relative, resolve } from "path";
|
|
9
|
-
import { parallelize } from "
|
|
10
|
-
import { writeFileIfChanged } from "
|
|
11
|
-
import { writeJsonIfChanged } from "
|
|
9
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
10
|
+
import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
|
|
11
|
+
import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
|
|
12
12
|
const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "esm", configuration = getConfiguration()) => {
|
|
13
13
|
const { dynamicDictionariesDir } = configuration.content;
|
|
14
14
|
let content = "";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/writeDynamicDictionary.ts"],"sourcesContent":["import {\n colorizePath,\n getConfiguration,\n Locales,\n normalizePath,\n} from '@intlayer/config';\nimport { getLocalisedContent, type Dictionary } from '@intlayer/core';\nimport { mkdir } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\nimport { MergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locales, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\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 { dynamicDictionariesDir } = configuration.content;\n\n let content = '';\n\n // Format Dictionary Map - map locales to functions\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n // The following filter/sort preserve determinism of the generated map\n // when files are built in parallel or across different Node versions.\n .filter((entry): entry is [string, DictionaryResult] => Boolean(entry[1]))\n .sort(([a], [b]) => String(a).localeCompare(String(b)))\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(dynamicDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;\n }\n\n return ` '${locale}': () => 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/dynamic_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeDynamicDictionary = async (\n mergedDictionaries: MergedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dynamicDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n Object.entries(mergedDictionaries).sort(([a], [b]) =>\n String(a).localeCompare(String(b))\n ),\n async ([key, dictionaryEntry]) => {\n if (key === 'undefined') return;\n\n let localedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n await parallelize(locales, async (locale) => {\n const localizedDictionary = {\n ...dictionaryEntry.dictionary,\n locale,\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n content: getLocalisedContent(\n JSON.parse(JSON.stringify(dictionaryEntry.dictionary.content)),\n locale,\n { dictionaryKey: key, keyPath: [] },\n defaultLocale\n ) as any,\n };\n\n const outputFileName = `${key}.${locale}.json`;\n const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);\n\n // Write the localized dictionary\n await writeJsonIfChanged(resultFilePath, localizedDictionary).catch(\n (err) => {\n console.error(`Error creating localized ${outputFileName}:`, err);\n }\n );\n\n localedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n });\n\n resultDictionariesPaths[key] = localedDictionariesPathsRecord;\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 writeFileIfChanged(\n resolve(dynamicDictionariesDir, `${key}.${extension}`),\n content\n ).catch((err) => {\n console.error(\n `Error creating dynamic ${colorizePath(resolve(dynamicDictionariesDir, `${key}.${extension}`))}:`,\n err\n );\n });\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,2BAA4C;AACrD,SAAS,aAAa;AACtB,SAAS,UAAU,eAAe;AAClC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAoB5B,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,uBAAuB,IAAI,cAAc;AAEjD,MAAI,UAAU;AAGd,QAAM,yBAAiC,OAAO;AAAA,IAC5C;AAAA,EACF,EAGG,OAAO,CAAC,UAA+C,QAAQ,MAAM,CAAC,CAAC,CAAC,EACxE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE,cAAc,OAAO,CAAC,CAAC,CAAC,EACrD,IAAI,CAAC,CAAC,QAAQ,UAAU,MAAM;AAC7B,UAAM,eAAe;AAAA,MACnB,SAAS,wBAAw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EAAE;AAAA,UAC5D,CAAC,QAAQ;AACP,oBAAQ,MAAM,4BAA4B,cAAc,KAAK,GAAG;AAAA,UAClE;AAAA,QACF;AAEA,uCAA+B,MAAM,IAAI;AAAA,UACvC,gBAAgB;AAAA,UAChB,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,8BAAwB,GAAG,IAAI;AAE/B,YAAM,YAAY,SAAS,OAAO,WAAW;AAC3C,cAAM,YAAY,WAAW,QAAQ,QAAQ;AAC7C,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,cAAM;AAAA,UACJ,QAAQ,wBAAwB,GAAG,GAAG,IAAI,SAAS,EAAE;AAAA,UACrD;AAAA,QACF,EAAE,MAAM,CAAC,QAAQ;AACf,kBAAQ;AAAA,YACN,0BAA0B,aAAa,QAAQ,wBAAwB,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,CAAC;AAAA,YAC9F;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/{transpiler/intlayer_dictionary → buildIntlayerDictionary}/writeFetchDictionary.mjs
RENAMED
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
} from "@intlayer/config";
|
|
6
6
|
import { mkdir } from "fs/promises";
|
|
7
7
|
import { relative, resolve } from "path";
|
|
8
|
-
import { parallelize } from "
|
|
9
|
-
import { writeFileIfChanged } from "
|
|
8
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
9
|
+
import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
|
|
10
10
|
const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "esm", configuration = getConfiguration()) => {
|
|
11
11
|
const { fetchDictionariesDir } = configuration.content;
|
|
12
12
|
const { liveSyncURL } = configuration.editor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/writeFetchDictionary.ts"],"sourcesContent":["import {\n colorizePath,\n getConfiguration,\n normalizePath,\n} from '@intlayer/config';\nimport { mkdir } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\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 writeFileIfChanged(\n resolve(fetchDictionariesDir, `${key}.${extension}`),\n content\n ).catch((err) => {\n console.error(\n `Error creating fetch ${colorizePath(resolve(fetchDictionariesDir, `${key}.${extension}`))}:`,\n err\n );\n });\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,UAAU,eAAe;AAClC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AAS5B,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,gBAAgB,iBAAiB,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,eAAe;AAAA,MACnB,SAAS,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,gBAAgB,iBAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACH;AACvC,QAAM,EAAE,qBAAqB,IAAI,cAAc;AAG/C,QAAM,MAAM,QAAQ,oBAAoB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE9D,MAAI,0BAAqD,CAAC;AAG1D,QAAM;AAAA,IACJ,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAK,8BAA8B,MAAM;AAC/C,UAAI,QAAQ,YAAa;AAEzB,YAAM,YAAY,SAAS,OAAO,WAAW;AAC3C,cAAM,YAAY,WAAW,QAAQ,QAAQ;AAC7C,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,cAAM;AAAA,UACJ,QAAQ,sBAAsB,GAAG,GAAG,IAAI,SAAS,EAAE;AAAA,UACnD;AAAA,QACF,EAAE,MAAM,CAAC,QAAQ;AACf,kBAAQ;AAAA,YACN,wBAAwB,aAAa,QAAQ,sBAAsB,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,CAAC;AAAA,YAC1F;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { colorizePath, getConfiguration } from "@intlayer/config";
|
|
2
2
|
import { mkdir } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
|
-
import { mergeDictionaries } from "
|
|
5
|
-
import { processPerLocaleDictionary } from "
|
|
6
|
-
import { parallelize } from "
|
|
7
|
-
import { writeJsonIfChanged } from "
|
|
4
|
+
import { mergeDictionaries } from "../mergeDictionaries.mjs";
|
|
5
|
+
import { processPerLocaleDictionary } from "../processPerLocaleDictionary.mjs";
|
|
6
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
7
|
+
import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
|
|
8
8
|
const writeMergedDictionaries = async (groupedDictionaries, configuration = getConfiguration()) => {
|
|
9
9
|
const { dictionariesDir } = configuration.content;
|
|
10
10
|
await mkdir(resolve(dictionariesDir), { recursive: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/writeMergedDictionary.ts"],"sourcesContent":["import { colorizePath, getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../processPerLocaleDictionary';\nimport { parallelize } from '../utils/parallelize';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\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 outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Write the merged dictionary\n await writeJsonIfChanged(resultFilePath, mergedDictionary).catch(\n (err) => {\n console.error(\n `Error creating merged ${colorizePath(resultFilePath)}:`,\n err\n );\n }\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,SAAS,cAAc,wBAAwB;AAE/C,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AA0B5B,MAAM,0BAA0B,OACrC,qBACA,gBAAgB,iBAAiB,MACG;AACpC,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,UAAU,MAAM;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,eAAe,2BAA2B,UAAU;AAAA,MACvD;AAEA,YAAM,mBAAmB,kBAAkB,uBAAuB;AAElE,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,YAAM,mBAAmB,gBAAgB,gBAAgB,EAAE;AAAA,QACzD,CAAC,QAAQ;AACP,kBAAQ;AAAA,YACN,yBAAyB,aAAa,cAAc,CAAC;AAAA,YACrD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,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":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { colorizePath, getConfiguration } from "@intlayer/config";
|
|
2
2
|
import { mkdir } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
|
-
import { filterInvalidDictionaries } from "
|
|
5
|
-
import { formatDistantDictionaries } from "
|
|
6
|
-
import { parallelize } from "
|
|
7
|
-
import { writeJsonIfChanged } from "
|
|
4
|
+
import { filterInvalidDictionaries } from "../filterInvalidDictionaries.mjs";
|
|
5
|
+
import { formatDistantDictionaries } from "../loadDictionaries/index.mjs";
|
|
6
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
7
|
+
import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
|
|
8
8
|
const writeRemoteDictionary = async (remoteDictionaries, configuration = getConfiguration()) => {
|
|
9
9
|
const { remoteDictionariesDir } = configuration.content;
|
|
10
10
|
await mkdir(resolve(remoteDictionariesDir), { recursive: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/writeRemoteDictionary.ts"],"sourcesContent":["import { colorizePath, getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\nimport { filterInvalidDictionaries } from '../filterInvalidDictionaries';\nimport { formatDistantDictionaries } from '../loadDictionaries';\nimport { parallelize } from '../utils/parallelize';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\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 // Write the merged dictionary\n await writeJsonIfChanged(resultFilePath, dictionary).catch((err) => {\n console.error(\n `Error creating merged ${colorizePath(resultFilePath)}:`,\n err\n );\n });\n }\n );\n\n return formatDistantDictionaries(remoteDictionaries);\n};\n"],"mappings":"AAAA,SAAS,cAAc,wBAAwB;AAE/C,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,iCAAiC;AAC1C,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AAkB5B,MAAM,wBAAwB,OACnC,oBACA,gBAAgB,iBAAiB,MACP;AAC1B,QAAM,EAAE,sBAAsB,IAAI,cAAc;AAGhD,QAAM,MAAM,QAAQ,qBAAqB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE/D,QAAM,uBAAuB,0BAA0B,kBAAkB;AAGzE,QAAM;AAAA,IACJ,qBAAqB,OAAO,CAAC,eAAe,WAAW,QAAQ,WAAW;AAAA,IAC1E,OAAO,eAAe;AACpB,YAAM,iBAAiB,GAAG,WAAW,GAAG;AACxC,YAAM,iBAAiB,QAAQ,uBAAuB,cAAc;AAGpE,YAAM,mBAAmB,gBAAgB,UAAU,EAAE,MAAM,CAAC,QAAQ;AAClE,gBAAQ;AAAA,UACN,yBAAyB,aAAa,cAAc,CAAC;AAAA,UACrD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,0BAA0B,kBAAkB;AACrD;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { colorizePath, getConfiguration, x } from "@intlayer/config";
|
|
2
2
|
import { mkdir } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
|
-
import { filterInvalidDictionaries } from "
|
|
5
|
-
import { orderDictionaries } from "
|
|
6
|
-
import { parallelize } from "
|
|
7
|
-
import { writeJsonIfChanged } from "
|
|
4
|
+
import { filterInvalidDictionaries } from "../filterInvalidDictionaries.mjs";
|
|
5
|
+
import { orderDictionaries } from "../orderDictionaries.mjs";
|
|
6
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
7
|
+
import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
|
|
8
8
|
const groupDictionariesByKey = (dictionaries) => dictionaries.reduce(
|
|
9
9
|
(acc, dictionary) => {
|
|
10
10
|
const key = dictionary.key;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/buildIntlayerDictionary/writeUnmergedDictionary.ts"],"sourcesContent":["import { colorizePath, getConfiguration, x } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\nimport { filterInvalidDictionaries } from '../filterInvalidDictionaries';\nimport { orderDictionaries } from '../orderDictionaries';\nimport { parallelize } from '../utils/parallelize';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\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\n const outputFileName = `${key}.json`;\n const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);\n\n // Write the grouped dictionaries\n await writeJsonIfChanged(unmergedFilePath, orderedDictionaries).catch(\n (err) => {\n console.error(\n `${x} Error creating unmerged ${colorizePath(unmergedFilePath)}:`,\n err\n );\n }\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,SAAS,cAAc,kBAAkB,SAAS;AAElD,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,iCAAiC;AAC1C,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AAEnC,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,gBAAgB,iBAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,QAAM,MAAM,QAAQ,uBAAuB,GAAG,EAAE,WAAW,KAAK,CAAC;AAEjE,QAAM,uBAAuB,0BAA0B,YAAY;AAGnE,QAAM,sBAAsB,uBAAuB,oBAAoB;AAEvE,QAAM,UAAU,MAAM;AAAA,IACpB,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAKA,aAAY,MAAM;AAC7B,UAAI,QAAQ,aAAa;AACvB,eAAO;AAAA,MAIT;AAEA,YAAM,sBAAsB;AAAA,QAC1BA;AAAA,QACA;AAAA,MACF;AAEA,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,mBAAmB,QAAQ,yBAAyB,cAAc;AAGxE,YAAM,mBAAmB,kBAAkB,mBAAmB,EAAE;AAAA,QAC9D,CAAC,QAAQ;AACP,kBAAQ;AAAA,YACN,GAAG,CAAC,4BAA4B,aAAa,gBAAgB,CAAC;AAAA,YAC9D;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,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"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getConfiguration } from "@intlayer/config";
|
|
2
2
|
import { mkdir } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { getBuiltFetchDictionariesPath } from "../../getBuiltFetchDictionariesPath.mjs";
|
|
7
|
-
import { getBuiltRemoteDictionariesPath } from "../../getBuiltRemoteDictionariesPath.mjs";
|
|
8
|
-
import { getBuiltUnmergedDictionariesPath } from "../../getBuiltUnmergedDictionariesPath.mjs";
|
|
9
|
-
import { parallelize } from "../../utils/parallelize.mjs";
|
|
10
|
-
import { writeFileIfChanged } from "../../writeFileIfChanged.mjs";
|
|
4
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
5
|
+
import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
|
|
11
6
|
import { generateDictionaryListContent } from "./generateDictionaryListContent.mjs";
|
|
7
|
+
import { getBuiltDictionariesPath } from "./getBuiltDictionariesPath.mjs";
|
|
8
|
+
import { getBuiltDynamicDictionariesPath } from "./getBuiltDynamicDictionariesPath.mjs";
|
|
9
|
+
import { getBuiltFetchDictionariesPath } from "./getBuiltFetchDictionariesPath.mjs";
|
|
10
|
+
import { getBuiltRemoteDictionariesPath } from "./getBuiltRemoteDictionariesPath.mjs";
|
|
11
|
+
import { getBuiltUnmergedDictionariesPath } from "./getBuiltUnmergedDictionariesPath.mjs";
|
|
12
12
|
const filterDictionaries = (paths, keys) => {
|
|
13
13
|
if (!keys) return paths;
|
|
14
14
|
return paths.filter(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\nimport { getBuiltDictionariesPath } from './getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from './getBuiltDynamicDictionariesPath';\nimport { getBuiltFetchDictionariesPath } from './getBuiltFetchDictionariesPath';\nimport { getBuiltRemoteDictionariesPath } from './getBuiltRemoteDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from './getBuiltUnmergedDictionariesPath';\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 functionName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(\n paths,\n functionName,\n format,\n configuration\n );\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n await writeFileIfChanged(\n resolve(mainDir, `${fileName}.${extension}`),\n content\n );\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')[]\n) => {\n const outputFormats = formats ?? configuration.build.outputFormat;\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 ...outputFormats.map((format) => ({\n paths: remoteDictionariesPath,\n functionName: 'getRemoteDictionaries',\n fileName: 'remote_dictionaries' as const,\n format,\n })),\n ...outputFormats.map((format) => ({\n paths: dictionariesPath,\n functionName: 'getDictionaries',\n fileName: 'dictionaries' as const,\n format,\n })),\n ...outputFormats.map((format) => ({\n paths: unmergedDictionariesPath,\n functionName: 'getUnmergedDictionaries',\n fileName: 'unmerged_dictionaries' as const,\n format,\n })),\n ...outputFormats.map((format) => ({\n paths: getBuiltDynamicDictionariesPath(configuration, format),\n functionName: 'getDynamicDictionaries',\n fileName: 'dynamic_dictionaries' as const,\n format,\n })),\n ...outputFormats.map((format) => ({\n paths: getBuiltFetchDictionariesPath(configuration, format),\n functionName: 'getFetchDictionaries',\n fileName: 'fetch_dictionaries' as const,\n format,\n })),\n ];\n\n await parallelize(\n writeOperations,\n async ({ paths, fileName, format, functionName }) =>\n writeDictionaryFiles(paths, fileName, functionName, format, configuration)\n );\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,qCAAqC;AAC9C,SAAS,gCAAgC;AACzC,SAAS,uCAAuC;AAChD,SAAS,qCAAqC;AAC9C,SAAS,sCAAsC;AAC/C,SAAS,wCAAwC;AAEjD,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,cACA,QACA,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,UAAU;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IAC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AAE,OAAO,UAAU,QAAQ,aAAa,MAC7C,qBAAqB,OAAO,UAAU,cAAc,QAAQ,aAAa;AAAA,EAC7E;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getConfiguration, normalizePath } from "@intlayer/config";
|
|
2
2
|
import { basename, extname, relative } from "path";
|
|
3
|
-
import { getFileHash } from "
|
|
3
|
+
import { getFileHash } from "../utils/getFileHash.mjs";
|
|
4
4
|
const generateDictionaryListContent = (dictionaries, functionName, format = "esm", configuration = getConfiguration()) => {
|
|
5
5
|
const { mainDir } = configuration.content;
|
|
6
6
|
let content = "";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/generateDictionaryListContent.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport { basename, extname, relative } from 'path';\nimport { getFileHash } from '../utils/getFileHash';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryListContent = (\n dictionaries: string[],\n functionName: string,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { mainDir } = configuration.content;\n\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: normalizePath(relative(mainDir, dictionaryPath)),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}' with { type: 'json' };\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n content += `const dictionaries = {\\n${formattedDictionaryMap}\\n};\\n`;\n content += `const ${functionName} = () => dictionaries;\\n`;\n\n if (format === 'esm') {\n content += `\\n`;\n content += `export { ${functionName} };\\n`;\n content += `export default dictionaries;\\n`;\n }\n\n if (format === 'cjs') {\n content += `\\n`;\n content += `module.exports.${functionName} = ${functionName};\\n`;\n content += `module.exports = dictionaries;\\n`;\n }\n\n return content;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,SAAS,UAAU,SAAS,gBAAgB;AAC5C,SAAS,mBAAmB;AAKrB,MAAM,gCAAgC,CAC3C,cACA,cACA,SAAwB,OACxB,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,MAAI,UAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,cAAc,SAAS,SAAS,cAAc,CAAC;AAAA,IAC7D,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,iBAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,iBAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,aAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,KAAK,KAAK;AAEb,aAAW;AAAA,EAA2B,sBAAsB;AAAA;AAAA;AAC5D,aAAW,SAAS,YAAY;AAAA;AAEhC,MAAI,WAAW,OAAO;AACpB,eAAW;AAAA;AACX,eAAW,YAAY,YAAY;AAAA;AACnC,eAAW;AAAA;AAAA,EACb;AAEA,MAAI,WAAW,OAAO;AACpB,eAAW;AAAA;AACX,eAAW,kBAAkB,YAAY,MAAM,YAAY;AAAA;AAC3D,eAAW;AAAA;AAAA,EACb;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/getBuiltDictionariesPath.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltDictionariesPath = (\n configuration = getConfiguration()\n) => {\n const { dictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(\n `${normalizePath(dictionariesDir)}/**/*.json`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,2BAA2B,CACtC,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,iBAAiB,QAAQ,IAAI,cAAc;AAGnD,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,cAAc,eAAe,CAAC;AAAA,EACnC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltDynamicDictionariesPath = (\n configuration = getConfiguration(),\n format: 'cjs' | 'esm' = 'esm'\n) => {\n const { dynamicDictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const dictionariesPath: string[] = fg.sync(\n `${normalizePath(dynamicDictionariesDir)}/**/*.${extension}`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,kCAAkC,CAC7C,gBAAgB,iBAAiB,GACjC,SAAwB,UACrB;AACH,QAAM,EAAE,wBAAwB,QAAQ,IAAI,cAAc;AAG1D,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,cAAc,sBAAsB,CAAC,SAAS,SAAS;AAAA,EAC5D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltFetchDictionariesPath = (\n configuration = getConfiguration(),\n format: 'cjs' | 'esm' = 'esm'\n) => {\n const { fetchDictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const dictionariesPath: string[] = fg.sync(\n `${normalizePath(fetchDictionariesDir)}/**/*.${extension}`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,gCAAgC,CAC3C,gBAAgB,iBAAiB,GACjC,SAAwB,UACrB;AACH,QAAM,EAAE,sBAAsB,QAAQ,IAAI,cAAc;AAGxD,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,cAAc,oBAAoB,CAAC,SAAS,SAAS;AAAA,EAC1D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltRemoteDictionariesPath = (\n configuration = getConfiguration()\n) => {\n const { remoteDictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(\n `${normalizePath(remoteDictionariesDir)}/**/*.json`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,iCAAiC,CAC5C,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,QAAQ,IAAI,cAAc;AAGzD,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,cAAc,qBAAqB,CAAC;AAAA,EACzC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltUnmergedDictionariesPath = (\n configuration = getConfiguration()\n) => {\n const { unmergedDictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(\n `${normalizePath(unmergedDictionariesDir)}/**/*.json`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,mCAAmC,CAC9C,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,yBAAyB,QAAQ,IAAI,cAAc;AAG3D,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,cAAc,uBAAuB,CAAC;AAAA,EAC3C;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./createDictionaryEntryPoint.mjs";
|
|
2
|
+
export * from "./generateDictionaryListContent.mjs";
|
|
3
|
+
export * from "./getBuiltDictionariesPath.mjs";
|
|
4
|
+
export * from "./getBuiltDynamicDictionariesPath.mjs";
|
|
5
|
+
export * from "./getBuiltFetchDictionariesPath.mjs";
|
|
6
|
+
export * from "./getBuiltRemoteDictionariesPath.mjs";
|
|
7
|
+
export * from "./getBuiltUnmergedDictionariesPath.mjs";
|
|
8
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createDictionaryEntryPoint/index.ts"],"sourcesContent":["export * from './createDictionaryEntryPoint';\nexport * from './generateDictionaryListContent';\nexport * from './getBuiltDictionariesPath';\nexport * from './getBuiltDynamicDictionariesPath';\nexport * from './getBuiltFetchDictionariesPath';\nexport * from './getBuiltRemoteDictionariesPath';\nexport * from './getBuiltUnmergedDictionariesPath';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -2,9 +2,9 @@ import { Locales, getConfiguration, normalizePath } from "@intlayer/config";
|
|
|
2
2
|
import fg from "fast-glob";
|
|
3
3
|
import { mkdir } from "fs/promises";
|
|
4
4
|
import { basename, extname, join, relative } from "path";
|
|
5
|
-
import { getFileHash } from "
|
|
6
|
-
import { kebabCaseToCamelCase } from "
|
|
7
|
-
import { writeFileIfChanged } from "
|
|
5
|
+
import { getFileHash } from "../utils/getFileHash.mjs";
|
|
6
|
+
import { kebabCaseToCamelCase } from "../utils/kebabCaseToCamelCase.mjs";
|
|
7
|
+
import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
|
|
8
8
|
const getTypeName = (key) => `${kebabCaseToCamelCase(key)}Content`;
|
|
9
9
|
const formatLocales = (locales) => locales.map((locale) => {
|
|
10
10
|
for (const key in Locales) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createType/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { mkdir } from 'fs/promises';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../utils/kebabCaseToCamelCase';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\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\n // Create the dictionary list file\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n\n const tsFilePath = join(moduleAugmentationDir, 'intlayer.d.ts');\n\n await writeFileIfChanged(tsFilePath, tsContent);\n};\n"],"mappings":"AAAA,SAAS,SAAS,kBAAkB,qBAAqB;AACzD,OAAO,QAAQ;AACf,SAAS,aAAa;AACtB,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AAE5B,MAAM,cAAc,CAAC,QAC1B,GAAG,qBAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,SAAS;AACzB,QAAI,QAAQ,GAA2B,MAAM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AAe;AAEf,SAAO;AACT;AAKO,MAAM,2BAA2B,OACtC,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,QAAM,MAAM,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAEtD,QAAM,+BAAyC,GAAG;AAAA,IAChD,cAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AAEvE,QAAM,aAAa,KAAK,uBAAuB,eAAe;AAE9D,QAAM,mBAAmB,YAAY,SAAS;AAChD;","names":["locale"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "@intlayer/config";
|
|
5
5
|
import { mkdir, writeFile } from "fs/promises";
|
|
6
6
|
import { resolve } from "path";
|
|
7
|
-
import { parallelize } from "
|
|
7
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
8
8
|
const requireUncached = (module) => {
|
|
9
9
|
delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];
|
|
10
10
|
return ESMxCJSRequire(module);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createType/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,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAE5B,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;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,gBAAgC,iBAAiB,MAC3B;AACtB,QAAM,EAAE,SAAS,IAAI,cAAc;AAGnC,QAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AAEzC,QAAM,UAAU,MAAM;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,aAAqB,QAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,YAAM,UAAU,YAAY,cAAc;AAE1C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,OAAO;AAC/B;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/createType/index.ts"],"sourcesContent":["export * from './createModuleAugmentation';\nexport * from './createType';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import configuration from "@intlayer/config/built";
|
|
2
1
|
import {
|
|
3
2
|
colorizeKey,
|
|
4
3
|
colorizePath,
|
|
5
4
|
getAppLogger
|
|
6
5
|
} from "@intlayer/config/client";
|
|
7
6
|
import { formatPath } from "./utils/formatter.mjs";
|
|
8
|
-
const
|
|
7
|
+
const isInvalidDictionary = (dictionary, configuration) => {
|
|
9
8
|
const appLogger = getAppLogger(configuration);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
if (!dictionary) return false;
|
|
10
|
+
const isLocal = Boolean(dictionary.location === "locale");
|
|
11
|
+
const location = isLocal ? "Local" : "Remote";
|
|
12
|
+
const hasKey = Boolean(dictionary.key);
|
|
13
|
+
const hasContent = Boolean(dictionary.content);
|
|
14
|
+
if (!hasKey) {
|
|
15
|
+
appLogger(`${location} dictionary has no key`, {
|
|
16
|
+
level: "error"
|
|
17
|
+
});
|
|
18
|
+
appLogger(JSON.stringify(dictionary, null, 2), {
|
|
19
|
+
level: "error"
|
|
20
|
+
});
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (!hasContent) {
|
|
24
|
+
appLogger(
|
|
25
|
+
`${location} dictionary ${colorizeKey(dictionary.key)} has no content - ${dictionary.filePath ? formatPath(dictionary.filePath) : colorizePath("Remote")}`,
|
|
26
|
+
{
|
|
18
27
|
level: "error"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
if (!hasContent) {
|
|
26
|
-
appLogger(
|
|
27
|
-
`${location} dictionary ${colorizeKey(dictionary.key)} has no content - ${dictionary.filePath ? formatPath(dictionary.filePath) : colorizePath("Remote")}`,
|
|
28
|
-
{
|
|
29
|
-
level: "error"
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
});
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
36
33
|
};
|
|
34
|
+
const filterInvalidDictionaries = (dictionaries, configuration) => (dictionaries ?? [])?.filter(
|
|
35
|
+
(dictionary) => isInvalidDictionary(dictionary, configuration)
|
|
36
|
+
);
|
|
37
37
|
export {
|
|
38
|
-
filterInvalidDictionaries
|
|
38
|
+
filterInvalidDictionaries,
|
|
39
|
+
isInvalidDictionary
|
|
39
40
|
};
|
|
40
41
|
//# sourceMappingURL=filterInvalidDictionaries.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/filterInvalidDictionaries.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/filterInvalidDictionaries.ts"],"sourcesContent":["import { type IntlayerConfig } from '@intlayer/config';\nimport {\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { formatPath } from './utils/formatter';\n\nexport const isInvalidDictionary = (\n dictionary: Dictionary | undefined,\n configuration?: IntlayerConfig\n): boolean => {\n const appLogger = getAppLogger(configuration);\n\n if (!dictionary) return false;\n\n const isLocal = Boolean(dictionary.location === 'locale');\n const location = isLocal ? 'Local' : 'Remote';\n const hasKey = Boolean(dictionary.key);\n const hasContent = Boolean(dictionary.content);\n\n if (!hasKey) {\n appLogger(`${location} dictionary has no key`, {\n level: 'error',\n });\n appLogger(JSON.stringify(dictionary, null, 2), {\n level: 'error',\n });\n return false;\n }\n\n if (!hasContent) {\n appLogger(\n `${location} dictionary ${colorizeKey(dictionary.key)} has no content - ${dictionary.filePath ? formatPath(dictionary.filePath) : colorizePath('Remote')}`,\n {\n level: 'error',\n }\n );\n return false;\n }\n\n return true;\n};\n\nexport const filterInvalidDictionaries = (\n dictionaries: (Dictionary | undefined)[] | undefined,\n configuration?: IntlayerConfig\n): Dictionary[] =>\n (dictionaries ?? [])?.filter((dictionary) =>\n isInvalidDictionary(dictionary, configuration)\n ) as Dictionary[];\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,kBAAkB;AAEpB,MAAM,sBAAsB,CACjC,YACA,kBACY;AACZ,QAAM,YAAY,aAAa,aAAa;AAE5C,MAAI,CAAC,WAAY,QAAO;AAExB,QAAM,UAAU,QAAQ,WAAW,aAAa,QAAQ;AACxD,QAAM,WAAW,UAAU,UAAU;AACrC,QAAM,SAAS,QAAQ,WAAW,GAAG;AACrC,QAAM,aAAa,QAAQ,WAAW,OAAO;AAE7C,MAAI,CAAC,QAAQ;AACX,cAAU,GAAG,QAAQ,0BAA0B;AAAA,MAC7C,OAAO;AAAA,IACT,CAAC;AACD,cAAU,KAAK,UAAU,YAAY,MAAM,CAAC,GAAG;AAAA,MAC7C,OAAO;AAAA,IACT,CAAC;AACD,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,YAAY;AACf;AAAA,MACE,GAAG,QAAQ,eAAe,YAAY,WAAW,GAAG,CAAC,qBAAqB,WAAW,WAAW,WAAW,WAAW,QAAQ,IAAI,aAAa,QAAQ,CAAC;AAAA,MACxJ;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,4BAA4B,CACvC,cACA,mBAEC,gBAAgB,CAAC,IAAI;AAAA,EAAO,CAAC,eAC5B,oBAAoB,YAAY,aAAa;AAC/C;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getAppLogger } from "@intlayer/config";
|
|
2
|
+
import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
|
|
3
|
+
import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
|
|
4
|
+
import { createModuleAugmentation, createTypes } from "./createType/index.mjs";
|
|
5
|
+
import { loadLocalDictionaries } from "./loadDictionaries/loadLocalDictionaries.mjs";
|
|
6
|
+
import { formatPath } from "./utils/formatter.mjs";
|
|
7
|
+
const handleAdditionalContentDeclarationFile = async (filePath, config) => {
|
|
8
|
+
const appLogger = getAppLogger(config);
|
|
9
|
+
appLogger(`Additional file detected: ${formatPath(filePath)}`, {
|
|
10
|
+
isVerbose: true
|
|
11
|
+
});
|
|
12
|
+
const localeDictionaries = await loadLocalDictionaries(filePath, config);
|
|
13
|
+
const dictionariesOutput = await buildDictionary(localeDictionaries, config);
|
|
14
|
+
const dictionariesPaths = Object.values(
|
|
15
|
+
dictionariesOutput?.mergedDictionaries ?? {}
|
|
16
|
+
).map((dictionary) => dictionary.dictionaryPath);
|
|
17
|
+
await createTypes(dictionariesPaths);
|
|
18
|
+
await createDictionaryEntryPoint(config);
|
|
19
|
+
appLogger("Dictionaries built", {
|
|
20
|
+
isVerbose: true
|
|
21
|
+
});
|
|
22
|
+
createModuleAugmentation(config);
|
|
23
|
+
appLogger("Module augmentation built", {
|
|
24
|
+
isVerbose: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
handleAdditionalContentDeclarationFile
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=handleAdditionalContentDeclarationFile.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handleAdditionalContentDeclarationFile.ts"],"sourcesContent":["import { type IntlayerConfig, getAppLogger } from '@intlayer/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { createModuleAugmentation, createTypes } from './createType/index';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Additional file detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths);\n\n await createDictionaryEntryPoint(config);\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n"],"mappings":"AAAA,SAA8B,oBAAoB;AAClD,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,0BAA0B,mBAAmB;AACtD,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;AAEpB,MAAM,yCAAyC,OACpD,UACA,WACG;AACH,QAAM,YAAY,aAAa,MAAM;AAGrC,YAAU,6BAA6B,WAAW,QAAQ,CAAC,IAAI;AAAA,IAC7D,WAAW;AAAA,EACb,CAAC;AAED,QAAM,qBAAqB,MAAM,sBAAsB,UAAU,MAAM;AAEvE,QAAM,qBAAqB,MAAM,gBAAgB,oBAAoB,MAAM;AAE3E,QAAM,oBAAoB,OAAO;AAAA,IAC/B,oBAAoB,sBAAsB,CAAC;AAAA,EAC7C,EAAE,IAAI,CAAC,eAAe,WAAW,cAAc;AAE/C,QAAM,YAAY,iBAAiB;AAEnC,QAAM,2BAA2B,MAAM;AAEvC,YAAU,sBAAsB;AAAA,IAC9B,WAAW;AAAA,EACb,CAAC;AAED,2BAAyB,MAAM;AAE/B,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|