miqro 5.0.5 → 6.0.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 (372) hide show
  1. package/.eslintrc +15 -0
  2. package/README.md +618 -20
  3. package/bin/miqro +34 -0
  4. package/build/editor.bundle.js +61154 -0
  5. package/build/esm/editor/auth.d.ts +6 -0
  6. package/build/esm/editor/auth.js +42 -0
  7. package/build/esm/editor/auth.js.map +1 -0
  8. package/build/esm/editor/common/admin-interface.d.ts +36 -0
  9. package/build/esm/editor/common/admin-interface.js +45 -0
  10. package/build/esm/editor/common/admin-interface.js.map +1 -0
  11. package/build/esm/editor/common/constants.d.ts +4 -0
  12. package/build/esm/editor/common/constants.js +21 -0
  13. package/build/esm/editor/common/constants.js.map +1 -0
  14. package/build/esm/editor/common/constants.server.d.ts +2 -0
  15. package/build/esm/editor/common/constants.server.js +5 -0
  16. package/build/esm/editor/common/constants.server.js.map +1 -0
  17. package/build/esm/editor/common/editor-index.d.ts +2 -0
  18. package/build/esm/editor/common/editor-index.js +15 -0
  19. package/build/esm/editor/common/editor-index.js.map +1 -0
  20. package/build/esm/editor/common/html-encode.d.ts +1 -0
  21. package/build/esm/editor/common/html-encode.js +15 -0
  22. package/build/esm/editor/common/html-encode.js.map +1 -0
  23. package/build/esm/editor/common/log-socket.d.ts +13 -0
  24. package/build/esm/editor/common/log-socket.js +68 -0
  25. package/build/esm/editor/common/log-socket.js.map +1 -0
  26. package/build/esm/editor/common/templates.d.ts +11 -0
  27. package/build/esm/editor/common/templates.js +444 -0
  28. package/build/esm/editor/common/templates.js.map +1 -0
  29. package/build/esm/editor/components/api-preview.d.ts +11 -0
  30. package/build/esm/editor/components/api-preview.js +91 -0
  31. package/build/esm/editor/components/api-preview.js.map +1 -0
  32. package/build/esm/editor/components/editor.d.ts +16 -0
  33. package/build/esm/editor/components/editor.js +355 -0
  34. package/build/esm/editor/components/editor.js.map +1 -0
  35. package/build/esm/editor/components/file-browser.d.ts +37 -0
  36. package/build/esm/editor/components/file-browser.js +122 -0
  37. package/build/esm/editor/components/file-browser.js.map +1 -0
  38. package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
  39. package/build/esm/editor/components/file-editor-toolbar.js +94 -0
  40. package/build/esm/editor/components/file-editor-toolbar.js.map +1 -0
  41. package/build/esm/editor/components/file-editor.d.ts +32 -0
  42. package/build/esm/editor/components/file-editor.js +60 -0
  43. package/build/esm/editor/components/file-editor.js.map +1 -0
  44. package/build/esm/editor/components/filter-query.d.ts +1 -0
  45. package/build/esm/editor/components/filter-query.js +23 -0
  46. package/build/esm/editor/components/filter-query.js.map +1 -0
  47. package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
  48. package/build/esm/editor/components/highlight-text-area.js +139 -0
  49. package/build/esm/editor/components/highlight-text-area.js.map +1 -0
  50. package/build/esm/editor/components/log-viewer.d.ts +6 -0
  51. package/build/esm/editor/components/log-viewer.js +70 -0
  52. package/build/esm/editor/components/log-viewer.js.map +1 -0
  53. package/build/esm/editor/components/new-file.d.ts +10 -0
  54. package/build/esm/editor/components/new-file.js +118 -0
  55. package/build/esm/editor/components/new-file.js.map +1 -0
  56. package/build/esm/editor/components/scroll-query.d.ts +7 -0
  57. package/build/esm/editor/components/scroll-query.js +22 -0
  58. package/build/esm/editor/components/scroll-query.js.map +1 -0
  59. package/build/esm/editor/components/start-page.d.ts +13 -0
  60. package/build/esm/editor/components/start-page.js +31 -0
  61. package/build/esm/editor/components/start-page.js.map +1 -0
  62. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
  63. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +30 -0
  64. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +1 -0
  65. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
  66. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +50 -0
  67. package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +1 -0
  68. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
  69. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +40 -0
  70. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +1 -0
  71. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
  72. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +150 -0
  73. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +1 -0
  74. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
  75. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +39 -0
  76. package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +1 -0
  77. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
  78. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
  79. package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +1 -0
  80. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
  81. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +46 -0
  82. package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +1 -0
  83. package/build/esm/editor/http/admin/editor/editor.js +8 -0
  84. package/build/esm/editor/http/admin/editor/editor.js.map +1 -0
  85. package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
  86. package/build/esm/editor/http/admin/editor/index.api.js +22 -0
  87. package/build/esm/editor/http/admin/editor/index.api.js.map +1 -0
  88. package/build/esm/editor/server.d.ts +3 -0
  89. package/build/esm/editor/server.js +50 -0
  90. package/build/esm/editor/server.js.map +1 -0
  91. package/build/esm/editor/ws.d.ts +3 -0
  92. package/build/esm/editor/ws.js +12 -0
  93. package/build/esm/editor/ws.js.map +1 -0
  94. package/build/esm/src/bin/compile.d.ts +3 -0
  95. package/build/esm/src/bin/compile.js +31 -0
  96. package/build/esm/src/bin/compile.js.map +1 -0
  97. package/build/{utils/doc/md.d.ts → esm/src/bin/doc-md.d.ts} +2 -4
  98. package/build/{utils/doc/md.js → esm/src/bin/doc-md.js} +32 -18
  99. package/build/esm/src/bin/doc-md.js.map +1 -0
  100. package/build/esm/src/bin/generate-doc.d.ts +4 -0
  101. package/build/esm/src/bin/generate-doc.js +47 -0
  102. package/build/esm/src/bin/generate-doc.js.map +1 -0
  103. package/build/esm/src/bin/test.d.ts +3 -0
  104. package/build/esm/src/bin/test.js +68 -0
  105. package/build/esm/src/bin/test.js.map +1 -0
  106. package/build/esm/src/bin/types.d.ts +3 -0
  107. package/build/esm/src/bin/types.js +21 -0
  108. package/build/esm/src/bin/types.js.map +1 -0
  109. package/build/esm/src/cluster.js +11 -0
  110. package/build/esm/src/cluster.js.map +1 -0
  111. package/build/esm/src/common/arguments.d.ts +22 -0
  112. package/build/esm/src/common/arguments.js +310 -0
  113. package/build/esm/src/common/arguments.js.map +1 -0
  114. package/build/esm/src/common/assets.d.ts +11 -0
  115. package/build/esm/src/common/assets.js +121 -0
  116. package/build/esm/src/common/assets.js.map +1 -0
  117. package/build/esm/src/common/checksum.d.ts +19 -0
  118. package/build/esm/src/common/checksum.js +57 -0
  119. package/build/esm/src/common/checksum.js.map +1 -0
  120. package/build/esm/src/common/constants.d.ts +10 -0
  121. package/build/esm/src/common/constants.js +14 -0
  122. package/build/esm/src/common/constants.js.map +1 -0
  123. package/build/esm/src/common/content-type.d.ts +4 -0
  124. package/build/esm/src/common/content-type.js +82 -0
  125. package/build/esm/src/common/content-type.js.map +1 -0
  126. package/build/esm/src/common/esbuild.d.ts +17 -0
  127. package/build/esm/src/common/esbuild.js +79 -0
  128. package/build/esm/src/common/esbuild.js.map +1 -0
  129. package/build/esm/src/common/exit.d.ts +2 -0
  130. package/build/esm/src/common/exit.js +84 -0
  131. package/build/esm/src/common/exit.js.map +1 -0
  132. package/build/esm/src/common/fs.d.ts +8 -0
  133. package/build/esm/src/common/fs.js +17 -0
  134. package/build/esm/src/common/fs.js.map +1 -0
  135. package/build/esm/src/common/help.d.ts +3 -0
  136. package/build/esm/src/common/help.js +44 -0
  137. package/build/esm/src/common/help.js.map +1 -0
  138. package/build/esm/src/common/jsx.d.ts +52 -0
  139. package/build/esm/src/common/jsx.js +365 -0
  140. package/build/esm/src/common/jsx.js.map +1 -0
  141. package/build/esm/src/common/paths.d.ts +14 -0
  142. package/build/esm/src/common/paths.js +110 -0
  143. package/build/esm/src/common/paths.js.map +1 -0
  144. package/build/esm/src/common/watch.d.ts +3 -0
  145. package/build/esm/src/common/watch.js +74 -0
  146. package/build/esm/src/common/watch.js.map +1 -0
  147. package/build/esm/src/inflate/inflate-sea.d.ts +5 -0
  148. package/build/esm/src/inflate/inflate-sea.js +175 -0
  149. package/build/esm/src/inflate/inflate-sea.js.map +1 -0
  150. package/build/esm/src/inflate/inflate.d.ts +14 -0
  151. package/build/esm/src/inflate/inflate.js +65 -0
  152. package/build/esm/src/inflate/inflate.js.map +1 -0
  153. package/build/esm/src/inflate/md.d.ts +2 -0
  154. package/build/esm/src/inflate/md.js +19 -0
  155. package/build/esm/src/inflate/md.js.map +1 -0
  156. package/build/esm/src/inflate/setup-auth.d.ts +3 -0
  157. package/build/esm/src/inflate/setup-auth.js +38 -0
  158. package/build/esm/src/inflate/setup-auth.js.map +1 -0
  159. package/build/esm/src/inflate/setup-cors.d.ts +3 -0
  160. package/build/esm/src/inflate/setup-cors.js +38 -0
  161. package/build/esm/src/inflate/setup-cors.js.map +1 -0
  162. package/build/esm/src/inflate/setup-db.d.ts +8 -0
  163. package/build/esm/src/inflate/setup-db.js +99 -0
  164. package/build/esm/src/inflate/setup-db.js.map +1 -0
  165. package/build/esm/src/inflate/setup-http.d.ts +37 -0
  166. package/build/esm/src/inflate/setup-http.js +543 -0
  167. package/build/esm/src/inflate/setup-http.js.map +1 -0
  168. package/build/esm/src/inflate/setup-log.d.ts +7 -0
  169. package/build/esm/src/inflate/setup-log.js +37 -0
  170. package/build/esm/src/inflate/setup-log.js.map +1 -0
  171. package/build/esm/src/inflate/setup-server-config.d.ts +7 -0
  172. package/build/esm/src/inflate/setup-server-config.js +37 -0
  173. package/build/esm/src/inflate/setup-server-config.js.map +1 -0
  174. package/build/esm/src/inflate/setup-test.d.ts +2 -0
  175. package/build/esm/src/inflate/setup-test.js +22 -0
  176. package/build/esm/src/inflate/setup-test.js.map +1 -0
  177. package/build/esm/src/inflate/setup-ws.d.ts +4 -0
  178. package/build/esm/src/inflate/setup-ws.js +46 -0
  179. package/build/esm/src/inflate/setup-ws.js.map +1 -0
  180. package/build/esm/src/inflate/utils/sea-utils.d.ts +2 -0
  181. package/build/esm/src/inflate/utils/sea-utils.js +13 -0
  182. package/build/esm/src/inflate/utils/sea-utils.js.map +1 -0
  183. package/build/esm/src/lib.d.ts +13 -0
  184. package/build/esm/src/lib.js +17 -0
  185. package/build/esm/src/lib.js.map +1 -0
  186. package/build/esm/src/main.d.ts +2 -0
  187. package/build/esm/src/main.js +92 -0
  188. package/build/esm/src/main.js.map +1 -0
  189. package/build/esm/src/services/app.d.ts +88 -0
  190. package/build/esm/src/services/app.js +619 -0
  191. package/build/esm/src/services/app.js.map +1 -0
  192. package/build/esm/src/services/editor.d.ts +3 -0
  193. package/build/esm/src/services/editor.js +61 -0
  194. package/build/esm/src/services/editor.js.map +1 -0
  195. package/build/esm/src/services/globals.d.ts +3 -0
  196. package/build/esm/src/services/globals.js +139 -0
  197. package/build/esm/src/services/globals.js.map +1 -0
  198. package/build/esm/src/services/hot-reload.d.ts +1 -0
  199. package/build/esm/src/services/hot-reload.js +45 -0
  200. package/build/esm/src/services/hot-reload.js.map +1 -0
  201. package/build/esm/src/services/migrations.d.ts +4 -0
  202. package/build/esm/src/services/migrations.js +61 -0
  203. package/build/esm/src/services/migrations.js.map +1 -0
  204. package/build/esm/src/services/utils/cache.d.ts +19 -0
  205. package/build/esm/src/services/utils/cache.js +85 -0
  206. package/build/esm/src/services/utils/cache.js.map +1 -0
  207. package/build/esm/src/services/utils/cluster-cache.d.ts +20 -0
  208. package/build/esm/src/services/utils/cluster-cache.js +211 -0
  209. package/build/esm/src/services/utils/cluster-cache.js.map +1 -0
  210. package/build/esm/src/services/utils/cluster-ws.d.ts +24 -0
  211. package/build/esm/src/services/utils/cluster-ws.js +176 -0
  212. package/build/esm/src/services/utils/cluster-ws.js.map +1 -0
  213. package/build/esm/src/services/utils/db-manager.d.ts +20 -0
  214. package/build/esm/src/services/utils/db-manager.js +59 -0
  215. package/build/esm/src/services/utils/db-manager.js.map +1 -0
  216. package/build/esm/src/services/utils/get-route.d.ts +9 -0
  217. package/build/esm/src/services/utils/get-route.js +58 -0
  218. package/build/esm/src/services/utils/get-route.js.map +1 -0
  219. package/build/esm/src/services/utils/log.d.ts +17 -0
  220. package/build/esm/src/services/utils/log.js +74 -0
  221. package/build/esm/src/services/utils/log.js.map +1 -0
  222. package/build/esm/src/services/utils/server-interface.d.ts +41 -0
  223. package/build/esm/src/services/utils/server-interface.js +74 -0
  224. package/build/esm/src/services/utils/server-interface.js.map +1 -0
  225. package/build/esm/src/services/utils/websocketmanager.d.ts +23 -0
  226. package/build/esm/src/services/utils/websocketmanager.js +128 -0
  227. package/build/esm/src/services/utils/websocketmanager.js.map +1 -0
  228. package/build/esm/src/types.d.ts +166 -0
  229. package/build/esm/src/types.js +2 -0
  230. package/build/esm/src/types.js.map +1 -0
  231. package/build/jsx.dom.js +1585 -0
  232. package/build/lib.cjs +14009 -0
  233. package/build/postject.base64.cjs +1 -0
  234. package/editor/auth.ts +51 -0
  235. package/editor/common/admin-interface.ts +84 -0
  236. package/editor/common/constants.server.ts +5 -0
  237. package/editor/common/constants.ts +21 -0
  238. package/editor/common/editor-index.tsx +17 -0
  239. package/editor/common/html-encode.ts +14 -0
  240. package/editor/common/log-socket.tsx +82 -0
  241. package/editor/common/templates.ts +448 -0
  242. package/editor/components/api-preview.tsx +116 -0
  243. package/editor/components/editor.tsx +483 -0
  244. package/editor/components/file-browser.tsx +295 -0
  245. package/editor/components/file-editor-toolbar.tsx +187 -0
  246. package/editor/components/file-editor.tsx +122 -0
  247. package/editor/components/filter-query.tsx +22 -0
  248. package/editor/components/highlight-text-area.tsx +159 -0
  249. package/editor/components/log-viewer.tsx +110 -0
  250. package/editor/components/new-file.tsx +169 -0
  251. package/editor/components/scroll-query.tsx +22 -0
  252. package/editor/components/start-page.tsx +49 -0
  253. package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
  254. package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
  255. package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
  256. package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
  257. package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
  258. package/editor/http/admin/editor/api/server/reload.api.ts +52 -0
  259. package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
  260. package/editor/http/admin/editor/editor.tsx +8 -0
  261. package/editor/http/admin/editor/font.ttf +0 -0
  262. package/editor/http/admin/editor/index.api.tsx +39 -0
  263. package/editor/http/admin/editor/style.css +620 -0
  264. package/editor/server.ts +57 -0
  265. package/editor/static/android-chrome-192x192.png +0 -0
  266. package/editor/static/android-chrome-512x512.png +0 -0
  267. package/editor/static/apple-touch-icon.png +0 -0
  268. package/editor/static/editor.bundle.in.mjs +20 -0
  269. package/editor/static/favicon-16x16.png +0 -0
  270. package/editor/static/favicon-32x32.png +0 -0
  271. package/editor/static/favicon.ico +0 -0
  272. package/editor/static/site.webmanifest +19 -0
  273. package/editor/ws.ts +15 -0
  274. package/package.json +43 -24
  275. package/package.json--OLD +36 -0
  276. package/sea/app.sh +33 -0
  277. package/sea/base64.js +3 -0
  278. package/sea/basic-compile.base64.sh +1 -0
  279. package/sea/basic-compile.sh +73 -0
  280. package/sea/basic-config.json +9 -0
  281. package/sea/compile.sh +124 -0
  282. package/sea/copy-types.sh +46 -0
  283. package/sea/editor-assets/editor.bundle.in.mjs +19 -0
  284. package/sea/esbuild.sh +31 -0
  285. package/sea/generate-global-types-asset-json.js +34 -0
  286. package/sea/install-esbuild.sh +53 -0
  287. package/sea/install-nodejs.sh +49 -0
  288. package/sea/main.sh +34 -0
  289. package/sea/node.sh +33 -0
  290. package/sea/node.version.tag +1 -0
  291. package/sea/precompile.sh +7 -0
  292. package/sea/release-tar.sh +5 -0
  293. package/sea/sign-add.sh +22 -0
  294. package/sea/sign-remove.sh +22 -0
  295. package/sea/tsc.sh +1 -0
  296. package/sea/types.json +1 -0
  297. package/src/bin/compile.ts +35 -0
  298. package/src/bin/doc-md.ts +210 -0
  299. package/src/bin/generate-doc.ts +55 -0
  300. package/src/bin/test.ts +92 -0
  301. package/src/bin/types.ts +22 -0
  302. package/src/cluster.ts +16 -0
  303. package/src/common/arguments.ts +366 -0
  304. package/src/common/assets.ts +124 -0
  305. package/src/common/checksum.ts +58 -0
  306. package/src/common/constants.ts +18 -0
  307. package/src/common/content-type.ts +84 -0
  308. package/src/common/esbuild.ts +94 -0
  309. package/src/common/exit.ts +91 -0
  310. package/src/common/fs.ts +17 -0
  311. package/src/common/help.ts +46 -0
  312. package/src/common/jsx.ts +414 -0
  313. package/src/common/paths.ts +117 -0
  314. package/src/common/watch.ts +80 -0
  315. package/src/inflate/inflate-sea.ts +193 -0
  316. package/src/inflate/inflate.ts +96 -0
  317. package/src/inflate/md.ts +20 -0
  318. package/src/inflate/setup-auth.ts +40 -0
  319. package/src/inflate/setup-cors.ts +40 -0
  320. package/src/inflate/setup-db.ts +113 -0
  321. package/src/inflate/setup-http.ts +643 -0
  322. package/src/inflate/setup-log.ts +44 -0
  323. package/src/inflate/setup-server-config.ts +47 -0
  324. package/src/inflate/setup-test.ts +23 -0
  325. package/src/inflate/setup-ws.ts +48 -0
  326. package/src/inflate/utils/sea-utils.ts +14 -0
  327. package/src/lib.ts +19 -0
  328. package/src/main.ts +87 -0
  329. package/src/services/app.ts +718 -0
  330. package/src/services/editor.tsx +93 -0
  331. package/src/services/globals.ts +143 -0
  332. package/src/services/hot-reload.ts +46 -0
  333. package/src/services/migrations.ts +66 -0
  334. package/src/services/utils/cache.ts +88 -0
  335. package/src/services/utils/cluster-cache.ts +225 -0
  336. package/src/services/utils/cluster-ws.ts +192 -0
  337. package/src/services/utils/db-manager.ts +79 -0
  338. package/src/services/utils/get-route.ts +70 -0
  339. package/src/services/utils/log.ts +91 -0
  340. package/src/services/utils/server-interface.ts +166 -0
  341. package/src/services/utils/websocketmanager.ts +139 -0
  342. package/src/types/@esbuild.d.ts +1 -0
  343. package/src/types/@miqro/core.d.ts +2 -0
  344. package/src/types/@miqro/jsx.d.ts +2 -0
  345. package/src/types/@miqro/parser.d.ts +2 -0
  346. package/src/types/@miqro/query.d.ts +2 -0
  347. package/src/types/@miqro/request.d.ts +2 -0
  348. package/src/types/@miqro/test.d.ts +2 -0
  349. package/src/types/@miqro.d.ts +1 -0
  350. package/src/types/@types.d.ts +1 -0
  351. package/src/types/browser.globals.d.ts +9 -0
  352. package/src/types/globals.d.ts +2 -0
  353. package/src/types/jsx.globals.d.ts +37 -0
  354. package/src/types/miqro.d.ts +109 -0
  355. package/src/types/postject.d.ts +1 -0
  356. package/src/types/server.globals.d.ts +72 -0
  357. package/src/types.ts +199 -0
  358. package/tsconfig.json +35 -0
  359. package/build/cli.js +0 -4
  360. package/build/cmd-map.d.ts +0 -90
  361. package/build/cmd-map.js +0 -460
  362. package/build/index.js +0 -2
  363. package/build/utils/doc/json.d.ts +0 -7
  364. package/build/utils/doc/json.js +0 -12
  365. package/build/utils/exec.d.ts +0 -32
  366. package/build/utils/exec.js +0 -102
  367. package/build/utils/templates.d.ts +0 -33
  368. package/build/utils/templates.js +0 -302
  369. package/build/utils/watch.d.ts +0 -1
  370. package/build/utils/watch.js +0 -35
  371. /package/build/{index.d.ts → esm/editor/http/admin/editor/editor.d.ts} +0 -0
  372. /package/build/{cli.d.ts → esm/src/cluster.d.ts} +0 -0
