@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,252 +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('../writeContentDeclaration/detectFormatCommand.cjs');
4
- const require_writeContentDeclaration_writeContentDeclaration = require('../writeContentDeclaration/writeContentDeclaration.cjs');
5
- const require_transformFiles_extractDictionaryKey = require('./extractDictionaryKey.cjs');
6
- let _intlayer_config = require("@intlayer/config");
7
- let node_fs_promises = require("node:fs/promises");
8
- node_fs_promises = require_runtime.__toESM(node_fs_promises);
9
- let node_path = require("node:path");
10
- let ts_morph = require("ts-morph");
11
- let node_child_process = require("node:child_process");
12
-
13
- //#region src/transformFiles/transformFiles.ts
14
- /**
15
- * Attributes that should be extracted for localization
16
- */
17
- const ATTRIBUTES_TO_EXTRACT = [
18
- "title",
19
- "placeholder",
20
- "alt",
21
- "aria-label",
22
- "label"
23
- ];
24
- /**
25
- * Default function to determine if a string should be extracted for localization
26
- */
27
- const shouldExtract = (text) => {
28
- const trimmed = text.trim();
29
- if (!trimmed) return false;
30
- if (!trimmed.includes(" ")) return false;
31
- if (!/^[A-Z]/.test(trimmed)) return false;
32
- if (trimmed.startsWith("{") || trimmed.startsWith("v-")) return false;
33
- return true;
34
- };
35
- /**
36
- * Generate a unique key from text for use as a dictionary key
37
- */
38
- const generateKey = (text, existingKeys) => {
39
- let key = text.replace(/\s+/g, " ").replace(/_+/g, " ").replace(/-+/g, " ").replace(/[^a-zA-Z0-9 ]/g, "").trim().split(" ").filter(Boolean).slice(0, 5).map((word, index) => index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
40
- if (!key) key = "content";
41
- if (existingKeys.has(key)) {
42
- let i = 1;
43
- while (existingKeys.has(`${key}${i}`)) i++;
44
- key = `${key}${i}`;
45
- }
46
- return key;
47
- };
48
- const writeContentHelper = async (extractedContent, componentKey, filePath, configuration, outputDir) => {
49
- const { defaultLocale } = configuration.internationalization;
50
- const { baseDir, fileExtensions } = configuration.content;
51
- const isPerLocaleFile = configuration?.dictionary?.locale;
52
- const dirName = outputDir ? (0, node_path.resolve)(outputDir) : (0, node_path.dirname)(filePath);
53
- const baseName = (0, node_path.basename)(filePath, (0, node_path.extname)(filePath));
54
- const contentFilePath = (0, node_path.join)(dirName, `${baseName.charAt(0).toLowerCase() + baseName.slice(1)}.${fileExtensions[0]}`);
55
- const relativeContentFilePath = (0, node_path.relative)(baseDir, contentFilePath);
56
- let dictionary;
57
- if (isPerLocaleFile) dictionary = {
58
- key: componentKey,
59
- content: extractedContent,
60
- locale: defaultLocale,
61
- filePath: relativeContentFilePath
62
- };
63
- else {
64
- const multilingualContent = {};
65
- for (const [key, value] of Object.entries(extractedContent)) multilingualContent[key] = {
66
- nodeType: "translation",
67
- translation: { [defaultLocale]: value }
68
- };
69
- dictionary = {
70
- key: componentKey,
71
- content: multilingualContent,
72
- filePath: relativeContentFilePath
73
- };
74
- }
75
- const relativeDir = (0, node_path.relative)(baseDir, dirName);
76
- await require_writeContentDeclaration_writeContentDeclaration.writeContentDeclaration(dictionary, configuration, { newDictionariesPath: relativeDir });
77
- return contentFilePath;
78
- };
79
- const extractTsContent = (sourceFile, existingKeys) => {
80
- const extractedContent = {};
81
- const replacements = [];
82
- sourceFile.forEachDescendant((node) => {
83
- if (ts_morph.Node.isJsxText(node)) {
84
- const text = node.getText();
85
- if (shouldExtract(text)) {
86
- const key = generateKey(text, existingKeys);
87
- existingKeys.add(key);
88
- extractedContent[key] = text.replace(/\s+/g, " ").trim();
89
- replacements.push({
90
- node,
91
- key,
92
- type: "jsx-text"
93
- });
94
- }
95
- } else if (ts_morph.Node.isJsxAttribute(node)) {
96
- const name = node.getNameNode().getText();
97
- if (ATTRIBUTES_TO_EXTRACT.includes(name)) {
98
- const initializer = node.getInitializer();
99
- if (ts_morph.Node.isStringLiteral(initializer)) {
100
- const text = initializer.getLiteralValue();
101
- if (shouldExtract(text)) {
102
- const key = generateKey(text, existingKeys);
103
- existingKeys.add(key);
104
- extractedContent[key] = text.trim();
105
- replacements.push({
106
- node,
107
- key,
108
- type: "jsx-attribute"
109
- });
110
- }
111
- }
112
- }
113
- } else if (ts_morph.Node.isStringLiteral(node)) {
114
- const text = node.getLiteralValue();
115
- if (shouldExtract(text)) {
116
- const parent = node.getParent();
117
- if (parent?.getKindName() === "ImportDeclaration" || parent?.getKindName() === "ImportSpecifier" || parent?.getKindName() === "ModuleSpecifier") return;
118
- if (ts_morph.Node.isJsxAttribute(parent)) return;
119
- if (ts_morph.Node.isCallExpression(parent)) {
120
- if (parent.getExpression().getText().includes("console.log")) return;
121
- }
122
- if (ts_morph.Node.isPropertyAssignment(parent)) {
123
- if (parent.getNameNode() === node) return;
124
- }
125
- const key = generateKey(text, existingKeys);
126
- existingKeys.add(key);
127
- extractedContent[key] = text.trim();
128
- replacements.push({
129
- node,
130
- key,
131
- type: "string-literal"
132
- });
133
- }
134
- }
135
- });
136
- return {
137
- extractedContent,
138
- replacements
139
- };
140
- };
141
- const processTsxFile = async (filePath, componentKey, packageName, project, save = true) => {
142
- let sourceFile;
143
- try {
144
- sourceFile = project.addSourceFileAtPath(filePath);
145
- } catch {
146
- sourceFile = project.getSourceFileOrThrow(filePath);
147
- }
148
- const isSolid = packageName === "solid-intlayer";
149
- const { extractedContent, replacements } = extractTsContent(sourceFile, /* @__PURE__ */ new Set());
150
- if (Object.keys(extractedContent).length === 0) return null;
151
- for (const { node, key, type } of replacements) {
152
- const contentAccess = isSolid ? `content().${key}` : `content.${key}`;
153
- if (type === "jsx-text" && ts_morph.Node.isJsxText(node)) node.replaceWithText(`{${contentAccess}}`);
154
- else if (type === "jsx-attribute" && ts_morph.Node.isJsxAttribute(node)) node.setInitializer(`{${contentAccess}.value}`);
155
- else if (type === "string-literal" && ts_morph.Node.isStringLiteral(node)) node.replaceWithText(`${contentAccess}.value`);
156
- }
157
- const importDecl = sourceFile.getImportDeclaration((d) => d.getModuleSpecifierValue() === packageName);
158
- if (!importDecl) sourceFile.addImportDeclaration({
159
- namedImports: ["useIntlayer"],
160
- moduleSpecifier: packageName
161
- });
162
- else if (!importDecl.getNamedImports().some((n) => n.getName() === "useIntlayer")) importDecl.addNamedImport("useIntlayer");
163
- sourceFile.getFunctions().forEach((f) => {
164
- f.getBody()?.asKind(ts_morph.SyntaxKind.Block)?.insertStatements(0, `const content = useIntlayer("${componentKey}");`);
165
- });
166
- sourceFile.getVariableDeclarations().forEach((v) => {
167
- const init = v.getInitializer();
168
- if (ts_morph.Node.isArrowFunction(init) || ts_morph.Node.isFunctionExpression(init)) {
169
- const body = init.getBody();
170
- if (ts_morph.Node.isBlock(body)) {
171
- if (body.getText().includes("return") || body.getText().includes("use")) body.insertStatements(0, `const content = useIntlayer("${componentKey}");`);
172
- }
173
- }
174
- });
175
- if (save) await sourceFile.save();
176
- return extractedContent;
177
- };
178
- const extractIntlayer = async (filePath, packageName, options, project) => {
179
- const saveComponent = !options?.declarationOnly;
180
- const writeContent = !options?.codeOnly;
181
- const configuration = (0, _intlayer_config.getConfiguration)(options?.configOptions);
182
- const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
183
- const { baseDir } = configuration.content;
184
- const _project = project || new ts_morph.Project({ skipAddingFilesFromTsConfig: true });
185
- const baseName = require_transformFiles_extractDictionaryKey.extractDictionaryKey(filePath, (await node_fs_promises.default.readFile(filePath)).toString());
186
- const componentKey = (0, _intlayer_config.camelCaseToKebabCase)(baseName);
187
- const ext = (0, node_path.extname)(filePath);
188
- let extractedContent = null;
189
- if (ext === ".vue") try {
190
- const { processVueFile } = await import("@intlayer/vue-transformer");
191
- extractedContent = await processVueFile(filePath, componentKey, packageName, {
192
- generateKey,
193
- shouldExtract,
194
- extractTsContent
195
- }, saveComponent);
196
- } catch (error) {
197
- if (error.code === "ERR_MODULE_NOT_FOUND" || error.message?.includes("Cannot find module")) throw new Error(`Please install ${(0, _intlayer_config.colorizePath)("@intlayer/vue-transformer", _intlayer_config.ANSIColors.YELLOW)} to process Vue files.`);
198
- throw error;
199
- }
200
- else if (ext === ".svelte") try {
201
- const { processSvelteFile } = await import("@intlayer/svelte-transformer");
202
- extractedContent = await processSvelteFile(filePath, componentKey, packageName, {
203
- generateKey,
204
- shouldExtract,
205
- extractTsContent
206
- }, saveComponent);
207
- } catch (error) {
208
- if (error.code === "ERR_MODULE_NOT_FOUND" || error.message?.includes("Cannot find module")) throw new Error(`Please install ${(0, _intlayer_config.colorizePath)("@intlayer/svelte-transformer", _intlayer_config.ANSIColors.YELLOW)} to process Svelte files.`);
209
- throw error;
210
- }
211
- else if ([
212
- ".tsx",
213
- ".jsx",
214
- ".ts",
215
- ".js"
216
- ].includes(ext)) extractedContent = await processTsxFile(filePath, componentKey, packageName, _project, saveComponent);
217
- if (!extractedContent) {
218
- appLogger(`No extractable text found in ${baseName}`);
219
- return;
220
- }
221
- if (writeContent) {
222
- const contentFilePath = await writeContentHelper(extractedContent, componentKey, filePath, configuration, options?.outputDir);
223
- appLogger(`Created content file: ${(0, _intlayer_config.colorizePath)((0, node_path.relative)(configuration.content.baseDir, contentFilePath))}`);
224
- }
225
- if (saveComponent) {
226
- try {
227
- const formatCommand = require_writeContentDeclaration_detectFormatCommand.detectFormatCommand(configuration);
228
- if (formatCommand) (0, node_child_process.execSync)(formatCommand.replace("{{file}}", filePath), {
229
- stdio: "ignore",
230
- cwd: baseDir
231
- });
232
- } catch {}
233
- appLogger(`Updated component: ${(0, _intlayer_config.colorizePath)((0, node_path.relative)(baseDir, filePath))}`);
234
- }
235
- };
236
- const transformFiles = async (filePaths, packageName, options) => {
237
- const appLogger = (0, _intlayer_config.getAppLogger)((0, _intlayer_config.getConfiguration)(options?.configOptions));
238
- const project = new ts_morph.Project({ skipAddingFilesFromTsConfig: true });
239
- for (const filePath of filePaths) try {
240
- await extractIntlayer(filePath, packageName, options, project);
241
- } catch (error) {
242
- appLogger(`Failed to transform ${filePath}: ${error.message}`);
243
- }
244
- };
245
-
246
- //#endregion
247
- exports.ATTRIBUTES_TO_EXTRACT = ATTRIBUTES_TO_EXTRACT;
248
- exports.extractIntlayer = extractIntlayer;
249
- exports.generateKey = generateKey;
250
- exports.shouldExtract = shouldExtract;
251
- exports.transformFiles = transformFiles;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../writeContentDeclaration/detectFormatCommand.cjs`),n=require(`../writeContentDeclaration/writeContentDeclaration.cjs`),r=require(`./extractDictionaryKey.cjs`);let i=require(`@intlayer/config/node`),a=require(`node:fs/promises`);a=e.__toESM(a);let o=require(`node:path`),s=require(`@intlayer/config/logger`),c=require(`@intlayer/config/utils`),l=require(`ts-morph`),u=require(`node:child_process`);const d=[`title`,`placeholder`,`alt`,`aria-label`,`label`],f=e=>{let t=e.trim();return!(!t||!t.includes(` `)||!/^[A-Z]/.test(t)||t.startsWith(`{`)||t.startsWith(`v-`))},p=(e,t)=>{let n=e.replace(/\s+/g,` `).replace(/_+/g,` `).replace(/-+/g,` `).replace(/[^a-zA-Z0-9 ]/g,``).trim().split(` `).filter(Boolean).slice(0,5).map((e,t)=>t===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``);if(n||=`content`,t.has(n)){let e=1;for(;t.has(`${n}${e}`);)e++;n=`${n}${e}`}return n},m=async(e,t,r,i,a)=>{let{defaultLocale:s}=i.internationalization,{baseDir:c,fileExtensions:l}=i.content,u=i?.dictionary?.locale,d=a?(0,o.resolve)(a):(0,o.dirname)(r),f=(0,o.basename)(r,(0,o.extname)(r)),p=(0,o.join)(d,`${f.charAt(0).toLowerCase()+f.slice(1)}.${l[0]}`),m=(0,o.relative)(c,p),h;if(u)h={key:t,content:e,locale:s,filePath:m};else{let n={};for(let[t,r]of Object.entries(e))n[t]={nodeType:`translation`,translation:{[s]:r}};h={key:t,content:n,filePath:m}}let g=(0,o.relative)(c,d);return await n.writeContentDeclaration(h,i,{newDictionariesPath:g}),p},h=(e,t)=>{let n={},r=[];return e.forEachDescendant(e=>{if(l.Node.isJsxText(e)){let i=e.getText();if(f(i)){let a=p(i,t);t.add(a),n[a]=i.replace(/\s+/g,` `).trim(),r.push({node:e,key:a,type:`jsx-text`})}}else if(l.Node.isJsxAttribute(e)){let i=e.getNameNode().getText();if(d.includes(i)){let i=e.getInitializer();if(l.Node.isStringLiteral(i)){let a=i.getLiteralValue();if(f(a)){let i=p(a,t);t.add(i),n[i]=a.trim(),r.push({node:e,key:i,type:`jsx-attribute`})}}}}else if(l.Node.isStringLiteral(e)){let i=e.getLiteralValue();if(f(i)){let a=e.getParent();if(a?.getKindName()===`ImportDeclaration`||a?.getKindName()===`ImportSpecifier`||a?.getKindName()===`ModuleSpecifier`||l.Node.isJsxAttribute(a)||l.Node.isCallExpression(a)&&a.getExpression().getText().includes(`console.log`)||l.Node.isPropertyAssignment(a)&&a.getNameNode()===e)return;let o=p(i,t);t.add(o),n[o]=i.trim(),r.push({node:e,key:o,type:`string-literal`})}}}),{extractedContent:n,replacements:r}},g=async(e,t,n,r,i=!0)=>{let a;try{a=r.addSourceFileAtPath(e)}catch{a=r.getSourceFileOrThrow(e)}let o=n===`solid-intlayer`,{extractedContent:s,replacements:c}=h(a,new Set);if(Object.keys(s).length===0)return null;for(let{node:e,key:t,type:n}of c){let r=o?`content().${t}`:`content.${t}`;n===`jsx-text`&&l.Node.isJsxText(e)?e.replaceWithText(`{${r}}`):n===`jsx-attribute`&&l.Node.isJsxAttribute(e)?e.setInitializer(`{${r}.value}`):n===`string-literal`&&l.Node.isStringLiteral(e)&&e.replaceWithText(`${r}.value`)}let u=a.getImportDeclaration(e=>e.getModuleSpecifierValue()===n);return u?u.getNamedImports().some(e=>e.getName()===`useIntlayer`)||u.addNamedImport(`useIntlayer`):a.addImportDeclaration({namedImports:[`useIntlayer`],moduleSpecifier:n}),a.getFunctions().forEach(e=>{e.getBody()?.asKind(l.SyntaxKind.Block)?.insertStatements(0,`const content = useIntlayer("${t}");`)}),a.getVariableDeclarations().forEach(e=>{let n=e.getInitializer();if(l.Node.isArrowFunction(n)||l.Node.isFunctionExpression(n)){let e=n.getBody();l.Node.isBlock(e)&&(e.getText().includes(`return`)||e.getText().includes(`use`))&&e.insertStatements(0,`const content = useIntlayer("${t}");`)}}),i&&await a.save(),s},_=async(e,n,d,_)=>{let v=!d?.declarationOnly,y=!d?.codeOnly,b=(0,i.getConfiguration)(d?.configOptions),x=(0,s.getAppLogger)(b),{baseDir:S}=b.content,C=_||new l.Project({skipAddingFilesFromTsConfig:!0}),w=r.extractDictionaryKey(e,(await a.default.readFile(e)).toString()),T=(0,c.camelCaseToKebabCase)(w),E=(0,o.extname)(e),D=null;if(E===`.vue`)try{let{processVueFile:t}=await import(`@intlayer/vue-transformer`);D=await t(e,T,n,{generateKey:p,shouldExtract:f,extractTsContent:h},v)}catch(e){throw e.code===`ERR_MODULE_NOT_FOUND`||e.message?.includes(`Cannot find module`)?Error(`Please install ${(0,s.colorizePath)(`@intlayer/vue-transformer`,s.ANSIColors.YELLOW)} to process Vue files.`):e}else if(E===`.svelte`)try{let{processSvelteFile:t}=await import(`@intlayer/svelte-transformer`);D=await t(e,T,n,{generateKey:p,shouldExtract:f,extractTsContent:h},v)}catch(e){throw e.code===`ERR_MODULE_NOT_FOUND`||e.message?.includes(`Cannot find module`)?Error(`Please install ${(0,s.colorizePath)(`@intlayer/svelte-transformer`,s.ANSIColors.YELLOW)} to process Svelte files.`):e}else [`.tsx`,`.jsx`,`.ts`,`.js`].includes(E)&&(D=await g(e,T,n,C,v));if(!D){x(`No extractable text found in ${w}`);return}if(y){let t=await m(D,T,e,b,d?.outputDir);x(`Created content file: ${(0,s.colorizePath)((0,o.relative)(b.content.baseDir,t))}`)}if(v){try{let n=t.detectFormatCommand(b);n&&(0,u.execSync)(n.replace(`{{file}}`,e),{stdio:`ignore`,cwd:S})}catch{}x(`Updated component: ${(0,s.colorizePath)((0,o.relative)(S,e))}`)}},v=async(e,t,n)=>{let r=(0,s.getAppLogger)((0,i.getConfiguration)(n?.configOptions)),a=new l.Project({skipAddingFilesFromTsConfig:!0});for(let i of e)try{await _(i,t,n,a)}catch(e){r(`Failed to transform ${i}: ${e.message}`)}};exports.ATTRIBUTES_TO_EXTRACT=d,exports.extractIntlayer=_,exports.generateKey=p,exports.shouldExtract=f,exports.transformFiles=v;
252
2
  //# sourceMappingURL=transformFiles.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformFiles.cjs","names":["writeContentDeclaration","Node","SyntaxKind","Project","extractDictionaryKey","fs","ANSIColors","detectFormatCommand"],"sources":["../../../src/transformFiles/transformFiles.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path';\nimport {\n ANSIColors,\n camelCaseToKebabCase,\n colorizePath,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';\nimport { writeContentDeclaration } from '../writeContentDeclaration';\nimport { detectFormatCommand } from '../writeContentDeclaration/detectFormatCommand';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\n// ==========================================\n// Shared Utilities (exported for reuse in babel plugin)\n// ==========================================\n\n/**\n * Attributes that should be extracted for localization\n */\nexport const ATTRIBUTES_TO_EXTRACT = [\n 'title',\n 'placeholder',\n 'alt',\n 'aria-label',\n 'label',\n];\n\n/**\n * Default function to determine if a string should be extracted for localization\n */\nexport const shouldExtract = (text: string): boolean => {\n const trimmed = text.trim();\n if (!trimmed) return false;\n if (!trimmed.includes(' ')) return false;\n // Starts with Capital letter\n if (!/^[A-Z]/.test(trimmed)) return false;\n // Filter out template logic identifiers (simple check)\n if (trimmed.startsWith('{') || trimmed.startsWith('v-')) return false;\n return true;\n};\n\n/**\n * Generate a unique key from text for use as a dictionary key\n */\nexport const generateKey = (\n text: string,\n existingKeys: Set<string>\n): string => {\n const maxWords = 5;\n let key = text\n .replace(/\\s+/g, ' ')\n .replace(/_+/g, ' ')\n .replace(/-+/g, ' ')\n .replace(/[^a-zA-Z0-9 ]/g, '')\n .trim()\n .split(' ')\n .filter(Boolean)\n .slice(0, maxWords)\n .map((word, index) =>\n index === 0\n ? word.toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n )\n .join('');\n\n if (!key) key = 'content';\n if (existingKeys.has(key)) {\n let i = 1;\n while (existingKeys.has(`${key}${i}`)) i++;\n key = `${key}${i}`;\n }\n return key;\n};\n\n/**\n * Translation node structure used in multilingual dictionaries\n */\ntype TranslationNode = {\n nodeType: 'translation';\n translation: Record<string, string>;\n};\n\nconst writeContentHelper = async (\n extractedContent: Record<string, string>,\n componentKey: string,\n filePath: string,\n configuration: IntlayerConfig,\n outputDir?: string\n) => {\n const { defaultLocale } = configuration.internationalization;\n const { baseDir, fileExtensions } = configuration.content;\n\n const isPerLocaleFile = configuration?.dictionary?.locale;\n\n const dirName = outputDir ? resolve(outputDir) : dirname(filePath);\n const ext = extname(filePath);\n const baseName = basename(filePath, ext);\n const contentBaseName = baseName.charAt(0).toLowerCase() + baseName.slice(1);\n\n const contentFilePath = join(\n dirName,\n `${contentBaseName}.${fileExtensions[0]}`\n );\n const relativeContentFilePath = relative(baseDir, contentFilePath);\n\n let dictionary: Dictionary;\n\n if (isPerLocaleFile) {\n // Per-locale format: simple string content with locale property\n dictionary = {\n key: componentKey,\n content: extractedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\n };\n } else {\n // Multilingual format: content wrapped in translation nodes, no locale property\n const multilingualContent: Record<string, TranslationNode> = {};\n for (const [key, value] of Object.entries(extractedContent)) {\n multilingualContent[key] = {\n nodeType: 'translation',\n translation: {\n [defaultLocale]: value,\n },\n };\n }\n\n dictionary = {\n key: componentKey,\n content: multilingualContent,\n filePath: relativeContentFilePath,\n };\n }\n\n const relativeDir = relative(baseDir, dirName);\n await writeContentDeclaration(dictionary, configuration, {\n newDictionariesPath: relativeDir,\n });\n\n return contentFilePath;\n};\n\ntype TsReplacement = {\n node: Node;\n key: string;\n type: 'jsx-text' | 'jsx-attribute' | 'string-literal';\n};\n\nconst extractTsContent = (\n sourceFile: SourceFile,\n existingKeys: Set<string>\n): {\n extractedContent: Record<string, string>;\n replacements: TsReplacement[];\n} => {\n const extractedContent: Record<string, string> = {};\n const replacements: TsReplacement[] = [];\n\n sourceFile.forEachDescendant((node) => {\n // 1. JSX Text\n if (Node.isJsxText(node)) {\n const text = node.getText();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.replace(/\\s+/g, ' ').trim();\n replacements.push({ node, key, type: 'jsx-text' });\n }\n }\n\n // 2. JSX Attributes\n else if (Node.isJsxAttribute(node)) {\n const name = node.getNameNode().getText();\n if (ATTRIBUTES_TO_EXTRACT.includes(name)) {\n const initializer = node.getInitializer();\n if (Node.isStringLiteral(initializer)) {\n const text = initializer.getLiteralValue();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'jsx-attribute' });\n }\n }\n }\n }\n\n // 3. String Literals (Variables, Arrays, etc.)\n else if (Node.isStringLiteral(node)) {\n const text = node.getLiteralValue();\n if (shouldExtract(text)) {\n const parent = node.getParent();\n\n // Skip if inside ImportDeclaration\n if (\n parent?.getKindName() === 'ImportDeclaration' ||\n parent?.getKindName() === 'ImportSpecifier' ||\n parent?.getKindName() === 'ModuleSpecifier'\n ) {\n return;\n }\n\n // Skip if it's a JSX Attribute value (handled above)\n if (Node.isJsxAttribute(parent)) return;\n\n // Skip console.log\n if (Node.isCallExpression(parent)) {\n const expression = parent.getExpression();\n if (expression.getText().includes('console.log')) return;\n }\n\n // Skip Object Keys: { key: \"value\" } -> \"key\" is PropertyAssignment name if not computed\n if (Node.isPropertyAssignment(parent)) {\n if (parent.getNameNode() === node) return; // It's the key\n }\n\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'string-literal' });\n }\n }\n });\n\n return { extractedContent, replacements };\n};\n\n// ==========================================\n// React (TS-Morph) Strategy\n// ==========================================\n\nconst processTsxFile = async (\n filePath: string,\n componentKey: string,\n packageName: PackageName,\n project: Project,\n save: boolean = true\n) => {\n let sourceFile: SourceFile;\n try {\n sourceFile = project.addSourceFileAtPath(filePath);\n } catch {\n sourceFile = project.getSourceFileOrThrow(filePath);\n }\n\n const isSolid = packageName === 'solid-intlayer';\n\n const existingKeys = new Set<string>();\n const { extractedContent, replacements } = extractTsContent(\n sourceFile,\n existingKeys\n );\n\n if (Object.keys(extractedContent).length === 0) return null;\n\n for (const { node, key, type } of replacements) {\n const contentAccess = isSolid ? `content().${key}` : `content.${key}`;\n\n if (type === 'jsx-text' && Node.isJsxText(node)) {\n node.replaceWithText(`{${contentAccess}}`);\n } else if (type === 'jsx-attribute' && Node.isJsxAttribute(node)) {\n node.setInitializer(`{${contentAccess}.value}`);\n } else if (type === 'string-literal' && Node.isStringLiteral(node)) {\n // For React/JS variables, we usually want the value\n node.replaceWithText(`${contentAccess}.value`);\n }\n }\n\n // Inject hook\n const importDecl = sourceFile.getImportDeclaration(\n (d) => d.getModuleSpecifierValue() === packageName\n );\n if (!importDecl) {\n sourceFile.addImportDeclaration({\n namedImports: ['useIntlayer'],\n moduleSpecifier: packageName,\n });\n } else if (\n !importDecl.getNamedImports().some((n) => n.getName() === 'useIntlayer')\n ) {\n importDecl.addNamedImport('useIntlayer');\n }\n\n // Insert hook at start of component\n sourceFile.getFunctions().forEach((f) => {\n f.getBody()\n ?.asKind(SyntaxKind.Block)\n ?.insertStatements(0, `const content = useIntlayer(\"${componentKey}\");`);\n });\n\n // Also handle const/arrow components\n sourceFile.getVariableDeclarations().forEach((v) => {\n const init = v.getInitializer();\n if (Node.isArrowFunction(init) || Node.isFunctionExpression(init)) {\n const body = init.getBody();\n if (Node.isBlock(body)) {\n // Heuristic: check if it returns JSX or uses hooks\n if (\n body.getText().includes('return') ||\n body.getText().includes('use')\n ) {\n body.insertStatements(\n 0,\n `const content = useIntlayer(\"${componentKey}\");`\n );\n }\n }\n }\n });\n\n if (save) {\n await sourceFile.save();\n }\n return extractedContent;\n};\n\n// ==========================================\n// 5. Main Dispatcher\n// ==========================================\n\nexport type PackageName =\n | 'next-intlayer'\n | 'react-intlayer'\n | 'vue-intlayer'\n | 'svelte-intlayer'\n | 'preact-intlayer'\n | 'solid-intlayer'\n | 'angular-intlayer'\n | 'express-intlayer';\n\nexport type ExtractIntlayerOptions = {\n configOptions?: GetConfigurationOptions;\n outputDir?: string;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n};\n\nexport const extractIntlayer = async (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions,\n project?: Project\n) => {\n const saveComponent = !options?.declarationOnly;\n const writeContent = !options?.codeOnly;\n\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n const { baseDir } = configuration.content;\n\n // Setup Project for TS/React files if needed\n const _project =\n project || new Project({ skipAddingFilesFromTsConfig: true });\n\n const baseName = extractDictionaryKey(\n filePath,\n (await fs.readFile(filePath)).toString()\n );\n const componentKey = camelCaseToKebabCase(baseName);\n const ext = extname(filePath);\n\n let extractedContent: Record<string, string> | null = null;\n\n if (ext === '.vue') {\n try {\n const { processVueFile } = await import('@intlayer/vue-transformer');\n extractedContent = await processVueFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/vue-transformer', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n throw error;\n }\n } else if (ext === '.svelte') {\n try {\n const { processSvelteFile } = (await import(\n '@intlayer/svelte-transformer'\n )) as any;\n extractedContent = await processSvelteFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/svelte-transformer', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n throw error;\n }\n } else if (['.tsx', '.jsx', '.ts', '.js'].includes(ext)) {\n extractedContent = await processTsxFile(\n filePath,\n componentKey,\n packageName,\n _project,\n saveComponent\n );\n }\n\n if (!extractedContent) {\n appLogger(`No extractable text found in ${baseName}`);\n return;\n }\n\n // Shared Write Logic\n if (writeContent) {\n const contentFilePath = await writeContentHelper(\n extractedContent,\n componentKey,\n filePath,\n configuration,\n options?.outputDir\n );\n\n const relativeContentFilePath = relative(\n configuration.content.baseDir,\n contentFilePath\n );\n appLogger(`Created content file: ${colorizePath(relativeContentFilePath)}`);\n }\n\n // Optional: Format\n if (saveComponent) {\n try {\n const formatCommand = detectFormatCommand(configuration);\n if (formatCommand) {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'ignore', // Silent\n cwd: baseDir,\n });\n }\n } catch {\n // Ignore format errors\n }\n\n appLogger(\n `Updated component: ${colorizePath(relative(baseDir, filePath))}`\n );\n }\n};\n\nexport const transformFiles = async (\n filePaths: string[],\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n) => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n });\n\n for (const filePath of filePaths) {\n try {\n await extractIntlayer(filePath, packageName, options, project);\n } catch (error) {\n appLogger(`Failed to transform ${filePath}: ${(error as Error).message}`);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACD;;;;AAKD,MAAa,iBAAiB,SAA0B;CACtD,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,KAAI,CAAC,QAAQ,SAAS,IAAI,CAAE,QAAO;AAEnC,KAAI,CAAC,SAAS,KAAK,QAAQ,CAAE,QAAO;AAEpC,KAAI,QAAQ,WAAW,IAAI,IAA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,MAAM,EAAE,sBAAuB,MAAM,OACnC;AAEF,qBAAmB,MAAM,kBACvB,UACA,cACA,aACA;GACE;GACA;GACA;GACD,EACD,cACD;UACM,OAAY;AACnB,MACE,MAAM,SAAS,0BACf,MAAM,SAAS,SAAS,qBAAqB,CAE7C,OAAM,IAAI,MACR,qDAA+B,gCAAgCA,4BAAW,OAAO,CAAC,2BACnF;AAEH,QAAM;;UAEC;EAAC;EAAQ;EAAQ;EAAO;EAAM,CAAC,SAAS,IAAI,CACrD,oBAAmB,MAAM,eACvB,UACA,cACA,aACA,UACA,cACD;AAGH,KAAI,CAAC,kBAAkB;AACrB,YAAU,gCAAgC,WAAW;AACrD;;AAIF,KAAI,cAAc;EAChB,MAAM,kBAAkB,MAAM,mBAC5B,kBACA,cACA,UACA,eACA,SAAS,UACV;AAMD,YAAU,oFAHR,cAAc,QAAQ,SACtB,gBACD,CACuE,GAAG;;AAI7E,KAAI,eAAe;AACjB,MAAI;GACF,MAAM,gBAAgBC,wEAAoB,cAAc;AACxD,OAAI,cACF,kCAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;IACpD,OAAO;IACP,KAAK;IACN,CAAC;UAEE;AAIR,YACE,iFAA4C,SAAS,SAAS,CAAC,GAChE;;;AAIL,MAAa,iBAAiB,OAC5B,WACA,aACA,YACG;CAEH,MAAM,sFADiC,SAAS,cAAc,CACjB;CAE7C,MAAM,UAAU,IAAIJ,iBAAQ,EAC1B,6BAA6B,MAC9B,CAAC;AAEF,MAAK,MAAM,YAAY,UACrB,KAAI;AACF,QAAM,gBAAgB,UAAU,aAAa,SAAS,QAAQ;UACvD,OAAO;AACd,YAAU,uBAAuB,SAAS,IAAK,MAAgB,UAAU"}
1
+ {"version":3,"file":"transformFiles.cjs","names":["writeContentDeclaration","Node","SyntaxKind","Project","extractDictionaryKey","fs","ANSIColors","detectFormatCommand"],"sources":["../../../src/transformFiles/transformFiles.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path';\nimport {\n ANSIColors,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { camelCaseToKebabCase } from '@intlayer/config/utils';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';\nimport { writeContentDeclaration } from '../writeContentDeclaration';\nimport { detectFormatCommand } from '../writeContentDeclaration/detectFormatCommand';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\n// ==========================================\n// Shared Utilities (exported for reuse in babel plugin)\n// ==========================================\n\n/**\n * Attributes that should be extracted for localization\n */\nexport const ATTRIBUTES_TO_EXTRACT = [\n 'title',\n 'placeholder',\n 'alt',\n 'aria-label',\n 'label',\n];\n\n/**\n * Default function to determine if a string should be extracted for localization\n */\nexport const shouldExtract = (text: string): boolean => {\n const trimmed = text.trim();\n if (!trimmed) return false;\n if (!trimmed.includes(' ')) return false;\n // Starts with Capital letter\n if (!/^[A-Z]/.test(trimmed)) return false;\n // Filter out template logic identifiers (simple check)\n if (trimmed.startsWith('{') || trimmed.startsWith('v-')) return false;\n return true;\n};\n\n/**\n * Generate a unique key from text for use as a dictionary key\n */\nexport const generateKey = (\n text: string,\n existingKeys: Set<string>\n): string => {\n const maxWords = 5;\n let key = text\n .replace(/\\s+/g, ' ')\n .replace(/_+/g, ' ')\n .replace(/-+/g, ' ')\n .replace(/[^a-zA-Z0-9 ]/g, '')\n .trim()\n .split(' ')\n .filter(Boolean)\n .slice(0, maxWords)\n .map((word, index) =>\n index === 0\n ? word.toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n )\n .join('');\n\n if (!key) key = 'content';\n if (existingKeys.has(key)) {\n let i = 1;\n while (existingKeys.has(`${key}${i}`)) i++;\n key = `${key}${i}`;\n }\n return key;\n};\n\n/**\n * Translation node structure used in multilingual dictionaries\n */\ntype TranslationNode = {\n nodeType: 'translation';\n translation: Record<string, string>;\n};\n\nconst writeContentHelper = async (\n extractedContent: Record<string, string>,\n componentKey: string,\n filePath: string,\n configuration: IntlayerConfig,\n outputDir?: string\n) => {\n const { defaultLocale } = configuration.internationalization;\n const { baseDir, fileExtensions } = configuration.content;\n\n const isPerLocaleFile = configuration?.dictionary?.locale;\n\n const dirName = outputDir ? resolve(outputDir) : dirname(filePath);\n const ext = extname(filePath);\n const baseName = basename(filePath, ext);\n const contentBaseName = baseName.charAt(0).toLowerCase() + baseName.slice(1);\n\n const contentFilePath = join(\n dirName,\n `${contentBaseName}.${fileExtensions[0]}`\n );\n const relativeContentFilePath = relative(baseDir, contentFilePath);\n\n let dictionary: Dictionary;\n\n if (isPerLocaleFile) {\n // Per-locale format: simple string content with locale property\n dictionary = {\n key: componentKey,\n content: extractedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\n };\n } else {\n // Multilingual format: content wrapped in translation nodes, no locale property\n const multilingualContent: Record<string, TranslationNode> = {};\n for (const [key, value] of Object.entries(extractedContent)) {\n multilingualContent[key] = {\n nodeType: 'translation',\n translation: {\n [defaultLocale]: value,\n },\n };\n }\n\n dictionary = {\n key: componentKey,\n content: multilingualContent,\n filePath: relativeContentFilePath,\n };\n }\n\n const relativeDir = relative(baseDir, dirName);\n await writeContentDeclaration(dictionary, configuration, {\n newDictionariesPath: relativeDir,\n });\n\n return contentFilePath;\n};\n\ntype TsReplacement = {\n node: Node;\n key: string;\n type: 'jsx-text' | 'jsx-attribute' | 'string-literal';\n};\n\nconst extractTsContent = (\n sourceFile: SourceFile,\n existingKeys: Set<string>\n): {\n extractedContent: Record<string, string>;\n replacements: TsReplacement[];\n} => {\n const extractedContent: Record<string, string> = {};\n const replacements: TsReplacement[] = [];\n\n sourceFile.forEachDescendant((node) => {\n // 1. JSX Text\n if (Node.isJsxText(node)) {\n const text = node.getText();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.replace(/\\s+/g, ' ').trim();\n replacements.push({ node, key, type: 'jsx-text' });\n }\n }\n\n // 2. JSX Attributes\n else if (Node.isJsxAttribute(node)) {\n const name = node.getNameNode().getText();\n if (ATTRIBUTES_TO_EXTRACT.includes(name)) {\n const initializer = node.getInitializer();\n if (Node.isStringLiteral(initializer)) {\n const text = initializer.getLiteralValue();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'jsx-attribute' });\n }\n }\n }\n }\n\n // 3. String Literals (Variables, Arrays, etc.)\n else if (Node.isStringLiteral(node)) {\n const text = node.getLiteralValue();\n if (shouldExtract(text)) {\n const parent = node.getParent();\n\n // Skip if inside ImportDeclaration\n if (\n parent?.getKindName() === 'ImportDeclaration' ||\n parent?.getKindName() === 'ImportSpecifier' ||\n parent?.getKindName() === 'ModuleSpecifier'\n ) {\n return;\n }\n\n // Skip if it's a JSX Attribute value (handled above)\n if (Node.isJsxAttribute(parent)) return;\n\n // Skip console.log\n if (Node.isCallExpression(parent)) {\n const expression = parent.getExpression();\n if (expression.getText().includes('console.log')) return;\n }\n\n // Skip Object Keys: { key: \"value\" } -> \"key\" is PropertyAssignment name if not computed\n if (Node.isPropertyAssignment(parent)) {\n if (parent.getNameNode() === node) return; // It's the key\n }\n\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'string-literal' });\n }\n }\n });\n\n return { extractedContent, replacements };\n};\n\n// ==========================================\n// React (TS-Morph) Strategy\n// ==========================================\n\nconst processTsxFile = async (\n filePath: string,\n componentKey: string,\n packageName: PackageName,\n project: Project,\n save: boolean = true\n) => {\n let sourceFile: SourceFile;\n try {\n sourceFile = project.addSourceFileAtPath(filePath);\n } catch {\n sourceFile = project.getSourceFileOrThrow(filePath);\n }\n\n const isSolid = packageName === 'solid-intlayer';\n\n const existingKeys = new Set<string>();\n const { extractedContent, replacements } = extractTsContent(\n sourceFile,\n existingKeys\n );\n\n if (Object.keys(extractedContent).length === 0) return null;\n\n for (const { node, key, type } of replacements) {\n const contentAccess = isSolid ? `content().${key}` : `content.${key}`;\n\n if (type === 'jsx-text' && Node.isJsxText(node)) {\n node.replaceWithText(`{${contentAccess}}`);\n } else if (type === 'jsx-attribute' && Node.isJsxAttribute(node)) {\n node.setInitializer(`{${contentAccess}.value}`);\n } else if (type === 'string-literal' && Node.isStringLiteral(node)) {\n // For React/JS variables, we usually want the value\n node.replaceWithText(`${contentAccess}.value`);\n }\n }\n\n // Inject hook\n const importDecl = sourceFile.getImportDeclaration(\n (d) => d.getModuleSpecifierValue() === packageName\n );\n if (!importDecl) {\n sourceFile.addImportDeclaration({\n namedImports: ['useIntlayer'],\n moduleSpecifier: packageName,\n });\n } else if (\n !importDecl.getNamedImports().some((n) => n.getName() === 'useIntlayer')\n ) {\n importDecl.addNamedImport('useIntlayer');\n }\n\n // Insert hook at start of component\n sourceFile.getFunctions().forEach((f) => {\n f.getBody()\n ?.asKind(SyntaxKind.Block)\n ?.insertStatements(0, `const content = useIntlayer(\"${componentKey}\");`);\n });\n\n // Also handle const/arrow components\n sourceFile.getVariableDeclarations().forEach((v) => {\n const init = v.getInitializer();\n if (Node.isArrowFunction(init) || Node.isFunctionExpression(init)) {\n const body = init.getBody();\n if (Node.isBlock(body)) {\n // Heuristic: check if it returns JSX or uses hooks\n if (\n body.getText().includes('return') ||\n body.getText().includes('use')\n ) {\n body.insertStatements(\n 0,\n `const content = useIntlayer(\"${componentKey}\");`\n );\n }\n }\n }\n });\n\n if (save) {\n await sourceFile.save();\n }\n return extractedContent;\n};\n\n// ==========================================\n// 5. Main Dispatcher\n// ==========================================\n\nexport type PackageName =\n | 'next-intlayer'\n | 'react-intlayer'\n | 'vue-intlayer'\n | 'svelte-intlayer'\n | 'preact-intlayer'\n | 'solid-intlayer'\n | 'angular-intlayer'\n | 'express-intlayer';\n\nexport type ExtractIntlayerOptions = {\n configOptions?: GetConfigurationOptions;\n outputDir?: string;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n};\n\nexport const extractIntlayer = async (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions,\n project?: Project\n) => {\n const saveComponent = !options?.declarationOnly;\n const writeContent = !options?.codeOnly;\n\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n const { baseDir } = configuration.content;\n\n // Setup Project for TS/React files if needed\n const _project =\n project || new Project({ skipAddingFilesFromTsConfig: true });\n\n const baseName = extractDictionaryKey(\n filePath,\n (await fs.readFile(filePath)).toString()\n );\n const componentKey = camelCaseToKebabCase(baseName);\n const ext = extname(filePath);\n\n let extractedContent: Record<string, string> | null = null;\n\n if (ext === '.vue') {\n try {\n const { processVueFile } = await import('@intlayer/vue-transformer');\n extractedContent = await processVueFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/vue-transformer', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n throw error;\n }\n } else if (ext === '.svelte') {\n try {\n const { processSvelteFile } = (await import(\n '@intlayer/svelte-transformer'\n )) as any;\n extractedContent = await processSvelteFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/svelte-transformer', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n throw error;\n }\n } else if (['.tsx', '.jsx', '.ts', '.js'].includes(ext)) {\n extractedContent = await processTsxFile(\n filePath,\n componentKey,\n packageName,\n _project,\n saveComponent\n );\n }\n\n if (!extractedContent) {\n appLogger(`No extractable text found in ${baseName}`);\n return;\n }\n\n // Shared Write Logic\n if (writeContent) {\n const contentFilePath = await writeContentHelper(\n extractedContent,\n componentKey,\n filePath,\n configuration,\n options?.outputDir\n );\n\n const relativeContentFilePath = relative(\n configuration.content.baseDir,\n contentFilePath\n );\n appLogger(`Created content file: ${colorizePath(relativeContentFilePath)}`);\n }\n\n // Optional: Format\n if (saveComponent) {\n try {\n const formatCommand = detectFormatCommand(configuration);\n if (formatCommand) {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'ignore', // Silent\n cwd: baseDir,\n });\n }\n } catch {\n // Ignore format errors\n }\n\n appLogger(\n `Updated component: ${colorizePath(relative(baseDir, filePath))}`\n );\n }\n};\n\nexport const transformFiles = async (\n filePaths: string[],\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n) => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n });\n\n for (const filePath of filePaths) {\n try {\n await extractIntlayer(filePath, packageName, options, project);\n } catch (error) {\n appLogger(`Failed to transform ${filePath}: ${(error as Error).message}`);\n }\n }\n};\n"],"mappings":"khBA0BA,MAAa,EAAwB,CACnC,QACA,cACA,MACA,aACA,QACD,CAKY,EAAiB,GAA0B,CACtD,IAAM,EAAU,EAAK,MAAM,CAO3B,MADA,EALI,CAAC,GACD,CAAC,EAAQ,SAAS,IAAI,EAEtB,CAAC,SAAS,KAAK,EAAQ,EAEvB,EAAQ,WAAW,IAAI,EAAI,EAAQ,WAAW,KAAK,GAO5C,GACX,EACA,IACW,CAEX,IAAI,EAAM,EACP,QAAQ,OAAQ,IAAI,CACpB,QAAQ,MAAO,IAAI,CACnB,QAAQ,MAAO,IAAI,CACnB,QAAQ,iBAAkB,GAAG,CAC7B,MAAM,CACN,MAAM,IAAI,CACV,OAAO,QAAQ,CACf,MAAM,EATQ,EASI,CAClB,KAAK,EAAM,IACV,IAAU,EACN,EAAK,aAAa,CA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AAQ,OAAQ,MAAO,MAAM,CAAC,SAAS,EAAI,GACrD,EAAmB,MAAM,EACvB,EACA,EACA,EACA,EACA,EACD,EAGH,GAAI,CAAC,EAAkB,CACrB,EAAU,gCAAgC,IAAW,CACrD,OAIF,GAAI,EAAc,CAChB,IAAM,EAAkB,MAAM,EAC5B,EACA,EACA,EACA,EACA,GAAS,UACV,CAMD,EAAU,0BAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAHR,EAAc,QAAQ,QACtB,EACD,CACuE,GAAG,CAI7E,GAAI,EAAe,CACjB,GAAI,CACF,IAAM,EAAgBC,EAAAA,oBAAoB,EAAc,CACpD,IACF,EAAA,EAAA,UAAS,EAAc,QAAQ,WAAY,EAAS,CAAE,CACpD,MAAO,SACP,IAAK,EACN,CAAC,MAEE,EAIR,EACE,uBAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAA4C,EAAS,EAAS,CAAC,GAChE,GAIQ,EAAiB,MAC5B,EACA,EACA,IACG,CAEH,IAAM,GAAA,EAAA,EAAA,eAAA,EAAA,EAAA,kBADiC,GAAS,cAAc,CACjB,CAEvC,EAAU,IAAIJ,EAAAA,QAAQ,CAC1B,4BAA6B,GAC9B,CAAC,CAEF,IAAK,IAAM,KAAY,EACrB,GAAI,CACF,MAAM,EAAgB,EAAU,EAAa,EAAS,EAAQ,OACvD,EAAO,CACd,EAAU,uBAAuB,EAAS,IAAK,EAAgB,UAAU"}
@@ -1,88 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_core = require("@intlayer/core");
4
- let _intlayer_types = require("@intlayer/types");
5
-
6
- //#region src/utils/autoDecorateContent.ts
7
- /**
8
- * Check if a string is a markdown string
9
- */
10
- const isMarkdown = (str) => {
11
- return [
12
- /^\s*---/m,
13
- /^\s*#+\s/m,
14
- /^\s*[-*+]\s/m,
15
- /^\s*\d+\.\s/m,
16
- /^\s*>\s/m,
17
- /\[.+\]\(.+\)/,
18
- /!\[.+\]\(.+\)/,
19
- /`{1,3}.+`{1,3}/,
20
- /\*\*.+\*\*/,
21
- /__.+__/,
22
- /<(https?:\/\/[^\s>]+)>/
23
- ].some((pattern) => pattern.test(str));
24
- };
25
- /**
26
- * Check if a string is an insertion string
27
- */
28
- const isInsertion = (str) => (0, _intlayer_core.getInsertionValues)(str).length > 0;
29
- /**
30
- * Check if a string is an HTML/JSX string
31
- * Matches:
32
- * - <Tag>
33
- * - </Tag>
34
- * - <Tag />
35
- * - <Tag attribute="value">
36
- * - <Component.SubComponent>
37
- */
38
- const isHTML = (str) => {
39
- return /<[a-zA-Z][a-zA-Z0-9\-.]*(\s+[^>]*)?\/?>/.test(str) || /<\/[a-zA-Z][a-zA-Z0-9\-.]*\s*>/.test(str);
40
- };
41
- const leafNodeTypes = [
42
- _intlayer_types.NodeType.HTML,
43
- _intlayer_types.NodeType.Markdown,
44
- _intlayer_types.NodeType.Insertion,
45
- _intlayer_types.NodeType.File,
46
- _intlayer_types.NodeType.ReactNode,
47
- _intlayer_types.NodeType.Text,
48
- _intlayer_types.NodeType.Number,
49
- _intlayer_types.NodeType.Boolean,
50
- _intlayer_types.NodeType.Null,
51
- _intlayer_types.NodeType.Unknown
52
- ];
53
- /**
54
- * Automatically decorate content strings with md() or insert() if they match
55
- */
56
- const autoDecorateContent = (content, options = true) => {
57
- if (options === false) return content;
58
- const { markdown = true, html: htmlOption = true, insertion = true } = typeof options === "object" ? options : {};
59
- if (typeof content === "string") {
60
- if (markdown && isMarkdown(content)) return {
61
- ...(0, _intlayer_core.md)(content),
62
- metadata: (0, _intlayer_core.getMarkdownMetadata)(content)
63
- };
64
- if (htmlOption && isHTML(content)) return (0, _intlayer_core.html)(content);
65
- if (insertion && isInsertion(content)) return (0, _intlayer_core.insert)(content);
66
- return content;
67
- }
68
- if (Array.isArray(content)) return content.map((item) => autoDecorateContent(item, options));
69
- if (content && typeof content === "object") {
70
- if ("nodeType" in content) {
71
- const nodeType = content.nodeType;
72
- if (leafNodeTypes.includes(nodeType)) return content;
73
- if (nodeType in content) return {
74
- ...content,
75
- [nodeType]: autoDecorateContent(content[nodeType], options)
76
- };
77
- return content;
78
- }
79
- const result = {};
80
- for (const key of Object.keys(content)) result[key] = autoDecorateContent(content[key], options);
81
- return result;
82
- }
83
- return content;
84
- };
85
-
86
- //#endregion
87
- exports.autoDecorateContent = autoDecorateContent;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/types`),t=require(`@intlayer/core/markdown`),n=require(`@intlayer/core/transpiler`);const r=e=>[/^\s*---/m,/^\s*#+\s/m,/^\s*[-*+]\s/m,/^\s*\d+\.\s/m,/^\s*>\s/m,/\[.+\]\(.+\)/,/!\[.+\]\(.+\)/,/`{1,3}.+`{1,3}/,/\*\*.+\*\*/,/__.+__/,/<(https?:\/\/[^\s>]+)>/].some(t=>t.test(e)),i=e=>(0,n.getInsertionValues)(e).length>0,a=e=>/<[a-zA-Z][a-zA-Z0-9\-.]*(\s+[^>]*)?\/?>/.test(e)||/<\/[a-zA-Z][a-zA-Z0-9\-.]*\s*>/.test(e),o=[e.NodeType.HTML,e.NodeType.Markdown,e.NodeType.Insertion,e.NodeType.File,e.NodeType.ReactNode,e.NodeType.Text,e.NodeType.Number,e.NodeType.Boolean,e.NodeType.Null,e.NodeType.Unknown],s=(e,c=!0)=>{if(c===!1)return e;let{markdown:l=!0,html:u=!0,insertion:d=!0}=typeof c==`object`?c:{};if(typeof e==`string`)return l&&r(e)?{...(0,n.md)(e),metadata:(0,t.getMarkdownMetadata)(e)}:u&&a(e)?(0,n.html)(e):d&&i(e)?(0,n.insert)(e):e;if(Array.isArray(e))return e.map(e=>s(e,c));if(e&&typeof e==`object`){if(`nodeType`in e){let t=e.nodeType;return o.includes(t)?e:t in e?{...e,[t]:s(e[t],c)}:e}let t={};for(let n of Object.keys(e))t[n]=s(e[n],c);return t}return e};exports.autoDecorateContent=s;
88
2
  //# sourceMappingURL=autoDecorateContent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"autoDecorateContent.cjs","names":["NodeType"],"sources":["../../../src/utils/autoDecorateContent.ts"],"sourcesContent":["import {\n getInsertionValues,\n getMarkdownMetadata,\n html,\n insert,\n md,\n} from '@intlayer/core';\nimport { NodeType } from '@intlayer/types';\n\n/**\n * Check if a string is a markdown string\n */\nconst isMarkdown = (str: string): boolean => {\n // Check for common markdown indicators\n const patterns = [\n /^\\s*---/m, // Front Matter\n /^\\s*#+\\s/m, // Headers: # Title\n /^\\s*[-*+]\\s/m, // Unordered lists: - Item or * Item\n /^\\s*\\d+\\.\\s/m, // Ordered lists: 1. Item\n /^\\s*>\\s/m, // Blockquotes: > Quote\n /\\[.+\\]\\(.+\\)/, // Links: [text](url)\n /!\\[.+\\]\\(.+\\)/, // Images: ![alt](url)\n /`{1,3}.+`{1,3}/, // Code blocks or inline code: `code` or ```code```\n /\\*\\*.+\\*\\*/, // Bold: **text**\n /__.+__/, // Bold: __text__\n /<(https?:\\/\\/[^\\s>]+)>/, // Autolinks: <http://...>\n ];\n\n return patterns.some((pattern) => pattern.test(str));\n};\n\n/**\n * Check if a string is an insertion string\n */\nconst isInsertion = (str: string): boolean =>\n getInsertionValues(str).length > 0;\n\n/**\n * Check if a string is an HTML/JSX string\n * Matches:\n * - <Tag>\n * - </Tag>\n * - <Tag />\n * - <Tag attribute=\"value\">\n * - <Component.SubComponent>\n */\nconst isHTML = (str: string): boolean => {\n // 1. Matches opening or self-closing tags: <Tag ... > or <Tag ... />\n // - Must start with < followed by a letter (to avoid math comparisons like a < b)\n // - Allows alphanumeric, hyphens, and dots (for Namespaced components) in tag name\n // - Allows attributes until the closing >\n const openTagRegex = /<[a-zA-Z][a-zA-Z0-9\\-.]*(\\s+[^>]*)?\\/?>/;\n\n // 2. Matches closing tags: </Tag>\n const closeTagRegex = /<\\/[a-zA-Z][a-zA-Z0-9\\-.]*\\s*>/;\n\n return openTagRegex.test(str) || closeTagRegex.test(str);\n};\n\nconst leafNodeTypes: string[] = [\n NodeType.HTML,\n NodeType.Markdown,\n NodeType.Insertion,\n NodeType.File,\n NodeType.ReactNode,\n NodeType.Text,\n NodeType.Number,\n NodeType.Boolean,\n NodeType.Null,\n NodeType.Unknown,\n];\n\ntype AutoTransformationOptions = {\n markdown?: boolean;\n html?: boolean;\n insertion?: boolean;\n};\n\n/**\n * Automatically decorate content strings with md() or insert() if they match\n */\nexport const autoDecorateContent = (\n content: any,\n options: boolean | AutoTransformationOptions = true\n): any => {\n if (options === false) {\n return content;\n }\n\n const {\n markdown = true,\n html: htmlOption = true,\n insertion = true,\n } = typeof options === 'object' ? options : {};\n\n if (typeof content === 'string') {\n if (markdown && isMarkdown(content)) {\n const markdownNode = md(content);\n\n return {\n ...markdownNode,\n metadata: getMarkdownMetadata(content),\n };\n }\n\n if (htmlOption && isHTML(content)) {\n return html(content);\n }\n\n if (insertion && isInsertion(content)) {\n return insert(content);\n }\n\n return content;\n }\n\n if (Array.isArray(content)) {\n return content.map((item) => autoDecorateContent(item, options));\n }\n\n if (content && typeof content === 'object') {\n // If it's already a decorated node (has nodeType)\n if ('nodeType' in content) {\n const nodeType = content.nodeType;\n\n // If it's a leaf node type, don't re-decorate its content\n if (leafNodeTypes.includes(nodeType)) {\n return content;\n }\n\n // If it's a container node type (like translation, enumeration, etc.), recurse into its content field\n if (nodeType in content) {\n return {\n ...content,\n [nodeType]: autoDecorateContent(content[nodeType], options),\n };\n }\n\n return content;\n }\n\n // Plain object, recurse into all keys\n const result: Record<string, any> = {};\n for (const key of Object.keys(content)) {\n result[key] = autoDecorateContent(content[key], options);\n }\n return result;\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;;AAYA,MAAM,cAAc,QAAyB;AAgB3C,QAdiB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAEe,MAAM,YAAY,QAAQ,KAAK,IAAI,CAAC;;;;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oDecorateContent.ts"],"sourcesContent":["import { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport {\n getInsertionValues,\n html,\n insert,\n md,\n} from '@intlayer/core/transpiler';\nimport { NodeType } from '@intlayer/types';\n\n/**\n * Check if a string is a markdown string\n */\nconst isMarkdown = (str: string): boolean => {\n // Check for common markdown indicators\n const patterns = [\n /^\\s*---/m, // Front Matter\n /^\\s*#+\\s/m, // Headers: # Title\n /^\\s*[-*+]\\s/m, // Unordered lists: - Item or * Item\n /^\\s*\\d+\\.\\s/m, // Ordered lists: 1. Item\n /^\\s*>\\s/m, // Blockquotes: > Quote\n /\\[.+\\]\\(.+\\)/, // Links: [text](url)\n /!\\[.+\\]\\(.+\\)/, // Images: ![alt](url)\n /`{1,3}.+`{1,3}/, // Code blocks or inline code: `code` or ```code```\n /\\*\\*.+\\*\\*/, // Bold: **text**\n /__.+__/, // Bold: __text__\n /<(https?:\\/\\/[^\\s>]+)>/, // Autolinks: <http://...>\n ];\n\n return patterns.some((pattern) => pattern.test(str));\n};\n\n/**\n * Check if a string is an insertion string\n */\nconst isInsertion = (str: string): boolean =>\n getInsertionValues(str).length > 0;\n\n/**\n * Check if a string is an HTML/JSX string\n * Matches:\n * - <Tag>\n * - </Tag>\n * - <Tag />\n * - <Tag attribute=\"value\">\n * - <Component.SubComponent>\n */\nconst isHTML = (str: string): boolean => {\n // 1. Matches opening or self-closing tags: <Tag ... > or <Tag ... />\n // - Must start with < followed by a letter (to avoid math comparisons like a < b)\n // - Allows alphanumeric, hyphens, and dots (for Namespaced components) in tag name\n // - Allows attributes until the closing >\n const openTagRegex = /<[a-zA-Z][a-zA-Z0-9\\-.]*(\\s+[^>]*)?\\/?>/;\n\n // 2. Matches closing tags: </Tag>\n const closeTagRegex = /<\\/[a-zA-Z][a-zA-Z0-9\\-.]*\\s*>/;\n\n return openTagRegex.test(str) || closeTagRegex.test(str);\n};\n\nconst leafNodeTypes: string[] = [\n NodeType.HTML,\n NodeType.Markdown,\n NodeType.Insertion,\n NodeType.File,\n NodeType.ReactNode,\n NodeType.Text,\n NodeType.Number,\n NodeType.Boolean,\n NodeType.Null,\n NodeType.Unknown,\n];\n\ntype AutoTransformationOptions = {\n markdown?: boolean;\n html?: boolean;\n insertion?: boolean;\n};\n\n/**\n * Automatically decorate content strings with md() or insert() if they match\n */\nexport const autoDecorateContent = (\n content: any,\n options: boolean | AutoTransformationOptions = true\n): any => {\n if (options === false) {\n return content;\n }\n\n const {\n markdown = true,\n html: htmlOption = true,\n insertion = true,\n } = typeof options === 'object' ? options : {};\n\n if (typeof content === 'string') {\n if (markdown && isMarkdown(content)) {\n const markdownNode = md(content);\n\n return {\n ...markdownNode,\n metadata: getMarkdownMetadata(content),\n };\n }\n\n if (htmlOption && isHTML(content)) {\n return html(content);\n }\n\n if (insertion && isInsertion(content)) {\n return insert(content);\n }\n\n return content;\n }\n\n if (Array.isArray(content)) {\n return content.map((item) => autoDecorateContent(item, options));\n }\n\n if (content && typeof content === 'object') {\n // If it's already a decorated node (has nodeType)\n if ('nodeType' in content) {\n const nodeType = content.nodeType;\n\n // If it's a leaf node type, don't re-decorate its content\n if (leafNodeTypes.includes(nodeType)) {\n return content;\n }\n\n // If it's a container node type (like translation, enumeration, etc.), recurse into its content field\n if (nodeType in content) {\n return {\n ...content,\n [nodeType]: autoDecorateContent(content[nodeType], options),\n };\n }\n\n return content;\n }\n\n // Plain object, recurse into all keys\n const result: Record<string, any> = {};\n for (const key of Object.keys(content)) {\n result[key] = autoDecorateContent(content[key], options);\n }\n return result;\n }\n\n return content;\n};\n"],"mappings":"6NAYA,MAAM,EAAc,GAED,CACf,WACA,YACA,eACA,eACA,WACA,eACA,gBACA,iBACA,aACA,SACA,yBACD,CAEe,KAAM,GAAY,EAAQ,KAAK,EAAI,CAAC,CAMhD,EAAe,IAAA,EAAA,EAAA,oBACA,EAAI,CAAC,OAAS,EAW7B,EAAU,GAKO,0CAKD,KAAK,EAAI,EAFP,iCAEyB,KAAK,EAAI,CAGpD,EAA0B,CAC9BA,EAAAA,SAAS,KACTA,EAAAA,SAAS,SACTA,EAAAA,SAAS,UACTA,EAAAA,SAAS,KACTA,EAAAA,SAAS,UACTA,EAAAA,SAAS,KACTA,EAAAA,SAAS,OACTA,EAAAA,SAAS,QACTA,EAAAA,SAAS,KACTA,EAAAA,SAAS,QACV,CAWY,GACX,EACA,EAA+C,KACvC,CACR,GAAI,IAAY,GACd,OAAO,EAGT,GAAM,CACJ,WAAW,GACX,KAAM,EAAa,GACnB,YAAY,IACV,OAAO,GAAY,SAAW,EAAU,EAAE,CAE9C,GAAI,OAAO,GAAY,SAkBrB,OAjBI,GAAY,EAAW,EAAQ,CAG1B,CACL,IAAA,EAAA,EAAA,IAHsB,EAAQ,CAI9B,UAAA,EAAA,EAAA,qBAA8B,EAAQ,CACvC,CAGC,GAAc,EAAO,EAAQ,EAC/B,EAAA,EAAA,MAAY,EAAQ,CAGlB,GAAa,EAAY,EAAQ,EACnC,EAAA,EAAA,QAAc,EAAQ,CAGjB,EAGT,GAAI,MAAM,QAAQ,EAAQ,CACxB,OAAO,EAAQ,IAAK,GAAS,EAAoB,EAAM,EAAQ,CAAC,CAGlE,GAAI,GAAW,OAAO,GAAY,SAAU,CAE1C,GAAI,aAAc,EAAS,CACzB,IAAM,EAAW,EAAQ,SAezB,OAZI,EAAc,SAAS,EAAS,CAC3B,EAIL,KAAY,EACP,CACL,GAAG,GACF,GAAW,EAAoB,EAAQ,GAAW,EAAQ,CAC5D,CAGI,EAIT,IAAM,EAA8B,EAAE,CACtC,IAAK,IAAM,KAAO,OAAO,KAAK,EAAQ,CACpC,EAAO,GAAO,EAAoB,EAAQ,GAAM,EAAQ,CAE1D,OAAO,EAGT,OAAO"}
@@ -1,51 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let node_path = require("node:path");
4
- let fast_glob = require("fast-glob");
5
- fast_glob = require_runtime.__toESM(fast_glob);
6
-
7
- //#region src/utils/buildFilesList.ts
8
- /**
9
- * Normalizes a pattern value to an array
10
- */
11
- const normalizeToArray = (value) => {
12
- return Array.isArray(value) ? value : [value];
13
- };
14
- /**
15
- * Builds a list of files matching the given patterns.
16
- *
17
- * This utility consolidates the file listing logic used across multiple compilers
18
- * (Vue, Svelte, Vite) to avoid code duplication.
19
- *
20
- * @param options - Configuration options for building the file list
21
- * @returns Array of absolute file paths matching the patterns
22
- *
23
- * @example
24
- * // Basic usage
25
- * const files = buildFilesList({
26
- * transformPattern: 'src/**\/*.{ts,tsx}',
27
- * excludePattern: ['**\/node_modules;\/**'],
28
- * baseDir: '/path/to/project',
29
- * });
30
- *
31
- * @example
32
- * // With framework extension (Vue)
33
- * const files = buildFilesList({
34
- * transformPattern: 'src/**\/*.{ts,tsx}',
35
- * excludePattern: ['**\/node_modules\/**'],
36
- * baseDir: '/path/to/project',
37
- * });
38
- */
39
- const buildFilesList = (options) => {
40
- const { transformPattern, excludePattern, baseDir } = options;
41
- const patterns = normalizeToArray(transformPattern);
42
- const excludePatterns = normalizeToArray(excludePattern);
43
- return fast_glob.default.sync(patterns, {
44
- cwd: baseDir,
45
- ignore: excludePatterns
46
- }).map((file) => (0, node_path.join)(baseDir, file));
47
- };
48
-
49
- //#endregion
50
- exports.buildFilesList = buildFilesList;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`node:path`),n=require(`fast-glob`);n=e.__toESM(n);const r=e=>Array.isArray(e)?e:[e],i=e=>{let{transformPattern:i,excludePattern:a,baseDir:o}=e,s=r(i),c=r(a);return n.default.sync(s,{cwd:o,ignore:c}).map(e=>(0,t.join)(o,e))};exports.buildFilesList=i;
51
2
  //# sourceMappingURL=buildFilesList.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildFilesList.cjs","names":["fg"],"sources":["../../../src/utils/buildFilesList.ts"],"sourcesContent":["import { join } from 'node:path';\nimport fg from 'fast-glob';\n\n/**\n * Options for building the files list\n */\nexport type BuildFilesListOptions = {\n /**\n * Glob patterns to match files\n */\n transformPattern: string | string[];\n /**\n * Glob patterns to exclude files\n */\n excludePattern: string | string[];\n /**\n * Base directory for file resolution\n */\n baseDir: string;\n};\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] => {\n return Array.isArray(value) ? value : [value];\n};\n\n/**\n * Builds a list of files matching the given patterns.\n *\n * This utility consolidates the file listing logic used across multiple compilers\n * (Vue, Svelte, Vite) to avoid code duplication.\n *\n * @param options - Configuration options for building the file list\n * @returns Array of absolute file paths matching the patterns\n *\n * @example\n * // Basic usage\n * const files = buildFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules;\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // With framework extension (Vue)\n * const files = buildFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n */\nexport const buildFilesList = (options: BuildFilesListOptions): string[] => {\n const { transformPattern, excludePattern, baseDir } = options;\n\n const patterns = normalizeToArray(transformPattern);\n const excludePatterns = normalizeToArray(excludePattern);\n\n const files = fg\n .sync(patterns, {\n cwd: baseDir,\n ignore: excludePatterns,\n })\n .map((file) => join(baseDir, file));\n\n return files;\n};\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,oBAAuB,UAAwB;AACnD,QAAO,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B/C,MAAa,kBAAkB,YAA6C;CAC1E,MAAM,EAAE,kBAAkB,gBAAgB,YAAY;CAEtD,MAAM,WAAW,iBAAiB,iBAAiB;CACnD,MAAM,kBAAkB,iBAAiB,eAAe;AASxD,QAPcA,kBACX,KAAK,UAAU;EACd,KAAK;EACL,QAAQ;EACT,CAAC,CACD,KAAK,6BAAc,SAAS,KAAK,CAAC"}
1
+ {"version":3,"file":"buildFilesList.cjs","names":["fg"],"sources":["../../../src/utils/buildFilesList.ts"],"sourcesContent":["import { join } from 'node:path';\nimport fg from 'fast-glob';\n\n/**\n * Options for building the files list\n */\nexport type BuildFilesListOptions = {\n /**\n * Glob patterns to match files\n */\n transformPattern: string | string[];\n /**\n * Glob patterns to exclude files\n */\n excludePattern: string | string[];\n /**\n * Base directory for file resolution\n */\n baseDir: string;\n};\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] => {\n return Array.isArray(value) ? value : [value];\n};\n\n/**\n * Builds a list of files matching the given patterns.\n *\n * This utility consolidates the file listing logic used across multiple compilers\n * (Vue, Svelte, Vite) to avoid code duplication.\n *\n * @param options - Configuration options for building the file list\n * @returns Array of absolute file paths matching the patterns\n *\n * @example\n * // Basic usage\n * const files = buildFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules;\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // With framework extension (Vue)\n * const files = buildFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n */\nexport const buildFilesList = (options: BuildFilesListOptions): string[] => {\n const { transformPattern, excludePattern, baseDir } = options;\n\n const patterns = normalizeToArray(transformPattern);\n const excludePatterns = normalizeToArray(excludePattern);\n\n const files = fg\n .sync(patterns, {\n cwd: baseDir,\n ignore: excludePatterns,\n })\n .map((file) => join(baseDir, file));\n\n return files;\n};\n"],"mappings":"yLAwBA,MAAM,EAAuB,GACpB,MAAM,QAAQ,EAAM,CAAG,EAAQ,CAAC,EAAM,CA4BlC,EAAkB,GAA6C,CAC1E,GAAM,CAAE,mBAAkB,iBAAgB,WAAY,EAEhD,EAAW,EAAiB,EAAiB,CAC7C,EAAkB,EAAiB,EAAe,CASxD,OAPcA,EAAAA,QACX,KAAK,EAAU,CACd,IAAK,EACL,OAAQ,EACT,CAAC,CACD,IAAK,IAAA,EAAA,EAAA,MAAc,EAAS,EAAK,CAAC"}