forgebook 0.1.2 → 0.1.4

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 (345) hide show
  1. package/README.md +94 -5
  2. package/dist/bin/forgebook/agentClient.d.ts +39 -0
  3. package/dist/bin/forgebook/agentClient.d.ts.map +1 -0
  4. package/dist/bin/forgebook/agentClient.js +91 -0
  5. package/dist/bin/forgebook/agentClient.js.map +1 -0
  6. package/dist/bin/forgebook/agentLoopCommands.d.mts +9 -0
  7. package/dist/bin/forgebook/agentLoopCommands.d.mts.map +1 -0
  8. package/dist/bin/forgebook/agentLoopCommands.mjs +217 -0
  9. package/dist/bin/forgebook/agentLoopCommands.mjs.map +1 -0
  10. package/dist/bin/forgebook/agentText.d.ts +54 -0
  11. package/dist/bin/forgebook/agentText.d.ts.map +1 -0
  12. package/dist/bin/forgebook/agentText.js +91 -0
  13. package/dist/bin/forgebook/agentText.js.map +1 -0
  14. package/dist/bin/forgebook/agents.md +46 -0
  15. package/dist/bin/forgebook/agentsText.d.ts +29 -0
  16. package/dist/bin/forgebook/agentsText.d.ts.map +1 -0
  17. package/dist/bin/forgebook/agentsText.js +48 -0
  18. package/dist/bin/forgebook/agentsText.js.map +1 -0
  19. package/dist/bin/forgebook/catalogueCommands.d.ts +51 -0
  20. package/dist/bin/forgebook/catalogueCommands.d.ts.map +1 -0
  21. package/dist/bin/forgebook/catalogueCommands.js +90 -0
  22. package/dist/bin/forgebook/catalogueCommands.js.map +1 -0
  23. package/dist/bin/forgebook/errorsRun.d.ts +27 -0
  24. package/dist/bin/forgebook/errorsRun.d.ts.map +1 -0
  25. package/dist/bin/forgebook/errorsRun.js +60 -0
  26. package/dist/bin/forgebook/errorsRun.js.map +1 -0
  27. package/dist/bin/forgebook/forgebook.mjs +283 -79
  28. package/dist/bin/forgebook/forgebook.mjs.map +1 -1
  29. package/dist/bin/forgebook/importers/storybook.d.ts +53 -0
  30. package/dist/bin/forgebook/importers/storybook.d.ts.map +1 -0
  31. package/dist/bin/forgebook/importers/storybook.js +318 -0
  32. package/dist/bin/forgebook/importers/storybook.js.map +1 -0
  33. package/dist/bin/forgebook/initCommands.d.mts +9 -0
  34. package/dist/bin/forgebook/initCommands.d.mts.map +1 -0
  35. package/dist/bin/forgebook/initCommands.mjs +86 -0
  36. package/dist/bin/forgebook/initCommands.mjs.map +1 -0
  37. package/dist/bin/forgebook/initConfig.d.ts +22 -0
  38. package/dist/bin/forgebook/initConfig.d.ts.map +1 -0
  39. package/dist/bin/forgebook/initConfig.js +51 -0
  40. package/dist/bin/forgebook/initConfig.js.map +1 -0
  41. package/dist/bin/forgebook/mcpTools.d.ts +38 -0
  42. package/dist/bin/forgebook/mcpTools.d.ts.map +1 -0
  43. package/dist/bin/forgebook/mcpTools.js +212 -0
  44. package/dist/bin/forgebook/mcpTools.js.map +1 -0
  45. package/dist/bin/forgebook/newStories.d.ts +27 -0
  46. package/dist/bin/forgebook/newStories.d.ts.map +1 -0
  47. package/dist/bin/forgebook/newStories.js +109 -0
  48. package/dist/bin/forgebook/newStories.js.map +1 -0
  49. package/dist/bin/forgebook/newStoriesFile.d.ts +18 -0
  50. package/dist/bin/forgebook/newStoriesFile.d.ts.map +1 -0
  51. package/dist/bin/forgebook/newStoriesFile.js +58 -0
  52. package/dist/bin/forgebook/newStoriesFile.js.map +1 -0
  53. package/dist/bin/forgebook/storyCheckRun.d.ts +39 -0
  54. package/dist/bin/forgebook/storyCheckRun.d.ts.map +1 -0
  55. package/dist/bin/forgebook/storyCheckRun.js +177 -0
  56. package/dist/bin/forgebook/storyCheckRun.js.map +1 -0
  57. package/dist/bin/forgebook-docs/catalogueDocs.d.ts +24 -0
  58. package/dist/bin/forgebook-docs/catalogueDocs.d.ts.map +1 -0
  59. package/dist/bin/forgebook-docs/catalogueDocs.js +71 -0
  60. package/dist/bin/forgebook-docs/catalogueDocs.js.map +1 -0
  61. package/dist/bin/forgebook-docs/catalogueDocs.types.d.ts +8 -0
  62. package/dist/bin/forgebook-docs/catalogueDocs.types.d.ts.map +1 -1
  63. package/dist/bin/forgebook-docs/catalogueMarkdown.d.ts +3 -1
  64. package/dist/bin/forgebook-docs/catalogueMarkdown.d.ts.map +1 -1
  65. package/dist/bin/forgebook-docs/catalogueMarkdown.js +62 -42
  66. package/dist/bin/forgebook-docs/catalogueMarkdown.js.map +1 -1
  67. package/dist/bin/forgebook-docs/catalogueOptions.d.ts +39 -0
  68. package/dist/bin/forgebook-docs/catalogueOptions.d.ts.map +1 -0
  69. package/dist/bin/forgebook-docs/catalogueOptions.js +76 -0
  70. package/dist/bin/forgebook-docs/catalogueOptions.js.map +1 -0
  71. package/dist/bin/forgebook-docs/collectDocs.d.ts +3 -1
  72. package/dist/bin/forgebook-docs/collectDocs.d.ts.map +1 -1
  73. package/dist/bin/forgebook-docs/collectDocs.js +37 -13
  74. package/dist/bin/forgebook-docs/collectDocs.js.map +1 -1
  75. package/dist/bin/forgebook-docs/forgebook-docs.mjs +17 -80
  76. package/dist/bin/forgebook-docs/forgebook-docs.mjs.map +1 -1
  77. package/dist/bin/forgebook-docs/llmsText.d.ts +24 -0
  78. package/dist/bin/forgebook-docs/llmsText.d.ts.map +1 -0
  79. package/dist/bin/forgebook-docs/llmsText.js +33 -0
  80. package/dist/bin/forgebook-docs/llmsText.js.map +1 -0
  81. package/dist/bin/forgebook-docs/sourceId.d.ts +9 -0
  82. package/dist/bin/forgebook-docs/sourceId.d.ts.map +1 -0
  83. package/dist/bin/forgebook-docs/sourceId.js +45 -0
  84. package/dist/bin/forgebook-docs/sourceId.js.map +1 -0
  85. package/dist/bin/frameworkDocs.d.ts +10 -0
  86. package/dist/bin/frameworkDocs.d.ts.map +1 -0
  87. package/dist/bin/frameworkDocs.js +43 -0
  88. package/dist/bin/frameworkDocs.js.map +1 -0
  89. package/dist/src/argTypes.d.ts +23 -0
  90. package/dist/src/argTypes.d.ts.map +1 -1
  91. package/dist/src/argTypes.js +27 -0
  92. package/dist/src/argTypes.js.map +1 -1
  93. package/dist/src/catalogue.d.ts +70 -3
  94. package/dist/src/catalogue.d.ts.map +1 -1
  95. package/dist/src/catalogue.js +85 -3
  96. package/dist/src/catalogue.js.map +1 -1
  97. package/dist/src/controlKeys.d.ts +85 -0
  98. package/dist/src/controlKeys.d.ts.map +1 -0
  99. package/dist/src/controlKeys.js +118 -0
  100. package/dist/src/controlKeys.js.map +1 -0
  101. package/dist/src/frame/frame.css +33 -2
  102. package/dist/src/frame/frameView.d.ts +2 -2
  103. package/dist/src/frame/frameView.d.ts.map +1 -1
  104. package/dist/src/frame/frameView.js +7 -3
  105. package/dist/src/frame/frameView.js.map +1 -1
  106. package/dist/src/frame/mountFrame.d.ts.map +1 -1
  107. package/dist/src/frame/mountFrame.js +26 -2
  108. package/dist/src/frame/mountFrame.js.map +1 -1
  109. package/dist/src/frame/spillOutline.d.ts +10 -0
  110. package/dist/src/frame/spillOutline.d.ts.map +1 -0
  111. package/dist/src/frame/spillOutline.js +80 -0
  112. package/dist/src/frame/spillOutline.js.map +1 -0
  113. package/dist/src/liveErrors.d.ts +57 -0
  114. package/dist/src/liveErrors.d.ts.map +1 -0
  115. package/dist/src/liveErrors.js +52 -0
  116. package/dist/src/liveErrors.js.map +1 -0
  117. package/dist/src/messages.d.ts +12 -0
  118. package/dist/src/messages.d.ts.map +1 -1
  119. package/dist/src/messages.js +4 -0
  120. package/dist/src/messages.js.map +1 -1
  121. package/dist/src/namedViews.d.ts +80 -0
  122. package/dist/src/namedViews.d.ts.map +1 -0
  123. package/dist/src/namedViews.js +88 -0
  124. package/dist/src/namedViews.js.map +1 -0
  125. package/dist/src/shell/AppearanceMenu.d.ts +15 -0
  126. package/dist/src/shell/AppearanceMenu.d.ts.map +1 -0
  127. package/dist/src/shell/AppearanceMenu.js +28 -0
  128. package/dist/src/shell/AppearanceMenu.js.map +1 -0
  129. package/dist/src/shell/BoxWidth.d.ts +40 -0
  130. package/dist/src/shell/BoxWidth.d.ts.map +1 -0
  131. package/dist/src/shell/BoxWidth.js +56 -0
  132. package/dist/src/shell/BoxWidth.js.map +1 -0
  133. package/dist/src/shell/ComponentPage.d.ts +17 -1
  134. package/dist/src/shell/ComponentPage.d.ts.map +1 -1
  135. package/dist/src/shell/ComponentPage.js +19 -54
  136. package/dist/src/shell/ComponentPage.js.map +1 -1
  137. package/dist/src/shell/ControlKeyField.d.ts +21 -0
  138. package/dist/src/shell/ControlKeyField.d.ts.map +1 -0
  139. package/dist/src/shell/ControlKeyField.js +46 -0
  140. package/dist/src/shell/ControlKeyField.js.map +1 -0
  141. package/dist/src/shell/ControlRow.d.ts +31 -0
  142. package/dist/src/shell/ControlRow.d.ts.map +1 -0
  143. package/dist/src/shell/ControlRow.js +27 -0
  144. package/dist/src/shell/ControlRow.js.map +1 -0
  145. package/dist/src/shell/Example.d.ts +58 -0
  146. package/dist/src/shell/Example.d.ts.map +1 -0
  147. package/dist/src/shell/Example.js +89 -0
  148. package/dist/src/shell/Example.js.map +1 -0
  149. package/dist/src/shell/NamedViews.d.ts +23 -0
  150. package/dist/src/shell/NamedViews.d.ts.map +1 -0
  151. package/dist/src/shell/NamedViews.js +49 -0
  152. package/dist/src/shell/NamedViews.js.map +1 -0
  153. package/dist/src/shell/PinnedControl.d.ts +25 -0
  154. package/dist/src/shell/PinnedControl.d.ts.map +1 -0
  155. package/dist/src/shell/PinnedControl.js +81 -0
  156. package/dist/src/shell/PinnedControl.js.map +1 -0
  157. package/dist/src/shell/PropsTab.d.ts +5 -2
  158. package/dist/src/shell/PropsTab.d.ts.map +1 -1
  159. package/dist/src/shell/PropsTab.js +12 -15
  160. package/dist/src/shell/PropsTab.js.map +1 -1
  161. package/dist/src/shell/Shell.d.ts.map +1 -1
  162. package/dist/src/shell/Shell.js +27 -2
  163. package/dist/src/shell/Shell.js.map +1 -1
  164. package/dist/src/shell/Sidebar.d.ts +11 -9
  165. package/dist/src/shell/Sidebar.d.ts.map +1 -1
  166. package/dist/src/shell/Sidebar.js +48 -42
  167. package/dist/src/shell/Sidebar.js.map +1 -1
  168. package/dist/src/shell/SidebarEntries.d.ts +50 -0
  169. package/dist/src/shell/SidebarEntries.d.ts.map +1 -0
  170. package/dist/src/shell/SidebarEntries.js +51 -0
  171. package/dist/src/shell/SidebarEntries.js.map +1 -0
  172. package/dist/src/shell/Stage.d.ts.map +1 -1
  173. package/dist/src/shell/Stage.js +19 -2
  174. package/dist/src/shell/Stage.js.map +1 -1
  175. package/dist/src/shell/Toolbar.d.ts +7 -3
  176. package/dist/src/shell/Toolbar.d.ts.map +1 -1
  177. package/dist/src/shell/Toolbar.js +38 -68
  178. package/dist/src/shell/Toolbar.js.map +1 -1
  179. package/dist/src/shell/ToolbarControl.d.ts +47 -0
  180. package/dist/src/shell/ToolbarControl.d.ts.map +1 -0
  181. package/dist/src/shell/ToolbarControl.js +150 -0
  182. package/dist/src/shell/ToolbarControl.js.map +1 -0
  183. package/dist/src/shell/UsedIn.d.ts +38 -0
  184. package/dist/src/shell/UsedIn.d.ts.map +1 -0
  185. package/dist/src/shell/UsedIn.js +77 -0
  186. package/dist/src/shell/UsedIn.js.map +1 -0
  187. package/dist/src/shell/ViewMenu.d.ts +37 -0
  188. package/dist/src/shell/ViewMenu.d.ts.map +1 -0
  189. package/dist/src/shell/ViewMenu.js +216 -0
  190. package/dist/src/shell/ViewMenu.js.map +1 -0
  191. package/dist/src/shell/controlCycle.d.ts +28 -0
  192. package/dist/src/shell/controlCycle.d.ts.map +1 -0
  193. package/dist/src/shell/controlCycle.js +51 -0
  194. package/dist/src/shell/controlCycle.js.map +1 -0
  195. package/dist/src/shell/dockTabs.d.ts +3 -0
  196. package/dist/src/shell/dockTabs.d.ts.map +1 -1
  197. package/dist/src/shell/dockTabs.js +1 -1
  198. package/dist/src/shell/dockTabs.js.map +1 -1
  199. package/dist/src/shell/icons.d.ts +6 -0
  200. package/dist/src/shell/icons.d.ts.map +1 -1
  201. package/dist/src/shell/icons.js +7 -1
  202. package/dist/src/shell/icons.js.map +1 -1
  203. package/dist/src/shell/keyboard.d.ts +2 -1
  204. package/dist/src/shell/keyboard.d.ts.map +1 -1
  205. package/dist/src/shell/keyboard.js +5 -2
  206. package/dist/src/shell/keyboard.js.map +1 -1
  207. package/dist/src/shell/shell.css +826 -243
  208. package/dist/src/shell/strings.d.ts +45 -0
  209. package/dist/src/shell/strings.d.ts.map +1 -1
  210. package/dist/src/shell/strings.js +45 -0
  211. package/dist/src/shell/strings.js.map +1 -1
  212. package/dist/src/shell/useAppearance.d.ts +17 -0
  213. package/dist/src/shell/useAppearance.d.ts.map +1 -0
  214. package/dist/src/shell/useAppearance.js +36 -0
  215. package/dist/src/shell/useAppearance.js.map +1 -0
  216. package/dist/src/shell/useControlKeys.d.ts +23 -0
  217. package/dist/src/shell/useControlKeys.d.ts.map +1 -0
  218. package/dist/src/shell/useControlKeys.js +44 -0
  219. package/dist/src/shell/useControlKeys.js.map +1 -0
  220. package/dist/src/shell/useFold.d.ts +27 -0
  221. package/dist/src/shell/useFold.d.ts.map +1 -0
  222. package/dist/src/shell/useFold.js +87 -0
  223. package/dist/src/shell/useFold.js.map +1 -0
  224. package/dist/src/shell/useFrameMessages.d.ts +2 -0
  225. package/dist/src/shell/useFrameMessages.d.ts.map +1 -1
  226. package/dist/src/shell/useFrameMessages.js +3 -0
  227. package/dist/src/shell/useFrameMessages.js.map +1 -1
  228. package/dist/src/shell/useFullPage.d.ts +45 -0
  229. package/dist/src/shell/useFullPage.d.ts.map +1 -0
  230. package/dist/src/shell/useFullPage.js +149 -0
  231. package/dist/src/shell/useFullPage.js.map +1 -0
  232. package/dist/src/shell/usePopover.d.ts +17 -3
  233. package/dist/src/shell/usePopover.d.ts.map +1 -1
  234. package/dist/src/shell/usePopover.js +65 -4
  235. package/dist/src/shell/usePopover.js.map +1 -1
  236. package/dist/src/shell/useStored.d.ts +13 -2
  237. package/dist/src/shell/useStored.d.ts.map +1 -1
  238. package/dist/src/shell/useStored.js +1 -1
  239. package/dist/src/shell/useStored.js.map +1 -1
  240. package/dist/src/shell/useToolbarLayout.d.ts +39 -0
  241. package/dist/src/shell/useToolbarLayout.d.ts.map +1 -0
  242. package/dist/src/shell/useToolbarLayout.js +58 -0
  243. package/dist/src/shell/useToolbarLayout.js.map +1 -0
  244. package/dist/src/shell/useToolbarOverflow.d.ts +31 -0
  245. package/dist/src/shell/useToolbarOverflow.d.ts.map +1 -0
  246. package/dist/src/shell/useToolbarOverflow.js +62 -0
  247. package/dist/src/shell/useToolbarOverflow.js.map +1 -0
  248. package/dist/src/shell/useWorstCase.d.ts +46 -0
  249. package/dist/src/shell/useWorstCase.d.ts.map +1 -0
  250. package/dist/src/shell/useWorstCase.js +42 -0
  251. package/dist/src/shell/useWorstCase.js.map +1 -0
  252. package/dist/src/shell/worstArgs.d.ts +42 -0
  253. package/dist/src/shell/worstArgs.d.ts.map +1 -0
  254. package/dist/src/shell/worstArgs.js +47 -0
  255. package/dist/src/shell/worstArgs.js.map +1 -0
  256. package/dist/src/spills.d.ts +31 -0
  257. package/dist/src/spills.d.ts.map +1 -0
  258. package/dist/src/spills.js +65 -0
  259. package/dist/src/spills.js.map +1 -0
  260. package/dist/src/storyCheck.d.ts +105 -0
  261. package/dist/src/storyCheck.d.ts.map +1 -0
  262. package/dist/src/storyCheck.js +63 -0
  263. package/dist/src/storyCheck.js.map +1 -0
  264. package/dist/src/switches.d.ts +16 -4
  265. package/dist/src/switches.d.ts.map +1 -1
  266. package/dist/src/switches.js +30 -5
  267. package/dist/src/switches.js.map +1 -1
  268. package/dist/src/toolbarLayout.d.ts +119 -0
  269. package/dist/src/toolbarLayout.d.ts.map +1 -0
  270. package/dist/src/toolbarLayout.js +155 -0
  271. package/dist/src/toolbarLayout.js.map +1 -0
  272. package/dist/src/usedIn.d.ts +60 -0
  273. package/dist/src/usedIn.d.ts.map +1 -0
  274. package/dist/src/usedIn.js +92 -0
  275. package/dist/src/usedIn.js.map +1 -0
  276. package/dist/src/viewState.d.ts +15 -10
  277. package/dist/src/viewState.d.ts.map +1 -1
  278. package/dist/src/viewState.js +35 -18
  279. package/dist/src/viewState.js.map +1 -1
  280. package/dist/src/viewWords.d.ts +26 -0
  281. package/dist/src/viewWords.d.ts.map +1 -0
  282. package/dist/src/viewWords.js +29 -0
  283. package/dist/src/viewWords.js.map +1 -0
  284. package/dist/src/vite/adapter.d.ts +13 -4
  285. package/dist/src/vite/adapter.d.ts.map +1 -1
  286. package/dist/src/vite/adapter.js +4 -2
  287. package/dist/src/vite/adapter.js.map +1 -1
  288. package/dist/src/vite/agent.types.d.ts +120 -0
  289. package/dist/src/vite/agent.types.d.ts.map +1 -0
  290. package/dist/src/vite/agent.types.js +1 -0
  291. package/dist/src/vite/agent.types.js.map +1 -0
  292. package/dist/src/vite/agentApi.d.ts +106 -0
  293. package/dist/src/vite/agentApi.d.ts.map +1 -0
  294. package/dist/src/vite/agentApi.js +216 -0
  295. package/dist/src/vite/agentApi.js.map +1 -0
  296. package/dist/src/vite/agentRoutes.d.ts +50 -0
  297. package/dist/src/vite/agentRoutes.d.ts.map +1 -0
  298. package/dist/src/vite/agentRoutes.js +155 -0
  299. package/dist/src/vite/agentRoutes.js.map +1 -0
  300. package/dist/src/vite/configFile.d.ts +2 -1
  301. package/dist/src/vite/configFile.d.ts.map +1 -1
  302. package/dist/src/vite/configFile.js +29 -11
  303. package/dist/src/vite/configFile.js.map +1 -1
  304. package/dist/src/vite/docsExtractor.d.ts +26 -2
  305. package/dist/src/vite/docsExtractor.d.ts.map +1 -1
  306. package/dist/src/vite/docsExtractor.js +12 -9
  307. package/dist/src/vite/docsExtractor.js.map +1 -1
  308. package/dist/src/vite/docsWorker.js +18 -2
  309. package/dist/src/vite/docsWorker.js.map +1 -1
  310. package/dist/src/vite/forgebookPlugin.d.ts.map +1 -1
  311. package/dist/src/vite/forgebookPlugin.js +116 -16
  312. package/dist/src/vite/forgebookPlugin.js.map +1 -1
  313. package/dist/src/vite/indexStoryFile.d.ts +14 -0
  314. package/dist/src/vite/indexStoryFile.d.ts.map +1 -1
  315. package/dist/src/vite/indexStoryFile.js +13 -4
  316. package/dist/src/vite/indexStoryFile.js.map +1 -1
  317. package/dist/src/vite/mcpProtocol.d.ts +82 -0
  318. package/dist/src/vite/mcpProtocol.d.ts.map +1 -0
  319. package/dist/src/vite/mcpProtocol.js +184 -0
  320. package/dist/src/vite/mcpProtocol.js.map +1 -0
  321. package/dist/src/vite/pages.d.ts +12 -0
  322. package/dist/src/vite/pages.d.ts.map +1 -1
  323. package/dist/src/vite/pages.js +21 -0
  324. package/dist/src/vite/pages.js.map +1 -1
  325. package/dist/src/vite/storyFilesModule.d.ts +28 -1
  326. package/dist/src/vite/storyFilesModule.d.ts.map +1 -1
  327. package/dist/src/vite/storyFilesModule.js +34 -14
  328. package/dist/src/vite/storyFilesModule.js.map +1 -1
  329. package/dist/src/vite/usageGraph.d.ts +45 -0
  330. package/dist/src/vite/usageGraph.d.ts.map +1 -0
  331. package/dist/src/vite/usageGraph.js +246 -0
  332. package/dist/src/vite/usageGraph.js.map +1 -0
  333. package/dist/src/vite/usageModule.d.ts +33 -0
  334. package/dist/src/vite/usageModule.d.ts.map +1 -0
  335. package/dist/src/vite/usageModule.js +135 -0
  336. package/dist/src/vite/usageModule.js.map +1 -0
  337. package/dist/src/worstCase.d.ts +16 -0
  338. package/dist/src/worstCase.d.ts.map +1 -0
  339. package/dist/src/worstCase.js +16 -0
  340. package/dist/src/worstCase.js.map +1 -0
  341. package/package.json +18 -2
  342. package/dist/src/shell/SchemeSwitches.d.ts +0 -24
  343. package/dist/src/shell/SchemeSwitches.d.ts.map +0 -1
  344. package/dist/src/shell/SchemeSwitches.js +0 -36
  345. package/dist/src/shell/SchemeSwitches.js.map +0 -1
