@intlayer/chokidar 8.1.2 → 8.1.3

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.
Files changed (396) hide show
  1. package/dist/assets/installSkills/skills/angular.md +3 -0
  2. package/dist/assets/installSkills/skills/astro.md +3 -0
  3. package/dist/assets/installSkills/skills/cli.md +7 -4
  4. package/dist/assets/installSkills/skills/config.md +3 -0
  5. package/dist/assets/installSkills/skills/content.md +3 -0
  6. package/dist/assets/installSkills/skills/next_js.md +3 -0
  7. package/dist/assets/installSkills/skills/preact.md +3 -2
  8. package/dist/assets/installSkills/skills/react.md +3 -0
  9. package/dist/assets/installSkills/skills/solid.md +3 -0
  10. package/dist/assets/installSkills/skills/svelte.md +3 -0
  11. package/dist/assets/installSkills/skills/usage.md +2 -0
  12. package/dist/assets/installSkills/skills/vue.md +3 -0
  13. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
  14. package/dist/cjs/_virtual/_utils_asset.cjs +2 -98
  15. package/dist/cjs/build.cjs +1 -51
  16. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +1 -53
  17. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
  18. package/dist/cjs/buildIntlayerDictionary/index.cjs +1 -6
  19. package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs +1 -26
  20. package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs.map +1 -1
  21. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +4 -78
  22. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
  23. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +4 -62
  24. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -1
  25. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +1 -46
  26. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs.map +1 -1
  27. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +1 -50
  28. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs.map +1 -1
  29. package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +1 -59
  30. package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs.map +1 -1
  31. package/dist/cjs/cleanOutputDir.cjs +1 -30
  32. package/dist/cjs/cleanOutputDir.cjs.map +1 -1
  33. package/dist/cjs/cleanRemovedContentDeclaration.cjs +1 -96
  34. package/dist/cjs/cleanRemovedContentDeclaration.cjs.map +1 -1
  35. package/dist/cjs/cli.cjs +1 -21
  36. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +1 -70
  37. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs.map +1 -1
  38. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs +7 -41
  39. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
  40. package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs +1 -23
  41. package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs.map +1 -1
  42. package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs +1 -24
  43. package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs.map +1 -1
  44. package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs +1 -24
  45. package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs.map +1 -1
  46. package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs +1 -23
  47. package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs.map +1 -1
  48. package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs +1 -23
  49. package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs.map +1 -1
  50. package/dist/cjs/createDictionaryEntryPoint/index.cjs +1 -16
  51. package/dist/cjs/createType/createModuleAugmentation.cjs +9 -110
  52. package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
  53. package/dist/cjs/createType/createType.cjs +1 -29
  54. package/dist/cjs/createType/createType.cjs.map +1 -1
  55. package/dist/cjs/createType/index.cjs +1 -8
  56. package/dist/cjs/fetchDistantDictionaries.cjs +1 -50
  57. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  58. package/dist/cjs/filterInvalidDictionaries.cjs +1 -49
  59. package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -1
  60. package/dist/cjs/formatDictionary.cjs +1 -49
  61. package/dist/cjs/formatDictionary.cjs.map +1 -1
  62. package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +1 -39
  63. package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -1
  64. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +1 -34
  65. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs.map +1 -1
  66. package/dist/cjs/handleContentDeclarationFileChange.cjs +1 -49
  67. package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
  68. package/dist/cjs/handleContentDeclarationFileMoved.cjs +1 -24
  69. package/dist/cjs/handleContentDeclarationFileMoved.cjs.map +1 -1
  70. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +1 -37
  71. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs.map +1 -1
  72. package/dist/cjs/index.cjs +1 -131
  73. package/dist/cjs/init/index.cjs +1 -242
  74. package/dist/cjs/init/index.cjs.map +1 -1
  75. package/dist/cjs/init/utils/configManipulation.cjs +1 -164
  76. package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
  77. package/dist/cjs/init/utils/fileSystem.cjs +1 -30
  78. package/dist/cjs/init/utils/fileSystem.cjs.map +1 -1
  79. package/dist/cjs/init/utils/index.cjs +1 -13
  80. package/dist/cjs/init/utils/jsonParser.cjs +3 -42
  81. package/dist/cjs/init/utils/jsonParser.cjs.map +1 -1
  82. package/dist/cjs/init/utils/tsConfig.cjs +1 -18
  83. package/dist/cjs/init/utils/tsConfig.cjs.map +1 -1
  84. package/dist/cjs/initConfig/index.cjs +1 -38
  85. package/dist/cjs/initConfig/index.cjs.map +1 -1
  86. package/dist/cjs/installSkills/index.cjs +1 -172
  87. package/dist/cjs/installSkills/index.cjs.map +1 -1
  88. package/dist/cjs/listDictionariesPath.cjs +1 -41
  89. package/dist/cjs/listDictionariesPath.cjs.map +1 -1
  90. package/dist/cjs/listGitFiles.cjs +5 -95
  91. package/dist/cjs/listGitFiles.cjs.map +1 -1
  92. package/dist/cjs/listProjects.cjs +1 -47
  93. package/dist/cjs/listProjects.cjs.map +1 -1
  94. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +1 -66
  95. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs.map +1 -1
  96. package/dist/cjs/loadDictionaries/index.cjs +1 -12
  97. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +2 -72
  98. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
  99. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +1 -125
  100. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  101. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +1 -28
  102. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
  103. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +1 -61
  104. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
  105. package/dist/cjs/loadDictionaries/log.cjs +3 -135
  106. package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
  107. package/dist/cjs/prepareIntlayer.cjs +1 -95
  108. package/dist/cjs/prepareIntlayer.cjs.map +1 -1
  109. package/dist/cjs/reduceDictionaryContent/applyMask.cjs +1 -30
  110. package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -1
  111. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +1 -12
  112. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -1
  113. package/dist/cjs/transformFiles/extractDictionaryKey.cjs +1 -16
  114. package/dist/cjs/transformFiles/extractDictionaryKey.cjs.map +1 -1
  115. package/dist/cjs/transformFiles/index.cjs +1 -10
  116. package/dist/cjs/transformFiles/transformFiles.cjs +1 -251
  117. package/dist/cjs/transformFiles/transformFiles.cjs.map +1 -1
  118. package/dist/cjs/utils/autoDecorateContent.cjs +1 -87
  119. package/dist/cjs/utils/autoDecorateContent.cjs.map +1 -1
  120. package/dist/cjs/utils/buildFilesList.cjs +1 -50
  121. package/dist/cjs/utils/buildFilesList.cjs.map +1 -1
  122. package/dist/cjs/utils/chunkJSON.cjs +1 -336
  123. package/dist/cjs/utils/chunkJSON.cjs.map +1 -1
  124. package/dist/cjs/utils/formatter.cjs +1 -16
  125. package/dist/cjs/utils/formatter.cjs.map +1 -1
  126. package/dist/cjs/utils/getChunk.cjs +1 -34
  127. package/dist/cjs/utils/getChunk.cjs.map +1 -1
  128. package/dist/cjs/utils/getComponentTransformPattern.cjs +1 -48
  129. package/dist/cjs/utils/getComponentTransformPattern.cjs.map +1 -1
  130. package/dist/cjs/utils/getFileHash.cjs +1 -12
  131. package/dist/cjs/utils/getFileHash.cjs.map +1 -1
  132. package/dist/cjs/utils/getFormatFromExtension.cjs +1 -31
  133. package/dist/cjs/utils/getFormatFromExtension.cjs.map +1 -1
  134. package/dist/cjs/utils/index.cjs +1 -46
  135. package/dist/cjs/utils/pLimit.cjs +1 -128
  136. package/dist/cjs/utils/pLimit.cjs.map +1 -1
  137. package/dist/cjs/utils/parallelize.cjs +1 -11
  138. package/dist/cjs/utils/parallelize.cjs.map +1 -1
  139. package/dist/cjs/utils/parallelizeGlobal.cjs +1 -29
  140. package/dist/cjs/utils/parallelizeGlobal.cjs.map +1 -1
  141. package/dist/cjs/utils/reduceObjectFormat.cjs +1 -31
  142. package/dist/cjs/utils/reduceObjectFormat.cjs.map +1 -1
  143. package/dist/cjs/utils/resolveObjectPromises.cjs +1 -21
  144. package/dist/cjs/utils/resolveObjectPromises.cjs.map +1 -1
  145. package/dist/cjs/utils/runOnce.cjs +1 -95
  146. package/dist/cjs/utils/runOnce.cjs.map +1 -1
  147. package/dist/cjs/utils/runParallel/bin.cjs +1 -54
  148. package/dist/cjs/utils/runParallel/bin.cjs.map +1 -1
  149. package/dist/cjs/utils/runParallel/bootstrap.cjs +1 -24
  150. package/dist/cjs/utils/runParallel/bootstrap.cjs.map +1 -1
  151. package/dist/cjs/utils/runParallel/index.cjs +1 -110
  152. package/dist/cjs/utils/runParallel/index.cjs.map +1 -1
  153. package/dist/cjs/utils/runParallel/pidTree.cjs +1 -145
  154. package/dist/cjs/utils/runParallel/pidTree.cjs.map +1 -1
  155. package/dist/cjs/utils/runParallel/ps.cjs +1 -49
  156. package/dist/cjs/utils/runParallel/ps.cjs.map +1 -1
  157. package/dist/cjs/utils/runParallel/runTask.cjs +1 -154
  158. package/dist/cjs/utils/runParallel/runTask.cjs.map +1 -1
  159. package/dist/cjs/utils/runParallel/spawnPosix.cjs +1 -59
  160. package/dist/cjs/utils/runParallel/spawnPosix.cjs.map +1 -1
  161. package/dist/cjs/utils/runParallel/spawnWin32.cjs +1 -43
  162. package/dist/cjs/utils/runParallel/spawnWin32.cjs.map +1 -1
  163. package/dist/cjs/utils/runParallel/wmic.cjs +1 -52
  164. package/dist/cjs/utils/runParallel/wmic.cjs.map +1 -1
  165. package/dist/cjs/utils/sortAlphabetically.cjs +1 -7
  166. package/dist/cjs/utils/sortAlphabetically.cjs.map +1 -1
  167. package/dist/cjs/utils/splitTextByLine.cjs +1 -11
  168. package/dist/cjs/utils/splitTextByLine.cjs.map +1 -1
  169. package/dist/cjs/utils/verifyIdenticObjectFormat.cjs +1 -60
  170. package/dist/cjs/utils/verifyIdenticObjectFormat.cjs.map +1 -1
  171. package/dist/cjs/watcher.cjs +1 -95
  172. package/dist/cjs/watcher.cjs.map +1 -1
  173. package/dist/cjs/writeConfiguration/index.cjs +1 -34
  174. package/dist/cjs/writeConfiguration/index.cjs.map +1 -1
  175. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs +1 -28
  176. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs.map +1 -1
  177. package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs +1 -31
  178. package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs.map +1 -1
  179. package/dist/cjs/writeContentDeclaration/index.cjs +1 -12
  180. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +1 -93
  181. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -1
  182. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +2 -1775
  183. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
  184. package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs +1 -77
  185. package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs.map +1 -1
  186. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +1 -123
  187. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  188. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +1 -71
  189. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  190. package/dist/cjs/writeFileIfChanged.cjs +1 -12
  191. package/dist/cjs/writeFileIfChanged.cjs.map +1 -1
  192. package/dist/cjs/writeJsonIfChanged.cjs +1 -17
  193. package/dist/cjs/writeJsonIfChanged.cjs.map +1 -1
  194. package/dist/esm/_virtual/_rolldown/runtime.mjs +1 -8
  195. package/dist/esm/_virtual/_utils_asset.mjs +2 -97
  196. package/dist/esm/build.mjs +1 -24
  197. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +1 -51
  198. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
  199. package/dist/esm/buildIntlayerDictionary/index.mjs +1 -4
  200. package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs +1 -24
  201. package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs.map +1 -1
  202. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +4 -75
  203. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
  204. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +4 -59
  205. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -1
  206. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +1 -44
  207. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs.map +1 -1
  208. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +1 -48
  209. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs.map +1 -1
  210. package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +1 -56
  211. package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs.map +1 -1
  212. package/dist/esm/cleanOutputDir.mjs +1 -28
  213. package/dist/esm/cleanOutputDir.mjs.map +1 -1
  214. package/dist/esm/cleanRemovedContentDeclaration.mjs +1 -93
  215. package/dist/esm/cleanRemovedContentDeclaration.mjs.map +1 -1
  216. package/dist/esm/cli.mjs +1 -8
  217. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +1 -68
  218. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs.map +1 -1
  219. package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs +7 -39
  220. package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -1
  221. package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs +1 -20
  222. package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs.map +1 -1
  223. package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs +1 -21
  224. package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs.map +1 -1
  225. package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs +1 -21
  226. package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs.map +1 -1
  227. package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs +1 -20
  228. package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs.map +1 -1
  229. package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs +1 -20
  230. package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs.map +1 -1
  231. package/dist/esm/createDictionaryEntryPoint/index.mjs +1 -9
  232. package/dist/esm/createType/createModuleAugmentation.mjs +9 -106
  233. package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
  234. package/dist/esm/createType/createType.mjs +1 -26
  235. package/dist/esm/createType/createType.mjs.map +1 -1
  236. package/dist/esm/createType/index.mjs +1 -4
  237. package/dist/esm/fetchDistantDictionaries.mjs +1 -48
  238. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  239. package/dist/esm/filterInvalidDictionaries.mjs +1 -46
  240. package/dist/esm/filterInvalidDictionaries.mjs.map +1 -1
  241. package/dist/esm/formatDictionary.mjs +1 -44
  242. package/dist/esm/formatDictionary.mjs.map +1 -1
  243. package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +1 -37
  244. package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -1
  245. package/dist/esm/handleAdditionalContentDeclarationFile.mjs +1 -32
  246. package/dist/esm/handleAdditionalContentDeclarationFile.mjs.map +1 -1
  247. package/dist/esm/handleContentDeclarationFileChange.mjs +1 -47
  248. package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
  249. package/dist/esm/handleContentDeclarationFileMoved.mjs +1 -22
  250. package/dist/esm/handleContentDeclarationFileMoved.mjs.map +1 -1
  251. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +1 -35
  252. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs.map +1 -1
  253. package/dist/esm/index.mjs +1 -57
  254. package/dist/esm/init/index.mjs +1 -240
  255. package/dist/esm/init/index.mjs.map +1 -1
  256. package/dist/esm/init/utils/configManipulation.mjs +1 -161
  257. package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
  258. package/dist/esm/init/utils/fileSystem.mjs +1 -26
  259. package/dist/esm/init/utils/fileSystem.mjs.map +1 -1
  260. package/dist/esm/init/utils/index.mjs +1 -6
  261. package/dist/esm/init/utils/jsonParser.mjs +3 -40
  262. package/dist/esm/init/utils/jsonParser.mjs.map +1 -1
  263. package/dist/esm/init/utils/tsConfig.mjs +1 -16
  264. package/dist/esm/init/utils/tsConfig.mjs.map +1 -1
  265. package/dist/esm/initConfig/index.mjs +1 -36
  266. package/dist/esm/initConfig/index.mjs.map +1 -1
  267. package/dist/esm/installSkills/index.mjs +1 -167
  268. package/dist/esm/installSkills/index.mjs.map +1 -1
  269. package/dist/esm/listDictionariesPath.mjs +1 -37
  270. package/dist/esm/listDictionariesPath.mjs.map +1 -1
  271. package/dist/esm/listGitFiles.mjs +5 -90
  272. package/dist/esm/listGitFiles.mjs.map +1 -1
  273. package/dist/esm/listProjects.mjs +1 -43
  274. package/dist/esm/listProjects.mjs.map +1 -1
  275. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +1 -65
  276. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs.map +1 -1
  277. package/dist/esm/loadDictionaries/index.mjs +1 -6
  278. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +2 -69
  279. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  280. package/dist/esm/loadDictionaries/loadDictionaries.mjs +1 -123
  281. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  282. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +1 -26
  283. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
  284. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +1 -58
  285. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
  286. package/dist/esm/loadDictionaries/log.mjs +3 -132
  287. package/dist/esm/loadDictionaries/log.mjs.map +1 -1
  288. package/dist/esm/prepareIntlayer.mjs +1 -92
  289. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  290. package/dist/esm/reduceDictionaryContent/applyMask.mjs +1 -28
  291. package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -1
  292. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +1 -10
  293. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -1
  294. package/dist/esm/transformFiles/extractDictionaryKey.mjs +1 -14
  295. package/dist/esm/transformFiles/extractDictionaryKey.mjs.map +1 -1
  296. package/dist/esm/transformFiles/index.mjs +1 -4
  297. package/dist/esm/transformFiles/transformFiles.mjs +1 -244
  298. package/dist/esm/transformFiles/transformFiles.mjs.map +1 -1
  299. package/dist/esm/utils/autoDecorateContent.mjs +1 -85
  300. package/dist/esm/utils/autoDecorateContent.mjs.map +1 -1
  301. package/dist/esm/utils/buildFilesList.mjs +1 -47
  302. package/dist/esm/utils/buildFilesList.mjs.map +1 -1
  303. package/dist/esm/utils/chunkJSON.mjs +1 -333
  304. package/dist/esm/utils/chunkJSON.mjs.map +1 -1
  305. package/dist/esm/utils/formatter.mjs +1 -12
  306. package/dist/esm/utils/formatter.mjs.map +1 -1
  307. package/dist/esm/utils/getChunk.mjs +1 -33
  308. package/dist/esm/utils/getChunk.mjs.map +1 -1
  309. package/dist/esm/utils/getComponentTransformPattern.mjs +1 -44
  310. package/dist/esm/utils/getComponentTransformPattern.mjs.map +1 -1
  311. package/dist/esm/utils/getFileHash.mjs +1 -9
  312. package/dist/esm/utils/getFileHash.mjs.map +1 -1
  313. package/dist/esm/utils/getFormatFromExtension.mjs +1 -28
  314. package/dist/esm/utils/getFormatFromExtension.mjs.map +1 -1
  315. package/dist/esm/utils/index.mjs +1 -20
  316. package/dist/esm/utils/pLimit.mjs +1 -125
  317. package/dist/esm/utils/pLimit.mjs.map +1 -1
  318. package/dist/esm/utils/parallelize.mjs +1 -10
  319. package/dist/esm/utils/parallelize.mjs.map +1 -1
  320. package/dist/esm/utils/parallelizeGlobal.mjs +1 -26
  321. package/dist/esm/utils/parallelizeGlobal.mjs.map +1 -1
  322. package/dist/esm/utils/reduceObjectFormat.mjs +1 -29
  323. package/dist/esm/utils/reduceObjectFormat.mjs.map +1 -1
  324. package/dist/esm/utils/resolveObjectPromises.mjs +1 -19
  325. package/dist/esm/utils/resolveObjectPromises.mjs.map +1 -1
  326. package/dist/esm/utils/runOnce.mjs +1 -92
  327. package/dist/esm/utils/runOnce.mjs.map +1 -1
  328. package/dist/esm/utils/runParallel/bin.mjs +1 -52
  329. package/dist/esm/utils/runParallel/bin.mjs.map +1 -1
  330. package/dist/esm/utils/runParallel/bootstrap.mjs +1 -22
  331. package/dist/esm/utils/runParallel/bootstrap.mjs.map +1 -1
  332. package/dist/esm/utils/runParallel/index.mjs +1 -108
  333. package/dist/esm/utils/runParallel/index.mjs.map +1 -1
  334. package/dist/esm/utils/runParallel/pidTree.mjs +1 -142
  335. package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -1
  336. package/dist/esm/utils/runParallel/ps.mjs +1 -46
  337. package/dist/esm/utils/runParallel/ps.mjs.map +1 -1
  338. package/dist/esm/utils/runParallel/runTask.mjs +1 -152
  339. package/dist/esm/utils/runParallel/runTask.mjs.map +1 -1
  340. package/dist/esm/utils/runParallel/spawnPosix.mjs +1 -57
  341. package/dist/esm/utils/runParallel/spawnPosix.mjs.map +1 -1
  342. package/dist/esm/utils/runParallel/spawnWin32.mjs +1 -41
  343. package/dist/esm/utils/runParallel/spawnWin32.mjs.map +1 -1
  344. package/dist/esm/utils/runParallel/wmic.mjs +1 -49
  345. package/dist/esm/utils/runParallel/wmic.mjs.map +1 -1
  346. package/dist/esm/utils/sortAlphabetically.mjs +1 -5
  347. package/dist/esm/utils/sortAlphabetically.mjs.map +1 -1
  348. package/dist/esm/utils/splitTextByLine.mjs +1 -9
  349. package/dist/esm/utils/splitTextByLine.mjs.map +1 -1
  350. package/dist/esm/utils/verifyIdenticObjectFormat.mjs +1 -58
  351. package/dist/esm/utils/verifyIdenticObjectFormat.mjs.map +1 -1
  352. package/dist/esm/watcher.mjs +1 -92
  353. package/dist/esm/watcher.mjs.map +1 -1
  354. package/dist/esm/writeConfiguration/index.mjs +1 -31
  355. package/dist/esm/writeConfiguration/index.mjs.map +1 -1
  356. package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs +1 -26
  357. package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs.map +1 -1
  358. package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs +1 -29
  359. package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs.map +1 -1
  360. package/dist/esm/writeContentDeclaration/index.mjs +1 -7
  361. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +1 -91
  362. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -1
  363. package/dist/esm/writeContentDeclaration/transformJSFile.mjs +2 -1773
  364. package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
  365. package/dist/esm/writeContentDeclaration/transformJSONFile.mjs +1 -75
  366. package/dist/esm/writeContentDeclaration/transformJSONFile.mjs.map +1 -1
  367. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +1 -121
  368. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  369. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +1 -69
  370. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  371. package/dist/esm/writeFileIfChanged.mjs +1 -10
  372. package/dist/esm/writeFileIfChanged.mjs.map +1 -1
  373. package/dist/esm/writeJsonIfChanged.mjs +1 -16
  374. package/dist/esm/writeJsonIfChanged.mjs.map +1 -1
  375. package/dist/types/build.d.ts +3 -1
  376. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
  377. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
  378. package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
  379. package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
  380. package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
  381. package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts.map +1 -1
  382. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  383. package/dist/types/index.d.ts +16 -24
  384. package/dist/types/initConfig/index.d.ts +1 -1
  385. package/dist/types/initConfig/index.d.ts.map +1 -1
  386. package/dist/types/listGitFiles.d.ts.map +1 -1
  387. package/dist/types/loadDictionaries/getIntlayerBundle.d.ts.map +1 -1
  388. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
  389. package/dist/types/prepareIntlayer.d.ts.map +1 -1
  390. package/dist/types/transformFiles/transformFiles.d.ts +1 -1
  391. package/dist/types/transformFiles/transformFiles.d.ts.map +1 -1
  392. package/dist/types/utils/formatter.d.ts +1 -1
  393. package/dist/types/watcher.d.ts +1 -1
  394. package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts.map +1 -1
  395. package/dist/types/writeContentDeclaration/transformJSFile.d.ts.map +1 -1
  396. package/package.json +10 -15
