gt 2.14.35 → 2.14.36

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 (429) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/api/collectUserEditDiffs.js +112 -155
  3. package/dist/api/collectUserEditDiffs.js.map +1 -0
  4. package/dist/api/downloadFileBatch.js +164 -241
  5. package/dist/api/downloadFileBatch.js.map +1 -0
  6. package/dist/api/saveLocalEdits.js +37 -41
  7. package/dist/api/saveLocalEdits.js.map +1 -0
  8. package/dist/bin/bin-entry.js +17 -7
  9. package/dist/bin/bin-entry.js.map +1 -0
  10. package/dist/bin/bin-main.js +43 -61
  11. package/dist/bin/bin-main.js.map +1 -0
  12. package/dist/cli/base.js +382 -497
  13. package/dist/cli/base.js.map +1 -0
  14. package/dist/cli/commands/download.js +41 -49
  15. package/dist/cli/commands/download.js.map +1 -0
  16. package/dist/cli/commands/enqueue.js +26 -25
  17. package/dist/cli/commands/enqueue.js.map +1 -0
  18. package/dist/cli/commands/setupProject.js +33 -36
  19. package/dist/cli/commands/setupProject.js.map +1 -0
  20. package/dist/cli/commands/stage.js +53 -61
  21. package/dist/cli/commands/stage.js.map +1 -0
  22. package/dist/cli/commands/translate.js +75 -112
  23. package/dist/cli/commands/translate.js.map +1 -0
  24. package/dist/cli/commands/upload.js +185 -213
  25. package/dist/cli/commands/upload.js.map +1 -0
  26. package/dist/cli/commands/utils/validation.js +39 -34
  27. package/dist/cli/commands/utils/validation.js.map +1 -0
  28. package/dist/cli/flags.js +35 -62
  29. package/dist/cli/flags.js.map +1 -0
  30. package/dist/cli/inline.js +112 -137
  31. package/dist/cli/inline.js.map +1 -0
  32. package/dist/cli/next.js +17 -12
  33. package/dist/cli/next.js.map +1 -0
  34. package/dist/cli/node.js +19 -15
  35. package/dist/cli/node.js.map +1 -0
  36. package/dist/cli/python.js +13 -8
  37. package/dist/cli/python.js.map +1 -0
  38. package/dist/cli/react.js +61 -78
  39. package/dist/cli/react.js.map +1 -0
  40. package/dist/config/defaults.js +16 -11
  41. package/dist/config/defaults.js.map +1 -0
  42. package/dist/config/generateSettings.js +167 -269
  43. package/dist/config/generateSettings.js.map +1 -0
  44. package/dist/config/optionPresets.js +78 -96
  45. package/dist/config/optionPresets.js.map +1 -0
  46. package/dist/config/resolveConfig.js +27 -32
  47. package/dist/config/resolveConfig.js.map +1 -0
  48. package/dist/config/utils.js +7 -3
  49. package/dist/config/utils.js.map +1 -0
  50. package/dist/config/validateSettings.js +19 -30
  51. package/dist/config/validateSettings.js.map +1 -0
  52. package/dist/console/colors.js +18 -13
  53. package/dist/console/colors.js.map +1 -0
  54. package/dist/console/displayTranslateSummary.js +40 -37
  55. package/dist/console/displayTranslateSummary.js.map +1 -0
  56. package/dist/console/formatting.js +8 -5
  57. package/dist/console/formatting.js.map +1 -0
  58. package/dist/console/index.d.ts +11 -9
  59. package/dist/console/index.js +53 -50
  60. package/dist/console/index.js.map +1 -0
  61. package/dist/console/inkFields.d.ts +23 -0
  62. package/dist/console/inkFields.js +87 -0
  63. package/dist/console/inkFields.js.map +1 -0
  64. package/dist/console/inkLayout.d.ts +7 -0
  65. package/dist/console/inkLayout.js +139 -0
  66. package/dist/console/inkLayout.js.map +1 -0
  67. package/dist/console/inkLocaleData.d.ts +4 -0
  68. package/dist/console/inkLocaleData.js +32 -0
  69. package/dist/console/inkLocaleData.js.map +1 -0
  70. package/dist/console/inkPrompts.d.ts +8 -0
  71. package/dist/console/inkPrompts.js +496 -0
  72. package/dist/console/inkPrompts.js.map +1 -0
  73. package/dist/console/inkSession.d.ts +3 -0
  74. package/dist/console/inkSession.js +42 -0
  75. package/dist/console/inkSession.js.map +1 -0
  76. package/dist/console/inkTerminal.d.ts +4 -0
  77. package/dist/console/inkTerminal.js +15 -0
  78. package/dist/console/inkTerminal.js.map +1 -0
  79. package/dist/console/inkTypes.d.ts +66 -0
  80. package/dist/console/inkTypes.js +1 -0
  81. package/dist/console/inkUtils.d.ts +24 -0
  82. package/dist/console/inkUtils.js +87 -0
  83. package/dist/console/inkUtils.js.map +1 -0
  84. package/dist/console/logger.js +209 -249
  85. package/dist/console/logger.js.map +1 -0
  86. package/dist/console/logging.d.ts +14 -0
  87. package/dist/console/logging.js +203 -162
  88. package/dist/console/logging.js.map +1 -0
  89. package/dist/console/promptParsing.d.ts +5 -0
  90. package/dist/console/promptParsing.js +28 -0
  91. package/dist/console/promptParsing.js.map +1 -0
  92. package/dist/console/terminalSession.d.ts +5 -0
  93. package/dist/console/terminalSession.js +38 -0
  94. package/dist/console/terminalSession.js.map +1 -0
  95. package/dist/extraction/index.js +3 -2
  96. package/dist/extraction/mapToUpdates.js +19 -18
  97. package/dist/extraction/mapToUpdates.js.map +1 -0
  98. package/dist/extraction/postProcess.js +68 -86
  99. package/dist/extraction/postProcess.js.map +1 -0
  100. package/dist/formats/files/aggregateFiles.js +223 -304
  101. package/dist/formats/files/aggregateFiles.js.map +1 -0
  102. package/dist/formats/files/collectFiles.js +53 -54
  103. package/dist/formats/files/collectFiles.js.map +1 -0
  104. package/dist/formats/files/convertToFileTranslationData.js +21 -19
  105. package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
  106. package/dist/formats/files/fileMapping.js +82 -119
  107. package/dist/formats/files/fileMapping.js.map +1 -0
  108. package/dist/formats/files/preprocess/mdx.js +15 -12
  109. package/dist/formats/files/preprocess/mdx.js.map +1 -0
  110. package/dist/formats/files/preprocess/mintlify.js +15 -13
  111. package/dist/formats/files/preprocess/mintlify.js.map +1 -0
  112. package/dist/formats/files/preprocessContent.js +20 -21
  113. package/dist/formats/files/preprocessContent.js.map +1 -0
  114. package/dist/formats/files/save.js +18 -15
  115. package/dist/formats/files/save.js.map +1 -0
  116. package/dist/formats/files/supportedFiles.js +27 -22
  117. package/dist/formats/files/supportedFiles.js.map +1 -0
  118. package/dist/formats/files/transformFormat.js +93 -100
  119. package/dist/formats/files/transformFormat.js.map +1 -0
  120. package/dist/formats/json/extractJson.js +83 -110
  121. package/dist/formats/json/extractJson.js.map +1 -0
  122. package/dist/formats/json/flattenJson.js +41 -48
  123. package/dist/formats/json/flattenJson.js.map +1 -0
  124. package/dist/formats/json/jsonPath.js +20 -15
  125. package/dist/formats/json/jsonPath.js.map +1 -0
  126. package/dist/formats/json/jsonPointer.js +17 -17
  127. package/dist/formats/json/jsonPointer.js.map +1 -0
  128. package/dist/formats/json/mergeJson.js +230 -371
  129. package/dist/formats/json/mergeJson.js.map +1 -0
  130. package/dist/formats/json/parseJson.js +74 -111
  131. package/dist/formats/json/parseJson.js.map +1 -0
  132. package/dist/formats/json/transformJson.js +53 -61
  133. package/dist/formats/json/transformJson.js.map +1 -0
  134. package/dist/formats/json/utils.js +158 -187
  135. package/dist/formats/json/utils.js.map +1 -0
  136. package/dist/formats/parseKeyedMetadata.js +85 -106
  137. package/dist/formats/parseKeyedMetadata.js.map +1 -0
  138. package/dist/formats/utils.js +13 -23
  139. package/dist/formats/utils.js.map +1 -0
  140. package/dist/formats/yaml/extractYaml.js +32 -31
  141. package/dist/formats/yaml/extractYaml.js.map +1 -0
  142. package/dist/formats/yaml/mergeYaml.js +43 -60
  143. package/dist/formats/yaml/mergeYaml.js.map +1 -0
  144. package/dist/formats/yaml/parseYaml.js +34 -23
  145. package/dist/formats/yaml/parseYaml.js.map +1 -0
  146. package/dist/formats/yaml/utils.js +19 -21
  147. package/dist/formats/yaml/utils.js.map +1 -0
  148. package/dist/fs/clearLocaleDirs.js +82 -114
  149. package/dist/fs/clearLocaleDirs.js.map +1 -0
  150. package/dist/fs/config/downloadedVersions.js +174 -188
  151. package/dist/fs/config/downloadedVersions.js.map +1 -0
  152. package/dist/fs/config/loadConfig.js +12 -8
  153. package/dist/fs/config/loadConfig.js.map +1 -0
  154. package/dist/fs/config/parseFilesConfig.js +166 -227
  155. package/dist/fs/config/parseFilesConfig.js.map +1 -0
  156. package/dist/fs/config/setupConfig.js +43 -52
  157. package/dist/fs/config/setupConfig.js.map +1 -0
  158. package/dist/fs/config/updateConfig.js +44 -56
  159. package/dist/fs/config/updateConfig.js.map +1 -0
  160. package/dist/fs/config/updateVersions.js +27 -28
  161. package/dist/fs/config/updateVersions.js.map +1 -0
  162. package/dist/fs/copyFile.js +33 -37
  163. package/dist/fs/copyFile.js.map +1 -0
  164. package/dist/fs/createLoadTranslationsFile.js +32 -48
  165. package/dist/fs/createLoadTranslationsFile.js.map +1 -0
  166. package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
  167. package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
  168. package/dist/fs/determineFramework/index.js +46 -64
  169. package/dist/fs/determineFramework/index.js.map +1 -0
  170. package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
  171. package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
  172. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
  173. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
  174. package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
  175. package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
  176. package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
  177. package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
  178. package/dist/fs/findFilepath.js +63 -78
  179. package/dist/fs/findFilepath.js.map +1 -0
  180. package/dist/fs/loadJSON.js +18 -15
  181. package/dist/fs/loadJSON.js.map +1 -0
  182. package/dist/fs/matchFiles.js +12 -7
  183. package/dist/fs/matchFiles.js.map +1 -0
  184. package/dist/fs/saveJSON.js +10 -6
  185. package/dist/fs/saveJSON.js.map +1 -0
  186. package/dist/fs/utils.js +19 -15
  187. package/dist/fs/utils.js.map +1 -0
  188. package/dist/functions.d.ts +2 -1
  189. package/dist/functions.js +3 -6
  190. package/dist/generated/version.d.ts +1 -1
  191. package/dist/generated/version.js +6 -2
  192. package/dist/generated/version.js.map +1 -0
  193. package/dist/git/branches.js +77 -83
  194. package/dist/git/branches.js.map +1 -0
  195. package/dist/hooks/postProcess.js +97 -114
  196. package/dist/hooks/postProcess.js.map +1 -0
  197. package/dist/index.js +23 -31
  198. package/dist/index.js.map +1 -0
  199. package/dist/locadex/setupFlow.js +11 -8
  200. package/dist/locadex/setupFlow.js.map +1 -0
  201. package/dist/main.js +17 -7
  202. package/dist/main.js.map +1 -0
  203. package/dist/next/config/parseNextConfig.js +32 -51
  204. package/dist/next/config/parseNextConfig.js.map +1 -0
  205. package/dist/next/jsx/utils.js +25 -37
  206. package/dist/next/jsx/utils.js.map +1 -0
  207. package/dist/next/parse/handleInitGT.js +87 -154
  208. package/dist/next/parse/handleInitGT.js.map +1 -0
  209. package/dist/next/parse/wrapContent.js +136 -158
  210. package/dist/next/parse/wrapContent.js.map +1 -0
  211. package/dist/python/parse/createPythonInlineUpdates.js +36 -33
  212. package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
  213. package/dist/react/config/createESBuildConfig.js +115 -115
  214. package/dist/react/config/createESBuildConfig.js.map +1 -0
  215. package/dist/react/jsx/evaluateJsx.js +90 -124
  216. package/dist/react/jsx/evaluateJsx.js.map +1 -0
  217. package/dist/react/jsx/utils/buildImportMap.js +24 -28
  218. package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
  219. package/dist/react/jsx/utils/constants.js +79 -87
  220. package/dist/react/jsx/utils/constants.js.map +1 -0
  221. package/dist/react/jsx/utils/extractSourceCode.js +36 -37
  222. package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
  223. package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
  224. package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
  225. package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
  226. package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
  227. package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
  228. package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
  229. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
  230. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
  231. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
  232. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
  233. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
  234. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
  235. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
  236. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
  237. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
  238. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
  239. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
  240. package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
  241. package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
  242. package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
  243. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
  244. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
  245. package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
  246. package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
  247. package/dist/react/jsx/utils/mapAttributeName.js +13 -13
  248. package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
  249. package/dist/react/jsx/utils/parseAst.js +142 -272
  250. package/dist/react/jsx/utils/parseAst.js.map +1 -0
  251. package/dist/react/jsx/utils/parseString.js +726 -1090
  252. package/dist/react/jsx/utils/parseString.js.map +1 -0
  253. package/dist/react/jsx/utils/parseStringFunction.js +274 -401
  254. package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
  255. package/dist/react/jsx/utils/resolveImportPath.js +104 -108
  256. package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
  257. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
  258. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
  259. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
  260. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
  261. package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
  262. package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
  263. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
  264. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
  265. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
  266. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
  267. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
  268. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
  269. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
  270. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
  271. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
  272. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
  273. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
  274. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
  275. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
  276. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
  277. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
  278. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
  279. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
  280. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
  281. package/dist/react/jsx/utils/validateStringFunction.js +21 -29
  282. package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
  283. package/dist/react/jsx/wrapJsx.js +192 -375
  284. package/dist/react/jsx/wrapJsx.js.map +1 -0
  285. package/dist/react/parse/addVitePlugin/index.js +40 -34
  286. package/dist/react/parse/addVitePlugin/index.js.map +1 -0
  287. package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
  288. package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
  289. package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
  290. package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
  291. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
  292. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
  293. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
  294. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
  295. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
  296. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
  297. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
  298. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
  299. package/dist/react/parse/createDictionaryUpdates.js +121 -185
  300. package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
  301. package/dist/react/parse/createInlineUpdates.js +123 -139
  302. package/dist/react/parse/createInlineUpdates.js.map +1 -0
  303. package/dist/react/parse/wrapContent.js +131 -156
  304. package/dist/react/parse/wrapContent.js.map +1 -0
  305. package/dist/react/utils/flattenDictionary.js +55 -70
  306. package/dist/react/utils/flattenDictionary.js.map +1 -0
  307. package/dist/react/utils/getEntryAndMetadata.js +14 -10
  308. package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
  309. package/dist/react/utils/getVariableName.js +36 -33
  310. package/dist/react/utils/getVariableName.js.map +1 -0
  311. package/dist/setup/detectFramework.js +85 -102
  312. package/dist/setup/detectFramework.js.map +1 -0
  313. package/dist/setup/frameworkUtils.js +17 -28
  314. package/dist/setup/frameworkUtils.js.map +1 -0
  315. package/dist/setup/userInput.js +24 -31
  316. package/dist/setup/userInput.js.map +1 -0
  317. package/dist/setup/wizard.js +141 -143
  318. package/dist/setup/wizard.js.map +1 -0
  319. package/dist/state/mintlifyRefMap.js +12 -9
  320. package/dist/state/mintlifyRefMap.js.map +1 -0
  321. package/dist/state/recentDownloads.js +26 -23
  322. package/dist/state/recentDownloads.js.map +1 -0
  323. package/dist/state/translateWarnings.js +17 -8
  324. package/dist/state/translateWarnings.js.map +1 -0
  325. package/dist/translation/parse.js +77 -98
  326. package/dist/translation/parse.js.map +1 -0
  327. package/dist/translation/stage.js +28 -43
  328. package/dist/translation/stage.js.map +1 -0
  329. package/dist/translation/validate.js +68 -91
  330. package/dist/translation/validate.js.map +1 -0
  331. package/dist/types/libraries.js +93 -91
  332. package/dist/types/libraries.js.map +1 -0
  333. package/dist/types/parsing.js +19 -10
  334. package/dist/types/parsing.js.map +1 -0
  335. package/dist/utils/addExplicitAnchorIds.js +270 -389
  336. package/dist/utils/addExplicitAnchorIds.js.map +1 -0
  337. package/dist/utils/calculateTimeoutMs.js +11 -6
  338. package/dist/utils/calculateTimeoutMs.js.map +1 -0
  339. package/dist/utils/constants.js +15 -12
  340. package/dist/utils/constants.js.map +1 -0
  341. package/dist/utils/credentials.js +67 -114
  342. package/dist/utils/credentials.js.map +1 -0
  343. package/dist/utils/fetch.js +22 -20
  344. package/dist/utils/fetch.js.map +1 -0
  345. package/dist/utils/flattenJsonFiles.js +27 -34
  346. package/dist/utils/flattenJsonFiles.js.map +1 -0
  347. package/dist/utils/gitDiff.js +30 -32
  348. package/dist/utils/gitDiff.js.map +1 -0
  349. package/dist/utils/gt.js +7 -2
  350. package/dist/utils/gt.js.map +1 -0
  351. package/dist/utils/hash.js +14 -9
  352. package/dist/utils/hash.js.map +1 -0
  353. package/dist/utils/headers.js +10 -13
  354. package/dist/utils/headers.js.map +1 -0
  355. package/dist/utils/installPackage.js +70 -75
  356. package/dist/utils/installPackage.js.map +1 -0
  357. package/dist/utils/localizeRelativeAssets.js +114 -157
  358. package/dist/utils/localizeRelativeAssets.js.map +1 -0
  359. package/dist/utils/localizeStaticImports.js +229 -371
  360. package/dist/utils/localizeStaticImports.js.map +1 -0
  361. package/dist/utils/localizeStaticUrls.js +241 -424
  362. package/dist/utils/localizeStaticUrls.js.map +1 -0
  363. package/dist/utils/mintlifyTitleFallback.js +64 -72
  364. package/dist/utils/mintlifyTitleFallback.js.map +1 -0
  365. package/dist/utils/monorepoVersionCheck.js +177 -215
  366. package/dist/utils/monorepoVersionCheck.js.map +1 -0
  367. package/dist/utils/packageInfo.js +17 -16
  368. package/dist/utils/packageInfo.js.map +1 -0
  369. package/dist/utils/packageJson.js +51 -66
  370. package/dist/utils/packageJson.js.map +1 -0
  371. package/dist/utils/packageManager.js +237 -260
  372. package/dist/utils/packageManager.js.map +1 -0
  373. package/dist/utils/parse/needsCJS.js +36 -69
  374. package/dist/utils/parse/needsCJS.js.map +1 -0
  375. package/dist/utils/persistPostprocessHashes.js +30 -32
  376. package/dist/utils/persistPostprocessHashes.js.map +1 -0
  377. package/dist/utils/processAnchorIds.js +32 -54
  378. package/dist/utils/processAnchorIds.js.map +1 -0
  379. package/dist/utils/processOpenApi.js +469 -578
  380. package/dist/utils/processOpenApi.js.map +1 -0
  381. package/dist/utils/resolveMintlifyRefs.js +89 -105
  382. package/dist/utils/resolveMintlifyRefs.js.map +1 -0
  383. package/dist/utils/resolvePublish.js +46 -54
  384. package/dist/utils/resolvePublish.js.map +1 -0
  385. package/dist/utils/sanitizeFileContent.js +20 -27
  386. package/dist/utils/sanitizeFileContent.js.map +1 -0
  387. package/dist/utils/sharedStaticAssets.js +248 -366
  388. package/dist/utils/sharedStaticAssets.js.map +1 -0
  389. package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
  390. package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
  391. package/dist/utils/validateMdx.js +26 -23
  392. package/dist/utils/validateMdx.js.map +1 -0
  393. package/dist/utils/wrapPlainUrls.js +58 -70
  394. package/dist/utils/wrapPlainUrls.js.map +1 -0
  395. package/dist/workflows/download.js +92 -126
  396. package/dist/workflows/download.js.map +1 -0
  397. package/dist/workflows/enqueue.js +47 -54
  398. package/dist/workflows/enqueue.js.map +1 -0
  399. package/dist/workflows/publish.js +29 -29
  400. package/dist/workflows/publish.js.map +1 -0
  401. package/dist/workflows/setupProject.js +39 -40
  402. package/dist/workflows/setupProject.js.map +1 -0
  403. package/dist/workflows/stage.js +61 -65
  404. package/dist/workflows/stage.js.map +1 -0
  405. package/dist/workflows/steps/BranchStep.js +118 -163
  406. package/dist/workflows/steps/BranchStep.js.map +1 -0
  407. package/dist/workflows/steps/DownloadStep.js +107 -137
  408. package/dist/workflows/steps/DownloadStep.js.map +1 -0
  409. package/dist/workflows/steps/EnqueueStep.js +32 -32
  410. package/dist/workflows/steps/EnqueueStep.js.map +1 -0
  411. package/dist/workflows/steps/PollJobsStep.js +208 -292
  412. package/dist/workflows/steps/PollJobsStep.js.map +1 -0
  413. package/dist/workflows/steps/PublishStep.js +33 -38
  414. package/dist/workflows/steps/PublishStep.js.map +1 -0
  415. package/dist/workflows/steps/SetupStep.js +71 -72
  416. package/dist/workflows/steps/SetupStep.js.map +1 -0
  417. package/dist/workflows/steps/TagStep.js +39 -44
  418. package/dist/workflows/steps/TagStep.js.map +1 -0
  419. package/dist/workflows/steps/UploadSourcesStep.js +108 -140
  420. package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
  421. package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
  422. package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
  423. package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
  424. package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
  425. package/dist/workflows/steps/WorkflowStep.js +6 -2
  426. package/dist/workflows/steps/WorkflowStep.js.map +1 -0
  427. package/dist/workflows/upload.js +45 -46
  428. package/dist/workflows/upload.js.map +1 -0
  429. package/package.json +14 -7
