@intlayer/engine 9.2.0 → 9.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/README.md +24 -24
  2. package/dist/assets/initConfig/templates/cjs.txt +1 -1
  3. package/dist/assets/initConfig/templates/mjs.txt +1 -1
  4. package/dist/assets/initConfig/templates/ts.txt +1 -1
  5. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
  6. package/dist/cjs/_virtual/_utils_asset.cjs +2 -1
  7. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +14 -2
  8. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
  9. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +26 -5
  10. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
  11. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +43 -6
  12. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -1
  13. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +2 -1
  14. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs.map +1 -1
  15. package/dist/cjs/buildIntlayerDictionary/writeNestedDictionary.cjs +96 -0
  16. package/dist/cjs/buildIntlayerDictionary/writeNestedDictionary.cjs.map +1 -0
  17. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +4 -2
  18. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs.map +1 -1
  19. package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs.map +1 -1
  20. package/dist/cjs/cleanOutputDir.cjs.map +1 -1
  21. package/dist/cjs/cleanRemovedContentDeclaration.cjs +7 -4
  22. package/dist/cjs/cleanRemovedContentDeclaration.cjs.map +1 -1
  23. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +5 -3
  24. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs.map +1 -1
  25. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
  26. package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs.map +1 -1
  27. package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs.map +1 -1
  28. package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs.map +1 -1
  29. package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs.map +1 -1
  30. package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs.map +1 -1
  31. package/dist/cjs/createType/createModuleAugmentation.cjs +2 -1
  32. package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
  33. package/dist/cjs/createType/createType.cjs.map +1 -1
  34. package/dist/cjs/detectFormatCommand.cjs.map +1 -1
  35. package/dist/cjs/docReview/alignBlocks.cjs +1 -1
  36. package/dist/cjs/docReview/alignBlocks.cjs.map +1 -1
  37. package/dist/cjs/docReview/computeSimilarity.cjs +0 -1
  38. package/dist/cjs/docReview/computeSimilarity.cjs.map +1 -1
  39. package/dist/cjs/docReview/mapChangedLinesToBlocks.cjs +0 -1
  40. package/dist/cjs/docReview/mapChangedLinesToBlocks.cjs.map +1 -1
  41. package/dist/cjs/docReview/normalizeBlock.cjs +0 -1
  42. package/dist/cjs/docReview/normalizeBlock.cjs.map +1 -1
  43. package/dist/cjs/docReview/planActions.cjs +0 -1
  44. package/dist/cjs/docReview/planActions.cjs.map +1 -1
  45. package/dist/cjs/docReview/rebuildDocument.cjs +0 -1
  46. package/dist/cjs/docReview/rebuildDocument.cjs.map +1 -1
  47. package/dist/cjs/docReview/reviewReport.cjs +2 -1
  48. package/dist/cjs/docReview/reviewReport.cjs.map +1 -1
  49. package/dist/cjs/docReview/segmentDocument.cjs +0 -1
  50. package/dist/cjs/docReview/segmentDocument.cjs.map +1 -1
  51. package/dist/cjs/fetchDistantDictionaries.cjs +107 -13
  52. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  53. package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -1
  54. package/dist/cjs/formatDictionary.cjs.map +1 -1
  55. package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -1
  56. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +4 -2
  57. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs.map +1 -1
  58. package/dist/cjs/handleContentDeclarationFileChange.cjs +6 -2
  59. package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
  60. package/dist/cjs/handleContentDeclarationFileMoved.cjs.map +1 -1
  61. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +4 -2
  62. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs.map +1 -1
  63. package/dist/cjs/init/cms.cjs.map +1 -1
  64. package/dist/cjs/init/frameworkSetup/nextAppRouter/detect.cjs.map +1 -1
  65. package/dist/cjs/init/frameworkSetup/nextAppRouter/index.cjs +1 -3
  66. package/dist/cjs/init/frameworkSetup/nextAppRouter/index.cjs.map +1 -1
  67. package/dist/cjs/init/frameworkSetup/nextAppRouter/restructure.cjs +2 -1
  68. package/dist/cjs/init/frameworkSetup/nextAppRouter/restructure.cjs.map +1 -1
  69. package/dist/cjs/init/frameworkSetup/nextAppRouter/templates.cjs +0 -1
  70. package/dist/cjs/init/frameworkSetup/nextAppRouter/templates.cjs.map +1 -1
  71. package/dist/cjs/init/frameworkSetup/tanstackStart/detect.cjs.map +1 -1
  72. package/dist/cjs/init/frameworkSetup/tanstackStart/index.cjs +3 -5
  73. package/dist/cjs/init/frameworkSetup/tanstackStart/index.cjs.map +1 -1
  74. package/dist/cjs/init/frameworkSetup/tanstackStart/restructure.cjs +2 -1
  75. package/dist/cjs/init/frameworkSetup/tanstackStart/restructure.cjs.map +1 -1
  76. package/dist/cjs/init/frameworkSetup/tanstackStart/templates.cjs +18 -12
  77. package/dist/cjs/init/frameworkSetup/tanstackStart/templates.cjs.map +1 -1
  78. package/dist/cjs/init/frameworkSetup/tanstackStart/transforms.cjs +58 -15
  79. package/dist/cjs/init/frameworkSetup/tanstackStart/transforms.cjs.map +1 -1
  80. package/dist/cjs/init/index.cjs +66 -38
  81. package/dist/cjs/init/index.cjs.map +1 -1
  82. package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
  83. package/dist/cjs/init/utils/fileSystem.cjs +3 -1
  84. package/dist/cjs/init/utils/fileSystem.cjs.map +1 -1
  85. package/dist/cjs/init/utils/githubActions.cjs.map +1 -1
  86. package/dist/cjs/init/utils/jsonParser.cjs +0 -1
  87. package/dist/cjs/init/utils/jsonParser.cjs.map +1 -1
  88. package/dist/cjs/init/utils/nextCompilerBabel.cjs.map +1 -1
  89. package/dist/cjs/init/utils/packageManager.cjs +4 -2
  90. package/dist/cjs/init/utils/packageManager.cjs.map +1 -1
  91. package/dist/cjs/init/utils/tsConfig.cjs.map +1 -1
  92. package/dist/cjs/init/utils/version.cjs +0 -1
  93. package/dist/cjs/init/utils/version.cjs.map +1 -1
  94. package/dist/cjs/initConfig/index.cjs +12 -8
  95. package/dist/cjs/initConfig/index.cjs.map +1 -1
  96. package/dist/cjs/installSkills/index.cjs.map +1 -1
  97. package/dist/cjs/listDictionariesPath.cjs +6 -5
  98. package/dist/cjs/listDictionariesPath.cjs.map +1 -1
  99. package/dist/cjs/listGitFiles.cjs.map +1 -1
  100. package/dist/cjs/listProjects.cjs +2 -1
  101. package/dist/cjs/listProjects.cjs.map +1 -1
  102. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +2 -1
  103. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs.map +1 -1
  104. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +8 -5
  105. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
  106. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +4 -2
  107. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  108. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
  109. package/dist/cjs/loadDictionaries/loadMarkdownContentDeclaration.cjs.map +1 -1
  110. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +3 -2
  111. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
  112. package/dist/cjs/loadDictionaries/loadYamlContentDeclaration.cjs +2 -1
  113. package/dist/cjs/loadDictionaries/loadYamlContentDeclaration.cjs.map +1 -1
  114. package/dist/cjs/loadDictionaries/log.cjs +38 -11
  115. package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
  116. package/dist/cjs/loadDictionaries/logTypeScriptErrors.cjs.map +1 -1
  117. package/dist/cjs/logConfigDetails.cjs +4 -3
  118. package/dist/cjs/logConfigDetails.cjs.map +1 -1
  119. package/dist/cjs/prepareIntlayer.cjs +5 -3
  120. package/dist/cjs/prepareIntlayer.cjs.map +1 -1
  121. package/dist/cjs/reduceDictionaryContent/applyMask.cjs +0 -1
  122. package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -1
  123. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +2 -1
  124. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -1
  125. package/dist/cjs/scan/calculateScore.cjs +0 -1
  126. package/dist/cjs/scan/calculateScore.cjs.map +1 -1
  127. package/dist/cjs/scan/checks.cjs +1 -1
  128. package/dist/cjs/scan/checks.cjs.map +1 -1
  129. package/dist/cjs/scan/parseHtml.cjs +0 -1
  130. package/dist/cjs/scan/parseHtml.cjs.map +1 -1
  131. package/dist/cjs/scan/scanWebsite.cjs.map +1 -1
  132. package/dist/cjs/syncPluginKit/createFileAdapter.cjs +2 -1
  133. package/dist/cjs/syncPluginKit/createFileAdapter.cjs.map +1 -1
  134. package/dist/cjs/syncPluginKit/createSyncPlugin.cjs +4 -1
  135. package/dist/cjs/syncPluginKit/createSyncPlugin.cjs.map +1 -1
  136. package/dist/cjs/syncPluginKit/extractKeyAndLocaleFromPath.cjs +0 -1
  137. package/dist/cjs/syncPluginKit/extractKeyAndLocaleFromPath.cjs.map +1 -1
  138. package/dist/cjs/syncPluginKit/filePathPatternHelpers.cjs +0 -1
  139. package/dist/cjs/syncPluginKit/filePathPatternHelpers.cjs.map +1 -1
  140. package/dist/cjs/utils/autoDecorateContent.cjs.map +1 -1
  141. package/dist/cjs/utils/babelParser.cjs.map +1 -1
  142. package/dist/cjs/utils/buildComponentFilesList.cjs.map +1 -1
  143. package/dist/cjs/utils/buildFilesList.cjs.map +1 -1
  144. package/dist/cjs/utils/chunkArray.cjs +23 -0
  145. package/dist/cjs/utils/chunkArray.cjs.map +1 -0
  146. package/dist/cjs/utils/formatter.cjs.map +1 -1
  147. package/dist/cjs/utils/getContentExtension.cjs +1 -4
  148. package/dist/cjs/utils/getContentExtension.cjs.map +1 -1
  149. package/dist/cjs/utils/getFormatFromExtension.cjs +0 -1
  150. package/dist/cjs/utils/getFormatFromExtension.cjs.map +1 -1
  151. package/dist/cjs/utils/getPathHash.cjs +0 -1
  152. package/dist/cjs/utils/getPathHash.cjs.map +1 -1
  153. package/dist/cjs/utils/index.cjs +2 -0
  154. package/dist/cjs/utils/mergeChunks.cjs +0 -1
  155. package/dist/cjs/utils/mergeChunks.cjs.map +1 -1
  156. package/dist/cjs/utils/pLimit.cjs +0 -1
  157. package/dist/cjs/utils/pLimit.cjs.map +1 -1
  158. package/dist/cjs/utils/readDictionariesFromDisk.cjs.map +1 -1
  159. package/dist/cjs/utils/reduceObjectFormat.cjs +0 -1
  160. package/dist/cjs/utils/reduceObjectFormat.cjs.map +1 -1
  161. package/dist/cjs/utils/resolveObjectPromises.cjs +0 -1
  162. package/dist/cjs/utils/resolveObjectPromises.cjs.map +1 -1
  163. package/dist/cjs/utils/resolveRelativePath.cjs +4 -1
  164. package/dist/cjs/utils/resolveRelativePath.cjs.map +1 -1
  165. package/dist/cjs/utils/runOnce.cjs +2 -2
  166. package/dist/cjs/utils/runOnce.cjs.map +1 -1
  167. package/dist/cjs/utils/runParallel/bin.cjs.map +1 -1
  168. package/dist/cjs/utils/runParallel/bootstrap.cjs +0 -1
  169. package/dist/cjs/utils/runParallel/bootstrap.cjs.map +1 -1
  170. package/dist/cjs/utils/runParallel/index.cjs.map +1 -1
  171. package/dist/cjs/utils/runParallel/spawnPosix.cjs.map +1 -1
  172. package/dist/cjs/utils/runParallel/spawnWin32.cjs.map +1 -1
  173. package/dist/cjs/utils/sortAlphabetically.cjs +0 -1
  174. package/dist/cjs/utils/sortAlphabetically.cjs.map +1 -1
  175. package/dist/cjs/utils/splitTextByLine.cjs +0 -1
  176. package/dist/cjs/utils/splitTextByLine.cjs.map +1 -1
  177. package/dist/cjs/utils/verifyIdenticObjectFormat.cjs +0 -1
  178. package/dist/cjs/utils/verifyIdenticObjectFormat.cjs.map +1 -1
  179. package/dist/cjs/watcher.cjs +4 -2
  180. package/dist/cjs/watcher.cjs.map +1 -1
  181. package/dist/cjs/writeConfiguration/index.cjs +2 -1
  182. package/dist/cjs/writeConfiguration/index.cjs.map +1 -1
  183. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs +0 -1
  184. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs.map +1 -1
  185. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -1
  186. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +173 -109
  187. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
  188. package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs +6 -5
  189. package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs.map +1 -1
  190. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +9 -3
  191. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  192. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +2 -1
  193. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  194. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs +2 -1
  195. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs.map +1 -1
  196. package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs +4 -2
  197. package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs.map +1 -1
  198. package/dist/cjs/writeFileIfChanged.cjs.map +1 -1
  199. package/dist/esm/_virtual/_utils_asset.mjs +2 -1
  200. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +15 -3
  201. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
  202. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +26 -5
  203. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
  204. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +43 -6
  205. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -1
  206. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +2 -1
  207. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs.map +1 -1
  208. package/dist/esm/buildIntlayerDictionary/writeNestedDictionary.mjs +92 -0
  209. package/dist/esm/buildIntlayerDictionary/writeNestedDictionary.mjs.map +1 -0
  210. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +4 -2
  211. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs.map +1 -1
  212. package/dist/esm/cleanRemovedContentDeclaration.mjs +7 -4
  213. package/dist/esm/cleanRemovedContentDeclaration.mjs.map +1 -1
  214. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +5 -3
  215. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs.map +1 -1
  216. package/dist/esm/createType/createModuleAugmentation.mjs +2 -1
  217. package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
  218. package/dist/esm/docReview/alignBlocks.mjs +1 -1
  219. package/dist/esm/docReview/alignBlocks.mjs.map +1 -1
  220. package/dist/esm/docReview/reviewReport.mjs +2 -1
  221. package/dist/esm/docReview/reviewReport.mjs.map +1 -1
  222. package/dist/esm/fetchDistantDictionaries.mjs +107 -13
  223. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  224. package/dist/esm/handleAdditionalContentDeclarationFile.mjs +4 -2
  225. package/dist/esm/handleAdditionalContentDeclarationFile.mjs.map +1 -1
  226. package/dist/esm/handleContentDeclarationFileChange.mjs +6 -2
  227. package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
  228. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +4 -2
  229. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs.map +1 -1
  230. package/dist/esm/init/frameworkSetup/nextAppRouter/index.mjs +1 -3
  231. package/dist/esm/init/frameworkSetup/nextAppRouter/index.mjs.map +1 -1
  232. package/dist/esm/init/frameworkSetup/nextAppRouter/restructure.mjs +2 -1
  233. package/dist/esm/init/frameworkSetup/nextAppRouter/restructure.mjs.map +1 -1
  234. package/dist/esm/init/frameworkSetup/tanstackStart/index.mjs +4 -6
  235. package/dist/esm/init/frameworkSetup/tanstackStart/index.mjs.map +1 -1
  236. package/dist/esm/init/frameworkSetup/tanstackStart/restructure.mjs +2 -1
  237. package/dist/esm/init/frameworkSetup/tanstackStart/restructure.mjs.map +1 -1
  238. package/dist/esm/init/frameworkSetup/tanstackStart/templates.mjs +17 -10
  239. package/dist/esm/init/frameworkSetup/tanstackStart/templates.mjs.map +1 -1
  240. package/dist/esm/init/frameworkSetup/tanstackStart/transforms.mjs +59 -16
  241. package/dist/esm/init/frameworkSetup/tanstackStart/transforms.mjs.map +1 -1
  242. package/dist/esm/init/index.mjs +66 -38
  243. package/dist/esm/init/index.mjs.map +1 -1
  244. package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
  245. package/dist/esm/init/utils/fileSystem.mjs +3 -1
  246. package/dist/esm/init/utils/fileSystem.mjs.map +1 -1
  247. package/dist/esm/init/utils/packageManager.mjs +4 -2
  248. package/dist/esm/init/utils/packageManager.mjs.map +1 -1
  249. package/dist/esm/initConfig/index.mjs +12 -8
  250. package/dist/esm/initConfig/index.mjs.map +1 -1
  251. package/dist/esm/listDictionariesPath.mjs +6 -5
  252. package/dist/esm/listDictionariesPath.mjs.map +1 -1
  253. package/dist/esm/listProjects.mjs +2 -1
  254. package/dist/esm/listProjects.mjs.map +1 -1
  255. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +2 -1
  256. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs.map +1 -1
  257. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +8 -5
  258. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  259. package/dist/esm/loadDictionaries/loadDictionaries.mjs +4 -2
  260. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  261. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +3 -2
  262. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
  263. package/dist/esm/loadDictionaries/loadYamlContentDeclaration.mjs +2 -1
  264. package/dist/esm/loadDictionaries/loadYamlContentDeclaration.mjs.map +1 -1
  265. package/dist/esm/loadDictionaries/log.mjs +38 -11
  266. package/dist/esm/loadDictionaries/log.mjs.map +1 -1
  267. package/dist/esm/logConfigDetails.mjs +4 -3
  268. package/dist/esm/logConfigDetails.mjs.map +1 -1
  269. package/dist/esm/prepareIntlayer.mjs +5 -3
  270. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  271. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +2 -1
  272. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -1
  273. package/dist/esm/scan/checks.mjs +1 -1
  274. package/dist/esm/scan/checks.mjs.map +1 -1
  275. package/dist/esm/syncPluginKit/createFileAdapter.mjs +2 -1
  276. package/dist/esm/syncPluginKit/createFileAdapter.mjs.map +1 -1
  277. package/dist/esm/syncPluginKit/createSyncPlugin.mjs +4 -1
  278. package/dist/esm/syncPluginKit/createSyncPlugin.mjs.map +1 -1
  279. package/dist/esm/utils/babelParser.mjs.map +1 -1
  280. package/dist/esm/utils/chunkArray.mjs +22 -0
  281. package/dist/esm/utils/chunkArray.mjs.map +1 -0
  282. package/dist/esm/utils/getContentExtension.mjs +1 -3
  283. package/dist/esm/utils/getContentExtension.mjs.map +1 -1
  284. package/dist/esm/utils/index.mjs +2 -1
  285. package/dist/esm/utils/resolveRelativePath.mjs +4 -1
  286. package/dist/esm/utils/resolveRelativePath.mjs.map +1 -1
  287. package/dist/esm/utils/runOnce.mjs +2 -2
  288. package/dist/esm/utils/runOnce.mjs.map +1 -1
  289. package/dist/esm/watcher.mjs +4 -2
  290. package/dist/esm/watcher.mjs.map +1 -1
  291. package/dist/esm/writeConfiguration/index.mjs +2 -1
  292. package/dist/esm/writeConfiguration/index.mjs.map +1 -1
  293. package/dist/esm/writeContentDeclaration/transformJSFile.mjs +173 -109
  294. package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
  295. package/dist/esm/writeContentDeclaration/transformJSONFile.mjs +6 -5
  296. package/dist/esm/writeContentDeclaration/transformJSONFile.mjs.map +1 -1
  297. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +9 -3
  298. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  299. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +2 -1
  300. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  301. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs +2 -1
  302. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs.map +1 -1
  303. package/dist/esm/writeContentDeclaration/writeYamlFile.mjs +4 -2
  304. package/dist/esm/writeContentDeclaration/writeYamlFile.mjs.map +1 -1
  305. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
  306. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +14 -2
  307. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
  308. package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +16 -2
  309. package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
  310. package/dist/types/buildIntlayerDictionary/writeNestedDictionary.d.ts +54 -0
  311. package/dist/types/buildIntlayerDictionary/writeNestedDictionary.d.ts.map +1 -0
  312. package/dist/types/fetchDistantDictionaries.d.ts +26 -0
  313. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  314. package/dist/types/formatDictionary.d.ts +2 -0
  315. package/dist/types/formatDictionary.d.ts.map +1 -1
  316. package/dist/types/init/frameworkSetup/tanstackStart/templates.d.ts +9 -4
  317. package/dist/types/init/frameworkSetup/tanstackStart/templates.d.ts.map +1 -1
  318. package/dist/types/init/frameworkSetup/tanstackStart/transforms.d.ts +6 -2
  319. package/dist/types/init/frameworkSetup/tanstackStart/transforms.d.ts.map +1 -1
  320. package/dist/types/loadDictionaries/log.d.ts +16 -1
  321. package/dist/types/loadDictionaries/log.d.ts.map +1 -1
  322. package/dist/types/utils/chunkArray.d.ts +16 -0
  323. package/dist/types/utils/chunkArray.d.ts.map +1 -0
  324. package/dist/types/utils/index.d.ts +2 -1
  325. package/dist/types/writeContentDeclaration/transformJSFile.d.ts.map +1 -1
  326. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"getContentDeclarationFileTemplate.cjs","names":[],"sources":["../../../src/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.ts"],"sourcesContent":["import { kebabCaseToCamelCase } from '@intlayer/config/utils';\nimport type { Format } from '../utils/getFormatFromExtension';\n\nexport const getContentDeclarationFileTemplate = async (\n key: string,\n format: Format,\n fileParams: Record<string, any> = {},\n noMetadata?: boolean\n) => {\n const camelCaseKey = kebabCaseToCamelCase(key);\n const name = camelCaseKey.charAt(0).toLowerCase() + camelCaseKey.slice(1);\n\n const fileParamsString = Object.entries(fileParams)\n .filter(([, value]) => value !== undefined)\n .map(([paramKey, value]) => {\n const formattedKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(paramKey)\n ? paramKey\n : JSON.stringify(paramKey);\n\n const formattedValue =\n typeof value === 'object' || typeof value === 'string'\n ? JSON.stringify(value)\n : value;\n\n return `\\n ${formattedKey}: ${formattedValue},`;\n })\n .join('');\n\n let content: string;\n\n if (noMetadata) {\n content = '{}';\n } else if (format === 'json' || format === 'jsonc' || format === 'json5') {\n content = [\n '{',\n ' \"$schema\": \"https://intlayer.org/schema.json\",',\n ` \"key\": \"${key}\",${fileParamsString}`,\n ' \"content\": {',\n ' }',\n '}',\n ].join('\\n');\n } else {\n content = [\n '{',\n ` key: '${key}',${fileParamsString}`,\n ' content: {',\n ' },',\n '}',\n ].join('\\n');\n }\n\n const jsdoc = `/** @type {import('intlayer').Dictionary${noMetadata ? \"['content']\" : ''}} **/`;\n const satisfiesType = noMetadata ? \"Dictionary['content']\" : 'Dictionary';\n\n switch (format) {\n case 'yaml': {\n const yamlLines = [\n `key: ${key}`,\n ...(fileParams.locale ? [`locale: ${fileParams.locale}`] : []),\n ...(fileParams.title\n ? [`title: ${JSON.stringify(fileParams.title)}`]\n : []),\n ...(fileParams.description\n ? [`description: ${JSON.stringify(fileParams.description)}`]\n : []),\n ...(fileParams.tags?.length\n ? [\n 'tags:',\n ...(fileParams.tags as string[]).map(\n (tag) => ` - ${JSON.stringify(tag)}`\n ),\n ]\n : []),\n 'content: {}',\n ];\n return `${yamlLines.join('\\n')}\\n`;\n }\n\n case 'md': {\n const mdFrontmatterLines = [\n `key: ${key}`,\n ...(fileParams.locale ? [`locale: ${fileParams.locale}`] : []),\n ...(fileParams.title\n ? [`title: ${JSON.stringify(fileParams.title)}`]\n : []),\n ...(fileParams.description\n ? [`description: ${JSON.stringify(fileParams.description)}`]\n : []),\n ...(fileParams.tags?.length\n ? [\n 'tags:',\n ...(fileParams.tags as string[]).map(\n (t) => ` - ${JSON.stringify(t)}`\n ),\n ]\n : []),\n ];\n return ['---', ...mdFrontmatterLines, '---', '', ''].join('\\n');\n }\n\n case 'ts':\n return [\n \"import { type Dictionary } from 'intlayer';\",\n '',\n `const ${name}Content = ${content} satisfies ${satisfiesType};`,\n '',\n `export default ${name}Content;`,\n '',\n ].join('\\n');\n\n case 'cjs':\n return [\n jsdoc,\n `const ${name}Content = ${content};`,\n '',\n `module.exports = ${name}Content;`,\n '',\n ].join('\\n');\n\n case 'json':\n case 'jsonc':\n case 'json5':\n return [content, ''].join('\\n');\n\n default: // esm\n return [\n jsdoc,\n `const ${name}Content = ${content};`,\n '',\n `export default ${name}Content;`,\n '',\n ].join('\\n');\n }\n};\n"],"mappings":";;;;AAGA,MAAa,oCAAoC,OAC/C,KACA,QACA,aAAkC,CAAC,GACnC,eACG;CACH,MAAM,gEAAoC,GAAG;CAC7C,MAAM,OAAO,aAAa,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,aAAa,MAAM,CAAC;CAExE,MAAM,mBAAmB,OAAO,QAAQ,UAAU,CAAC,CAChD,QAAQ,GAAG,WAAW,UAAU,MAAS,CAAC,CAC1C,KAAK,CAAC,UAAU,WAAW;EAU1B,OAAO,OATc,6BAA6B,KAAK,QAAQ,IAC3D,WACA,KAAK,UAAU,QAAQ,EAOA,IAJzB,OAAO,UAAU,YAAY,OAAO,UAAU,WAC1C,KAAK,UAAU,KAAK,IACpB,MAEwC;CAChD,CAAC,CAAC,CACD,KAAK,EAAE;CAEV,IAAI;CAEJ,IAAI,YACF,UAAU;MACL,IAAI,WAAW,UAAU,WAAW,WAAW,WAAW,SAC/D,UAAU;EACR;EACA;EACA,aAAa,IAAI,IAAI;EACrB;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;MAEX,UAAU;EACR;EACA,WAAW,IAAI,IAAI;EACnB;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;CAGb,MAAM,QAAQ,2CAA2C,aA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K,SACH,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;EAEhC,SACE,OAAO;GACL;GACA,SAAS,KAAK,YAAY,QAAQ;GAClC;GACA,kBAAkB,KAAK;GACvB;EACF,CAAC,CAAC,KAAK,IAAI;CACf;AACF"}