@@ -1,78 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let ts_morph = require("ts-morph");
4
-
5
- //#region src/writeContentDeclaration/transformJSONFile.ts
6
- /**
7
- * Checks if a value is a plain object (and not null/array)
8
- */
9
- const isPlainObject = (value) => {
10
- return typeof value === "object" && value !== null && !Array.isArray(value);
11
- };
12
- /**
13
- * Safely formats a key for use in object literals.
14
- * Always quotes keys to ensure compatibility with standard JSON files.
15
- */
16
- const stringifyKey = (objectKey) => {
17
- return JSON.stringify(objectKey);
18
- };
19
- /**
20
- * Robustly finds a property in an ObjectLiteralExpression.
21
- * Handles cases where the property name in the source file is quoted ("key") or unquoted (key).
22
- */
23
- const getMatchingProperty = (node, key) => {
24
- return node.getProperties().find((prop) => {
25
- if (ts_morph.Node.isPropertyAssignment(prop)) {
26
- const propName = prop.getName();
27
- return propName === key || propName === `"${key}"` || propName === `'${key}'`;
28
- }
29
- return false;
30
- });
31
- };
32
- /**
33
- * Recursively updates the AST object literal with new data.
34
- */
35
- const updateObjectLiteral = (node, data) => {
36
- for (const [key, val] of Object.entries(data)) {
37
- if (val === void 0) continue;
38
- const stringifiedValue = JSON.stringify(val, null, 2);
39
- if (stringifiedValue === void 0 && !isPlainObject(val)) continue;
40
- const existingProp = getMatchingProperty(node, key);
41
- if (isPlainObject(val)) if (existingProp && ts_morph.Node.isPropertyAssignment(existingProp)) {
42
- const initializer = existingProp.getInitializer();
43
- if (ts_morph.Node.isObjectLiteralExpression(initializer)) updateObjectLiteral(initializer, val);
44
- else existingProp.setInitializer(stringifiedValue);
45
- } else if (existingProp) existingProp.replaceWithText(`${stringifyKey(key)}: ${stringifiedValue}`);
46
- else node.addPropertyAssignment({
47
- name: stringifyKey(key),
48
- initializer: stringifiedValue
49
- });
50
- else if (existingProp && ts_morph.Node.isPropertyAssignment(existingProp)) existingProp.setInitializer(stringifiedValue);
51
- else if (existingProp) existingProp.replaceWithText(`${stringifyKey(key)}: ${stringifiedValue}`);
52
- else node.addPropertyAssignment({
53
- name: stringifyKey(key),
54
- initializer: stringifiedValue
55
- });
56
- }
57
- };
58
- const transformJSONFile = (fileContent, dictionary) => {
59
- const project = new ts_morph.Project({
60
- useInMemoryFileSystem: true,
61
- manipulationSettings: {
62
- indentationText: ts_morph.IndentationText.TwoSpaces,
63
- quoteKind: ts_morph.QuoteKind.Double
64
- }
65
- });
66
- const dummyFileName = "temp.ts";
67
- const wrappedContent = `const _config = ${fileContent.trim() || "{}"}`;
68
- const sourceFile = project.createSourceFile(dummyFileName, wrappedContent);
69
- const objectLiteral = sourceFile.getVariableDeclaration("_config")?.getInitializerIfKind(ts_morph.SyntaxKind.ObjectLiteralExpression);
70
- if (!objectLiteral) return JSON.stringify(dictionary, null, 2);
71
- updateObjectLiteral(objectLiteral, dictionary);
72
- sourceFile.formatText();
73
- return objectLiteral.getText();
74
- };
75
-
76
- //#endregion
77
- exports.transformJSONFile = transformJSONFile;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`ts-morph`);const t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=e=>JSON.stringify(e),r=(t,n)=>t.getProperties().find(t=>{if(e.Node.isPropertyAssignment(t)){let e=t.getName();return e===n||e===`"${n}"`||e===`'${n}'`}return!1}),i=(a,o)=>{for(let[s,c]of Object.entries(o)){if(c===void 0)continue;let o=JSON.stringify(c,null,2);if(o===void 0&&!t(c))continue;let l=r(a,s);if(t(c))if(l&&e.Node.isPropertyAssignment(l)){let t=l.getInitializer();e.Node.isObjectLiteralExpression(t)?i(t,c):l.setInitializer(o)}else l?l.replaceWithText(`${n(s)}: ${o}`):a.addPropertyAssignment({name:n(s),initializer:o});else l&&e.Node.isPropertyAssignment(l)?l.setInitializer(o):l?l.replaceWithText(`${n(s)}: ${o}`):a.addPropertyAssignment({name:n(s),initializer:o})}},a=(t,n)=>{let r=new e.Project({useInMemoryFileSystem:!0,manipulationSettings:{indentationText:e.IndentationText.TwoSpaces,quoteKind:e.QuoteKind.Double}}),a=`const _config = ${t.trim()||`{}`}`,o=r.createSourceFile(`temp.ts`,a),s=o.getVariableDeclaration(`_config`)?.getInitializerIfKind(e.SyntaxKind.ObjectLiteralExpression);return s?(i(s,n),o.formatText(),s.getText()):JSON.stringify(n,null,2)};exports.transformJSONFile=a;
78
2
  //# sourceMappingURL=transformJSONFile.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformJSONFile.cjs","names":["Node","Project","IndentationText","QuoteKind","SyntaxKind"],"sources":["../../../src/writeContentDeclaration/transformJSONFile.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\nimport {\n IndentationText,\n Node,\n type ObjectLiteralExpression,\n Project,\n QuoteKind,\n SyntaxKind,\n} from 'ts-morph';\n\n/**\n * Checks if a value is a plain object (and not null/array)\n */\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n};\n\n/**\n * Safely formats a key for use in object literals.\n * Always quotes keys to ensure compatibility with standard JSON files.\n */\nconst stringifyKey = (objectKey: string): string => {\n return JSON.stringify(objectKey);\n};\n\n/**\n * Robustly finds a property in an ObjectLiteralExpression.\n * Handles cases where the property name in the source file is quoted (\"key\") or unquoted (key).\n */\nconst getMatchingProperty = (node: ObjectLiteralExpression, key: string) => {\n return node.getProperties().find((prop) => {\n // We only care about property assignments (key: value)\n if (Node.isPropertyAssignment(prop)) {\n const propName = prop.getName();\n // Check for strict match (unquoted identifier) or quoted match (string literal)\n // We check both double and single quotes to handle JSONC/JSON5 variations.\n return (\n propName === key || propName === `\"${key}\"` || propName === `'${key}'`\n );\n }\n return false;\n });\n};\n\n/**\n * Recursively updates the AST object literal with new data.\n */\nconst updateObjectLiteral = (\n node: ObjectLiteralExpression,\n data: Record<string, any>\n) => {\n for (const [key, val] of Object.entries(data)) {\n // Skip undefined values.\n if (val === undefined) continue;\n\n const stringifiedValue = JSON.stringify(val, null, 2);\n\n // Safety check: ensure we have a string unless we are recursing into an object\n if (stringifiedValue === undefined && !isPlainObject(val)) continue;\n\n // Use robust lookup instead of node.getProperty(key)\n const existingProp = getMatchingProperty(node, key);\n\n if (isPlainObject(val)) {\n if (existingProp && Node.isPropertyAssignment(existingProp)) {\n const initializer = existingProp.getInitializer();\n\n if (Node.isObjectLiteralExpression(initializer)) {\n // Recurse into nested object\n updateObjectLiteral(initializer, val);\n } else {\n // Property exists but is not an object (e.g. was null or number), overwrite with new object\n existingProp.setInitializer(stringifiedValue!);\n }\n } else if (existingProp) {\n // Property exists but isn't a simple assignment, overwrite it safely\n existingProp.replaceWithText(\n `${stringifyKey(key)}: ${stringifiedValue}`\n );\n } else {\n // Property doesn't exist, add it\n node.addPropertyAssignment({\n name: stringifyKey(key),\n initializer: stringifiedValue!,\n });\n }\n } else {\n // Handling Primitives / Arrays\n if (existingProp && Node.isPropertyAssignment(existingProp)) {\n existingProp.setInitializer(stringifiedValue!);\n } else if (existingProp) {\n existingProp.replaceWithText(\n `${stringifyKey(key)}: ${stringifiedValue}`\n );\n } else {\n node.addPropertyAssignment({\n name: stringifyKey(key),\n initializer: stringifiedValue!,\n });\n }\n }\n }\n};\n\nexport const transformJSONFile = (\n fileContent: string,\n dictionary: Dictionary\n): string => {\n // Initialize a virtual project\n const project = new Project({\n useInMemoryFileSystem: true,\n manipulationSettings: {\n indentationText: IndentationText.TwoSpaces,\n quoteKind: QuoteKind.Double,\n },\n });\n\n // Wrap content in a variable declaration so it acts as a valid SourceFile\n const dummyFileName = 'temp.ts';\n const wrappedContent = `const _config = ${fileContent.trim() || '{}'}`;\n const sourceFile = project.createSourceFile(dummyFileName, wrappedContent);\n\n // Locate the object literal\n const varDecl = sourceFile.getVariableDeclaration('_config');\n const objectLiteral = varDecl?.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n\n if (!objectLiteral) {\n // Fallback if parsing failed\n return JSON.stringify(dictionary, null, 2);\n }\n\n // Update the AST\n updateObjectLiteral(objectLiteral, dictionary);\n\n // Format text to ensure new properties are aligned\n sourceFile.formatText();\n\n // Extract the object literal text.\n return objectLiteral.getText();\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,iBAAiB,UAAqD;AAC1E,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;AAO7E,MAAM,gBAAgB,cAA8B;AAClD,QAAO,KAAK,UAAU,UAAU;;;;;;AAOlC,MAAM,uBAAuB,MAA+B,QAAgB;AAC1E,QAAO,KAAK,eAAe,CAAC,MAAM,SAAS;AAEzC,MAAIA,cAAK,qBAAqB,KAAK,EAAE;GACnC,MAAM,WAAW,KAAK,SAAS;AAG/B,UACE,aAAa,OAAO,aAAa,IAAI,IAAI,MAAM,aAAa,IAAI,IAAI;;AAGxE,SAAO;GACP;;;;;AAMJ,MAAM,uBACJ,MACA,SACG;AACH,MAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,KAAK,EAAE;AAE7C,MAAI,QAAQ,OAAW;EAEvB,MAAM,mBAAmB,KAAK,UAAU,KAAK,MAAM,EAAE;AAGrD,MAAI,qBAAqB,UAAa,CAAC,cAAc,IAAI,CAAE;EAG3D,MAAM,eAAe,oBAAoB,MAAM,IAAI;AAEnD,MAAI,cAAc,IAAI,CACpB,KAAI,gBAAgBA,cAAK,qBAAqB,aAAa,EAAE;GAC3D,MAAM,cAAc,aAAa,gBAAgB;AAEjD,OAAIA,cAAK,0BAA0B,YAAY,CAE7C,qBAAoB,aAAa,IAAI;OAGrC,cAAa,eAAe,iBAAkB;aAEvC,aAET,cAAa,gBACX,GAAG,aAAa,IAAI,CAAC,IAAI,mBAC1B;MAGD,MAAK,sBAAsB;GACzB,MAAM,aAAa,IAAI;GACvB,aAAa;GACd,CAAC;WAIA,gBAAgBA,cAAK,qBAAqB,aAAa,CACzD,cAAa,eAAe,iBAAkB;WACrC,aACT,cAAa,gBACX,GAAG,aAAa,IAAI,CAAC,IAAI,mBAC1B;MAED,MAAK,sBAAsB;GACzB,MAAM,aAAa,IAAI;GACvB,aAAa;GACd,CAAC;;;AAMV,MAAa,qBACX,aACA,eACW;CAEX,MAAM,UAAU,IAAIC,iBAAQ;EAC1B,uBAAuB;EACvB,sBAAsB;GACpB,iBAAiBC,yBAAgB;GACjC,WAAWC,mBAAU;GACtB;EACF,CAAC;CAGF,MAAM,gBAAgB;CACtB,MAAM,iBAAiB,mBAAmB,YAAY,MAAM,IAAI;CAChE,MAAM,aAAa,QAAQ,iBAAiB,eAAe,eAAe;CAI1E,MAAM,gBADU,WAAW,uBAAuB,UAAU,EAC7B,qBAC7BC,oBAAW,wBACZ;AAED,KAAI,CAAC,cAEH,QAAO,KAAK,UAAU,YAAY,MAAM,EAAE;AAI5C,qBAAoB,eAAe,WAAW;AAG9C,YAAW,YAAY;AAGvB,QAAO,cAAc,SAAS"}