@@ -0,0 +1,212 @@
1
+ /**
2
+ * The tools `forgebook mcp` offers agents, each answered as the command of the same name answers: `list_stories`,
3
+ * `get_story`, `story_address`, `new_stories`, `check_story`, `recent_errors` and `story_shot`.
4
+ *
5
+ * @module
6
+ */
7
+ import { mkdtempSync, readFileSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+ import { filteredStories, isStoriesDocument } from "../../src/vite/agentApi.js";
11
+ import { askErrors } from "./errorsRun.js";
12
+ /** The schema of the view argument, shared by the tools. */
13
+ const VIEW = {
14
+ type: "string",
15
+ description: "The view the links open in, as the catalogue's address writes it (theme=dark&lang=it); none for the default."
16
+ };
17
+ /** A text argument, or none. */
18
+ const textOf = (args, name) => {
19
+ const value = args[name];
20
+ return typeof value === "string" && value !== "" ? value : undefined;
21
+ };
22
+ /** An answer as a tool's result: a failure when the catalogue did not answer 200. */
23
+ const resultOf = (answer) => ({
24
+ structured: answer.body,
25
+ isError: answer.status !== 200
26
+ });
27
+ /**
28
+ * The tools.
29
+ *
30
+ * @param reach - what they reach the catalogue through.
31
+ */
32
+ export const catalogueTools = ({ ask, writeNew, check, shot }) => [
33
+ {
34
+ name: "list_stories",
35
+ description: "List the catalogue's components and stories, with each story's id and the links that open it, and the problems the story index found. Filter by source id or by text in a component's title.",
36
+ inputSchema: {
37
+ type: "object",
38
+ properties: {
39
+ source: { type: "string", description: "Only this source's stories (its id)." },
40
+ component: { type: "string", description: "Only components whose title holds this text, any case." },
41
+ usedIn: {
42
+ type: "boolean",
43
+ description: "Add each component's usedIn: the components whose stories use it, directly or through another. Reads the package's import graph, so the first call takes longer."
44
+ },
45
+ view: VIEW
46
+ },
47
+ additionalProperties: false
48
+ },
49
+ call: async (args) => {
50
+ const answer = await ask("stories", new URLSearchParams({ view: textOf(args, "view") ?? "", usedIn: String(args["usedIn"] === true) }));
51
+ if (answer.status !== 200 || !isStoriesDocument(answer.body))
52
+ return resultOf(answer);
53
+ const filter = { source: textOf(args, "source"), component: textOf(args, "component") };
54
+ return { structured: filteredStories(answer.body, filter), isError: false };
55
+ }
56
+ },
57
+ {
58
+ name: "get_story",
59
+ description: "One story in detail: its args as the catalogue renders it, its component's props (types, defaults, descriptions), the components whose stories use it (usedIn), its links in the view asked for, and what failed while reading it.",
60
+ inputSchema: {
61
+ type: "object",
62
+ properties: {
63
+ id: { type: "string", description: "The story's id, as list_stories gives it." },
64
+ view: VIEW
65
+ },
66
+ required: ["id"],
67
+ additionalProperties: false
68
+ },
69
+ call: async (args) => resultOf(await ask("story", new URLSearchParams({ id: textOf(args, "id") ?? "", view: textOf(args, "view") ?? "" })))
70
+ },
71
+ {
72
+ name: "story_address",
73
+ description: "The links that open a story in the catalogue and in its frame alone, in the view asked for: give them to a person to look at what you describe.",
74
+ inputSchema: {
75
+ type: "object",
76
+ properties: {
77
+ id: { type: "string", description: "The story's id, as list_stories gives it." },
78
+ view: VIEW
79
+ },
80
+ required: ["id"],
81
+ additionalProperties: false
82
+ },
83
+ call: async (args) => {
84
+ const id = textOf(args, "id") ?? "";
85
+ const answer = await ask("stories", new URLSearchParams({ view: textOf(args, "view") ?? "" }));
86
+ if (answer.status !== 200 || !isStoriesDocument(answer.body))
87
+ return resultOf(answer);
88
+ const story = answer.body.components
89
+ .flatMap((component) => component.stories)
90
+ .find((each) => each.id === id);
91
+ return story === undefined
92
+ ? { structured: { error: `No story "${id}"` }, isError: true }
93
+ : { structured: { id, links: story.links }, isError: false };
94
+ }
95
+ },
96
+ {
97
+ name: "new_stories",
98
+ description: "Write a component's first stories from its typed props (the main story with its required props, one story per value of its first choice prop, the worst case) and answer the file's text and where it would go; writes nothing.",
99
+ inputSchema: {
100
+ type: "object",
101
+ properties: {
102
+ file: {
103
+ type: "string",
104
+ description: "The component's file, relative to the catalogue's folder or absolute."
105
+ },
106
+ export: { type: "string", description: "The component to read, when the file exports several." }
107
+ },
108
+ required: ["file"],
109
+ additionalProperties: false
110
+ },
111
+ call: async (args) => {
112
+ try {
113
+ const written = await writeNew(textOf(args, "file") ?? "", textOf(args, "export"));
114
+ return { structured: { file: written.file, text: written.text }, isError: false };
115
+ }
116
+ catch (error) {
117
+ return {
118
+ structured: { error: error instanceof Error ? error.message : String(error) },
119
+ isError: true
120
+ };
121
+ }
122
+ }
123
+ },
124
+ {
125
+ name: "check_story",
126
+ description: "Run the catalogue's checks on a story in a browser, as its tests do: accessibility (axe), elements spilling out of their parents, overlays past the frame, the page's errors (a failed play among them), a story that could not be shown. Give a component's id to check all its stories. Needs @forgebook/testing and Playwright in the project.",
127
+ inputSchema: {
128
+ type: "object",
129
+ properties: {
130
+ id: { type: "string", description: "A story's id, or a component's for its listed stories." },
131
+ views: {
132
+ type: "array",
133
+ items: { type: "string" },
134
+ description: "The views to check in, each as the catalogue's address writes it (theme=dark&width=360); the default view when none."
135
+ },
136
+ allVariants: {
137
+ type: "boolean",
138
+ description: "Check every variant the catalogue's browser tests check."
139
+ }
140
+ },
141
+ required: ["id"],
142
+ additionalProperties: false
143
+ },
144
+ call: async (args) => {
145
+ const views = Array.isArray(args["views"])
146
+ ? args["views"].filter((view) => typeof view === "string")
147
+ : [];
148
+ const report = await check({
149
+ id: textOf(args, "id") ?? "",
150
+ views,
151
+ isAllVariants: args["allVariants"] === true
152
+ });
153
+ if (typeof report === "string")
154
+ return { structured: { error: report }, isError: true };
155
+ return { structured: report, isError: report.results.some((result) => result.problems.length > 0) };
156
+ }
157
+ },
158
+ {
159
+ name: "recent_errors",
160
+ description: "What the catalogue's open frames reported while you edited: stories that could not be shown and plays that failed, numbered, with the story index's problems. Give since (the last answer's last) to get only the new ones. Only frames open in a browser report; check_story checks a story without one.",
161
+ inputSchema: {
162
+ type: "object",
163
+ properties: {
164
+ since: { type: "number", description: "Only the errors after this number; every one kept when none." }
165
+ },
166
+ additionalProperties: false
167
+ },
168
+ call: async (args) => {
169
+ const since = typeof args["since"] === "number" ? args["since"] : 0;
170
+ const document = await askErrors(ask, since);
171
+ if (typeof document === "string")
172
+ return { structured: { error: document }, isError: true };
173
+ return { structured: document, isError: false };
174
+ }
175
+ },
176
+ {
177
+ name: "story_shot",
178
+ description: "Take a story's pictures in a browser, one per view, and look at them: the answer holds the pictures themselves, and the PNG files' paths. Views are written as the catalogue's address writes them (theme=dark&width=360) or as words (\"dark it 360\"). Needs @forgebook/testing and Playwright in the project.",
179
+ inputSchema: {
180
+ type: "object",
181
+ properties: {
182
+ id: { type: "string", description: "A story's id, or a component's for its listed stories." },
183
+ views: {
184
+ type: "array",
185
+ items: { type: "string" },
186
+ description: "The views to picture it in; the default view when none."
187
+ },
188
+ allVariants: {
189
+ type: "boolean",
190
+ description: "Picture every variant the catalogue's browser tests check."
191
+ }
192
+ },
193
+ required: ["id"],
194
+ additionalProperties: false
195
+ },
196
+ call: async (args) => {
197
+ const views = Array.isArray(args["views"])
198
+ ? args["views"].filter((view) => typeof view === "string")
199
+ : [];
200
+ const outDir = mkdtempSync(join(tmpdir(), "forgebook-shot-"));
201
+ const report = await shot({ id: textOf(args, "id") ?? "", views, isAllVariants: args["allVariants"] === true }, outDir);
202
+ if (typeof report === "string")
203
+ return { structured: { error: report }, isError: true };
204
+ const images = report.shots.map((each) => ({
205
+ data: readFileSync(each.file).toString("base64"),
206
+ mimeType: "image/png"
207
+ }));
208
+ return { structured: report, isError: false, images };
209
+ }
210
+ }
211
+ ];
212
+ //# sourceMappingURL=mcpTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcpTools.js","sourceRoot":"","sources":["../../../bin/forgebook/mcpTools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGhF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO3C,4DAA4D;AAC5D,MAAM,IAAI,GAAG;IACX,IAAI,EAAE,QAAQ;IACd,WAAW,EACT,8GAA8G;CACxG,CAAC;AAEX,gCAAgC;AAChC,MAAM,MAAM,GAAG,CAAC,IAAuC,EAAE,IAAY,EAAsB,EAAE;IAC3F,MAAM,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ACF,IAAI,OAAO,MAAM,KAAK,QAAQ;gBAAE,OAAO,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YACxF,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACzC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAChD,QAAQ,EAAE,WAAW;aACtB,CAAC,CAAC,CAAC;YACJ,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QACxD,CAAC;KACF;CACF,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The first stories of a component, written from its props as the docs extractor reads them (`forgebook new`): the
3
+ * meta, the main story with the required props filled, one story per value of its first choice prop, and the worst
4
+ * case. Args only, so the file is the same for any framework but its type import. Pure: docs in, text out.
5
+ *
6
+ * @module
7
+ */
8
+ import type { ComponentDocs } from "../../src/componentDocs.ts";
9
+ /** What the file is written from. */
10
+ export type NewStoriesInput = {
11
+ /** The component's docs (its props). */
12
+ readonly docs: ComponentDocs;
13
+ /** How the story file imports the component (`./Badge`). */
14
+ readonly importPath: string;
15
+ /** The meta's title (`Actions/Badge`). */
16
+ readonly title: string;
17
+ /** The module the story types come from (`@forgebook/react`). */
18
+ readonly typesModule: string;
19
+ };
20
+ /**
21
+ * The story file's text.
22
+ *
23
+ * @param input - the component's docs, its import, the title and the story types' module.
24
+ * @returns the file, ending with a newline.
25
+ */
26
+ export declare const newStories: (input: NewStoriesInput) => string;
27
+ //# sourceMappingURL=newStories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newStories.d.ts","sourceRoot":"","sources":["../../../bin/forgebook/newStories.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,4BAA4B,CAAC;AAG1E,qCAAqC;AACrC,MAAM,MAAM,eAAe,GAAG;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AA0DF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,eAAe,KAAG,MAyDnD,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { WORST_NUMBER, WORST_TEXT } from "../../src/worstCase.js";
2
+ /** A prop's name in words, for a text's value (`helperText` → `Helper text`). */
3
+ const words = (name) => {
4
+ const spaced = name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase();
5
+ return `${spaced.charAt(0).toUpperCase()}${spaced.slice(1)}`;
6
+ };
7
+ /** A name in PascalCase, letters and digits only (`md` → `Md`, `x-large` → `XLarge`). */
8
+ const pascal = (text) => text
9
+ .split(/[^A-Za-z0-9]+/)
10
+ .filter((part) => part !== "")
11
+ .map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
12
+ .join("");
13
+ /** A default written in TSDoc, as code: a number or a boolean as it is, a quoted string kept, a word quoted. */
14
+ const defaultCode = (text) => /^(-?\d+(\.\d+)?|true|false|null|"[^"]*"|'[^']*')$/.test(text)
15
+ ? text.replace(/^'(.*)'$/, '"$1"')
16
+ : JSON.stringify(text);
17
+ /** A required prop's value as code, from its kind; none for one the type checker must point at. */
18
+ const requiredCode = (prop) => {
19
+ if (prop.defaultValue !== undefined)
20
+ return defaultCode(prop.defaultValue);
21
+ if (prop.kind === "choice" && prop.choices?.[0] !== undefined)
22
+ return JSON.stringify(prop.choices[0]);
23
+ if (prop.kind === "text")
24
+ return JSON.stringify(words(prop.name));
25
+ if (prop.kind === "number")
26
+ return "0";
27
+ if (prop.kind === "toggle")
28
+ return "false";
29
+ if (prop.kind === "event")
30
+ return "() => undefined";
31
+ // an empty list is a safe start for any list prop (`readonly string[]`, `Array<Item>`)
32
+ if (/\[\]$|^(readonly\s+)?(Readonly)?Array<.*>$/.test(prop.type.trim()))
33
+ return "[]";
34
+ return undefined;
35
+ };
36
+ /** The widest a line of args gets before each arg goes on a line of its own. */
37
+ const LINE_WIDTH = 100;
38
+ /** One story's args as code: on one line when it fits, one arg per line otherwise. */
39
+ const argsCode = (args) => {
40
+ if (args.length === 0)
41
+ return "{}";
42
+ const pairs = args.map(([name, value]) => `${name}: ${value}`);
43
+ const line = `{ ${pairs.join(", ")} }`;
44
+ return line.length <= LINE_WIDTH ? line : `{\n${pairs.map((pair) => ` ${pair}`).join(",\n")}\n }`;
45
+ };
46
+ /** The required props' args, and the ones the type checker must point at, as comments. */
47
+ const requiredArgs = (props) => {
48
+ const args = [];
49
+ const todo = [];
50
+ for (const prop of props.filter((each) => each.isRequired)) {
51
+ const value = requiredCode(prop);
52
+ if (value === undefined)
53
+ todo.push(`${prop.name}: ${prop.type}`);
54
+ else
55
+ args.push([prop.name, value]);
56
+ }
57
+ return { args, todo };
58
+ };
59
+ /**
60
+ * The story file's text.
61
+ *
62
+ * @param input - the component's docs, its import, the title and the story types' module.
63
+ * @returns the file, ending with a newline.
64
+ */
65
+ export const newStories = (input) => {
66
+ const { docs } = input;
67
+ const name = docs.name;
68
+ const type = `Story<typeof ${name}>`;
69
+ const { args, todo } = requiredArgs(docs.props);
70
+ const todoLine = todo.length === 0 ? [] : [` // TODO: give ${todo.join(", ")}`];
71
+ const story = (exportName, summary, storyArgs, parameters) => [
72
+ `/** ${summary} */`,
73
+ `export const ${exportName}: ${type} = {`,
74
+ ...todoLine,
75
+ ` args: ${argsCode(storyArgs)}${parameters === undefined ? "" : ","}`,
76
+ ...(parameters === undefined ? [] : [` parameters: ${parameters}`]),
77
+ "};",
78
+ ""
79
+ ];
80
+ const choice = docs.props.find((prop) => prop.kind === "choice" && (prop.choices?.length ?? 0) > 1);
81
+ const choiceStories = (choice?.choices ?? []).flatMap((value) => story(`${pascal(choice?.name ?? "")}${pascal(String(value))}`, `With ${choice?.name} ${JSON.stringify(value)}.`, [...args.filter(([prop]) => prop !== choice?.name), [choice?.name ?? "", JSON.stringify(value)]]));
82
+ const worst = docs.props.flatMap((prop) => {
83
+ if (prop.kind === "text" || prop.canTakeText === true)
84
+ return [[prop.name, JSON.stringify(WORST_TEXT)]];
85
+ if (prop.kind === "number")
86
+ return [[prop.name, String(WORST_NUMBER)]];
87
+ return [];
88
+ });
89
+ const worstArgs = [...args.filter(([prop]) => !worst.some(([each]) => each === prop)), ...worst];
90
+ return [
91
+ "/**",
92
+ ` * The stories of ${name}, written by \`forgebook new\` from its props: complete them by hand.`,
93
+ " *",
94
+ " * @module",
95
+ " */",
96
+ `import type { Meta, Story } from ${JSON.stringify(input.typesModule)};`,
97
+ "",
98
+ `import { ${name} } from ${JSON.stringify(input.importPath)};`,
99
+ "",
100
+ `export default { title: ${JSON.stringify(input.title)}, component: ${name} } satisfies Meta<typeof ${name}>;`,
101
+ "",
102
+ ...story("Default", `${name} as most pages use it.`, args, "{ main: true }"),
103
+ ...choiceStories,
104
+ ...story("WorstCase", `Long texts and huge numbers, to see where ${name} breaks.`, worstArgs, '{ group: "worst-case" }')
105
+ ]
106
+ .join("\n")
107
+ .replace(/\n+$/, "\n");
108
+ };
109
+ //# sourceMappingURL=newStories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newStories.js","sourceRoot":"","sources":["../../../bin/forgebook/newStories.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAclE,iFAAiF;AACjF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC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AC,CAAC;QACvE,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC;IACjG,OAAO;QACL,KAAK;QACL,qBAAqB,IAAI,uEAAuE;QAChG,IAAI;QACJ,YAAY;QACZ,KAAK;QACL,oCAAoC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG;QACxE,EAAE;QACF,YAAY,IAAI,WAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG;QAC9D,EAAE;QACF,2BAA2B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,IAAI,4BAA4B,IAAI,IAAI;QAC9G,EAAE;QACF,GAAG,KAAK,CAAC,SAAS,EAAE,GAAG,IAAI,wBAAwB,EAAE,IAAI,EAAE,gBAAgB,CAAC;QAC5E,GAAG,aAAa;QAChB,GAAG,KAAK,CACN,WAAW,EACX,6CAA6C,IAAI,UAAU,EAC3D,SAAS,EACT,yBAAyB,CAC1B;KACF;SACE,IAAI,CAAC,IAAI,CAAC;SACV,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /** A component's first stories, ready to write. */
2
+ export type NewStoriesFile = {
3
+ /** Where they go: `<Component>.stories.tsx` beside the component. */
4
+ readonly file: string;
5
+ /** The file's text. */
6
+ readonly text: string;
7
+ };
8
+ /**
9
+ * A component's first stories.
10
+ *
11
+ * @param componentFile - the component's file, absolute.
12
+ * @param exportName - the export to read; the file's only component when none.
13
+ * @param framework - the framework the stories are written for (`react`).
14
+ * @throws a `ScriptError` when the file is in no package, the framework cannot read it, or it exports no single
15
+ * component.
16
+ */
17
+ export declare const newStoriesFile: (componentFile: string, exportName: string | undefined, framework: string) => Promise<NewStoriesFile>;
18
+ //# sourceMappingURL=newStoriesFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newStoriesFile.d.ts","sourceRoot":"","sources":["../../../bin/forgebook/newStoriesFile.ts"],"names":[],"mappings":"AAiBA,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG;IAC3B,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uBAAuB;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAUF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GACzB,eAAe,MAAM,EACrB,YAAY,MAAM,GAAG,SAAS,EAC9B,WAAW,MAAM,KAChB,OAAO,CAAC,cAAc,CAsBxB,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Where `forgebook new` writes a component's first stories and what they say: the component read from its file by the
3
+ * framework's docs module, the title from the stories file's path, the import beside it. Shared by the command and the
4
+ * MCP tool `new_stories`.
5
+ *
6
+ * @module
7
+ */
8
+ import { basename, dirname, join, relative } from "node:path";
9
+ import { findUp } from "@ensiria/cli-kit/files";
10
+ import { ScriptError } from "@ensiria/cli-kit/script";
11
+ import { autoTitle, patternBase } from "../../src/vite/autoTitle.js";
12
+ import { findConfigFile, loadConfigFile } from "../../src/vite/configFile.js";
13
+ import { frameworkDocsModule } from "../frameworkDocs.js";
14
+ import { newStories } from "./newStories.js";
15
+ /** The folder the title starts from: the catalogue's first stories pattern's, else `src` for a file under it. */
16
+ const titleBase = async (packageDir, storiesFile) => {
17
+ const config = findConfigFile(packageDir);
18
+ const [pattern] = config === undefined ? [] : (await loadConfigFile(config)).stories;
19
+ if (pattern !== undefined)
20
+ return patternBase(pattern).replace(/^\.\//, "");
21
+ return relative(packageDir, storiesFile).split("/")[0] === "src" ? "src" : "";
22
+ };
23
+ /**
24
+ * A component's first stories.
25
+ *
26
+ * @param componentFile - the component's file, absolute.
27
+ * @param exportName - the export to read; the file's only component when none.
28
+ * @param framework - the framework the stories are written for (`react`).
29
+ * @throws a `ScriptError` when the file is in no package, the framework cannot read it, or it exports no single
30
+ * component.
31
+ */
32
+ export const newStoriesFile = async (componentFile, exportName, framework) => {
33
+ const manifest = findUp("package.json", dirname(componentFile));
34
+ if (manifest === undefined)
35
+ throw new ScriptError(`${componentFile} is in no package`);
36
+ const packageDir = dirname(manifest);
37
+ const docsModule = await frameworkDocsModule(packageDir, framework);
38
+ if (docsModule.extractFileComponent === undefined)
39
+ throw new ScriptError(`@forgebook/${framework} cannot read a component from its file yet`, {
40
+ hint: `Update @forgebook/${framework}`
41
+ });
42
+ const component = docsModule.extractFileComponent(componentFile, exportName);
43
+ if (typeof component === "string")
44
+ throw new ScriptError(component);
45
+ if (!("file" in component))
46
+ throw new ScriptError(`${componentFile} exports no component`);
47
+ const name = component.docs.name;
48
+ const file = join(dirname(componentFile), `${name}.stories.tsx`);
49
+ const title = autoTitle(await titleBase(packageDir, file), relative(packageDir, file)) ?? name;
50
+ const text = newStories({
51
+ docs: component.docs,
52
+ importPath: `./${basename(componentFile).replace(/\.[cm]?[jt]sx?$/, "")}`,
53
+ title,
54
+ typesModule: docsModule.storyTypesModule ?? `@forgebook/${framework}`
55
+ });
56
+ return { file, text };
57
+ };
58
+ //# sourceMappingURL=newStoriesFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newStoriesFile.js","sourceRoot":"","sources":["../../../bin/forgebook/newStoriesFile.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;A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SAAS,CAAC,CAAC;IACpE,IAAI,UAAU,CAAC,oBAAoB,KAAK,SAAS;QAC/C,MAAM,IAAI,WAAW,CAAC,cAAc,SAAS,4CAA4C,EAAE;YACzF,IAAI,EAAE,qBAAqB,SAAS,EAAE;SACvC,CAAC,CAAC;IACL,MAAM,SAAS,GAAG,UAAU,CAAC,oBAAoB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAC7E,IAAI,OAAO,SAAS,KAAK,QAAQ;QAAE,MAAM,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;IACpE,IAAI,CAAC,CAAC,MAAM,IAAI,SAAS,CAAC;QAAE,MAAM,IAAI,WAAW,CAAC,GAAG,aAAa,uBAAuB,CAAC,CAAC;IAC3F,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,GAAG,IAAI,cAAc,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;IAC/F,MAAM,IAAI,GAAG,UAAU,CAAC;QACtB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,UAAU,EAAE,KAAK,QAAQ,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,EAAE;QACzE,KAAK;QACL,WAAW,EAAE,UAAU,CAAC,gBAAgB,IAAI,cAAc,SAAS,EAAE;KACtE,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type StoryCheckReport, type StoryShotReport } from "../../src/storyCheck.ts";
2
+ import type { AgentStory, StoriesDocument } from "../../src/vite/agent.types.ts";
3
+ import type { ResolvedConfig } from "../../src/vite/configFile.ts";
4
+ /** What a run is asked: the id, the views and whether to run every variant. */
5
+ export type StoryCheckInput = {
6
+ /** A story's id, or a component's for its listed stories. */
7
+ readonly id: string;
8
+ /** The views, in the address's form or as words; none for the default view. */
9
+ readonly views: readonly string[];
10
+ /** Run every variant the catalogue's browser tests check. */
11
+ readonly isAllVariants: boolean;
12
+ };
13
+ /**
14
+ * The stories an id names: the story itself, or a component's listed stories.
15
+ *
16
+ * @param document - the catalogue's stories.
17
+ * @param id - the id.
18
+ */
19
+ export declare const storiesNamed: (document: StoriesDocument, id: string) => AgentStory[];
20
+ /**
21
+ * Runs the catalogue's checks.
22
+ *
23
+ * @param config - the catalogue's configuration.
24
+ * @param url - where `forgebook dev` runs, when not at Vite's default address.
25
+ * @param input - the id, the views and whether to check every variant.
26
+ * @returns the report, or why the check could not run.
27
+ */
28
+ export declare const runStoryCheck: (config: ResolvedConfig, url: string | undefined, input: StoryCheckInput) => Promise<StoryCheckReport | string>;
29
+ /**
30
+ * Takes the stories' pictures.
31
+ *
32
+ * @param config - the catalogue's configuration.
33
+ * @param url - where `forgebook dev` runs, when not at Vite's default address.
34
+ * @param input - the id, the views and whether to picture every variant.
35
+ * @param outDir - the folder the pictures go in, absolute.
36
+ * @returns the pictures, or why they could not be taken.
37
+ */
38
+ export declare const runStoryShot: (config: ResolvedConfig, url: string | undefined, input: StoryCheckInput, outDir: string) => Promise<StoryShotReport | string>;
39
+ //# sourceMappingURL=storyCheckRun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storyCheckRun.d.ts","sourceRoot":"","sources":["../../../bin/forgebook/storyCheckRun.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAOnE,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,eAAe,EAAE,IAAI,MAAM,KAAG,UAAU,EAI9E,CAAC;AA8GF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,cAAc,EACtB,KAAK,MAAM,GAAG,SAAS,EACvB,OAAO,eAAe,KACrB,OAAO,CAAC,gBAAgB,GAAG,MAAM,CAQnC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,cAAc,EACtB,KAAK,MAAM,GAAG,SAAS,EACvB,OAAO,eAAe,EACtB,QAAQ,MAAM,KACb,OAAO,CAAC,eAAe,GAAG,MAAM,CAQlC,CAAC"}