@@ -1,241 +1,180 @@
1
- import path from 'node:path';
2
- import fg from 'fast-glob';
3
- import { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';
4
- import { logger } from '../../console/logger.js';
5
- import chalk from 'chalk';
6
- import micromatch from 'micromatch';
7
- import { BASE_PARSING_FLAGS_DEFAULT, GT_PARSING_FLAGS_DEFAULT, } from '../../config/defaults.js';
8
- import { resolveTransformationFormat } from '../../formats/files/transformFormat.js';
1
+ import { logger } from "../../console/logger.js";
2
+ import { SUPPORTED_FILE_EXTENSIONS } from "../../formats/files/supportedFiles.js";
3
+ import { BASE_PARSING_FLAGS_DEFAULT, GT_PARSING_FLAGS_DEFAULT } from "../../config/defaults.js";
4
+ import { resolveTransformationFormat } from "../../formats/files/transformFormat.js";
5
+ import chalk from "chalk";
6
+ import path from "node:path";
7
+ import fg from "fast-glob";
8
+ import micromatch from "micromatch";
9
+ //#region src/fs/config/parseFilesConfig.ts
9
10
  /**
10
- * Resolves the files from the files object
11
- * Replaces [locale] with the actual locale in the files
12
- *
13
- * @param files - The files object
14
- * @param locale - The locale to replace [locale] with
15
- * @returns The resolved files
16
- */
17
- export function resolveLocaleFiles(files, locale) {
18
- const result = {};
19
- for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
20
- result[fileType] = files[fileType]?.map((filepath) => filepath.replace(/\[locale\]/g, locale));
21
- }
22
- // Replace [locale] with locale in all paths
23
- result.gt = files.gt?.replace(/\[locale\]/g, locale);
24
- return result;
11
+ * Resolves the files from the files object
12
+ * Replaces [locale] with the actual locale in the files
13
+ *
14
+ * @param files - The files object
15
+ * @param locale - The locale to replace [locale] with
16
+ * @returns The resolved files
17
+ */
18
+ function resolveLocaleFiles(files, locale) {
19
+ const result = {};
20
+ for (const fileType of SUPPORTED_FILE_EXTENSIONS) result[fileType] = files[fileType]?.map((filepath) => filepath.replace(/\[locale\]/g, locale));
21
+ result.gt = files.gt?.replace(/\[locale\]/g, locale);
22
+ return result;
25
23
  }
26
24
  /**
27
- * Normalizes include patterns into plain path strings and tracks which
28
- * patterns have explicit publish flags.
29
- */
30
- export function normalizeIncludePatterns(patterns) {
31
- const paths = [];
32
- const publishPatterns = [];
33
- const unpublishPatterns = [];
34
- for (const pattern of patterns) {
35
- if (typeof pattern === 'string') {
36
- paths.push(pattern);
37
- }
38
- else {
39
- paths.push(pattern.pattern);
40
- if (pattern.publish === true) {
41
- publishPatterns.push(pattern.pattern);
42
- }
43
- else if (pattern.publish === false) {
44
- unpublishPatterns.push(pattern.pattern);
45
- }
46
- }
47
- }
48
- return { paths, publishPatterns, unpublishPatterns };
25
+ * Normalizes include patterns into plain path strings and tracks which
26
+ * patterns have explicit publish flags.
27
+ */
28
+ function normalizeIncludePatterns(patterns) {
29
+ const paths = [];
30
+ const publishPatterns = [];
31
+ const unpublishPatterns = [];
32
+ for (const pattern of patterns) if (typeof pattern === "string") paths.push(pattern);
33
+ else {
34
+ paths.push(pattern.pattern);
35
+ if (pattern.publish === true) publishPatterns.push(pattern.pattern);
36
+ else if (pattern.publish === false) unpublishPatterns.push(pattern.pattern);
37
+ }
38
+ return {
39
+ paths,
40
+ publishPatterns,
41
+ unpublishPatterns
42
+ };
49
43
  }
50
44
  /**
51
- * Resolves the files from the files object.
52
- * Performs glob pattern expansion on the files.
53
- * Replaces [locale] with the actual locale in the files.
54
- *
55
- * @param files - The files object
56
- * @returns The resolved files
57
- */
58
- export function resolveFiles(files, locale, locales, cwd, compositePatterns) {
59
- // Initialize result object with empty arrays for each file type
60
- const resolvedPaths = {};
61
- const placeholderResult = {};
62
- const transformPaths = {};
63
- // Output format transforms are tracked separately from path transforms.
64
- const transformFormats = {};
65
- const publishPaths = new Set();
66
- const unpublishPaths = new Set();
67
- const parsingFlags = {};
68
- // Process GT files
69
- if (files.gt?.output) {
70
- placeholderResult.gt = path.resolve(cwd, files.gt.output);
71
- }
72
- for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
73
- // ==== TRANSFORMS ==== //
74
- const transform = files[fileType]?.transform;
75
- if (transform &&
76
- (typeof transform === 'string' ||
77
- typeof transform === 'object' ||
78
- Array.isArray(transform))) {
79
- transformPaths[fileType] = transform;
80
- }
81
- // Validate source -> output format transforms during settings generation.
82
- const transformFormat = resolveTransformationFormat(fileType, files[fileType]?.transformationFormat);
83
- if (transformFormat) {
84
- transformFormats[fileType] = transformFormat;
85
- }
86
- // ==== PLACEHOLDERS ==== //
87
- if (files[fileType]?.include) {
88
- const { paths, publishPatterns, unpublishPatterns } = normalizeIncludePatterns(files[fileType].include);
89
- const filePaths = expandGlobPatterns(cwd, paths, files[fileType]?.exclude || [], locale, locales, transformPaths[fileType] || undefined, compositePatterns);
90
- resolvedPaths[fileType] = filePaths.resolvedPaths;
91
- placeholderResult[fileType] = filePaths.placeholderPaths;
92
- // Classify resolved paths into publish/unpublish sets
93
- classifyPublishPaths(filePaths.resolvedPaths, publishPatterns, unpublishPatterns, cwd, locale, publishPaths, unpublishPaths);
94
- }
95
- // ==== OTHER ==== //
96
- if (files[fileType]?.parsingFlags) {
97
- parsingFlags[fileType] = {
98
- ...BASE_PARSING_FLAGS_DEFAULT,
99
- ...files[fileType].parsingFlags,
100
- };
101
- }
102
- }
103
- return {
104
- resolvedPaths,
105
- placeholderPaths: placeholderResult,
106
- transformPaths: transformPaths,
107
- transformFormats,
108
- publishPaths,
109
- unpublishPaths,
110
- parsingFlags,
111
- gtJson: (() => {
112
- const rawGtFlags = (files.gt?.parsingFlags || {});
113
- if ('autoDerive' in rawGtFlags && !('autoderive' in rawGtFlags)) {
114
- rawGtFlags.autoderive = rawGtFlags.autoDerive;
115
- delete rawGtFlags.autoDerive;
116
- }
117
- return {
118
- publish: files.gt?.publish,
119
- parsingFlags: {
120
- ...GT_PARSING_FLAGS_DEFAULT,
121
- ...rawGtFlags,
122
- },
123
- };
124
- })(),
125
- };
45
+ * Resolves the files from the files object.
46
+ * Performs glob pattern expansion on the files.
47
+ * Replaces [locale] with the actual locale in the files.
48
+ *
49
+ * @param files - The files object
50
+ * @returns The resolved files
51
+ */
52
+ function resolveFiles(files, locale, locales, cwd, compositePatterns) {
53
+ const resolvedPaths = {};
54
+ const placeholderResult = {};
55
+ const transformPaths = {};
56
+ const transformFormats = {};
57
+ const publishPaths = /* @__PURE__ */ new Set();
58
+ const unpublishPaths = /* @__PURE__ */ new Set();
59
+ const parsingFlags = {};
60
+ if (files.gt?.output) placeholderResult.gt = path.resolve(cwd, files.gt.output);
61
+ for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
62
+ const transform = files[fileType]?.transform;
63
+ if (transform && (typeof transform === "string" || typeof transform === "object" || Array.isArray(transform))) transformPaths[fileType] = transform;
64
+ const transformFormat = resolveTransformationFormat(fileType, files[fileType]?.transformationFormat);
65
+ if (transformFormat) transformFormats[fileType] = transformFormat;
66
+ if (files[fileType]?.include) {
67
+ const { paths, publishPatterns, unpublishPatterns } = normalizeIncludePatterns(files[fileType].include);
68
+ const filePaths = expandGlobPatterns(cwd, paths, files[fileType]?.exclude || [], locale, locales, transformPaths[fileType] || void 0, compositePatterns);
69
+ resolvedPaths[fileType] = filePaths.resolvedPaths;
70
+ placeholderResult[fileType] = filePaths.placeholderPaths;
71
+ classifyPublishPaths(filePaths.resolvedPaths, publishPatterns, unpublishPatterns, cwd, locale, publishPaths, unpublishPaths);
72
+ }
73
+ if (files[fileType]?.parsingFlags) parsingFlags[fileType] = {
74
+ ...BASE_PARSING_FLAGS_DEFAULT,
75
+ ...files[fileType].parsingFlags
76
+ };
77
+ }
78
+ return {
79
+ resolvedPaths,
80
+ placeholderPaths: placeholderResult,
81
+ transformPaths,
82
+ transformFormats,
83
+ publishPaths,
84
+ unpublishPaths,
85
+ parsingFlags,
86
+ gtJson: (() => {
87
+ const rawGtFlags = files.gt?.parsingFlags || {};
88
+ if ("autoDerive" in rawGtFlags && !("autoderive" in rawGtFlags)) {
89
+ rawGtFlags.autoderive = rawGtFlags.autoDerive;
90
+ delete rawGtFlags.autoDerive;
91
+ }
92
+ return {
93
+ publish: files.gt?.publish,
94
+ parsingFlags: {
95
+ ...GT_PARSING_FLAGS_DEFAULT,
96
+ ...rawGtFlags
97
+ }
98
+ };
99
+ })()
100
+ };
126
101
  }
127
- // Helper function to expand glob patterns
128
- export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, locales, transformPatterns, compositePatterns) {
129
- // Expand glob patterns to include all matching files
130
- const resolvedPaths = [];
131
- const placeholderPaths = [];
132
- // Process include patterns
133
- for (const pattern of includePatterns) {
134
- // Track positions where [locale] appears in the original pattern
135
- // It must be included in the pattern, otherwise the CLI tool will not be able to find the correct output path
136
- // Warn if it's not included
137
- // Ignore if is composite pattern
138
- if (!pattern.includes('[locale]') &&
139
- !transformPatterns &&
140
- !compositePatterns?.includes(pattern)) {
141
- logger.warn(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
142
- }
143
- const localePositions = [];
144
- let searchIndex = 0;
145
- const localeTag = '[locale]';
146
- while (true) {
147
- const foundIndex = pattern.indexOf(localeTag, searchIndex);
148
- if (foundIndex === -1)
149
- break;
150
- localePositions.push(foundIndex);
151
- searchIndex = foundIndex + localeTag.length;
152
- }
153
- const expandedPattern = pattern.replace(/\[locale\]/g, locale);
154
- // Resolve the absolute pattern path
155
- const absolutePattern = path.resolve(cwd, expandedPattern);
156
- // Prepare exclude patterns with locale replaced
157
- const expandedExcludePatterns = Array.from(new Set(excludePatterns.flatMap((p) => locales.map((targetLocale) => path.resolve(cwd, p
158
- .replace(/\[locale\]/g, locale)
159
- .replace(/\[locales\]/g, targetLocale))))));
160
- // Use fast-glob to find all matching files, excluding the patterns
161
- const matches = fg.sync(absolutePattern, {
162
- absolute: true,
163
- ignore: expandedExcludePatterns,
164
- });
165
- resolvedPaths.push(...matches);
166
- // For each match, create a version with [locale] in the correct positions
167
- matches.forEach((match) => {
168
- const absolutePath = path.resolve(cwd, match);
169
- const patternPath = path.resolve(cwd, pattern);
170
- let originalAbsolutePath = absolutePath;
171
- if (localePositions.length > 0) {
172
- const placeholderPath = buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag);
173
- originalAbsolutePath = placeholderPath;
174
- }
175
- placeholderPaths.push(originalAbsolutePath);
176
- });
177
- }
178
- return { resolvedPaths, placeholderPaths };
102
+ function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, locales, transformPatterns, compositePatterns) {
103
+ const resolvedPaths = [];
104
+ const placeholderPaths = [];
105
+ for (const pattern of includePatterns) {
106
+ if (!pattern.includes("[locale]") && !transformPatterns && !compositePatterns?.includes(pattern)) logger.warn(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
107
+ const localePositions = [];
108
+ let searchIndex = 0;
109
+ const localeTag = "[locale]";
110
+ while (true) {
111
+ const foundIndex = pattern.indexOf(localeTag, searchIndex);
112
+ if (foundIndex === -1) break;
113
+ localePositions.push(foundIndex);
114
+ searchIndex = foundIndex + 8;
115
+ }
116
+ const expandedPattern = pattern.replace(/\[locale\]/g, locale);
117
+ const absolutePattern = path.resolve(cwd, expandedPattern);
118
+ const expandedExcludePatterns = Array.from(new Set(excludePatterns.flatMap((p) => locales.map((targetLocale) => path.resolve(cwd, p.replace(/\[locale\]/g, locale).replace(/\[locales\]/g, targetLocale))))));
119
+ const matches = fg.sync(absolutePattern, {
120
+ absolute: true,
121
+ ignore: expandedExcludePatterns
122
+ });
123
+ resolvedPaths.push(...matches);
124
+ matches.forEach((match) => {
125
+ const absolutePath = path.resolve(cwd, match);
126
+ const patternPath = path.resolve(cwd, pattern);
127
+ let originalAbsolutePath = absolutePath;
128
+ if (localePositions.length > 0) originalAbsolutePath = buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag);
129
+ placeholderPaths.push(originalAbsolutePath);
130
+ });
131
+ }
132
+ return {
133
+ resolvedPaths,
134
+ placeholderPaths
135
+ };
179
136
  }