1
+ {"version":3,"file":"transformJSONFile.cjs","names":["Node","Project","IndentationText","QuoteKind","SyntaxKind"],"sources":["../../../src/writeContentDeclaration/transformJSONFile.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\nimport {\n IndentationText,\n Node,\n type ObjectLiteralExpression,\n Project,\n QuoteKind,\n SyntaxKind,\n} from 'ts-morph';\n\n/**\n * Checks if a value is a plain object (and not null/array)\n */\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n};\n\n/**\n * Safely formats a key for use in object literals.\n * Always quotes keys to ensure compatibility with standard JSON files.\n */\nconst stringifyKey = (objectKey: string): string => {\n return JSON.stringify(objectKey);\n};\n\n/**\n * Robustly finds a property in an ObjectLiteralExpression.\n * Handles cases where the property name in the source file is quoted (\"key\") or unquoted (key).\n */\nconst getMatchingProperty = (node: ObjectLiteralExpression, key: string) => {\n return node.getProperties().find((prop) => {\n // We only care about property assignments (key: value)\n if (Node.isPropertyAssignment(prop)) {\n const propName = prop.getName();\n // Check for strict match (unquoted identifier) or quoted match (string literal)\n // We check both double and single quotes to handle JSONC/JSON5 variations.\n return (\n propName === key || propName === `\"${key}\"` || propName === `'${key}'`\n );\n }\n return false;\n });\n};\n\n/**\n * Recursively updates the AST object literal with new data.\n */\nconst updateObjectLiteral = (\n node: ObjectLiteralExpression,\n data: Record<string, any>\n) => {\n for (const [key, val] of Object.entries(data)) {\n // Skip undefined values.\n if (val === undefined) continue;\n\n const stringifiedValue = JSON.stringify(val, null, 2);\n\n // Safety check: ensure we have a string unless we are recursing into an object\n if (stringifiedValue === undefined && !isPlainObject(val)) continue;\n\n // Use robust lookup instead of node.getProperty(key)\n const existingProp = getMatchingProperty(node, key);\n\n if (isPlainObject(val)) {\n if (existingProp && Node.isPropertyAssignment(existingProp)) {\n const initializer = existingProp.getInitializer();\n\n if (Node.isObjectLiteralExpression(initializer)) {\n // Recurse into nested object\n updateObjectLiteral(initializer, val);\n } else {\n // Property exists but is not an object (e.g. was null or number), overwrite with new object\n existingProp.setInitializer(stringifiedValue!);\n }\n } else if (existingProp) {\n // Property exists but isn't a simple assignment, overwrite it safely\n existingProp.replaceWithText(\n `${stringifyKey(key)}: ${stringifiedValue}`\n );\n } else {\n // Property doesn't exist, add it\n node.addPropertyAssignment({\n name: stringifyKey(key),\n initializer: stringifiedValue!,\n });\n }\n } else {\n // Handling Primitives / Arrays\n if (existingProp && Node.isPropertyAssignment(existingProp)) {\n existingProp.setInitializer(stringifiedValue!);\n } else if (existingProp) {\n existingProp.replaceWithText(\n `${stringifyKey(key)}: ${stringifiedValue}`\n );\n } else {\n node.addPropertyAssignment({\n name: stringifyKey(key),\n initializer: stringifiedValue!,\n });\n }\n }\n }\n};\n\nexport const transformJSONFile = (\n fileContent: string,\n dictionary: Dictionary\n): string => {\n // Initialize a virtual project\n const project = new Project({\n useInMemoryFileSystem: true,\n manipulationSettings: {\n indentationText: IndentationText.TwoSpaces,\n quoteKind: QuoteKind.Double,\n },\n });\n\n // Wrap content in a variable declaration so it acts as a valid SourceFile\n const dummyFileName = 'temp.ts';\n const wrappedContent = `const _config = ${fileContent.trim() || '{}'}`;\n const sourceFile = project.createSourceFile(dummyFileName, wrappedContent);\n\n // Locate the object literal\n const varDecl = sourceFile.getVariableDeclaration('_config');\n const objectLiteral = varDecl?.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n\n if (!objectLiteral) {\n // Fallback if parsing failed\n return JSON.stringify(dictionary, null, 2);\n }\n\n // Update the AST\n updateObjectLiteral(objectLiteral, dictionary);\n\n // Format text to ensure new properties are aligned\n sourceFile.formatText();\n\n // Extract the object literal text.\n return objectLiteral.getText();\n};\n"],"mappings":"0IAaA,MAAM,EAAiB,GACd,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,EAAM,CAOvE,EAAgB,GACb,KAAK,UAAU,EAAU,CAO5B,GAAuB,EAA+B,IACnD,EAAK,eAAe,CAAC,KAAM,GAAS,CAEzC,GAAIA,EAAAA,KAAK,qBAAqB,EAAK,CAAE,CACnC,IAAM,EAAW,EAAK,SAAS,CAG/B,OACE,IAAa,GAAO,IAAa,IAAI,EAAI,IAAM,IAAa,IAAI,EAAI,GAGxE,MAAO,IACP,CAME,GACJ,EACA,IACG,CACH,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,EAAK,CAAE,CAE7C,GAAI,IAAQ,IAAA,GAAW,SAEvB,IAAM,EAAmB,KAAK,UAAU,EAAK,KAAM,EAAE,CAGrD,GAAI,IAAqB,IAAA,IAAa,CAAC,EAAc,EAAI,CAAE,SAG3D,IAAM,EAAe,EAAoB,EAAM,EAAI,CAEnD,GAAI,EAAc,EAAI,CACpB,GAAI,GAAgBA,EAAAA,KAAK,qBAAqB,EAAa,CAAE,CAC3D,IAAM,EAAc,EAAa,gBAAgB,CAE7CA,EAAAA,KAAK,0BAA0B,EAAY,CAE7C,EAAoB,EAAa,EAAI,CAGrC,EAAa,eAAe,EAAkB,MAEvC,EAET,EAAa,gBACX,GAAG,EAAa,EAAI,CAAC,IAAI,IAC1B,CAGD,EAAK,sBAAsB,CACzB,KAAM,EAAa,EAAI,CACvB,YAAa,EACd,CAAC,MAIA,GAAgBA,EAAAA,KAAK,qBAAqB,EAAa,CACzD,EAAa,eAAe,EAAkB,CACrC,EACT,EAAa,gBACX,GAAG,EAAa,EAAI,CAAC,IAAI,IAC1B,CAED,EAAK,sBAAsB,CACzB,KAAM,EAAa,EAAI,CACvB,YAAa,EACd,CAAC,GAMG,GACX,EACA,IACW,CAEX,IAAM,EAAU,IAAIC,EAAAA,QAAQ,CAC1B,sBAAuB,GACvB,qBAAsB,CACpB,gBAAiBC,EAAAA,gBAAgB,UACjC,UAAWC,EAAAA,UAAU,OACtB,CACF,CAAC,CAII,EAAiB,mBAAmB,EAAY,MAAM,EAAI,OAC1D,EAAa,EAAQ,iBAAiB,UAAe,EAAe,CAIpE,EADU,EAAW,uBAAuB,UAAU,EAC7B,qBAC7BC,EAAAA,WAAW,wBACZ,CAcD,OAZK,GAML,EAAoB,EAAe,EAAW,CAG9C,EAAW,YAAY,CAGhB,EAAc,SAAS,EAVrB,KAAK,UAAU,EAAY,KAAM,EAAE"}
@@ -1,124 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_utils_getFormatFromExtension = require('../utils/getFormatFromExtension.cjs');
4
- const require_writeContentDeclaration_processContentDeclarationContent = require('./processContentDeclarationContent.cjs');
5
- const require_writeContentDeclaration_transformJSONFile = require('./transformJSONFile.cjs');
6
- const require_writeContentDeclaration_writeJSFile = require('./writeJSFile.cjs');
7
- let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
8
- let node_fs_promises = require("node:fs/promises");
9
- let node_path = require("node:path");
10
- let _intlayer_core = require("@intlayer/core");
11
- let node_fs = require("node:fs");
12
- let node_util = require("node:util");
13
-
14
- //#region src/writeContentDeclaration/writeContentDeclaration.ts
15
- const formatContentDeclaration = async (dictionary, configuration, localeList) => {
16
- /**
17
- * Clean Markdown, Insertion, File, etc. node metadata
18
- */
19
- const processedDictionary = await require_writeContentDeclaration_processContentDeclarationContent.processContentDeclarationContent(dictionary);
20
- let content = processedDictionary.content;
21
- /**
22
- * Filter locales content
23
- */
24
- if (dictionary.locale) content = (0, _intlayer_core.getPerLocaleDictionary)(processedDictionary, dictionary.locale).content;
25
- else if (localeList) content = (0, _intlayer_core.getFilteredLocalesDictionary)(processedDictionary, localeList).content;
26
- let pluginFormatResult = {
27
- ...dictionary,
28
- content
29
- };
30
- /**
31
- * Format the dictionary with the plugins
32
- */
33
- for await (const plugin of configuration.plugins ?? []) if (plugin.formatOutput) {
34
- const formattedResult = await plugin.formatOutput?.({
35
- dictionary: pluginFormatResult,
36
- configuration
37
- });
38
- if (formattedResult) pluginFormatResult = formattedResult;
39
- }
40
- if (!(pluginFormatResult.content && pluginFormatResult.key)) return pluginFormatResult;
41
- let result = {
42
- key: dictionary.key,
43
- id: dictionary.id,
44
- title: dictionary.title,
45
- description: dictionary.description,
46
- tags: dictionary.tags,
47
- locale: dictionary.locale,
48
- fill: dictionary.fill,
49
- filled: dictionary.filled,
50
- priority: dictionary.priority,
51
- importMode: dictionary.importMode,
52
- version: dictionary.version,
53
- content
54
- };
55
- if (require_utils_getFormatFromExtension.getFormatFromExtension(dictionary.filePath ? (0, node_path.extname)(dictionary.filePath) : ".json") === "json" && pluginFormatResult.content && pluginFormatResult.key) result = {
56
- $schema: "https://intlayer.org/schema.json",
57
- ...result
58
- };
59
- return result;
60
- };
61
- const defaultOptions = { newDictionariesPath: "intlayer-dictionaries" };
62
- const writeContentDeclaration = async (dictionary, configuration, options) => {
63
- const { content } = configuration;
64
- const { baseDir } = content;
65
- const { newDictionariesPath, localeList } = {
66
- ...defaultOptions,
67
- ...options
68
- };
69
- const newDictionaryLocationPath = (0, node_path.join)(baseDir, newDictionariesPath);
70
- const existingDictionary = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration)[dictionary.key]?.find((el) => el.localId === dictionary.localId);
71
- const formattedContentDeclaration = await formatContentDeclaration(dictionary, configuration, localeList);
72
- if (existingDictionary?.filePath) {
73
- const isSameContent = (0, node_util.isDeepStrictEqual)(existingDictionary, dictionary);
74
- const filePath = (0, node_path.resolve)(configuration.content.baseDir, existingDictionary.filePath);
75
- if (isSameContent) return {
76
- status: "up-to-date",
77
- path: filePath
78
- };
79
- await writeFileWithDirectories(filePath, formattedContentDeclaration, configuration);
80
- return {
81
- status: "updated",
82
- path: filePath
83
- };
84
- }
85
- if (dictionary.filePath) {
86
- const filePath = (0, node_path.resolve)(configuration.content.baseDir, dictionary.filePath);
87
- await writeFileWithDirectories(filePath, formattedContentDeclaration, configuration);
88
- return {
89
- status: "created",
90
- path: filePath
91
- };
92
- }
93
- const contentDeclarationPath = (0, node_path.join)(newDictionaryLocationPath, `${dictionary.key}.content.json`);
94
- await writeFileWithDirectories(contentDeclarationPath, formattedContentDeclaration, configuration);
95
- return {
96
- status: "imported",
97
- path: contentDeclarationPath
98
- };
99
- };
100
- const writeFileWithDirectories = async (absoluteFilePath, dictionary, configuration) => {
101
- await (0, node_fs_promises.mkdir)((0, node_path.dirname)(absoluteFilePath), { recursive: true });
102
- const extension = (0, node_path.extname)(absoluteFilePath);
103
- if (!configuration.content.fileExtensions.map((extension) => (0, node_path.extname)(extension)).includes(extension)) throw new Error(`Invalid file extension: ${extension}, file: ${absoluteFilePath}`);
104
- if (extension === ".json") {
105
- await (0, node_fs_promises.writeFile)(absoluteFilePath, `${JSON.stringify(dictionary, null, 2)}\n`);
106
- return;
107
- }
108
- if ([".jsonc", ".json5"].includes(extension)) {
109
- let fileContent = "{}";
110
- if ((0, node_fs.existsSync)(absoluteFilePath)) try {
111
- fileContent = await (0, node_fs_promises.readFile)(absoluteFilePath, "utf-8");
112
- } catch {}
113
- await (0, node_fs_promises.writeFile)(absoluteFilePath, require_writeContentDeclaration_transformJSONFile.transformJSONFile(fileContent, dictionary), "utf-8");
114
- return;
115
- }
116
- await require_writeContentDeclaration_writeJSFile.writeJSFile(absoluteFilePath, dictionary, configuration);
117
- try {
118
- await (0, node_fs_promises.rm)((0, node_path.join)(configuration.system.cacheDir, "intlayer-prepared.lock"), { recursive: true });
119
- } catch {}
120
- };
121
-
122
- //#endregion
123
- exports.writeContentDeclaration = writeContentDeclaration;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../utils/getFormatFromExtension.cjs`),t=require(`./processContentDeclarationContent.cjs`),n=require(`./transformJSONFile.cjs`),r=require(`./writeJSFile.cjs`);let i=require(`@intlayer/unmerged-dictionaries-entry`),a=require(`node:fs/promises`),o=require(`node:path`),s=require(`@intlayer/core/plugins`),c=require(`node:fs`),l=require(`node:util`);const u=async(n,r,i)=>{let a=await t.processContentDeclarationContent(n),c=a.content;n.locale?c=(0,s.getPerLocaleDictionary)(a,n.locale).content:i&&(c=(0,s.getFilteredLocalesDictionary)(a,i).content);let l={...n,content:c};for await(let e of r.plugins??[])if(e.formatOutput){let t=await e.formatOutput?.({dictionary:l,configuration:r});t&&(l=t)}if(!(l.content&&l.key))return l;let u={key:n.key,id:n.id,title:n.title,description:n.description,tags:n.tags,locale:n.locale,fill:n.fill,filled:n.filled,priority:n.priority,importMode:n.importMode,version:n.version,content:c};return e.getFormatFromExtension(n.filePath?(0,o.extname)(n.filePath):`.json`)===`json`&&l.content&&l.key&&(u={$schema:`https://intlayer.org/schema.json`,...u}),u},d={newDictionariesPath:`intlayer-dictionaries`},f=async(e,t,n)=>{let{content:r}=t,{baseDir:a}=r,{newDictionariesPath:s,localeList:c}={...d,...n},f=(0,o.join)(a,s),m=(0,i.getUnmergedDictionaries)(t)[e.key]?.find(t=>t.localId===e.localId),h=await u(e,t,c);if(m?.filePath){let n=(0,l.isDeepStrictEqual)(m,e),r=(0,o.resolve)(t.content.baseDir,m.filePath);return n?{status:`up-to-date`,path:r}:(await p(r,h,t),{status:`updated`,path:r})}if(e.filePath){let n=(0,o.resolve)(t.content.baseDir,e.filePath);return await p(n,h,t),{status:`created`,path:n}}let g=(0,o.join)(f,`${e.key}.content.json`);return await p(g,h,t),{status:`imported`,path:g}},p=async(e,t,i)=>{await(0,a.mkdir)((0,o.dirname)(e),{recursive:!0});let s=(0,o.extname)(e);if(!i.content.fileExtensions.map(e=>(0,o.extname)(e)).includes(s))throw Error(`Invalid file extension: ${s}, file: ${e}`);if(s===`.json`){await(0,a.writeFile)(e,`${JSON.stringify(t,null,2)}\n`);return}if([`.jsonc`,`.json5`].includes(s)){let r=`{}`;if((0,c.existsSync)(e))try{r=await(0,a.readFile)(e,`utf-8`)}catch{}await(0,a.writeFile)(e,n.transformJSONFile(r,t),`utf-8`);return}await r.writeJSFile(e,t,i);try{await(0,a.rm)((0,o.join)(i.system.cacheDir,`intlayer-prepared.lock`),{recursive:!0})}catch{}};exports.writeContentDeclaration=f;
124
2
  //# sourceMappingURL=writeContentDeclaration.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeContentDeclaration.cjs","names":["processContentDeclarationContent","getFormatFromExtension","transformJSONFile","writeJSFile"],"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { dirname, extname, join, resolve } from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\nimport {\n getFilteredLocalesDictionary,\n getPerLocaleDictionary,\n} from '@intlayer/core';\nimport type {\n Dictionary,\n IntlayerConfig,\n Locale,\n LocalesValues,\n} from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { processContentDeclarationContent } from './processContentDeclarationContent';\nimport { transformJSONFile } from './transformJSONFile';\nimport { writeJSFile } from './writeJSFile';\n\nconst formatContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n localeList?: LocalesValues[]\n) => {\n /**\n * Clean Markdown, Insertion, File, etc. node metadata\n */\n const processedDictionary =\n await processContentDeclarationContent(dictionary);\n\n let content = processedDictionary.content;\n\n /**\n * Filter locales content\n */\n\n if (dictionary.locale) {\n content = getPerLocaleDictionary(\n processedDictionary,\n dictionary.locale\n ).content;\n } else if (localeList) {\n content = getFilteredLocalesDictionary(\n processedDictionary,\n localeList\n ).content;\n }\n\n let pluginFormatResult: any = {\n ...dictionary,\n content,\n } satisfies Dictionary;\n\n /**\n * Format the dictionary with the plugins\n */\n\n for await (const plugin of configuration.plugins ?? []) {\n if (plugin.formatOutput) {\n const formattedResult = await plugin.formatOutput?.({\n dictionary: pluginFormatResult,\n configuration,\n });\n\n if (formattedResult) {\n pluginFormatResult = formattedResult;\n }\n }\n }\n\n const isDictionaryFormat =\n pluginFormatResult.content && pluginFormatResult.key;\n\n if (!isDictionaryFormat) return pluginFormatResult;\n\n let result: Dictionary = {\n key: dictionary.key,\n id: dictionary.id,\n title: dictionary.title,\n description: dictionary.description,\n tags: dictionary.tags,\n locale: dictionary.locale,\n fill: dictionary.fill,\n filled: dictionary.filled,\n priority: dictionary.priority,\n importMode: dictionary.importMode,\n version: dictionary.version,\n content,\n };\n\n /**\n * Add $schema to JSON dictionaries\n */\n const extension = (\n dictionary.filePath ? extname(dictionary.filePath) : '.json'\n ) as Extension;\n const format = getFormatFromExtension(extension);\n\n if (\n format === 'json' &&\n pluginFormatResult.content &&\n pluginFormatResult.key\n ) {\n result = {\n $schema: 'https://intlayer.org/schema.json',\n ...result,\n };\n }\n\n return result;\n};\n\ntype WriteContentDeclarationOptions = {\n newDictionariesPath?: string;\n localeList?: LocalesValues[];\n fallbackLocale?: Locale;\n};\n\nconst defaultOptions = {\n newDictionariesPath: 'intlayer-dictionaries',\n} satisfies WriteContentDeclarationOptions;\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n options?: WriteContentDeclarationOptions\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = configuration;\n const { baseDir } = content;\n const { newDictionariesPath, localeList } = {\n ...defaultOptions,\n ...options,\n };\n\n const newDictionaryLocationPath = join(baseDir, newDictionariesPath);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const unmergedDictionaries = unmergedDictionariesRecord[\n dictionary.key\n ] as Dictionary[];\n\n const existingDictionary = unmergedDictionaries?.find(\n (el) => el.localId === dictionary.localId\n );\n\n const formattedContentDeclaration = await formatContentDeclaration(\n dictionary,\n configuration,\n localeList\n );\n\n if (existingDictionary?.filePath) {\n // Compare existing dictionary content with new dictionary content\n const isSameContent = isDeepStrictEqual(existingDictionary, dictionary);\n\n const filePath = resolve(\n configuration.content.baseDir,\n existingDictionary.filePath\n );\n\n // Up to date, nothing to do\n if (isSameContent) {\n return {\n status: 'up-to-date',\n path: filePath,\n };\n }\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'updated', path: filePath };\n }\n\n if (dictionary.filePath) {\n const filePath = resolve(\n configuration.content.baseDir,\n dictionary.filePath\n );\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'created', path: filePath };\n }\n\n // No existing dictionary, write to new location\n const contentDeclarationPath = join(\n newDictionaryLocationPath,\n `${dictionary.key}.content.json`\n );\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration,\n configuration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n};\n\nconst writeFileWithDirectories = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n // Extract the directory from the file path\n const dir = dirname(absoluteFilePath);\n\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n\n const extension = extname(absoluteFilePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extension) => extname(extension)\n );\n\n if (!acceptedExtensions.includes(extension)) {\n throw new Error(\n `Invalid file extension: ${extension}, file: ${absoluteFilePath}`\n );\n }\n\n if (extension === '.json') {\n const jsonDictionary = JSON.stringify(dictionary, null, 2);\n\n // Write the file\n await writeFile(absoluteFilePath, `${jsonDictionary}\\n`); // Add a new line at the end of the file to avoid formatting issues with VSCode\n\n return;\n }\n\n // Handle JSONC, and JSON5 via the AST transformer\n if (['.jsonc', '.json5'].includes(extension)) {\n let fileContent = '{}';\n\n if (existsSync(absoluteFilePath)) {\n try {\n fileContent = await readFile(absoluteFilePath, 'utf-8');\n } catch {\n // ignore read errors, start with empty object\n }\n }\n\n const transformedContent = transformJSONFile(fileContent, dictionary);\n\n // We use standard writeFile because transformedContent is already a string\n await writeFile(absoluteFilePath, transformedContent, 'utf-8');\n return;\n }\n\n await writeJSFile(absoluteFilePath, dictionary, configuration);\n\n // remove the cache as content has changed\n // Will force a new preparation of the intlayer on next build\n try {\n const sentinelPath = join(\n configuration.system.cacheDir,\n 'intlayer-prepared.lock'\n );\n await rm(sentinelPath, { recursive: true });\n } catch {}\n};\n"],"mappings":"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"}