1
+ {"version":3,"file":"getContentDeclarationFileTemplate.cjs","names":["kebabCaseToCamelCase"],"sources":["../../../src/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.ts"],"sourcesContent":["import { kebabCaseToCamelCase } from '@intlayer/config/utils';\nimport type { Format } from '../utils/getFormatFromExtension';\n\nexport const getContentDeclarationFileTemplate = async (\n key: string,\n format: Format,\n fileParams: Record<string, any> = {},\n noMetadata?: boolean\n) => {\n const camelCaseKey = kebabCaseToCamelCase(key);\n const name = camelCaseKey.charAt(0).toLowerCase() + camelCaseKey.slice(1);\n\n const fileParamsString = Object.entries(fileParams)\n .filter(([, value]) => value !== undefined)\n .map(([paramKey, value]) => {\n const formattedKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(paramKey)\n ? paramKey\n : JSON.stringify(paramKey);\n\n const formattedValue =\n typeof value === 'object' || typeof value === 'string'\n ? JSON.stringify(value)\n : value;\n\n return `\\n ${formattedKey}: ${formattedValue},`;\n })\n .join('');\n\n let content: string;\n\n if (noMetadata) {\n content = '{}';\n } else if (format === 'json' || format === 'jsonc' || format === 'json5') {\n content = [\n '{',\n ' \"$schema\": \"https://intlayer.org/schema.json\",',\n ` \"key\": \"${key}\",${fileParamsString}`,\n ' \"content\": {',\n ' }',\n '}',\n ].join('\\n');\n } else {\n content = [\n '{',\n ` key: '${key}',${fileParamsString}`,\n ' content: {',\n ' },',\n '}',\n ].join('\\n');\n }\n\n const jsdoc = `/** @type {import('intlayer').Dictionary${noMetadata ? \"['content']\" : ''}} **/`;\n const satisfiesType = noMetadata ? \"Dictionary['content']\" : 'Dictionary';\n\n switch (format) {\n case 'yaml': {\n const yamlLines = [\n `key: ${key}`,\n ...(fileParams.locale ? [`locale: ${fileParams.locale}`] : []),\n ...(fileParams.title\n ? [`title: ${JSON.stringify(fileParams.title)}`]\n : []),\n ...(fileParams.description\n ? [`description: ${JSON.stringify(fileParams.description)}`]\n : []),\n ...(fileParams.tags?.length\n ? [\n 'tags:',\n ...(fileParams.tags as string[]).map(\n (tag) => ` - ${JSON.stringify(tag)}`\n ),\n ]\n : []),\n 'content: {}',\n ];\n return `${yamlLines.join('\\n')}\\n`;\n }\n\n case 'md': {\n const mdFrontmatterLines = [\n `key: ${key}`,\n ...(fileParams.locale ? [`locale: ${fileParams.locale}`] : []),\n ...(fileParams.title\n ? [`title: ${JSON.stringify(fileParams.title)}`]\n : []),\n ...(fileParams.description\n ? [`description: ${JSON.stringify(fileParams.description)}`]\n : []),\n ...(fileParams.tags?.length\n ? [\n 'tags:',\n ...(fileParams.tags as string[]).map(\n (t) => ` - ${JSON.stringify(t)}`\n ),\n ]\n : []),\n ];\n return ['---', ...mdFrontmatterLines, '---', '', ''].join('\\n');\n }\n\n case 'ts':\n return [\n \"import { type Dictionary } from 'intlayer';\",\n '',\n `const ${name}Content = ${content} satisfies ${satisfiesType};`,\n '',\n `export default ${name}Content;`,\n '',\n ].join('\\n');\n\n case 'cjs':\n return [\n jsdoc,\n `const ${name}Content = ${content};`,\n '',\n `module.exports = ${name}Content;`,\n '',\n ].join('\\n');\n\n case 'json':\n case 'jsonc':\n case 'json5':\n return [content, ''].join('\\n');\n\n default: // esm\n return [\n jsdoc,\n `const ${name}Content = ${content};`,\n '',\n `export default ${name}Content;`,\n '',\n ].join('\\n');\n }\n};\n"],"mappings":";;;;AAGA,MAAa,oCAAoC,OAC/C,KACA,QACA,aAAkC,CAAC,GACnC,eACG;CACH,MAAM,mBAAeA,6CAAqB,GAAG;CAC7C,MAAM,OAAO,aAAa,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,aAAa,MAAM,CAAC;CAExE,MAAM,mBAAmB,OAAO,QAAQ,UAAU,CAAC,CAChD,QAAQ,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AAI,WAAW,cACX,CAAC,gBAAgB,KAAK,UAAU,WAAW,WAAW,GAAG,IACzD,CAAC;IACL,GAAI,WAAW,MAAM,SACjB,CACE,SACA,GAAI,WAAW,KAAkB,KAC9B,MAAM,OAAO,KAAK,UAAU,CAAC,GAChC,CACF,IACA,CAAC;GAE4B;GAAG;GAAO;GAAI;EAAE,CAAC,CAAC,KAAK,IAAI;EAGhE,KAAK,MACH,OAAO;GACL;GACA;GACA,SAAS,KAAK,YAAY,QAAQ,aAAa,cAAc;GAC7D;GACA,kBAAkB,KAAK;GACvB;EACF,CAAC,CAAC,KAAK,IAAI;EAEb,KAAK,OACH,OAAO;GACL;GACA,SAAS,KAAK,YAAY,QAAQ;GAClC;GACA,oBAAoB,KAAK;GACzB;EACF,CAAC,CAAC,KAAK,IAAI;EAEb,KAAK;EACL,KAAK;EACL,KAAK,SACH,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;EAEhC,SACE,OAAO;GACL;GACA,SAAS,KAAK,YAAY,QAAQ;GAClC;GACA,kBAAkB,KAAK;GACvB;EACF,CAAC,CAAC,KAAK,IAAI;CACf;AACF"}
@@ -11,8 +11,10 @@ let _intlayer_config_logger = require("@intlayer/config/logger");
11
11
  const handleAdditionalContentDeclarationFile = async (filePath, config) => {
12
12
  const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
13
13
  appLogger(`Additional file detected: ${require_utils_formatter.formatPath(filePath)}`, { isVerbose: true });
14
- const dictionariesOutput = await require_buildIntlayerDictionary_buildIntlayerDictionary.buildDictionary(await require_loadDictionaries_loadLocalDictionaries.loadLocalDictionaries(filePath, config), config);
15
- await require_createType_createType.createTypes(Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionary), config);
14
+ const localeDictionaries = await require_loadDictionaries_loadLocalDictionaries.loadLocalDictionaries(filePath, config);
15
+ const dictionariesOutput = await require_buildIntlayerDictionary_buildIntlayerDictionary.buildDictionary(localeDictionaries, config);
16
+ const dictionariesToBuild = Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionary);
17
+ await require_createType_createType.createTypes(dictionariesToBuild, config);
16
18
  await require_createDictionaryEntryPoint_createDictionaryEntryPoint.createDictionaryEntryPoint(config);
17
19
  appLogger("Dictionaries built", { isVerbose: true });
18
20
  await require_createType_createModuleAugmentation.createModuleAugmentation(config);
