@intlayer/chokidar 6.1.6 → 7.0.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cjs → assets}/getContentDeclarationFileTemplate/cjsTemplate.txt +3 -2
- package/dist/{cjs → assets}/getContentDeclarationFileTemplate/esmTemplate.txt +2 -1
- package/dist/{cjs → assets}/getContentDeclarationFileTemplate/jsonTemplate.txt +2 -1
- package/dist/{cjs → assets}/getContentDeclarationFileTemplate/tsTemplate.txt +2 -1
- package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +42 -80
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/index.cjs +5 -25
- package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs +21 -42
- package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +79 -116
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +62 -86
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +48 -69
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +42 -52
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +60 -82
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/cleanOutputDir.cjs +20 -60
- package/dist/cjs/cleanOutputDir.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +64 -103
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs +41 -73
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs +19 -49
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs +20 -50
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs +20 -50
- package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs +19 -49
- package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs +19 -49
- package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/index.cjs +15 -35
- package/dist/cjs/createType/createModuleAugmentation.cjs +56 -108
- package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/createType/createType.cjs +29 -58
- package/dist/cjs/createType/createType.cjs.map +1 -1
- package/dist/cjs/createType/index.cjs +7 -25
- package/dist/cjs/fetchDistantDictionaries.cjs +49 -77
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/filterInvalidDictionaries.cjs +26 -59
- package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -1
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +32 -68
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -1
- package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +32 -51
- package/dist/cjs/handleAdditionalContentDeclarationFile.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileChange.cjs +35 -56
- package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
- package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +36 -0
- package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs.map +1 -0
- package/dist/cjs/index.cjs +103 -156
- package/dist/cjs/listDictionariesPath.cjs +27 -59
- package/dist/cjs/listDictionariesPath.cjs.map +1 -1
- package/dist/cjs/listGitFiles.cjs +93 -162
- package/dist/cjs/listGitFiles.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +70 -0
- package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/index.cjs +11 -29
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +68 -90
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +111 -166
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +27 -53
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +60 -102
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/log.cjs +107 -182
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +73 -130
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs +27 -61
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -1
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +10 -32
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -1
- package/dist/cjs/utils/chunkJSON.cjs +329 -0
- package/dist/cjs/utils/chunkJSON.cjs.map +1 -0
- package/dist/cjs/utils/extractErrorMessage.cjs +92 -135
- package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -1
- package/dist/cjs/utils/formatter.cjs +19 -49
- package/dist/cjs/utils/formatter.cjs.map +1 -1
- package/dist/cjs/utils/getChunk.cjs +34 -0
- package/dist/cjs/utils/getChunk.cjs.map +1 -0
- package/dist/cjs/utils/getFileHash.cjs +9 -40
- package/dist/cjs/utils/getFileHash.cjs.map +1 -1
- package/dist/cjs/utils/getFormatFromExtension.cjs +23 -54
- package/dist/cjs/utils/getFormatFromExtension.cjs.map +1 -1
- package/dist/cjs/utils/kebabCaseToCamelCase.cjs +11 -36
- package/dist/cjs/utils/kebabCaseToCamelCase.cjs.map +1 -1
- package/dist/cjs/utils/pLimit.cjs +128 -0
- package/dist/cjs/utils/pLimit.cjs.map +1 -0
- package/dist/cjs/utils/parallelize.cjs +10 -169
- package/dist/cjs/utils/parallelize.cjs.map +1 -1
- package/dist/cjs/utils/parallelizeGlobal.cjs +29 -0
- package/dist/cjs/utils/parallelizeGlobal.cjs.map +1 -0
- package/dist/cjs/utils/reduceObjectFormat.cjs +31 -0
- package/dist/cjs/utils/reduceObjectFormat.cjs.map +1 -0
- package/dist/cjs/utils/resolveObjectPromises.cjs +18 -48
- package/dist/cjs/utils/resolveObjectPromises.cjs.map +1 -1
- package/dist/cjs/utils/runOnce.cjs +80 -57
- package/dist/cjs/utils/runOnce.cjs.map +1 -1
- package/dist/cjs/utils/runParallel.cjs +163 -74
- package/dist/cjs/utils/runParallel.cjs.map +1 -1
- package/dist/cjs/utils/sortAlphabetically.cjs +5 -27
- package/dist/cjs/utils/sortAlphabetically.cjs.map +1 -1
- package/dist/cjs/utils/splitTextByLine.cjs +11 -0
- package/dist/cjs/utils/splitTextByLine.cjs.map +1 -0
- package/dist/cjs/utils/verifyIdenticObjectFormat copy.cjs +54 -0
- package/dist/cjs/utils/verifyIdenticObjectFormat copy.cjs.map +1 -0
- package/dist/cjs/utils/verifyIdenticObjectFormat.cjs +60 -0
- package/dist/cjs/utils/verifyIdenticObjectFormat.cjs.map +1 -0
- package/dist/cjs/watcher.cjs +61 -83
- package/dist/cjs/watcher.cjs.map +1 -1
- package/dist/cjs/writeConfiguration/index.cjs +15 -35
- package/dist/cjs/writeConfiguration/index.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs +25 -51
- package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/dictionaryStatus.cjs +0 -17
- package/dist/cjs/writeContentDeclaration/index.cjs +9 -33
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +77 -0
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +1731 -755
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +113 -112
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +56 -66
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/cjs/writeFileIfChanged.cjs +10 -43
- package/dist/cjs/writeFileIfChanged.cjs.map +1 -1
- package/dist/cjs/writeJsonIfChanged.cjs +14 -31
- package/dist/cjs/writeJsonIfChanged.cjs.map +1 -1
- package/dist/esm/_virtual/_utils_asset.mjs +100 -0
- package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +35 -54
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/index.mjs +4 -3
- package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs +18 -17
- package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +69 -91
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +53 -61
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +40 -42
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +35 -25
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +53 -56
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs +17 -36
- package/dist/esm/cleanOutputDir.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +51 -70
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs +36 -47
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs +14 -14
- package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs +15 -15
- package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs +15 -15
- package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs +14 -14
- package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs +14 -14
- package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/index.mjs +9 -8
- package/dist/esm/createType/createModuleAugmentation.mjs +48 -71
- package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/createType/createType.mjs +24 -35
- package/dist/esm/createType/createType.mjs.map +1 -1
- package/dist/esm/createType/index.mjs +4 -3
- package/dist/esm/fetchDistantDictionaries.mjs +45 -52
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/filterInvalidDictionaries.mjs +22 -37
- package/dist/esm/filterInvalidDictionaries.mjs.map +1 -1
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +31 -42
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -1
- package/dist/esm/handleAdditionalContentDeclarationFile.mjs +27 -24
- package/dist/esm/handleAdditionalContentDeclarationFile.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileChange.mjs +30 -29
- package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
- package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +34 -0
- package/dist/esm/handleUnlinkedContentDeclarationFile.mjs.map +1 -0
- package/dist/esm/index.mjs +39 -99
- package/dist/esm/listDictionariesPath.mjs +24 -24
- package/dist/esm/listDictionariesPath.mjs.map +1 -1
- package/dist/esm/listGitFiles.mjs +83 -124
- package/dist/esm/listGitFiles.mjs.map +1 -1
- package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +66 -0
- package/dist/esm/loadDictionaries/getIntlayerBundle.mjs.map +1 -0
- package/dist/esm/loadDictionaries/index.mjs +6 -5
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -70
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +105 -146
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +23 -31
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +52 -74
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/log.mjs +105 -165
- package/dist/esm/loadDictionaries/log.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +64 -97
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/reduceDictionaryContent/applyMask.mjs +26 -37
- package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -1
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +7 -7
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -1
- package/dist/esm/utils/chunkJSON.mjs +327 -0
- package/dist/esm/utils/chunkJSON.mjs.map +1 -0
- package/dist/esm/utils/extractErrorMessage.mjs +91 -111
- package/dist/esm/utils/extractErrorMessage.mjs.map +1 -1
- package/dist/esm/utils/formatter.mjs +10 -12
- package/dist/esm/utils/formatter.mjs.map +1 -1
- package/dist/esm/utils/getChunk.mjs +34 -0
- package/dist/esm/utils/getChunk.mjs.map +1 -0
- package/dist/esm/utils/getFileHash.mjs +6 -5
- package/dist/esm/utils/getFileHash.mjs.map +1 -1
- package/dist/esm/utils/getFormatFromExtension.mjs +21 -29
- package/dist/esm/utils/getFormatFromExtension.mjs.map +1 -1
- package/dist/esm/utils/kebabCaseToCamelCase.mjs +10 -12
- package/dist/esm/utils/kebabCaseToCamelCase.mjs.map +1 -1
- package/dist/esm/utils/pLimit.mjs +126 -0
- package/dist/esm/utils/pLimit.mjs.map +1 -0
- package/dist/esm/utils/parallelize.mjs +10 -144
- package/dist/esm/utils/parallelize.mjs.map +1 -1
- package/dist/esm/utils/parallelizeGlobal.mjs +27 -0
- package/dist/esm/utils/parallelizeGlobal.mjs.map +1 -0
- package/dist/esm/utils/reduceObjectFormat.mjs +30 -0
- package/dist/esm/utils/reduceObjectFormat.mjs.map +1 -0
- package/dist/esm/utils/resolveObjectPromises.mjs +17 -24
- package/dist/esm/utils/resolveObjectPromises.mjs.map +1 -1
- package/dist/esm/utils/runOnce.mjs +76 -33
- package/dist/esm/utils/runOnce.mjs.map +1 -1
- package/dist/esm/utils/runParallel.mjs +160 -40
- package/dist/esm/utils/runParallel.mjs.map +1 -1
- package/dist/esm/utils/sortAlphabetically.mjs +4 -3
- package/dist/esm/utils/sortAlphabetically.mjs.map +1 -1
- package/dist/esm/utils/splitTextByLine.mjs +10 -0
- package/dist/esm/utils/splitTextByLine.mjs.map +1 -0
- package/dist/esm/utils/verifyIdenticObjectFormat copy.mjs +53 -0
- package/dist/esm/utils/verifyIdenticObjectFormat copy.mjs.map +1 -0
- package/dist/esm/utils/verifyIdenticObjectFormat.mjs +59 -0
- package/dist/esm/utils/verifyIdenticObjectFormat.mjs.map +1 -0
- package/dist/esm/watcher.mjs +53 -58
- package/dist/esm/watcher.mjs.map +1 -1
- package/dist/esm/writeConfiguration/index.mjs +11 -10
- package/dist/esm/writeConfiguration/index.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs +24 -27
- package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/dictionaryStatus.mjs +0 -1
- package/dist/esm/writeContentDeclaration/index.mjs +6 -7
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +71 -0
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs +1726 -735
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +105 -76
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +48 -46
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
- package/dist/esm/writeFileIfChanged.mjs +7 -18
- package/dist/esm/writeFileIfChanged.mjs.map +1 -1
- package/dist/esm/writeJsonIfChanged.mjs +14 -7
- package/dist/esm/writeJsonIfChanged.mjs.map +1 -1
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +14 -7
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/index.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts +7 -2
- package/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +14 -10
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +8 -3
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +12 -7
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +8 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts +10 -6
- package/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts.map +1 -1
- package/dist/types/cleanOutputDir.d.ts +6 -1
- package/dist/types/cleanOutputDir.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +6 -1
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +6 -1
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts +7 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts +7 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts +7 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts +7 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts +7 -1
- package/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/index.d.ts +8 -8
- package/dist/types/createType/createModuleAugmentation.d.ts +8 -5
- package/dist/types/createType/createModuleAugmentation.d.ts.map +1 -1
- package/dist/types/createType/createType.d.ts +7 -4
- package/dist/types/createType/createType.d.ts.map +1 -1
- package/dist/types/createType/index.d.ts +3 -3
- package/dist/types/fetchDistantDictionaries.d.ts +10 -7
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/filterInvalidDictionaries.d.ts +7 -4
- package/dist/types/filterInvalidDictionaries.d.ts.map +1 -1
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts +6 -2
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts.map +1 -1
- package/dist/types/handleAdditionalContentDeclarationFile.d.ts +6 -2
- package/dist/types/handleAdditionalContentDeclarationFile.d.ts.map +1 -1
- package/dist/types/handleContentDeclarationFileChange.d.ts +6 -2
- package/dist/types/handleContentDeclarationFileChange.d.ts.map +1 -1
- package/dist/types/handleUnlinkedContentDeclarationFile.d.ts +7 -0
- package/dist/types/handleUnlinkedContentDeclarationFile.d.ts.map +1 -0
- package/dist/types/index.d.ts +49 -33
- package/dist/types/listDictionariesPath.d.ts +7 -2
- package/dist/types/listDictionariesPath.d.ts.map +1 -1
- package/dist/types/listGitFiles.d.ts +24 -12
- package/dist/types/listGitFiles.d.ts.map +1 -1
- package/dist/types/loadDictionaries/getIntlayerBundle.d.ts +11 -0
- package/dist/types/loadDictionaries/getIntlayerBundle.d.ts.map +1 -0
- package/dist/types/loadDictionaries/index.d.ts +5 -5
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +8 -5
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +18 -14
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +6 -3
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +13 -8
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/log.d.ts +28 -24
- package/dist/types/loadDictionaries/log.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts +12 -2
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/reduceDictionaryContent/applyMask.d.ts +6 -2
- package/dist/types/reduceDictionaryContent/applyMask.d.ts.map +1 -1
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts +6 -2
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts.map +1 -1
- package/dist/types/utils/chunkJSON.d.ts +56 -0
- package/dist/types/utils/chunkJSON.d.ts.map +1 -0
- package/dist/types/utils/extractErrorMessage.d.ts +4 -1
- package/dist/types/utils/extractErrorMessage.d.ts.map +1 -1
- package/dist/types/utils/formatter.d.ts +8 -3
- package/dist/types/utils/formatter.d.ts.map +1 -1
- package/dist/types/utils/getChunk.d.ts +11 -0
- package/dist/types/utils/getChunk.d.ts.map +1 -0
- package/dist/types/utils/getFileHash.d.ts +4 -1
- package/dist/types/utils/getFileHash.d.ts.map +1 -1
- package/dist/types/utils/getFormatFromExtension.d.ts +7 -4
- package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
- package/dist/types/utils/kebabCaseToCamelCase.d.ts +4 -1
- package/dist/types/utils/kebabCaseToCamelCase.d.ts.map +1 -1
- package/dist/types/utils/pLimit.d.ts +16 -0
- package/dist/types/utils/pLimit.d.ts.map +1 -0
- package/dist/types/utils/parallelize.d.ts +4 -13
- package/dist/types/utils/parallelize.d.ts.map +1 -1
- package/dist/types/utils/parallelizeGlobal.d.ts +22 -0
- package/dist/types/utils/parallelizeGlobal.d.ts.map +1 -0
- package/dist/types/utils/reduceObjectFormat.d.ts +17 -0
- package/dist/types/utils/reduceObjectFormat.d.ts.map +1 -0
- package/dist/types/utils/resolveObjectPromises.d.ts +4 -1
- package/dist/types/utils/resolveObjectPromises.d.ts.map +1 -1
- package/dist/types/utils/runOnce.d.ts +23 -2
- package/dist/types/utils/runOnce.d.ts.map +1 -1
- package/dist/types/utils/runParallel.d.ts +9 -6
- package/dist/types/utils/runParallel.d.ts.map +1 -1
- package/dist/types/utils/sortAlphabetically.d.ts +4 -1
- package/dist/types/utils/sortAlphabetically.d.ts.map +1 -1
- package/dist/types/utils/splitTextByLine.d.ts +5 -0
- package/dist/types/utils/splitTextByLine.d.ts.map +1 -0
- package/dist/types/utils/verifyIdenticObjectFormat copy.d.ts +23 -0
- package/dist/types/utils/verifyIdenticObjectFormat copy.d.ts.map +1 -0
- package/dist/types/utils/verifyIdenticObjectFormat.d.ts +23 -0
- package/dist/types/utils/verifyIdenticObjectFormat.d.ts.map +1 -0
- package/dist/types/watcher.d.ts +13 -9
- package/dist/types/watcher.d.ts.map +1 -1
- package/dist/types/writeConfiguration/index.d.ts +6 -2
- package/dist/types/writeConfiguration/index.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/detectExportedComponentName.d.ts +4 -1
- package/dist/types/writeContentDeclaration/detectExportedComponentName.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts +4 -1
- package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/index.d.ts +6 -7
- package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts +7 -0
- package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/transformJSFile.d.ts +33 -6
- package/dist/types/writeContentDeclaration/transformJSFile.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +14 -6
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +7 -3
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
- package/dist/types/writeFileIfChanged.d.ts +7 -2
- package/dist/types/writeFileIfChanged.d.ts.map +1 -1
- package/dist/types/writeJsonIfChanged.d.ts +7 -2
- package/dist/types/writeJsonIfChanged.d.ts.map +1 -1
- package/package.json +48 -54
- package/LICENSE +0 -202
- package/dist/cjs/buildIntlayerDictionary/index.cjs.map +0 -1
- package/dist/cjs/createDictionaryEntryPoint/index.cjs.map +0 -1
- package/dist/cjs/createType/index.cjs.map +0 -1
- package/dist/cjs/handleUnlikedContentDeclarationFile.cjs +0 -57
- package/dist/cjs/handleUnlikedContentDeclarationFile.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/loadDictionaries/index.cjs.map +0 -1
- package/dist/cjs/mergeDictionaries.cjs +0 -143
- package/dist/cjs/mergeDictionaries.cjs.map +0 -1
- package/dist/cjs/orderDictionaries.cjs +0 -71
- package/dist/cjs/orderDictionaries.cjs.map +0 -1
- package/dist/cjs/prepareContentDeclaration.cjs +0 -93
- package/dist/cjs/prepareContentDeclaration.cjs.map +0 -1
- package/dist/cjs/processPerLocaleDictionary.cjs +0 -49
- package/dist/cjs/processPerLocaleDictionary.cjs.map +0 -1
- package/dist/cjs/utils/getExtention.cjs +0 -37
- package/dist/cjs/utils/getExtention.cjs.map +0 -1
- package/dist/cjs/writeContentDeclaration/dictionaryStatus.cjs.map +0 -1
- package/dist/cjs/writeContentDeclaration/formatCode.cjs +0 -78
- package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +0 -1
- package/dist/cjs/writeContentDeclaration/index.cjs.map +0 -1
- package/dist/esm/buildIntlayerDictionary/index.mjs.map +0 -1
- package/dist/esm/createDictionaryEntryPoint/index.mjs.map +0 -1
- package/dist/esm/createType/index.mjs.map +0 -1
- package/dist/esm/getContentDeclarationFileTemplate/cjsTemplate.txt +0 -9
- package/dist/esm/getContentDeclarationFileTemplate/esmTemplate.txt +0 -9
- package/dist/esm/getContentDeclarationFileTemplate/jsonTemplate.txt +0 -5
- package/dist/esm/getContentDeclarationFileTemplate/tsTemplate.txt +0 -8
- package/dist/esm/handleUnlikedContentDeclarationFile.mjs +0 -33
- package/dist/esm/handleUnlikedContentDeclarationFile.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/loadDictionaries/index.mjs.map +0 -1
- package/dist/esm/mergeDictionaries.mjs +0 -109
- package/dist/esm/mergeDictionaries.mjs.map +0 -1
- package/dist/esm/orderDictionaries.mjs +0 -37
- package/dist/esm/orderDictionaries.mjs.map +0 -1
- package/dist/esm/prepareContentDeclaration.mjs +0 -72
- package/dist/esm/prepareContentDeclaration.mjs.map +0 -1
- package/dist/esm/processPerLocaleDictionary.mjs +0 -25
- package/dist/esm/processPerLocaleDictionary.mjs.map +0 -1
- package/dist/esm/utils/getExtention.mjs +0 -13
- package/dist/esm/utils/getExtention.mjs.map +0 -1
- package/dist/esm/writeContentDeclaration/dictionaryStatus.mjs.map +0 -1
- package/dist/esm/writeContentDeclaration/formatCode.mjs +0 -44
- package/dist/esm/writeContentDeclaration/formatCode.mjs.map +0 -1
- package/dist/esm/writeContentDeclaration/index.mjs.map +0 -1
- package/dist/types/buildIntlayerDictionary/index.d.ts.map +0 -1
- package/dist/types/createDictionaryEntryPoint/index.d.ts.map +0 -1
- package/dist/types/createType/index.d.ts.map +0 -1
- package/dist/types/handleUnlikedContentDeclarationFile.d.ts +0 -3
- package/dist/types/handleUnlikedContentDeclarationFile.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/loadDictionaries/index.d.ts.map +0 -1
- package/dist/types/mergeDictionaries.d.ts +0 -3
- package/dist/types/mergeDictionaries.d.ts.map +0 -1
- package/dist/types/orderDictionaries.d.ts +0 -10
- package/dist/types/orderDictionaries.d.ts.map +0 -1
- package/dist/types/prepareContentDeclaration.d.ts +0 -3
- package/dist/types/prepareContentDeclaration.d.ts.map +0 -1
- package/dist/types/processPerLocaleDictionary.d.ts +0 -32
- package/dist/types/processPerLocaleDictionary.d.ts.map +0 -1
- package/dist/types/utils/getExtention.d.ts +0 -3
- package/dist/types/utils/getExtention.d.ts.map +0 -1
- package/dist/types/writeContentDeclaration/formatCode.d.ts +0 -2
- package/dist/types/writeContentDeclaration/formatCode.d.ts.map +0 -1
- package/dist/types/writeContentDeclaration/index.d.ts.map +0 -1
|
@@ -1,751 +1,1742 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
1
|
+
import { getNodeType } from "@intlayer/core";
|
|
2
|
+
import { NodeType } from "@intlayer/types";
|
|
3
|
+
import { IndentationText, NewLineKind, Node, Project, QuoteKind, SyntaxKind, ts } from "ts-morph";
|
|
4
|
+
|
|
5
|
+
//#region src/writeContentDeclaration/transformJSFile.ts
|
|
6
|
+
/**
|
|
7
|
+
* Builds a translation initializer string for the 't' function call.
|
|
8
|
+
* Creates a properly formatted translation object with locale keys and values.
|
|
9
|
+
*
|
|
10
|
+
* @param translationMap - Map of locale codes to translation values
|
|
11
|
+
* @param typeArgumentsText - Optional generic type arguments for the translation function
|
|
12
|
+
* @returns Formatted string for the translation function call
|
|
13
|
+
*/
|
|
14
|
+
const buildTranslationInitializer = (translationMap, typeArgumentsText) => {
|
|
15
|
+
const translationEntries = Object.entries(translationMap).sort(([firstKey], [secondKey]) => firstKey.localeCompare(secondKey));
|
|
16
|
+
const translationParts = [];
|
|
17
|
+
for (const [localeCode, translationValue] of translationEntries) {
|
|
18
|
+
const formattedLocaleKey = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(localeCode) ? localeCode : JSON.stringify(localeCode);
|
|
19
|
+
if (typeof translationValue === "string") translationParts.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
|
|
20
|
+
else if (Array.isArray(translationValue)) {
|
|
21
|
+
const serializedArrayElements = translationValue.map((arrayElement) => JSON.stringify(arrayElement)).join(", ");
|
|
22
|
+
translationParts.push(`${formattedLocaleKey}: [ ${serializedArrayElements} ]`);
|
|
23
|
+
} else translationParts.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
|
|
24
|
+
}
|
|
25
|
+
return `t${typeArgumentsText ?? ""}({ ${translationParts.join(", ")} })`;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Synchronizes numeric suffixes across locales to maintain consistency.
|
|
29
|
+
* When updating a fallback locale's numeric suffix, this function updates
|
|
30
|
+
* the corresponding numeric suffixes in other locales to match.
|
|
31
|
+
*
|
|
32
|
+
* This is useful for maintaining numbered lists across translations,
|
|
33
|
+
* e.g., "Hello 1" / "Bonjour 1" when updating to "Hello 3".
|
|
34
|
+
*
|
|
35
|
+
* @param existingTranslationMap - Current translation map with locale values
|
|
36
|
+
* @param fallbackLocaleCode - The locale being updated (fallback)
|
|
37
|
+
* @param newFallbackValue - The new value for the fallback locale
|
|
38
|
+
* @returns Updated translation map with synchronized numeric suffixes
|
|
39
|
+
*/
|
|
40
|
+
const syncNumericSuffixAcrossLocales = (existingTranslationMap, fallbackLocaleCode, newFallbackValue) => {
|
|
41
|
+
const updatedTranslationMap = {
|
|
42
|
+
...existingTranslationMap,
|
|
43
|
+
[fallbackLocaleCode]: newFallbackValue
|
|
44
|
+
};
|
|
45
|
+
const trailingNumberMatch = newFallbackValue.match(/\d+(?!.*\d)/);
|
|
46
|
+
if (!trailingNumberMatch) return updatedTranslationMap;
|
|
47
|
+
const newTrailingNumber = trailingNumberMatch[0];
|
|
48
|
+
for (const [localeCode, currentValue] of Object.entries(existingTranslationMap)) {
|
|
49
|
+
if (localeCode === fallbackLocaleCode) continue;
|
|
50
|
+
if (!currentValue.match(/\d+(?!.*\d)/)) continue;
|
|
51
|
+
updatedTranslationMap[localeCode] = currentValue.replace(/(\d+)(?!.*\d)/, newTrailingNumber);
|
|
52
|
+
}
|
|
53
|
+
return updatedTranslationMap;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Safely formats a key for use in object literals.
|
|
57
|
+
* Handles special cases like reserved keywords and non-identifier keys.
|
|
58
|
+
*
|
|
59
|
+
* @param objectKey - The key to format
|
|
60
|
+
* @returns Properly formatted key string
|
|
61
|
+
*/
|
|
62
|
+
const stringifyKey = (objectKey) => {
|
|
63
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(objectKey)) return JSON.stringify(objectKey);
|
|
64
|
+
if (objectKey === "true" || objectKey === "false") return JSON.stringify(objectKey);
|
|
65
|
+
return objectKey;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Builds an enumeration initializer string for the 'enu' function call.
|
|
69
|
+
* Creates a properly formatted enumeration object with key-value pairs.
|
|
70
|
+
*
|
|
71
|
+
* @param enumerationMap - Map of enumeration keys to string values
|
|
72
|
+
* @returns Formatted string for the enumeration function call, or empty string if invalid
|
|
73
|
+
*/
|
|
74
|
+
const buildEnumerationInitializer = (enumerationMap) => {
|
|
75
|
+
const enumerationParts = [];
|
|
76
|
+
for (const [enumerationKey, enumerationValue] of Object.entries(enumerationMap)) {
|
|
77
|
+
if (typeof enumerationValue !== "string") return "";
|
|
78
|
+
enumerationParts.push(`${stringifyKey(enumerationKey)}: ${JSON.stringify(enumerationValue)}`);
|
|
79
|
+
}
|
|
80
|
+
return `enu({ ${enumerationParts.join(", ")} })`;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Builds a condition initializer string for the 'cond' function call.
|
|
84
|
+
* Creates a properly formatted condition object with key-value pairs.
|
|
85
|
+
*
|
|
86
|
+
* @param conditionMap - Map of condition keys to string values
|
|
87
|
+
* @returns Formatted string for the condition function call, or empty string if invalid
|
|
88
|
+
*/
|
|
89
|
+
const buildConditionInitializer = (conditionMap) => {
|
|
90
|
+
const conditionParts = [];
|
|
91
|
+
for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {
|
|
92
|
+
if (typeof conditionValue !== "string") return "";
|
|
93
|
+
conditionParts.push(`${stringifyKey(conditionKey)}: ${JSON.stringify(conditionValue)}`);
|
|
94
|
+
}
|
|
95
|
+
return `cond({ ${conditionParts.join(", ")} })`;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Builds a gender initializer string for the 'gender' function call.
|
|
99
|
+
* Creates a properly formatted gender object with key-value pairs.
|
|
100
|
+
*
|
|
101
|
+
* @param genderMap - Map of gender keys to string values
|
|
102
|
+
* @returns Formatted string for the gender function call, or empty string if invalid
|
|
103
|
+
*/
|
|
104
|
+
const buildGenderInitializer = (genderMap) => {
|
|
105
|
+
const genderParts = [];
|
|
106
|
+
for (const [genderKey, genderValue] of Object.entries(genderMap)) {
|
|
107
|
+
if (typeof genderValue !== "string") return "";
|
|
108
|
+
genderParts.push(`${stringifyKey(genderKey)}: ${JSON.stringify(genderValue)}`);
|
|
109
|
+
}
|
|
110
|
+
return `gender({ ${genderParts.join(", ")} })`;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Builds an insertion initializer string for the 'insert' function call.
|
|
114
|
+
* Handles both string content and translation content for insertions.
|
|
115
|
+
*
|
|
116
|
+
* @param insertionContent - The content to be inserted (string or translation)
|
|
117
|
+
* @returns Formatted string for the insertion function call, or undefined if invalid
|
|
118
|
+
*/
|
|
119
|
+
const buildInsertionInitializer = (insertionContent) => {
|
|
120
|
+
if (typeof insertionContent === "string") return `insert(${JSON.stringify(insertionContent)})`;
|
|
121
|
+
if (getNodeType(insertionContent) === NodeType.Translation) {
|
|
122
|
+
const translationMap = insertionContent[NodeType.Translation] ?? {};
|
|
123
|
+
if (!Object.values(translationMap).every((translationValue) => typeof translationValue === "string")) return void 0;
|
|
124
|
+
return `insert(${buildTranslationInitializer(translationMap)})`;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Builds a file initializer string for the 'file' function call.
|
|
129
|
+
* Creates a properly formatted file path reference.
|
|
130
|
+
*
|
|
131
|
+
* @param filePath - The file path to reference
|
|
132
|
+
* @returns Formatted string for the file function call, or undefined if invalid
|
|
133
|
+
*/
|
|
134
|
+
const buildFileInitializer = (filePath) => {
|
|
135
|
+
if (typeof filePath === "string") return `file(${JSON.stringify(filePath)})`;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Builds a markdown initializer string for the 'md' function call.
|
|
139
|
+
* Handles string content, translation content, and file references for markdown.
|
|
140
|
+
*
|
|
141
|
+
* @param markdownContent - The markdown content (string, translation, or file reference)
|
|
142
|
+
* @returns Formatted string for the markdown function call, or undefined if invalid
|
|
143
|
+
*/
|
|
144
|
+
const buildMarkdownInitializer = (markdownContent) => {
|
|
145
|
+
if (typeof markdownContent === "string") return `md(${JSON.stringify(markdownContent)})`;
|
|
146
|
+
if (getNodeType(markdownContent) === NodeType.Translation) {
|
|
147
|
+
const translationMap = markdownContent[NodeType.Translation] ?? {};
|
|
148
|
+
if (!Object.values(translationMap).every((translationValue) => typeof translationValue === "string")) return void 0;
|
|
149
|
+
return `md(${buildTranslationInitializer(translationMap)})`;
|
|
150
|
+
}
|
|
151
|
+
if (getNodeType(markdownContent) === NodeType.File) {
|
|
152
|
+
const filePath = markdownContent[NodeType.File];
|
|
153
|
+
const fileInitializer = buildFileInitializer(filePath);
|
|
154
|
+
if (!fileInitializer) return void 0;
|
|
155
|
+
return `md(${fileInitializer})`;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Builds a nested initializer string for the 'nest' function call.
|
|
160
|
+
* Creates a properly formatted nested dictionary reference.
|
|
161
|
+
*
|
|
162
|
+
* @param nestedContent - The nested content with dictionary key and optional path
|
|
163
|
+
* @returns Formatted string for the nested function call, or undefined if invalid
|
|
164
|
+
*/
|
|
165
|
+
const buildNestedInitializer = (nestedContent) => {
|
|
166
|
+
if (!nestedContent || typeof nestedContent.dictionaryKey !== "string") return void 0;
|
|
167
|
+
if (nestedContent.path && typeof nestedContent.path === "string") return `nest(${JSON.stringify(nestedContent.dictionaryKey)}, ${JSON.stringify(nestedContent.path)})`;
|
|
168
|
+
return `nest(${JSON.stringify(nestedContent.dictionaryKey)})`;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Reads an existing translation map from a property in a content object.
|
|
172
|
+
* Parses the 't' function call and extracts the translation key-value pairs.
|
|
173
|
+
*
|
|
174
|
+
* @param contentObject - The object containing the property
|
|
175
|
+
* @param propertyName - The name of the property to read
|
|
176
|
+
* @returns Translation map with locale keys and values, or undefined if not found
|
|
177
|
+
*/
|
|
178
|
+
const readExistingTranslationMap = (contentObject, propertyName) => {
|
|
179
|
+
const property = contentObject.getProperty(propertyName);
|
|
180
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
181
|
+
const propertyInitializer = property.getInitializer();
|
|
182
|
+
if (!propertyInitializer) return void 0;
|
|
183
|
+
if (!Node.isCallExpression(propertyInitializer)) return void 0;
|
|
184
|
+
const callExpression = propertyInitializer.getExpression();
|
|
185
|
+
if (!Node.isIdentifier(callExpression) || callExpression.getText() !== "t") return void 0;
|
|
186
|
+
const translationArgument = propertyInitializer.getArguments()[0];
|
|
187
|
+
if (!translationArgument || !Node.isObjectLiteralExpression(translationArgument)) return void 0;
|
|
188
|
+
const translationMap = {};
|
|
189
|
+
for (const propertyAssignment of translationArgument.getProperties()) {
|
|
190
|
+
if (!Node.isPropertyAssignment(propertyAssignment)) continue;
|
|
191
|
+
const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
192
|
+
const valueInitializer = propertyAssignment.getInitializer();
|
|
193
|
+
if (valueInitializer && Node.isStringLiteral(valueInitializer)) translationMap[cleanPropertyName] = valueInitializer.getLiteralValue();
|
|
194
|
+
else if (valueInitializer && Node.isArrayLiteralExpression(valueInitializer)) {
|
|
195
|
+
const stringArray = [];
|
|
196
|
+
for (const arrayElement of valueInitializer.getElements()) {
|
|
197
|
+
if (!Node.isStringLiteral(arrayElement)) return void 0;
|
|
198
|
+
stringArray.push(arrayElement.getLiteralValue());
|
|
199
|
+
}
|
|
200
|
+
translationMap[cleanPropertyName] = stringArray;
|
|
201
|
+
} else return;
|
|
202
|
+
}
|
|
203
|
+
return translationMap;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Reads an existing map from a function call (enu, cond, or gender).
|
|
207
|
+
* Parses the function call and extracts the key-value pairs.
|
|
208
|
+
*
|
|
209
|
+
* @param contentObject - The object containing the property
|
|
210
|
+
* @param propertyName - The name of the property to read
|
|
211
|
+
* @param functionName - The name of the function to look for ('enu', 'cond', or 'gender')
|
|
212
|
+
* @returns Map with keys and string values, or undefined if not found
|
|
213
|
+
*/
|
|
214
|
+
const readExistingMapFromCall = (contentObject, propertyName, functionName) => {
|
|
215
|
+
const property = contentObject.getProperty(propertyName);
|
|
216
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
217
|
+
const propertyInitializer = property.getInitializer();
|
|
218
|
+
if (!propertyInitializer || !Node.isCallExpression(propertyInitializer)) return void 0;
|
|
219
|
+
const callExpression = propertyInitializer.getExpression();
|
|
220
|
+
if (!Node.isIdentifier(callExpression) || callExpression.getText() !== functionName) return void 0;
|
|
221
|
+
const functionArgument = propertyInitializer.getArguments()[0];
|
|
222
|
+
if (!functionArgument || !Node.isObjectLiteralExpression(functionArgument)) return void 0;
|
|
223
|
+
const keyValueMap = {};
|
|
224
|
+
for (const propertyAssignment of functionArgument.getProperties()) {
|
|
225
|
+
if (!Node.isPropertyAssignment(propertyAssignment)) continue;
|
|
226
|
+
const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
227
|
+
const valueInitializer = propertyAssignment.getInitializer();
|
|
228
|
+
if (valueInitializer && Node.isStringLiteral(valueInitializer)) keyValueMap[cleanPropertyName] = valueInitializer.getLiteralValue();
|
|
229
|
+
}
|
|
230
|
+
return keyValueMap;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Extracts generic type arguments text from a call expression.
|
|
234
|
+
* Returns the type arguments as a string (e.g., "<string[]>").
|
|
235
|
+
*
|
|
236
|
+
* @param callExpression - The call expression to extract type arguments from
|
|
237
|
+
* @returns Type arguments as a string, or undefined if none found
|
|
238
|
+
*/
|
|
239
|
+
const getCallExpressionTypeArgsText = (callExpression) => {
|
|
240
|
+
try {
|
|
241
|
+
const typeArguments = callExpression.getTypeArguments();
|
|
242
|
+
if (!typeArguments || typeArguments.length === 0) return void 0;
|
|
243
|
+
return `<${typeArguments.map((typeArgument) => typeArgument.getText()).join(", ")}>`;
|
|
244
|
+
} catch {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Reads existing type arguments used in a specific property call.
|
|
250
|
+
* Supports both direct calls and nested calls (e.g., md(t<...>(...))).
|
|
251
|
+
*
|
|
252
|
+
* @param contentObject - The object containing the property
|
|
253
|
+
* @param propertyName - The name of the property to read
|
|
254
|
+
* @param functionName - The name of the function to look for
|
|
255
|
+
* @returns Type arguments as a string, or undefined if not found
|
|
256
|
+
*/
|
|
257
|
+
const readExistingTypeArgsForCall = (contentObject, propertyName, functionName) => {
|
|
258
|
+
const property = contentObject.getProperty(propertyName);
|
|
259
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
260
|
+
const propertyInitializer = property.getInitializer();
|
|
261
|
+
if (!propertyInitializer || !Node.isCallExpression(propertyInitializer)) return void 0;
|
|
262
|
+
const callExpression = propertyInitializer.getExpression();
|
|
263
|
+
if (Node.isIdentifier(callExpression) && callExpression.getText() === functionName) return getCallExpressionTypeArgsText(propertyInitializer);
|
|
264
|
+
if (functionName === "t" && Node.isIdentifier(callExpression) && callExpression.getText() === "md") {
|
|
265
|
+
const markdownArgument = propertyInitializer.getArguments()[0];
|
|
266
|
+
if (markdownArgument && Node.isCallExpression(markdownArgument)) {
|
|
267
|
+
const innerExpression = markdownArgument.getExpression();
|
|
268
|
+
if (Node.isIdentifier(innerExpression) && innerExpression.getText() === "t") return getCallExpressionTypeArgsText(markdownArgument);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Compares two string maps for equality.
|
|
274
|
+
* Filters out non-string values from the first map before comparison.
|
|
275
|
+
*
|
|
276
|
+
* @param firstMap - First map to compare (may contain non-string values)
|
|
277
|
+
* @param secondMap - Second map to compare (should contain only strings)
|
|
278
|
+
* @returns True if the string values in both maps are equal
|
|
279
|
+
*/
|
|
280
|
+
const areStringMapsEqual = (firstMap, secondMap) => {
|
|
281
|
+
if (!secondMap) return false;
|
|
282
|
+
const firstMapStringEntries = Object.entries(firstMap).filter(([, value]) => typeof value === "string");
|
|
283
|
+
if (firstMapStringEntries.length !== Object.keys(firstMap).length) return false;
|
|
284
|
+
if (firstMapStringEntries.length !== Object.keys(secondMap).length) return false;
|
|
285
|
+
for (const [key, value] of firstMapStringEntries) {
|
|
286
|
+
if (!(key in secondMap)) return false;
|
|
287
|
+
if (secondMap[key] !== value) return false;
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Compares translation maps for equality.
|
|
293
|
+
* Handles both string and array values in translations.
|
|
294
|
+
*
|
|
295
|
+
* @param desiredTranslationMap - The desired translation map
|
|
296
|
+
* @param existingTranslationMap - The existing translation map to compare against
|
|
297
|
+
* @returns True if both translation maps are equal
|
|
298
|
+
*/
|
|
299
|
+
const areTranslationsEqual = (desiredTranslationMap, existingTranslationMap) => {
|
|
300
|
+
if (!existingTranslationMap) return false;
|
|
301
|
+
for (const [localeCode, desiredValue] of Object.entries(desiredTranslationMap)) {
|
|
302
|
+
if (!(localeCode in existingTranslationMap)) return false;
|
|
303
|
+
const existingValue = existingTranslationMap[localeCode];
|
|
304
|
+
if (typeof desiredValue === "string") {
|
|
305
|
+
if (typeof existingValue !== "string") return false;
|
|
306
|
+
if (existingValue !== desiredValue) return false;
|
|
307
|
+
} else if (Array.isArray(desiredValue)) {
|
|
308
|
+
if (!Array.isArray(existingValue)) return false;
|
|
309
|
+
if (existingValue.length !== desiredValue.length) return false;
|
|
310
|
+
for (let arrayIndex = 0; arrayIndex < desiredValue.length; arrayIndex++) if (existingValue[arrayIndex] !== desiredValue[arrayIndex]) return false;
|
|
311
|
+
} else return false;
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* Gets existing property names from the content object.
|
|
317
|
+
* Handles both regular property assignments and shorthand properties.
|
|
318
|
+
*
|
|
319
|
+
* @param contentObject - The object literal expression to extract property names from
|
|
320
|
+
* @returns Set of existing property names
|
|
321
|
+
*/
|
|
322
|
+
const getExistingPropertyNames = (contentObject) => {
|
|
323
|
+
const existingPropertyNames = /* @__PURE__ */ new Set();
|
|
324
|
+
for (const property of contentObject.getProperties()) {
|
|
325
|
+
if (Node.isPropertyAssignment(property)) {
|
|
326
|
+
const propertyName = property.getName();
|
|
327
|
+
if (propertyName) existingPropertyNames.add(propertyName.replace(/^['"]|['"]$/g, ""));
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (Node.isShorthandPropertyAssignment(property)) {
|
|
331
|
+
const shorthandPropertyName = property.getNameNode().getText();
|
|
332
|
+
if (shorthandPropertyName) existingPropertyNames.add(shorthandPropertyName);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return existingPropertyNames;
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Processes array content entries.
|
|
339
|
+
* Handles arrays of various content types including strings, objects, and complex content nodes.
|
|
340
|
+
* Supports nested objects within arrays and maintains existing translation structures.
|
|
341
|
+
*
|
|
342
|
+
* @param contentObject - The object containing the array property
|
|
343
|
+
* @param propertyKey - The key of the array property
|
|
344
|
+
* @param arrayValue - The array of values to process
|
|
345
|
+
* @param existingPropertyKeys - Set of existing property names in the content object
|
|
346
|
+
* @param effectiveFallbackLocale - The fallback locale for translations
|
|
347
|
+
* @param requiredImports - Set to track required imports
|
|
348
|
+
* @param sourceFile - The source file being processed
|
|
349
|
+
* @returns True if the content was modified
|
|
350
|
+
*/
|
|
351
|
+
const processArrayContent = (contentObject, propertyKey, arrayValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
|
|
352
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
353
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
354
|
+
if (spreadTargetObject) return processArrayContent(spreadTargetObject, propertyKey, arrayValue, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
|
|
355
|
+
}
|
|
356
|
+
const serializedArrayElements = [];
|
|
357
|
+
let hasUnsupportedContent = false;
|
|
358
|
+
let existingArrayElements;
|
|
359
|
+
let existingArrayHasTranslation = false;
|
|
360
|
+
let existingArrayTypeArguments;
|
|
361
|
+
let arrayWasChanged = false;
|
|
362
|
+
const existingProperty = contentObject.getProperty(propertyKey);
|
|
363
|
+
if (existingProperty && Node.isPropertyAssignment(existingProperty)) {
|
|
364
|
+
const propertyInitializer = existingProperty.getInitializer();
|
|
365
|
+
let existingPropertyTypeArguments;
|
|
366
|
+
const areAllDesiredValuesStrings = arrayValue.every((arrayElement) => typeof arrayElement === "string");
|
|
367
|
+
if (propertyInitializer && Node.isCallExpression(propertyInitializer) && Node.isIdentifier(propertyInitializer.getExpression()) && propertyInitializer.getExpression().getText() === "t" && areAllDesiredValuesStrings) {
|
|
368
|
+
existingPropertyTypeArguments = getCallExpressionTypeArgsText(propertyInitializer);
|
|
369
|
+
const existingTranslationMap = readExistingTranslationMap(contentObject, propertyKey);
|
|
370
|
+
if (existingTranslationMap) {
|
|
371
|
+
const translationInitializerText = buildTranslationInitializer({
|
|
372
|
+
...existingTranslationMap,
|
|
373
|
+
[effectiveFallbackLocale]: arrayValue
|
|
374
|
+
}, existingPropertyTypeArguments);
|
|
375
|
+
requiredImports.add("t");
|
|
376
|
+
const property$1 = contentObject.getProperty(propertyKey);
|
|
377
|
+
if (property$1 && Node.isPropertyAssignment(property$1)) {
|
|
378
|
+
if (property$1.getInitializer()?.getText() !== translationInitializerText) {
|
|
379
|
+
property$1.setInitializer(translationInitializerText);
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (propertyInitializer && Node.isArrayLiteralExpression(propertyInitializer)) {
|
|
387
|
+
existingArrayElements = propertyInitializer.getElements();
|
|
388
|
+
existingArrayHasTranslation = propertyInitializer.getElements().some((arrayElement) => {
|
|
389
|
+
if (!Node.isCallExpression(arrayElement)) return false;
|
|
390
|
+
const callExpression = arrayElement.getExpression();
|
|
391
|
+
return Node.isIdentifier(callExpression) && callExpression.getText() === "t";
|
|
392
|
+
});
|
|
393
|
+
if (existingArrayHasTranslation) {
|
|
394
|
+
for (const arrayElement of existingArrayElements) if (Node.isCallExpression(arrayElement)) {
|
|
395
|
+
const callExpression = arrayElement.getExpression();
|
|
396
|
+
if (Node.isIdentifier(callExpression) && callExpression.getText() === "t") {
|
|
397
|
+
existingArrayTypeArguments = getCallExpressionTypeArgsText(arrayElement);
|
|
398
|
+
if (existingArrayTypeArguments) break;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
for (let elementIndex = 0; elementIndex < arrayValue.length; elementIndex++) {
|
|
405
|
+
const currentElement = arrayValue[elementIndex];
|
|
406
|
+
if (currentElement === null || currentElement === void 0 || typeof currentElement === "string" || typeof currentElement === "number" || typeof currentElement === "boolean") {
|
|
407
|
+
let serializedElementValue = serializeValue(currentElement);
|
|
408
|
+
if (typeof currentElement === "string" && existingArrayElements && elementIndex < existingArrayElements.length) {
|
|
409
|
+
const existingArrayElement = existingArrayElements[elementIndex];
|
|
410
|
+
if (Node.isCallExpression(existingArrayElement)) {
|
|
411
|
+
const callExpression = existingArrayElement.getExpression();
|
|
412
|
+
if (Node.isIdentifier(callExpression) && callExpression.getText() === "t") {
|
|
413
|
+
const translationArgument = existingArrayElement.getArguments()[0];
|
|
414
|
+
if (translationArgument && Node.isObjectLiteralExpression(translationArgument)) {
|
|
415
|
+
const translationMap = {};
|
|
416
|
+
for (const propertyAssignment of translationArgument.getProperties()) {
|
|
417
|
+
if (!Node.isPropertyAssignment(propertyAssignment)) continue;
|
|
418
|
+
const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
419
|
+
const propertyValue = propertyAssignment.getInitializer();
|
|
420
|
+
if (propertyValue && Node.isStringLiteral(propertyValue)) translationMap[cleanPropertyName] = propertyValue.getLiteralValue();
|
|
421
|
+
}
|
|
422
|
+
serializedElementValue = buildTranslationInitializer(syncNumericSuffixAcrossLocales(translationMap, effectiveFallbackLocale, currentElement), getCallExpressionTypeArgsText(existingArrayElement));
|
|
423
|
+
requiredImports.add("t");
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (typeof currentElement === "string" && existingArrayHasTranslation && serializedElementValue && serializedElementValue.startsWith("\"")) {
|
|
429
|
+
serializedElementValue = buildTranslationInitializer({ [effectiveFallbackLocale]: currentElement }, existingArrayTypeArguments);
|
|
430
|
+
requiredImports.add("t");
|
|
431
|
+
}
|
|
432
|
+
if (serializedElementValue === void 0) {
|
|
433
|
+
hasUnsupportedContent = true;
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
serializedArrayElements.push(serializedElementValue);
|
|
437
|
+
} else if (typeof currentElement === "object" && currentElement !== null) {
|
|
438
|
+
if (existingArrayElements && elementIndex < existingArrayElements.length) {
|
|
439
|
+
const existingArrayElement = existingArrayElements[elementIndex];
|
|
440
|
+
if (Node.isObjectLiteralExpression(existingArrayElement)) {
|
|
441
|
+
if (processContentEntries(existingArrayElement, currentElement, effectiveFallbackLocale, requiredImports, sourceFile)) arrayWasChanged = true;
|
|
442
|
+
serializedArrayElements.push(existingArrayElement.getText());
|
|
443
|
+
} else {
|
|
444
|
+
const serializedElementValue = serializeValue(currentElement);
|
|
445
|
+
if (serializedElementValue === void 0) {
|
|
446
|
+
hasUnsupportedContent = true;
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
serializedArrayElements.push(serializedElementValue);
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
const serializedElementValue = serializeValue(currentElement);
|
|
453
|
+
if (serializedElementValue === void 0) {
|
|
454
|
+
hasUnsupportedContent = true;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
serializedArrayElements.push(serializedElementValue);
|
|
458
|
+
}
|
|
459
|
+
const elementNodeType = getNodeType(currentElement);
|
|
460
|
+
if (elementNodeType === NodeType.Translation) requiredImports.add("t");
|
|
461
|
+
else if (elementNodeType === NodeType.Enumeration) requiredImports.add("enu");
|
|
462
|
+
else if (elementNodeType === NodeType.Condition) requiredImports.add("cond");
|
|
463
|
+
else if (elementNodeType === NodeType.Gender) requiredImports.add("gender");
|
|
464
|
+
else if (elementNodeType === NodeType.Insertion) {
|
|
465
|
+
requiredImports.add("insert");
|
|
466
|
+
const insertionContent = currentElement[NodeType.Insertion];
|
|
467
|
+
if (typeof insertionContent === "object" && insertionContent !== null && getNodeType(insertionContent) === NodeType.Translation) requiredImports.add("t");
|
|
468
|
+
} else if (elementNodeType === NodeType.Markdown) {
|
|
469
|
+
requiredImports.add("md");
|
|
470
|
+
const markdownContent = currentElement[NodeType.Markdown];
|
|
471
|
+
if (typeof markdownContent === "object" && markdownContent !== null && getNodeType(markdownContent) === NodeType.File) requiredImports.add("file");
|
|
472
|
+
} else if (elementNodeType === NodeType.File) requiredImports.add("file");
|
|
473
|
+
else if (elementNodeType === NodeType.Nested) requiredImports.add("nest");
|
|
474
|
+
} else {
|
|
475
|
+
hasUnsupportedContent = true;
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (hasUnsupportedContent) return false;
|
|
480
|
+
if (arrayWasChanged) return true;
|
|
481
|
+
const arrayInitializerText = `[ ${serializedArrayElements.join(", ")} ]`;
|
|
482
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
483
|
+
contentObject.addPropertyAssignment({
|
|
484
|
+
name: propertyKey,
|
|
485
|
+
initializer: arrayInitializerText
|
|
486
|
+
});
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
const property = contentObject.getProperty(propertyKey);
|
|
490
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
491
|
+
const existingSerializedArray = readExistingArraySerialized(contentObject, propertyKey);
|
|
492
|
+
if (!(existingSerializedArray !== void 0 && existingSerializedArray.length === serializedArrayElements.length && existingSerializedArray.every((existingElement, elementIndex) => existingElement === serializedArrayElements[elementIndex]))) {
|
|
493
|
+
property.setInitializer(arrayInitializerText);
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return false;
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Processes primitive content entries (string, number, boolean, null).
|
|
501
|
+
* Handles simple value types and updates existing translation maps when appropriate.
|
|
502
|
+
*
|
|
503
|
+
* @param contentObject - The object containing the property
|
|
504
|
+
* @param propertyKey - The key of the property to process
|
|
505
|
+
* @param primitiveValue - The primitive value to process
|
|
506
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
507
|
+
* @param effectiveFallbackLocale - The fallback locale for translations
|
|
508
|
+
* @param requiredImports - Set to track required imports
|
|
509
|
+
* @param sourceFile - The source file being processed
|
|
510
|
+
* @returns True if the content was modified
|
|
511
|
+
*/
|
|
512
|
+
const processPrimitiveContent = (contentObject, propertyKey, primitiveValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
|
|
513
|
+
if (typeof primitiveValue === "string" && existingPropertyKeys.has(propertyKey)) {
|
|
514
|
+
const property$1 = contentObject.getProperty(propertyKey);
|
|
515
|
+
if (property$1 && Node.isPropertyAssignment(property$1)) {
|
|
516
|
+
const propertyInitializer = property$1.getInitializer();
|
|
517
|
+
if (propertyInitializer && !Node.isStringLiteral(propertyInitializer) && !Node.isCallExpression(propertyInitializer)) {
|
|
518
|
+
console.log(`Skipping update for key "${propertyKey}" because existing value is not a string literal`);
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const existingTranslationMap = readExistingTranslationMap(contentObject, propertyKey);
|
|
523
|
+
if (existingTranslationMap) {
|
|
524
|
+
const translationInitializerText = buildTranslationInitializer({
|
|
525
|
+
...existingTranslationMap,
|
|
526
|
+
[effectiveFallbackLocale]: primitiveValue
|
|
527
|
+
}, readExistingTypeArgsForCall(contentObject, propertyKey, "t"));
|
|
528
|
+
requiredImports.add("t");
|
|
529
|
+
if (property$1 && Node.isPropertyAssignment(property$1)) {
|
|
530
|
+
property$1.setInitializer(translationInitializerText);
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
537
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
538
|
+
if (spreadTargetObject) return processPrimitiveContent(spreadTargetObject, propertyKey, primitiveValue, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
|
|
539
|
+
contentObject.addPropertyAssignment({
|
|
540
|
+
name: propertyKey,
|
|
541
|
+
initializer: typeof primitiveValue === "string" ? JSON.stringify(primitiveValue) : String(primitiveValue)
|
|
542
|
+
});
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
const property = contentObject.getProperty(propertyKey);
|
|
546
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
547
|
+
const propertyInitializer = property.getInitializer();
|
|
548
|
+
const isPrimitiveLiteral = propertyInitializer && (Node.isStringLiteral(propertyInitializer) || Node.isNumericLiteral(propertyInitializer) || propertyInitializer.getKind() === SyntaxKind.TrueKeyword || propertyInitializer.getKind() === SyntaxKind.FalseKeyword || Node.isNullLiteral(propertyInitializer) || Node.isCallExpression(propertyInitializer));
|
|
549
|
+
if (propertyInitializer && !isPrimitiveLiteral) {
|
|
550
|
+
console.log(`Skipping update for key "${propertyKey}" because existing value is not a primitive literal`);
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
const currentInitializerText = propertyInitializer?.getText();
|
|
554
|
+
const desiredInitializerText = typeof primitiveValue === "string" ? JSON.stringify(primitiveValue) : String(primitiveValue);
|
|
555
|
+
if (currentInitializerText !== desiredInitializerText) {
|
|
556
|
+
property.setInitializer(desiredInitializerText);
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return false;
|
|
561
|
+
};
|
|
562
|
+
/**
|
|
563
|
+
* Processes complex content entries (translation, enumeration, condition, etc.).
|
|
564
|
+
* Routes content to the appropriate specialized processor based on node type.
|
|
565
|
+
*
|
|
566
|
+
* @param contentObject - The object containing the property
|
|
567
|
+
* @param propertyKey - The key of the property to process
|
|
568
|
+
* @param contentNode - The complex content node to process
|
|
569
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
570
|
+
* @param effectiveFallbackLocale - The fallback locale for translations
|
|
571
|
+
* @param requiredImports - Set to track required imports
|
|
572
|
+
* @param sourceFile - The source file being processed
|
|
573
|
+
* @returns True if the content was modified
|
|
574
|
+
*/
|
|
575
|
+
const processComplexContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
|
|
576
|
+
switch (getNodeType(contentNode)) {
|
|
577
|
+
case NodeType.Translation: return processTranslationContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
|
|
578
|
+
case NodeType.Enumeration: return processEnumerationContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
|
|
579
|
+
case NodeType.Condition: return processConditionContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
|
|
580
|
+
case NodeType.Gender: return processGenderContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
|
|
581
|
+
case NodeType.Insertion: return processInsertionContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
|
|
582
|
+
case NodeType.Markdown: return processMarkdownContent(contentObject, propertyKey, contentNode, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile);
|
|
583
|
+
case NodeType.File: return processFileContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
|
|
584
|
+
case NodeType.Nested: return processNestedContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
|
|
585
|
+
default: return false;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Processes translation content.
|
|
590
|
+
* Handles translation objects with locale keys and string/array values.
|
|
591
|
+
*
|
|
592
|
+
* @param contentObject - The object containing the property
|
|
593
|
+
* @param propertyKey - The key of the property to process
|
|
594
|
+
* @param contentNode - The translation content node
|
|
595
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
596
|
+
* @param requiredImports - Set to track required imports
|
|
597
|
+
* @param sourceFile - The source file being processed
|
|
598
|
+
* @returns True if the content was modified
|
|
599
|
+
*/
|
|
600
|
+
const processTranslationContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
|
|
601
|
+
const translationMap = contentNode[NodeType.Translation] ?? {};
|
|
602
|
+
const areAllValuesStringsOrArrays = Object.values(translationMap).every((translationValue) => typeof translationValue === "string" || Array.isArray(translationValue));
|
|
603
|
+
if (Object.values(translationMap).some((translationValue) => typeof translationValue === "object" && translationValue !== null && !Array.isArray(translationValue) && getNodeType(translationValue) !== NodeType.Text) && !areAllValuesStringsOrArrays) {
|
|
604
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
605
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
606
|
+
if (spreadTargetObject) return processTranslationContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
607
|
+
}
|
|
608
|
+
const translationParts$1 = [];
|
|
609
|
+
let hasUnsupportedValue = false;
|
|
610
|
+
for (const [localeCode, translationValue] of Object.entries(translationMap)) {
|
|
611
|
+
const formattedLocaleKey = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(localeCode) ? localeCode : JSON.stringify(localeCode);
|
|
612
|
+
if (typeof translationValue === "object" && translationValue !== null && !Array.isArray(translationValue)) {
|
|
613
|
+
const serializedValue = serializeValue(translationValue);
|
|
614
|
+
if (serializedValue === void 0) {
|
|
615
|
+
hasUnsupportedValue = true;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
translationParts$1.push(`${formattedLocaleKey}: ${serializedValue}`);
|
|
619
|
+
const nodeType = getNodeType(translationValue);
|
|
620
|
+
if (nodeType === NodeType.Markdown) {
|
|
621
|
+
requiredImports.add("md");
|
|
622
|
+
const markdownContent = translationValue[NodeType.Markdown];
|
|
623
|
+
if (typeof markdownContent === "object" && markdownContent !== null && getNodeType(markdownContent) === NodeType.File) requiredImports.add("file");
|
|
624
|
+
} else if (nodeType === NodeType.File) requiredImports.add("file");
|
|
625
|
+
else if (nodeType === NodeType.Insertion) requiredImports.add("insert");
|
|
626
|
+
else if (nodeType === NodeType.Enumeration) requiredImports.add("enu");
|
|
627
|
+
else if (nodeType === NodeType.Condition) requiredImports.add("cond");
|
|
628
|
+
else if (nodeType === NodeType.Gender) requiredImports.add("gender");
|
|
629
|
+
else if (nodeType === NodeType.Nested) requiredImports.add("nest");
|
|
630
|
+
} else if (typeof translationValue === "string") translationParts$1.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
|
|
631
|
+
else if (Array.isArray(translationValue)) {
|
|
632
|
+
const serializedArrayElements = translationValue.map((arrayElement) => JSON.stringify(arrayElement)).join(", ");
|
|
633
|
+
translationParts$1.push(`${formattedLocaleKey}: [ ${serializedArrayElements} ]`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if (hasUnsupportedValue) return false;
|
|
637
|
+
const translationInitializerText$1 = `t${readExistingTypeArgsForCall(contentObject, propertyKey, "t") ?? ""}({ ${translationParts$1.join(", ")} })`;
|
|
638
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
639
|
+
requiredImports.add("t");
|
|
640
|
+
contentObject.addPropertyAssignment({
|
|
641
|
+
name: propertyKey,
|
|
642
|
+
initializer: translationInitializerText$1
|
|
643
|
+
});
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
const property = contentObject.getProperty(propertyKey);
|
|
647
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
648
|
+
if (property.getInitializer()?.getText() !== translationInitializerText$1) {
|
|
649
|
+
requiredImports.add("t");
|
|
650
|
+
property.setInitializer(translationInitializerText$1);
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
if (!areAllValuesStringsOrArrays) return false;
|
|
657
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
658
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
659
|
+
if (spreadTargetObject) return processTranslationContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
660
|
+
}
|
|
661
|
+
const translationParts = [];
|
|
662
|
+
for (const [localeCode, translationValue] of Object.entries(translationMap)) {
|
|
663
|
+
const formattedLocaleKey = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(localeCode) ? localeCode : JSON.stringify(localeCode);
|
|
664
|
+
if (typeof translationValue === "string") translationParts.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
|
|
665
|
+
else if (Array.isArray(translationValue)) {
|
|
666
|
+
const serializedArrayElements = translationValue.map((arrayElement) => JSON.stringify(arrayElement)).join(", ");
|
|
667
|
+
translationParts.push(`${formattedLocaleKey}: [ ${serializedArrayElements} ]`);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const translationInitializerText = `t${readExistingTypeArgsForCall(contentObject, propertyKey, "t") ?? ""}({ ${translationParts.join(", ")} })`;
|
|
671
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
672
|
+
requiredImports.add("t");
|
|
673
|
+
contentObject.addPropertyAssignment({
|
|
674
|
+
name: propertyKey,
|
|
675
|
+
initializer: translationInitializerText
|
|
676
|
+
});
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
if (!areTranslationsEqual(translationMap, readExistingTranslationMap(contentObject, propertyKey))) {
|
|
680
|
+
requiredImports.add("t");
|
|
681
|
+
const property = contentObject.getProperty(propertyKey);
|
|
682
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
683
|
+
property.setInitializer(translationInitializerText);
|
|
684
|
+
return true;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return false;
|
|
688
|
+
};
|
|
689
|
+
/**
|
|
690
|
+
* Processes enumeration content.
|
|
691
|
+
* Handles enumeration objects with key-value string pairs.
|
|
692
|
+
*
|
|
693
|
+
* @param contentObject - The object containing the property
|
|
694
|
+
* @param propertyKey - The key of the property to process
|
|
695
|
+
* @param contentNode - The enumeration content node
|
|
696
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
697
|
+
* @param requiredImports - Set to track required imports
|
|
698
|
+
* @param sourceFile - The source file being processed
|
|
699
|
+
* @returns True if the content was modified
|
|
700
|
+
*/
|
|
701
|
+
const processEnumerationContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
|
|
702
|
+
const enumerationMap = contentNode[NodeType.Enumeration];
|
|
703
|
+
if (!Object.values(enumerationMap).every((enumerationValue) => typeof enumerationValue === "string")) return false;
|
|
704
|
+
const enumerationInitializerText = buildEnumerationInitializer(enumerationMap);
|
|
705
|
+
if (!enumerationInitializerText) return false;
|
|
706
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
707
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
708
|
+
if (spreadTargetObject) return processEnumerationContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
709
|
+
requiredImports.add("enu");
|
|
710
|
+
contentObject.addPropertyAssignment({
|
|
711
|
+
name: propertyKey,
|
|
712
|
+
initializer: enumerationInitializerText
|
|
713
|
+
});
|
|
714
|
+
return true;
|
|
715
|
+
}
|
|
716
|
+
if (!areStringMapsEqual(enumerationMap, readExistingMapFromCall(contentObject, propertyKey, "enu"))) {
|
|
717
|
+
requiredImports.add("enu");
|
|
718
|
+
const property = contentObject.getProperty(propertyKey);
|
|
719
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
720
|
+
property.setInitializer(enumerationInitializerText);
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return false;
|
|
725
|
+
};
|
|
726
|
+
/**
|
|
727
|
+
* Processes condition content.
|
|
728
|
+
* Handles condition objects with key-value string pairs.
|
|
729
|
+
*
|
|
730
|
+
* @param contentObject - The object containing the property
|
|
731
|
+
* @param propertyKey - The key of the property to process
|
|
732
|
+
* @param contentNode - The condition content node
|
|
733
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
734
|
+
* @param requiredImports - Set to track required imports
|
|
735
|
+
* @param sourceFile - The source file being processed
|
|
736
|
+
* @returns True if the content was modified
|
|
737
|
+
*/
|
|
738
|
+
const processConditionContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
|
|
739
|
+
const conditionMap = contentNode[NodeType.Condition];
|
|
740
|
+
if (Object.values(conditionMap).every((conditionValue) => typeof conditionValue === "string")) {
|
|
741
|
+
const conditionInitializerText = buildConditionInitializer(conditionMap);
|
|
742
|
+
if (!conditionInitializerText) return false;
|
|
743
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
744
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
745
|
+
if (spreadTargetObject) return processConditionContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
746
|
+
requiredImports.add("cond");
|
|
747
|
+
contentObject.addPropertyAssignment({
|
|
748
|
+
name: propertyKey,
|
|
749
|
+
initializer: conditionInitializerText
|
|
750
|
+
});
|
|
751
|
+
return true;
|
|
752
|
+
}
|
|
753
|
+
if (!areStringMapsEqual(conditionMap, readExistingMapFromCall(contentObject, propertyKey, "cond"))) {
|
|
754
|
+
requiredImports.add("cond");
|
|
755
|
+
const property$1 = contentObject.getProperty(propertyKey);
|
|
756
|
+
if (property$1 && Node.isPropertyAssignment(property$1)) {
|
|
757
|
+
property$1.setInitializer(conditionInitializerText);
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
764
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
765
|
+
if (spreadTargetObject) return processConditionContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
const property = contentObject.getProperty(propertyKey);
|
|
769
|
+
if (!property || !Node.isPropertyAssignment(property)) return false;
|
|
770
|
+
const propertyInitializer = property.getInitializer();
|
|
771
|
+
if (!propertyInitializer || !Node.isCallExpression(propertyInitializer)) return false;
|
|
772
|
+
const callExpression = propertyInitializer.getExpression();
|
|
773
|
+
if (!Node.isIdentifier(callExpression) || callExpression.getText() !== "cond") return false;
|
|
774
|
+
const condArgument = propertyInitializer.getArguments()[0];
|
|
775
|
+
if (!condArgument || !Node.isObjectLiteralExpression(condArgument)) return false;
|
|
776
|
+
requiredImports.add("cond");
|
|
777
|
+
let hasModifications = false;
|
|
778
|
+
for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {
|
|
779
|
+
const nodeType = getNodeType(conditionValue);
|
|
780
|
+
if (!nodeType) continue;
|
|
781
|
+
let condProperty = condArgument.getProperty(conditionKey);
|
|
782
|
+
if (!condProperty) condProperty = condArgument.getProperty(stringifyKey(conditionKey));
|
|
783
|
+
if (!condProperty || !Node.isPropertyAssignment(condProperty)) continue;
|
|
784
|
+
const condValueInitializer = condProperty.getInitializer();
|
|
785
|
+
if (!condValueInitializer) continue;
|
|
786
|
+
if (nodeType === NodeType.Translation) {
|
|
787
|
+
if (!Node.isCallExpression(condValueInitializer)) continue;
|
|
788
|
+
const tCallExpression = condValueInitializer.getExpression();
|
|
789
|
+
if (!Node.isIdentifier(tCallExpression) || tCallExpression.getText() !== "t") continue;
|
|
790
|
+
const tArgument = condValueInitializer.getArguments()[0];
|
|
791
|
+
if (!tArgument || !Node.isObjectLiteralExpression(tArgument)) continue;
|
|
792
|
+
const translationMap = conditionValue[NodeType.Translation];
|
|
793
|
+
if (!translationMap || typeof translationMap !== "object") continue;
|
|
794
|
+
const existingTranslationMap = {};
|
|
795
|
+
for (const propertyAssignment of tArgument.getProperties()) {
|
|
796
|
+
if (!Node.isPropertyAssignment(propertyAssignment)) continue;
|
|
797
|
+
const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
798
|
+
const valueInitializer = propertyAssignment.getInitializer();
|
|
799
|
+
if (valueInitializer && Node.isStringLiteral(valueInitializer)) existingTranslationMap[cleanPropertyName] = valueInitializer.getLiteralValue();
|
|
800
|
+
else if (valueInitializer && Node.isArrayLiteralExpression(valueInitializer)) {
|
|
801
|
+
const stringArray = [];
|
|
802
|
+
for (const arrayElement of valueInitializer.getElements()) if (Node.isStringLiteral(arrayElement)) stringArray.push(arrayElement.getLiteralValue());
|
|
803
|
+
existingTranslationMap[cleanPropertyName] = stringArray;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
if (!areTranslationsEqual(translationMap, existingTranslationMap)) {
|
|
807
|
+
requiredImports.add("t");
|
|
808
|
+
for (const [locale, localeValue] of Object.entries(translationMap)) {
|
|
809
|
+
const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(locale);
|
|
810
|
+
const formattedLocaleKey = isLocaleCodeValidIdentifier ? locale : JSON.stringify(locale);
|
|
811
|
+
let existingProperty = tArgument.getProperty(locale);
|
|
812
|
+
if (!existingProperty && !isLocaleCodeValidIdentifier) existingProperty = tArgument.getProperty(JSON.stringify(locale));
|
|
813
|
+
if (existingProperty && Node.isPropertyAssignment(existingProperty)) {
|
|
814
|
+
const currentValue = existingProperty.getInitializer();
|
|
815
|
+
const newValue = Array.isArray(localeValue) ? `[${localeValue.map((v) => JSON.stringify(v)).join(", ")}]` : JSON.stringify(localeValue);
|
|
816
|
+
if (currentValue?.getText() !== newValue) {
|
|
817
|
+
existingProperty.setInitializer(newValue);
|
|
818
|
+
hasModifications = true;
|
|
819
|
+
}
|
|
820
|
+
} else if (!existingProperty) {
|
|
821
|
+
const newValue = Array.isArray(localeValue) ? `[${localeValue.map((v) => JSON.stringify(v)).join(", ")}]` : JSON.stringify(localeValue);
|
|
822
|
+
tArgument.addPropertyAssignment({
|
|
823
|
+
name: formattedLocaleKey,
|
|
824
|
+
initializer: newValue
|
|
825
|
+
});
|
|
826
|
+
hasModifications = true;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return hasModifications;
|
|
833
|
+
};
|
|
834
|
+
/**
|
|
835
|
+
* Processes gender content.
|
|
836
|
+
* Handles gender objects with key-value string pairs.
|
|
837
|
+
*
|
|
838
|
+
* @param contentObject - The object containing the property
|
|
839
|
+
* @param propertyKey - The key of the property to process
|
|
840
|
+
* @param contentNode - The gender content node
|
|
841
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
842
|
+
* @param requiredImports - Set to track required imports
|
|
843
|
+
* @param sourceFile - The source file being processed
|
|
844
|
+
* @returns True if the content was modified
|
|
845
|
+
*/
|
|
846
|
+
const processGenderContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
|
|
847
|
+
const genderMap = contentNode[NodeType.Gender];
|
|
848
|
+
if (!Object.values(genderMap).every((genderValue) => typeof genderValue === "string")) return false;
|
|
849
|
+
const genderInitializerText = buildGenderInitializer(genderMap);
|
|
850
|
+
if (!genderInitializerText) return false;
|
|
851
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
852
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
853
|
+
if (spreadTargetObject) return processGenderContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
854
|
+
requiredImports.add("gender");
|
|
855
|
+
contentObject.addPropertyAssignment({
|
|
856
|
+
name: propertyKey,
|
|
857
|
+
initializer: genderInitializerText
|
|
858
|
+
});
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
if (!areStringMapsEqual(genderMap, readExistingMapFromCall(contentObject, propertyKey, "gender"))) {
|
|
862
|
+
requiredImports.add("gender");
|
|
863
|
+
const property = contentObject.getProperty(propertyKey);
|
|
864
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
865
|
+
property.setInitializer(genderInitializerText);
|
|
866
|
+
return true;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return false;
|
|
870
|
+
};
|
|
871
|
+
/**
|
|
872
|
+
* Processes insertion content.
|
|
873
|
+
* Handles insertion objects with string or translation content.
|
|
874
|
+
*
|
|
875
|
+
* @param contentObject - The object containing the property
|
|
876
|
+
* @param propertyKey - The key of the property to process
|
|
877
|
+
* @param contentNode - The insertion content node
|
|
878
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
879
|
+
* @param requiredImports - Set to track required imports
|
|
880
|
+
* @param sourceFile - The source file being processed
|
|
881
|
+
* @returns True if the content was modified
|
|
882
|
+
*/
|
|
883
|
+
const processInsertionContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
|
|
884
|
+
const insertionContent = contentNode[NodeType.Insertion];
|
|
885
|
+
const insertionInitializerText = buildInsertionInitializer(insertionContent);
|
|
886
|
+
if (!insertionInitializerText) return false;
|
|
887
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
888
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
889
|
+
if (spreadTargetObject) return processInsertionContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
890
|
+
requiredImports.add("insert");
|
|
891
|
+
if (typeof insertionContent === "object" && insertionContent !== null && getNodeType(insertionContent) === NodeType.Translation) requiredImports.add("t");
|
|
892
|
+
contentObject.addPropertyAssignment({
|
|
893
|
+
name: propertyKey,
|
|
894
|
+
initializer: insertionInitializerText
|
|
895
|
+
});
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
const existingInsertion = readExistingInsertion(contentObject, propertyKey);
|
|
899
|
+
if (!(typeof insertionContent === "string" && existingInsertion?.kind === "string" && existingInsertion.value === insertionContent || typeof insertionContent === "object" && insertionContent !== null && getNodeType(insertionContent) === NodeType.Translation && existingInsertion?.kind === "translation" && areStringMapsEqual(insertionContent[NodeType.Translation] ?? {}, existingInsertion.map))) {
|
|
900
|
+
requiredImports.add("insert");
|
|
901
|
+
if (typeof insertionContent === "object" && insertionContent !== null && getNodeType(insertionContent) === NodeType.Translation) requiredImports.add("t");
|
|
902
|
+
const property = contentObject.getProperty(propertyKey);
|
|
903
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
904
|
+
property.setInitializer(insertionInitializerText);
|
|
905
|
+
return true;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return false;
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* Processes markdown content.
|
|
912
|
+
* Handles markdown objects with string, translation, or file content.
|
|
913
|
+
*
|
|
914
|
+
* @param contentObject - The object containing the property
|
|
915
|
+
* @param propertyKey - The key of the property to process
|
|
916
|
+
* @param contentNode - The markdown content node
|
|
917
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
918
|
+
* @param effectiveFallbackLocale - The fallback locale for translations
|
|
919
|
+
* @param requiredImports - Set to track required imports
|
|
920
|
+
* @param sourceFile - The source file being processed
|
|
921
|
+
* @returns True if the content was modified
|
|
922
|
+
*/
|
|
923
|
+
const processMarkdownContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
|
|
924
|
+
const markdownContent = contentNode[NodeType.Markdown];
|
|
925
|
+
const markdownInitializerText = buildMarkdownInitializer(markdownContent);
|
|
926
|
+
if (!markdownInitializerText) return false;
|
|
927
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
928
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
929
|
+
if (spreadTargetObject) return processMarkdownContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
|
|
930
|
+
requiredImports.add("md");
|
|
931
|
+
const markdownNodeType$1 = getNodeType(markdownContent);
|
|
932
|
+
if (markdownNodeType$1 === NodeType.File) requiredImports.add("file");
|
|
933
|
+
else if (markdownNodeType$1 === NodeType.Translation) requiredImports.add("t");
|
|
934
|
+
contentObject.addPropertyAssignment({
|
|
935
|
+
name: propertyKey,
|
|
936
|
+
initializer: markdownInitializerText
|
|
937
|
+
});
|
|
938
|
+
return true;
|
|
939
|
+
}
|
|
940
|
+
const markdownNodeType = getNodeType(markdownContent);
|
|
941
|
+
const existingSimpleMarkdown = readExistingMarkdown(contentObject, propertyKey);
|
|
942
|
+
const existingMarkdownTranslationMap = readExistingMarkdownTranslationMap(contentObject, propertyKey);
|
|
943
|
+
const existingTranslationTypeArguments = readExistingTypeArgsForCall(contentObject, propertyKey, "t");
|
|
944
|
+
if (typeof markdownContent === "string" && existingMarkdownTranslationMap && effectiveFallbackLocale) {
|
|
945
|
+
const updatedTranslationMap = {
|
|
946
|
+
...existingMarkdownTranslationMap,
|
|
947
|
+
[effectiveFallbackLocale]: markdownContent
|
|
948
|
+
};
|
|
949
|
+
requiredImports.add("md");
|
|
950
|
+
requiredImports.add("t");
|
|
951
|
+
const property = contentObject.getProperty(propertyKey);
|
|
952
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
953
|
+
property.setInitializer(`md(${buildTranslationInitializer(updatedTranslationMap, existingTranslationTypeArguments)})`);
|
|
954
|
+
return true;
|
|
955
|
+
}
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
if (markdownNodeType === NodeType.Translation) {
|
|
959
|
+
const markdownTranslationMap = markdownContent[NodeType.Translation];
|
|
960
|
+
if (!Object.values(markdownTranslationMap).every((translationValue) => typeof translationValue === "string")) return false;
|
|
961
|
+
if (!areStringMapsEqual(markdownTranslationMap, existingMarkdownTranslationMap)) {
|
|
962
|
+
requiredImports.add("md");
|
|
963
|
+
requiredImports.add("t");
|
|
964
|
+
const property = contentObject.getProperty(propertyKey);
|
|
965
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
966
|
+
property.setInitializer(`md(${buildTranslationInitializer(markdownTranslationMap, existingTranslationTypeArguments)})`);
|
|
967
|
+
return true;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return false;
|
|
971
|
+
}
|
|
972
|
+
if (!(typeof markdownContent === "string" && existingSimpleMarkdown?.kind === "string" && existingSimpleMarkdown.value === markdownContent || markdownNodeType === NodeType.File && existingSimpleMarkdown?.kind === "file" && existingSimpleMarkdown.path === markdownContent[NodeType.File])) {
|
|
973
|
+
requiredImports.add("md");
|
|
974
|
+
if (markdownNodeType === NodeType.File) requiredImports.add("file");
|
|
975
|
+
const property = contentObject.getProperty(propertyKey);
|
|
976
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
977
|
+
property.setInitializer(markdownInitializerText);
|
|
978
|
+
return true;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
return false;
|
|
982
|
+
};
|
|
983
|
+
/**
|
|
984
|
+
* Processes file content.
|
|
985
|
+
* Handles file objects with file path references.
|
|
986
|
+
*
|
|
987
|
+
* @param contentObject - The object containing the property
|
|
988
|
+
* @param propertyKey - The key of the property to process
|
|
989
|
+
* @param contentNode - The file content node
|
|
990
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
991
|
+
* @param requiredImports - Set to track required imports
|
|
992
|
+
* @param sourceFile - The source file being processed
|
|
993
|
+
* @returns True if the content was modified
|
|
994
|
+
*/
|
|
995
|
+
const processFileContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
|
|
996
|
+
const filePath = contentNode[NodeType.File];
|
|
997
|
+
const fileInitializerText = buildFileInitializer(filePath);
|
|
998
|
+
if (!fileInitializerText) return false;
|
|
999
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
1000
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
1001
|
+
if (spreadTargetObject) return processFileContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
1002
|
+
requiredImports.add("file");
|
|
1003
|
+
contentObject.addPropertyAssignment({
|
|
1004
|
+
name: propertyKey,
|
|
1005
|
+
initializer: fileInitializerText
|
|
1006
|
+
});
|
|
1007
|
+
return true;
|
|
1008
|
+
}
|
|
1009
|
+
if (readExistingFilePath(contentObject, propertyKey) !== filePath) {
|
|
1010
|
+
requiredImports.add("file");
|
|
1011
|
+
const property = contentObject.getProperty(propertyKey);
|
|
1012
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
1013
|
+
property.setInitializer(fileInitializerText);
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return false;
|
|
1018
|
+
};
|
|
1019
|
+
/**
|
|
1020
|
+
* Processes nested content.
|
|
1021
|
+
* Handles nested objects with dictionary key and optional path references.
|
|
1022
|
+
*
|
|
1023
|
+
* @param contentObject - The object containing the property
|
|
1024
|
+
* @param propertyKey - The key of the property to process
|
|
1025
|
+
* @param contentNode - The nested content node
|
|
1026
|
+
* @param existingPropertyKeys - Set of existing property names
|
|
1027
|
+
* @param requiredImports - Set to track required imports
|
|
1028
|
+
* @param sourceFile - The source file being processed
|
|
1029
|
+
* @returns True if the content was modified
|
|
1030
|
+
*/
|
|
1031
|
+
const processNestedContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
|
|
1032
|
+
const nestedContent = contentNode[NodeType.Nested];
|
|
1033
|
+
const nestedInitializerText = buildNestedInitializer(nestedContent);
|
|
1034
|
+
if (!nestedInitializerText) return false;
|
|
1035
|
+
if (!existingPropertyKeys.has(propertyKey)) {
|
|
1036
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
1037
|
+
if (spreadTargetObject) return processNestedContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
|
|
1038
|
+
requiredImports.add("nest");
|
|
1039
|
+
contentObject.addPropertyAssignment({
|
|
1040
|
+
name: propertyKey,
|
|
1041
|
+
initializer: nestedInitializerText
|
|
1042
|
+
});
|
|
1043
|
+
return true;
|
|
1044
|
+
}
|
|
1045
|
+
const existingNestedContent = readExistingNest(contentObject, propertyKey);
|
|
1046
|
+
if (!(!!nestedContent && existingNestedContent?.dictionaryKey === nestedContent.dictionaryKey && existingNestedContent?.path === nestedContent.path)) {
|
|
1047
|
+
requiredImports.add("nest");
|
|
1048
|
+
const property = contentObject.getProperty(propertyKey);
|
|
1049
|
+
if (property && Node.isPropertyAssignment(property)) {
|
|
1050
|
+
property.setInitializer(nestedInitializerText);
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
return false;
|
|
1055
|
+
};
|
|
1056
|
+
/**
|
|
1057
|
+
* Processes nested object content.
|
|
1058
|
+
* Handles nested objects within content structures.
|
|
1059
|
+
*
|
|
1060
|
+
* @param contentObject - The object containing the property
|
|
1061
|
+
* @param propertyKey - The key of the property to process
|
|
1062
|
+
* @param nestedObjectValue - The nested object value to process
|
|
1063
|
+
* @param _existingPropertyKeys - Set of existing property names (unused)
|
|
1064
|
+
* @param effectiveFallbackLocale - The fallback locale for translations
|
|
1065
|
+
* @param requiredImports - Set to track required imports
|
|
1066
|
+
* @param sourceFile - The source file being processed
|
|
1067
|
+
* @returns True if the content was modified
|
|
1068
|
+
*/
|
|
1069
|
+
const processNestedObjectContent = (contentObject, propertyKey, nestedObjectValue, _existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
|
|
1070
|
+
let childObject;
|
|
1071
|
+
const existingProperty = contentObject.getProperty(propertyKey);
|
|
1072
|
+
if (existingProperty && Node.isPropertyAssignment(existingProperty)) childObject = existingProperty.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);
|
|
1073
|
+
if (!childObject) {
|
|
1074
|
+
const shorthandProperty = contentObject.getProperty(propertyKey);
|
|
1075
|
+
if (shorthandProperty && Node.isShorthandPropertyAssignment(shorthandProperty)) childObject = resolveNameToObjectLiteral(contentObject.getSourceFile(), propertyKey);
|
|
1076
|
+
else if (existingProperty && Node.isPropertyAssignment(existingProperty)) {
|
|
1077
|
+
const propertyInitializer = existingProperty.getInitializer();
|
|
1078
|
+
if (propertyInitializer) {
|
|
1079
|
+
if (Node.isIdentifier(propertyInitializer)) childObject = resolveNameToObjectLiteral(sourceFile, propertyInitializer.getText());
|
|
1080
|
+
else if (Node.isPropertyAccessExpression(propertyInitializer)) childObject = resolveExpressionToObjectLiteral(sourceFile, propertyInitializer);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
if (!childObject) {
|
|
1085
|
+
const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
|
|
1086
|
+
if (spreadTargetObject) return processNestedObjectContent(spreadTargetObject, propertyKey, nestedObjectValue, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
|
|
1087
|
+
contentObject.addPropertyAssignment({
|
|
1088
|
+
name: propertyKey,
|
|
1089
|
+
initializer: "{ }"
|
|
1090
|
+
});
|
|
1091
|
+
const newProperty = contentObject.getProperty(propertyKey);
|
|
1092
|
+
if (newProperty && Node.isPropertyAssignment(newProperty)) childObject = newProperty.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);
|
|
1093
|
+
}
|
|
1094
|
+
if (childObject) return processContentEntries(childObject, nestedObjectValue, effectiveFallbackLocale, requiredImports, sourceFile);
|
|
1095
|
+
return false;
|
|
1096
|
+
};
|
|
1097
|
+
/**
|
|
1098
|
+
* Processes content entries in a dictionary object.
|
|
1099
|
+
* Routes different content types to appropriate processors.
|
|
1100
|
+
*
|
|
1101
|
+
* @param contentObject - The object containing the content
|
|
1102
|
+
* @param dictionaryContent - The dictionary content to process
|
|
1103
|
+
* @param effectiveFallbackLocale - The fallback locale for translations
|
|
1104
|
+
* @param requiredImports - Set to track required imports
|
|
1105
|
+
* @param sourceFile - The source file being processed
|
|
1106
|
+
* @returns True if any content was modified
|
|
1107
|
+
*/
|
|
1108
|
+
const processContentEntries = (contentObject, dictionaryContent, effectiveFallbackLocale, requiredImports, sourceFile) => {
|
|
1109
|
+
let contentWasChanged = false;
|
|
1110
|
+
const existingPropertyKeys = getExistingPropertyNames(contentObject);
|
|
1111
|
+
for (const [propertyKey, propertyValue] of Object.entries(dictionaryContent)) {
|
|
1112
|
+
if (Array.isArray(propertyValue)) {
|
|
1113
|
+
if (processArrayContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) contentWasChanged = true;
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if (typeof propertyValue === "string" || typeof propertyValue === "number" || typeof propertyValue === "boolean" || propertyValue === null) {
|
|
1117
|
+
if (processPrimitiveContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) contentWasChanged = true;
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
const nodeType = getNodeType(propertyValue);
|
|
1121
|
+
if (nodeType !== NodeType.Text && nodeType !== NodeType.Number && nodeType !== NodeType.Boolean && nodeType !== NodeType.Null) {
|
|
1122
|
+
if (processComplexContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) {
|
|
1123
|
+
contentWasChanged = true;
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
if (propertyValue && typeof propertyValue === "object" && !Array.isArray(propertyValue) && !propertyValue.nodeType) {
|
|
1128
|
+
if (processNestedObjectContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) contentWasChanged = true;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
return contentWasChanged;
|
|
187
1132
|
};
|
|
188
1133
|
const readExistingInsertion = (contentObject, propName) => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return void 0;
|
|
1134
|
+
const prop = contentObject.getProperty(propName);
|
|
1135
|
+
if (!prop || !Node.isPropertyAssignment(prop)) return void 0;
|
|
1136
|
+
const init = prop.getInitializer();
|
|
1137
|
+
if (!init || !Node.isCallExpression(init)) return void 0;
|
|
1138
|
+
const exp = init.getExpression();
|
|
1139
|
+
if (!Node.isIdentifier(exp) || exp.getText() !== "insert") return void 0;
|
|
1140
|
+
const argument = init.getArguments()[0];
|
|
1141
|
+
if (!argument) return void 0;
|
|
1142
|
+
if (Node.isStringLiteral(argument)) return {
|
|
1143
|
+
kind: "string",
|
|
1144
|
+
value: argument.getLiteralValue()
|
|
1145
|
+
};
|
|
1146
|
+
if (Node.isCallExpression(argument)) {
|
|
1147
|
+
const argumentExpression = argument.getExpression();
|
|
1148
|
+
if (Node.isIdentifier(argumentExpression) && argumentExpression.getText() === "t") {
|
|
1149
|
+
const translationArgument = argument.getArguments()[0];
|
|
1150
|
+
if (translationArgument && Node.isObjectLiteralExpression(translationArgument)) {
|
|
1151
|
+
const map = {};
|
|
1152
|
+
for (const propertyAssignment of translationArgument.getProperties()) {
|
|
1153
|
+
if (!Node.isPropertyAssignment(propertyAssignment)) continue;
|
|
1154
|
+
const name = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
1155
|
+
const valueInitializer = propertyAssignment.getInitializer();
|
|
1156
|
+
if (valueInitializer && Node.isStringLiteral(valueInitializer)) map[name] = valueInitializer.getLiteralValue();
|
|
1157
|
+
}
|
|
1158
|
+
return {
|
|
1159
|
+
kind: "translation",
|
|
1160
|
+
map
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
221
1165
|
};
|
|
222
1166
|
const readExistingMarkdown = (contentObject, propName) => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
1167
|
+
const property = contentObject.getProperty(propName);
|
|
1168
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
1169
|
+
const initializer = property.getInitializer();
|
|
1170
|
+
if (!initializer) return void 0;
|
|
1171
|
+
if (Node.isCallExpression(initializer)) {
|
|
1172
|
+
const expression = initializer.getExpression();
|
|
1173
|
+
if (!Node.isIdentifier(expression)) return void 0;
|
|
1174
|
+
if (expression.getText() === "md") {
|
|
1175
|
+
const argument = initializer.getArguments()[0];
|
|
1176
|
+
if (!argument) return void 0;
|
|
1177
|
+
if (Node.isStringLiteral(argument)) return {
|
|
1178
|
+
kind: "string",
|
|
1179
|
+
value: argument.getLiteralValue()
|
|
1180
|
+
};
|
|
1181
|
+
if (Node.isCallExpression(argument)) {
|
|
1182
|
+
const argumentExpression = argument.getExpression();
|
|
1183
|
+
if (Node.isIdentifier(argumentExpression) && argumentExpression.getText() === "file") {
|
|
1184
|
+
const fileArgument = argument.getArguments()[0];
|
|
1185
|
+
if (fileArgument && Node.isStringLiteral(fileArgument)) return {
|
|
1186
|
+
kind: "file",
|
|
1187
|
+
path: fileArgument.getLiteralValue()
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
244
1193
|
};
|
|
245
1194
|
const readExistingFilePath = (contentObject, propName) => {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
1195
|
+
const property = contentObject.getProperty(propName);
|
|
1196
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
1197
|
+
const initializer = property.getInitializer();
|
|
1198
|
+
if (!initializer || !Node.isCallExpression(initializer)) return void 0;
|
|
1199
|
+
const expression = initializer.getExpression();
|
|
1200
|
+
if (!Node.isIdentifier(expression) || expression.getText() !== "file") return void 0;
|
|
1201
|
+
const argument = initializer.getArguments()[0];
|
|
1202
|
+
if (argument && Node.isStringLiteral(argument)) return argument.getLiteralValue();
|
|
1203
|
+
};
|
|
1204
|
+
const readExistingMarkdownTranslationMap = (contentObject, propName) => {
|
|
1205
|
+
const property = contentObject.getProperty(propName);
|
|
1206
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
1207
|
+
const initializer = property.getInitializer();
|
|
1208
|
+
if (!initializer) return void 0;
|
|
1209
|
+
if (Node.isCallExpression(initializer)) {
|
|
1210
|
+
const exp = initializer.getExpression();
|
|
1211
|
+
if (Node.isIdentifier(exp) && exp.getText() === "md") {
|
|
1212
|
+
const arg = initializer.getArguments()[0];
|
|
1213
|
+
if (arg && Node.isCallExpression(arg)) {
|
|
1214
|
+
const tExp = arg.getExpression();
|
|
1215
|
+
if (Node.isIdentifier(tExp) && tExp.getText() === "t") {
|
|
1216
|
+
const tArg = arg.getArguments()[0];
|
|
1217
|
+
if (tArg && Node.isObjectLiteralExpression(tArg)) {
|
|
1218
|
+
const map = {};
|
|
1219
|
+
for (const prop of tArg.getProperties()) {
|
|
1220
|
+
if (!Node.isPropertyAssignment(prop)) continue;
|
|
1221
|
+
const name = prop.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
1222
|
+
const valueInit = prop.getInitializer();
|
|
1223
|
+
if (valueInit && Node.isStringLiteral(valueInit)) map[name] = valueInit.getLiteralValue();
|
|
1224
|
+
else return;
|
|
1225
|
+
}
|
|
1226
|
+
return map;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
if (Node.isCallExpression(initializer)) {
|
|
1233
|
+
const exp = initializer.getExpression();
|
|
1234
|
+
if (Node.isIdentifier(exp) && exp.getText() === "t") {
|
|
1235
|
+
const tArg = initializer.getArguments()[0];
|
|
1236
|
+
if (tArg && Node.isObjectLiteralExpression(tArg)) {
|
|
1237
|
+
const map = {};
|
|
1238
|
+
for (const prop of tArg.getProperties()) {
|
|
1239
|
+
if (!Node.isPropertyAssignment(prop)) continue;
|
|
1240
|
+
const name = prop.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
1241
|
+
const valueInit = prop.getInitializer();
|
|
1242
|
+
if (valueInit && Node.isCallExpression(valueInit) && Node.isIdentifier(valueInit.getExpression()) && valueInit.getExpression().getText() === "md") {
|
|
1243
|
+
const mdArg = valueInit.getArguments()[0];
|
|
1244
|
+
if (mdArg && Node.isStringLiteral(mdArg)) map[name] = mdArg.getLiteralValue();
|
|
1245
|
+
else return;
|
|
1246
|
+
} else return;
|
|
1247
|
+
}
|
|
1248
|
+
return map;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
255
1252
|
};
|
|
256
1253
|
const readExistingNest = (contentObject, propName) => {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
1254
|
+
const property = contentObject.getProperty(propName);
|
|
1255
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
1256
|
+
let initializer = property.getInitializer();
|
|
1257
|
+
if (!initializer) return void 0;
|
|
1258
|
+
let safetyCounter = 0;
|
|
1259
|
+
while (safetyCounter++ < 5) {
|
|
1260
|
+
if (Node.isCallExpression(initializer)) break;
|
|
1261
|
+
const nextExpression = initializer.getExpression?.();
|
|
1262
|
+
if (nextExpression && typeof nextExpression === "object" && nextExpression !== initializer) {
|
|
1263
|
+
initializer = nextExpression;
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
if (!Node.isCallExpression(initializer)) return void 0;
|
|
1269
|
+
const expression = initializer.getExpression();
|
|
1270
|
+
if (!Node.isIdentifier(expression) || expression.getText() !== "nest") return void 0;
|
|
1271
|
+
const [firstArgument, secondArgument] = initializer.getArguments();
|
|
1272
|
+
if (!firstArgument || !Node.isStringLiteral(firstArgument)) return void 0;
|
|
1273
|
+
const dictionaryKey = firstArgument.getLiteralValue();
|
|
1274
|
+
let path;
|
|
1275
|
+
if (secondArgument && Node.isStringLiteral(secondArgument)) path = secondArgument.getLiteralValue();
|
|
1276
|
+
return {
|
|
1277
|
+
dictionaryKey,
|
|
1278
|
+
path
|
|
1279
|
+
};
|
|
281
1280
|
};
|
|
282
1281
|
const unwrapToObjectLiteral = (node) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
1282
|
+
if (!node || typeof node !== "object") return void 0;
|
|
1283
|
+
let current = node;
|
|
1284
|
+
let safetyCounter = 0;
|
|
1285
|
+
while (safetyCounter++ < 8) {
|
|
1286
|
+
if (Node.isObjectLiteralExpression(current)) return current;
|
|
1287
|
+
const next = current?.getExpression?.();
|
|
1288
|
+
if (next && typeof next === "object" && next !== current) {
|
|
1289
|
+
current = next;
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
const resolveNameToObjectLiteral = (sourceFile, name) => {
|
|
1296
|
+
const varDecl = sourceFile.getVariableDeclaration(name);
|
|
1297
|
+
if (varDecl) {
|
|
1298
|
+
const obj = unwrapToObjectLiteral(varDecl.getInitializer());
|
|
1299
|
+
if (obj) return obj;
|
|
1300
|
+
}
|
|
1301
|
+
const decl = sourceFile.getDescendants().find((n) => {
|
|
1302
|
+
return Node.isIdentifier(n) && n.getText() === name;
|
|
1303
|
+
})?.getSymbol()?.getDeclarations()?.[0];
|
|
1304
|
+
if (decl && Node.isVariableDeclaration(decl)) {
|
|
1305
|
+
const obj = unwrapToObjectLiteral(decl.getInitializer());
|
|
1306
|
+
if (obj) return obj;
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
const resolveExpressionToObjectLiteral = (sourceFile, expr) => {
|
|
1310
|
+
if (Node.isIdentifier(expr)) return resolveNameToObjectLiteral(sourceFile, expr.getText());
|
|
1311
|
+
if (Node.isPropertyAccessExpression(expr)) {
|
|
1312
|
+
const leftResolved = resolveExpressionToObjectLiteral(sourceFile, expr.getExpression());
|
|
1313
|
+
if (!leftResolved) return void 0;
|
|
1314
|
+
const propName = expr.getName();
|
|
1315
|
+
const prop = leftResolved.getProperty(propName);
|
|
1316
|
+
if (prop && Node.isPropertyAssignment(prop)) {
|
|
1317
|
+
const init = prop.getInitializer();
|
|
1318
|
+
const obj = unwrapToObjectLiteral(init);
|
|
1319
|
+
if (obj) return obj;
|
|
1320
|
+
if (init && Node.isIdentifier(init)) return resolveNameToObjectLiteral(sourceFile, init.getText());
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
const getSpreadSourceObjects = (contentObject, sourceFile) => {
|
|
1325
|
+
const spreads = [];
|
|
1326
|
+
for (const prop of contentObject.getProperties()) if (Node.isSpreadAssignment(prop)) {
|
|
1327
|
+
const resolved = resolveExpressionToObjectLiteral(sourceFile, prop.getExpression());
|
|
1328
|
+
if (resolved) spreads.push(resolved);
|
|
1329
|
+
}
|
|
1330
|
+
return spreads;
|
|
1331
|
+
};
|
|
1332
|
+
const findSpreadTargetObjectForKey = (contentObject, key, sourceFile) => {
|
|
1333
|
+
const spreads = getSpreadSourceObjects(contentObject, sourceFile);
|
|
1334
|
+
for (let i = spreads.length - 1; i >= 0; i--) {
|
|
1335
|
+
const spreadObj = spreads[i];
|
|
1336
|
+
const prop = spreadObj.getProperty(key);
|
|
1337
|
+
if (prop && Node.isPropertyAssignment(prop)) return spreadObj;
|
|
1338
|
+
}
|
|
296
1339
|
};
|
|
297
1340
|
const readExistingArraySerialized = (contentObject, propName) => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return void 0;
|
|
344
|
-
}
|
|
345
|
-
return serialized;
|
|
1341
|
+
const property = contentObject.getProperty(propName);
|
|
1342
|
+
if (!property || !Node.isPropertyAssignment(property)) return void 0;
|
|
1343
|
+
const initializer = property.getInitializer();
|
|
1344
|
+
if (!initializer || !Node.isArrayLiteralExpression(initializer)) return void 0;
|
|
1345
|
+
const serialized = [];
|
|
1346
|
+
for (const element of initializer.getElements()) {
|
|
1347
|
+
if (Node.isStringLiteral(element)) {
|
|
1348
|
+
serialized.push(JSON.stringify(element.getLiteralValue()));
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
if (Node.isNumericLiteral(element)) {
|
|
1352
|
+
serialized.push(element.getText());
|
|
1353
|
+
continue;
|
|
1354
|
+
}
|
|
1355
|
+
if (element.getKind() === SyntaxKind.TrueKeyword || element.getKind() === SyntaxKind.FalseKeyword) {
|
|
1356
|
+
serialized.push(element.getText());
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (Node.isNullLiteral(element)) {
|
|
1360
|
+
serialized.push("null");
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
if (Node.isCallExpression(element)) {
|
|
1364
|
+
const expression = element.getExpression();
|
|
1365
|
+
if (Node.isIdentifier(expression) && expression.getText() === "t") {
|
|
1366
|
+
const argument = element.getArguments()[0];
|
|
1367
|
+
if (argument && Node.isObjectLiteralExpression(argument)) {
|
|
1368
|
+
const map = {};
|
|
1369
|
+
for (const propertyAssignment of argument.getProperties()) {
|
|
1370
|
+
if (!Node.isPropertyAssignment(propertyAssignment)) return void 0;
|
|
1371
|
+
const name = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
1372
|
+
const valueInitializer = propertyAssignment.getInitializer();
|
|
1373
|
+
if (valueInitializer && Node.isStringLiteral(valueInitializer)) map[name] = valueInitializer.getLiteralValue();
|
|
1374
|
+
else return;
|
|
1375
|
+
}
|
|
1376
|
+
serialized.push(buildTranslationInitializer(map));
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
return serialized;
|
|
346
1384
|
};
|
|
347
1385
|
const serializeValue = (value) => {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
const desired = value[NodeType.File];
|
|
701
|
-
const initializerText = buildFileInitializer(desired);
|
|
702
|
-
if (!initializerText) continue;
|
|
703
|
-
if (!existingKeys.has(key)) {
|
|
704
|
-
contentObject.addPropertyAssignment({
|
|
705
|
-
name: key,
|
|
706
|
-
initializer: initializerText
|
|
707
|
-
});
|
|
708
|
-
changed = true;
|
|
709
|
-
continue;
|
|
710
|
-
}
|
|
711
|
-
const existing = readExistingFilePath(contentObject, key);
|
|
712
|
-
if (existing !== desired) {
|
|
713
|
-
const prop = contentObject.getProperty(key);
|
|
714
|
-
if (prop && Node.isPropertyAssignment(prop)) {
|
|
715
|
-
prop.setInitializer(initializerText);
|
|
716
|
-
changed = true;
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
} else if (isNestedNode(value)) {
|
|
720
|
-
const initializerText = buildNestedInitializer(value);
|
|
721
|
-
if (!initializerText) continue;
|
|
722
|
-
if (!existingKeys.has(key)) {
|
|
723
|
-
contentObject.addPropertyAssignment({
|
|
724
|
-
name: key,
|
|
725
|
-
initializer: initializerText
|
|
726
|
-
});
|
|
727
|
-
changed = true;
|
|
728
|
-
continue;
|
|
729
|
-
}
|
|
730
|
-
const existing = readExistingNest(contentObject, key);
|
|
731
|
-
const desired = value[NodeType.Nested];
|
|
732
|
-
const isSame = !!desired && existing?.dictionaryKey === desired.dictionaryKey && existing?.path === desired.path;
|
|
733
|
-
if (!isSame) {
|
|
734
|
-
const prop = contentObject.getProperty(key);
|
|
735
|
-
if (prop && Node.isPropertyAssignment(prop)) {
|
|
736
|
-
prop.setInitializer(initializerText);
|
|
737
|
-
changed = true;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
if (!changed) return fileContent;
|
|
743
|
-
return sourceFile.getFullText();
|
|
744
|
-
} catch {
|
|
745
|
-
return fileContent;
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
|
-
export {
|
|
749
|
-
transformJSFile
|
|
1386
|
+
const nodeType = getNodeType(value);
|
|
1387
|
+
if (nodeType === NodeType.Text) return JSON.stringify(value);
|
|
1388
|
+
if (nodeType === NodeType.Number || nodeType === NodeType.Boolean) return String(value);
|
|
1389
|
+
if (nodeType === NodeType.Null) return "null";
|
|
1390
|
+
if (nodeType === NodeType.Translation) {
|
|
1391
|
+
const translations = value[NodeType.Translation] ?? {};
|
|
1392
|
+
if (!Object.values(translations).every((v) => typeof v === "string")) return void 0;
|
|
1393
|
+
return buildTranslationInitializer(translations);
|
|
1394
|
+
}
|
|
1395
|
+
if (nodeType === NodeType.Enumeration) {
|
|
1396
|
+
const map = value[NodeType.Enumeration];
|
|
1397
|
+
return buildEnumerationInitializer(map);
|
|
1398
|
+
}
|
|
1399
|
+
if (nodeType === NodeType.Condition) {
|
|
1400
|
+
const map = value[NodeType.Condition];
|
|
1401
|
+
return buildConditionInitializer(map);
|
|
1402
|
+
}
|
|
1403
|
+
if (nodeType === NodeType.Gender) {
|
|
1404
|
+
const map = value[NodeType.Gender];
|
|
1405
|
+
return buildGenderInitializer(map);
|
|
1406
|
+
}
|
|
1407
|
+
if (nodeType === NodeType.Insertion) {
|
|
1408
|
+
const content = value[NodeType.Insertion];
|
|
1409
|
+
return buildInsertionInitializer(content);
|
|
1410
|
+
}
|
|
1411
|
+
if (nodeType === NodeType.Markdown) {
|
|
1412
|
+
const content = value[NodeType.Markdown];
|
|
1413
|
+
return buildMarkdownInitializer(content);
|
|
1414
|
+
}
|
|
1415
|
+
if (nodeType === NodeType.File) {
|
|
1416
|
+
const path = value[NodeType.File];
|
|
1417
|
+
return buildFileInitializer(path);
|
|
1418
|
+
}
|
|
1419
|
+
if (nodeType === NodeType.Nested) {
|
|
1420
|
+
const content = value[NodeType.Nested];
|
|
1421
|
+
return buildNestedInitializer(content);
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
/**
|
|
1425
|
+
* Gets the existing imports from @intlayer/core in the source file
|
|
1426
|
+
*/
|
|
1427
|
+
const getExistingIntlayerImports = (sourceFile) => {
|
|
1428
|
+
const imported = /* @__PURE__ */ new Set();
|
|
1429
|
+
for (const importDecl of sourceFile.getImportDeclarations()) {
|
|
1430
|
+
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
1431
|
+
if (moduleSpecifier === "intlayer") {
|
|
1432
|
+
const namedImports = importDecl.getNamedImports();
|
|
1433
|
+
for (const namedImport of namedImports) imported.add(namedImport.getName());
|
|
1434
|
+
}
|
|
1435
|
+
if (moduleSpecifier === "intlayer/file") {
|
|
1436
|
+
const namedImports = importDecl.getNamedImports();
|
|
1437
|
+
for (const namedImport of namedImports) {
|
|
1438
|
+
const alias = namedImport.getAliasNode();
|
|
1439
|
+
imported.add(alias ? alias.getText() : namedImport.getName());
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return imported;
|
|
1444
|
+
};
|
|
1445
|
+
/**
|
|
1446
|
+
* Adds missing imports to the source file
|
|
1447
|
+
*/
|
|
1448
|
+
const addMissingImports = (sourceFile, requiredImports) => {
|
|
1449
|
+
if (requiredImports.size === 0) return false;
|
|
1450
|
+
const existingImports = getExistingIntlayerImports(sourceFile);
|
|
1451
|
+
const missingImports = [...requiredImports].filter((imp) => !existingImports.has(imp));
|
|
1452
|
+
if (missingImports.length === 0) return false;
|
|
1453
|
+
const hasMissingFile = missingImports.includes("file");
|
|
1454
|
+
const otherMissingImports = missingImports.filter((imp) => imp !== "file");
|
|
1455
|
+
if (otherMissingImports.length > 0) {
|
|
1456
|
+
const coreImport = sourceFile.getImportDeclarations().find((imp) => imp.getModuleSpecifierValue() === "intlayer");
|
|
1457
|
+
if (coreImport) {
|
|
1458
|
+
const existingNamedImports = coreImport.getNamedImports().map((ni) => ni.getName());
|
|
1459
|
+
const allImports = [...new Set([...existingNamedImports, ...otherMissingImports])].sort();
|
|
1460
|
+
coreImport.removeNamedImports();
|
|
1461
|
+
coreImport.addNamedImports(allImports.map((name) => ({ name })));
|
|
1462
|
+
} else sourceFile.insertImportDeclaration(0, {
|
|
1463
|
+
moduleSpecifier: "intlayer",
|
|
1464
|
+
namedImports: otherMissingImports.sort().map((name) => ({ name }))
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
if (hasMissingFile) {
|
|
1468
|
+
if (!sourceFile.getImportDeclarations().find((imp) => imp.getModuleSpecifierValue() === "intlayer/file")) {
|
|
1469
|
+
const coreImportIndex = sourceFile.getImportDeclarations().findIndex((imp) => imp.getModuleSpecifierValue() === "intlayer");
|
|
1470
|
+
const insertIndex = coreImportIndex >= 0 ? coreImportIndex + 1 : 0;
|
|
1471
|
+
sourceFile.insertImportDeclaration(insertIndex, {
|
|
1472
|
+
moduleSpecifier: "intlayer/file",
|
|
1473
|
+
namedImports: [{ name: "file" }]
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
return true;
|
|
1478
|
+
};
|
|
1479
|
+
/**
|
|
1480
|
+
* Detect whether the current source file is written in CommonJS style.
|
|
1481
|
+
* Prefers ESM when import/export syntax is present; otherwise detects CJS via require/module.exports.
|
|
1482
|
+
*/
|
|
1483
|
+
const isCommonJS = (sourceFile) => {
|
|
1484
|
+
if (sourceFile.getImportDeclarations().length > 0) return false;
|
|
1485
|
+
if (sourceFile.getExportDeclarations().length > 0) return false;
|
|
1486
|
+
if (sourceFile.getExportAssignments().length > 0) return false;
|
|
1487
|
+
for (const statement of sourceFile.getStatements()) {
|
|
1488
|
+
if (!Node.isExpressionStatement(statement)) continue;
|
|
1489
|
+
const expression = statement.getExpression();
|
|
1490
|
+
if (!Node.isBinaryExpression(expression)) continue;
|
|
1491
|
+
const leftSide = expression.getLeft();
|
|
1492
|
+
if (!Node.isPropertyAccessExpression(leftSide)) continue;
|
|
1493
|
+
const leftExpression = leftSide.getExpression();
|
|
1494
|
+
const leftName = leftSide.getName();
|
|
1495
|
+
const isModuleExports = Node.isIdentifier(leftExpression) && leftExpression.getText() === "module" && leftName === "exports";
|
|
1496
|
+
const isExportsDefault = Node.isIdentifier(leftExpression) && leftExpression.getText() === "exports";
|
|
1497
|
+
if (isModuleExports || isExportsDefault) return true;
|
|
1498
|
+
}
|
|
1499
|
+
return sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).some((call) => {
|
|
1500
|
+
const exp = call.getExpression();
|
|
1501
|
+
return Node.isIdentifier(exp) && exp.getText() === "require";
|
|
1502
|
+
});
|
|
1503
|
+
};
|
|
1504
|
+
/**
|
|
1505
|
+
* Adds missing CommonJS requires for intlayer helpers.
|
|
1506
|
+
* - Core helpers (t, md, insert, enu, cond, gender, nest) come from require('intlayer') via destructuring
|
|
1507
|
+
* - file helper comes from require('intlayer/file') via destructuring
|
|
1508
|
+
* Existing destructured requires are respected to avoid duplicates.
|
|
1509
|
+
*/
|
|
1510
|
+
const addMissingRequires = (sourceFile, requiredImports) => {
|
|
1511
|
+
if (requiredImports.size === 0) return false;
|
|
1512
|
+
const existingCoreNames = /* @__PURE__ */ new Set();
|
|
1513
|
+
let hasFileHelper = false;
|
|
1514
|
+
for (const varDecl of sourceFile.getVariableDeclarations()) {
|
|
1515
|
+
const init = varDecl.getInitializer();
|
|
1516
|
+
if (!init || !Node.isCallExpression(init)) continue;
|
|
1517
|
+
const callee = init.getExpression();
|
|
1518
|
+
if (!Node.isIdentifier(callee) || callee.getText() !== "require") continue;
|
|
1519
|
+
const arg = init.getArguments()[0];
|
|
1520
|
+
if (!arg || !Node.isStringLiteral(arg)) continue;
|
|
1521
|
+
const spec = arg.getLiteralValue();
|
|
1522
|
+
const nameNode = varDecl.getNameNode();
|
|
1523
|
+
if (spec === "intlayer") {
|
|
1524
|
+
if (Node.isObjectBindingPattern(nameNode)) for (const el of nameNode.getElements()) existingCoreNames.add(el.getNameNode().getText());
|
|
1525
|
+
}
|
|
1526
|
+
if (spec === "intlayer/file") {
|
|
1527
|
+
if (Node.isObjectBindingPattern(nameNode)) {
|
|
1528
|
+
for (const el of nameNode.getElements()) if (el.getNameNode().getText() === "file") hasFileHelper = true;
|
|
1529
|
+
} else if (Node.isIdentifier(nameNode) && nameNode.getText() === "file") hasFileHelper = true;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
const missingCore = Array.from(requiredImports).filter((n) => n !== "file").filter((n) => !existingCoreNames.has(n));
|
|
1533
|
+
const needsFile = requiredImports.has("file") && !hasFileHelper;
|
|
1534
|
+
if (missingCore.length === 0 && !needsFile) return false;
|
|
1535
|
+
let insertIndex = 0;
|
|
1536
|
+
const statements = sourceFile.getStatements();
|
|
1537
|
+
for (const st of statements) {
|
|
1538
|
+
if (Node.isExpressionStatement(st)) {
|
|
1539
|
+
const expr = st.getExpression();
|
|
1540
|
+
if (Node.isStringLiteral(expr)) {
|
|
1541
|
+
insertIndex += 1;
|
|
1542
|
+
continue;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
break;
|
|
1546
|
+
}
|
|
1547
|
+
const lines = [];
|
|
1548
|
+
if (missingCore.length > 0) {
|
|
1549
|
+
const sorted = Array.from(new Set(missingCore)).sort();
|
|
1550
|
+
lines.push(`const { ${sorted.join(", ")} } = require('intlayer');`);
|
|
1551
|
+
}
|
|
1552
|
+
if (needsFile) lines.push("const { file } = require('intlayer/file');");
|
|
1553
|
+
if (lines.length > 0) {
|
|
1554
|
+
sourceFile.insertStatements(insertIndex, lines.join("\n"));
|
|
1555
|
+
return true;
|
|
1556
|
+
}
|
|
1557
|
+
return false;
|
|
1558
|
+
};
|
|
1559
|
+
/**
|
|
1560
|
+
* Updates dictionary metadata properties (title, description, tags) in the root object
|
|
1561
|
+
*/
|
|
1562
|
+
const updateDictionaryMetadata = (rootObject, dictionary) => {
|
|
1563
|
+
let changed = false;
|
|
1564
|
+
if (dictionary.title !== void 0) {
|
|
1565
|
+
const titleProperty = rootObject.getProperty("title");
|
|
1566
|
+
const titleValue = JSON.stringify(dictionary.title);
|
|
1567
|
+
if (titleProperty && Node.isPropertyAssignment(titleProperty)) {
|
|
1568
|
+
if (titleProperty.getInitializer()?.getText() !== titleValue) {
|
|
1569
|
+
titleProperty.setInitializer(titleValue);
|
|
1570
|
+
changed = true;
|
|
1571
|
+
}
|
|
1572
|
+
} else {
|
|
1573
|
+
rootObject.addPropertyAssignment({
|
|
1574
|
+
name: "title",
|
|
1575
|
+
initializer: titleValue
|
|
1576
|
+
});
|
|
1577
|
+
changed = true;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
if (dictionary.description !== void 0) {
|
|
1581
|
+
const descriptionProperty = rootObject.getProperty("description");
|
|
1582
|
+
const descriptionValue = JSON.stringify(dictionary.description);
|
|
1583
|
+
if (descriptionProperty && Node.isPropertyAssignment(descriptionProperty)) {
|
|
1584
|
+
if (descriptionProperty.getInitializer()?.getText() !== descriptionValue) {
|
|
1585
|
+
descriptionProperty.setInitializer(descriptionValue);
|
|
1586
|
+
changed = true;
|
|
1587
|
+
}
|
|
1588
|
+
} else {
|
|
1589
|
+
rootObject.addPropertyAssignment({
|
|
1590
|
+
name: "description",
|
|
1591
|
+
initializer: descriptionValue
|
|
1592
|
+
});
|
|
1593
|
+
changed = true;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
if (dictionary.tags !== void 0) {
|
|
1597
|
+
const tagsProperty = rootObject.getProperty("tags");
|
|
1598
|
+
const tagsValue = `[${dictionary.tags.map((tag) => JSON.stringify(tag)).join(", ")}]`;
|
|
1599
|
+
if (tagsProperty && Node.isPropertyAssignment(tagsProperty)) {
|
|
1600
|
+
if (tagsProperty.getInitializer()?.getText() !== tagsValue) {
|
|
1601
|
+
tagsProperty.setInitializer(tagsValue);
|
|
1602
|
+
changed = true;
|
|
1603
|
+
}
|
|
1604
|
+
} else {
|
|
1605
|
+
rootObject.addPropertyAssignment({
|
|
1606
|
+
name: "tags",
|
|
1607
|
+
initializer: tagsValue
|
|
1608
|
+
});
|
|
1609
|
+
changed = true;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return changed;
|
|
1613
|
+
};
|
|
1614
|
+
/**
|
|
1615
|
+
* Locates the root dictionary object in the source file
|
|
1616
|
+
*/
|
|
1617
|
+
const findRootDictionaryObject = (sourceFile) => {
|
|
1618
|
+
const exportAssignment = sourceFile.getExportAssignment((_) => true);
|
|
1619
|
+
if (exportAssignment) {
|
|
1620
|
+
const expression = exportAssignment.getExpression();
|
|
1621
|
+
if (Node.isIdentifier(expression)) {
|
|
1622
|
+
const declarationByName = expression.getSymbol()?.getDeclarations()?.[0] ?? sourceFile.getVariableDeclaration(expression.getText());
|
|
1623
|
+
if (declarationByName && Node.isVariableDeclaration(declarationByName)) {
|
|
1624
|
+
const objectLiteral = unwrapToObjectLiteral(declarationByName.getInitializer());
|
|
1625
|
+
if (objectLiteral) return objectLiteral;
|
|
1626
|
+
}
|
|
1627
|
+
} else {
|
|
1628
|
+
const objectLiteral = unwrapToObjectLiteral(expression);
|
|
1629
|
+
if (objectLiteral) return objectLiteral;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
const variableDeclaration = sourceFile.getVariableDeclaration((variable) => {
|
|
1633
|
+
try {
|
|
1634
|
+
return variable.getType().getText().includes("Dictionary") || variable.getName() === "content" || variable.getName().toLowerCase().includes("dictionary");
|
|
1635
|
+
} catch {
|
|
1636
|
+
return variable.getName() === "content";
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
if (variableDeclaration) {
|
|
1640
|
+
const objectLiteral = unwrapToObjectLiteral(variableDeclaration.getInitializer());
|
|
1641
|
+
if (objectLiteral) return objectLiteral;
|
|
1642
|
+
}
|
|
1643
|
+
for (const statement of sourceFile.getStatements()) {
|
|
1644
|
+
if (!Node.isExpressionStatement(statement)) continue;
|
|
1645
|
+
const expression = statement.getExpression();
|
|
1646
|
+
if (!Node.isBinaryExpression(expression)) continue;
|
|
1647
|
+
if (expression.getOperatorToken().getText() !== "=") continue;
|
|
1648
|
+
const leftSide = expression.getLeft();
|
|
1649
|
+
if (!Node.isPropertyAccessExpression(leftSide)) continue;
|
|
1650
|
+
const leftExpression = leftSide.getExpression();
|
|
1651
|
+
const leftName = leftSide.getName();
|
|
1652
|
+
const isModuleExports = Node.isIdentifier(leftExpression) && leftExpression.getText() === "module" && leftName === "exports";
|
|
1653
|
+
const isExportsDefault = Node.isIdentifier(leftExpression) && leftExpression.getText() === "exports" && leftName === "default";
|
|
1654
|
+
if (!isModuleExports && !isExportsDefault) continue;
|
|
1655
|
+
const rightSide = expression.getRight();
|
|
1656
|
+
if (Node.isObjectLiteralExpression(rightSide)) return rightSide;
|
|
1657
|
+
if (Node.isIdentifier(rightSide)) {
|
|
1658
|
+
const declaration = rightSide.getSymbol()?.getDeclarations()?.[0];
|
|
1659
|
+
if (declaration && Node.isVariableDeclaration(declaration)) {
|
|
1660
|
+
const objectLiteral = unwrapToObjectLiteral(declaration.getInitializer());
|
|
1661
|
+
if (objectLiteral) return objectLiteral;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
/**
|
|
1667
|
+
* Updates a JavaScript/TypeScript file based on the provided dictionary.
|
|
1668
|
+
* It targets a specific dictionary object within the file and updates its
|
|
1669
|
+
* metadata (title, description, tags) and content entries.
|
|
1670
|
+
*
|
|
1671
|
+
* This function now supports inserting translation keys into nested objects
|
|
1672
|
+
* within arrays. For example, if you have:
|
|
1673
|
+
* ```
|
|
1674
|
+
* content: [
|
|
1675
|
+
* { question: t({ en: '...', fr: '...' }) }
|
|
1676
|
+
* ]
|
|
1677
|
+
* ```
|
|
1678
|
+
*
|
|
1679
|
+
* You can add a new locale (e.g., 'pl') by providing a dictionary with:
|
|
1680
|
+
* ```
|
|
1681
|
+
* {
|
|
1682
|
+
* content: [
|
|
1683
|
+
* { question: { [NodeType.Translation]: { en: '...', fr: '...', pl: '...' } } }
|
|
1684
|
+
* ]
|
|
1685
|
+
* }
|
|
1686
|
+
* ```
|
|
1687
|
+
*
|
|
1688
|
+
* The function will:
|
|
1689
|
+
* 1. Detect the existing array structure
|
|
1690
|
+
* 2. Navigate into each array element (if it's an object)
|
|
1691
|
+
* 3. Recursively process nested properties
|
|
1692
|
+
* 4. Update translation maps while preserving existing locales
|
|
1693
|
+
*/
|
|
1694
|
+
const transformJSFile = async (fileContent, dictionary, fallbackLocale) => {
|
|
1695
|
+
try {
|
|
1696
|
+
if (!dictionary || typeof dictionary !== "object") return fileContent;
|
|
1697
|
+
const sourceFile = new Project({
|
|
1698
|
+
useInMemoryFileSystem: true,
|
|
1699
|
+
skipAddingFilesFromTsConfig: true,
|
|
1700
|
+
skipFileDependencyResolution: true,
|
|
1701
|
+
compilerOptions: {
|
|
1702
|
+
allowJs: true,
|
|
1703
|
+
jsx: ts.JsxEmit.Preserve
|
|
1704
|
+
},
|
|
1705
|
+
manipulationSettings: {
|
|
1706
|
+
indentationText: IndentationText.TwoSpaces,
|
|
1707
|
+
quoteKind: QuoteKind.Double,
|
|
1708
|
+
newLineKind: NewLineKind.LineFeed
|
|
1709
|
+
}
|
|
1710
|
+
}).createSourceFile("file.tsx", fileContent, { overwrite: true });
|
|
1711
|
+
const rootObject = findRootDictionaryObject(sourceFile);
|
|
1712
|
+
if (!rootObject) return fileContent;
|
|
1713
|
+
let changed = false;
|
|
1714
|
+
const requiredImports = /* @__PURE__ */ new Set();
|
|
1715
|
+
if (updateDictionaryMetadata(rootObject, dictionary)) changed = true;
|
|
1716
|
+
if (dictionary.content) {
|
|
1717
|
+
const contentProperty = rootObject.getProperty("content");
|
|
1718
|
+
let contentObject;
|
|
1719
|
+
let isContentArrayInSource = false;
|
|
1720
|
+
if (contentProperty && Node.isPropertyAssignment(contentProperty)) {
|
|
1721
|
+
contentObject = contentProperty.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);
|
|
1722
|
+
isContentArrayInSource = !!contentProperty.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression);
|
|
1723
|
+
}
|
|
1724
|
+
const effectiveFallbackLocale = fallbackLocale ?? "en";
|
|
1725
|
+
if (contentObject && !Array.isArray(dictionary.content)) {
|
|
1726
|
+
const dictContent = dictionary.content ?? {};
|
|
1727
|
+
if (processContentEntries(contentObject, dictContent, effectiveFallbackLocale, requiredImports, sourceFile)) changed = true;
|
|
1728
|
+
} else if (Array.isArray(dictionary.content) && isContentArrayInSource) {
|
|
1729
|
+
if (processArrayContent(rootObject, "content", dictionary.content ?? [], getExistingPropertyNames(rootObject), effectiveFallbackLocale, requiredImports, sourceFile)) changed = true;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (!changed) return fileContent;
|
|
1733
|
+
if ((isCommonJS(sourceFile) ? addMissingRequires(sourceFile, requiredImports) : addMissingImports(sourceFile, requiredImports)) || changed) return sourceFile.getFullText();
|
|
1734
|
+
return fileContent;
|
|
1735
|
+
} catch {
|
|
1736
|
+
return fileContent;
|
|
1737
|
+
}
|
|
750
1738
|
};
|
|
1739
|
+
|
|
1740
|
+
//#endregion
|
|
1741
|
+
export { transformJSFile };
|
|
751
1742
|
//# sourceMappingURL=transformJSFile.mjs.map
|