@shware/workflow-ui 0.0.0-stage → 0.0.0

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 (363) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +180 -2
  3. package/dist/assets/iphone-17-pro-DzaacWSl.png +0 -0
  4. package/dist/assets/pixel-10-pro-back-7MDj1_lz.webp +0 -0
  5. package/dist/assets/pixel-10-pro-mask-Bi1deQ9Y.webp +0 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +673 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/config.d.mts +247 -0
  10. package/dist/config.d.mts.map +1 -0
  11. package/dist/config.mjs +27 -0
  12. package/dist/config.mjs.map +1 -0
  13. package/dist/index.d.mts +451 -0
  14. package/dist/index.d.mts.map +1 -0
  15. package/dist/index.mjs +2722 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/dist/postgres.d.mts +34 -0
  18. package/dist/postgres.d.mts.map +1 -0
  19. package/dist/postgres.mjs +313 -0
  20. package/dist/postgres.mjs.map +1 -0
  21. package/package.json +93 -3
  22. package/src/app/assets/devices/iphone-17-pro.png +0 -0
  23. package/src/app/assets/devices/pixel-10-pro-back.webp +0 -0
  24. package/src/app/assets/devices/pixel-10-pro-mask.webp +0 -0
  25. package/src/app/assets/flags/AC.svg +1 -0
  26. package/src/app/assets/flags/AD.svg +1 -0
  27. package/src/app/assets/flags/AE.svg +1 -0
  28. package/src/app/assets/flags/AF.svg +1 -0
  29. package/src/app/assets/flags/AG.svg +1 -0
  30. package/src/app/assets/flags/AI.svg +1 -0
  31. package/src/app/assets/flags/AL.svg +1 -0
  32. package/src/app/assets/flags/AM.svg +1 -0
  33. package/src/app/assets/flags/AO.svg +1 -0
  34. package/src/app/assets/flags/AQ.svg +1 -0
  35. package/src/app/assets/flags/AR.svg +1 -0
  36. package/src/app/assets/flags/AS.svg +1 -0
  37. package/src/app/assets/flags/AT.svg +1 -0
  38. package/src/app/assets/flags/AU.svg +1 -0
  39. package/src/app/assets/flags/AW.svg +1 -0
  40. package/src/app/assets/flags/AX.svg +1 -0
  41. package/src/app/assets/flags/AZ.svg +1 -0
  42. package/src/app/assets/flags/BA.svg +1 -0
  43. package/src/app/assets/flags/BB.svg +1 -0
  44. package/src/app/assets/flags/BD.svg +1 -0
  45. package/src/app/assets/flags/BE.svg +1 -0
  46. package/src/app/assets/flags/BF.svg +1 -0
  47. package/src/app/assets/flags/BG.svg +1 -0
  48. package/src/app/assets/flags/BH.svg +1 -0
  49. package/src/app/assets/flags/BI.svg +1 -0
  50. package/src/app/assets/flags/BJ.svg +1 -0
  51. package/src/app/assets/flags/BL.svg +1 -0
  52. package/src/app/assets/flags/BM.svg +1 -0
  53. package/src/app/assets/flags/BN.svg +1 -0
  54. package/src/app/assets/flags/BO.svg +1 -0
  55. package/src/app/assets/flags/BQ-BO.svg +1 -0
  56. package/src/app/assets/flags/BQ-SA.svg +1 -0
  57. package/src/app/assets/flags/BQ-SE.svg +1 -0
  58. package/src/app/assets/flags/BQ.svg +1 -0
  59. package/src/app/assets/flags/BR.svg +1 -0
  60. package/src/app/assets/flags/BS.svg +1 -0
  61. package/src/app/assets/flags/BT.svg +1 -0
  62. package/src/app/assets/flags/BV.svg +1 -0
  63. package/src/app/assets/flags/BW.svg +1 -0
  64. package/src/app/assets/flags/BY.svg +1 -0
  65. package/src/app/assets/flags/BZ.svg +1 -0
  66. package/src/app/assets/flags/CA.svg +1 -0
  67. package/src/app/assets/flags/CC.svg +1 -0
  68. package/src/app/assets/flags/CD.svg +1 -0
  69. package/src/app/assets/flags/CF.svg +1 -0
  70. package/src/app/assets/flags/CG.svg +1 -0
  71. package/src/app/assets/flags/CH.svg +1 -0
  72. package/src/app/assets/flags/CI.svg +1 -0
  73. package/src/app/assets/flags/CK.svg +1 -0
  74. package/src/app/assets/flags/CL.svg +1 -0
  75. package/src/app/assets/flags/CM.svg +1 -0
  76. package/src/app/assets/flags/CN.svg +1 -0
  77. package/src/app/assets/flags/CO.svg +1 -0
  78. package/src/app/assets/flags/CR.svg +1 -0
  79. package/src/app/assets/flags/CU.svg +1 -0
  80. package/src/app/assets/flags/CV.svg +1 -0
  81. package/src/app/assets/flags/CW.svg +1 -0
  82. package/src/app/assets/flags/CX.svg +1 -0
  83. package/src/app/assets/flags/CY.svg +1 -0
  84. package/src/app/assets/flags/CZ.svg +1 -0
  85. package/src/app/assets/flags/DE.svg +1 -0
  86. package/src/app/assets/flags/DJ.svg +1 -0
  87. package/src/app/assets/flags/DK.svg +1 -0
  88. package/src/app/assets/flags/DM.svg +1 -0
  89. package/src/app/assets/flags/DO.svg +1 -0
  90. package/src/app/assets/flags/DZ.svg +1 -0
  91. package/src/app/assets/flags/EC.svg +1 -0
  92. package/src/app/assets/flags/EE.svg +1 -0
  93. package/src/app/assets/flags/EG.svg +1 -0
  94. package/src/app/assets/flags/EH.svg +1 -0
  95. package/src/app/assets/flags/ER.svg +1 -0
  96. package/src/app/assets/flags/ES-CT.svg +1 -0
  97. package/src/app/assets/flags/ES.svg +1 -0
  98. package/src/app/assets/flags/ET.svg +1 -0
  99. package/src/app/assets/flags/EU.svg +1 -0
  100. package/src/app/assets/flags/FI.svg +1 -0
  101. package/src/app/assets/flags/FJ.svg +1 -0
  102. package/src/app/assets/flags/FK.svg +1 -0
  103. package/src/app/assets/flags/FM.svg +1 -0
  104. package/src/app/assets/flags/FO.svg +1 -0
  105. package/src/app/assets/flags/FR.svg +1 -0
  106. package/src/app/assets/flags/GA.svg +1 -0
  107. package/src/app/assets/flags/GB-ENG.svg +1 -0
  108. package/src/app/assets/flags/GB-NIR.svg +1 -0
  109. package/src/app/assets/flags/GB-SCT.svg +1 -0
  110. package/src/app/assets/flags/GB-WLS.svg +1 -0
  111. package/src/app/assets/flags/GB.svg +1 -0
  112. package/src/app/assets/flags/GD.svg +1 -0
  113. package/src/app/assets/flags/GE.svg +1 -0
  114. package/src/app/assets/flags/GF.svg +1 -0
  115. package/src/app/assets/flags/GG.svg +1 -0
  116. package/src/app/assets/flags/GH.svg +1 -0
  117. package/src/app/assets/flags/GI.svg +1 -0
  118. package/src/app/assets/flags/GL.svg +1 -0
  119. package/src/app/assets/flags/GM.svg +1 -0
  120. package/src/app/assets/flags/GN.svg +1 -0
  121. package/src/app/assets/flags/GP.svg +1 -0
  122. package/src/app/assets/flags/GQ.svg +1 -0
  123. package/src/app/assets/flags/GR.svg +1 -0
  124. package/src/app/assets/flags/GS.svg +1 -0
  125. package/src/app/assets/flags/GT.svg +1 -0
  126. package/src/app/assets/flags/GU.svg +1 -0
  127. package/src/app/assets/flags/GW.svg +1 -0
  128. package/src/app/assets/flags/GY.svg +1 -0
  129. package/src/app/assets/flags/HK.svg +1 -0
  130. package/src/app/assets/flags/HM.svg +1 -0
  131. package/src/app/assets/flags/HN.svg +1 -0
  132. package/src/app/assets/flags/HR.svg +1 -0
  133. package/src/app/assets/flags/HT.svg +1 -0
  134. package/src/app/assets/flags/HU.svg +1 -0
  135. package/src/app/assets/flags/IC.svg +1 -0
  136. package/src/app/assets/flags/ID.svg +1 -0
  137. package/src/app/assets/flags/IE.svg +1 -0
  138. package/src/app/assets/flags/IL.svg +1 -0
  139. package/src/app/assets/flags/IM.svg +1 -0
  140. package/src/app/assets/flags/IN.svg +1 -0
  141. package/src/app/assets/flags/IO.svg +1 -0
  142. package/src/app/assets/flags/IQ.svg +1 -0
  143. package/src/app/assets/flags/IR.svg +1 -0
  144. package/src/app/assets/flags/IS.svg +1 -0
  145. package/src/app/assets/flags/IT.svg +1 -0
  146. package/src/app/assets/flags/JE.svg +1 -0
  147. package/src/app/assets/flags/JM.svg +1 -0
  148. package/src/app/assets/flags/JO.svg +1 -0
  149. package/src/app/assets/flags/JP.svg +1 -0
  150. package/src/app/assets/flags/KE.svg +1 -0
  151. package/src/app/assets/flags/KG.svg +1 -0
  152. package/src/app/assets/flags/KH.svg +1 -0
  153. package/src/app/assets/flags/KI.svg +1 -0
  154. package/src/app/assets/flags/KM.svg +1 -0
  155. package/src/app/assets/flags/KN.svg +1 -0
  156. package/src/app/assets/flags/KP.svg +1 -0
  157. package/src/app/assets/flags/KR.svg +1 -0
  158. package/src/app/assets/flags/KW.svg +1 -0
  159. package/src/app/assets/flags/KY.svg +1 -0
  160. package/src/app/assets/flags/KZ.svg +1 -0
  161. package/src/app/assets/flags/LA.svg +1 -0
  162. package/src/app/assets/flags/LB.svg +1 -0
  163. package/src/app/assets/flags/LC.svg +1 -0
  164. package/src/app/assets/flags/LI.svg +1 -0
  165. package/src/app/assets/flags/LK.svg +1 -0
  166. package/src/app/assets/flags/LR.svg +1 -0
  167. package/src/app/assets/flags/LS.svg +1 -0
  168. package/src/app/assets/flags/LT.svg +1 -0
  169. package/src/app/assets/flags/LU.svg +1 -0
  170. package/src/app/assets/flags/LV.svg +1 -0
  171. package/src/app/assets/flags/LY.svg +1 -0
  172. package/src/app/assets/flags/MA.svg +1 -0
  173. package/src/app/assets/flags/MC.svg +1 -0
  174. package/src/app/assets/flags/MD.svg +1 -0
  175. package/src/app/assets/flags/ME.svg +1 -0
  176. package/src/app/assets/flags/MF.svg +1 -0
  177. package/src/app/assets/flags/MG.svg +1 -0
  178. package/src/app/assets/flags/MH.svg +1 -0
  179. package/src/app/assets/flags/MK.svg +1 -0
  180. package/src/app/assets/flags/ML.svg +1 -0
  181. package/src/app/assets/flags/MM.svg +1 -0
  182. package/src/app/assets/flags/MN.svg +1 -0
  183. package/src/app/assets/flags/MO.svg +1 -0
  184. package/src/app/assets/flags/MP.svg +1 -0
  185. package/src/app/assets/flags/MQ.svg +1 -0
  186. package/src/app/assets/flags/MR.svg +1 -0
  187. package/src/app/assets/flags/MS.svg +1 -0
  188. package/src/app/assets/flags/MT.svg +1 -0
  189. package/src/app/assets/flags/MU.svg +1 -0
  190. package/src/app/assets/flags/MV.svg +1 -0
  191. package/src/app/assets/flags/MW.svg +1 -0
  192. package/src/app/assets/flags/MX.svg +1 -0
  193. package/src/app/assets/flags/MY.svg +1 -0
  194. package/src/app/assets/flags/MZ.svg +1 -0
  195. package/src/app/assets/flags/NA.svg +1 -0
  196. package/src/app/assets/flags/NC.svg +1 -0
  197. package/src/app/assets/flags/NE.svg +1 -0
  198. package/src/app/assets/flags/NF.svg +1 -0
  199. package/src/app/assets/flags/NG.svg +1 -0
  200. package/src/app/assets/flags/NI.svg +1 -0
  201. package/src/app/assets/flags/NL.svg +1 -0
  202. package/src/app/assets/flags/NO.svg +1 -0
  203. package/src/app/assets/flags/NP.svg +1 -0
  204. package/src/app/assets/flags/NR.svg +1 -0
  205. package/src/app/assets/flags/NU.svg +1 -0
  206. package/src/app/assets/flags/NZ.svg +1 -0
  207. package/src/app/assets/flags/OM.svg +1 -0
  208. package/src/app/assets/flags/PA.svg +1 -0
  209. package/src/app/assets/flags/PE.svg +1 -0
  210. package/src/app/assets/flags/PF.svg +1 -0
  211. package/src/app/assets/flags/PG.svg +1 -0
  212. package/src/app/assets/flags/PH.svg +1 -0
  213. package/src/app/assets/flags/PK.svg +1 -0
  214. package/src/app/assets/flags/PL.svg +1 -0
  215. package/src/app/assets/flags/PM.svg +1 -0
  216. package/src/app/assets/flags/PN.svg +1 -0
  217. package/src/app/assets/flags/PR.svg +1 -0
  218. package/src/app/assets/flags/PS.svg +1 -0
  219. package/src/app/assets/flags/PT.svg +1 -0
  220. package/src/app/assets/flags/PW.svg +1 -0
  221. package/src/app/assets/flags/PY.svg +1 -0
  222. package/src/app/assets/flags/QA.svg +1 -0
  223. package/src/app/assets/flags/RE.svg +1 -0
  224. package/src/app/assets/flags/README.md +6 -0
  225. package/src/app/assets/flags/RO.svg +1 -0
  226. package/src/app/assets/flags/RS.svg +1 -0
  227. package/src/app/assets/flags/RU.svg +1 -0
  228. package/src/app/assets/flags/RW.svg +1 -0
  229. package/src/app/assets/flags/SA.svg +1 -0
  230. package/src/app/assets/flags/SB.svg +1 -0
  231. package/src/app/assets/flags/SC.svg +1 -0
  232. package/src/app/assets/flags/SD.svg +1 -0
  233. package/src/app/assets/flags/SE.svg +1 -0
  234. package/src/app/assets/flags/SG.svg +1 -0
  235. package/src/app/assets/flags/SH.svg +1 -0
  236. package/src/app/assets/flags/SI.svg +1 -0
  237. package/src/app/assets/flags/SJ.svg +1 -0
  238. package/src/app/assets/flags/SK.svg +1 -0
  239. package/src/app/assets/flags/SL.svg +1 -0
  240. package/src/app/assets/flags/SM.svg +1 -0
  241. package/src/app/assets/flags/SN.svg +1 -0
  242. package/src/app/assets/flags/SO.svg +1 -0
  243. package/src/app/assets/flags/SR.svg +1 -0
  244. package/src/app/assets/flags/SS.svg +1 -0
  245. package/src/app/assets/flags/ST.svg +1 -0
  246. package/src/app/assets/flags/SV.svg +1 -0
  247. package/src/app/assets/flags/SX.svg +1 -0
  248. package/src/app/assets/flags/SY.svg +1 -0
  249. package/src/app/assets/flags/SZ.svg +1 -0
  250. package/src/app/assets/flags/TA.svg +1 -0
  251. package/src/app/assets/flags/TC.svg +1 -0
  252. package/src/app/assets/flags/TD.svg +1 -0
  253. package/src/app/assets/flags/TF.svg +1 -0
  254. package/src/app/assets/flags/TG.svg +1 -0
  255. package/src/app/assets/flags/TH.svg +1 -0
  256. package/src/app/assets/flags/TJ.svg +1 -0
  257. package/src/app/assets/flags/TK.svg +1 -0
  258. package/src/app/assets/flags/TL.svg +1 -0
  259. package/src/app/assets/flags/TM.svg +1 -0
  260. package/src/app/assets/flags/TN.svg +1 -0
  261. package/src/app/assets/flags/TO.svg +1 -0
  262. package/src/app/assets/flags/TR.svg +1 -0
  263. package/src/app/assets/flags/TT.svg +1 -0
  264. package/src/app/assets/flags/TV.svg +1 -0
  265. package/src/app/assets/flags/TW.svg +1 -0
  266. package/src/app/assets/flags/TZ.svg +1 -0
  267. package/src/app/assets/flags/UA.svg +1 -0
  268. package/src/app/assets/flags/UG.svg +1 -0
  269. package/src/app/assets/flags/UM.svg +1 -0
  270. package/src/app/assets/flags/US.svg +1 -0
  271. package/src/app/assets/flags/UY.svg +1 -0
  272. package/src/app/assets/flags/UZ.svg +1 -0
  273. package/src/app/assets/flags/VA.svg +1 -0
  274. package/src/app/assets/flags/VC.svg +1 -0
  275. package/src/app/assets/flags/VE.svg +1 -0
  276. package/src/app/assets/flags/VG.svg +1 -0
  277. package/src/app/assets/flags/VI.svg +1 -0
  278. package/src/app/assets/flags/VN.svg +1 -0
  279. package/src/app/assets/flags/VU.svg +1 -0
  280. package/src/app/assets/flags/WF.svg +1 -0
  281. package/src/app/assets/flags/WS.svg +1 -0
  282. package/src/app/assets/flags/XA.svg +1 -0
  283. package/src/app/assets/flags/XC.svg +1 -0
  284. package/src/app/assets/flags/XK.svg +1 -0
  285. package/src/app/assets/flags/XO.svg +1 -0
  286. package/src/app/assets/flags/YE.svg +1 -0
  287. package/src/app/assets/flags/YT.svg +1 -0
  288. package/src/app/assets/flags/ZA.svg +1 -0
  289. package/src/app/assets/flags/ZM.svg +1 -0
  290. package/src/app/assets/flags/ZW.svg +1 -0
  291. package/src/app/email-preview.ts +46 -0
  292. package/src/app/index.css +203 -0
  293. package/src/app/index.html +12 -0
  294. package/src/app/integrations/i18n/react-i18next.d.ts +11 -0
  295. package/src/app/integrations/i18n/root-provider.tsx +62 -0
  296. package/src/app/integrations/tanstack-query/devtools.tsx +6 -0
  297. package/src/app/integrations/tanstack-query/root-provider.tsx +37 -0
  298. package/src/app/integrations/theme/root-provider.tsx +75 -0
  299. package/src/app/integrations/toast/toast-provider.tsx +46 -0
  300. package/src/app/locales/en-US/common.ts +268 -0
  301. package/src/app/locales/zh-CN/common.ts +263 -0
  302. package/src/app/main.tsx +40 -0
  303. package/src/app/page-chrome.tsx +79 -0
  304. package/src/app/router.tsx +40 -0
  305. package/src/app/routes/__root.tsx +293 -0
  306. package/src/app/routes/emails.tsx +199 -0
  307. package/src/app/routes/home.tsx +87 -0
  308. package/src/app/routes/index.ts +19 -0
  309. package/src/app/routes/metrics.tsx +541 -0
  310. package/src/app/routes/segment-overview.tsx +211 -0
  311. package/src/app/routes/segments.tsx +236 -0
  312. package/src/app/routes/settings.tsx +90 -0
  313. package/src/app/routes/workflows.tsx +348 -0
  314. package/src/app/studio.ts +16 -0
  315. package/src/app/svg.d.ts +17 -0
  316. package/src/app/virtual-config.d.ts +6 -0
  317. package/src/cli.ts +110 -0
  318. package/src/components/avatar.tsx +57 -0
  319. package/src/components/breadcrumb.tsx +49 -0
  320. package/src/components/button/index.tsx +86 -0
  321. package/src/components/channel-icon.ts +39 -0
  322. package/src/components/chat-markup.tsx +109 -0
  323. package/src/components/corner-shape.ts +13 -0
  324. package/src/components/date-range.tsx +181 -0
  325. package/src/components/discord-preview.tsx +165 -0
  326. package/src/components/dropdown/index.tsx +172 -0
  327. package/src/components/email-defaults.tsx +40 -0
  328. package/src/components/email-list.tsx +149 -0
  329. package/src/components/email-thumbnail.tsx +123 -0
  330. package/src/components/flag.tsx +40 -0
  331. package/src/components/input/index.tsx +40 -0
  332. package/src/components/input/search-input.tsx +24 -0
  333. package/src/components/layout.ts +403 -0
  334. package/src/components/menu/index.tsx +118 -0
  335. package/src/components/metric-card.tsx +321 -0
  336. package/src/components/modal/index.tsx +70 -0
  337. package/src/components/nav-drawer.tsx +84 -0
  338. package/src/components/node-inspector.tsx +242 -0
  339. package/src/components/profile-drawer.tsx +331 -0
  340. package/src/components/push-preview.tsx +470 -0
  341. package/src/components/push-thumbnail.tsx +78 -0
  342. package/src/components/segment-list.tsx +184 -0
  343. package/src/components/select/index.tsx +70 -0
  344. package/src/components/series-chart.tsx +120 -0
  345. package/src/components/slack-preview.tsx +223 -0
  346. package/src/components/sparkline.tsx +58 -0
  347. package/src/components/tabs/index.tsx +45 -0
  348. package/src/components/template-refs.ts +110 -0
  349. package/src/components/templates-page.tsx +601 -0
  350. package/src/components/textarea/index.tsx +37 -0
  351. package/src/components/thumbnail-window.tsx +65 -0
  352. package/src/components/workflow-canvas.tsx +503 -0
  353. package/src/components/workflow-list.tsx +231 -0
  354. package/src/config.ts +288 -0
  355. package/src/generate.ts +56 -0
  356. package/src/index.ts +35 -0
  357. package/src/postgres.ts +415 -0
  358. package/src/server/project.ts +290 -0
  359. package/src/server.ts +500 -0
  360. package/src/utils/cn.ts +6 -0
  361. package/src/utils/label.ts +12 -0
  362. package/src/utils/lookup.ts +11 -0
  363. package/src/utils/template-content.ts +213 -0