180
137
  function buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag) {
181
- if (!patternPath.includes(localeTag)) {
182
- return absolutePath;
183
- }
184
- const posixPattern = toPosixPath(patternPath);
185
- const posixPath = toPosixPath(absolutePath);
186
- const baseRegex = micromatch.makeRe(posixPattern, {
187
- literalBrackets: true,
188
- });
189
- const localeRegexSource = baseRegex.source.replace(/\\\[locale\\\]/g, '([^/]+)');
190
- const flags = baseRegex.flags.includes('d')
191
- ? baseRegex.flags
192
- : `${baseRegex.flags}d`;
193
- const matcher = new RegExp(localeRegexSource, flags);
194
- const match = matcher.exec(posixPath);
195
- const matchWithIndices = match;
196
- if (!match || !matchWithIndices.indices) {
197
- return absolutePath;
198
- }
199
- let placeholderPosixPath = posixPath;
200
- const indices = matchWithIndices.indices;
201
- for (let i = indices.length - 1; i >= 1; i--) {
202
- const [start, end] = indices[i];
203
- if (start === -1 || end === -1)
204
- continue;
205
- placeholderPosixPath =
206
- placeholderPosixPath.slice(0, start) +
207
- localeTag +
208
- placeholderPosixPath.slice(end);
209
- }
210
- return path.normalize(placeholderPosixPath);
138
+ if (!patternPath.includes(localeTag)) return absolutePath;
139
+ const posixPattern = toPosixPath(patternPath);
140
+ const posixPath = toPosixPath(absolutePath);
141
+ const baseRegex = micromatch.makeRe(posixPattern, { literalBrackets: true });
142
+ const localeRegexSource = baseRegex.source.replace(/\\\[locale\\\]/g, "([^/]+)");
143
+ const flags = baseRegex.flags.includes("d") ? baseRegex.flags : `${baseRegex.flags}d`;
144
+ const match = new RegExp(localeRegexSource, flags).exec(posixPath);
145
+ const matchWithIndices = match;
146
+ if (!match || !matchWithIndices.indices) return absolutePath;
147
+ let placeholderPosixPath = posixPath;
148
+ const indices = matchWithIndices.indices;
149
+ for (let i = indices.length - 1; i >= 1; i--) {
150
+ const [start, end] = indices[i];
151
+ if (start === -1 || end === -1) continue;
152
+ placeholderPosixPath = placeholderPosixPath.slice(0, start) + localeTag + placeholderPosixPath.slice(end);
153
+ }
154
+ return path.normalize(placeholderPosixPath);
211
155
  }