1
+ {"version":3,"file":"writeContentDeclaration.cjs","names":["processContentDeclarationContent","getFormatFromExtension","transformJSONFile","writeJSFile"],"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { dirname, extname, join, resolve } from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\nimport {\n getFilteredLocalesDictionary,\n getPerLocaleDictionary,\n} from '@intlayer/core/plugins';\nimport type {\n Dictionary,\n IntlayerConfig,\n Locale,\n LocalesValues,\n} from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { processContentDeclarationContent } from './processContentDeclarationContent';\nimport { transformJSONFile } from './transformJSONFile';\nimport { writeJSFile } from './writeJSFile';\n\nconst formatContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n localeList?: LocalesValues[]\n) => {\n /**\n * Clean Markdown, Insertion, File, etc. node metadata\n */\n const processedDictionary =\n await processContentDeclarationContent(dictionary);\n\n let content = processedDictionary.content;\n\n /**\n * Filter locales content\n */\n\n if (dictionary.locale) {\n content = getPerLocaleDictionary(\n processedDictionary,\n dictionary.locale\n ).content;\n } else if (localeList) {\n content = getFilteredLocalesDictionary(\n processedDictionary,\n localeList\n ).content;\n }\n\n let pluginFormatResult: any = {\n ...dictionary,\n content,\n } satisfies Dictionary;\n\n /**\n * Format the dictionary with the plugins\n */\n\n for await (const plugin of configuration.plugins ?? []) {\n if (plugin.formatOutput) {\n const formattedResult = await plugin.formatOutput?.({\n dictionary: pluginFormatResult,\n configuration,\n });\n\n if (formattedResult) {\n pluginFormatResult = formattedResult;\n }\n }\n }\n\n const isDictionaryFormat =\n pluginFormatResult.content && pluginFormatResult.key;\n\n if (!isDictionaryFormat) return pluginFormatResult;\n\n let result: Dictionary = {\n key: dictionary.key,\n id: dictionary.id,\n title: dictionary.title,\n description: dictionary.description,\n tags: dictionary.tags,\n locale: dictionary.locale,\n fill: dictionary.fill,\n filled: dictionary.filled,\n priority: dictionary.priority,\n importMode: dictionary.importMode,\n version: dictionary.version,\n content,\n };\n\n /**\n * Add $schema to JSON dictionaries\n */\n const extension = (\n dictionary.filePath ? extname(dictionary.filePath) : '.json'\n ) as Extension;\n const format = getFormatFromExtension(extension);\n\n if (\n format === 'json' &&\n pluginFormatResult.content &&\n pluginFormatResult.key\n ) {\n result = {\n $schema: 'https://intlayer.org/schema.json',\n ...result,\n };\n }\n\n return result;\n};\n\ntype WriteContentDeclarationOptions = {\n newDictionariesPath?: string;\n localeList?: LocalesValues[];\n fallbackLocale?: Locale;\n};\n\nconst defaultOptions = {\n newDictionariesPath: 'intlayer-dictionaries',\n} satisfies WriteContentDeclarationOptions;\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n options?: WriteContentDeclarationOptions\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = configuration;\n const { baseDir } = content;\n const { newDictionariesPath, localeList } = {\n ...defaultOptions,\n ...options,\n };\n\n const newDictionaryLocationPath = join(baseDir, newDictionariesPath);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const unmergedDictionaries = unmergedDictionariesRecord[\n dictionary.key\n ] as Dictionary[];\n\n const existingDictionary = unmergedDictionaries?.find(\n (el) => el.localId === dictionary.localId\n );\n\n const formattedContentDeclaration = await formatContentDeclaration(\n dictionary,\n configuration,\n localeList\n );\n\n if (existingDictionary?.filePath) {\n // Compare existing dictionary content with new dictionary content\n const isSameContent = isDeepStrictEqual(existingDictionary, dictionary);\n\n const filePath = resolve(\n configuration.content.baseDir,\n existingDictionary.filePath\n );\n\n // Up to date, nothing to do\n if (isSameContent) {\n return {\n status: 'up-to-date',\n path: filePath,\n };\n }\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'updated', path: filePath };\n }\n\n if (dictionary.filePath) {\n const filePath = resolve(\n configuration.content.baseDir,\n dictionary.filePath\n );\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'created', path: filePath };\n }\n\n // No existing dictionary, write to new location\n const contentDeclarationPath = join(\n newDictionaryLocationPath,\n `${dictionary.key}.content.json`\n );\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration,\n configuration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n};\n\nconst writeFileWithDirectories = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n // Extract the directory from the file path\n const dir = dirname(absoluteFilePath);\n\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n\n const extension = extname(absoluteFilePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extension) => extname(extension)\n );\n\n if (!acceptedExtensions.includes(extension)) {\n throw new Error(\n `Invalid file extension: ${extension}, file: ${absoluteFilePath}`\n );\n }\n\n if (extension === '.json') {\n const jsonDictionary = JSON.stringify(dictionary, null, 2);\n\n // Write the file\n await writeFile(absoluteFilePath, `${jsonDictionary}\\n`); // Add a new line at the end of the file to avoid formatting issues with VSCode\n\n return;\n }\n\n // Handle JSONC, and JSON5 via the AST transformer\n if (['.jsonc', '.json5'].includes(extension)) {\n let fileContent = '{}';\n\n if (existsSync(absoluteFilePath)) {\n try {\n fileContent = await readFile(absoluteFilePath, 'utf-8');\n } catch {\n // ignore read errors, start with empty object\n }\n }\n\n const transformedContent = transformJSONFile(fileContent, dictionary);\n\n // We use standard writeFile because transformedContent is already a string\n await writeFile(absoluteFilePath, transformedContent, 'utf-8');\n return;\n }\n\n await writeJSFile(absoluteFilePath, dictionary, configuration);\n\n // remove the cache as content has changed\n // Will force a new preparation of the intlayer on next build\n try {\n const sentinelPath = join(\n configuration.system.cacheDir,\n 'intlayer-prepared.lock'\n );\n await rm(sentinelPath, { recursive: true });\n } catch {}\n};\n"],"mappings":"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"}
@@ -1,72 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_writeContentDeclaration_detectFormatCommand = require('./detectFormatCommand.cjs');
4
- const require_writeContentDeclaration_transformJSFile = require('./transformJSFile.cjs');
5
- const require_utils_getFormatFromExtension = require('../utils/getFormatFromExtension.cjs');
6
- const require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate = require('../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs');
7
- let _intlayer_config = require("@intlayer/config");
8
- let node_fs_promises = require("node:fs/promises");
9
- let node_path = require("node:path");
10
- let node_fs = require("node:fs");
11
- let node_child_process = require("node:child_process");
12
-
13
- //#region src/writeContentDeclaration/writeJSFile.ts
14
- /**
15
- * Updates a JavaScript/TypeScript file based on the provided JSON instructions.
16
- * It targets a specific dictionary object within the file (identified by its 'key' property)
17
- * and updates its 'content' entries. Currently, it focuses on modifying arguments
18
- * of 't' (translation) function calls.
19
- */
20
- const writeJSFile = async (filePath, dictionary, configuration) => {
21
- const mergedDictionary = {
22
- ...configuration.dictionary,
23
- ...dictionary
24
- };
25
- const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
26
- if (!(0, node_fs.existsSync)(filePath)) {
27
- const format = require_utils_getFormatFromExtension.getFormatFromExtension((0, node_path.extname)(filePath));
28
- appLogger("File does not exist, creating it", { isVerbose: true });
29
- await (0, node_fs_promises.writeFile)(filePath, await require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate.getContentDeclarationFileTemplate(mergedDictionary.key, format, Object.fromEntries(Object.entries({
30
- id: mergedDictionary.id,
31
- locale: mergedDictionary.locale,
32
- filled: mergedDictionary.filled,
33
- fill: mergedDictionary.fill,
34
- description: mergedDictionary.description,
35
- title: mergedDictionary.title,
36
- tags: mergedDictionary.tags,
37
- version: mergedDictionary.version,
38
- priority: mergedDictionary.priority,
39
- importMode: mergedDictionary.importMode
40
- }).filter(([, value]) => value !== void 0))), "utf-8");
41
- }
42
- let fileContent = await (0, node_fs_promises.readFile)(filePath, "utf-8");
43
- if (fileContent === "") {
44
- const format = require_utils_getFormatFromExtension.getFormatFromExtension((0, node_path.extname)(filePath));
45
- fileContent = await require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate.getContentDeclarationFileTemplate(mergedDictionary.key, format);
46
- }
47
- const finalCode = await require_writeContentDeclaration_transformJSFile.transformJSFile(fileContent, dictionary);
48
- try {
49
- await (0, node_fs_promises.writeFile)(filePath, finalCode, "utf-8");
50
- (0, _intlayer_config.logger)(`Successfully updated ${filePath}`, {
51
- level: "info",
52
- isVerbose: true
53
- });
54
- } catch (error) {
55
- const err = error;
56
- (0, _intlayer_config.logger)(`Failed to write updated file: ${filePath}`, { level: "error" });
57
- throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);
58
- }
59
- const formatCommand = require_writeContentDeclaration_detectFormatCommand.detectFormatCommand(configuration);
60
- if (formatCommand) try {
61
- (0, node_child_process.execSync)(formatCommand.replace("{{file}}", filePath), {
62
- stdio: "inherit",
63
- cwd: configuration.content.baseDir
64
- });
65
- } catch (error) {
66
- console.error(error);
67
- }
68
- };
69
-
70
- //#endregion
71
- exports.writeJSFile = writeJSFile;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./detectFormatCommand.cjs`),t=require(`./transformJSFile.cjs`),n=require(`../utils/getFormatFromExtension.cjs`),r=require(`../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs`);let i=require(`node:fs/promises`),a=require(`node:path`),o=require(`@intlayer/config/logger`),s=require(`node:fs`),c=require(`node:child_process`);const l=async(l,u,d)=>{let f={...d.dictionary,...u},p=(0,o.getAppLogger)(d);if(!(0,s.existsSync)(l)){let e=n.getFormatFromExtension((0,a.extname)(l));p(`File does not exist, creating it`,{isVerbose:!0}),await(0,i.writeFile)(l,await r.getContentDeclarationFileTemplate(f.key,e,Object.fromEntries(Object.entries({id:f.id,locale:f.locale,filled:f.filled,fill:f.fill,description:f.description,title:f.title,tags:f.tags,version:f.version,priority:f.priority,importMode:f.importMode}).filter(([,e])=>e!==void 0))),`utf-8`)}let m=await(0,i.readFile)(l,`utf-8`);if(m===``){let e=n.getFormatFromExtension((0,a.extname)(l));m=await r.getContentDeclarationFileTemplate(f.key,e)}let h=await t.transformJSFile(m,u);try{await(0,i.writeFile)(l,h,`utf-8`),(0,o.logger)(`Successfully updated ${l}`,{level:`info`,isVerbose:!0})}catch(e){let t=e;throw(0,o.logger)(`Failed to write updated file: ${l}`,{level:`error`}),Error(`Failed to write updated file ${l}: ${t.message}`)}let g=e.detectFormatCommand(d);if(g)try{(0,c.execSync)(g.replace(`{{file}}`,l),{stdio:`inherit`,cwd:d.content.baseDir})}catch(e){console.error(e)}};exports.writeJSFile=l;
72
2
  //# sourceMappingURL=writeJSFile.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeJSFile.cjs","names":["getFormatFromExtension","getContentDeclarationFileTemplate","transformJSFile","detectFormatCommand"],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { detectFormatCommand } from './detectFormatCommand';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n id: mergedDictionary.id,\n locale: mergedDictionary.locale,\n filled: mergedDictionary.filled,\n fill: mergedDictionary.fill,\n description: mergedDictionary.description,\n title: mergedDictionary.title,\n tags: mergedDictionary.tags,\n version: mergedDictionary.version,\n priority: mergedDictionary.priority,\n importMode: mergedDictionary.importMode,\n }).filter(([, value]) => value !== undefined)\n )\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n let fileContent = await readFile(filePath, 'utf-8');\n\n if (fileContent === '') {\n const format = getFormatFromExtension(extname(filePath) as Extension);\n\n fileContent = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format\n );\n }\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAc,OACzB,UACA,YACA,kBACkB;CAClB,MAAM,mBAAmB;EACvB,GAAG,cAAc;EACjB,GAAG;EACJ;CAED,MAAM,+CAAyB,cAAc;AAG7C,KAAI,yBAAY,SAAS,EAAE;EAGzB,MAAM,SAASA,mFAFe,SAAS,CAEa;AAEpD,YAAU,oCAAoC,EAC5C,WAAW,MACZ,CAAC;AAqBF,wCAAgB,UApBC,MAAMC,8GACrB,iBAAiB,KACjB,QAEA,OAAO,YACL,OAAO,QAAQ;GACb,IAAI,iBAAiB;GACrB,QAAQ,iBAAiB;GACzB,QAAQ,iBAAiB;GACzB,MAAM,iBAAiB;GACvB,aAAa,iBAAiB;GAC9B,OAAO,iBAAiB;GACxB,MAAM,iBAAiB;GACvB,SAAS,iBAAiB;GAC1B,UAAU,iBAAiB;GAC3B,YAAY,iBAAiB;GAC9B,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,OAAU,CAC9C,CACF,EAEmC,QAAQ;;CAG9C,IAAI,cAAc,qCAAe,UAAU,QAAQ;AAEnD,KAAI,gBAAgB,IAAI;EACtB,MAAM,SAASD,mFAA+B,SAAS,CAAc;AAErE,gBAAc,MAAMC,8GAClB,iBAAiB,KACjB,OACD;;CAGH,MAAM,YAAY,MAAMC,gEAAgB,aAAa,WAAW;AAGhE,KAAI;AACF,wCAAgB,UAAU,WAAW,QAAQ;AAC7C,+BAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;GACZ,CAAC;UACK,OAAO;EACd,MAAM,MAAM;AACZ,+BAAO,iCAAiC,YAAY,EAClD,OAAO,SACR,CAAC;AACF,QAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,UAAU;;CAG7E,MAAM,gBAAgBC,wEAAoB,cAAc;AAExD,KAAI,cACF,KAAI;AACF,mCAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;GACpD,OAAO;GACP,KAAK,cAAc,QAAQ;GAC5B,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,MAAM"}
1
+ {"version":3,"file":"writeJSFile.cjs","names":["getFormatFromExtension","getContentDeclarationFileTemplate","transformJSFile","detectFormatCommand"],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config/logger';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { detectFormatCommand } from './detectFormatCommand';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n id: mergedDictionary.id,\n locale: mergedDictionary.locale,\n filled: mergedDictionary.filled,\n fill: mergedDictionary.fill,\n description: mergedDictionary.description,\n title: mergedDictionary.title,\n tags: mergedDictionary.tags,\n version: mergedDictionary.version,\n priority: mergedDictionary.priority,\n importMode: mergedDictionary.importMode,\n }).filter(([, value]) => value !== undefined)\n )\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n let fileContent = await readFile(filePath, 'utf-8');\n\n if (fileContent === '') {\n const format = getFormatFromExtension(extname(filePath) as Extension);\n\n fileContent = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format\n );\n }\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":"4dAoBA,MAAa,EAAc,MACzB,EACA,EACA,IACkB,CAClB,IAAM,EAAmB,CACvB,GAAG,EAAc,WACjB,GAAG,EACJ,CAEK,GAAA,EAAA,EAAA,cAAyB,EAAc,CAG7C,GAAI,EAAA,EAAA,EAAA,YAAY,EAAS,CAAE,CAGzB,IAAM,EAASA,EAAAA,wBAAAA,EAAAA,EAAAA,SAFe,EAAS,CAEa,CAEpD,EAAU,mCAAoC,CAC5C,UAAW,GACZ,CAAC,CAqBF,MAAA,EAAA,EAAA,WAAgB,EApBC,MAAMC,EAAAA,kCACrB,EAAiB,IACjB,EAEA,OAAO,YACL,OAAO,QAAQ,CACb,GAAI,EAAiB,GACrB,OAAQ,EAAiB,OACzB,OAAQ,EAAiB,OACzB,KAAM,EAAiB,KACvB,YAAa,EAAiB,YAC9B,MAAO,EAAiB,MACxB,KAAM,EAAiB,KACvB,QAAS,EAAiB,QAC1B,SAAU,EAAiB,SAC3B,WAAY,EAAiB,WAC9B,CAAC,CAAC,QAAQ,EAAG,KAAW,IAAU,IAAA,GAAU,CAC9C,CACF,CAEmC,QAAQ,CAG9C,IAAI,EAAc,MAAA,EAAA,EAAA,UAAe,EAAU,QAAQ,CAEnD,GAAI,IAAgB,GAAI,CACtB,IAAM,EAASD,EAAAA,wBAAAA,EAAAA,EAAAA,SAA+B,EAAS,CAAc,CAErE,EAAc,MAAMC,EAAAA,kCAClB,EAAiB,IACjB,EACD,CAGH,IAAM,EAAY,MAAMC,EAAAA,gBAAgB,EAAa,EAAW,CAGhE,GAAI,CACF,MAAA,EAAA,EAAA,WAAgB,EAAU,EAAW,QAAQ,EAC7C,EAAA,EAAA,QAAO,wBAAwB,IAAY,CACzC,MAAO,OACP,UAAW,GACZ,CAAC,OACK,EAAO,CACd,IAAM,EAAM,EAIZ,MAHA,EAAA,EAAA,QAAO,iCAAiC,IAAY,CAClD,MAAO,QACR,CAAC,CACQ,MAAM,gCAAgC,EAAS,IAAI,EAAI,UAAU,CAG7E,IAAM,EAAgBC,EAAAA,oBAAoB,EAAc,CAExD,GAAI,EACF,GAAI,EACF,EAAA,EAAA,UAAS,EAAc,QAAQ,WAAY,EAAS,CAAE,CACpD,MAAO,UACP,IAAK,EAAc,QAAQ,QAC5B,CAAC,OACK,EAAO,CACd,QAAQ,MAAM,EAAM"}
@@ -1,13 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- let node_fs_promises = require("node:fs/promises");
4
-
5
- //#region src/writeFileIfChanged.ts
6
- const writeFileIfChanged = async (path, dataOrStream, { encoding = "utf8" } = {}) => {
7
- await (0, node_fs_promises.writeFile)(path, dataOrStream, { encoding });
8
- return true;
9
- };
10
-
11
- //#endregion
12
- exports.writeFileIfChanged = writeFileIfChanged;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`node:fs/promises`);const t=async(t,n,{encoding:r=`utf8`}={})=>(await(0,e.writeFile)(t,n,{encoding:r}),!0);exports.writeFileIfChanged=t;
13
2
  //# sourceMappingURL=writeFileIfChanged.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeFileIfChanged.cjs","names":[],"sources":["../../src/writeFileIfChanged.ts"],"sourcesContent":["import { writeFile } from 'node:fs/promises';\n// import { createHash } from 'node:crypto';\n// import { createReadStream } from 'node:fs';\n// import type { Readable } from 'node:stream';\n\n// const hashFile = async (path: string) => {\n// const h = createHash('sha256');\n// const rs = createReadStream(path);\n// rs.on('data', (chunk) => h.update(chunk));\n// await new Promise<void>((res, rej) => {\n// rs.on('end', () => res());\n// rs.on('error', rej);\n// });\n// return h.digest('hex');\n// };\n\n// const isReadableStream = (value: unknown): value is Readable =>\n// !!value &&\n// typeof value === 'object' &&\n// typeof (value as any).pipe === 'function';\n\nexport const writeFileIfChanged = async (\n path: string,\n dataOrStream: string,\n { encoding = 'utf8' }: { encoding?: BufferEncoding } = {}\n): Promise<boolean> => {\n // Disabled because it's too slow. Build time increases from 3s to 7s.\n await writeFile(path, dataOrStream, { encoding });\n\n // 1) write new content to temporary file (stream-safe)\n // const tmp = `${path}.tmp`;\n\n // if (isReadableStream(dataOrStream)) {\n // await pipeline(dataOrStream, createWriteStream(tmp));\n // } else {\n // // dataOrStream = string | Buffer\n // const buf = Buffer.isBuffer(dataOrStream)\n // ? dataOrStream\n // : Buffer.from(dataOrStream, encoding);\n // await writeFile(tmp, buf);\n // }\n\n // 2) if old file exists, compare hashes (streaming)\n // let same = false;\n // try {\n // const [oldHash, newHash] = await Promise.all([\n // hashFile(path),\n // hashFile(tmp),\n // ]);\n // same = oldHash === newHash;\n // } catch {\n // // old file missing -> will replace\n // }\n\n // if (same) {\n // await rm(tmp);\n // return false; // no change\n // }\n\n // 3) atomic replacement\n // On Unix, rename is atomic. On Windows, if file exists, we can delete it first.\n // try {\n // await rename(tmp, path);\n // } catch {\n // try {\n // await rm(path);\n // } catch {}\n // await rename(tmp, path);\n // }\n\n return true; // changed\n};\n"],"mappings":";;;;;AAqBA,MAAa,qBAAqB,OAChC,MACA,cACA,EAAE,WAAW,WAA0C,EAAE,KACpC;AAErB,uCAAgB,MAAM,cAAc,EAAE,UAAU,CAAC;AA2CjD,QAAO"}
1
+ {"version":3,"file":"writeFileIfChanged.cjs","names":[],"sources":["../../src/writeFileIfChanged.ts"],"sourcesContent":["import { writeFile } from 'node:fs/promises';\n// import { createHash } from 'node:crypto';\n// import { createReadStream } from 'node:fs';\n// import type { Readable } from 'node:stream';\n\n// const hashFile = async (path: string) => {\n// const h = createHash('sha256');\n// const rs = createReadStream(path);\n// rs.on('data', (chunk) => h.update(chunk));\n// await new Promise<void>((res, rej) => {\n// rs.on('end', () => res());\n// rs.on('error', rej);\n// });\n// return h.digest('hex');\n// };\n\n// const isReadableStream = (value: unknown): value is Readable =>\n// !!value &&\n// typeof value === 'object' &&\n// typeof (value as any).pipe === 'function';\n\nexport const writeFileIfChanged = async (\n path: string,\n dataOrStream: string,\n { encoding = 'utf8' }: { encoding?: BufferEncoding } = {}\n): Promise<boolean> => {\n // Disabled because it's too slow. Build time increases from 3s to 7s.\n await writeFile(path, dataOrStream, { encoding });\n\n // 1) write new content to temporary file (stream-safe)\n // const tmp = `${path}.tmp`;\n\n // if (isReadableStream(dataOrStream)) {\n // await pipeline(dataOrStream, createWriteStream(tmp));\n // } else {\n // // dataOrStream = string | Buffer\n // const buf = Buffer.isBuffer(dataOrStream)\n // ? dataOrStream\n // : Buffer.from(dataOrStream, encoding);\n // await writeFile(tmp, buf);\n // }\n\n // 2) if old file exists, compare hashes (streaming)\n // let same = false;\n // try {\n // const [oldHash, newHash] = await Promise.all([\n // hashFile(path),\n // hashFile(tmp),\n // ]);\n // same = oldHash === newHash;\n // } catch {\n // // old file missing -> will replace\n // }\n\n // if (same) {\n // await rm(tmp);\n // return false; // no change\n // }\n\n // 3) atomic replacement\n // On Unix, rename is atomic. On Windows, if file exists, we can delete it first.\n // try {\n // await rename(tmp, path);\n // } catch {\n // try {\n // await rm(path);\n // } catch {}\n // await rename(tmp, path);\n // }\n\n return true; // changed\n};\n"],"mappings":"iJAqBA,MAAa,EAAqB,MAChC,EACA,EACA,CAAE,WAAW,QAA0C,EAAE,IAGzD,MAAA,EAAA,EAAA,WAAgB,EAAM,EAAc,CAAE,WAAU,CAAC,CA2C1C"}
@@ -1,18 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_writeFileIfChanged = require('./writeFileIfChanged.cjs');
3
-
4
- //#region src/writeJsonIfChanged.ts
5
- const writeJsonIfChanged = async (path, data, { pretty = process.env.NODE_ENV === "development" } = {}) => {
6
- const space = pretty ? 2 : void 0;
7
- let json = "{}";
8
- try {
9
- json = JSON.stringify(data, null, space);
10
- } catch (error) {
11
- console.error(`Error while parsing data to JSON for ${path}:`, error);
12
- }
13
- return await require_writeFileIfChanged.writeFileIfChanged(path, json);
14
- };
15
-
16
- //#endregion
17
- exports.writeJsonIfChanged = writeJsonIfChanged;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./writeFileIfChanged.cjs`),t=async(t,n,{pretty:r=process.env.NODE_ENV===`development`}={})=>{let i=r?2:void 0,a=`{}`;try{a=JSON.stringify(n,null,i)}catch(e){console.error(`Error while parsing data to JSON for ${t}:`,e)}return await e.writeFileIfChanged(t,a)};exports.writeJsonIfChanged=t;
18
2
  //# sourceMappingURL=writeJsonIfChanged.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeJsonIfChanged.cjs","names":["writeFileIfChanged"],"sources":["../../src/writeJsonIfChanged.ts"],"sourcesContent":["import { writeFileIfChanged } from './writeFileIfChanged';\n\nexport const writeJsonIfChanged = async <T>(\n path: string,\n data: T,\n { pretty = process.env.NODE_ENV === 'development' } = {}\n): Promise<boolean> => {\n const space = pretty ? 2 : undefined;\n\n let json = '{}';\n\n try {\n json = JSON.stringify(data, null, space);\n } catch (error) {\n console.error(`Error while parsing data to JSON for ${path}:`, error);\n }\n\n return await writeFileIfChanged(path, json);\n};\n"],"mappings":";;;;AAEA,MAAa,qBAAqB,OAChC,MACA,MACA,EAAE,SAAS,QAAQ,IAAI,aAAa,kBAAkB,EAAE,KACnC;CACrB,MAAM,QAAQ,SAAS,IAAI;CAE3B,IAAI,OAAO;AAEX,KAAI;AACF,SAAO,KAAK,UAAU,MAAM,MAAM,MAAM;UACjC,OAAO;AACd,UAAQ,MAAM,wCAAwC,KAAK,IAAI,MAAM;;AAGvE,QAAO,MAAMA,8CAAmB,MAAM,KAAK"}