@@ -1 +1 @@
1
- {"version":3,"file":"handleAdditionalContentDeclarationFile.cjs","names":["formatPath","buildDictionary","loadLocalDictionaries","createTypes","createDictionaryEntryPoint","createModuleAugmentation"],"sources":["../../src/handleAdditionalContentDeclarationFile.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { createModuleAugmentation, createTypes } from './createType/index';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Additional file detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesToBuild = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionary);\n\n await createTypes(dictionariesToBuild, config);\n\n await createDictionaryEntryPoint(config);\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n await createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAa,yCAAyC,OACpD,UACA,WACG;CACH,MAAM,sDAAyB,MAAM;CAGrC,UAAU,6BAA6BA,mCAAW,QAAQ,KAAK,EAC7D,WAAW,KACb,CAAC;CAID,MAAM,qBAAqB,MAAMC,wEAAgB,MAFhBC,qEAAsB,UAAU,MAAM,GAEF,MAAM;CAM3E,MAAMC,0CAJsB,OAAO,OACjC,oBAAoB,sBAAsB,CAAC,CAC7C,CAAC,CAAC,KAAK,eAAe,WAAW,UAEG,GAAG,MAAM;CAE7C,MAAMC,yFAA2B,MAAM;CAEvC,UAAU,sBAAsB,EAC9B,WAAW,KACb,CAAC;CAED,MAAMC,qEAAyB,MAAM;CAErC,UAAU,6BAA6B,EACrC,WAAW,KACb,CAAC;CAID,WAAW,MAAM,UAAU,OAAO,WAAW,CAAC,GAAG;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;EAErD,MAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;GACF;GACA,eAAe;EACjB,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"handleAdditionalContentDeclarationFile.cjs","names":["getAppLogger","formatPath","loadLocalDictionaries","buildDictionary","createTypes","createDictionaryEntryPoint","createModuleAugmentation"],"sources":["../../src/handleAdditionalContentDeclarationFile.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { createModuleAugmentation, createTypes } from './createType/index';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Additional file detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesToBuild = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionary);\n\n await createTypes(dictionariesToBuild, config);\n\n await createDictionaryEntryPoint(config);\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n await createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAa,yCAAyC,OACpD,UACA,WACG;CACH,MAAM,gBAAYA,sCAAa,MAAM;CAGrC,UAAU,6BAA6BC,mCAAW,QAAQ,KAAK,EAC7D,WAAW,KACb,CAAC;CAED,MAAM,qBAAqB,MAAMC,qEAAsB,UAAU,MAAM;CAEvE,MAAM,qBAAqB,MAAMC,wEAAgB,oBAAoB,MAAM;CAE3E,MAAM,sBAAsB,OAAO,OACjC,oBAAoB,sBAAsB,CAAC,CAC7C,CAAC,CAAC,KAAK,eAAe,WAAW,UAAU;CAE3C,MAAMC,0CAAY,qBAAqB,MAAM;CAE7C,MAAMC,yFAA2B,MAAM;CAEvC,UAAU,sBAAsB,EAC9B,WAAW,KACb,CAAC;CAED,MAAMC,qEAAyB,MAAM;CAErC,UAAU,6BAA6B,EACrC,WAAW,KACb,CAAC;CAID,WAAW,MAAM,UAAU,OAAO,WAAW,CAAC,GAAG;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;EAErD,MAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;GACF;GACA,eAAe;EACjB,CAAC;CACH;AACF"}
@@ -23,7 +23,8 @@ const handleContentDeclarationFileChange = async (filePath, config) => {
23
23
  const updatedDictionariesPaths = updatedDictionaries.map((dictionary) => dictionary.dictionaryPath);
24
24
  const { excludeKeys, hasRebuilt } = await require_cleanRemovedContentDeclaration.cleanRemovedContentDeclaration(filePath, localeDictionaries.map((dictionary) => dictionary.key), config);
25
25
  const hasNewDictionaries = updatedDictionariesPaths.some((updatedDictionaryPath) => !allDictionariesPaths.includes(updatedDictionaryPath));
26
- await require_createType_createType.createTypes(updatedDictionaries.map((dictionary) => dictionary.dictionary), config);
26
+ const dictionariesToBuild = updatedDictionaries.map((dictionary) => dictionary.dictionary);
27
+ await require_createType_createType.createTypes(dictionariesToBuild, config);
27
28
  appLogger("TypeScript types built", { isVerbose: true });
28
29
  await require_createType_createModuleAugmentation.createModuleAugmentation(config);
29
30
  appLogger("Module augmentation built", { isVerbose: true });
@@ -36,7 +37,10 @@ const handleContentDeclarationFileChange = async (filePath, config) => {
36
37
  const { mainDir } = config.system;
37
38
  for (const extension of config.build.outputFormat) {
38
39
  const entryPointPath = (0, node_path.join)(mainDir, `dictionaries.${extension}`);
39
- if ((0, node_fs.existsSync)(entryPointPath)) await (0, node_fs_promises.writeFile)(entryPointPath, await (0, node_fs_promises.readFile)(entryPointPath, "utf-8"));
40
+ if ((0, node_fs.existsSync)(entryPointPath)) {
41
+ const content = await (0, node_fs_promises.readFile)(entryPointPath, "utf-8");
42
+ await (0, node_fs_promises.writeFile)(entryPointPath, content);
43
+ }
40
44
  }
41
45
  for await (const plugin of config.plugins ?? []) {
42
46
  const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;
@@ -1 +1 @@
1
- {"version":3,"file":"handleContentDeclarationFileChange.cjs","names":["formatPath","getBuiltDictionariesPath","loadLocalDictionaries","buildDictionary","cleanRemovedContentDeclaration","createTypes","createModuleAugmentation","createDictionaryEntryPoint"],"sources":["../../src/handleContentDeclarationFileChange.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { getBuiltDictionariesPath } from './createDictionaryEntryPoint/getBuiltDictionariesPath';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const allDictionariesPaths: string[] = await getBuiltDictionariesPath(config);\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n const updatedDictionaries = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n );\n const updatedDictionariesPaths = updatedDictionaries.map(\n (dictionary) => dictionary.dictionaryPath\n );\n\n const { excludeKeys, hasRebuilt } = await cleanRemovedContentDeclaration(\n filePath,\n localeDictionaries.map((dictionary) => dictionary.key),\n config\n );\n\n const hasNewDictionaries = updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n );\n\n // Rebuild Types first — types must be ready before anything triggers a bundler rebuild.\n // esbuild (used by Angular, Vite, etc.) only watches files in its JS bundle graph; it does\n // NOT watch .intlayer/types/*.ts (TypeScript-only files). Generating types here, before\n // updating the entry point, guarantees that when the entry point write below fires esbuild's\n // file watcher the types are already up-to-date.\n const dictionariesToBuild = updatedDictionaries.map(\n (dictionary) => dictionary.dictionary\n );\n\n await createTypes(dictionariesToBuild, config);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n // Always regenerate the module augmentation so that structural changes to existing\n // dictionaries (new content keys, type changes) are reflected in intlayer.d.ts.\n await createModuleAugmentation(config);\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Rebuild Entry Point\n // Only needed when the *list* of dictionaries changed (Add/Remove/Rename).\n if (hasRebuilt || hasNewDictionaries) {\n // If hasRebuilt is true, cleanRemovedContentDeclaration has already updated the entry point\n // to remove the old keys (and it likely included the new ones if they were already on disk).\n // If NOT hasRebuilt, we explicitly need to update the entry point to include the new dictionaries.\n if (!hasRebuilt) {\n await createDictionaryEntryPoint(config, { excludeKeys });\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n }\n\n // Force-write the entry point files so esbuild detects a change and triggers a fresh rebuild\n // now that all types are ready. Without this, the only rebuild esbuild sees is the one\n // triggered by buildDictionary's JSON writes above — which races against type generation\n // and often runs before the new .intlayer/types/*.ts files are on disk.\n const { mainDir } = config.system;\n\n for (const extension of config.build.outputFormat) {\n const entryPointPath = join(mainDir, `dictionaries.${extension}`);\n\n if (existsSync(entryPointPath)) {\n const content = await readFile(entryPointPath, 'utf-8');\n await writeFile(entryPointPath, content);\n }\n }\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,qCAAqC,OAChD,UACA,WACG;CACH,MAAM,sDAAyB,MAAM;CAGrC,UAAU,oBAAoBA,mCAAW,QAAQ,KAAK,EACpD,WAAW,KACb,CAAC;CAED,MAAM,uBAAiC,MAAMC,qFAAyB,MAAM;CAE5E,MAAM,qBAAqB,MAAMC,qEAAsB,UAAU,MAAM;CAEvE,MAAM,qBAAqB,MAAMC,wEAAgB,oBAAoB,MAAM;CAC3E,MAAM,sBAAsB,OAAO,OACjC,oBAAoB,sBAAsB,CAAC,CAC7C;CACA,MAAM,2BAA2B,oBAAoB,KAClD,eAAe,WAAW,cAC7B;CAEA,MAAM,EAAE,aAAa,eAAe,MAAMC,sEACxC,UACA,mBAAmB,KAAK,eAAe,WAAW,GAAG,GACrD,MACF;CAEA,MAAM,qBAAqB,yBAAyB,MACjD,0BACC,CAAC,qBAAqB,SAAS,qBAAqB,CACxD;CAWA,MAAMC,0CAJsB,oBAAoB,KAC7C,eAAe,WAAW,UAGO,GAAG,MAAM;CAC7C,UAAU,0BAA0B,EAClC,WAAW,KACb,CAAC;CAID,MAAMC,qEAAyB,MAAM;CACrC,UAAU,6BAA6B,EACrC,WAAW,KACb,CAAC;CAID,IAAI,cAAc,oBAIhB;MAAI,CAAC,YAAY;GACf,MAAMC,yFAA2B,QAAQ,EAAE,YAAY,CAAC;GACxD,UAAU,yBAAyB,EACjC,WAAW,KACb,CAAC;EACH;;CAOF,MAAM,EAAE,YAAY,OAAO;CAE3B,KAAK,MAAM,aAAa,OAAO,MAAM,cAAc;EACjD,MAAM,qCAAsB,SAAS,gBAAgB,WAAW;EAEhE,4BAAe,cAAc,GAE3B,sCAAgB,gBAAgB,qCADD,gBAAgB,OAAO,CACf;CAE3C;CAIA,WAAW,MAAM,UAAU,OAAO,WAAW,CAAC,GAAG;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;EAErD,MAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;GACF;GACA,eAAe;EACjB,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"handleContentDeclarationFileChange.cjs","names":["getAppLogger","formatPath","getBuiltDictionariesPath","loadLocalDictionaries","buildDictionary","cleanRemovedContentDeclaration","createTypes","createModuleAugmentation","createDictionaryEntryPoint","join","existsSync","readFile","writeFile"],"sources":["../../src/handleContentDeclarationFileChange.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { getBuiltDictionariesPath } from './createDictionaryEntryPoint/getBuiltDictionariesPath';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const allDictionariesPaths: string[] = await getBuiltDictionariesPath(config);\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n const updatedDictionaries = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n );\n const updatedDictionariesPaths = updatedDictionaries.map(\n (dictionary) => dictionary.dictionaryPath\n );\n\n const { excludeKeys, hasRebuilt } = await cleanRemovedContentDeclaration(\n filePath,\n localeDictionaries.map((dictionary) => dictionary.key),\n config\n );\n\n const hasNewDictionaries = updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n );\n\n // Rebuild Types first — types must be ready before anything triggers a bundler rebuild.\n // esbuild (used by Angular, Vite, etc.) only watches files in its JS bundle graph; it does\n // NOT watch .intlayer/types/*.ts (TypeScript-only files). Generating types here, before\n // updating the entry point, guarantees that when the entry point write below fires esbuild's\n // file watcher the types are already up-to-date.\n const dictionariesToBuild = updatedDictionaries.map(\n (dictionary) => dictionary.dictionary\n );\n\n await createTypes(dictionariesToBuild, config);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n // Always regenerate the module augmentation so that structural changes to existing\n // dictionaries (new content keys, type changes) are reflected in intlayer.d.ts.\n await createModuleAugmentation(config);\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Rebuild Entry Point\n // Only needed when the *list* of dictionaries changed (Add/Remove/Rename).\n if (hasRebuilt || hasNewDictionaries) {\n // If hasRebuilt is true, cleanRemovedContentDeclaration has already updated the entry point\n // to remove the old keys (and it likely included the new ones if they were already on disk).\n // If NOT hasRebuilt, we explicitly need to update the entry point to include the new dictionaries.\n if (!hasRebuilt) {\n await createDictionaryEntryPoint(config, { excludeKeys });\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n }\n\n // Force-write the entry point files so esbuild detects a change and triggers a fresh rebuild\n // now that all types are ready. Without this, the only rebuild esbuild sees is the one\n // triggered by buildDictionary's JSON writes above — which races against type generation\n // and often runs before the new .intlayer/types/*.ts files are on disk.\n const { mainDir } = config.system;\n\n for (const extension of config.build.outputFormat) {\n const entryPointPath = join(mainDir, `dictionaries.${extension}`);\n\n if (existsSync(entryPointPath)) {\n const content = await readFile(entryPointPath, 'utf-8');\n await writeFile(entryPointPath, content);\n }\n }\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,qCAAqC,OAChD,UACA,WACG;CACH,MAAM,gBAAYA,sCAAa,MAAM;CAGrC,UAAU,oBAAoBC,mCAAW,QAAQ,KAAK,EACpD,WAAW,KACb,CAAC;CAED,MA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cjs","names":["formatPath","loadLocalDictionaries","cleanRemovedContentDeclaration","handleContentDeclarationFileChange"],"sources":["../../src/handleContentDeclarationFileMoved.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileMoved = async (\n oldFilePath: string,\n newFilePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n appLogger(\n `File moved from ${formatPath(oldFilePath)} to ${formatPath(newFilePath)}`,\n {\n isVerbose: true,\n }\n );\n\n let keysToKeep: string[] = [];\n\n try {\n // Pre-load the new file to identify the keys inside it.\n // We need to pass these keys to the cleaner so it knows NOT to completely delete\n // the dictionary artifacts (types/json) if the key has simply moved to a new file.\n const newLocaleDictionaries = await loadLocalDictionaries(\n newFilePath,\n config\n );\n keysToKeep = newLocaleDictionaries.map((d) => d.key);\n } catch {\n appLogger(\n `Error parsing new file during move operation: ${formatPath(newFilePath)}`,\n {\n isVerbose: true,\n }\n );\n // Proceed with empty keysToKeep; this will result in the old dictionary being cleaned up\n // entirely, and the new one being re-created in the next step.\n }\n\n // Clean up the artifacts associated with the old file path.\n // By passing 'keysToKeep', we instruct the cleaner to remove the specific file association\n // (filePath reference) from the dictionaries, but preserve the dictionary Entry Point and Types\n // if the key is still present in the new file.\n await cleanRemovedContentDeclaration(oldFilePath, keysToKeep, config);\n\n // Process the new file.\n // This will add the new file association, rebuild the dictionary JSONs with the new path,\n // and ensure types and module augmentation are up to date.\n await handleContentDeclarationFileChange(newFilePath, config);\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,oCAAoC,OAC/C,aACA,aACA,WACG;CACH,MAAM,sDAAyB,MAAM;CAErC,UACE,mBAAmBA,mCAAW,WAAW,EAAE,MAAMA,mCAAW,WAAW,KACvE,EACE,WAAW,KACb,CACF;CAEA,IAAI,aAAuB,CAAC;CAE5B,IAAI;EAQF,cAAa,MAJuBC,qEAClC,aACA,MACF,EACkC,CAAC,KAAK,MAAM,EAAE,GAAG;CACrD,QAAQ;EACN,UACE,iDAAiDD,mCAAW,WAAW,KACvE,EACE,WAAW,KACb,CACF;CAGF;CAMA,MAAME,sEAA+B,aAAa,YAAY,MAAM;CAKpE,MAAMC,8EAAmC,aAAa,MAAM;AAC9D"}
1
+ {"version":3,"file":"handleContentDeclarationFileMoved.cjs","names":["getAppLogger","formatPath","loadLocalDictionaries","cleanRemovedContentDeclaration","handleContentDeclarationFileChange"],"sources":["../../src/handleContentDeclarationFileMoved.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileMoved = async (\n oldFilePath: string,\n newFilePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n appLogger(\n `File moved from ${formatPath(oldFilePath)} to ${formatPath(newFilePath)}`,\n {\n isVerbose: true,\n }\n );\n\n let keysToKeep: string[] = [];\n\n try {\n // Pre-load the new file to identify the keys inside it.\n // We need to pass these keys to the cleaner so it knows NOT to completely delete\n // the dictionary artifacts (types/json) if the key has simply moved to a new file.\n const newLocaleDictionaries = await loadLocalDictionaries(\n newFilePath,\n config\n );\n keysToKeep = newLocaleDictionaries.map((d) => d.key);\n } catch {\n appLogger(\n `Error parsing new file during move operation: ${formatPath(newFilePath)}`,\n {\n isVerbose: true,\n }\n );\n // Proceed with empty keysToKeep; this will result in the old dictionary being cleaned up\n // entirely, and the new one being re-created in the next step.\n }\n\n // Clean up the artifacts associated with the old file path.\n // By passing 'keysToKeep', we instruct the cleaner to remove the specific file association\n // (filePath reference) from the dictionaries, but preserve the dictionary Entry Point and Types\n // if the key is still present in the new file.\n await cleanRemovedContentDeclaration(oldFilePath, keysToKeep, config);\n\n // Process the new file.\n // This will add the new file association, rebuild the dictionary JSONs with the new path,\n // and ensure types and module augmentation are up to date.\n await handleContentDeclarationFileChange(newFilePath, config);\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,oCAAoC,OAC/C,aACA,aACA,WACG;CACH,MAAM,gBAAYA,sCAAa,MAAM;CAErC,UACE,mBAAmBC,mCAAW,WAAW,EAAE,MAAMA,mCAAW,WAAW,KACvE,EACE,WAAW,KACb,CACF;CAEA,IAAI,aAAuB,CAAC;CAE5B,IAAI;EAQF,cAAa,MAJuBC,qEAClC,aACA,MACF,EACkC,CAAC,KAAK,MAAM,EAAE,GAAG;CACrD,QAAQ;EACN,UACE,iDAAiDD,mCAAW,WAAW,KACvE,EACE,WAAW,KACb,CACF;CAGF;CAMA,MAAME,sEAA+B,aAAa,YAAY,MAAM;CAKpE,MAAMC,8EAAmC,aAAa,MAAM;AAC9D"}
@@ -13,10 +13,12 @@ let _intlayer_config_logger = require("@intlayer/config/logger");
13
13
  const handleUnlinkedContentDeclarationFile = async (filePath, config) => {
14
14
  const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
15
15
  appLogger(`Unlinked detected: ${require_utils_formatter.formatPath(filePath)}`, { isVerbose: true });
16
- const localeDictionaries = await require_loadDictionaries_loadLocalDictionaries.loadLocalDictionaries((await require_listDictionariesPath.listDictionaries(config)).filter((file) => (0, node_path.normalize)(file) !== (0, node_path.normalize)(filePath)), config);
16
+ const existingFiles = (await require_listDictionariesPath.listDictionaries(config)).filter((file) => (0, node_path.normalize)(file) !== (0, node_path.normalize)(filePath));
17
+ const localeDictionaries = await require_loadDictionaries_loadLocalDictionaries.loadLocalDictionaries(existingFiles, config);
17
18
  await require_cleanRemovedContentDeclaration.cleanRemovedContentDeclaration(filePath, [], config);
18
19
  const dictionariesOutput = await require_buildIntlayerDictionary_buildIntlayerDictionary.buildDictionary(localeDictionaries, config);
19
- await require_createType_createType.createTypes(Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionary), config);
20
+ const dictionariesToBuild = Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionary);
21
+ await require_createType_createType.createTypes(dictionariesToBuild, config);
20
22
  appLogger("Dictionaries rebuilt", { isVerbose: true });
21
23
  await require_createType_createModuleAugmentation.createModuleAugmentation(config);
22
24
  appLogger("Module augmentation built", { isVerbose: true });
@@ -1 +1 @@
1
- {"version":3,"file":"handleUnlinkedContentDeclarationFile.cjs","names":["formatPath","loadLocalDictionaries","listDictionaries","cleanRemovedContentDeclaration","buildDictionary","createTypes","createModuleAugmentation"],"sources":["../../src/handleUnlinkedContentDeclarationFile.ts"],"sourcesContent":["import { normalize } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleUnlinkedContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = await listDictionaries(config);\n\n const existingFiles = files.filter(\n (file) => normalize(file) !== normalize(filePath)\n );\n\n const localeDictionaries = await loadLocalDictionaries(existingFiles, config);\n\n await cleanRemovedContentDeclaration(filePath, [], config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesToBuild = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionary);\n\n await createTypes(dictionariesToBuild, config);\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n await createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,uCAAuC,OAClD,UACA,WACG;CACH,MAAM,sDAAyB,MAAM;CAGrC,UAAU,sBAAsBA,mCAAW,QAAQ,KAAK,EACtD,WAAW,KACb,CAAC;CAQD,MAAM,qBAAqB,MAAMC,sEAJX,MAFQC,8CAAiB,MAAM,EAE1B,CAAC,QACzB,kCAAmB,IAAI,+BAAgB,QAAQ,CAGiB,GAAG,MAAM;CAE5E,MAAMC,sEAA+B,UAAU,CAAC,GAAG,MAAM;CAEzD,MAAM,qBAAqB,MAAMC,wEAAgB,oBAAoB,MAAM;CAM3E,MAAMC,0CAJsB,OAAO,OACjC,oBAAoB,sBAAsB,CAAC,CAC7C,CAAC,CAAC,KAAK,eAAe,WAAW,UAEG,GAAG,MAAM;CAE7C,UAAU,wBAAwB,EAChC,WAAW,KACb,CAAC;CAED,MAAMC,qEAAyB,MAAM;CAErC,UAAU,6BAA6B,EACrC,WAAW,KACb,CAAC;CAID,WAAW,MAAM,UAAU,OAAO,WAAW,CAAC,GAAG;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;EAErD,MAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;GACF;GACA,eAAe;EACjB,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"handleUnlinkedContentDeclarationFile.cjs","names":["getAppLogger","formatPath","listDictionaries","normalize","loadLocalDictionaries","cleanRemovedContentDeclaration","buildDictionary","createTypes","createModuleAugmentation"],"sources":["../../src/handleUnlinkedContentDeclarationFile.ts"],"sourcesContent":["import { normalize } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleUnlinkedContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = await listDictionaries(config);\n\n const existingFiles = files.filter(\n (file) => normalize(file) !== normalize(filePath)\n );\n\n const localeDictionaries = await loadLocalDictionaries(existingFiles, config);\n\n await cleanRemovedContentDeclaration(filePath, [], config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesToBuild = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionary);\n\n await createTypes(dictionariesToBuild, config);\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n await createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,uCAAuC,OAClD,UACA,WACG;CACH,MAAM,gBAAYA,sCAAa,MAAM;CAGrC,UAAU,sBAAsBC,mCAAW,QAAQ,KAAK,EACtD,WAAW,KACb,CAAC;CAID,MAAM,iBAAgB,MAFQC,8CAAiB,MAAM,EAE1B,CAAC,QACzB,aAASC,qBAAU,IAAI,UAAMA,qBAAU,QAAQ,CAClD;CAEA,MAAM,qBAAqB,MAAMC,qEAAsB,eAAe,MAAM;CAE5E,MAAMC,sEAA+B,UAAU,CAAC,GAAG,MAAM;CAEzD,MAAM,qBAAqB,MAAMC,wEAAgB,oBAAoB,MAAM;CAE3E,MAAM,sBAAsB,OAAO,OACjC,oBAAoB,sBAAsB,CAAC,CAC7C,CAAC,CAAC,KAAK,eAAe,WAAW,UAAU;CAE3C,MAAMC,0CAAY,qBAAqB,MAAM;CAE7C,UAAU,wBAAwB,EAChC,WAAW,KACb,CAAC;CAED,MAAMC,qEAAyB,MAAM;CAErC,UAAU,6BAA6B,EACrC,WAAW,KACb,CAAC;CAID,WAAW,MAAM,UAAU,OAAO,WAAW,CAAC,GAAG;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;EAErD,MAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;GACF;GACA,eAAe;EACjB,CAAC;CACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"cms.cjs","names":["exists","readFileFromRoot","writeFileToRoot","v","ANSIColors","x","enableIntlayerEditorConfig","setIntlayerConfigRoutingMode","setIntlayerConfigCompilerOutput"],"sources":["../../../src/init/cms.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport fg from 'fast-glob';\nimport {\n enableIntlayerEditorConfig,\n type RoutingMode,\n setIntlayerConfigCompilerOutput,\n setIntlayerConfigRoutingMode,\n} from './utils/configManipulation';\nimport { exists, readFileFromRoot, writeFileToRoot } from './utils/fileSystem';\n\n/**\n * Intlayer configuration file candidates, ordered by the precedence used when\n * resolving which file to mutate.\n */\nexport const INTLAYER_CONFIG_FILE_CANDIDATES = [\n 'intlayer.config.ts',\n 'intlayer.config.mjs',\n 'intlayer.config.js',\n 'intlayer.config.cjs',\n 'intlayer.config.json',\n] as const;\n\n/**\n * Environment files searched (most-preferred first) when persisting the CMS\n * credentials. The first existing match is reused; otherwise a `.env` file is\n * created at the project root.\n */\nconst ENV_FILE_CANDIDATES = ['.env', '.env.local', '.env.development'] as const;\n\n/** Credentials returned by the CMS login flow (access key pair). */\nexport type CmsCredentials = {\n clientId: string;\n clientSecret: string;\n};\n\n/**\n * Resolves the first existing Intlayer configuration file at the project root,\n * or `undefined` when none is present.\n */\nconst findIntlayerConfigFile = async (\n rootDir: string\n): Promise<(typeof INTLAYER_CONFIG_FILE_CANDIDATES)[number] | undefined> => {\n for (const candidate of INTLAYER_CONFIG_FILE_CANDIDATES) {\n if (await exists(rootDir, candidate)) {\n return candidate;\n }\n }\n\n return undefined;\n};\n\n/**\n * Locates the environment file the CMS credentials should be written to. Uses\n * `fast-glob` to detect an existing dotenv file at the project root, preferring\n * a plain `.env`; falls back to `.env` (to be created) when none exist.\n */\nexport const findEnvFile = async (rootDir: string): Promise<string> => {\n const matches = await fg([...ENV_FILE_CANDIDATES], {\n cwd: rootDir,\n dot: true,\n deep: 1,\n onlyFiles: true,\n });\n\n return (\n ENV_FILE_CANDIDATES.find((candidate) => matches.includes(candidate)) ??\n '.env'\n );\n};\n\n/**\n * Inserts or updates a `KEY=value` line in dotenv file content. An existing\n * assignment of the same key is replaced in place; otherwise the line is\n * appended with a trailing newline.\n */\nconst upsertEnvVariable = (\n content: string,\n key: string,\n value: string\n): string => {\n const line = `${key}=${value}`;\n const keyMatcher = new RegExp(`^${key}=.*$`, 'm');\n\n if (keyMatcher.test(content)) {\n return content.replace(keyMatcher, line);\n }\n\n const needsLeadingNewline = content.length > 0 && !content.endsWith('\\n');\n\n return `${content}${needsLeadingNewline ? '\\n' : ''}${line}\\n`;\n};\n\n/**\n * Persists the CMS access-key credentials to the project's environment file as\n * `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET`. The target file is detected\n * with {@link findEnvFile} and created when missing. Returns the relative path\n * of the file that was written.\n */\nexport const writeCmsCredentialsToEnv = async (\n rootDir: string,\n { clientId, clientSecret }: CmsCredentials\n): Promise<string> => {\n const envFile = await findEnvFile(rootDir);\n\n let content = '';\n if (await exists(rootDir, envFile)) {\n content = await readFileFromRoot(rootDir, envFile);\n }\n\n let updatedContent = content;\n updatedContent = upsertEnvVariable(\n updatedContent,\n 'INTLAYER_CLIENT_ID',\n clientId\n );\n updatedContent = upsertEnvVariable(\n updatedContent,\n 'INTLAYER_CLIENT_SECRET',\n clientSecret\n );\n\n await writeFileToRoot(rootDir, envFile, updatedContent);\n logger(\n `${v} Saved Intlayer CMS credentials to ${colorizePath(envFile)} (${colorize('INTLAYER_CLIENT_ID', ANSIColors.GREY_LIGHT)}, ${colorize('INTLAYER_CLIENT_SECRET', ANSIColors.GREY_LIGHT)})`\n );\n\n return envFile;\n};\n\n/**\n * Enables the Intlayer visual editor in the project's configuration file:\n * flips `editor.enabled` to `true` and wires `clientId` / `clientSecret` to the\n * matching environment variables. JSON configs cannot reference `process.env`,\n * so they are skipped with a warning. Returns the config file that was updated,\n * or `undefined` when no editable config was found.\n */\nexport const enableEditorInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) {\n logger(\n `${x} Could not find an Intlayer configuration file to enable the editor.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const extension = configFile.split('.').pop()!;\n\n if (extension === 'json') {\n logger(\n `${x} ${colorizePath(configFile)} is a JSON config and cannot reference environment variables. Enable the editor and set clientId/clientSecret manually.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = enableIntlayerEditorConfig(content);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(`${v} Enabled the Intlayer editor in ${colorizePath(configFile)}`);\n } else {\n logger(\n `${v} ${colorizePath(configFile)} already has the Intlayer editor enabled`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `routing.mode` in the project's Intlayer configuration file. Returns the\n * config file that was updated, or `undefined` when none was found.\n */\nexport const setRoutingModeInConfig = async (\n rootDir: string,\n mode: RoutingMode\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigRoutingMode(content, extension, mode);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`routing.mode = '${mode}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `compiler.output` in the project's Intlayer configuration file to the\n * given `{{variable}}` path template. Returns the config file that was updated,\n * or `undefined` when none was found.\n */\nexport const setCompilerOutputInConfig = async (\n rootDir: string,\n outputTemplate: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigCompilerOutput(\n content,\n extension,\n outputTemplate\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`compiler.output = '${outputTemplate}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Completes the CMS setup once credentials are received from the login flow:\n * writes them to the environment file and enables the editor in the Intlayer\n * configuration file.\n */\nexport const setupCmsCredentials = async (\n rootDir: string,\n credentials: CmsCredentials\n): Promise<void> => {\n await writeCmsCredentialsToEnv(rootDir, credentials);\n await enableEditorInCon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IAAI;CAC5C,MAAM,UAAU,MAAMH,+CAAiB,SAAS,UAAU;CAC1D,MAAM,iBAAiBO,sEACrB,SACA,WACA,cACF;CAEA,IAAI,mBAAmB,SAAS;EAC9B,MAAMN,8CAAgB,SAAS,YAAY,cAAc;EACzD,oCACE,GAAGC,0BAAE,6CAAgB,sBAAsB,eAAe,IAAIC,wBAAW,UAAU,EAAE,gDAAmB,UAAU,GACpH;CACF;CAEA,OAAO;AACT;;;;;;AAOA,MAAa,sBAAsB,OACjC,SACA,gBACkB;CAClB,MAAM,yBAAyB,SAAS,WAAW;CACnD,MAAM,qBAAqB,OAAO;AACpC"}
1
+ {"version":3,"file":"cms.cjs","names":["exists","fg","readFileFromRoot","writeFileToRoot","v","colorizePath","colorize","ANSIColors","x","enableIntlayerEditorConfig","setIntlayerConfigRoutingMode","setIntlayerConfigCompilerOutput"],"sources":["../../../src/init/cms.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport fg from 'fast-glob';\nimport {\n enableIntlayerEditorConfig,\n type RoutingMode,\n setIntlayerConfigCompilerOutput,\n setIntlayerConfigRoutingMode,\n} from './utils/configManipulation';\nimport { exists, readFileFromRoot, writeFileToRoot } from './utils/fileSystem';\n\n/**\n * Intlayer configuration file candidates, ordered by the precedence used when\n * resolving which file to mutate.\n */\nexport const INTLAYER_CONFIG_FILE_CANDIDATES = [\n 'intlayer.config.ts',\n 'intlayer.config.mjs',\n 'intlayer.config.js',\n 'intlayer.config.cjs',\n 'intlayer.config.json',\n] as const;\n\n/**\n * Environment files searched (most-preferred first) when persisting the CMS\n * credentials. The first existing match is reused; otherwise a `.env` file is\n * created at the project root.\n */\nconst ENV_FILE_CANDIDATES = ['.env', '.env.local', '.env.development'] as const;\n\n/** Credentials returned by the CMS login flow (access key pair). */\nexport type CmsCredentials = {\n clientId: string;\n clientSecret: string;\n};\n\n/**\n * Resolves the first existing Intlayer configuration file at the project root,\n * or `undefined` when none is present.\n */\nconst findIntlayerConfigFile = async (\n rootDir: string\n): Promise<(typeof INTLAYER_CONFIG_FILE_CANDIDATES)[number] | undefined> => {\n for (const candidate of INTLAYER_CONFIG_FILE_CANDIDATES) {\n if (await exists(rootDir, candidate)) {\n return candidate;\n }\n }\n\n return undefined;\n};\n\n/**\n * Locates the environment file the CMS credentials should be written to. Uses\n * `fast-glob` to detect an existing dotenv file at the project root, preferring\n * a plain `.env`; falls back to `.env` (to be created) when none exist.\n */\nexport const findEnvFile = async (rootDir: string): Promise<string> => {\n const matches = await fg([...ENV_FILE_CANDIDATES], {\n cwd: rootDir,\n dot: true,\n deep: 1,\n onlyFiles: true,\n });\n\n return (\n ENV_FILE_CANDIDATES.find((candidate) => matches.includes(candidate)) ??\n '.env'\n );\n};\n\n/**\n * Inserts or updates a `KEY=value` line in dotenv file content. An existing\n * assignment of the same key is replaced in place; otherwise the line is\n * appended with a trailing newline.\n */\nconst upsertEnvVariable = (\n content: string,\n key: string,\n value: string\n): string => {\n const line = `${key}=${value}`;\n const keyMatcher = new RegExp(`^${key}=.*$`, 'm');\n\n if (keyMatcher.test(content)) {\n return content.replace(keyMatcher, line);\n }\n\n const needsLeadingNewline = content.length > 0 && !content.endsWith('\\n');\n\n return `${content}${needsLeadingNewline ? '\\n' : ''}${line}\\n`;\n};\n\n/**\n * Persists the CMS access-key credentials to the project's environment file as\n * `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET`. The target file is detected\n * with {@link findEnvFile} and created when missing. Returns the relative path\n * of the file that was written.\n */\nexport const writeCmsCredentialsToEnv = async (\n rootDir: string,\n { clientId, clientSecret }: CmsCredentials\n): Promise<string> => {\n const envFile = await findEnvFile(rootDir);\n\n let content = '';\n if (await exists(rootDir, envFile)) {\n content = await readFileFromRoot(rootDir, envFile);\n }\n\n let updatedContent = content;\n updatedContent = upsertEnvVariable(\n updatedContent,\n 'INTLAYER_CLIENT_ID',\n clientId\n );\n updatedContent = upsertEnvVariable(\n updatedContent,\n 'INTLAYER_CLIENT_SECRET',\n clientSecret\n );\n\n await writeFileToRoot(rootDir, envFile, updatedContent);\n logger(\n `${v} Saved Intlayer CMS credentials to ${colorizePath(envFile)} (${colorize('INTLAYER_CLIENT_ID', ANSIColors.GREY_LIGHT)}, ${colorize('INTLAYER_CLIENT_SECRET', ANSIColors.GREY_LIGHT)})`\n );\n\n return envFile;\n};\n\n/**\n * Enables the Intlayer visual editor in the project's configuration file:\n * flips `editor.enabled` to `true` and wires `clientId` / `clientSecret` to the\n * matching environment variables. JSON configs cannot reference `process.env`,\n * so they are skipped with a warning. Returns the config file that was updated,\n * or `undefined` when no editable config was found.\n */\nexport const enableEditorInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) {\n logger(\n `${x} Could not find an Intlayer configuration file to enable the editor.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const extension = configFile.split('.').pop()!;\n\n if (extension === 'json') {\n logger(\n `${x} ${colorizePath(configFile)} is a JSON config and cannot reference environment variables. Enable the editor and set clientId/clientSecret manually.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = enableIntlayerEditorConfig(content);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(`${v} Enabled the Intlayer editor in ${colorizePath(configFile)}`);\n } else {\n logger(\n `${v} ${colorizePath(configFile)} already has the Intlayer editor enabled`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `routing.mode` in the project's Intlayer configuration file. Returns the\n * config file that was updated, or `undefined` when none was found.\n */\nexport const setRoutingModeInConfig = async (\n rootDir: string,\n mode: RoutingMode\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigRoutingMode(content, extension, mode);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`routing.mode = '${mode}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `compiler.output` in the project's Intlayer configuration file to the\n * given `{{variable}}` path template. Returns the config file that was updated,\n * or `undefined` when none was found.\n */\nexport const setCompilerOutputInConfig = async (\n rootDir: string,\n outputTemplate: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigCompilerOutput(\n content,\n extension,\n outputTemplate\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`compiler.output = '${outputTemplate}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Completes the CMS setup once credentials are received from the login flow:\n * writes them to the environment file and enables the editor in the Intlayer\n * configuration file.\n */\nexport const setupCmsCredentials = async (\n rootDir: string,\n credentials: CmsCredentials\n): Promise<void> => {\n await writeCmsCredentialsToEnv(rootDir, credentials);\n await enableEditorInConfig(rootDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,kCAAkC;CAC7C;CACA;CACA;CACA;CACA;AACF;;;;;;AAOA,MAAM,sBAAsB;CAAC;CAAQ;CAAc;AAAkB;;;;;AAYrE,MAAM,yBAAyB,OAC7B,YAC0E;CAC1E,KAAK,MAAM,aAAa,iCACtB,IAAI,MAAMA,qCAAO,SAAS,SAAS,GACjC,OAAO;AAKb;;;;;;AAOA,MAAa,cAAc,OAAO,YAAqC;CACrE,MAAM,UAAU,UAAMC,mBAAG,CAAC,GAAG,mBAAmB,GAAG;EACjD,KAAK;EACL,KAAK;EACL,MAAM;EACN,WAAW;CAC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AAyB,SAAS,WAAW;CACnD,MAAM,qBAAqB,OAAO;AACpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"detect.cjs","names":["exists"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/detect.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { exists } from '../../utils/fileSystem';\n\n/** Script extensions probed when locating an App Router convention file. */\nconst SCRIPT_EXTENSIONS = ['tsx', 'jsx', 'ts', 'js'] as const;\n\n/** Location of the Next.js App Router directory within the project. */\nexport type NextAppDirInfo = {\n /** App Router directory relative to the root, e.g. `src/app` or `app`. */\n appDir: string;\n /** `src` when the project uses a `src/` directory, otherwise `''`. */\n srcDir: string;\n};\n\n/**\n * Detects the Next.js App Router directory, preferring `src/app` over `app`.\n * Returns `null` when neither exists (e.g. a Pages Router project).\n */\nexport const detectNextAppDir = async (\n rootDir: string\n): Promise<NextAppDirInfo | null> => {\n if (await exists(rootDir, join('src', 'app'))) {\n return { appDir: join('src', 'app'), srcDir: 'src' };\n }\n if (await exists(rootDir, 'app')) {\n return { appDir: 'app', srcDir: '' };\n }\n return null;\n};\n\n/**\n * Finds an existing App Router convention file (e.g. `layout`, `page`) within\n * `dir`, trying each known script extension. Returns the matching relative path\n * or `null`.\n */\nexport const findAppFile = async (\n rootDir: string,\n dir: string,\n baseName: string\n): Promise<string | null> => {\n for (const extension of SCRIPT_EXTENSIONS) {\n const candidate = join(dir, `${baseName}.${extension}`);\n if (await exists(rootDir, candidate)) {\n return candidate;\n }\n }\n return null;\n};\n\nexport { isVersionAtLeast } from '../../utils/version';\n"],"mappings":";;;;;;;AAIA,MAAM,oBAAoB;CAAC;CAAO;CAAO;CAAM;AAAI;;;;;AAcnD,MAAa,mBAAmB,OAC9B,YACmC;CACnC,IAAI,MAAMA,qCAAO,6BAAc,OAAO,KAAK,CAAC,GAC1C,OAAO;EAAE,4BAAa,OAAO,KAAK;EAAG,QAAQ;CAAM;CAErD,IAAI,MAAMA,qCAAO,SAAS,KAAK,GAC7B,OAAO;EAAE,QAAQ;EAAO,QAAQ;CAAG;CAErC,OAAO;AACT;;;;;;AAOA,MAAa,cAAc,OACzB,SACA,KACA,aAC2B;CAC3B,KAAK,MAAM,aAAa,mBAAmB;EACzC,MAAM,gCAAiB,KAAK,GAAG,SAAS,GAAG,WAAW;EACtD,IAAI,MAAMA,qCAAO,SAAS,SAAS,GACjC,OAAO;CAEX;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"detect.cjs","names":["exists","join"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/detect.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { exists } from '../../utils/fileSystem';\n\n/** Script extensions probed when locating an App Router convention file. */\nconst SCRIPT_EXTENSIONS = ['tsx', 'jsx', 'ts', 'js'] as const;\n\n/** Location of the Next.js App Router directory within the project. */\nexport type NextAppDirInfo = {\n /** App Router directory relative to the root, e.g. `src/app` or `app`. */\n appDir: string;\n /** `src` when the project uses a `src/` directory, otherwise `''`. */\n srcDir: string;\n};\n\n/**\n * Detects the Next.js App Router directory, preferring `src/app` over `app`.\n * Returns `null` when neither exists (e.g. a Pages Router project).\n */\nexport const detectNextAppDir = async (\n rootDir: string\n): Promise<NextAppDirInfo | null> => {\n if (await exists(rootDir, join('src', 'app'))) {\n return { appDir: join('src', 'app'), srcDir: 'src' };\n }\n if (await exists(rootDir, 'app')) {\n return { appDir: 'app', srcDir: '' };\n }\n return null;\n};\n\n/**\n * Finds an existing App Router convention file (e.g. `layout`, `page`) within\n * `dir`, trying each known script extension. Returns the matching relative path\n * or `null`.\n */\nexport const findAppFile = async (\n rootDir: string,\n dir: string,\n baseName: string\n): Promise<string | null> => {\n for (const extension of SCRIPT_EXTENSIONS) {\n const candidate = join(dir, `${baseName}.${extension}`);\n if (await exists(rootDir, candidate)) {\n return candidate;\n }\n }\n return null;\n};\n\nexport { isVersionAtLeast } from '../../utils/version';\n"],"mappings":";;;;;;;AAIA,MAAM,oBAAoB;CAAC;CAAO;CAAO;CAAM;AAAI;;;;;AAcnD,MAAa,mBAAmB,OAC9B,YACmC;CACnC,IAAI,MAAMA,qCAAO,aAASC,gBAAK,OAAO,KAAK,CAAC,GAC1C,OAAO;EAAE,YAAQA,gBAAK,OAAO,KAAK;EAAG,QAAQ;CAAM;CAErD,IAAI,MAAMD,qCAAO,SAAS,KAAK,GAC7B,OAAO;EAAE,QAAQ;EAAO,QAAQ;CAAG;CAErC,OAAO;AACT;;;;;;AAOA,MAAa,cAAc,OACzB,SACA,KACA,aAC2B;CAC3B,KAAK,MAAM,aAAa,mBAAmB;EACzC,MAAM,gBAAYC,gBAAK,KAAK,GAAG,SAAS,GAAG,WAAW;EACtD,IAAI,MAAMD,qCAAO,SAAS,SAAS,GACjC,OAAO;CAEX;CACA,OAAO;AACT"}
@@ -47,9 +47,7 @@ const logTransformOutcome = (filePath, result) => {
47
47
  case "skipped-client":
48
48
  (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} ${(0, _intlayer_config_logger.colorizePath)(filePath)} is a client component — add the Intlayer provider manually.`, { level: "warn" });
49
49
  break;
50
- case "skipped":
51
- (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not safely add the Intlayer provider to ${(0, _intlayer_config_logger.colorizePath)(filePath)} — please wire it manually.`, { level: "warn" });
52
- break;
50
+ case "skipped": (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not safely add the Intlayer provider to ${(0, _intlayer_config_logger.colorizePath)(filePath)} — please wire it manually.`, { level: "warn" });
53
51
  }
54
52
  };
55
53
  /** Transforms an existing file in place, writing it back only when changed. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["exists","v","PROXY_TEMPLATE","MIDDLEWARE_TEMPLATE","ensureDirectory","writeFileToRoot","x","readFileFromRoot","detectNextAppDir","isVersionAtLeast","ANSIColors","restructureAppIntoLocale","ROOT_LAYOUT_TEMPLATE_TS","ROOT_LAYOUT_TEMPLATE_JS","findAppFile","wrapLayoutWithProvider","LOCALE_LAYOUT_TEMPLATE_TS","LOCALE_LAYOUT_TEMPLATE_JS","wrapPageWithProvider","LOCALE_PAGE_TEMPLATE_TS","LOCALE_PAGE_TEMPLATE_JS"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport {\n ensureDirectory,\n exists,\n readFileFromRoot,\n writeFileToRoot,\n} from '../../utils/fileSystem';\nimport type { FrameworkAdapter, FrameworkSetupContext } from '../types';\nimport { detectNextAppDir, findAppFile, isVersionAtLeast } from './detect';\nimport { restructureAppIntoLocale } from './restructure';\nimport {\n LOCALE_LAYOUT_TEMPLATE_JS,\n LOCALE_LAYOUT_TEMPLATE_TS,\n LOCALE_PAGE_TEMPLATE_JS,\n LOCALE_PAGE_TEMPLATE_TS,\n MIDDLEWARE_TEMPLATE,\n PROXY_TEMPLATE,\n ROOT_LAYOUT_TEMPLATE_JS,\n ROOT_LAYOUT_TEMPLATE_TS,\n} from './templates';\nimport {\n type TransformResult,\n wrapLayoutWithProvider,\n wrapPageWithProvider,\n} from './transforms';\n\n/**\n * Creates the locale-detection proxy (Next >= 16) or middleware (Next < 16),\n * but only when neither already exists, so a user's custom file is never\n * touched. Placed next to the app directory's parent (`src/` when present).\n */\nconst ensureProxyOrMiddleware = async (\n rootDir: string,\n srcDir: string,\n isNext16: boolean\n): Promise<void> => {\n const baseDir = srcDir || '.';\n const proxyCandidates = [\n 'proxy.ts',\n 'proxy.js',\n 'middleware.ts',\n 'middleware.js',\n ];\n\n for (const candidate of proxyCandidates) {\n if (await exists(rootDir, join(baseDir, candidate))) {\n logger(\n `${v} ${colorizePath(join(baseDir, candidate))} already exists, leaving it untouched`\n );\n return;\n }\n }\n\n const fileName = isNext16 ? 'proxy.ts' : 'middleware.ts';\n const content = isNext16 ? PROXY_TEMPLATE : MIDDLEWARE_TEMPLATE;\n const targetPath = join(baseDir, fileName);\n\n if (srcDir) await ensureDirectory(rootDir, srcDir);\n await writeFileToRoot(rootDir, targetPath, content);\n logger(`${v} Created ${colorizePath(targetPath)} for locale detection`);\n};\n\n/** Logs the outcome of a layout/page provider-wrap transform. */\nconst logTransformOutcome = (\n filePath: string,\n result: TransformResult\n): void => {\n switch (result.status) {\n case 'wrapped':\n logger(`${v} Added Intlayer provider to ${colorizePath(filePath)}`);\n break;\n case 'already':\n logger(\n `${v} ${colorizePath(filePath)} already wraps the Intlayer provider`\n );\n break;\n case 'skipped-client':\n logger(\n `${x} ${colorizePath(filePath)} is a client component — add the Intlayer provider manually.`,\n { level: 'warn' }\n );\n break;\n case 'skipped':\n logger(\n `${x} Could not safely add the Intlayer provider to ${colorizePath(filePath)} — please wire it manually.`,\n { level: 'warn' }\n );\n break;\n }\n};\n\n/** Transforms an existing file in place, writing it back only when changed. */\nconst transformExistingFile = async (\n rootDir: string,\n filePath: string,\n transform: (code: string) => TransformResult\n): Promise<void> => {\n const code = await readFileFromRoot(rootDir, filePath);\n const result = transform(code);\n if (result.status === 'wrapped') {\n await writeFileToRoot(rootDir, filePath, result.code);\n }\n logTransformOutcome(filePath, result);\n};\n\n/** Creates a file from a template only when it does not already exist. */\nconst createIfMissing = async (\n rootDir: string,\n filePath: string,\n content: string,\n description: string\n): Promise<boolean> => {\n if (await exists(rootDir, filePath)) return false;\n await writeFileToRoot(rootDir, filePath, content);\n logger(`${v} Created ${description} ${colorizePath(filePath)}`);\n return true;\n};\n\n/**\n * Next.js App Router adapter. Scaffolds the locale proxy/middleware, restructures\n * the app into a `[locale]` segment, and wraps the layout/page with the Intlayer\n * providers — all idempotently and without overwriting recognizable user code.\n */\nexport const nextAppRouterAdapter: FrameworkAdapter = {\n name: 'Next.js App Router',\n\n detect: async ({ rootDir, allDeps }) => {\n if (!allDeps.next) return false;\n return (await detectNextAppDir(rootDir)) !== null;\n },\n\n setup: async ({ rootDir, allDeps, useTypeScript }: FrameworkSetupContext) => {\n const appDirInfo = await detectNextAppDir(rootDir);\n if (!appDirInfo) return;\n\n const { appDir, srcDir } = appDirInfo;\n const isNext16 = isVersionAtLeast(allDeps.next, 16);\n const scriptExtension = useTypeScript ? 'tsx' : 'jsx';\n\n logger(\n colorize('Setting up Next.js App Router integration...', ANSIColors.CYAN)\n );\n\n // 1. Locale detection proxy / middleware (create only when absent).\n await ensureProxyOrMiddleware(rootDir, srcDir, isNext16);\n\n // 2. Move routable files under a `[locale]` segment (idempotent).\n const restructureResult = await restructureAppIntoLocale(rootDir, appDir);\n if (restructureResult.status === 'moved') {\n logger(\n `${v} Restructured app routes under ${colorizePath(join(appDir, '[locale]'))}: ${restructureResult.movedEntries\n .map((entry) => colorize(entry, ANSIColors.MAGENTA))\n .join(', ')}`\n );\n } else if (restructureResult.status === 'already-structured') {\n logger(\n `${v} ${colorizePath(join(appDir, restructureResult.localeSegment))} already exists, skipping restructure`\n );\n }\n\n // When the app already uses a different locale-prefix scheme (e.g. an\n // `[...locale]` / `[[...locale]]` catch-all), respect the user's routing:\n // don't scaffold a second, conflicting `[locale]` segment.\n if (\n restructureResult.status === 'already-structured' &&\n restructureResult.localeSegment !== '[locale]'\n ) {\n logger(\n `${v} Detected existing locale routing (${colorize(restructureResult.localeSegment, ANSIColors.MAGENTA)}), skipping locale layout/page scaffold`\n );\n return;\n }\n\n const localeDir = join(appDir, '[locale]');\n await ensureDirectory(rootDir, localeDir);\n\n // 3. Minimal pass-through root layout (the `[locale]` layout owns `<html>`).\n await createIfMissing(\n rootDir,\n join(appDir, `layout.${scriptExtension}`),\n useTypeScript ? ROOT_LAYOUT_TEMPLATE_TS : ROOT_LAYOUT_TEMPLATE_JS,\n 'root layout'\n );\n\n // 4. Locale layout — transform an existing one, else scaffold from template.\n const existingLayout = await findAppFile(rootDir, localeDir, 'layout');\n if (existingLayout) {\n await transformExistingFile(\n rootDir,\n existingLayout,\n wrapLayoutWithProvider\n );\n } else {\n await createIfMissing(\n rootDir,\n join(localeDir, `layout.${scriptExtension}`),\n useTypeScript ? LOCALE_LAYOUT_TEMPLATE_TS : LOCALE_LAYOUT_TEMPLATE_JS,\n 'locale layout'\n );\n }\n\n // 5. Locale page — transform an existing one, else scaffold from template.\n const existingPage = await findAppFile(rootDir, localeDir, 'page');\n if (existingPage) {\n await transformExistingFile(rootDir, existingPage, wrapPageWithProvider);\n } else {\n await createIfMissing(\n rootDir,\n join(localeDir, `page.${scriptExtension}`),\n useTypeScript ? LOCALE_PAGE_TEMPLATE_TS : LOCALE_PAGE_TEMPLATE_JS,\n 'locale page'\n );\n }\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,MAAM,0BAA0B,OAC9B,SACA,QACA,aACkB;CAClB,MAAM,UAAU,UAAU;CAQ1B,KAAK,MAAM,aAAa;EANtB;EACA;EACA;EACA;CAGoC,GACpC,IAAI,MAAMA,qCAAO,6BAAc,SAAS,SAAS,CAAC,GAAG;EACnD,oCACE,GAAGC,0BAAE,iEAAqB,SAAS,SAAS,CAAC,EAAE,sCACjD;EACA;CACF;CAGF,MAAM,WAAW,WAAW,aAAa;CACzC,MAAM,UAAU,WAAWC,qEAAiBC;CAC5C,MAAM,iCAAkB,SAAS,QAAQ;CAEzC,IAAI,QAAQ,MAAMC,8CAAgB,SAAS,MAAM;CACjD,MAAMC,8CAAgB,SAAS,YAAY,OAAO;CAClD,oCAAO,GAAGJ,0BAAE,qDAAwB,UAAU,EAAE,sBAAsB;AACxE;;AAGA,MAAM,uBACJ,UACA,WACS;CACT,QAAQ,OAAO,QAAf;EACE,KAAK;GACH,oCAAO,GAAGA,0BAAE,wEAA2C,QAAQ,GAAG;GAClE;EACF,KAAK;GACH,oCACE,GAAGA,0BAAE,6CAAgB,QAAQ,EAAE,qCACjC;GACA;EACF,KAAK;GACH,oCACE,GAAGK,0BAAE,6CAAgB,QAAQ,EAAE,+DAC/B,EAAE,OAAO,OAAO,CAClB;GACA;EACF,KAAK;GACH,oCACE,GAAGA,0BAAE,2FAA8D,QAAQ,EAAE,8BA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B,QAAQ,kBAAkB,aAAa,CAAC,EAAE,sCACtE;EAMF,IACE,kBAAkB,WAAW,wBAC7B,kBAAkB,kBAAkB,YACpC;GACA,oCACE,GAAGA,0BAAE,2EAA8C,kBAAkB,eAAeS,wBAAW,OAAO,EAAE,wCAC1G;GACA;EACF;EAEA,MAAM,gCAAiB,QAAQ,UAAU;EACzC,MAAMN,8CAAgB,SAAS,SAAS;EAGxC,MAAM,gBACJ,6BACK,QAAQ,UAAU,iBAAiB,GACxC,gBAAgBQ,8EAA0BC,6EAC1C,aACF;EAGA,MAAM,iBAAiB,MAAMC,6DAAY,SAAS,WAAW,QAAQ;EACrE,IAAI,gBACF,MAAM,sBACJ,SACA,gBACAC,2EACF;OAEA,MAAM,gBACJ,6BACK,WAAW,UAAU,iBAAiB,GAC3C,gBAAgBC,gFAA4BC,+EAC5C,eACF;EAIF,MAAM,eAAe,MAAMH,6DAAY,SAAS,WAAW,MAAM;EACjE,IAAI,cACF,MAAM,sBAAsB,SAAS,cAAcI,yEAAoB;OAEvE,MAAM,gBACJ,6BACK,WAAW,QAAQ,iBAAiB,GACzC,gBAAgBC,8EAA0BC,6EAC1C,aACF;CAEJ;AACF"}
1
+ {"version":3,"file":"index.cjs","names":["exists","join","v","colorizePath","PROXY_TEMPLATE","MIDDLEWARE_TEMPLATE","ensureDirectory","writeFileToRoot","x","readFileFromRoot","detectNextAppDir","isVersionAtLeast","colorize","ANSIColors","restructureAppIntoLocale","ROOT_LAYOUT_TEMPLATE_TS","ROOT_LAYOUT_TEMPLATE_JS","findAppFile","wrapLayoutWithProvider","LOCALE_LAYOUT_TEMPLATE_TS","LOCALE_LAYOUT_TEMPLATE_JS","wrapPageWithProvider","LOCALE_PAGE_TEMPLATE_TS","LOCALE_PAGE_TEMPLATE_JS"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport {\n ensureDirectory,\n exists,\n readFileFromRoot,\n writeFileToRoot,\n} from '../../utils/fileSystem';\nimport type { FrameworkAdapter, FrameworkSetupContext } from '../types';\nimport { detectNextAppDir, findAppFile, isVersionAtLeast } from './detect';\nimport { restructureAppIntoLocale } from './restructure';\nimport {\n LOCALE_LAYOUT_TEMPLATE_JS,\n LOCALE_LAYOUT_TEMPLATE_TS,\n LOCALE_PAGE_TEMPLATE_JS,\n LOCALE_PAGE_TEMPLATE_TS,\n MIDDLEWARE_TEMPLATE,\n PROXY_TEMPLATE,\n ROOT_LAYOUT_TEMPLATE_JS,\n ROOT_LAYOUT_TEMPLATE_TS,\n} from './templates';\nimport {\n type TransformResult,\n wrapLayoutWithProvider,\n wrapPageWithProvider,\n} from './transforms';\n\n/**\n * Creates the locale-detection proxy (Next >= 16) or middleware (Next < 16),\n * but only when neither already exists, so a user's custom file is never\n * touched. Placed next to the app directory's parent (`src/` when present).\n */\nconst ensureProxyOrMiddleware = async (\n rootDir: string,\n srcDir: string,\n isNext16: boolean\n): Promise<void> => {\n const baseDir = srcDir || '.';\n const proxyCandidates = [\n 'proxy.ts',\n 'proxy.js',\n 'middleware.ts',\n 'middleware.js',\n ];\n\n for (const candidate of proxyCandidates) {\n if (await exists(rootDir, join(baseDir, candidate))) {\n logger(\n `${v} ${colorizePath(join(baseDir, candidate))} already exists, leaving it untouched`\n );\n return;\n }\n }\n\n const fileName = isNext16 ? 'proxy.ts' : 'middleware.ts';\n const content = isNext16 ? PROXY_TEMPLATE : MIDDLEWARE_TEMPLATE;\n const targetPath = join(baseDir, fileName);\n\n if (srcDir) await ensureDirectory(rootDir, srcDir);\n await writeFileToRoot(rootDir, targetPath, content);\n logger(`${v} Created ${colorizePath(targetPath)} for locale detection`);\n};\n\n/** Logs the outcome of a layout/page provider-wrap transform. */\nconst logTransformOutcome = (\n filePath: string,\n result: TransformResult\n): void => {\n switch (result.status) {\n case 'wrapped':\n logger(`${v} Added Intlayer provider to ${colorizePath(filePath)}`);\n break;\n case 'already':\n logger(\n `${v} ${colorizePath(filePath)} already wraps the Intlayer provider`\n );\n break;\n case 'skipped-client':\n logger(\n `${x} ${colorizePath(filePath)} is a client component — add the Intlayer provider manually.`,\n { level: 'warn' }\n );\n break;\n case 'skipped':\n logger(\n `${x} Could not safely add the Intlayer provider to ${colorizePath(filePath)} — please wire it manually.`,\n { level: 'warn' }\n );\n break;\n }\n};\n\n/** Transforms an existing file in place, writing it back only when changed. */\nconst transformExistingFile = async (\n rootDir: string,\n filePath: string,\n transform: (code: string) => TransformResult\n): Promise<void> => {\n const code = await readFileFromRoot(rootDir, filePath);\n const result = transform(code);\n if (result.status === 'wrapped') {\n await writeFileToRoot(rootDir, filePath, result.code);\n }\n logTransformOutcome(filePath, result);\n};\n\n/** Creates a file from a template only when it does not already exist. */\nconst createIfMissing = async (\n rootDir: string,\n filePath: string,\n content: string,\n description: string\n): Promise<boolean> => {\n if (await exists(rootDir, filePath)) return false;\n await writeFileToRoot(rootDir, filePath, content);\n logger(`${v} Created ${description} ${colorizePath(filePath)}`);\n return true;\n};\n\n/**\n * Next.js App Router adapter. Scaffolds the locale proxy/middleware, restructures\n * the app into a `[locale]` segment, and wraps the layout/page with the Intlayer\n * providers — all idempotently and without overwriting recognizable user code.\n */\nexport const nextAppRouterAdapter: FrameworkAdapter = {\n name: 'Next.js App Router',\n\n detect: async ({ rootDir, allDeps }) => {\n if (!allDeps.next) return false;\n return (await detectNextAppDir(rootDir)) !== null;\n },\n\n setup: async ({ rootDir, allDeps, useTypeScript }: FrameworkSetupContext) => {\n const appDirInfo = await detectNextAppDir(rootDir);\n if (!appDirInfo) return;\n\n const { appDir, srcDir } = appDirInfo;\n const isNext16 = isVersionAtLeast(allDeps.next, 16);\n const scriptExtension = useTypeScript ? 'tsx' : 'jsx';\n\n logger(\n colorize('Setting up Next.js App Router integration...', ANSIColors.CYAN)\n );\n\n // 1. Locale detection proxy / middleware (create only when absent).\n await ensureProxyOrMiddleware(rootDir, srcDir, isNext16);\n\n // 2. Move routable files under a `[locale]` segment (idempotent).\n const restructureResult = await restructureAppIntoLocale(rootDir, appDir);\n if (restructureResult.status === 'moved') {\n logger(\n `${v} Restructured app routes under ${colorizePath(join(appDir, '[locale]'))}: ${restructureResult.movedEntries\n .map((entry) => colorize(entry, ANSIColors.MAGENTA))\n .join(', ')}`\n );\n } else if (restructureResult.status === 'already-structured') {\n logger(\n `${v} ${colorizePath(join(appDir, restructureResult.localeSegment))} already exists, skipping restructure`\n );\n }\n\n // When the app already uses a different locale-prefix scheme (e.g. an\n // `[...locale]` / `[[...locale]]` catch-all), respect the user's routing:\n // don't scaffold a second, conflicting `[locale]` segment.\n if (\n restructureResult.status === 'already-structured' &&\n restructureResult.localeSegment !== '[locale]'\n ) {\n logger(\n `${v} Detected existing locale routing (${colorize(restructureResult.localeSegment, ANSIColors.MAGENTA)}), skipping locale layout/page scaffold`\n );\n return;\n }\n\n const localeDir = join(appDir, '[locale]');\n await ensureDirectory(rootDir, localeDir);\n\n // 3. Minimal pass-through root layout (the `[locale]` layout owns `<html>`).\n await createIfMissing(\n rootDir,\n join(appDir, `layout.${scriptExtension}`),\n useTypeScript ? ROOT_LAYOUT_TEMPLATE_TS : ROOT_LAYOUT_TEMPLATE_JS,\n 'root layout'\n );\n\n // 4. Locale layout — transform an existing one, else scaffold from template.\n const existingLayout = await findAppFile(rootDir, localeDir, 'layout');\n if (existingLayout) {\n await transformExistingFile(\n rootDir,\n existingLayout,\n wrapLayoutWithProvider\n );\n } else {\n await createIfMissing(\n rootDir,\n join(localeDir, `layout.${scriptExtension}`),\n useTypeScript ? LOCALE_LAYOUT_TEMPLATE_TS : LOCALE_LAYOUT_TEMPLATE_JS,\n 'locale layout'\n );\n }\n\n // 5. Locale page — transform an existing one, else scaffold from template.\n const existingPage = await findAppFile(rootDir, localeDir, 'page');\n if (existingPage) {\n await transformExistingFile(rootDir, existingPage, wrapPageWithProvider);\n } else {\n await createIfMissing(\n rootDir,\n join(local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,yCAAqCU,kCAAS,kBAAkB,eAAeC,wBAAW,OAAO,EAAE,wCAC1G;GACA;EACF;EAEA,MAAM,gBAAYZ,gBAAK,QAAQ,UAAU;EACzC,MAAMK,8CAAgB,SAAS,SAAS;EAGxC,MAAM,gBACJ,aACAL,gBAAK,QAAQ,UAAU,iBAAiB,GACxC,gBAAgBc,8EAA0BC,6EAC1C,aACF;EAGA,MAAM,iBAAiB,MAAMC,6DAAY,SAAS,WAAW,QAAQ;EACrE,IAAI,gBACF,MAAM,sBACJ,SACA,gBACAC,2EACF;OAEA,MAAM,gBACJ,aACAjB,gBAAK,WAAW,UAAU,iBAAiB,GAC3C,gBAAgBkB,gFAA4BC,+EAC5C,eACF;EAIF,MAAM,eAAe,MAAMH,6DAAY,SAAS,WAAW,MAAM;EACjE,IAAI,cACF,MAAM,sBAAsB,SAAS,cAAcI,yEAAoB;OAEvE,MAAM,gBACJ,aACApB,gBAAK,WAAW,QAAQ,iBAAiB,GACzC,gBAAgBqB,8EAA0BC,6EAC1C,aACF;CAEJ;AACF"}
@@ -146,7 +146,8 @@ const restructureAppIntoLocale = async (rootDir, appDir) => {
146
146
  movedTopLevelNames
147
147
  };
148
148
  for (const newAbs of movedFiles) {
149
- const oldAbs = (0, node_path.join)(appDirAbs, (0, node_path.relative)(localeDirAbs, newAbs));
149
+ const relFromLocale = (0, node_path.relative)(localeDirAbs, newAbs);
150
+ const oldAbs = (0, node_path.join)(appDirAbs, relFromLocale);
150
151
  const code = await (0, node_fs_promises.readFile)(newAbs, "utf8");
151
152
  const rewritten = rewriteRelativeImports(code, oldAbs, newAbs, rewriteContext);
152
153
  if (rewritten !== code) await (0, node_fs_promises.writeFile)(newAbs, rewritten, "utf8");
@@ -1 +1 @@
1
- {"version":3,"file":"restructure.cjs","names":["sep","babelTsParser"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/restructure.ts"],"sourcesContent":["import { mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\nimport fg from 'fast-glob';\nimport * as recast from 'recast';\nimport { babelTsParser } from '../../../utils/babelParser';\n\nconst { namedTypes: n } = recast.types;\n\n/** Source file extensions whose relative imports must be rewritten after a move. */\nconst SCRIPT_GLOB = '**/*.{ts,tsx,js,jsx,mjs,cjs}';\n\n/** Strips a known script extension from a file name, e.g. `page.tsx` -> `page`. */\nconst stripScriptExtension = (fileName: string): string =>\n fileName.replace(/\\.(tsx|ts|jsx|js|mjs|cjs)$/, '');\n\n/**\n * Detects whether a top-level App Router entry is already a locale segment, in\n * any of the Next.js dynamic-segment forms:\n * - `[locale]` — required segment (prefix every locale),\n * - `[...locale]` / `[[...locale]]` — catch-all / optional catch-all segments.\n *\n * Used to skip the restructure when the project is already locale-aware, so an\n * existing locale segment is never nested under a freshly created `[locale]`.\n */\nexport const isLocaleSegment = (entryName: string): boolean =>\n /^\\[\\[?\\.{0,3}locale\\]\\]?$/.test(entryName);\n\n/**\n * Top-level App Router entries that must stay at the app root and never be\n * moved under `[locale]`:\n * - `api/` route handlers (not locale-prefixed),\n * - global stylesheets,\n * - metadata/asset file conventions (favicon, icon, sitemap, robots, manifest…),\n * - `global-error` and `not-found` boundaries (kept as root fallbacks).\n *\n * Everything else (`page`, `loading`, `error`, `template`, `default`, the root\n * `layout`, and nested route folders) is moved so it becomes locale-aware.\n */\nexport const shouldKeepAppEntryAtRoot = (entryName: string): boolean => {\n if (entryName === 'api') return true;\n if (entryName.toLowerCase().endsWith('.css')) return true;\n if (entryName === 'favicon.ico') return true;\n\n const base = stripScriptExtension(entryName);\n const keepExactBases = new Set([\n 'not-found',\n 'global-error',\n 'sitemap',\n 'robots',\n 'manifest',\n ]);\n if (keepExactBases.has(base)) return true;\n\n // Image metadata conventions: favicon, icon, apple-icon, opengraph-image,\n // twitter-image — optionally suffixed (e.g. `icon1`, `opengraph-image-alt`).\n const imageConventionPrefixes = [\n 'favicon',\n 'icon',\n 'apple-icon',\n 'opengraph-image',\n 'twitter-image',\n ];\n if (imageConventionPrefixes.some((prefix) => base.startsWith(prefix))) {\n return true;\n }\n\n return false;\n};\n\ntype RewriteContext = {\n appDirAbs: string;\n localeDirAbs: string;\n movedTopLevelNames: string[];\n};\n\n/**\n * Maps an import target's pre-move absolute path to its post-move absolute path.\n * Targets that live inside a moved top-level entry are relocated under\n * `[locale]`; targets that stayed at the app root or live outside the app\n * directory are returned unchanged.\n */\nconst mapTargetPath = (\n oldTargetAbs: string,\n { appDirAbs, localeDirAbs, movedTopLevelNames }: RewriteContext\n): string => {\n const relFromApp = relative(appDirAbs, oldTargetAbs);\n\n // Outside the app directory (e.g. `../components/...`) — never moved.\n if (relFromApp.startsWith('..') || isAbsolute(relFromApp)) {\n return oldTargetAbs;\n }\n\n const firstSegment = relFromApp.split(sep)[0] ?? '';\n const isMoved = movedTopLevelNames.some(\n (name) =>\n name === firstSegment || stripScriptExtension(name) === firstSegment\n );\n\n if (!isMoved) return oldTargetAbs;\n\n return join(localeDirAbs, relFromApp);\n};\n\n/**\n * Rewrites relative import/export/`import()`/`require()` specifiers in a file\n * that has moved from `oldAbs` to `newAbs`, so they keep resolving to the same\n * modules after the move. Non-relative specifiers (bare packages, `@/` aliases)\n * are left untouched. Returns the original code unchanged when nothing matched.\n */\nexport const rewriteRelativeImports = (\n code: string,\n oldAbs: string,\n newAbs: string,\n context: RewriteContext\n): string => {\n // babel-ts handles TypeScript *and* JSX (App Router files are `.tsx`).\n const ast = recast.parse(code, { parser: babelTsParser });\n\n let changed = false;\n\n const rewriteSource = (sourceNode: any): void => {\n if (!sourceNode || !n.StringLiteral.check(sourceNode)) return;\n const specifier = sourceNode.value;\n if (typeof specifier !== 'string' || !specifier.startsWith('.')) return;\n\n const oldTargetAbs = resolve(dirname(oldAbs), specifier);\n const newTargetAbs = mapTargetPath(oldTargetAbs, context);\n\n let newSpecifier = relative(dirname(newAbs), newTargetAbs)\n .split(sep)\n .join('/');\n if (!newSpecifier.startsWith('.')) {\n newSpecifier = `./${newSpecifier}`;\n }\n\n if (newSpecifier !== specifier) {\n sourceNode.value = newSpecifier;\n changed = true;\n }\n };\n\n recast.visit(ast, {\n visitImportDeclaration(path) {\n rewriteSource(path.node.source);\n return false;\n },\n visitExportAllDeclaration(path) {\n rewriteSource(path.node.source);\n return false;\n },\n visitExportNamedDeclaration(path) {\n if (path.node.source) rewriteSource(path.node.source);\n return false;\n },\n visitCallExpression(path) {\n const { callee, arguments: args } = path.node;\n const isDynamicImport = callee.type === 'Import';\n const isRequire = n.Identifier.check(callee) && callee.name === 'require';\n if ((isDynamicImport || isRequire) && args.length > 0) {\n rewriteSource(args[0]);\n }\n this.traverse(path);\n },\n });\n\n if (!changed) return code;\n return recast.print(ast).code;\n};\n\n/** Outcome of an attempted `[locale]` restructure. */\nexport type RestructureResult =\n | { status: 'already-structured'; localeSegment: string }\n | { status: 'nothing-to-move' }\n | { status: 'moved'; movedEntries: string[] };\n\n/**\n * Moves the routable App Router entries of `appDir` under a new `[locale]`\n * segment and rewrites relative imports in the moved files. Idempotent: it is a\n * no-op when the app is already locale-aware in any prefix mode (see\n * {@link isLocaleSegment}), which is reported via `localeSegment`. Root-only\n * files (see {@link shouldKeepAppEntryAtRoot}) are left in place.\n */\nexport const restructureAppIntoLocale = async (\n rootDir: string,\n appDir: string\n): Promise<RestructureResult> => {\n const appDirAbs = join(rootDir, appDir);\n const localeDirAbs = join(appDirAbs, '[locale]');\n\n const entries = await readdir(appDirAbs, { withFileTypes: true });\n\n // Skip when the app is already locale-aware in any prefix mode — a fresh\n // `[locale]`, or an existing `[...locale]` / `[[...locale]]` catch-all segment.\n const existingLocaleSegment = entries.find((entry) =>\n isLocaleSegment(entry.name)\n );\n if (existingLocaleSegment) {\n return {\n status: 'already-structured',\n localeSegment: existingLocaleSegment.name,\n };\n }\n\n const movedTopLevelNames = entries\n .map((entry) => entry.name)\n .filter((name) => !shouldKeepAppEntryAtRoot(name));\n\n if (movedTopLevelNames.length === 0) {\n return { status: 'nothing-to-move' };\n }\n\n await mkdir(localeDirAbs, { recursive: true });\n\n for (const name of movedTopLevelNames) {\n await rename(join(appDirAbs, name), join(localeDirAbs, name));\n }\n\n const movedFiles = await fg(SCRIPT_GLOB, {\n cwd: localeDirAbs,\n absolute: true,\n onlyFiles: true,\n });\n\n const rewriteContext: RewriteContext = {\n appDirAbs,\n localeDirAbs,\n movedTopLevelNames,\n };\n\n for (const newAbs of movedFiles) {\n const relFromLocale = relative(localeDirAbs, newAbs);\n const oldAbs = join(appDirAbs, relFromLocale);\n const code = await readFile(newAbs, 'utf8');\n const rewritten = rewriteRelativeImports(\n code,\n oldAbs,\n newAbs,\n rewriteContext\n );\n if (rewritten !== code) {\n await writeFile(newAbs, rewritten, 'utf8');\n }\n }\n\n return { status: 'moved', movedEntries: movedTopLevelNames };\n};\n"],"mappings":";;;;;;;;;;;AAMA,MAAM,EAAE,YAAY,MAAM,OAAO;;AAGjC,MAAM,cAAc;;AAGpB,MAAM,wBAAwB,aAC5B,SAAS,QAAQ,8BAA8B,EAAE;;;;;;;;;;AAWnD,MAAa,mBAAmB,cAC9B,4BAA4B,KAAK,SAAS;;;;;;;;;;;;AAa5C,MAAa,4BAA4B,cAA+B;CACtE,IAAI,cAAc,OAAO,OAAO;CAChC,IAAI,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO;CACrD,IAAI,cAAc,eAAe,OAAO;CAExC,MAAM,OAAO,qBAAqB,SAAS;CAQ3C,qBAAI,IAPuB,IAAI;EAC7B;EACA;EACA;EACA;EACA;CACF,CACiB,EAAC,CAAC,IAAI,IAAI,GAAG,OAAO;CAWrC,IAAI;EANF;EACA;EACA;EACA;EACA;CAEwB,CAAC,CAAC,MAAM,WAAW,KAAK,WAAW,MAAM,CAAC,GAClE,OAAO;CAGT,OAAO;AACT;;;;;;;AAcA,MAAM,iBACJ,cACA,EAAE,WAAW,cAAc,yBAChB;CACX,MAAM,qCAAsB,WAAW,YAAY;CAGnD,IAAI,WAAW,WAAW,IAAI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K,SAAS,GAClD,cAAc,KAAK,EAAE;GAEvB,KAAK,SAAS,IAAI;EACpB;CACF,CAAC;CAED,IAAI,CAAC,SAAS,OAAO;CACrB,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;AAC3B;;;;;;;;AAeA,MAAa,2BAA2B,OACtC,SACA,WAC+B;CAC/B,MAAM,gCAAiB,SAAS,MAAM;CACtC,MAAM,mCAAoB,WAAW,UAAU;CAE/C,MAAM,UAAU,oCAAc,WAAW,EAAE,eAAe,KAAK,CAAC;CAIhE,MAAM,wBAAwB,QAAQ,MAAM,UAC1C,gBAAgB,MAAM,IAAI,CAC5B;CACA,IAAI,uBACF,OAAO;EACL,QAAQ;EACR,eAAe,sBAAsB;CACvC;CAGF,MAAM,qBAAqB,QACxB,KAAK,UAAU,MAAM,IAAI,CAAC,CAC1B,QAAQ,SAAS,CAAC,yBAAyB,IAAI,CAAC;CAEnD,IAAI,mBAAmB,WAAW,GAChC,OAAO,EAAE,QAAQ,kBAAkB;CAGrC,kCAAY,cAAc,EAAE,WAAW,KAAK,CAAC;CAE7C,KAAK,MAAM,QAAQ,oBACjB,uDAAkB,WAAW,IAAI,uBAAQ,cAAc,IAAI,CAAC;CAG9D,MAAM,aAAa,6BAAS,aAAa;EACvC,KAAK;EACL,UAAU;EACV,WAAW;CACb,CAAC;CAED,MAAM,iBAAiC;EACrC;EACA;EACA;CACF;CAEA,KAAK,MAAM,UAAU,YAAY;EAE/B,MAAM,6BAAc,mCADW,cAAc,MACF,CAAC;EAC5C,MAAM,OAAO,qCAAe,QAAQ,MAAM;EAC1C,MAAM,YAAY,uBAChB,MACA,QACA,QACA,cACF;EACA,IAAI,cAAc,MAChB,sCAAgB,QAAQ,WAAW,MAAM;CAE7C;CAEA,OAAO;EAAE,QAAQ;EAAS,cAAc;CAAmB;AAC7D"}
1
+ {"version":3,"file":"restructure.cjs","names":["relative","isAbsolute","sep","join","babelTsParser","resolve","dirname","readdir","mkdir","rename","fg","readFile","writeFile"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/restructure.ts"],"sourcesContent":["import { mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\nimport fg from 'fast-glob';\nimport * as recast from 'recast';\nimport { babelTsParser } from '../../../utils/babelParser';\n\nconst { namedTypes: n } = recast.types;\n\n/** Source file extensions whose relative imports must be rewritten after a move. */\nconst SCRIPT_GLOB = '**/*.{ts,tsx,js,jsx,mjs,cjs}';\n\n/** Strips a known script extension from a file name, e.g. `page.tsx` -> `page`. */\nconst stripScriptExtension = (fileName: string): string =>\n fileName.replace(/\\.(tsx|ts|jsx|js|mjs|cjs)$/, '');\n\n/**\n * Detects whether a top-level App Router entry is already a locale segment, in\n * any of the Next.js dynamic-segment forms:\n * - `[locale]` — required segment (prefix every locale),\n * - `[...locale]` / `[[...locale]]` — catch-all / optional catch-all segments.\n *\n * Used to skip the restructure when the project is already locale-aware, so an\n * existing locale segment is never nested under a freshly created `[locale]`.\n */\nexport const isLocaleSegment = (entryName: string): boolean =>\n /^\\[\\[?\\.{0,3}locale\\]\\]?$/.test(entryName);\n\n/**\n * Top-level App Router entries that must stay at the app root and never be\n * moved under `[locale]`:\n * - `api/` route handlers (not locale-prefixed),\n * - global stylesheets,\n * - metadata/asset file conventions (favicon, icon, sitemap, robots, manifest…),\n * - `global-error` and `not-found` boundaries (kept as root fallbacks).\n *\n * Everything else (`page`, `loading`, `error`, `template`, `default`, the root\n * `layout`, and nested route folders) is moved so it becomes locale-aware.\n */\nexport const shouldKeepAppEntryAtRoot = (entryName: string): boolean => {\n if (entryName === 'api') return true;\n if (entryName.toLowerCase().endsWith('.css')) return true;\n if (entryName === 'favicon.ico') return true;\n\n const base = stripScriptExtension(entryName);\n const keepExactBases = new Set([\n 'not-found',\n 'global-error',\n 'sitemap',\n 'robots',\n 'manifest',\n ]);\n if (keepExactBases.has(base)) return true;\n\n // Image metadata conventions: favicon, icon, apple-icon, opengraph-image,\n // twitter-image — optionally suffixed (e.g. `icon1`, `opengraph-image-alt`).\n const imageConventionPrefixes = [\n 'favicon',\n 'icon',\n 'apple-icon',\n 'opengraph-image',\n 'twitter-image',\n ];\n if (imageConventionPrefixes.some((prefix) => base.startsWith(prefix))) {\n return true;\n }\n\n return false;\n};\n\ntype RewriteContext = {\n appDirAbs: string;\n localeDirAbs: string;\n movedTopLevelNames: string[];\n};\n\n/**\n * Maps an import target's pre-move absolute path to its post-move absolute path.\n * Targets that live inside a moved top-level entry are relocated under\n * `[locale]`; targets that stayed at the app root or live outside the app\n * directory are returned unchanged.\n */\nconst mapTargetPath = (\n oldTargetAbs: string,\n { appDirAbs, localeDirAbs, movedTopLevelNames }: RewriteContext\n): string => {\n const relFromApp = relative(appDirAbs, oldTargetAbs);\n\n // Outside the app directory (e.g. `../components/...`) — never moved.\n if (relFromApp.startsWith('..') || isAbsolute(relFromApp)) {\n return oldTargetAbs;\n }\n\n const firstSegment = relFromApp.split(sep)[0] ?? '';\n const isMoved = movedTopLevelNames.some(\n (name) =>\n name === firstSegment || stripScriptExtension(name) === firstSegment\n );\n\n if (!isMoved) return oldTargetAbs;\n\n return join(localeDirAbs, relFromApp);\n};\n\n/**\n * Rewrites relative import/export/`import()`/`require()` specifiers in a file\n * that has moved from `oldAbs` to `newAbs`, so they keep resolving to the same\n * modules after the move. Non-relative specifiers (bare packages, `@/` aliases)\n * are left untouched. Returns the original code unchanged when nothing matched.\n */\nexport const rewriteRelativeImports = (\n code: string,\n oldAbs: string,\n newAbs: string,\n context: RewriteContext\n): string => {\n // babel-ts handles TypeScript *and* JSX (App Router files are `.tsx`).\n const ast = recast.parse(code, { parser: babelTsParser });\n\n let changed = false;\n\n const rewriteSource = (sourceNode: any): void => {\n if (!sourceNode || !n.StringLiteral.check(sourceNode)) return;\n const specifier = sourceNode.value;\n if (typeof specifier !== 'string' || !specifier.startsWith('.')) return;\n\n const oldTargetAbs = resolve(dirname(oldAbs), specifier);\n const newTargetAbs = mapTargetPath(oldTargetAbs, context);\n\n let newSpecifier = relative(dirname(newAbs), newTargetAbs)\n .split(sep)\n .join('/');\n if (!newSpecifier.startsWith('.')) {\n newSpecifier = `./${newSpecifier}`;\n }\n\n if (newSpecifier !== specifier) {\n sourceNode.value = newSpecifier;\n changed = true;\n }\n };\n\n recast.visit(ast, {\n visitImportDeclaration(path) {\n rewriteSource(path.node.source);\n return false;\n },\n visitExportAllDeclaration(path) {\n rewriteSource(path.node.source);\n return false;\n },\n visitExportNamedDeclaration(path) {\n if (path.node.source) rewriteSource(path.node.source);\n return false;\n },\n visitCallExpression(path) {\n const { callee, arguments: args } = path.node;\n const isDynamicImport = callee.type === 'Import';\n const isRequire = n.Identifier.check(callee) && callee.name === 'require';\n if ((isDynamicImport || isRequire) && args.length > 0) {\n rewriteSource(args[0]);\n }\n this.traverse(path);\n },\n });\n\n if (!changed) return code;\n return recast.print(ast).code;\n};\n\n/** Outcome of an attempted `[locale]` restructure. */\nexport type RestructureResult =\n | { status: 'already-structured'; localeSegment: string }\n | { status: 'nothing-to-move' }\n | { status: 'moved'; movedEntries: string[] };\n\n/**\n * Moves the routable App Router entries of `appDir` under a new `[locale]`\n * segment and rewrites relative imports in the moved files. Idempotent: it is a\n * no-op when the app is already locale-aware in any prefix mode (see\n * {@link isLocaleSegment}), which is reported via `localeSegment`. Root-only\n * files (see {@link shouldKeepAppEntryAtRoot}) are left in place.\n */\nexport const restructureAppIntoLocale = async (\n rootDir: string,\n appDir: string\n): Promise<RestructureResult> => {\n const appDirAbs = join(rootDir, appDir);\n const localeDirAbs = join(appDirAbs, '[locale]');\n\n const entries = await readdir(appDirAbs, { withFileTypes: true });\n\n // Skip when the app is already locale-aware in any prefix mode — a fresh\n // `[locale]`, or an existing `[...locale]` / `[[...locale]]` catch-all segment.\n const existingLocaleSegment = entries.find((entry) =>\n isLocaleSegment(entry.name)\n );\n if (existingLocaleSegment) {\n return {\n status: 'already-structured',\n localeSegment: existingLocaleSegment.name,\n };\n }\n\n const movedTopLevelNames = entries\n .map((entry) => entry.name)\n .filter((name) => !shouldKeepAppEntryAtRoot(name));\n\n if (movedTopLevelNames.length === 0) {\n return { status: 'nothing-to-move' };\n }\n\n await mkdir(localeDirAbs, { recursive: true });\n\n for (const name of movedTopLevelNames) {\n await rename(join(appDirAbs, name), join(localeDirAbs, name));\n }\n\n const movedFiles = await fg(SCRIPT_GLOB, {\n cwd: localeDirAbs,\n absolute: true,\n onlyFiles: true,\n });\n\n const rewriteContext: RewriteContext = {\n appDirAbs,\n localeDirAbs,\n movedTopLevelNames,\n };\n\n for (const newAbs of movedFiles) {\n const relFromLocale = relative(localeDirAbs, newAbs);\n const oldAbs = join(appDirAbs, relFromLocale);\n const code = await readFile(newAbs, 'utf8');\n const rewritten = rewriteRelativeImports(\n code,\n oldAbs,\n newAbs,\n rewriteContext\n );\n if (rewritten !== code) {\n await writeFile(newAbs, rewritten, 'utf8');\n }\n }\n\n return { status: 'moved', movedEntries: movedTopLevelNames };\n};\n"],"mappings":";;;;;;;;;;;AAMA,MAAM,EAAE,YAAY,MAAM,OAAO;;AAGjC,MAAM,cAAc;;AAGpB,MAAM,wBAAwB,aAC5B,SAAS,QAAQ,8BAA8B,EAAE;;;;;;;;;;AAWnD,MAAa,mBAAmB,cAC9B,4BAA4B,KAAK,SAAS;;;;;;;;;;;;AAa5C,MAAa,4BAA4B,cAA+B;CACtE,IAAI,cAAc,OAAO,OAAO;CAChC,IAAI,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO;CACrD,IAAI,cAAc,eAAe,OAAO;CAExC,MAAM,OAAO,qBAAqB,SAAS;CAQ3C,qBAAI,IAPuB,IAAI;EAC7B;EACA;EACA;EACA;EACA;CACF,CACiB,EAAC,CAAC,IAAI,IAAI,GAAG,OAAO;CAWrC,IAAI;EANF;EACA;EACA;EACA;EACA;CAEwB,CAAC,CAAC,MAAM,WAAW,KAAK,WAAW,MAAM,CAAC,GAClE,OAAO;CAGT,OAAO;AACT;;;;;;;A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AAM;EAC1C,MAAM,YAAY,uBAChB,MACA,QACA,QACA,cACF;EACA,IAAI,cAAc,MAChB,UAAMC,4BAAU,QAAQ,WAAW,MAAM;CAE7C;CAEA,OAAO;EAAE,QAAQ;EAAS,cAAc;CAAmB;AAC7D"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/init/frameworkSetup/nextAppRouter/templates.ts
4
3
  /**
5
4
  * File templates for a fresh Next.js App Router integration. These are only
@@ -1 +1 @@
1
- {"version":3,"file":"templates.cjs","names":[],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/templates.ts"],"sourcesContent":["/**\n * File templates for a fresh Next.js App Router integration. These are only\n * written when the target file does not exist (or, for the locale layout/page,\n * when the app is effectively empty) — they never overwrite user code.\n */\n\n/** Next.js >= 16 locale-detection proxy (`src/proxy.ts`). */\nexport const PROXY_TEMPLATE = `export { intlayerProxy as proxy } from \"next-intlayer/proxy\";\n\nexport const config = {\n matcher:\n \"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\\\\\..*|_next).*)\",\n};\n`;\n\n/** Next.js < 16 locale-detection middleware (`src/middleware.ts`). */\nexport const MIDDLEWARE_TEMPLATE = `export { intlayerMiddleware as middleware } from \"next-intlayer/middleware\";\n\nexport const config = {\n matcher:\n \"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\\\\\..*|_next).*)\",\n};\n`;\n\n/** Minimal pass-through root layout (`app/layout.tsx`), lets `[locale]/layout` own `<html>`. */\nexport const ROOT_LAYOUT_TEMPLATE_TS = `import type { PropsWithChildren, FC } from \"react\";\n\nconst RootLayout: FC<PropsWithChildren> = ({ children }) => <>{children}</>;\n\nexport default RootLayout;\n`;\n\nexport const ROOT_LAYOUT_TEMPLATE_JS = `const RootLayout = ({ children }) => <>{children}</>;\n\nexport default RootLayout;\n`;\n\n/** Locale layout (`app/[locale]/layout.tsx`) providing `<html>` + client provider. */\nexport const LOCALE_LAYOUT_TEMPLATE_TS = `import { type NextLayoutIntlayer, IntlayerClientProvider } from \"next-intlayer\";\nimport { getHTMLTextDir } from \"intlayer\";\n\nexport { generateStaticParams } from \"next-intlayer\";\n\nconst LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {\n const { locale } = await params;\n\n return (\n <html lang={locale} dir={getHTMLTextDir(locale)}>\n <body>\n <IntlayerClientProvider locale={locale}>\n {children}\n </IntlayerClientProvider>\n </body>\n </html>\n );\n};\n\nexport default LocaleLayout;\n`;\n\nexport const LOCALE_LAYOUT_TEMPLATE_JS = `import { IntlayerClientProvider } from \"next-intlayer\";\nimport { getHTMLTextDir } from \"intlayer\";\n\nexport { generateStaticParams } from \"next-intlayer\";\n\nconst LocaleLayout = async ({ children, params }) => {\n const { locale } = await params;\n\n return (\n <html lang={locale} dir={getHTMLTextDir(locale)}>\n <body>\n <IntlayerClientProvider locale={locale}>\n {children}\n </IntlayerClientProvider>\n </body>\n </html>\n );\n};\n\nexport default LocaleLayout;\n`;\n\n/**\n * Locale home page (`app/[locale]/page.tsx`). Self-contained starter that does\n * not depend on an example content declaration — add Intlayer content (a\n * `*.content.ts` file consumed via `useIntlayer`) as the next step.\n */\nexport const LOCALE_PAGE_TEMPLATE_TS = `import { type NextPageIntlayer } from \"next-intlayer\";\n\nconst Page: NextPageIntlayer = async ({ params }) => {\n const { locale } = await params;\n\n return (\n <main>\n <h1>{locale}</h1>\n <p>Get started by editing this page.</p>\n </main>\n );\n};\n\nexport default Page;\n`;\n\nexport const LOCALE_PAGE_TEMPLATE_JS = `const Page = async ({ params }) => {\n const { locale } = await params;\n\n return (\n <main>\n <h1>{locale}</h1>\n <p>Get started by editing this page.</p>\n </main>\n );\n};\n\nexport default Page;\n`;\n"],"mappings":";;;;;;;;;AAOA,MAAa,iBAAiB;;;;;;;;AAS9B,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,0BAA0B;;;;;;AAOvC,MAAa,0BAA0B;;;;;AAMvC,MAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;AAsBzC,MAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BzC,MAAa,0BAA0B;;;;;;;;;;;;;;;AAgBvC,MAAa,0BAA0B"}
1
+ {"version":3,"file":"templates.cjs","names":[],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/templates.ts"],"sourcesContent":["/**\n * File templates for a fresh Next.js App Router integration. These are only\n * written when the target file does not exist (or, for the locale layout/page,\n * when the app is effectively empty) — they never overwrite user code.\n */\n\n/** Next.js >= 16 locale-detection proxy (`src/proxy.ts`). */\nexport const PROXY_TEMPLATE = `export { intlayerProxy as proxy } from \"next-intlayer/proxy\";\n\nexport const config = {\n matcher:\n \"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\\\\\..*|_next).*)\",\n};\n`;\n\n/** Next.js < 16 locale-detection middleware (`src/middleware.ts`). */\nexport const MIDDLEWARE_TEMPLATE = `export { intlayerMiddleware as middleware } from \"next-intlayer/middleware\";\n\nexport const config = {\n matcher:\n \"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\\\\\..*|_next).*)\",\n};\n`;\n\n/** Minimal pass-through root layout (`app/layout.tsx`), lets `[locale]/layout` own `<html>`. */\nexport const ROOT_LAYOUT_TEMPLATE_TS = `import type { PropsWithChildren, FC } from \"react\";\n\nconst RootLayout: FC<PropsWithChildren> = ({ children }) => <>{children}</>;\n\nexport default RootLayout;\n`;\n\nexport const ROOT_LAYOUT_TEMPLATE_JS = `const RootLayout = ({ children }) => <>{children}</>;\n\nexport default RootLayout;\n`;\n\n/** Locale layout (`app/[locale]/layout.tsx`) providing `<html>` + client provider. */\nexport const LOCALE_LAYOUT_TEMPLATE_TS = `import { type NextLayoutIntlayer, IntlayerClientProvider } from \"next-intlayer\";\nimport { getHTMLTextDir } from \"intlayer\";\n\nexport { generateStaticParams } from \"next-intlayer\";\n\nconst LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {\n const { locale } = await params;\n\n return (\n <html lang={locale} dir={getHTMLTextDir(locale)}>\n <body>\n <IntlayerClientProvider locale={locale}>\n {children}\n </IntlayerClientProvider>\n </body>\n </html>\n );\n};\n\nexport default LocaleLayout;\n`;\n\nexport const LOCALE_LAYOUT_TEMPLATE_JS = `import { IntlayerClientProvider } from \"next-intlayer\";\nimport { getHTMLTextDir } from \"intlayer\";\n\nexport { generateStaticParams } from \"next-intlayer\";\n\nconst LocaleLayout = async ({ children, params }) => {\n const { locale } = await params;\n\n return (\n <html lang={locale} dir={getHTMLTextDir(locale)}>\n <body>\n <IntlayerClientProvider locale={locale}>\n {children}\n </IntlayerClientProvider>\n </body>\n </html>\n );\n};\n\nexport default LocaleLayout;\n`;\n\n/**\n * Locale home page (`app/[locale]/page.tsx`). Self-contained starter that does\n * not depend on an example content declaration — add Intlayer content (a\n * `*.content.ts` file consumed via `useIntlayer`) as the next step.\n */\nexport const LOCALE_PAGE_TEMPLATE_TS = `import { type NextPageIntlayer } from \"next-intlayer\";\n\nconst Page: NextPageIntlayer = async ({ params }) => {\n const { locale } = await params;\n\n return (\n <main>\n <h1>{locale}</h1>\n <p>Get started by editing this page.</p>\n </main>\n );\n};\n\nexport default Page;\n`;\n\nexport const LOCALE_PAGE_TEMPLATE_JS = `const Page = async ({ params }) => {\n const { locale } = await params;\n\n return (\n <main>\n <h1>{locale}</h1>\n <p>Get started by editing this page.</p>\n </main>\n );\n};\n\nexport default Page;\n`;\n"],"mappings":";;;;;;;;AAOA,MAAa,iBAAiB;;;;;;;;AAS9B,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,0BAA0B;;;;;;AAOvC,MAAa,0BAA0B;;;;;AAMvC,MAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;AAsBzC,MAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BzC,MAAa,0BAA0B;;;;;;;;;;;;;;;AAgBvC,MAAa,0BAA0B"}
@@ -1 +1 @@
1
- {"version":3,"file":"detect.cjs","names":["exists"],"sources":["../../../../../src/init/frameworkSetup/tanstackStart/detect.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { exists } from '../../utils/fileSystem';\n\n/** Location of the TanStack Router file-based routes directory. */\nexport type TanStackRoutesInfo = {\n /** Routes directory relative to the root, e.g. `src/routes` or `routes`. */\n routesDir: string;\n /** `src` when the project uses a `src/` directory, otherwise `''`. */\n srcDir: string;\n};\n\n/**\n * Detects the TanStack Router routes directory, preferring `src/routes` over\n * `routes`. Returns `null` when neither exists.\n */\nexport const detectTanStackRoutesDir = async (\n rootDir: string\n): Promise<TanStackRoutesInfo | null> => {\n if (await exists(rootDir, join('src', 'routes'))) {\n return { routesDir: join('src', 'routes'), srcDir: 'src' };\n }\n if (await exists(rootDir, 'routes')) {\n return { routesDir: 'routes', srcDir: '' };\n }\n return null;\n};\n\n/**\n * Returns true when the project depends on TanStack Start (`@tanstack/react-start`)\n * or, failing that, on `@tanstack/react-router` (file-based routing).\n */\nexport const hasTanStackStartDeps = (\n allDeps: Record<string, string>\n): boolean =>\n Boolean(\n allDeps['@tanstack/react-start'] || allDeps['@tanstack/react-router']\n );\n"],"mappings":";;;;;;;;;AAeA,MAAa,0BAA0B,OACrC,YACuC;CACvC,IAAI,MAAMA,qCAAO,6BAAc,OAAO,QAAQ,CAAC,GAC7C,OAAO;EAAE,+BAAgB,OAAO,QAAQ;EAAG,QAAQ;CAAM;CAE3D,IAAI,MAAMA,qCAAO,SAAS,QAAQ,GAChC,OAAO;EAAE,WAAW;EAAU,QAAQ;CAAG;CAE3C,OAAO;AACT;;;;;AAMA,MAAa,wBACX,YAEA,QACE,QAAQ,4BAA4B,QAAQ,yBAC9C"}
1
+ {"version":3,"file":"detect.cjs","names":["exists","join"],"sources":["../../../../../src/init/frameworkSetup/tanstackStart/detect.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { exists } from '../../utils/fileSystem';\n\n/** Location of the TanStack Router file-based routes directory. */\nexport type TanStackRoutesInfo = {\n /** Routes directory relative to the root, e.g. `src/routes` or `routes`. */\n routesDir: string;\n /** `src` when the project uses a `src/` directory, otherwise `''`. */\n srcDir: string;\n};\n\n/**\n * Detects the TanStack Router routes directory, preferring `src/routes` over\n * `routes`. Returns `null` when neither exists.\n */\nexport const detectTanStackRoutesDir = async (\n rootDir: string\n): Promise<TanStackRoutesInfo | null> => {\n if (await exists(rootDir, join('src', 'routes'))) {\n return { routesDir: join('src', 'routes'), srcDir: 'src' };\n }\n if (await exists(rootDir, 'routes')) {\n return { routesDir: 'routes', srcDir: '' };\n }\n return null;\n};\n\n/**\n * Returns true when the project depends on TanStack Start (`@tanstack/react-start`)\n * or, failing that, on `@tanstack/react-router` (file-based routing).\n */\nexport const hasTanStackStartDeps = (\n allDeps: Record<string, string>\n): boolean =>\n Boolean(\n allDeps['@tanstack/react-start'] || allDeps['@tanstack/react-router']\n );\n"],"mappings":";;;;;;;;;AAeA,MAAa,0BAA0B,OACrC,YACuC;CACvC,IAAI,MAAMA,qCAAO,aAASC,gBAAK,OAAO,QAAQ,CAAC,GAC7C,OAAO;EAAE,eAAWA,gBAAK,OAAO,QAAQ;EAAG,QAAQ;CAAM;CAE3D,IAAI,MAAMD,qCAAO,SAAS,QAAQ,GAChC,OAAO;EAAE,WAAW;EAAU,QAAQ;CAAG;CAE3C,OAAO;AACT;;;;;AAMA,MAAa,wBACX,YAEA,QACE,QAAQ,4BAA4B,QAAQ,yBAC9C"}
@@ -21,9 +21,7 @@ const logTransformOutcome = (filePath, result) => {
21
21
  case "already":
22
22
  (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} ${(0, _intlayer_config_logger.colorizePath)(filePath)} already wraps the Intlayer provider`);
23
23
  break;
24
- case "skipped":
25
- (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not safely add the Intlayer provider to ${(0, _intlayer_config_logger.colorizePath)(filePath)} — please wrap the document's {children} with <IntlayerProvider locale={locale}> manually.`, { level: "warn" });
26
- break;
24
+ case "skipped": (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not safely add the Intlayer provider to ${(0, _intlayer_config_logger.colorizePath)(filePath)} — please wrap the document's {children} with <IntlayerProvider locale={locale}> manually.`, { level: "warn" });
27
25
  }
28
26
  };
29
27
  /** Transforms an existing file in place, writing it back only when changed. */
@@ -66,8 +64,8 @@ const tanStackStartAdapter = {
66
64
  await require_init_utils_fileSystem.ensureDirectory(rootDir, localeDir);
67
65
  await createIfMissing(rootDir, (0, node_path.join)(localeDir, `route.${scriptExtension}`), require_init_frameworkSetup_tanstackStart_templates.buildLocaleRouteTemplate(activeLocaleSegment), "locale route");
68
66
  const existingRoot = await require_init_frameworkSetup_nextAppRouter_detect.findAppFile(rootDir, routesDir, "__root");
69
- if (existingRoot) await transformExistingFile(rootDir, existingRoot, require_init_frameworkSetup_tanstackStart_transforms.wrapRootWithProvider);
70
- else await createIfMissing(rootDir, (0, node_path.join)(routesDir, `__root.${scriptExtension}`), useTypeScript ? require_init_frameworkSetup_tanstackStart_templates.ROOT_TEMPLATE_TS : require_init_frameworkSetup_tanstackStart_templates.ROOT_TEMPLATE_JS, "root document");
67
+ if (existingRoot) await transformExistingFile(rootDir, existingRoot, (code) => require_init_frameworkSetup_tanstackStart_transforms.wrapRootWithProvider(code, activeLocaleSegment));
68
+ else await createIfMissing(rootDir, (0, node_path.join)(routesDir, `__root.${scriptExtension}`), useTypeScript ? require_init_frameworkSetup_tanstackStart_templates.buildRootTemplateTs(activeLocaleSegment) : require_init_frameworkSetup_tanstackStart_templates.buildRootTemplateJs(activeLocaleSegment), "root document");
71
69
  }
72
70
  };
73
71
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["v","x","readFileFromRoot","writeFileToRoot","exists","hasTanStackStartDeps","detectTanStackRoutesDir","getLocaleSegment","ANSIColors","restructureRoutesIntoLocale","ensureDirectory","buildLocaleRouteTemplate","findAppFile","wrapRootWithProvider","ROOT_TEMPLATE_TS","ROOT_TEMPLATE_JS"],"sources":["../../../../../src/init/frameworkSetup/tanstackStart/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport {\n ensureDirectory,\n exists,\n readFileFromRoot,\n writeFileToRoot,\n} from '../../utils/fileSystem';\nimport { findAppFile } from '../nextAppRouter/detect';\nimport type { FrameworkAdapter, FrameworkSetupContext } from '../types';\nimport { detectTanStackRoutesDir, hasTanStackStartDeps } from './detect';\nimport { getLocaleSegment, restructureRoutesIntoLocale } from './restructure';\nimport {\n buildLocaleRouteTemplate,\n ROOT_TEMPLATE_JS,\n ROOT_TEMPLATE_TS,\n} from './templates';\nimport { type TransformResult, wrapRootWithProvider } from './transforms';\n\n/** Logs the outcome of the root-document provider-wrap transform. */\nconst logTransformOutcome = (\n filePath: string,\n result: TransformResult\n): void => {\n switch (result.status) {\n case 'wrapped':\n logger(`${v} Added Intlayer provider to ${colorizePath(filePath)}`);\n break;\n case 'already':\n logger(\n `${v} ${colorizePath(filePath)} already wraps the Intlayer provider`\n );\n break;\n case 'skipped':\n logger(\n `${x} Could not safely add the Intlayer provider to ${colorizePath(filePath)} — please wrap the document's {children} with <IntlayerProvider locale={locale}> manually.`,\n { level: 'warn' }\n );\n break;\n }\n};\n\n/** Transforms an existing file in place, writing it back only when changed. */\nconst transformExistingFile = async (\n rootDir: string,\n filePath: string,\n transform: (code: string) => TransformResult\n): Promise<void> => {\n const code = await readFileFromRoot(rootDir, filePath);\n const result = transform(code);\n if (result.status === 'wrapped') {\n await writeFileToRoot(rootDir, filePath, result.code);\n }\n logTransformOutcome(filePath, result);\n};\n\n/** Creates a file from a template only when it does not already exist. */\nconst createIfMissing = async (\n rootDir: string,\n filePath: string,\n content: string,\n description: string\n): Promise<boolean> => {\n if (await exists(rootDir, filePath)) return false;\n await writeFileToRoot(rootDir, filePath, content);\n logger(`${v} Created ${description} ${colorizePath(filePath)}`);\n return true;\n};\n\n/**\n * TanStack Start adapter. Restructures the file-based routes under a `{-$locale}`\n * segment, scaffolds the locale segment route, and wraps the root document with\n * the Intlayer provider — all idempotently and without overwriting user code it\n * cannot confidently transform.\n */\nexport const tanStackStartAdapter: FrameworkAdapter = {\n name: 'TanStack Start',\n\n detect: async ({ rootDir, allDeps }) => {\n if (!hasTanStackStartDeps(allDeps)) return false;\n return (await detectTanStackRoutesDir(rootDir)) !== null;\n },\n\n setup: async ({\n rootDir,\n useTypeScript,\n routingMode,\n }: FrameworkSetupContext) => {\n const routesInfo = await detectTanStackRoutesDir(rootDir);\n if (!routesInfo) return;\n\n const { routesDir } = routesInfo;\n const scriptExtension = useTypeScript ? 'tsx' : 'jsx';\n\n // `prefix-all` needs the required `$locale` segment; every other mode uses\n // the optional `{-$locale}` segment so the default locale stays prefix-free.\n const targetLocaleSegment = getLocaleSegment(routingMode);\n\n logger(\n colorize('Setting up TanStack Start integration...', ANSIColors.CYAN)\n );\n\n // 1. Move routable route entries under the locale segment (idempotent).\n const restructureResult = await restructureRoutesIntoLocale(\n rootDir,\n routesDir,\n targetLocaleSegment\n );\n if (restructureResult.status === 'moved') {\n logger(\n `${v} Restructured routes under ${colorizePath(join(routesDir, targetLocaleSegment))}: ${restructureResult.movedEntries\n .map((entry) => colorize(entry, ANSIColors.MAGENTA))\n .join(', ')}`\n );\n } else if (restructureResult.status === 'already-structured') {\n logger(\n `${v} ${colorizePath(join(routesDir, restructureResult.localeSegment))} already exists, skipping restructure`\n );\n }\n\n // Scaffold the locale route for the segment actually in use: a pre-existing\n // segment (e.g. a prefix-all `$locale` the user already set up) wins over the\n // target, so we never create a second, conflicting locale segment.\n const activeLocaleSegment =\n restructureResult.status === 'already-structured'\n ? restructureResult.localeSegment\n : targetLocaleSegment;\n\n const localeDir = join(routesDir, activeLocaleSegment);\n await ensureDirectory(rootDir, localeDir);\n\n // 2. Locale segment route (`<segment>/route.tsx`) — create when absent.\n await createIfMissing(\n rootDir,\n join(localeDir, `route.${scriptExtension}`),\n buildLocaleRouteTemplate(activeLocaleSegment),\n 'locale route'\n );\n\n // 3. Root document — transform an existing `__root`, else scaffold one.\n const existingRoot = await findAppFile(rootDir, routesDir, '__root');\n if (existingRoot) {\n await transformExistingFile(rootDir, existingRoot, wrapRootWithProvider);\n } else {\n await createIfMissing(\n rootDir,\n join(routesDir, `__root.${scriptExtension}`),\n useTypeScript ? ROOT_TEMPLATE_TS : ROOT_TEMPLATE_JS,\n 'root document'\n );\n }\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAM,uBACJ,UACA,WACS;CACT,QAAQ,OAAO,QAAf;EACE,KAAK;GACH,oCAAO,GAAGA,0BAAE,wEAA2C,QAAQ,GAAG;GAClE;EACF,KAAK;GACH,oCACE,GAAGA,0BAAE,6CAAgB,QAAQ,EAAE,qCACjC;GACA;EACF,KAAK;GACH,oCACE,GAAGC,0BAAE,2FAA8D,QAAQ,EAAE,6FAC7E,EAAE,OAAO,OAAO,CAClB;GACA;CACJ;AACF;;AAGA,MAAM,wBAAwB,OAC5B,SACA,UACA,cACkB;CAElB,MAAM,SAAS,UAAU,MADNC,+CAAiB,SAAS,QAAQ,CACxB;CAC7B,IAAI,OAAO,WAAW,WACpB,MAAMC,8CAAgB,SAAS,UAAU,OAAO,IAAI;CAEtD,oBAAoB,UAAU,MAAM;AACtC;;AAGA,MAAM,kBAAkB,OACtB,SACA,UACA,SACA,gBACqB;CACrB,IAAI,MAAMC,qCAAO,SAAS,QAAQ,GAAG,OAAO;CAC5C,MAAMD,8CAAgB,SAAS,UAAU,OAAO;CAChD,oCAAO,GAAGH,0BAAE,WAAW,YAAY,6CAAgB,QAAQ,GAAG;CAC9D,OAAO;AACT;;;;;;;AAQA,MAAa,uBAAyC;CACpD,MAAM;CAEN,QAAQ,OAAO,EAAE,SAAS,cAAc;EACtC,IAAI,CAACK,sEAAqB,OAAO,GAAG,OAAO;EAC3C,OAAQ,MAAMC,yEAAwB,OAAO,MAAO;CACtD;CAEA,OAAO,OAAO,EACZ,SACA,eACA,kBAC2B;EAC3B,MAAM,aAAa,MAAMA,yEAAwB,OAAO;EACxD,IAAI,CAAC,YAAY;EAEjB,MAAM,EAAE,cAAc;EACtB,MAAM,kBAAkB,gBAAgB,QAAQ;EAIhD,MAAM,sBAAsBC,uEAAiB,WAAW;EAExD,0EACW,4CAA4CC,wBAAW,IAAI,CACtE;EAGA,MAAM,oBAAoB,MAAMC,kFAC9B,SACA,WACA,mBACF;EACA,IAAI,kBAAkB,WAAW,SAC/B,oCACE,GAAGT,0BAAE,2FAA+C,WAAW,mBAAmB,CAAC,EAAE,IAAI,kBAAkB,aACxG,KAAK,gDAAmB,OAAOQ,wBAAW,OAAO,CAAC,CAAC,CACnD,KAAK,IAAI,GACd;OACK,IAAI,kBAAkB,WAAW,sBACtC,oCACE,GAAGR,0BAAE,iEAAqB,WAAW,kBAAkB,aAAa,CAAC,EAAE,sCACzE;EAMF,MAAM,sBACJ,kBAAkB,WAAW,uBACzB,kBAAkB,gBAClB;EAEN,MAAM,gCAAiB,WAAW,mBAAmB;EACrD,MAAMU,8CAAgB,SAAS,SAAS;EAGxC,MAAM,gBACJ,6BACK,WAAW,SAAS,iBAAiB,GAC1CC,6EAAyB,mBAAmB,GAC5C,cACF;EAGA,MAAM,eAAe,MAAMC,6DAAY,SAAS,WAAW,QAAQ;EACnE,IAAI,cACF,MAAM,sBAAsB,SAAS,cAAcC,yEAAoB;OAEvE,MAAM,gBACJ,6BACK,WAAW,UAAU,iBAAiB,GAC3C,gBAAgBC,uEAAmBC,sEACnC,eACF;CAEJ;AACF"}
1
+ {"version":3,"file":"index.cjs","names":["v","colorizePath","x","readFileFromRoot","writeFileToRoot","exists","hasTanStackStartDeps","detectTanStackRoutesDir","getLocaleSegment","colorize","ANSIColors","restructureRoutesIntoLocale","join","ensureDirectory","buildLocaleRouteTemplate","findAppFile","wrapRootWithProvider","buildRootTemplateTs","buildRootTemplateJs"],"sources":["../../../../../src/init/frameworkSetup/tanstackStart/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport {\n ensureDirectory,\n exists,\n readFileFromRoot,\n writeFileToRoot,\n} from '../../utils/fileSystem';\nimport { findAppFile } from '../nextAppRouter/detect';\nimport type { FrameworkAdapter, FrameworkSetupContext } from '../types';\nimport { detectTanStackRoutesDir, hasTanStackStartDeps } from './detect';\nimport { getLocaleSegment, restructureRoutesIntoLocale } from './restructure';\nimport {\n buildLocaleRouteTemplate,\n buildRootTemplateJs,\n buildRootTemplateTs,\n} from './templates';\nimport { type TransformResult, wrapRootWithProvider } from './transforms';\n\n/** Logs the outcome of the root-document provider-wrap transform. */\nconst logTransformOutcome = (\n filePath: string,\n result: TransformResult\n): void => {\n switch (result.status) {\n case 'wrapped':\n logger(`${v} Added Intlayer provider to ${colorizePath(filePath)}`);\n break;\n case 'already':\n logger(\n `${v} ${colorizePath(filePath)} already wraps the Intlayer provider`\n );\n break;\n case 'skipped':\n logger(\n `${x} Could not safely add the Intlayer provider to ${colorizePath(filePath)} — please wrap the document's {children} with <IntlayerProvider locale={locale}> manually.`,\n { level: 'warn' }\n );\n break;\n }\n};\n\n/** Transforms an existing file in place, writing it back only when changed. */\nconst transformExistingFile = async (\n rootDir: string,\n filePath: string,\n transform: (code: string) => TransformResult\n): Promise<void> => {\n const code = await readFileFromRoot(rootDir, filePath);\n const result = transform(code);\n if (result.status === 'wrapped') {\n await writeFileToRoot(rootDir, filePath, result.code);\n }\n logTransformOutcome(filePath, result);\n};\n\n/** Creates a file from a template only when it does not already exist. */\nconst createIfMissing = async (\n rootDir: string,\n filePath: string,\n content: string,\n description: string\n): Promise<boolean> => {\n if (await exists(rootDir, filePath)) return false;\n await writeFileToRoot(rootDir, filePath, content);\n logger(`${v} Created ${description} ${colorizePath(filePath)}`);\n return true;\n};\n\n/**\n * TanStack Start adapter. Restructures the file-based routes under a `{-$locale}`\n * segment, scaffolds the locale segment route, and wraps the root document with\n * the Intlayer provider — all idempotently and without overwriting user code it\n * cannot confidently transform.\n */\nexport const tanStackStartAdapter: FrameworkAdapter = {\n name: 'TanStack Start',\n\n detect: async ({ rootDir, allDeps }) => {\n if (!hasTanStackStartDeps(allDeps)) return false;\n return (await detectTanStackRoutesDir(rootDir)) !== null;\n },\n\n setup: async ({\n rootDir,\n useTypeScript,\n routingMode,\n }: FrameworkSetupContext) => {\n const routesInfo = await detectTanStackRoutesDir(rootDir);\n if (!routesInfo) return;\n\n const { routesDir } = routesInfo;\n const scriptExtension = useTypeScript ? 'tsx' : 'jsx';\n\n // `prefix-all` needs the required `$locale` segment; every other mode uses\n // the optional `{-$locale}` segment so the default locale stays prefix-free.\n const targetLocaleSegment = getLocaleSegment(routingMode);\n\n logger(\n colorize('Setting up TanStack Start integration...', ANSIColors.CYAN)\n );\n\n // 1. Move routable route entries under the locale segment (idempotent).\n const restructureResult = await restructureRoutesIntoLocale(\n rootDir,\n routesDir,\n targetLocaleSegment\n );\n if (restructureResult.status === 'moved') {\n logger(\n `${v} Restructured routes under ${colorizePath(join(routesDir, targetLocaleSegment))}: ${restructureResult.movedEntries\n .map((entry) => colorize(entry, ANSIColors.MAGENTA))\n .join(', ')}`\n );\n } else if (restructureResult.status === 'already-structured') {\n logger(\n `${v} ${colorizePath(join(routesDir, restructureResult.localeSegment))} already exists, skipping restructure`\n );\n }\n\n // Scaffold the locale route for the segment actually in use: a pre-existing\n // segment (e.g. a prefix-all `$locale` the user already set up) wins over the\n // target, so we never create a second, conflicting locale segment.\n const activeLocaleSegment =\n restructureResult.status === 'already-structured'\n ? restructureResult.localeSegment\n : targetLocaleSegment;\n\n const localeDir = join(routesDir, activeLocaleSegment);\n await ensureDirectory(rootDir, localeDir);\n\n // 2. Locale segment route (`<segment>/route.tsx`) — create when absent.\n await createIfMissing(\n rootDir,\n join(localeDir, `route.${scriptExtension}`),\n buildLocaleRouteTemplate(activeLocaleSegment),\n 'locale route'\n );\n\n // 3. Root document — transform an existing `__root`, else scaffold one.\n const existingRoot = await findAppFile(rootDir, routesDir, '__root');\n if (existingRoot) {\n await transformExistingFile(rootDir, existingRoot, (code) =>\n wrapRootWithProvider(code, activeLocaleSegment)\n );\n } else {\n await createIfMissing(\n rootDir,\n join(routesDir, `__root.${scriptExtension}`),\n useTypeScript\n ? buildRootTemplateTs(activeLocaleSegment)\n : buildRootTemplateJs(activeLocaleSegment),\n 'root document'\n );\n }\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAM,uBACJ,UACA,WACS;CACT,QAAQ,OAAO,QAAf;EACE,KAAK;GACH,oCAAO,GAAGA,0BAAE,kCAA8BC,sCAAa,QAAQ,GAAG;GAClE;EACF,KAAK;GACH,oCACE,GAAGD,0BAAE,OAAGC,sCAAa,QAAQ,EAAE,qCACjC;GACA;EACF,KAAK,WACH,oCACE,GAAGC,0BAAE,qDAAiDD,sCAAa,QAAQ,EAAE,6FAC7E,EAAE,OAAO,OAAO,CAClB;CAEJ;AACF;;AAGA,MAAM,wBAAwB,OAC5B,SACA,UACA,cACkB;CAElB,MAAM,SAAS,UAAU,MADNE,+CAAiB,SAAS,QAAQ,CACxB;CAC7B,IAAI,OAAO,WAAW,WACpB,MAAMC,8CAAgB,SAAS,UAAU,OAAO,IAAI;CAEtD,oBAAoB,UAAU,MAAM;AACtC;;AAGA,MAAM,kBAAkB,OACtB,SACA,UACA,SACA,gBACqB;CACrB,IAAI,MAAMC,qCAAO,SAAS,QAAQ,GAAG,OAAO;CAC5C,MAAMD,8CAAgB,SAAS,UAAU,OAAO;CAChD,oCAAO,GAAGJ,0BAAE,WAAW,YAAY,OAAGC,sCAAa,QAAQ,GAAG;CAC9D,OAAO;AACT;;;;;;;AAQA,MAAa,uBAAyC;CACpD,MAAM;CAEN,QAAQ,OAAO,EAAE,SAAS,cAAc;EACtC,IAAI,CAACK,sEAAqB,OAAO,GAAG,OAAO;EAC3C,OAAQ,MAAMC,yEAAwB,OAAO,MAAO;CACtD;CAEA,OAAO,OAAO,EACZ,SACA,eACA,kBAC2B;EAC3B,MAAM,aAAa,MAAMA,yEAAwB,OAAO;EACxD,IAAI,CAAC,YAAY;EAEjB,MAAM,EAAE,cAAc;EACtB,MAAM,kBAAkB,gBAAgB,QAAQ;EAIhD,MAAM,sBAAsBC,uEAAiB,WAAW;EAExD,wCACEC,kCAAS,4CAA4CC,wBAAW,IAAI,CACtE;EAGA,MAAM,oBAAoB,MAAMC,kFAC9B,SACA,WACA,mBACF;EACA,IAAI,kBAAkB,WAAW,SAC/B,oCACE,GAAGX,0BAAE,iCAA6BC,0CAAaW,gBAAK,WAAW,mBAAmB,CAAC,EAAE,IAAI,kBAAkB,aACxG,KAAK,cAAUH,kCAAS,OAAOC,wBAAW,OAAO,CAAC,CAAC,CACnD,KAAK,IAAI,GACd;OACK,IAAI,kBAAkB,WAAW,sBACtC,oCACE,GAAGV,0BAAE,OAAGC,0CAAaW,gBAAK,WAAW,kBAAkB,aAAa,CAAC,EAAE,sCACzE;EAMF,MAAM,sBACJ,kBAAkB,WAAW,uBACzB,kBAAkB,gBAClB;EAEN,MAAM,gBAAYA,gBAAK,WAAW,mBAAmB;EACrD,MAAMC,8CAAgB,SAAS,SAAS;EAGxC,MAAM,gBACJ,aACAD,gBAAK,WAAW,SAAS,iBAAiB,GAC1CE,6EAAyB,mBAAmB,GAC5C,cACF;EAGA,MAAM,eAAe,MAAMC,6DAAY,SAAS,WAAW,QAAQ;EACnE,IAAI,cACF,MAAM,sBAAsB,SAAS,eAAe,SAClDC,0EAAqB,MAAM,mBAAmB,CAChD;OAEA,MAAM,gBACJ,aACAJ,gBAAK,WAAW,UAAU,iBAAiB,GAC3C,gBACIK,wEAAoB,mBAAmB,IACvCC,wEAAoB,mBAAmB,GAC3C,eACF;CAEJ;AACF"}
@@ -95,7 +95,8 @@ const restructureRoutesIntoLocale = async (rootDir, routesDir, localeSegment = L
95
95
  movedTopLevelNames
96
96
  };
97
97
  for (const newAbs of movedFiles) {
98
- const oldAbs = (0, node_path.join)(routesDirAbs, (0, node_path.relative)(localeDirAbs, newAbs));
98
+ const relFromLocale = (0, node_path.relative)(localeDirAbs, newAbs);
99
+ const oldAbs = (0, node_path.join)(routesDirAbs, relFromLocale);
99
100
  const code = await (0, node_fs_promises.readFile)(newAbs, "utf8");
100
101
  const rewritten = require_init_frameworkSetup_nextAppRouter_restructure.rewriteRelativeImports(code, oldAbs, newAbs, rewriteContext);
101
102
  if (rewritten !== code) await (0, node_fs_promises.writeFile)(newAbs, rewritten, "utf8");
@@ -1 +1 @@
1
- {"version":3,"file":"restructure.cjs","names":["rewriteRelativeImports"],"sources":["../../../../../src/init/frameworkSetup/tanstackStart/restructure.ts"],"sourcesContent":["import { mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport fg from 'fast-glob';\nimport type { RoutingMode } from '../../utils/configManipulation';\nimport { rewriteRelativeImports } from '../nextAppRouter/restructure';\n\n/** Source file extensions whose relative imports must be rewritten after a move. */\nconst SCRIPT_GLOB = '**/*.{ts,tsx,js,jsx,mjs,cjs}';\n\n/**\n * The optional TanStack Router locale segment directory (`{-$locale}` param),\n * used by every routing mode except `prefix-all` so the default locale stays\n * prefix-free.\n */\nexport const LOCALE_SEGMENT = '{-$locale}';\n\n/**\n * The required TanStack Router locale segment directory (`$locale` param), used\n * by `prefix-all` routing where every URL — including the default locale — is\n * prefixed.\n */\nexport const PREFIX_ALL_LOCALE_SEGMENT = '$locale';\n\n/**\n * Picks the locale segment directory for the project's routing mode. `prefix-all`\n * requires the mandatory `$locale` param so the default locale is also prefixed;\n * all other modes use the optional `{-$locale}` param so the default locale stays\n * prefix-free.\n */\nexport const getLocaleSegment = (routingMode: RoutingMode): string =>\n routingMode === 'prefix-all' ? PREFIX_ALL_LOCALE_SEGMENT : LOCALE_SEGMENT;\n\n/**\n * Detects whether a top-level route entry is already a locale segment, in any of\n * the TanStack Router param forms:\n * - `{-$locale}` — optional param (prefix every locale except the default),\n * - `$locale` / `{$locale}` — required param (prefix **all** locales).\n *\n * Used to skip the restructure when the project is already locale-aware, so an\n * existing prefix-all `$locale` directory is never nested under a freshly created\n * `{-$locale}` (which would produce `{-$locale}/$locale`).\n */\nexport const isLocaleSegment = (entryName: string): boolean =>\n /^(\\{-?\\$locale\\}|\\$locale)$/.test(entryName);\n\n/** Strips a known script extension from a file name, e.g. `index.tsx` -> `index`. */\nconst stripScriptExtension = (fileName: string): string =>\n fileName.replace(/\\.(tsx|ts|jsx|js|mjs|cjs)$/, '');\n\n/**\n * Routes-directory entries that must stay at the root and never be moved under\n * `{-$locale}`:\n * - `__root` (the root route document),\n * - `routeTree.gen` (generated route tree),\n * - `api` (server / API routes — these are not locale-prefixed),\n * - TanStack-ignored entries prefixed with `-` (e.g. `-components`, `-utils`),\n * - stylesheets.\n *\n * Everything else (route files and nested route folders) is moved so it becomes\n * locale-aware.\n */\nexport const shouldKeepRouteAtRoot = (entryName: string): boolean => {\n if (entryName.startsWith('-')) return true;\n if (entryName.toLowerCase().endsWith('.css')) return true;\n\n const base = stripScriptExtension(entryName);\n const keepExactBases = new Set(['__root', 'routeTree.gen', 'api']);\n return keepExactBases.has(base);\n};\n\n/** Outcome of an attempted `{-$locale}` restructure. */\nexport type RestructureResult =\n | { status: 'already-structured'; localeSegment: string }\n | { status: 'nothing-to-move' }\n | { status: 'moved'; movedEntries: string[] };\n\n/**\n * Moves the routable entries of `routesDir` under a new `localeSegment` directory\n * (the optional `{-$locale}` by default, or the required `$locale` for\n * `prefix-all`) and rewrites relative imports in the moved files. Idempotent: a\n * no-op when the routes are already locale-aware in any prefix mode (see\n * {@link isLocaleSegment}), which is reported via `localeSegment`. Root-only\n * files (see {@link shouldKeepRouteAtRoot}) are left in place.\n */\nexport const restructureRoutesIntoLocale = async (\n rootDir: string,\n routesDir: string,\n localeSegment: string = LOCALE_SEGMENT\n): Promise<RestructureResult> => {\n const routesDirAbs = join(rootDir, routesDir);\n const localeDirAbs = join(routesDirAbs, localeSegment);\n\n const entries = await readdir(routesDirAbs, { withFileTypes: true });\n\n // Skip when the routes are already locale-aware in any prefix mode — a fresh\n // `{-$locale}`, or an existing `$locale` / `{$locale}` (prefix-all) segment.\n const existingLocaleSegment = entries.find((entry) =>\n isLocaleSegment(entry.name)\n );\n if (existingLocaleSegment) {\n return {\n status: 'already-structured',\n localeSegment: existingLocaleSegment.name,\n };\n }\n\n const movedTopLevelNames = entries\n .map((entry) => entry.name)\n .filter((name) => !shouldKeepRouteAtRoot(name));\n\n if (movedTopLevelNames.length === 0) {\n return { status: 'nothing-to-move' };\n }\n\n await mkdir(localeDirAbs, { recursive: true });\n\n for (const name of movedTopLevelNames) {\n await rename(join(routesDirAbs, name), join(localeDirAbs, name));\n }\n\n const movedFiles = await fg(SCRIPT_GLOB, {\n cwd: localeDirAbs,\n absolute: true,\n onlyFiles: true,\n });\n\n const rewriteContext = {\n appDirAbs: routesDirAbs,\n localeDirAbs,\n movedTopLevelNames,\n };\n\n for (const newAbs of movedFiles) {\n const relFromLocale = relative(localeDirAbs, newAbs);\n const oldAbs = join(routesDirAbs, relFromLocale);\n const code = await readFile(newAbs, 'utf8');\n const rewritten = rewriteRelativeImports(\n code,\n oldAbs,\n newAbs,\n rewriteContext\n );\n if (rewritten !== code) {\n await writeFile(newAbs, rewritten, 'utf8');\n }\n }\n\n return { status: 'moved', movedEntries: movedTopLevelNames };\n};\n"],"mappings":";;;;;;;;;;AAOA,MAAM,cAAc;;;;;;AAOpB,MAAa,iBAAiB;;;;;;AAO9B,MAAa,4BAA4B;;;;;;;AAQzC,MAAa,oBAAoB,gBAC/B,gBAAgB,eAAe,4BAA4B;;;;;;;;;;;AAY7D,MAAa,mBAAmB,cAC9B,8BAA8B,KAAK,SAAS;;AAG9C,MAAM,wBAAwB,aAC5B,SAAS,QAAQ,8BAA8B,EAAE;;;;;;;;;;;;;AAcnD,MAAa,yBAAyB,cAA+B;CACnE,IAAI,UAAU,WAAW,GAAG,GAAG,OAAO;CACtC,IAAI,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO;CAErD,MAAM,OAAO,qBAAqB,SAAS;CAE3C,wBAAO,IADoB,IAAI;EAAC;EAAU;EAAiB;CAAK,CAC5C,EAAC,CAAC,IAAI,IAAI;AAChC;;;;;;;;;AAgBA,MAAa,8BAA8B,OACzC,SACA,WACA,gBAAwB,mBACO;CAC/B,MAAM,mCAAoB,SAAS,SAAS;CAC5C,MAAM,mCAAoB,cAAc,aAAa;CAErD,MAAM,UAAU,oCAAc,cAAc,EAAE,eAAe,KAAK,CAAC;CAInE,MAAM,wBAAwB,QAAQ,MAAM,UAC1C,gBAAgB,MAAM,IAAI,CAC5B;CACA,IAAI,uBACF,OAAO;EACL,QAAQ;EACR,eAAe,sBAAsB;CACvC;CAGF,MAAM,qBAAqB,QACxB,KAAK,UAAU,MAAM,IAAI,CAAC,CAC1B,QAAQ,SAAS,CAAC,sBAAsB,IAAI,CAAC;CAEhD,IAAI,mBAAmB,WAAW,GAChC,OAAO,EAAE,QAAQ,kBAAkB;CAGrC,kCAAY,cAAc,EAAE,WAAW,KAAK,CAAC;CAE7C,KAAK,MAAM,QAAQ,oBACjB,uDAAkB,cAAc,IAAI,uBAAQ,cAAc,IAAI,CAAC;CAGjE,MAAM,aAAa,6BAAS,aAAa;EACvC,KAAK;EACL,UAAU;EACV,WAAW;CACb,CAAC;CAED,MAAM,iBAAiB;EACrB,WAAW;EACX;EACA;CACF;CAEA,KAAK,MAAM,UAAU,YAAY;EAE/B,MAAM,6BAAc,sCADW,cAAc,MACC,CAAC;EAC/C,MAAM,OAAO,qCAAe,QAAQ,MAAM;EAC1C,MAAM,YAAYA,6EAChB,MACA,QACA,QACA,cACF;EACA,IAAI,cAAc,MAChB,sCAAgB,QAAQ,WAAW,MAAM;CAE7C;CAEA,OAAO;EAAE,QAAQ;EAAS,cAAc;CAAmB;AAC7D"}
1
+ {"version":3,"file":"restructure.cjs","names":["join","readdir","mkdir","rename","fg","relative","readFile","rewriteRelativeImports","writeFile"],"sources":["../../../../../src/init/frameworkSetup/tanstackStart/restructure.ts"],"sourcesContent":["import { mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport fg from 'fast-glob';\nimport type { RoutingMode } from '../../utils/configManipulation';\nimport { rewriteRelativeImports } from '../nextAppRouter/restructure';\n\n/** Source file extensions whose relative imports must be rewritten after a move. */\nconst SCRIPT_GLOB = '**/*.{ts,tsx,js,jsx,mjs,cjs}';\n\n/**\n * The optional TanStack Router locale segment directory (`{-$locale}` param),\n * used by every routing mode except `prefix-all` so the default locale stays\n * prefix-free.\n */\nexport const LOCALE_SEGMENT = '{-$locale}';\n\n/**\n * The required TanStack Router locale segment directory (`$locale` param), used\n * by `prefix-all` routing where every URL — including the default locale — is\n * prefixed.\n */\nexport const PREFIX_ALL_LOCALE_SEGMENT = '$locale';\n\n/**\n * Picks the locale segment directory for the project's routing mode. `prefix-all`\n * requires the mandatory `$locale` param so the default locale is also prefixed;\n * all other modes use the optional `{-$locale}` param so the default locale stays\n * prefix-free.\n */\nexport const getLocaleSegment = (routingMode: RoutingMode): string =>\n routingMode === 'prefix-all' ? PREFIX_ALL_LOCALE_SEGMENT : LOCALE_SEGMENT;\n\n/**\n * Detects whether a top-level route entry is already a locale segment, in any of\n * the TanStack Router param forms:\n * - `{-$locale}` — optional param (prefix every locale except the default),\n * - `$locale` / `{$locale}` — required param (prefix **all** locales).\n *\n * Used to skip the restructure when the project is already locale-aware, so an\n * existing prefix-all `$locale` directory is never nested under a freshly created\n * `{-$locale}` (which would produce `{-$locale}/$locale`).\n */\nexport const isLocaleSegment = (entryName: string): boolean =>\n /^(\\{-?\\$locale\\}|\\$locale)$/.test(entryName);\n\n/** Strips a known script extension from a file name, e.g. `index.tsx` -> `index`. */\nconst stripScriptExtension = (fileName: string): string =>\n fileName.replace(/\\.(tsx|ts|jsx|js|mjs|cjs)$/, '');\n\n/**\n * Routes-directory entries that must stay at the root and never be moved under\n * `{-$locale}`:\n * - `__root` (the root route document),\n * - `routeTree.gen` (generated route tree),\n * - `api` (server / API routes — these are not locale-prefixed),\n * - TanStack-ignored entries prefixed with `-` (e.g. `-components`, `-utils`),\n * - stylesheets.\n *\n * Everything else (route files and nested route folders) is moved so it becomes\n * locale-aware.\n */\nexport const shouldKeepRouteAtRoot = (entryName: string): boolean => {\n if (entryName.startsWith('-')) return true;\n if (entryName.toLowerCase().endsWith('.css')) return true;\n\n const base = stripScriptExtension(entryName);\n const keepExactBases = new Set(['__root', 'routeTree.gen', 'api']);\n return keepExactBases.has(base);\n};\n\n/** Outcome of an attempted `{-$locale}` restructure. */\nexport type RestructureResult =\n | { status: 'already-structured'; localeSegment: string }\n | { status: 'nothing-to-move' }\n | { status: 'moved'; movedEntries: string[] };\n\n/**\n * Moves the routable entries of `routesDir` under a new `localeSegment` directory\n * (the optional `{-$locale}` by default, or the required `$locale` for\n * `prefix-all`) and rewrites relative imports in the moved files. Idempotent: a\n * no-op when the routes are already locale-aware in any prefix mode (see\n * {@link isLocaleSegment}), which is reported via `localeSegment`. Root-only\n * files (see {@link shouldKeepRouteAtRoot}) are left in place.\n */\nexport const restructureRoutesIntoLocale = async (\n rootDir: string,\n routesDir: string,\n localeSegment: string = LOCALE_SEGMENT\n): Promise<RestructureResult> => {\n const routesDirAbs = join(rootDir, routesDir);\n const localeDirAbs = join(routesDirAbs, localeSegment);\n\n const entries = await readdir(routesDirAbs, { withFileTypes: true });\n\n // Skip when the routes are already locale-aware in any prefix mode — a fresh\n // `{-$locale}`, or an existing `$locale` / `{$locale}` (prefix-all) segment.\n const existingLocaleSegment = entries.find((entry) =>\n isLocaleSegment(entry.name)\n );\n if (existingLocaleSegment) {\n return {\n status: 'already-structured',\n localeSegment: existingLocaleSegment.name,\n };\n }\n\n const movedTopLevelNames = entries\n .map((entry) => entry.name)\n .filter((name) => !shouldKeepRouteAtRoot(name));\n\n if (movedTopLevelNames.length === 0) {\n return { status: 'nothing-to-move' };\n }\n\n await mkdir(localeDirAbs, { recursive: true });\n\n for (const name of movedTopLevelNames) {\n await rename(join(routesDirAbs, name), join(localeDirAbs, name));\n }\n\n const movedFiles = await fg(SCRIPT_GLOB, {\n cwd: localeDirAbs,\n absolute: true,\n onlyFiles: true,\n });\n\n const rewriteContext = {\n appDirAbs: routesDirAbs,\n localeDirAbs,\n movedTopLevelNames,\n };\n\n for (const newAbs of movedFiles) {\n const relFromLocale = relative(localeDirAbs, newAbs);\n const oldAbs = join(routesDirAbs, relFromLocale);\n const code = await readFile(newAbs, 'utf8');\n const rewritten = rewriteRelativeImports(\n code,\n oldAbs,\n newAbs,\n rewriteContext\n );\n if (rewritten !== code) {\n await writeFile(newAbs, rewritten, 'utf8');\n }\n }\n\n return { status: 'moved', movedEntries: movedTopLevelNames };\n};\n"],"mappings":";;;;;;;;;;AAOA,MAAM,cAAc;;;;;;AAOpB,MAAa,iBAAiB;;;;;;AAO9B,MAAa,4BAA4B;;;;;;;AAQzC,MAAa,oBAAoB,gBAC/B,gBAAgB,eAAe,4BAA4B;;;;;;;;;;;AAY7D,MAAa,mBAAmB,cAC9B,8BAA8B,KAAK,SAAS;;AAG9C,MAAM,wBAAwB,aAC5B,SAAS,QAAQ,8BAA8B,EAAE;;;;;;;;;;;;;AAcnD,MAAa,yBAAyB,cAA+B;CACnE,IAAI,UAAU,WAAW,GAAG,GAAG,OAAO;CACtC,IAAI,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO;CAErD,MAAM,OAAO,qBAAqB,SAAS;CAE3C,wBAAO,IADoB,IAAI;EAAC;EAAU;EAAiB;CAAK,CAC5C,EAAC,CAAC,IAAI,IAAI;AAChC;;;;;;;;;AAgBA,MAAa,8BAA8B,OACzC,SACA,WACA,gBAAwB,mBACO;CAC/B,MAAM,mBAAeA,gBAAK,SAAS,SAAS;CAC5C,MAAM,mBAAeA,gBAAK,cAAc,aAAa;CAErD,MAAM,UAAU,UAAMC,0BAAQ,cAAc,EAAE,eAAe,KAAK,CAAC;CAIn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