212
156
  function toPosixPath(value) {
213
- return value.split(path.sep).join(path.posix.sep);
157
+ return value.split(path.sep).join(path.posix.sep);
214
158
  }
215
159
  /**
216
- * Classifies resolved file paths into publish/unpublish sets by matching
217
- * them against the given glob patterns. Uses POSIX paths for micromatch
218
- * compatibility but stores platform-native paths in the output sets.
219
- */
160
+ * Classifies resolved file paths into publish/unpublish sets by matching
161
+ * them against the given glob patterns. Uses POSIX paths for micromatch
162
+ * compatibility but stores platform-native paths in the output sets.
163
+ */
220
164
  function classifyPublishPaths(resolvedPaths, publishPatterns, unpublishPatterns, cwd, locale, publishPaths, unpublishPaths) {
221
- if (publishPatterns.length === 0 && unpublishPatterns.length === 0)
222
- return;
223
- const posixPaths = resolvedPaths.map(toPosixPath);
224
- const toAbsoluteGlob = (p) => toPosixPath(path.resolve(cwd, p.replace(/\[locale\]/g, locale)));
225
- for (const pattern of publishPatterns) {
226
- const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));
227
- for (let i = 0; i < posixPaths.length; i++) {
228
- if (matched.has(posixPaths[i])) {
229
- publishPaths.add(resolvedPaths[i]);
230
- }
231
- }
232
- }
233
- for (const pattern of unpublishPatterns) {
234
- const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));
235
- for (let i = 0; i < posixPaths.length; i++) {
236
- if (matched.has(posixPaths[i])) {
237
- unpublishPaths.add(resolvedPaths[i]);
238
- }
239
- }
240
- }
165
+ if (publishPatterns.length === 0 && unpublishPatterns.length === 0) return;
166
+ const posixPaths = resolvedPaths.map(toPosixPath);
167
+ const toAbsoluteGlob = (p) => toPosixPath(path.resolve(cwd, p.replace(/\[locale\]/g, locale)));
168
+ for (const pattern of publishPatterns) {
169
+ const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));
170
+ for (let i = 0; i < posixPaths.length; i++) if (matched.has(posixPaths[i])) publishPaths.add(resolvedPaths[i]);
171
+ }
172
+ for (const pattern of unpublishPatterns) {
173
+ const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));
174
+ for (let i = 0; i < posixPaths.length; i++) if (matched.has(posixPaths[i])) unpublishPaths.add(resolvedPaths[i]);
175
+ }
241
176
  }