@@ -0,0 +1,643 @@
1
+ import { Router, newURL, Response, Request, RouterHandlerOptions, Logger, APIRoute, normalizePath } from "@miqro/core";
2
+ import { existsSync, mkdirSync, readFile, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, relative, resolve as pathResolve } from "node:path";
4
+
5
+ import { CONTENT_TYPE_MAP, DEFAULT_CONTENT_TYPE } from "../common/content-type.js";
6
+ import { InflateError, importHTMLModule, importAPIRoute, inflateJSX, importJSONModule, JSONModuleValue, jsx2HTML } from "../common/jsx.js";
7
+ import { createNodeRuntime } from "@miqro/jsx-node";
8
+ import { getHotReloadScript } from "../services/hot-reload.js";
9
+ import { RuntimeURL } from "@miqro/jsx";
10
+ import { cwd } from "node:process";
11
+ import { assertGlobalTampered } from "../services/globals.js";
12
+ import { getHTTPRouterPath, getStaticFilesPath } from "../common/paths.js";
13
+ import { setupCORS } from "./setup-cors.js";
14
+ import { setupAUTH } from "./setup-auth.js";
15
+ import { getRoutes } from "../services/utils/get-route.js";
16
+ import { describeFilePath } from "../common/fs.js";
17
+ import { inflateMD2HTML } from "./md.js";
18
+ import { ServerInterface, ServerRequest } from "../types.js";
19
+
20
+ export interface RouteFileMap {
21
+ [filePath: string]: {
22
+ routes: {
23
+ path?: string;
24
+ method?: string;
25
+ options?: RouterHandlerOptions;
26
+ inflatePath?: string;
27
+ }[];
28
+ service: string;
29
+ previewMethod: "api" | "html" | null;
30
+ }
31
+ }
32
+
33
+ export interface StaticFileMap {
34
+ [filePathKey: string]: {
35
+ path: string;
36
+ filePath: string;
37
+ method: string | null;
38
+ inflatePath?: string;
39
+ contentType: string;
40
+ previewMethod: "html" | null;
41
+ body: Buffer;
42
+ }
43
+ }
44
+
45
+ export async function setupHTTPRouter(server: ServerInterface, logger: Logger, hotreload: boolean, servicePath: string, service: string, routeFileMap: RouteFileMap, staticFileMap: StaticFileMap | null, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[]) {
46
+ const mainRouter = new Router();
47
+ const apiRouterPath = getHTTPRouterPath(servicePath); //resolve(process.cwd(), service, "http");
48
+ if (apiRouterPath) {
49
+
50
+ await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
51
+
52
+ await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
53
+ logger.trace("setting up http routes from [%s]", service);
54
+ const { router: httpRouter } = await createRouterFromDirectory(server, hotreload, service, logger, apiRouterPath, errors, routeFileMap, staticFileMap, inflateDir, inflateSea);
55
+
56
+ mainRouter.use(httpRouter);
57
+ }
58
+
59
+ const staticFilesPath = getStaticFilesPath(servicePath); //resolve(process.cwd(), service, "static");
60
+ if (staticFilesPath) {
61
+ logger.trace("setting up static file routes from [%s]", service);
62
+ const staticRouter = createStaticRouterFromDirectory(service, logger, staticFilesPath, inflateDir, routeFileMap, staticFileMap);
63
+ mainRouter.use(staticRouter);
64
+ }
65
+ return mainRouter;
66
+ }
67
+
68
+ function createStaticRoute(service: string, logger: Logger, router: Router, dir: string, file: ScannedFile, inflateDir?: string | undefined | false, routeFileMap?: RouteFileMap, staticFileMap?: StaticFileMap) {
69
+ logger.trace("creating static route for [%s]", file.filePath);
70
+ logger.trace("[%o]", {
71
+ file,
72
+ dir
73
+ });
74
+ const contentType = CONTENT_TYPE_MAP[String(file.ext).toLocaleLowerCase()];
75
+ const path = join("/", relative(dir, file.filePath));
76
+
77
+
78
+ routeFileMap[file.filePath] = {
79
+ routes: [{
80
+ method: "GET",
81
+ path: normalizePath(path)
82
+ }],
83
+ service,
84
+ previewMethod: "html"
85
+ };
86
+
87
+ if (inflateDir) {
88
+ const inflatePath = join(inflateDir, service, "static", path);
89
+ mkdirSync(dirname(inflatePath), {
90
+ recursive: true
91
+ });
92
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
93
+ const body = readFileSync(file.filePath);
94
+ writeFileSync(inflatePath, body);
95
+ if (staticFileMap) {
96
+ staticFileMap[file.filePath] = {
97
+ contentType,
98
+ filePath: file.filePath,
99
+ previewMethod: "html",
100
+ method: "GET",
101
+ path: normalizePath(path),
102
+ body: Buffer.from(body),
103
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
104
+ }
105
+ }
106
+ }
107
+
108
+
109
+
110
+ router.use(assertGlobalTampered);
111
+ router.get(path, async function (_req, res) {
112
+ await new Promise<void>((resolve, reject) => {
113
+ try {
114
+ readFile(file.filePath, async (err, body) => {
115
+ if (err) {
116
+ reject(err);
117
+ } else {
118
+ try {
119
+ await res.asyncEnd({
120
+ status: 200,
121
+ headers: {
122
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
123
+ },
124
+ body
125
+ });
126
+ resolve();
127
+ } catch (e) {
128
+ reject(e);
129
+ }
130
+ }
131
+ })
132
+ } catch (e) {
133
+ reject(e);
134
+ }
135
+ });
136
+ });
137
+ }
138
+
139
+ function createStaticRouterFromDirectory(service: string, logger: Logger, dir: string, inflateDir: string | false | undefined, routeFileMap: RouteFileMap | undefined, staticFileMap: StaticFileMap | null): Router {
140
+ const router = new Router();
141
+ scanFiles(dir).forEach(file => {
142
+ createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
143
+ });
144
+ return router;
145
+ }
146
+
147
+ async function createRouterFromDirectory(server: ServerInterface, hotreload: boolean, service: string, logger: Logger, dir: string, errors: InflateError[] = [], routeFileMap: RouteFileMap = {}, staticFileMap: StaticFileMap | null = null, inflateDir: string | undefined | false, inflateSea: boolean): Promise<{
148
+ router: Router;
149
+ errors: InflateError[];
150
+ routeFileMap: RouteFileMap;
151
+ }> {
152
+ const router = new Router();
153
+ router.use(assertGlobalTampered);
154
+ await Promise.all(scanFiles(dir).map(file => new Promise<void>(async (resolve) => {
155
+ try {
156
+ switch (file.ext) {
157
+ case ".jsx":
158
+ case ".js":
159
+ case ".ts":
160
+ case ".tsx": {
161
+ switch (file.subExt) {
162
+ case ".test":
163
+ return resolve();
164
+ case ".ignore":
165
+ logger.warn("ignoring [%s]", file.filePath);
166
+ return resolve();
167
+ case ".api": {
168
+
169
+ const module = await importAPIRoute(file.filePath, logger);
170
+
171
+ const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
172
+
173
+ routeFileMap[file.filePath] = {
174
+ routes,
175
+ service,
176
+ previewMethod: "api"
177
+ };
178
+
179
+ const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
180
+ embemedJSX: false,
181
+ minify: false,
182
+ useExport: true,
183
+ logger
184
+ }) : "";
185
+
186
+ for (const r of routes) {
187
+
188
+ /*if (inflateDir && r.inflatePath) {
189
+ const rPath = r.inflatePath;
190
+ const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
191
+ mkdirSync(dirname(inflatePath), {
192
+ recursive: true
193
+ });
194
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
195
+ writeFileSync(inflatePath, inflatedCode);
196
+ }*/
197
+
198
+ if (inflateDir && r.defaultInflatePath && inflateSea) {
199
+ const rPath = r.defaultInflatePath;
200
+ const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
201
+ mkdirSync(dirname(inflatePath), {
202
+ recursive: true
203
+ });
204
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
205
+ writeFileSync(inflatePath, inflatedCode);
206
+ }
207
+
208
+
209
+ router.use(assertGlobalTampered);
210
+ router.use(module.handler, r.path, r.method as any, r.options);
211
+ }
212
+ return resolve();
213
+ }
214
+ case ".json": {
215
+ const module = await importJSONModule(file.filePath, logger);
216
+ const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".json", module.apiOptions as Partial<APIRoute>);
217
+
218
+ routeFileMap[file.filePath] = {
219
+ routes,
220
+ service,
221
+ previewMethod: "html"
222
+ };
223
+
224
+ for (const r of routes) {
225
+
226
+ const contentType = CONTENT_TYPE_MAP[".json"] ? CONTENT_TYPE_MAP[".json"] : DEFAULT_CONTENT_TYPE;
227
+
228
+
229
+
230
+ if (inflateDir) {
231
+
232
+ if (r.inflatePath) {
233
+ //if (r.method === "GET" || r.method === "get") {
234
+ const rPath = r.inflatePath;
235
+ const inflatePath = join(inflateDir, service, "static", rPath);
236
+ mkdirSync(dirname(inflatePath), {
237
+ recursive: true
238
+ });
239
+ if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
240
+ logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
241
+ continue;
242
+ }
243
+ const JSON_STATIC = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
244
+ //const JSON = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
245
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
246
+ writeFileSync(inflatePath, JSON_STATIC);
247
+ //}
248
+
249
+ if (staticFileMap && inflateSea) {
250
+ staticFileMap[file.filePath] = {
251
+ contentType,
252
+ filePath: file.filePath,
253
+ method: r.method,
254
+ previewMethod: "html",
255
+ path: r.path,
256
+ body: Buffer.from(JSON_STATIC),
257
+ inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
258
+ }
259
+ }
260
+ }
261
+ }
262
+
263
+ router.use(assertGlobalTampered);
264
+ router.use(async function (req: Request, res: Response) {
265
+
266
+ const JSON = await getJSON(req, res, newURL(req.path), module.apiOptions?.basePath, module.default);
267
+
268
+ return res.asyncEnd({
269
+ status: 200,
270
+ headers: {
271
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
272
+ },
273
+ body: JSON
274
+ });
275
+ }, r.path, r.method as any, r.options)
276
+ }
277
+
278
+ return resolve();
279
+ }
280
+ case ".html": {
281
+
282
+ const module = await importHTMLModule(file.filePath, logger);
283
+
284
+ const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".html", module.apiOptions as Partial<APIRoute>);
285
+
286
+ routeFileMap[file.filePath] = {
287
+ routes,
288
+ service,
289
+ previewMethod: "html"
290
+ };
291
+
292
+ for (const r of routes) {
293
+
294
+ const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
295
+
296
+ if (inflateDir) {
297
+
298
+ if (r.inflatePath) {
299
+ //if (r.method === "GET" || r.method === "get") {
300
+ const rPath = r.inflatePath;
301
+ const inflatePath = join(inflateDir, service, "static", rPath);
302
+ mkdirSync(dirname(inflatePath), {
303
+ recursive: true
304
+ });
305
+ if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
306
+ logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
307
+ continue;
308
+ }
309
+ const toRender = typeof module.default === "function" ? module.default({ server } as ServerRequest, null) : module.default;
310
+ const HTML_STATIC = await getHTML(hotreload, { server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, await toRender);
311
+
312
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
313
+ writeFileSync(inflatePath, HTML_STATIC);
314
+ //}
315
+
316
+
317
+ if (staticFileMap && inflateSea) {
318
+ staticFileMap[file.filePath + r.method + r.path] = {
319
+ filePath: file.filePath,
320
+ contentType,
321
+ method: r.method,
322
+ previewMethod: "html",
323
+ path: r.path,
324
+ body: Buffer.from(HTML_STATIC),
325
+ inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
326
+ }
327
+ }
328
+ }
329
+ }
330
+
331
+ router.use(assertGlobalTampered);
332
+ router.use(async function (req: Request, res: Response) {
333
+ const toRender = typeof module.default === "function" ? module.default(req, res) : module.default;
334
+ const HTML = await getHTML(hotreload, req, res, newURL(req.path), module.apiOptions?.basePath, await toRender);
335
+
336
+ return res.asyncEnd({
337
+ status: 200,
338
+ headers: {
339
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
340
+ },
341
+ body: HTML
342
+ });
343
+ }, r.path, r.method as any, r.options)
344
+ }
345
+ return resolve();
346
+ }
347
+ case ".min":
348
+ case ".js":
349
+ default: {
350
+ // allow fall-through when extension is .js and .ts because is a static route without embemedJSX
351
+ if (file.ext !== ".js" && file.ext !== ".ts") {
352
+ const code = await inflateJSX(file.filePath, {
353
+ embemedJSX: true,
354
+ minify: file.subExt === ".min" ? true : false,
355
+ useExport: false,
356
+ logger
357
+ });
358
+ const contentType = CONTENT_TYPE_MAP[".js"];
359
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
360
+
361
+ routeFileMap[file.filePath] = {
362
+ routes: [{
363
+ method: "GET",
364
+ path
365
+ }],
366
+ service,
367
+ previewMethod: "html"
368
+ };
369
+
370
+ if (inflateDir) {
371
+ const inflatePath = join(inflateDir, service, "static", path);
372
+ mkdirSync(dirname(inflatePath), {
373
+ recursive: true
374
+ });
375
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
376
+ writeFileSync(inflatePath, code);
377
+
378
+
379
+ if (staticFileMap && inflateSea) {
380
+ staticFileMap[file.filePath] = {
381
+ contentType,
382
+ filePath: file.filePath,
383
+ method: "GET",
384
+ previewMethod: "html",
385
+ path,
386
+ body: Buffer.from(code),
387
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
388
+ }
389
+ }
390
+ }
391
+
392
+ router.use(assertGlobalTampered);
393
+ router.get(path, async function (req, res) {
394
+ return res.asyncEnd({
395
+ status: 200,
396
+ headers: {
397
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
398
+ },
399
+ body: code
400
+ });
401
+ });
402
+ return resolve();
403
+ }
404
+ }
405
+ }
406
+ }
407
+ case ".md": {
408
+ switch (file.subExt) {
409
+ case ".html": {
410
+ const code = await inflateMD2HTML(file.filePath, logger);
411
+ const contentType = CONTENT_TYPE_MAP[".html"];
412
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name);
413
+ routeFileMap[file.filePath] = {
414
+ routes: [{
415
+ method: "GET",
416
+ path
417
+ }],
418
+ service,
419
+ previewMethod: "html"
420
+ };
421
+
422
+ if (inflateDir) {
423
+ const inflatePath = join(inflateDir, service, "static", path);
424
+ mkdirSync(dirname(inflatePath), {
425
+ recursive: true
426
+ });
427
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
428
+ writeFileSync(inflatePath, code);
429
+ if (staticFileMap && inflateSea) {
430
+ staticFileMap[file.filePath] = {
431
+ contentType,
432
+ method: "GET",
433
+ filePath: file.filePath,
434
+ previewMethod: "html",
435
+ path,
436
+ body: Buffer.from(code),
437
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
438
+ }
439
+ }
440
+ }
441
+
442
+ router.use(assertGlobalTampered);
443
+ router.get(path, async function (_req, res) {
444
+ res.asyncEnd({
445
+ status: 200,
446
+ headers: {
447
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
448
+ },
449
+ body: code
450
+ });
451
+ });
452
+ return resolve();
453
+ }
454
+ }
455
+ }
456
+ default:
457
+ if (file.ext === ".js" || file.ext === ".ts") {
458
+ switch (file.subExt) {
459
+ case ".ignore": {
460
+ logger.warn("ignoring [%s]", file.filePath);
461
+ return resolve();
462
+ }
463
+ case ".bundle":
464
+ case ".min": {
465
+ const code = await inflateJSX(file.filePath, {
466
+ embemedJSX: false,
467
+ minify: file.subExt === ".min" ? true : false,
468
+ useExport: false,
469
+ logger
470
+ });
471
+ const contentType = CONTENT_TYPE_MAP[".js"];
472
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
473
+ routeFileMap[file.filePath] = {
474
+ routes: [{
475
+ method: "GET",
476
+ path
477
+ }],
478
+ service,
479
+ previewMethod: "html"
480
+ };
481
+
482
+ if (inflateDir) {
483
+ const inflatePath = join(inflateDir, service, "static", path);
484
+ mkdirSync(dirname(inflatePath), {
485
+ recursive: true
486
+ });
487
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
488
+ writeFileSync(inflatePath, code);
489
+ if (staticFileMap && inflateSea) {
490
+ staticFileMap[file.filePath] = {
491
+ contentType,
492
+ method: "GET",
493
+ filePath: file.filePath,
494
+ previewMethod: "html",
495
+ path,
496
+ body: Buffer.from(code),
497
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
498
+ }
499
+ }
500
+ }
501
+
502
+ router.use(assertGlobalTampered);
503
+ router.get(path, async function (_req, res) {
504
+ res.asyncEnd({
505
+ status: 200,
506
+ headers: {
507
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
508
+ },
509
+ body: code
510
+ });
511
+ });
512
+ return resolve();
513
+ }
514
+ }
515
+ } else if (file.ext === ".bundle") {
516
+ switch (file.subExt) {
517
+ case ".ignore": {
518
+ logger.warn("ignoring [%s]", file.filePath);
519
+ return resolve();
520
+ }
521
+ case ".css": {
522
+ const code = readFileSync(file.filePath).toString()
523
+ .split("\n")
524
+ .filter(c => c)
525
+ .filter(c => c.charAt(0) !== "#")
526
+ .map(cssPath => readFileSync(pathResolve(dirname(file.filePath), cssPath)).toString())
527
+ .join("\n");
528
+ const contentType = CONTENT_TYPE_MAP[".css"];
529
+ const path = join("/", dirname(relative(dir, file.filePath)), file.name);
530
+ routeFileMap[file.filePath] = {
531
+ routes: [{
532
+ method: "GET",
533
+ path
534
+ }],
535
+ service,
536
+ previewMethod: "html"
537
+ };
538
+
539
+ if (inflateDir) {
540
+ const inflatePath = join(inflateDir, service, "static", path);
541
+ mkdirSync(dirname(inflatePath), {
542
+ recursive: true
543
+ });
544
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
545
+ writeFileSync(inflatePath, code);
546
+ if (staticFileMap && inflateSea) {
547
+ staticFileMap[file.filePath] = {
548
+ contentType,
549
+ method: "GET",
550
+ filePath: file.filePath,
551
+ previewMethod: "html",
552
+ path,
553
+ body: Buffer.from(code),
554
+ inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
555
+ }
556
+ }
557
+ }
558
+
559
+ router.use(assertGlobalTampered);
560
+ router.get(path, async function (_req, res) {
561
+ res.asyncEnd({
562
+ status: 200,
563
+ headers: {
564
+ ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
565
+ },
566
+ body: code
567
+ });
568
+ });
569
+ return resolve();
570
+ }
571
+ }
572
+ }
573
+ createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
574
+ return resolve();
575
+
576
+ }
577
+ } catch (e) {
578
+ logger.error("error with " + file.filePath);
579
+ logger.error(e);
580
+ errors.push({
581
+ filePath: file.filePath,
582
+ error: e
583
+ });
584
+ } finally {
585
+ return resolve();
586
+ }
587
+ })));
588
+ router.use(assertGlobalTampered);
589
+ return {
590
+ routeFileMap,
591
+ router,
592
+ errors
593
+ };
594
+ }
595
+
596
+ interface ScannedFile {
597
+ filePath: string;
598
+ ext: string;
599
+ fileName: string;
600
+ name: string;
601
+ subExt: string;
602
+ subName: string;
603
+ }
604
+
605
+ export function scanFiles(path: string, ret: ScannedFile[] = []): ScannedFile[] {
606
+ const files = readdirSync(path);
607
+ for (const file of files) {
608
+ const filePath = pathResolve(path, file);
609
+ if (statSync(filePath).isDirectory()) {
610
+ scanFiles(filePath, ret);
611
+ continue;
612
+ } else {
613
+ const description = describeFilePath(filePath);
614
+ if (description.fileName === ".DS_Store") {
615
+ continue;
616
+ }
617
+ ret.push(description);
618
+ }
619
+ }
620
+ return ret;
621
+ }
622
+
623
+
624
+
625
+ function getHTML(hotreload: boolean, req: ServerRequest, res: Response | null, url: RuntimeURL, basePath: string | undefined, out: JSX.Element): string {
626
+ let HTML = `<!DOCTYPE html>\n${jsx2HTML(out, createNodeRuntime({
627
+ url,
628
+ basePath
629
+ }))}`;
630
+
631
+ //console.log("GET_HTML[%s] [%o]", HTML, out);
632
+
633
+ if (hotreload) {
634
+ HTML += getHotReloadScript()
635
+ }
636
+ return HTML;
637
+ }
638
+
639
+ async function getJSON(req: ServerRequest, res: Response | null, url: RuntimeURL, basePath: string | undefined, out: JSONModuleValue | Promise<JSONModuleValue> | ((req: Request | null, res: Response | null) => JSONModuleValue | Promise<JSONModuleValue>)) {
640
+
641
+ const toRender = await (typeof out === "function" ? out(req, res) : out);
642
+ return JSON.stringify(toRender, undefined, 2);
643
+ }
@@ -0,0 +1,44 @@
1
+ import { Logger } from "@miqro/core";
2
+ import { importLogConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
3
+ import { getLogConfigPath } from "../common/paths.js";
4
+ import { dirname, relative, resolve } from "node:path";
5
+ import { mkdirSync, writeFileSync } from "node:fs";
6
+ import { cwd } from "node:process";
7
+ import { LogConfig } from "../types.js";
8
+
9
+ export interface LogConfigMap {
10
+ [service: string]: LogConfig | undefined;
11
+ }
12
+
13
+ export async function setupLogConfig(logger: Logger, servicePath: string, service: string, logConfigMap: LogConfigMap, inflateDir: string | undefined | false, errors: InflateError[]) {
14
+ const logPath = getLogConfigPath(servicePath); // resolve(process.cwd(), service, "server.ts");
15
+ if (logPath) {
16
+ try {
17
+ //logger.debug("setting up server config from [%s]", join(service, basename(serverPath)));
18
+
19
+ const logConfig = await importLogConfigModule(logPath, logger);
20
+ logConfigMap[service] = logConfig;
21
+
22
+ if (inflateDir) {
23
+ const inflatePath = resolve(inflateDir, service, "log.js");
24
+ mkdirSync(dirname(inflatePath), {
25
+ recursive: true
26
+ });
27
+ logger.log("writing [%s]", relative(cwd(), inflatePath));
28
+ writeFileSync(inflatePath, await inflateJSX(logPath, {
29
+ embemedJSX: false,
30
+ minify: false,
31
+ useExport: true,
32
+ logger
33
+ }));
34
+ }
35
+ } catch (e) {
36
+ errors.push({
37
+ filePath: logPath,
38
+ error: e
39
+ });
40
+ logger.error("error with " + logPath);
41
+ logger.error(e);
42
+ }
43
+ }
44
+ }