1
+ {"version":3,"file":"writeJsonIfChanged.cjs","names":["writeFileIfChanged"],"sources":["../../src/writeJsonIfChanged.ts"],"sourcesContent":["import { writeFileIfChanged } from './writeFileIfChanged';\n\nexport const writeJsonIfChanged = async <T>(\n path: string,\n data: T,\n { pretty = process.env.NODE_ENV === 'development' } = {}\n): Promise<boolean> => {\n const space = pretty ? 2 : undefined;\n\n let json = '{}';\n\n try {\n json = JSON.stringify(data, null, space);\n } catch (error) {\n console.error(`Error while parsing data to JSON for ${path}:`, error);\n }\n\n return await writeFileIfChanged(path, json);\n};\n"],"mappings":"+GAEa,EAAqB,MAChC,EACA,EACA,CAAE,SAAS,QAAQ,IAAI,WAAa,eAAkB,EAAE,GACnC,CACrB,IAAM,EAAQ,EAAS,EAAI,IAAA,GAEvB,EAAO,KAEX,GAAI,CACF,EAAO,KAAK,UAAU,EAAM,KAAM,EAAM,OACjC,EAAO,CACd,QAAQ,MAAM,wCAAwC,EAAK,GAAI,EAAM,CAGvE,OAAO,MAAMA,EAAAA,mBAAmB,EAAM,EAAK"}
@@ -1,8 +1 @@
1
- //#region \0rolldown/runtime.js
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
3
- if (typeof require !== "undefined") return require.apply(this, arguments);
4
- throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
5
- });
6
-
7
- //#endregion
8
- export { __require };
1
+ var e=(e=>typeof require<`u`?require:typeof Proxy<`u`?new Proxy(e,{get:(e,t)=>(typeof require<`u`?require:e)[t]}):e)(function(e){if(typeof require<`u`)return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.")});export{e as __require};
@@ -1,97 +1,2 @@
1
- import { basename, dirname, join, relative, resolve, sep } from "node:path";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import { fileURLToPath } from "node:url";
4
-
5
- //#region \0utils:asset
6
- const hereDirname = () => {
7
- try {
8
- return dirname(fileURLToPath(import.meta.url));
9
- } catch {
10
- return typeof __dirname !== "undefined" ? __dirname : process.cwd();
11
- }
12
- };
13
- const findDistRoot = (startDir) => {
14
- let dir = startDir;
15
- for (let i = 0; i < 12; i++) {
16
- if (basename(dir) === "dist") return dir;
17
- const parent = resolve(dir, "..");
18
- if (parent === dir) break;
19
- dir = parent;
20
- }
21
- return null;
22
- };
23
- const normalizeFrameFile = (file) => {
24
- if (!file) return null;
25
- try {
26
- if (file.startsWith("file://")) return fileURLToPath(file);
27
- } catch {}
28
- return file;
29
- };
30
- /**
31
- * Returns the directory of the *caller* module that invoked readAsset.
32
- * Prefers non-virtual frames; falls back to the first real frame.
33
- */
34
- const getCallerDir = () => {
35
- const prev = Error.prepareStackTrace;
36
- try {
37
- Error.prepareStackTrace = (_, structured) => structured;
38
- const err = /* @__PURE__ */ new Error();
39
- Error.captureStackTrace(err, getCallerDir);
40
- /** @type {import('node:vm').CallSite[]} */
41
- const frames = err.stack || [];
42
- const isVirtualPath = (p) => p.includes(`${sep}_virtual${sep}`) || p.includes("/_virtual/");
43
- for (const frame of frames) {
44
- const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
45
- if (!file) continue;
46
- if (file.includes("node:internal") || file.includes(`${sep}internal${sep}modules${sep}`)) continue;
47
- if (!isVirtualPath(file)) return dirname(file);
48
- }
49
- for (const frame of frames) {
50
- const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
51
- if (file) return dirname(file);
52
- }
53
- } catch {} finally {
54
- Error.prepareStackTrace = prev;
55
- }
56
- return hereDirname();
57
- };
58
- /**
59
- * Read an asset copied from src/** to dist/assets/**.
60
- * - './' or '../' is resolved relative to the *caller module's* emitted directory.
61
- * - otherwise, treat as src-relative.
62
- *
63
- * @param {string} relPath - e.g. './PROMPT.md' or 'utils/AI/askDocQuestion/embeddings/<fileKey>.json'
64
- * @param {BufferEncoding} [encoding='utf8']
65
- */
66
- const readAsset = (relPath, encoding = "utf8") => {
67
- const here = hereDirname();
68
- const distRoot = findDistRoot(here) ?? resolve(here, "..", "..", "dist");
69
- const assetsRoot = join(distRoot, "assets");
70
- const tried = [];
71
- /**
72
- * Transform dist/(esm|cjs)/... and _virtual/ prefix to clean subpath (Windows-safe)
73
- */
74
- const callerSubpath = relative(distRoot, getCallerDir()).split("\\").join("/").replace(/^(?:dist\/)?(?:esm|cjs)\//, "").replace(/^_virtual\//, "");
75
- if (relPath.startsWith("./") || relPath.startsWith("../")) {
76
- const fromCallerAbs = resolve(assetsRoot, callerSubpath, relPath);
77
- tried.push(fromCallerAbs);
78
- if (existsSync(fromCallerAbs)) return readFileSync(fromCallerAbs, encoding);
79
- }
80
- const directPath = join(assetsRoot, relPath);
81
- tried.push(directPath);
82
- if (existsSync(directPath)) return readFileSync(directPath, encoding);
83
- if (callerSubpath) {
84
- const nested = join(assetsRoot, callerSubpath, relPath);
85
- tried.push(nested);
86
- if (existsSync(nested)) return readFileSync(nested, encoding);
87
- }
88
- const msg = [
89
- "readAsset: file not found.",
90
- "Searched:",
91
- ...tried.map((p) => `- ${p}`)
92
- ].join("\n");
93
- throw new Error(msg);
94
- };
95
-
96
- //#endregion
97
- export { readAsset };
1
+ import{basename as e,dirname as t,join as n,relative as r,resolve as i,sep as a}from"node:path";import{existsSync as o,readFileSync as s}from"node:fs";import{fileURLToPath as c}from"node:url";const l=()=>{try{return t(c(import.meta.url))}catch{return typeof __dirname<`u`?__dirname:process.cwd()}},u=t=>{let n=t;for(let t=0;t<12;t++){if(e(n)===`dist`)return n;let t=i(n,`..`);if(t===n)break;n=t}return null},d=e=>{if(!e)return null;try{if(e.startsWith(`file://`))return c(e)}catch{}return e},f=()=>{let e=Error.prepareStackTrace;try{Error.prepareStackTrace=(e,t)=>t;let e=Error();Error.captureStackTrace(e,f);let n=e.stack||[],r=e=>e.includes(`${a}_virtual${a}`)||e.includes(`/_virtual/`);for(let e of n){let n=d(typeof e.getFileName==`function`?e.getFileName():null);if(n&&!(n.includes(`node:internal`)||n.includes(`${a}internal${a}modules${a}`))&&!r(n))return t(n)}for(let e of n){let n=d(typeof e.getFileName==`function`?e.getFileName():null);if(n)return t(n)}}catch{}finally{Error.prepareStackTrace=e}return l()},p=(e,t=`utf8`)=>{let a=l(),c=u(a)??i(a,`..`,`..`,`dist`),d=n(c,`assets`),p=[],m=r(c,f()).split(`\\`).join(`/`).replace(/^(?:dist\/)?(?:esm|cjs)\//,``).replace(/^_virtual\//,``);if(e.startsWith(`./`)||e.startsWith(`../`)){let n=i(d,m,e);if(p.push(n),o(n))return s(n,t)}let h=n(d,e);if(p.push(h),o(h))return s(h,t);if(m){let r=n(d,m,e);if(p.push(r),o(r))return s(r,t)}let g=[`readAsset: file not found.`,`Searched:`,...p.map(e=>`- ${e}`)].join(`
2
+ `);throw Error(g)};export{p as readAsset};