177
+ //#endregion
178
+ export { expandGlobPatterns, normalizeIncludePatterns, resolveFiles, resolveLocaleFiles };
179
+
180
+ //# sourceMappingURL=parseFilesConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseFilesConfig.js","names":[],"sources":["../../../src/fs/config/parseFilesConfig.ts"],"sourcesContent":["import path from 'node:path';\nimport {\n FilesOptions,\n IncludePattern,\n ResolvedFiles,\n Settings,\n TransformFormats,\n TransformFiles,\n TransformOption,\n} from '../../types/index.js';\nimport fg from 'fast-glob';\nimport { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';\nimport { logger } from '../../console/logger.js';\nimport chalk from 'chalk';\nimport micromatch from 'micromatch';\nimport { ParseFlagsByFileType } from '../../types/parsing.js';\nimport {\n BASE_PARSING_FLAGS_DEFAULT,\n GT_PARSING_FLAGS_DEFAULT,\n} from '../../config/defaults.js';\nimport { resolveTransformationFormat } from '../../formats/files/transformFormat.js';\n\n/**\n * Resolves the files from the files object\n * Replaces [locale] with the actual locale in the files\n *\n * @param files - The files object\n * @param locale - The locale to replace [locale] with\n * @returns The resolved files\n */\nexport function resolveLocaleFiles(\n files: ResolvedFiles,\n locale: string\n): ResolvedFiles {\n const result: ResolvedFiles = {};\n\n for (const fileType of SUPPORTED_FILE_EXTENSIONS) {\n result[fileType] = files[fileType]?.map((filepath) =>\n filepath.replace(/\\[locale\\]/g, locale)\n );\n }\n\n // Replace [locale] with locale in all paths\n result.gt = files.gt?.replace(/\\[locale\\]/g, locale);\n\n return result;\n}\n/**\n * Normalizes include patterns into plain path strings and tracks which\n * patterns have explicit publish flags.\n */\nexport function normalizeIncludePatterns(patterns: IncludePattern[]): {\n paths: string[];\n publishPatterns: string[];\n unpublishPatterns: string[];\n} {\n const paths: string[] = [];\n const publishPatterns: string[] = [];\n const unpublishPatterns: string[] = [];\n\n for (const pattern of patterns) {\n if (typeof pattern === 'string') {\n paths.push(pattern);\n } else {\n paths.push(pattern.pattern);\n if (pattern.publish === true) {\n publishPatterns.push(pattern.pattern);\n } else if (pattern.publish === false) {\n unpublishPatterns.push(pattern.pattern);\n }\n }\n }\n\n return { paths, publishPatterns, unpublishPatterns };\n}\n\n/**\n * Resolves the files from the files object.\n * Performs glob pattern expansion on the files.\n * Replaces [locale] with the actual locale in the files.\n *\n * @param files - The files object\n * @returns The resolved files\n */\nexport function resolveFiles(\n files: FilesOptions,\n locale: string,\n locales: string[],\n cwd: string,\n compositePatterns?: string[]\n): Settings['files'] {\n // Initialize result object with empty arrays for each file type\n const resolvedPaths: ResolvedFiles = {};\n const placeholderResult: ResolvedFiles = {};\n const transformPaths: TransformFiles = {};\n // Output format transforms are tracked separately from path transforms.\n const transformFormats: TransformFormats = {};\n const publishPaths = new Set<string>();\n const unpublishPaths = new Set<string>();\n const parsingFlags: ParseFlagsByFileType = {};\n\n // Process GT files\n if (files.gt?.output) {\n placeholderResult.gt = path.resolve(cwd, files.gt.output);\n }\n\n for (const fileType of SUPPORTED_FILE_EXTENSIONS) {\n // ==== TRANSFORMS ==== //\n const transform = files[fileType]?.transform;\n if (\n transform &&\n (typeof transform === 'string' ||\n typeof transform === 'object' ||\n Array.isArray(transform))\n ) {\n transformPaths[fileType] = transform;\n }\n // Validate source -> output format transforms during settings generation.\n const transformFormat = resolveTransformationFormat(\n fileType,\n files[fileType]?.transformationFormat\n );\n if (transformFormat) {\n transformFormats[fileType] = transformFormat;\n }\n // ==== PLACEHOLDERS ==== //\n if (files[fileType]?.include) {\n const { paths, publishPatterns, unpublishPatterns } =\n normalizeIncludePatterns(files[fileType].include);\n\n const filePaths = expandGlobPatterns(\n cwd,\n paths,\n files[fileType]?.exclude || [],\n locale,\n locales,\n transformPaths[fileType] || undefined,\n compositePatterns\n );\n resolvedPaths[fileType] = filePaths.resolvedPaths;\n placeholderResult[fileType] = filePaths.placeholderPaths;\n\n // Classify resolved paths into publish/unpublish sets\n classifyPublishPaths(\n filePaths.resolvedPaths,\n publishPatterns,\n unpublishPatterns,\n cwd,\n locale,\n publishPaths,\n unpublishPaths\n );\n }\n // ==== OTHER ==== //\n if (files[fileType]?.parsingFlags) {\n parsingFlags[fileType] = {\n ...BASE_PARSING_FLAGS_DEFAULT,\n ...files[fileType].parsingFlags,\n };\n }\n }\n\n return {\n resolvedPaths,\n placeholderPaths: placeholderResult,\n transformPaths: transformPaths,\n transformFormats,\n publishPaths,\n unpublishPaths,\n parsingFlags,\n gtJson: (() => {\n const rawGtFlags = (files.gt?.parsingFlags || {}) as Record<\n string,\n unknown\n >;\n if ('autoDerive' in rawGtFlags && !('autoderive' in rawGtFlags)) {\n rawGtFlags.autoderive = rawGtFlags.autoDerive;\n delete rawGtFlags.autoDerive;\n }\n return {\n publish: files.gt?.publish,\n parsingFlags: {\n ...GT_PARSING_FLAGS_DEFAULT,\n ...rawGtFlags,\n },\n };\n })(),\n };\n}\n\n// Helper function to expand glob patterns\nexport function expandGlobPatterns(\n cwd: string,\n includePatterns: string[],\n excludePatterns: string[],\n locale: string,\n locales: string[],\n transformPatterns?: TransformOption | string | TransformOption[],\n compositePatterns?: string[]\n): {\n resolvedPaths: string[];\n placeholderPaths: string[];\n} {\n // Expand glob patterns to include all matching files\n const resolvedPaths: string[] = [];\n const placeholderPaths: string[] = [];\n\n // Process include patterns\n for (const pattern of includePatterns) {\n // Track positions where [locale] appears in the original pattern\n // It must be included in the pattern, otherwise the CLI tool will not be able to find the correct output path\n // Warn if it's not included\n // Ignore if is composite pattern\n if (\n !pattern.includes('[locale]') &&\n !transformPatterns &&\n !compositePatterns?.includes(pattern)\n ) {\n logger.warn(\n chalk.yellow(\n `Pattern \"${pattern}\" does not include [locale], so the CLI tool may incorrectly save translated files.`\n )\n );\n }\n const localePositions: number[] = [];\n let searchIndex = 0;\n const localeTag = '[locale]';\n\n while (true) {\n const foundIndex = pattern.indexOf(localeTag, searchIndex);\n if (foundIndex === -1) break;\n localePositions.push(foundIndex);\n searchIndex = foundIndex + localeTag.length;\n }\n\n const expandedPattern = pattern.replace(/\\[locale\\]/g, locale);\n\n // Resolve the absolute pattern path\n const absolutePattern = path.resolve(cwd, expandedPattern);\n\n // Prepare exclude patterns with locale replaced\n const expandedExcludePatterns = Array.from(\n new Set(\n excludePatterns.flatMap((p) =>\n locales.map((targetLocale) =>\n path.resolve(\n cwd,\n p\n .replace(/\\[locale\\]/g, locale)\n .replace(/\\[locales\\]/g, targetLocale)\n )\n )\n )\n )\n );\n\n // Use fast-glob to find all matching files, excluding the patterns\n const matches = fg.sync(absolutePattern, {\n absolute: true,\n ignore: expandedExcludePatterns,\n });\n\n resolvedPaths.push(...matches);\n\n // For each match, create a version with [locale] in the correct positions\n matches.forEach((match) => {\n const absolutePath = path.resolve(cwd, match);\n const patternPath = path.resolve(cwd, pattern);\n let originalAbsolutePath = absolutePath;\n\n if (localePositions.length > 0) {\n const placeholderPath = buildPlaceholderPathFromPattern(\n patternPath,\n absolutePath,\n localeTag\n );\n originalAbsolutePath = placeholderPath;\n }\n\n placeholderPaths.push(originalAbsolutePath);\n });\n }\n\n return { resolvedPaths, placeholderPaths };\n}\n\nfunction buildPlaceholderPathFromPattern(\n patternPath: string,\n absolutePath: string,\n localeTag: string\n): string {\n if (!patternPath.includes(localeTag)) {\n return absolutePath;\n }\n\n const posixPattern = toPosixPath(patternPath);\n const posixPath = toPosixPath(absolutePath);\n\n const baseRegex = micromatch.makeRe(posixPattern, {\n literalBrackets: true,\n });\n const localeRegexSource = baseRegex.source.replace(\n /\\\\\\[locale\\\\\\]/g,\n '([^/]+)'\n );\n const flags = baseRegex.flags.includes('d')\n ? baseRegex.flags\n : `${baseRegex.flags}d`;\n const matcher = new RegExp(localeRegexSource, flags);\n const match = matcher.exec(posixPath);\n\n const matchWithIndices = match as RegExpExecArray & {\n indices?: Array<[number, number]>;\n };\n\n if (!match || !matchWithIndices.indices) {\n return absolutePath;\n }\n\n let placeholderPosixPath = posixPath;\n const indices = matchWithIndices.indices;\n\n for (let i = indices.length - 1; i >= 1; i--) {\n const [start, end] = indices[i];\n if (start === -1 || end === -1) continue;\n placeholderPosixPath =\n placeholderPosixPath.slice(0, start) +\n localeTag +\n placeholderPosixPath.slice(end);\n }\n\n return path.normalize(placeholderPosixPath);\n}\n\nfunction toPosixPath(value: string): string {\n return value.split(path.sep).join(path.posix.sep);\n}\n\n/**\n * Classifies resolved file paths into publish/unpublish sets by matching\n * them against the given glob patterns. Uses POSIX paths for micromatch\n * compatibility but stores platform-native paths in the output sets.\n */\nfunction classifyPublishPaths(\n resolvedPaths: string[],\n publishPatterns: string[],\n unpublishPatterns: string[],\n cwd: string,\n locale: string,\n publishPaths: Set<string>,\n unpublishPaths: Set<string>\n): void {\n if (publishPatterns.length === 0 && unpublishPatterns.length === 0) return;\n\n const posixPaths = resolvedPaths.map(toPosixPath);\n const toAbsoluteGlob = (p: string) =>\n toPosixPath(path.resolve(cwd, p.replace(/\\[locale\\]/g, locale)));\n\n for (const pattern of publishPatterns) {\n const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));\n for (let i = 0; i < posixPaths.length; i++) {\n if (matched.has(posixPaths[i])) {\n publishPaths.add(resolvedPaths[i]);\n }\n }\n }\n\n for (const pattern of unpublishPatterns) {\n const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));\n for (let i = 0; i < posixPaths.length; i++) {\n if (matched.has(posixPaths[i])) {\n unpublishPaths.add(resolvedPaths[i]);\n }\n }\n }\n}\n"],"mappings":"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"}
@@ -1,54 +1,45 @@
1
- import fs from 'node:fs';
2
- import { displayCreatedConfigFile } from '../../console/logging.js';
3
- import { logger } from '../../console/logger.js';
4
- import { GT_CONFIG_SCHEMA_URL } from '../../utils/constants.js';
1
+ import { logger } from "../../console/logger.js";
2
+ import { GT_CONFIG_SCHEMA_URL } from "../../utils/constants.js";
3
+ import { displayCreatedConfigFile } from "../../console/logging.js";
4
+ import fs from "node:fs";
5
+ //#region src/fs/config/setupConfig.ts
5
6
  /**
6
- * Checks if the config file exists.
7
- * If yes, make sure make sure projectId is correct
8
- * If not, creates a new JSON file at the given filepath and writes the provided config object to it.
9
- * @param {string} configFilepath - The path to the config file.
10
- * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
11
- */
12
- export async function createOrUpdateConfig(configFilepath, options) {
13
- // Filter out empty string values from the config object
14
- const newContent = {
15
- ...(options.projectId && { projectId: options.projectId }),
16
- ...(options.defaultLocale && { defaultLocale: options.defaultLocale }),
17
- ...(options.files && { files: options.files }),
18
- ...(options.framework && { framework: options.framework }),
19
- ...(options.baseUrl && { baseUrl: options.baseUrl }),
20
- ...(options.publish && { publish: options.publish }),
21
- };
22
- try {
23
- // if file exists
24
- let oldContent = {};
25
- if (fs.existsSync(configFilepath)) {
26
- const parsed = JSON.parse(await fs.promises.readFile(configFilepath, 'utf-8'));
27
- oldContent =
28
- typeof parsed === 'object' && parsed !== null
29
- ? parsed
30
- : {};
31
- }
32
- // merge old and new content
33
- const mergedContent = {
34
- $schema: GT_CONFIG_SCHEMA_URL,
35
- ...oldContent,
36
- ...newContent,
37
- };
38
- // Add locales to mergedContent if they exist
39
- if (options.locales) {
40
- mergedContent.locales = mergedContent.locales
41
- ? [...new Set([...mergedContent.locales, ...options.locales])]
42
- : options.locales;
43
- }
44
- // write to file
45
- const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
46
- await fs.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');
47
- // show update in console
48
- displayCreatedConfigFile(configFilepath);
49
- }
50
- catch (error) {
51
- logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
52
- }
53
- return configFilepath;
7
+ * Checks if the config file exists.
8
+ * If yes, make sure make sure projectId is correct
9
+ * If not, creates a new JSON file at the given filepath and writes the provided config object to it.
10
+ * @param {string} configFilepath - The path to the config file.
11
+ * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
12
+ */
13
+ async function createOrUpdateConfig(configFilepath, options) {
14
+ const newContent = {
15
+ ...options.projectId && { projectId: options.projectId },
16
+ ...options.defaultLocale && { defaultLocale: options.defaultLocale },
17
+ ...options.files && { files: options.files },
18
+ ...options.framework && { framework: options.framework },
19
+ ...options.baseUrl && { baseUrl: options.baseUrl },
20
+ ...options.publish && { publish: options.publish }
21
+ };
22
+ try {
23
+ let oldContent = {};
24
+ if (fs.existsSync(configFilepath)) {
25
+ const parsed = JSON.parse(await fs.promises.readFile(configFilepath, "utf-8"));
26
+ oldContent = typeof parsed === "object" && parsed !== null ? parsed : {};
27
+ }
28
+ const mergedContent = {
29
+ $schema: GT_CONFIG_SCHEMA_URL,
30
+ ...oldContent,
31
+ ...newContent
32
+ };
33
+ if (options.locales) mergedContent.locales = mergedContent.locales ? [...new Set([...mergedContent.locales, ...options.locales])] : options.locales;
34
+ const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
35
+ await fs.promises.writeFile(configFilepath, mergedJsonContent, "utf-8");
36
+ displayCreatedConfigFile(configFilepath);
37
+ } catch (error) {
38
+ logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
39
+ }
40
+ return configFilepath;
54
41
  }
42
+ //#endregion
43
+ export { createOrUpdateConfig };
44
+
45
+ //# sourceMappingURL=setupConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupConfig.js","names":[],"sources":["../../../src/fs/config/setupConfig.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { displayCreatedConfigFile } from '../../console/logging.js';\nimport { FilesOptions, SupportedFrameworks } from '../../types/index.js';\nimport { logger } from '../../console/logger.js';\nimport { GT_CONFIG_SCHEMA_URL } from '../../utils/constants.js';\n\n/**\n * Checks if the config file exists.\n * If yes, make sure make sure projectId is correct\n * If not, creates a new JSON file at the given filepath and writes the provided config object to it.\n * @param {string} configFilepath - The path to the config file.\n * @param {Record<string, any>} configObject - The config object to write if the file does not exist.\n */\nexport async function createOrUpdateConfig(\n configFilepath: string,\n options: {\n projectId?: string;\n defaultLocale?: string;\n locales?: string[];\n files?: FilesOptions;\n framework?: SupportedFrameworks;\n baseUrl?: string;\n publish?: boolean;\n }\n): Promise<string> {\n // Filter out empty string values from the config object\n const newContent = {\n ...(options.projectId && { projectId: options.projectId }),\n ...(options.defaultLocale && { defaultLocale: options.defaultLocale }),\n ...(options.files && { files: options.files }),\n ...(options.framework && { framework: options.framework }),\n ...(options.baseUrl && { baseUrl: options.baseUrl }),\n ...(options.publish && { publish: options.publish }),\n };\n try {\n // if file exists\n let oldContent: Record<string, unknown> = {};\n if (fs.existsSync(configFilepath)) {\n const parsed = JSON.parse(\n await fs.promises.readFile(configFilepath, 'utf-8')\n );\n oldContent =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as Record<string, unknown>)\n : {};\n }\n\n // merge old and new content\n const mergedContent = {\n $schema: GT_CONFIG_SCHEMA_URL,\n ...oldContent,\n ...newContent,\n } as Record<string, unknown> & { locales?: string[] };\n\n // Add locales to mergedContent if they exist\n if (options.locales) {\n mergedContent.locales = mergedContent.locales\n ? [...new Set([...mergedContent.locales, ...options.locales])]\n : options.locales;\n }\n\n // write to file\n const mergedJsonContent = JSON.stringify(mergedContent, null, 2);\n await fs.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');\n\n // show update in console\n displayCreatedConfigFile(configFilepath);\n } catch (error) {\n logger.error(\n `An error occurred while updating ${configFilepath}: ${error}`\n );\n }\n return configFilepath;\n}\n"],"mappings":";;;;;;;;;;;;AAaA,eAAsB,qBACpB,gBACA,SASiB;CAEjB,MAAM,aAAa;EACjB,GAAI,QAAQ,aAAa,EAAE,WAAW,QAAQ,WAAW;EACzD,GAAI,QAAQ,iBAAiB,EAAE,eAAe,QAAQ,eAAe;EACrE,GAAI,QAAQ,SAAS,EAAE,OAAO,QAAQ,OAAO;EAC7C,GAAI,QAAQ,aAAa,EAAE,WAAW,QAAQ,WAAW;EACzD,GAAI,QAAQ,WAAW,EAAE,SAAS,QAAQ,SAAS;EACnD,GAAI,QAAQ,WAAW,EAAE,SAAS,QAAQ,SAAS;EACpD;AACD,KAAI;EAEF,IAAI,aAAsC,EAAE;AAC5C,MAAI,GAAG,WAAW,eAAe,EAAE;GACjC,MAAM,SAAS,KAAK,MAClB,MAAM,GAAG,SAAS,SAAS,gBAAgB,QAAQ,CACpD;AACD,gBACE,OAAO,WAAW,YAAY,WAAW,OACpC,SACD,EAAE;;EAIV,MAAM,gBAAgB;GACpB,SAAS;GACT,GAAG;GACH,GAAG;GACJ;AAGD,MAAI,QAAQ,QACV,eAAc,UAAU,cAAc,UAClC,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,cAAc,SAAS,GAAG,QAAQ,QAAQ,CAAC,CAAC,GAC5D,QAAQ;EAId,MAAM,oBAAoB,KAAK,UAAU,eAAe,MAAM,EAAE;AAChE,QAAM,GAAG,SAAS,UAAU,gBAAgB,mBAAmB,QAAQ;AAGvE,2BAAyB,eAAe;UACjC,OAAO;AACd,SAAO,MACL,oCAAoC,eAAe,IAAI,QACxD;;AAEH,QAAO"}