package/dist/cli.mjs ADDED
@@ -0,0 +1,673 @@
1
+ #!/usr/bin/env node
2
+ import { ConfigCompileError, compileConfig, formatEmailAddress, isConfig, isDiscordTemplate, isEmailTemplate, isPushTemplate, isSlackTemplate } from "@shware/workflow";
3
+ import { renderDrizzleSchema } from "@shware/workflow/store";
4
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
5
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
6
+ import { createServer, runnerImport, searchForWorkspaceRoot } from "vite";
7
+ import { fileURLToPath } from "node:url";
8
+ import tailwindcss from "@tailwindcss/vite";
9
+ import react from "@vitejs/plugin-react";
10
+ import svgr from "vite-plugin-svgr";
11
+ //#region src/server/project.ts
12
+ /** The modules a Vite server has evaluated for SSR — where registries are located by identity. */
13
+ function ssrModulesOf(server) {
14
+ return function* () {
15
+ for (const mod of server.moduleGraph.idToModuleMap.values()) {
16
+ const exports = mod.ssrModule;
17
+ if (mod.file !== null && exports !== null) yield [mod.file, exports];
18
+ }
19
+ };
20
+ }
21
+ /** Per channel: how to recognise its entries, the factory to name, the virtual module's field. */
22
+ const CHANNELS = {
23
+ email: {
24
+ is: isEmailTemplate,
25
+ factory: "emailTemplate",
26
+ field: "emails"
27
+ },
28
+ push: {
29
+ is: isPushTemplate,
30
+ factory: "pushTemplate",
31
+ field: "pushes"
32
+ },
33
+ discord: {
34
+ is: isDiscordTemplate,
35
+ factory: "discordTemplate",
36
+ field: "discords"
37
+ },
38
+ slack: {
39
+ is: isSlackTemplate,
40
+ factory: "slackTemplate",
41
+ field: "slacks"
42
+ }
43
+ };
44
+ /** A project the studio cannot read: the message says what to change. */
45
+ var StudioLoadError = class extends Error {};
46
+ /**
47
+ * The module that exports `registry`, by identity: the registry itself, or
48
+ * else an exported `{ email, push }` holding it (`export const registry =
49
+ * { email: {...}, push: {...} }` next to `t = templates(registry)`).
50
+ * workflow.config.ts itself is never a candidate: importing it would bring the
51
+ * whole config (and everything it imports) into the browser. Sorted by path,
52
+ * so the answer does not depend on load order.
53
+ */
54
+ function locate(channel, registry, modules, configPath) {
55
+ if (registry === void 0) return void 0;
56
+ const { is: isTemplate, factory } = CHANNELS[channel];
57
+ for (const [key, entry] of Object.entries(registry)) if (!isTemplate(entry)) throw new StudioLoadError(`templates.${channel}['${key}'] is not a ${factory}({...}) definition — every entry of the ${channel} registry must be one.`);
58
+ if (Object.keys(registry).length === 0) return void 0;
59
+ const sorted = [...modules()].filter(([file]) => file !== configPath).sort(([a], [b]) => a.localeCompare(b));
60
+ for (const [file, exports] of sorted) for (const [name, exported] of Object.entries(exports)) if (exported === registry) return {
61
+ file,
62
+ name
63
+ };
64
+ for (const [file, exports] of sorted) for (const [name, exported] of Object.entries(exports)) if (typeof exported === "object" && exported !== null && exported[channel] === registry) return {
65
+ file,
66
+ name,
67
+ property: channel
68
+ };
69
+ throw new StudioLoadError(`templates.${channel} is not exported from a module of its own. Export the registry (e.g. \`export const ${channel} = {...}\` in src/${channel}/index.ts, or \`export const registry = { email, push }\` in src/templates.ts) and import it into workflow.config.ts — the studio loads that module, never the config, into the browser.`);
70
+ }
71
+ function errorOf(error) {
72
+ return {
73
+ kind: error instanceof ConfigCompileError ? "compile" : "load",
74
+ message: error instanceof Error ? error.message : String(error)
75
+ };
76
+ }
77
+ function formatted(address) {
78
+ return address === void 0 ? void 0 : formatEmailAddress(address);
79
+ }
80
+ function failed(error, title) {
81
+ return {
82
+ payload: {
83
+ ...title !== void 0 ? { title } : {},
84
+ workflows: {},
85
+ segments: [],
86
+ emailDefaults: {},
87
+ error: errorOf(error)
88
+ },
89
+ registries: {
90
+ email: void 0,
91
+ push: void 0,
92
+ discord: void 0,
93
+ slack: void 0
94
+ }
95
+ };
96
+ }
97
+ /**
98
+ * Load and compile. Never throws: a config that fails to load, is not a
99
+ * `defineConfig({...})`, holds something other than template definitions, or
100
+ * does not compile becomes a snapshot carrying the error, which the studio
101
+ * shows in place of its views — a compile error names the workflow and node.
102
+ */
103
+ async function loadSnapshot(options) {
104
+ const { configPath, load, modules } = options;
105
+ let config;
106
+ let registries;
107
+ try {
108
+ const exported = (await load(configPath)).default;
109
+ if (!isConfig(exported)) throw new StudioLoadError(`${configPath} must \`export default defineConfig({...})\` from '@shware/workflow'.`);
110
+ config = exported;
111
+ registries = {
112
+ email: locate("email", config.templates?.email, modules, configPath),
113
+ push: locate("push", config.templates?.push, modules, configPath),
114
+ discord: locate("discord", config.templates?.discord, modules, configPath),
115
+ slack: locate("slack", config.templates?.slack, modules, configPath)
116
+ };
117
+ } catch (error) {
118
+ return failed(error);
119
+ }
120
+ const from = formatted(config.emails?.from);
121
+ const replyTo = formatted(config.emails?.replyTo);
122
+ const shared = {
123
+ ...config.title !== void 0 ? { title: config.title } : {},
124
+ emailDefaults: {
125
+ ...from !== void 0 ? { from } : {},
126
+ ...replyTo !== void 0 ? { replyTo } : {}
127
+ }
128
+ };
129
+ try {
130
+ const bundle = compileConfig(config);
131
+ return {
132
+ payload: {
133
+ ...shared,
134
+ workflows: Object.fromEntries(bundle.workflows.map((workflow) => [workflow.id, workflow])),
135
+ segments: bundle.segments
136
+ },
137
+ registries
138
+ };
139
+ } catch (error) {
140
+ return {
141
+ payload: {
142
+ ...shared,
143
+ workflows: {},
144
+ segments: [],
145
+ error: errorOf(error)
146
+ },
147
+ registries
148
+ };
149
+ }
150
+ }
151
+ /** The `StatsSource` methods, the only names the stats endpoint answers. */
152
+ const STATS_METHODS = [
153
+ "reports",
154
+ "segments",
155
+ "profiles",
156
+ "nodeStats",
157
+ "metrics",
158
+ "links",
159
+ "messages"
160
+ ];
161
+ /**
162
+ * The module the browser imports as `virtual:workflow-config`: the payload as
163
+ * a JSON literal, the two registries as imports from their own modules, and
164
+ * the stats source as calls to the studio's server, one per method
165
+ * workflow.stats.ts defines — the source itself runs there, next to the
166
+ * database and the secrets it reads with, never in the browser.
167
+ */
168
+ /** An export name as an import names it: quoted (ES2022) when it is not an identifier. */
169
+ const exportName = (name) => /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name);
170
+ function virtualModule(snapshot, statsMethods) {
171
+ const imports = [];
172
+ const importOf = (ref, local) => {
173
+ const binding = ref.property === void 0 ? local : `${local}Source`;
174
+ imports.push(ref.name === "default" ? `import ${binding} from ${JSON.stringify(ref.file)};` : `import { ${ref.name === binding ? binding : `${exportName(ref.name)} as ${binding}`} } from ${JSON.stringify(ref.file)};`);
175
+ return ref.property === void 0 ? binding : `${binding}.${ref.property}`;
176
+ };
177
+ const registries = Object.keys(CHANNELS).map((channel) => {
178
+ const ref = snapshot.registries[channel];
179
+ const { field } = CHANNELS[channel];
180
+ return ` ${field}: ${ref === void 0 ? "{}" : importOf(ref, field)},`;
181
+ });
182
+ const stats = statsMethods === void 0 ? void 0 : `{ ${statsMethods.map((method) => `${method}: call(${JSON.stringify(method)})`).join(", ")} }`;
183
+ const call = stats === void 0 ? "" : `
184
+ const call = (method) => async (...args) => {
185
+ const response = await fetch(\`/__studio/stats/\${method}\`, {
186
+ method: 'POST',
187
+ headers: { 'content-type': 'application/json' },
188
+ body: JSON.stringify(args),
189
+ });
190
+ const body = await response.json();
191
+ if (!response.ok) throw new Error(body.error ?? \`stats \${method} failed: \${response.status}\`);
192
+ return body;
193
+ };`;
194
+ return `${imports.join("\n")}${call}
195
+ const payload = ${JSON.stringify(snapshot.payload)};
196
+ export default {
197
+ ...payload,
198
+ ${registries.join("\n")}${stats === void 0 ? "" : `\n stats: ${stats},`}
199
+ };
200
+ `;
201
+ }
202
+ //#endregion
203
+ //#region src/server.ts
204
+ /**
205
+ * The studio dev server.
206
+ *
207
+ * Rather than shipping a prebuilt SPA and a JSON API, the CLI runs Vite over
208
+ * the app source with the project injected as a virtual module: compiled on
209
+ * the server, the template registries imported by the browser from their own
210
+ * modules. Vite serves our app and the user's react-email components as one
211
+ * graph — HMR on every one of them for free, and email previews render with
212
+ * exactly the component code on disk.
213
+ */
214
+ const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
215
+ /** `src/app` when running from source in the monorepo, the published copy otherwise. */
216
+ function resolveAppRoot() {
217
+ const found = [resolve(packageRoot, "src/app"), resolve(packageRoot, "../src/app")].find((path) => existsSync(resolve(path, "index.html")));
218
+ if (!found) throw new Error("workflow-ui: could not locate the app root");
219
+ return found;
220
+ }
221
+ const CONFIG_CANDIDATES = [
222
+ "workflow.config.ts",
223
+ "workflow.config.tsx",
224
+ "workflow.config.js",
225
+ "workflow.config.mjs"
226
+ ];
227
+ /**
228
+ * The project file — `export default defineConfig({...})` from
229
+ * `@shware/workflow`. Required: it is the only place the studio reads
230
+ * definitions from.
231
+ */
232
+ function findConfig(cwd, explicit) {
233
+ if (explicit !== void 0) {
234
+ const path = resolve(cwd, explicit);
235
+ if (!existsSync(path)) throw new Error(`workflow-ui: config not found at ${path}`);
236
+ return path;
237
+ }
238
+ const found = CONFIG_CANDIDATES.map((name) => resolve(cwd, name)).find((path) => existsSync(path));
239
+ if (found === void 0) throw new Error(`workflow-ui: no workflow.config.ts in ${cwd}.\nExport defineConfig({ workflows, templates }) from '@shware/workflow' there, or pass --config <path>.`);
240
+ return found;
241
+ }
242
+ const STATS_CANDIDATES = [
243
+ "workflow.stats.ts",
244
+ "workflow.stats.tsx",
245
+ "workflow.stats.js"
246
+ ];
247
+ /**
248
+ * The studio's optional stats source, apart from the project: an explicit
249
+ * path must exist; otherwise `workflow.stats.ts` beside the config, if any.
250
+ */
251
+ function findStats(cwd, explicit) {
252
+ if (explicit !== void 0) {
253
+ const path = resolve(cwd, explicit);
254
+ if (!existsSync(path)) throw new Error(`workflow-ui: stats source not found at ${path}`);
255
+ return path;
256
+ }
257
+ return STATS_CANDIDATES.map((name) => resolve(cwd, name)).find((path) => existsSync(path));
258
+ }
259
+ const VIRTUAL_ID = "virtual:workflow-config";
260
+ const RESOLVED_ID = `\0${VIRTUAL_ID}`;
261
+ const NODE_MODULES = /[/\\]node_modules[/\\]/;
262
+ /**
263
+ * Every file the last project load evaluated: the config and, transitively,
264
+ * whatever it imported in Vite's SSR module graph — wherever those files live.
265
+ * Dependencies under node_modules are left out: they change with an install,
266
+ * not an edit.
267
+ */
268
+ function evaluatedFiles(dev, configPath) {
269
+ const files = /* @__PURE__ */ new Set([resolve(configPath)]);
270
+ const queue = [...dev.environments.ssr.moduleGraph.getModulesByFile(configPath) ?? []];
271
+ const seen = new Set(queue);
272
+ while (queue.length > 0) {
273
+ const mod = queue.pop();
274
+ if (mod === void 0) continue;
275
+ if (mod.file !== null) {
276
+ if (NODE_MODULES.test(mod.file)) continue;
277
+ files.add(resolve(mod.file));
278
+ }
279
+ for (const imported of mod.importedModules) if (!seen.has(imported)) {
280
+ seen.add(imported);
281
+ queue.push(imported);
282
+ }
283
+ }
284
+ return files;
285
+ }
286
+ /**
287
+ * Serve `virtual:workflow-config` and keep it current.
288
+ *
289
+ * The project is evaluated on the server (ssrLoadModule) and compiled there;
290
+ * see server/project.ts for what reaches the browser. After every load the
291
+ * plugin records the files that load evaluated — the config and everything it
292
+ * imported, inside the working directory or not (`--config ../shared/...`,
293
+ * a contract in a sibling package) — and watches them. A change to any of
294
+ * them drops those evaluated modules and pushes a fresh snapshot over HMR, so
295
+ * adding a workflow or a template to the registration list shows up without a
296
+ * reload. Template components also update through their own client-side HMR,
297
+ * as any module does.
298
+ */
299
+ /** The stats source's default export, evaluated on the dev server. */
300
+ async function loadStats(dev, statsPath) {
301
+ const stats = (await dev.ssrLoadModule(statsPath)).default;
302
+ if (typeof stats !== "object" || stats === null) throw new Error(`workflow-ui: ${statsPath} must default-export defineStats({...})`);
303
+ return stats;
304
+ }
305
+ function readBody(req) {
306
+ return new Promise((resolveBody, reject) => {
307
+ let body = "";
308
+ req.setEncoding("utf8");
309
+ req.on("data", (chunk) => {
310
+ body += chunk;
311
+ });
312
+ req.on("end", () => resolveBody(body));
313
+ req.on("error", reject);
314
+ });
315
+ }
316
+ function projectPlugin(configPath, statsPath) {
317
+ let server;
318
+ let evaluated = /* @__PURE__ */ new Set([resolve(configPath)]);
319
+ return {
320
+ name: "workflow-ui:project",
321
+ resolveId: (id) => id === VIRTUAL_ID ? RESOLVED_ID : null,
322
+ async load(id) {
323
+ if (id !== RESOLVED_ID || server === void 0) return null;
324
+ const dev = server;
325
+ const snapshot = await loadSnapshot({
326
+ configPath,
327
+ load: (file) => dev.ssrLoadModule(file),
328
+ modules: ssrModulesOf(dev)
329
+ });
330
+ evaluated = evaluatedFiles(dev, configPath);
331
+ let methods;
332
+ if (statsPath !== void 0) {
333
+ const stats = await loadStats(dev, statsPath);
334
+ methods = STATS_METHODS.filter((method) => typeof stats[method] === "function");
335
+ for (const file of evaluatedFiles(dev, statsPath)) evaluated.add(file);
336
+ }
337
+ dev.watcher.add([...evaluated]);
338
+ return virtualModule(snapshot, methods);
339
+ },
340
+ configureServer(dev) {
341
+ server = dev;
342
+ process.setSourceMapsEnabled(true);
343
+ for (const file of [configPath, statsPath]) if (file !== void 0) dev.watcher.add(file);
344
+ const refresh = (file) => {
345
+ if (!evaluated.has(resolve(file))) return;
346
+ const virtual = dev.moduleGraph.getModuleById(RESOLVED_ID);
347
+ if (virtual === void 0) return;
348
+ for (const path of evaluated) for (const mod of dev.moduleGraph.getModulesByFile(path) ?? []) dev.moduleGraph.invalidateModule(mod);
349
+ dev.moduleGraph.invalidateModule(virtual);
350
+ dev.reloadModule(virtual);
351
+ };
352
+ dev.watcher.on("change", refresh);
353
+ dev.watcher.on("add", refresh);
354
+ dev.watcher.on("unlink", refresh);
355
+ dev.middlewares.use("/__studio/stats/", (req, res) => {
356
+ const sendJson = (status, body) => {
357
+ res.statusCode = status;
358
+ res.setHeader("content-type", "application/json");
359
+ res.end(JSON.stringify(body));
360
+ };
361
+ (async () => {
362
+ if (req.method !== "POST") {
363
+ res.setHeader("allow", "POST");
364
+ sendJson(405, { error: "stats calls are POST" });
365
+ return;
366
+ }
367
+ const rejection = studioRequestRejection(req);
368
+ if (rejection !== void 0) {
369
+ sendJson(403, { error: rejection });
370
+ return;
371
+ }
372
+ const method = (req.url ?? "").replace(/^\//, "").split("?")[0];
373
+ if (statsPath === void 0 || !STATS_METHODS.includes(method)) {
374
+ sendJson(404, { error: `no stats method '${method}'` });
375
+ return;
376
+ }
377
+ try {
378
+ const args = JSON.parse(await readBody(req) || "[]");
379
+ if (!Array.isArray(args)) {
380
+ sendJson(400, { error: "the body is the arguments, as a JSON array" });
381
+ return;
382
+ }
383
+ const fn = (await loadStats(dev, statsPath))[method];
384
+ if (fn === void 0) {
385
+ sendJson(404, { error: `workflow.stats.ts defines no '${method}'` });
386
+ return;
387
+ }
388
+ sendJson(200, await fn(...args) ?? null);
389
+ } catch (error) {
390
+ dev.config.logger.error(`[workflow-ui] stats ${method} failed: ${String(error)}`);
391
+ sendJson(500, { error: error instanceof Error ? error.message : String(error) });
392
+ }
393
+ })();
394
+ });
395
+ }
396
+ };
397
+ }
398
+ /** `Sec-Fetch-Site` values no other site can produce: our own page, or a direct navigation. */
399
+ const OWN_FETCH_SITES = /* @__PURE__ */ new Set(["same-origin", "none"]);
400
+ function headerValue(raw) {
401
+ const value = Array.isArray(raw) ? raw[0] : raw;
402
+ return value === void 0 || value === "" ? void 0 : value;
403
+ }
404
+ /**
405
+ * Refuse any request another website could have caused, and say why.
406
+ *
407
+ * The node endpoint reads the developer's source files to answer, so a page
408
+ * they merely *visit* should not be able to probe it. Vite's CORS handling
409
+ * decides who may read a response; this decides whether the request is served
410
+ * at all.
411
+ *
412
+ * - `Sec-Fetch-Site` is attached by the browser and cannot be set from
413
+ * script, so anything but `same-origin` (our page) or `none` (the address
414
+ * bar) is a request some other page caused — including `same-site`, which
415
+ * covers another port on localhost.
416
+ * - `Origin` covers clients that send no fetch metadata: present and not our
417
+ * own host means cross-origin. Absent is allowed on purpose — a same-origin
418
+ * GET and a terminal `curl` both have no Origin at all, and a cross-origin
419
+ * browser request always has one.
420
+ */
421
+ function studioRequestRejection(req) {
422
+ const site = headerValue(req.headers["sec-fetch-site"]);
423
+ if (site !== void 0 && !OWN_FETCH_SITES.has(site)) return `refused: sec-fetch-site is '${site}', so another site caused this request`;
424
+ const origin = headerValue(req.headers.origin);
425
+ if (origin !== void 0) {
426
+ const host = headerValue(req.headers.host);
427
+ let originHost;
428
+ try {
429
+ originHost = new URL(origin).host;
430
+ } catch {
431
+ originHost = void 0;
432
+ }
433
+ if (host === void 0 || originHost?.toLowerCase() !== host.toLowerCase()) return `refused: cross-origin request from ${origin}`;
434
+ }
435
+ }
436
+ /**
437
+ * The studio's dev-server API — read-only. The studio views source and never
438
+ * writes it: edits happen in the editor, and Vite's watcher and HMR bring them
439
+ * to the page. The one endpoint resolves a node's captured position to a line
440
+ * on disk for display; everything else under `/__studio` answers 404, so the
441
+ * write routes earlier versions served (`/__studio/envelope`,
442
+ * `/__studio/addresses`, POST `/__studio/node`) are gone rather than hidden.
443
+ */
444
+ function studioApiPlugin(cwd) {
445
+ const sendJson = (res, status, body) => {
446
+ res.statusCode = status;
447
+ res.setHeader("content-type", "application/json");
448
+ res.end(JSON.stringify(body));
449
+ };
450
+ return {
451
+ name: "workflow-ui:studio-api",
452
+ configureServer(server) {
453
+ server.middlewares.use("/__studio/node", (req, res) => {
454
+ if (req.method !== "GET" && req.method !== "HEAD") {
455
+ res.setHeader("allow", "GET, HEAD");
456
+ sendJson(res, 405, { error: "the studio is read-only: GET only" });
457
+ return;
458
+ }
459
+ const rejection = studioRequestRejection(req);
460
+ if (rejection !== void 0) {
461
+ sendJson(res, 403, { error: rejection });
462
+ return;
463
+ }
464
+ const params = new URL(req.url ?? "/", "http://internal").searchParams;
465
+ const found = sourcePosition(cwd, params.get("file") ?? "", Number(params.get("line")));
466
+ if ("error" in found) {
467
+ sendJson(res, 422, { error: found.error });
468
+ return;
469
+ }
470
+ sendJson(res, 200, {
471
+ file: relative(cwd, found.file),
472
+ line: found.line
473
+ });
474
+ });
475
+ server.middlewares.use("/__studio", (_req, res) => {
476
+ sendJson(res, 404, { error: "no such studio endpoint" });
477
+ });
478
+ }
479
+ };
480
+ }
481
+ /**
482
+ * Is `candidate` `root` itself or something below it?
483
+ *
484
+ * Asked through `relative`, never a string prefix. A prefix test needs a
485
+ * trailing separator (or `/proj-evil` passes for `/proj`), and the separator it
486
+ * appends is the wrong one on Windows, where `resolve()` returns `C:\proj\…`:
487
+ * that mismatch failed every path on Windows, which is how the whole
488
+ * /__studio/node surface came to answer "outside the project" there.
489
+ */
490
+ function isInsideDir(root, candidate, ops = {
491
+ isAbsolute,
492
+ relative
493
+ }) {
494
+ const rel = ops.relative(root, candidate);
495
+ if (rel === "") return true;
496
+ if (ops.isAbsolute(rel)) return false;
497
+ return rel.split(/[/\\]/)[0] !== "..";
498
+ }
499
+ /**
500
+ * Keep a path that arrived from the browser inside the project.
501
+ *
502
+ * The scope is `cwd` — the project the studio was started in — and not the
503
+ * workspace root `searchForWorkspaceRoot` walks up to: in a monorepo that root
504
+ * is the whole repo, so a studio started in `apps/marketing` accepted
505
+ * `file=../../packages/billing/src/rates.ts` and read it.
506
+ */
507
+ function isInsideProject(cwd, candidate) {
508
+ const root = resolve(cwd);
509
+ const path = resolve(candidate);
510
+ if (!isInsideDir(root, path)) return false;
511
+ if (!existsSync(path)) return true;
512
+ return isInsideDir(realpathSync(root), realpathSync(path));
513
+ }
514
+ /**
515
+ * Check a captured position before answering with it.
516
+ *
517
+ * The path is validated against cwd before anything is touched: it arrives
518
+ * from the browser, and an endpoint that follows an arbitrary path is a
519
+ * read-anywhere endpoint.
520
+ */
521
+ function sourcePosition(cwd, rawFile, line) {
522
+ let path = rawFile;
523
+ if (/^https?:\/\//.test(path)) path = new URL(path).pathname;
524
+ if (path.startsWith("/@fs")) path = path.slice(4);
525
+ path = resolve(cwd, decodeURIComponent(path));
526
+ if (!isInsideProject(cwd, path)) return { error: "source file is outside the project" };
527
+ if (!existsSync(path)) return { error: `no such source file: ${path}` };
528
+ if (!Number.isInteger(line) || line < 1) return { error: "expected a line number" };
529
+ return {
530
+ file: path,
531
+ line
532
+ };
533
+ }
534
+ async function startStudio(options = {}) {
535
+ const cwd = options.cwd ?? process.cwd();
536
+ const configPath = findConfig(cwd, options.config);
537
+ const statsPath = findStats(cwd, options.stats);
538
+ const appRoot = resolveAppRoot();
539
+ const server = await createServer({
540
+ root: appRoot,
541
+ configFile: false,
542
+ envDir: false,
543
+ plugins: [
544
+ react(),
545
+ svgr(),
546
+ tailwindcss(),
547
+ projectPlugin(configPath, statsPath),
548
+ studioApiPlugin(cwd)
549
+ ],
550
+ server: {
551
+ port: options.port ?? 4321,
552
+ open: options.open ?? false,
553
+ fs: { allow: [
554
+ searchForWorkspaceRoot(cwd),
555
+ searchForWorkspaceRoot(dirname(configPath)),
556
+ searchForWorkspaceRoot(packageRoot),
557
+ appRoot
558
+ ] }
559
+ },
560
+ resolve: { dedupe: ["react", "react-dom"] },
561
+ optimizeDeps: {
562
+ entries: ["index.html", configPath],
563
+ include: ["@react-email/render", "react-dom/server"]
564
+ }
565
+ });
566
+ await server.listen();
567
+ return server;
568
+ }
569
+ //#endregion
570
+ //#region src/generate.ts
571
+ /** The host's formatter may rewrap the file, change quotes or trailing commas: not a difference. */
572
+ function normalize(source) {
573
+ return source.replace(/"/g, "'").replace(/\s+/g, " ").replace(/ ?([{}()[\],;:=<>.]) ?/g, "$1").replace(/,([}\])])/g, "$1").trim();
574
+ }
575
+ async function generateSchema(options) {
576
+ const cwd = options.cwd ?? process.cwd();
577
+ const configPath = findConfig(cwd, options.config);
578
+ const { module } = await runnerImport(configPath);
579
+ if (!isConfig(module.default)) throw new Error(`workflow-ui: ${relative(cwd, configPath)} must \`export default defineConfig({...})\``);
580
+ const config = module.default;
581
+ const file = renderDrizzleSchema(config.database?.schema);
582
+ const out = resolve(cwd, options.out);
583
+ const current = existsSync(out) ? readFileSync(out, "utf8") : void 0;
584
+ if (current !== void 0 && normalize(current) === normalize(file)) return "unchanged";
585
+ if (options.check) return "outdated";
586
+ mkdirSync(dirname(out), { recursive: true });
587
+ writeFileSync(out, file);
588
+ return "written";
589
+ }
590
+ //#endregion
591
+ //#region src/cli.ts
592
+ function parseArgs(argv) {
593
+ const args = {
594
+ open: false,
595
+ check: false,
596
+ help: false
597
+ };
598
+ for (let i = 0; i < argv.length; i++) {
599
+ const arg = argv[i];
600
+ if (arg === "--help" || arg === "-h") args.help = true;
601
+ else if (arg === "--open") args.open = true;
602
+ else if (arg === "--check") args.check = true;
603
+ else if (arg === "--out" || arg === "-o") args.out = argv[++i];
604
+ else if (arg === "--port" || arg === "-p") args.port = Number(argv[++i]);
605
+ else if (arg === "--config" || arg === "-c") args.config = argv[++i];
606
+ else if (arg === "--stats" || arg === "-s") args.stats = argv[++i];
607
+ }
608
+ return args;
609
+ }
610
+ const HELP = `
611
+ workflow-ui — review your workflows, templates and reports
612
+
613
+ Usage
614
+ $ workflow-ui [dev] [options]
615
+ $ workflow-ui generate --out <file> [--check] [--config <path>]
616
+
617
+ Options
618
+ -p, --port <port> Port to listen on (default 4321)
619
+ -c, --config <path> Project file (default ./workflow.config.ts)
620
+ -s, --stats <path> Stats source (default ./workflow.stats.ts, if present)
621
+ --open Open the browser on start
622
+ -o, --out <file> generate: where the drizzle schema file goes
623
+ --check generate: fail when the file is out of date, write nothing
624
+ -h, --help Show this message
625
+ `;
626
+ async function main() {
627
+ const [command, ...rest] = process.argv.slice(2);
628
+ if (command === "generate") {
629
+ const args = parseArgs(rest);
630
+ if (args.help || args.out === void 0) {
631
+ console.log(HELP);
632
+ if (args.out === void 0 && !args.help) process.exitCode = 1;
633
+ return;
634
+ }
635
+ try {
636
+ const result = await generateSchema({
637
+ out: args.out,
638
+ check: args.check,
639
+ ...args.config !== void 0 ? { config: args.config } : {}
640
+ });
641
+ if (result === "outdated") {
642
+ console.error(`\n ${args.out} is out of date — run workflow-ui generate, then your migration tool\n`);
643
+ process.exitCode = 1;
644
+ } else console.log(`\n ${args.out} ${result === "written" ? "written" : "is up to date"}\n`);
645
+ } catch (error) {
646
+ console.error(`\n${error instanceof Error ? error.message : String(error)}\n`);
647
+ process.exitCode = 1;
648
+ }
649
+ return;
650
+ }
651
+ const args = parseArgs(process.argv.slice(2).filter((arg) => arg !== "dev"));
652
+ if (args.help) {
653
+ console.log(HELP);
654
+ return;
655
+ }
656
+ try {
657
+ const address = (await startStudio({
658
+ ...args.port !== void 0 ? { port: args.port } : {},
659
+ ...args.config !== void 0 ? { config: args.config } : {},
660
+ ...args.stats !== void 0 ? { stats: args.stats } : {},
661
+ open: args.open
662
+ })).resolvedUrls?.local[0] ?? `http://localhost:${args.port ?? 4321}`;
663
+ console.log(`\n workflow-ui ready at ${address}\n`);
664
+ } catch (error) {
665
+ console.error(`\n${error instanceof Error ? error.message : String(error)}\n`);
666
+ process.exitCode = 1;
667
+ }
668
+ }
669
+ main();
670
+ //#endregion
671
+ export {};
672
+
673
+ //# sourceMappingURL=cli.mjs.map