@ecopages/core 0.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/LICENSE +21 -0
  3. package/README.md +32 -0
  4. package/package.json +279 -0
  5. package/src/adapters/abstract/application-adapter.d.ts +168 -0
  6. package/src/adapters/abstract/application-adapter.js +109 -0
  7. package/src/adapters/abstract/application-adapter.ts +337 -0
  8. package/src/adapters/abstract/router-adapter.d.ts +26 -0
  9. package/src/adapters/abstract/router-adapter.js +5 -0
  10. package/src/adapters/abstract/router-adapter.ts +30 -0
  11. package/src/adapters/abstract/server-adapter.d.ts +69 -0
  12. package/src/adapters/abstract/server-adapter.js +15 -0
  13. package/src/adapters/abstract/server-adapter.ts +79 -0
  14. package/src/adapters/bun/client-bridge.d.ts +34 -0
  15. package/src/adapters/bun/client-bridge.js +48 -0
  16. package/src/adapters/bun/client-bridge.ts +62 -0
  17. package/src/adapters/bun/create-app.d.ts +60 -0
  18. package/src/adapters/bun/create-app.js +117 -0
  19. package/src/adapters/bun/create-app.ts +189 -0
  20. package/src/adapters/bun/define-api-handler.d.ts +61 -0
  21. package/src/adapters/bun/define-api-handler.js +15 -0
  22. package/src/adapters/bun/define-api-handler.ts +114 -0
  23. package/src/adapters/bun/hmr-manager.d.ts +84 -0
  24. package/src/adapters/bun/hmr-manager.js +227 -0
  25. package/src/adapters/bun/hmr-manager.ts +281 -0
  26. package/src/adapters/bun/index.d.ts +3 -0
  27. package/src/adapters/bun/index.js +8 -0
  28. package/src/adapters/bun/index.ts +3 -0
  29. package/src/adapters/bun/server-adapter.d.ts +155 -0
  30. package/src/adapters/bun/server-adapter.js +368 -0
  31. package/src/adapters/bun/server-adapter.ts +492 -0
  32. package/src/adapters/bun/server-lifecycle.d.ts +52 -0
  33. package/src/adapters/bun/server-lifecycle.js +120 -0
  34. package/src/adapters/bun/server-lifecycle.ts +154 -0
  35. package/src/adapters/index.d.ts +6 -0
  36. package/src/adapters/index.js +14 -0
  37. package/src/adapters/index.ts +6 -0
  38. package/src/adapters/node/create-app.d.ts +21 -0
  39. package/src/adapters/node/create-app.js +143 -0
  40. package/src/adapters/node/create-app.ts +179 -0
  41. package/src/adapters/node/index.d.ts +4 -0
  42. package/src/adapters/node/index.js +8 -0
  43. package/src/adapters/node/index.ts +9 -0
  44. package/src/adapters/node/node-client-bridge.d.ts +26 -0
  45. package/src/adapters/node/node-client-bridge.js +66 -0
  46. package/src/adapters/node/node-client-bridge.ts +79 -0
  47. package/src/adapters/node/node-hmr-manager.d.ts +62 -0
  48. package/src/adapters/node/node-hmr-manager.js +221 -0
  49. package/src/adapters/node/node-hmr-manager.ts +271 -0
  50. package/src/adapters/node/server-adapter.d.ts +190 -0
  51. package/src/adapters/node/server-adapter.js +420 -0
  52. package/src/adapters/node/server-adapter.ts +561 -0
  53. package/src/adapters/node/static-content-server.d.ts +24 -0
  54. package/src/adapters/node/static-content-server.js +166 -0
  55. package/src/adapters/node/static-content-server.ts +203 -0
  56. package/src/adapters/shared/api-response.d.ts +52 -0
  57. package/src/adapters/shared/api-response.js +96 -0
  58. package/src/adapters/shared/api-response.ts +104 -0
  59. package/src/adapters/shared/application-adapter.d.ts +18 -0
  60. package/src/adapters/shared/application-adapter.js +90 -0
  61. package/src/adapters/shared/application-adapter.ts +199 -0
  62. package/src/adapters/shared/explicit-static-route-matcher.d.ts +38 -0
  63. package/src/adapters/shared/explicit-static-route-matcher.js +100 -0
  64. package/src/adapters/shared/explicit-static-route-matcher.ts +134 -0
  65. package/src/adapters/shared/file-route-middleware-pipeline.d.ts +65 -0
  66. package/src/adapters/shared/file-route-middleware-pipeline.js +98 -0
  67. package/src/adapters/shared/file-route-middleware-pipeline.ts +123 -0
  68. package/src/adapters/shared/fs-server-response-factory.d.ts +19 -0
  69. package/src/adapters/shared/fs-server-response-factory.js +97 -0
  70. package/src/adapters/shared/fs-server-response-factory.ts +118 -0
  71. package/src/adapters/shared/fs-server-response-matcher.d.ts +71 -0
  72. package/src/adapters/shared/fs-server-response-matcher.js +155 -0
  73. package/src/adapters/shared/fs-server-response-matcher.ts +198 -0
  74. package/src/adapters/shared/render-context.d.ts +14 -0
  75. package/src/adapters/shared/render-context.js +69 -0
  76. package/src/adapters/shared/render-context.ts +105 -0
  77. package/src/adapters/shared/server-adapter.d.ts +87 -0
  78. package/src/adapters/shared/server-adapter.js +353 -0
  79. package/src/adapters/shared/server-adapter.ts +442 -0
  80. package/src/adapters/shared/server-route-handler.d.ts +89 -0
  81. package/src/adapters/shared/server-route-handler.js +120 -0
  82. package/src/adapters/shared/server-route-handler.ts +166 -0
  83. package/src/adapters/shared/server-static-builder.d.ts +38 -0
  84. package/src/adapters/shared/server-static-builder.js +46 -0
  85. package/src/adapters/shared/server-static-builder.ts +82 -0
  86. package/src/build/build-adapter.d.ts +74 -0
  87. package/src/build/build-adapter.js +54 -0
  88. package/src/build/build-adapter.ts +132 -0
  89. package/src/build/build-types.d.ts +57 -0
  90. package/src/build/build-types.js +0 -0
  91. package/src/build/build-types.ts +83 -0
  92. package/src/build/esbuild-build-adapter.d.ts +69 -0
  93. package/src/build/esbuild-build-adapter.js +390 -0
  94. package/src/build/esbuild-build-adapter.ts +510 -0
  95. package/src/config/config-builder.d.ts +227 -0
  96. package/src/config/config-builder.js +392 -0
  97. package/src/config/config-builder.ts +474 -0
  98. package/src/constants.d.ts +32 -0
  99. package/src/constants.js +21 -0
  100. package/src/constants.ts +39 -0
  101. package/src/create-app.d.ts +17 -0
  102. package/src/create-app.js +66 -0
  103. package/src/create-app.ts +87 -0
  104. package/src/declarations.d.ts +26 -0
  105. package/src/define-api-handler.d.ts +25 -0
  106. package/src/define-api-handler.js +15 -0
  107. package/src/define-api-handler.ts +66 -0
  108. package/src/dev/sc-server.d.ts +30 -0
  109. package/src/dev/sc-server.js +111 -0
  110. package/src/dev/sc-server.ts +143 -0
  111. package/src/eco/README.md +636 -0
  112. package/src/eco/component-render-context.d.ts +105 -0
  113. package/src/eco/component-render-context.js +77 -0
  114. package/src/eco/component-render-context.ts +202 -0
  115. package/src/eco/eco.d.ts +9 -0
  116. package/src/eco/eco.js +110 -0
  117. package/src/eco/eco.ts +221 -0
  118. package/src/eco/eco.types.d.ts +170 -0
  119. package/src/eco/eco.types.js +0 -0
  120. package/src/eco/eco.types.ts +202 -0
  121. package/src/eco/eco.utils.d.ts +40 -0
  122. package/src/eco/eco.utils.js +40 -0
  123. package/src/eco/eco.utils.ts +89 -0
  124. package/src/eco/global-injector-map.d.ts +16 -0
  125. package/src/eco/global-injector-map.js +80 -0
  126. package/src/eco/global-injector-map.ts +112 -0
  127. package/src/eco/lazy-injector-map.d.ts +8 -0
  128. package/src/eco/lazy-injector-map.js +70 -0
  129. package/src/eco/lazy-injector-map.ts +120 -0
  130. package/src/eco/module-dependencies.d.ts +18 -0
  131. package/src/eco/module-dependencies.js +49 -0
  132. package/src/eco/module-dependencies.ts +75 -0
  133. package/src/env.d.ts +20 -0
  134. package/src/errors/http-error.d.ts +31 -0
  135. package/src/errors/http-error.js +50 -0
  136. package/src/errors/http-error.ts +72 -0
  137. package/src/errors/index.d.ts +2 -0
  138. package/src/errors/index.js +4 -0
  139. package/src/errors/index.ts +2 -0
  140. package/src/errors/locals-access-error.d.ts +4 -0
  141. package/src/errors/locals-access-error.js +9 -0
  142. package/src/errors/locals-access-error.ts +7 -0
  143. package/src/global/app-logger.d.ts +2 -0
  144. package/src/global/app-logger.js +6 -0
  145. package/src/global/app-logger.ts +4 -0
  146. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-have-HMR-script-injected-in-page-1.png +0 -0
  147. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
  148. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
  149. package/src/hmr/client/hmr-runtime.d.ts +10 -0
  150. package/src/hmr/client/hmr-runtime.js +86 -0
  151. package/src/hmr/client/hmr-runtime.ts +121 -0
  152. package/src/hmr/hmr-strategy.d.ts +159 -0
  153. package/src/hmr/hmr-strategy.js +29 -0
  154. package/src/hmr/hmr-strategy.ts +172 -0
  155. package/src/hmr/hmr.test.e2e.d.ts +1 -0
  156. package/src/hmr/hmr.test.e2e.js +50 -0
  157. package/src/hmr/hmr.test.e2e.ts +75 -0
  158. package/src/hmr/strategies/default-hmr-strategy.d.ts +43 -0
  159. package/src/hmr/strategies/default-hmr-strategy.js +34 -0
  160. package/src/hmr/strategies/default-hmr-strategy.ts +60 -0
  161. package/src/hmr/strategies/js-hmr-strategy.d.ts +136 -0
  162. package/src/hmr/strategies/js-hmr-strategy.js +179 -0
  163. package/src/hmr/strategies/js-hmr-strategy.ts +308 -0
  164. package/src/index.browser.d.ts +3 -0
  165. package/src/index.browser.js +4 -0
  166. package/src/index.browser.ts +3 -0
  167. package/src/index.d.ts +5 -0
  168. package/src/index.js +10 -0
  169. package/src/index.ts +5 -0
  170. package/src/integrations/ghtml/ghtml-renderer.d.ts +15 -0
  171. package/src/integrations/ghtml/ghtml-renderer.js +60 -0
  172. package/src/integrations/ghtml/ghtml-renderer.ts +93 -0
  173. package/src/integrations/ghtml/ghtml.plugin.d.ts +20 -0
  174. package/src/integrations/ghtml/ghtml.plugin.js +21 -0
  175. package/src/integrations/ghtml/ghtml.plugin.ts +32 -0
  176. package/src/internal-types.d.ts +200 -0
  177. package/src/internal-types.js +0 -0
  178. package/src/internal-types.ts +212 -0
  179. package/src/plugins/alias-resolver-plugin.d.ts +2 -0
  180. package/src/plugins/alias-resolver-plugin.js +39 -0
  181. package/src/plugins/alias-resolver-plugin.ts +45 -0
  182. package/src/plugins/eco-component-meta-plugin.d.ts +95 -0
  183. package/src/plugins/eco-component-meta-plugin.js +157 -0
  184. package/src/plugins/eco-component-meta-plugin.ts +474 -0
  185. package/src/plugins/integration-plugin.d.ts +102 -0
  186. package/src/plugins/integration-plugin.js +100 -0
  187. package/src/plugins/integration-plugin.ts +184 -0
  188. package/src/plugins/processor.d.ts +82 -0
  189. package/src/plugins/processor.js +122 -0
  190. package/src/plugins/processor.ts +220 -0
  191. package/src/public-types.d.ts +1094 -0
  192. package/src/public-types.js +0 -0
  193. package/src/public-types.ts +1255 -0
  194. package/src/route-renderer/GRAPH.md +387 -0
  195. package/src/route-renderer/README.md +135 -0
  196. package/src/route-renderer/component-graph-executor.d.ts +32 -0
  197. package/src/route-renderer/component-graph-executor.js +31 -0
  198. package/src/route-renderer/component-graph-executor.ts +84 -0
  199. package/src/route-renderer/component-graph.d.ts +42 -0
  200. package/src/route-renderer/component-graph.js +72 -0
  201. package/src/route-renderer/component-graph.ts +159 -0
  202. package/src/route-renderer/component-marker.d.ts +52 -0
  203. package/src/route-renderer/component-marker.js +46 -0
  204. package/src/route-renderer/component-marker.ts +117 -0
  205. package/src/route-renderer/dependency-resolver.d.ts +24 -0
  206. package/src/route-renderer/dependency-resolver.js +428 -0
  207. package/src/route-renderer/dependency-resolver.ts +596 -0
  208. package/src/route-renderer/html-post-processing.service.d.ts +40 -0
  209. package/src/route-renderer/html-post-processing.service.js +86 -0
  210. package/src/route-renderer/html-post-processing.service.ts +103 -0
  211. package/src/route-renderer/integration-renderer.d.ts +339 -0
  212. package/src/route-renderer/integration-renderer.js +526 -0
  213. package/src/route-renderer/integration-renderer.ts +696 -0
  214. package/src/route-renderer/marker-graph-resolver.d.ts +76 -0
  215. package/src/route-renderer/marker-graph-resolver.js +93 -0
  216. package/src/route-renderer/marker-graph-resolver.ts +153 -0
  217. package/src/route-renderer/page-module-loader.d.ts +61 -0
  218. package/src/route-renderer/page-module-loader.js +102 -0
  219. package/src/route-renderer/page-module-loader.ts +153 -0
  220. package/src/route-renderer/render-execution.service.d.ts +69 -0
  221. package/src/route-renderer/render-execution.service.js +91 -0
  222. package/src/route-renderer/render-execution.service.ts +158 -0
  223. package/src/route-renderer/render-preparation.service.d.ts +112 -0
  224. package/src/route-renderer/render-preparation.service.js +243 -0
  225. package/src/route-renderer/render-preparation.service.ts +358 -0
  226. package/src/route-renderer/route-renderer.d.ts +26 -0
  227. package/src/route-renderer/route-renderer.js +68 -0
  228. package/src/route-renderer/route-renderer.ts +80 -0
  229. package/src/router/fs-router-scanner.d.ts +41 -0
  230. package/src/router/fs-router-scanner.js +155 -0
  231. package/src/router/fs-router-scanner.ts +217 -0
  232. package/src/router/fs-router.d.ts +26 -0
  233. package/src/router/fs-router.js +100 -0
  234. package/src/router/fs-router.ts +122 -0
  235. package/src/services/asset-processing-service/asset-processing.service.d.ts +41 -0
  236. package/src/services/asset-processing-service/asset-processing.service.js +250 -0
  237. package/src/services/asset-processing-service/asset-processing.service.ts +306 -0
  238. package/src/services/asset-processing-service/asset.factory.d.ts +17 -0
  239. package/src/services/asset-processing-service/asset.factory.js +82 -0
  240. package/src/services/asset-processing-service/asset.factory.ts +105 -0
  241. package/src/services/asset-processing-service/assets.types.d.ts +88 -0
  242. package/src/services/asset-processing-service/assets.types.js +0 -0
  243. package/src/services/asset-processing-service/assets.types.ts +112 -0
  244. package/src/services/asset-processing-service/index.d.ts +3 -0
  245. package/src/services/asset-processing-service/index.js +3 -0
  246. package/src/services/asset-processing-service/index.ts +3 -0
  247. package/src/services/asset-processing-service/processor.interface.d.ts +22 -0
  248. package/src/services/asset-processing-service/processor.interface.js +6 -0
  249. package/src/services/asset-processing-service/processor.interface.ts +27 -0
  250. package/src/services/asset-processing-service/processor.registry.d.ts +8 -0
  251. package/src/services/asset-processing-service/processor.registry.js +15 -0
  252. package/src/services/asset-processing-service/processor.registry.ts +18 -0
  253. package/src/services/asset-processing-service/processors/base/base-processor.d.ts +24 -0
  254. package/src/services/asset-processing-service/processors/base/base-processor.js +59 -0
  255. package/src/services/asset-processing-service/processors/base/base-processor.ts +76 -0
  256. package/src/services/asset-processing-service/processors/base/base-script-processor.d.ts +16 -0
  257. package/src/services/asset-processing-service/processors/base/base-script-processor.js +80 -0
  258. package/src/services/asset-processing-service/processors/base/base-script-processor.ts +105 -0
  259. package/src/services/asset-processing-service/processors/index.d.ts +5 -0
  260. package/src/services/asset-processing-service/processors/index.js +5 -0
  261. package/src/services/asset-processing-service/processors/index.ts +5 -0
  262. package/src/services/asset-processing-service/processors/script/content-script.processor.d.ts +5 -0
  263. package/src/services/asset-processing-service/processors/script/content-script.processor.js +57 -0
  264. package/src/services/asset-processing-service/processors/script/content-script.processor.ts +66 -0
  265. package/src/services/asset-processing-service/processors/script/file-script.processor.d.ts +8 -0
  266. package/src/services/asset-processing-service/processors/script/file-script.processor.js +76 -0
  267. package/src/services/asset-processing-service/processors/script/file-script.processor.ts +88 -0
  268. package/src/services/asset-processing-service/processors/script/node-module-script.processor.d.ts +7 -0
  269. package/src/services/asset-processing-service/processors/script/node-module-script.processor.js +74 -0
  270. package/src/services/asset-processing-service/processors/script/node-module-script.processor.ts +84 -0
  271. package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +5 -0
  272. package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +25 -0
  273. package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts +27 -0
  274. package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +9 -0
  275. package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +63 -0
  276. package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts +77 -0
  277. package/src/services/cache/cache.types.d.ts +107 -0
  278. package/src/services/cache/cache.types.js +0 -0
  279. package/src/services/cache/cache.types.ts +126 -0
  280. package/src/services/cache/index.d.ts +7 -0
  281. package/src/services/cache/index.js +7 -0
  282. package/src/services/cache/index.ts +18 -0
  283. package/src/services/cache/memory-cache-store.d.ts +42 -0
  284. package/src/services/cache/memory-cache-store.js +98 -0
  285. package/src/services/cache/memory-cache-store.ts +130 -0
  286. package/src/services/cache/page-cache-service.d.ts +70 -0
  287. package/src/services/cache/page-cache-service.js +152 -0
  288. package/src/services/cache/page-cache-service.ts +202 -0
  289. package/src/services/html-transformer.service.d.ts +50 -0
  290. package/src/services/html-transformer.service.js +163 -0
  291. package/src/services/html-transformer.service.ts +217 -0
  292. package/src/services/page-module-import.service.d.ts +37 -0
  293. package/src/services/page-module-import.service.js +88 -0
  294. package/src/services/page-module-import.service.ts +129 -0
  295. package/src/services/page-request-cache-coordinator.service.d.ts +75 -0
  296. package/src/services/page-request-cache-coordinator.service.js +107 -0
  297. package/src/services/page-request-cache-coordinator.service.ts +128 -0
  298. package/src/services/schema-validation-service.d.ts +122 -0
  299. package/src/services/schema-validation-service.js +101 -0
  300. package/src/services/schema-validation-service.ts +204 -0
  301. package/src/services/validation/standard-schema.types.d.ts +65 -0
  302. package/src/services/validation/standard-schema.types.js +0 -0
  303. package/src/services/validation/standard-schema.types.ts +68 -0
  304. package/src/static-site-generator/static-site-generator.d.ts +57 -0
  305. package/src/static-site-generator/static-site-generator.js +272 -0
  306. package/src/static-site-generator/static-site-generator.ts +359 -0
  307. package/src/utils/css.d.ts +1 -0
  308. package/src/utils/css.js +7 -0
  309. package/src/utils/css.ts +5 -0
  310. package/src/utils/deep-merge.d.ts +14 -0
  311. package/src/utils/deep-merge.js +32 -0
  312. package/src/utils/deep-merge.ts +47 -0
  313. package/src/utils/hash.d.ts +1 -0
  314. package/src/utils/hash.js +7 -0
  315. package/src/utils/hash.ts +5 -0
  316. package/src/utils/html.d.ts +1 -0
  317. package/src/utils/html.js +4 -0
  318. package/src/utils/html.ts +1 -0
  319. package/src/utils/invariant.d.ts +5 -0
  320. package/src/utils/invariant.js +11 -0
  321. package/src/utils/invariant.ts +15 -0
  322. package/src/utils/locals-utils.d.ts +15 -0
  323. package/src/utils/locals-utils.js +24 -0
  324. package/src/utils/locals-utils.ts +37 -0
  325. package/src/utils/parse-cli-args.d.ts +24 -0
  326. package/src/utils/parse-cli-args.js +47 -0
  327. package/src/utils/parse-cli-args.ts +83 -0
  328. package/src/utils/path-utils.module.d.ts +5 -0
  329. package/src/utils/path-utils.module.js +14 -0
  330. package/src/utils/path-utils.module.ts +14 -0
  331. package/src/utils/runtime.d.ts +11 -0
  332. package/src/utils/runtime.js +40 -0
  333. package/src/utils/runtime.ts +44 -0
  334. package/src/utils/server-utils.module.d.ts +19 -0
  335. package/src/utils/server-utils.module.js +56 -0
  336. package/src/utils/server-utils.module.ts +67 -0
  337. package/src/watchers/project-watcher.d.ts +120 -0
  338. package/src/watchers/project-watcher.js +238 -0
  339. package/src/watchers/project-watcher.test-helpers.d.ts +4 -0
  340. package/src/watchers/project-watcher.test-helpers.js +51 -0
  341. package/src/watchers/project-watcher.test-helpers.ts +40 -0
  342. package/src/watchers/project-watcher.ts +306 -0
@@ -0,0 +1,57 @@
1
+ import type { EcoPagesAppConfig } from '../internal-types.js';
2
+ import type { StaticRoute } from '../public-types.js';
3
+ import type { RouteRendererFactory } from '../route-renderer/route-renderer.js';
4
+ import type { FSRouter } from '../router/fs-router.js';
5
+ export declare const STATIC_SITE_GENERATOR_ERRORS: {
6
+ readonly ROUTE_RENDERER_FACTORY_REQUIRED: "RouteRendererFactory is required for render strategy";
7
+ readonly unsupportedBodyType: (bodyType: string) => string;
8
+ readonly missingIntegration: (routePath: string) => string;
9
+ readonly noRendererForIntegration: (integrationName: string) => string;
10
+ readonly dynamicRouteRequiresStaticPaths: (routePath: string) => string;
11
+ };
12
+ export declare class StaticSiteGenerator {
13
+ appConfig: EcoPagesAppConfig;
14
+ constructor({ appConfig }: {
15
+ appConfig: EcoPagesAppConfig;
16
+ });
17
+ generateRobotsTxt(): void;
18
+ isRootDir(path: string): boolean | null;
19
+ getDirectories(routes: string[]): string[];
20
+ /**
21
+ * Extracts dynamic parameters from the actual path based on the template path.
22
+ *
23
+ * @param templatePath - The template path (e.g., "/blog/[slug]")
24
+ * @param actualPath - The actual path (e.g., "/blog/my-post")
25
+ * @returns A record of extracted parameters (e.g., { slug: "my-post" })
26
+ */
27
+ private extractParams;
28
+ generateStaticPages(router: FSRouter, baseUrl: string, routeRendererFactory?: RouteRendererFactory): Promise<void>;
29
+ run({ router, baseUrl, routeRendererFactory, staticRoutes, }: {
30
+ router: FSRouter;
31
+ baseUrl: string;
32
+ routeRendererFactory?: RouteRendererFactory;
33
+ staticRoutes?: StaticRoute[];
34
+ }): Promise<void>;
35
+ /**
36
+ * Generates static pages from explicit static routes registered via app.static().
37
+ * These routes use eco.page views via loader functions for HMR support.
38
+ */
39
+ private generateExplicitStaticPages;
40
+ /**
41
+ * Generate a single static page for a non-dynamic route.
42
+ */
43
+ private generateSingleStaticRoute;
44
+ /**
45
+ * Generate static pages for a dynamic route using staticPaths.
46
+ */
47
+ private generateDynamicStaticRoute;
48
+ /**
49
+ * Resolve a route path template with actual params.
50
+ * Supports both :param and [param] syntax.
51
+ */
52
+ private resolveRoutePath;
53
+ /**
54
+ * Get the output file path for a given route.
55
+ */
56
+ private getOutputPath;
57
+ }
@@ -0,0 +1,272 @@
1
+ import path from "node:path";
2
+ import { appLogger } from "../global/app-logger.js";
3
+ import { fileSystem } from "@ecopages/file-system";
4
+ import { PathUtils } from "../utils/path-utils.module.js";
5
+ const STATIC_SITE_GENERATOR_ERRORS = {
6
+ ROUTE_RENDERER_FACTORY_REQUIRED: "RouteRendererFactory is required for render strategy",
7
+ unsupportedBodyType: (bodyType) => `Unsupported body type for static generation: ${bodyType}`,
8
+ missingIntegration: (routePath) => `View at ${routePath} is missing __eco.integration. Ensure it's defined with eco.page().`,
9
+ noRendererForIntegration: (integrationName) => `No renderer found for integration: ${integrationName}`,
10
+ dynamicRouteRequiresStaticPaths: (routePath) => `Dynamic route ${routePath} requires staticPaths to be defined on the view.`
11
+ };
12
+ class StaticSiteGenerator {
13
+ appConfig;
14
+ constructor({ appConfig }) {
15
+ this.appConfig = appConfig;
16
+ }
17
+ generateRobotsTxt() {
18
+ let data = "";
19
+ const preferences = this.appConfig.robotsTxt.preferences;
20
+ for (const userAgent in preferences) {
21
+ data += `user-agent: ${userAgent}
22
+ `;
23
+ for (const path2 of preferences[userAgent]) {
24
+ data += `disallow: ${path2}
25
+ `;
26
+ }
27
+ data += "\n";
28
+ }
29
+ fileSystem.ensureDir(this.appConfig.distDir);
30
+ fileSystem.write(`${this.appConfig.distDir}/robots.txt`, data);
31
+ }
32
+ isRootDir(path2) {
33
+ const slashes = path2.match(/\//g);
34
+ return slashes && slashes.length === 1;
35
+ }
36
+ getDirectories(routes) {
37
+ const directories = /* @__PURE__ */ new Set();
38
+ for (const route of routes) {
39
+ const path2 = route.startsWith("http") ? new URL(route).pathname : route;
40
+ const segments = path2.split("/");
41
+ if (segments.length > 2) {
42
+ directories.add(segments.slice(0, segments.length - 1).join("/"));
43
+ }
44
+ }
45
+ return Array.from(directories);
46
+ }
47
+ /**
48
+ * Extracts dynamic parameters from the actual path based on the template path.
49
+ *
50
+ * @param templatePath - The template path (e.g., "/blog/[slug]")
51
+ * @param actualPath - The actual path (e.g., "/blog/my-post")
52
+ * @returns A record of extracted parameters (e.g., { slug: "my-post" })
53
+ */
54
+ extractParams(templatePath, actualPath) {
55
+ const templateSegments = templateSegmentsFromPath(templatePath);
56
+ const actualSegments = templateSegmentsFromPath(actualPath);
57
+ const params = {};
58
+ for (let i = 0; i < templateSegments.length; i++) {
59
+ const segment = templateSegments[i];
60
+ if (segment.startsWith("[") && segment.endsWith("]")) {
61
+ const paramName = segment.slice(1, -1).replace("...", "");
62
+ params[paramName] = actualSegments[i];
63
+ }
64
+ }
65
+ return params;
66
+ }
67
+ async generateStaticPages(router, baseUrl, routeRendererFactory) {
68
+ const routes = Object.keys(router.routes).filter((route) => !route.includes("["));
69
+ appLogger.debug("Static Pages", routes);
70
+ const directories = this.getDirectories(routes);
71
+ for (const directory of directories) {
72
+ fileSystem.ensureDir(path.join(this.appConfig.rootDir, this.appConfig.distDir, directory));
73
+ }
74
+ for (const route of routes) {
75
+ try {
76
+ const { filePath, pathname: routePathname } = router.routes[route];
77
+ const ext = PathUtils.getEcoTemplateExtension(filePath);
78
+ const integration = this.appConfig.integrations.find((plugin) => plugin.extensions.includes(ext));
79
+ const strategy = integration?.staticBuildStep || "render";
80
+ let contents;
81
+ if (strategy === "fetch") {
82
+ const fetchUrl = route.startsWith("http") ? route : `${baseUrl}${route}`;
83
+ const response = await fetch(fetchUrl);
84
+ if (!response.ok) {
85
+ appLogger.error(`Failed to fetch ${fetchUrl}. Status: ${response.status}`);
86
+ continue;
87
+ }
88
+ contents = await response.text();
89
+ } else {
90
+ if (!routeRendererFactory) {
91
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.ROUTE_RENDERER_FACTORY_REQUIRED);
92
+ }
93
+ let pathname2 = routePathname;
94
+ const pathnameSegments2 = pathname2.split("/").filter(Boolean);
95
+ if (pathname2 === "/") {
96
+ pathname2 = "/index.html";
97
+ } else if (pathnameSegments2.join("/").includes("[")) {
98
+ pathname2 = `${route.replace(router.origin, "")}.html`;
99
+ } else if (pathnameSegments2.length >= 1 && directories.includes(`/${pathnameSegments2.join("/")}`)) {
100
+ pathname2 = `${pathname2.endsWith("/") ? pathname2 : `${pathname2}/`}index.html`;
101
+ } else {
102
+ pathname2 += ".html";
103
+ }
104
+ const renderer = routeRendererFactory.createRenderer(filePath);
105
+ const params = this.extractParams(routePathname, pathname2.replace(".html", ""));
106
+ const result = await renderer.createRoute({
107
+ file: filePath,
108
+ params
109
+ });
110
+ const body = result.body;
111
+ if (typeof body === "string" || Buffer.isBuffer(body)) {
112
+ contents = body;
113
+ } else if (body instanceof ReadableStream) {
114
+ contents = await new Response(body).text();
115
+ } else {
116
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.unsupportedBodyType(typeof body));
117
+ }
118
+ }
119
+ let pathname = routePathname;
120
+ const pathnameSegments = pathname.split("/").filter(Boolean);
121
+ if (pathname === "/") {
122
+ pathname = "/index.html";
123
+ } else if (pathnameSegments.join("/").includes("[")) {
124
+ pathname = `${route.replace(router.origin, "")}.html`;
125
+ } else if (pathnameSegments.length >= 1 && directories.includes(`/${pathnameSegments.join("/")}`)) {
126
+ pathname = `${pathname.endsWith("/") ? pathname : `${pathname}/`}index.html`;
127
+ } else {
128
+ pathname += ".html";
129
+ }
130
+ const outputPath = path.join(this.appConfig.rootDir, this.appConfig.distDir, pathname);
131
+ fileSystem.write(outputPath, contents);
132
+ } catch (error) {
133
+ appLogger.error(
134
+ `Error generating static page for ${route}:`,
135
+ error instanceof Error ? error : String(error)
136
+ );
137
+ }
138
+ }
139
+ }
140
+ async run({
141
+ router,
142
+ baseUrl,
143
+ routeRendererFactory,
144
+ staticRoutes
145
+ }) {
146
+ this.generateRobotsTxt();
147
+ await this.generateStaticPages(router, baseUrl, routeRendererFactory);
148
+ if (staticRoutes && staticRoutes.length > 0 && routeRendererFactory) {
149
+ await this.generateExplicitStaticPages(staticRoutes, routeRendererFactory);
150
+ }
151
+ }
152
+ /**
153
+ * Generates static pages from explicit static routes registered via app.static().
154
+ * These routes use eco.page views via loader functions for HMR support.
155
+ */
156
+ async generateExplicitStaticPages(staticRoutes, routeRendererFactory) {
157
+ appLogger.debug(
158
+ "Generating explicit static routes",
159
+ staticRoutes.map((r) => r.path)
160
+ );
161
+ for (const route of staticRoutes) {
162
+ try {
163
+ const mod = await route.loader();
164
+ const view = mod.default;
165
+ const isDynamic = route.path.includes(":") || route.path.includes("[");
166
+ if (isDynamic) {
167
+ await this.generateDynamicStaticRoute(route.path, view, routeRendererFactory);
168
+ } else {
169
+ await this.generateSingleStaticRoute(route.path, view, routeRendererFactory);
170
+ }
171
+ } catch (error) {
172
+ appLogger.error(
173
+ `Error generating explicit static page for ${route.path}:`,
174
+ error instanceof Error ? error : String(error)
175
+ );
176
+ }
177
+ }
178
+ }
179
+ /**
180
+ * Generate a single static page for a non-dynamic route.
181
+ */
182
+ async generateSingleStaticRoute(routePath, view, routeRendererFactory) {
183
+ const integrationName = view.config?.__eco?.integration;
184
+ if (!integrationName) {
185
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.missingIntegration(routePath));
186
+ }
187
+ const renderer = routeRendererFactory.getRendererByIntegration(integrationName);
188
+ if (!renderer) {
189
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.noRendererForIntegration(integrationName));
190
+ }
191
+ const props = view.staticProps ? (await view.staticProps({
192
+ pathname: { params: {} },
193
+ appConfig: this.appConfig,
194
+ runtimeOrigin: this.appConfig.baseUrl
195
+ })).props : {};
196
+ const response = await renderer.renderToResponse(view, props, {});
197
+ const contents = await response.text();
198
+ const outputPath = this.getOutputPath(routePath);
199
+ fileSystem.ensureDir(path.dirname(outputPath));
200
+ fileSystem.write(outputPath, contents);
201
+ appLogger.debug(`Generated static page: ${routePath} -> ${outputPath}`);
202
+ }
203
+ /**
204
+ * Generate static pages for a dynamic route using staticPaths.
205
+ */
206
+ async generateDynamicStaticRoute(routePath, view, routeRendererFactory) {
207
+ if (!view.staticPaths) {
208
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.dynamicRouteRequiresStaticPaths(routePath));
209
+ }
210
+ const integrationName = view.config?.__eco?.integration;
211
+ if (!integrationName) {
212
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.missingIntegration(routePath));
213
+ }
214
+ const renderer = routeRendererFactory.getRendererByIntegration(integrationName);
215
+ if (!renderer) {
216
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.noRendererForIntegration(integrationName));
217
+ }
218
+ const { paths } = await view.staticPaths({
219
+ appConfig: this.appConfig,
220
+ runtimeOrigin: this.appConfig.baseUrl
221
+ });
222
+ for (const { params } of paths) {
223
+ const resolvedPath = this.resolveRoutePath(routePath, params);
224
+ const props = view.staticProps ? (await view.staticProps({
225
+ pathname: { params },
226
+ appConfig: this.appConfig,
227
+ runtimeOrigin: this.appConfig.baseUrl
228
+ })).props : {};
229
+ const response = await renderer.renderToResponse(view, props, {});
230
+ const contents = await response.text();
231
+ const outputPath = this.getOutputPath(resolvedPath);
232
+ fileSystem.ensureDir(path.dirname(outputPath));
233
+ fileSystem.write(outputPath, contents);
234
+ appLogger.debug(`Generated static page: ${resolvedPath} -> ${outputPath}`);
235
+ }
236
+ }
237
+ /**
238
+ * Resolve a route path template with actual params.
239
+ * Supports both :param and [param] syntax.
240
+ */
241
+ resolveRoutePath(routePath, params) {
242
+ let resolved = routePath;
243
+ for (const [key, value] of Object.entries(params)) {
244
+ const paramValue = Array.isArray(value) ? value.join("/") : value;
245
+ resolved = resolved.replace(`:${key}`, paramValue);
246
+ resolved = resolved.replace(`[${key}]`, paramValue);
247
+ resolved = resolved.replace(`[...${key}]`, paramValue);
248
+ }
249
+ return resolved;
250
+ }
251
+ /**
252
+ * Get the output file path for a given route.
253
+ */
254
+ getOutputPath(routePath) {
255
+ let outputName;
256
+ if (routePath === "/") {
257
+ outputName = "index.html";
258
+ } else if (routePath.endsWith("/")) {
259
+ outputName = `${routePath}index.html`;
260
+ } else {
261
+ outputName = `${routePath}.html`;
262
+ }
263
+ return path.join(this.appConfig.rootDir, this.appConfig.distDir, outputName);
264
+ }
265
+ }
266
+ function templateSegmentsFromPath(path2) {
267
+ return path2.split("/").filter(Boolean);
268
+ }
269
+ export {
270
+ STATIC_SITE_GENERATOR_ERRORS,
271
+ StaticSiteGenerator
272
+ };
@@ -0,0 +1,359 @@
1
+ import path from 'node:path';
2
+ import { appLogger } from '../global/app-logger.ts';
3
+ import type { EcoPagesAppConfig } from '../internal-types.ts';
4
+ import type { EcoPageComponent, StaticRoute } from '../public-types.ts';
5
+ import type { RouteRendererFactory } from '../route-renderer/route-renderer.ts';
6
+ import type { FSRouter } from '../router/fs-router.ts';
7
+ import { fileSystem } from '@ecopages/file-system';
8
+ import { PathUtils } from '../utils/path-utils.module.ts';
9
+
10
+ export const STATIC_SITE_GENERATOR_ERRORS = {
11
+ ROUTE_RENDERER_FACTORY_REQUIRED: 'RouteRendererFactory is required for render strategy',
12
+ unsupportedBodyType: (bodyType: string) => `Unsupported body type for static generation: ${bodyType}`,
13
+ missingIntegration: (routePath: string) =>
14
+ `View at ${routePath} is missing __eco.integration. Ensure it's defined with eco.page().`,
15
+ noRendererForIntegration: (integrationName: string) => `No renderer found for integration: ${integrationName}`,
16
+ dynamicRouteRequiresStaticPaths: (routePath: string) =>
17
+ `Dynamic route ${routePath} requires staticPaths to be defined on the view.`,
18
+ } as const;
19
+
20
+ export class StaticSiteGenerator {
21
+ appConfig: EcoPagesAppConfig;
22
+
23
+ constructor({ appConfig }: { appConfig: EcoPagesAppConfig }) {
24
+ this.appConfig = appConfig;
25
+ }
26
+
27
+ generateRobotsTxt(): void {
28
+ let data = '';
29
+ const preferences = this.appConfig.robotsTxt.preferences;
30
+
31
+ for (const userAgent in preferences) {
32
+ data += `user-agent: ${userAgent}\n`;
33
+ for (const path of preferences[userAgent]) {
34
+ data += `disallow: ${path}\n`;
35
+ }
36
+ data += '\n';
37
+ }
38
+
39
+ fileSystem.ensureDir(this.appConfig.distDir);
40
+ fileSystem.write(`${this.appConfig.distDir}/robots.txt`, data);
41
+ }
42
+
43
+ isRootDir(path: string) {
44
+ const slashes = path.match(/\//g);
45
+ return slashes && slashes.length === 1;
46
+ }
47
+
48
+ getDirectories(routes: string[]) {
49
+ const directories = new Set<string>();
50
+
51
+ for (const route of routes) {
52
+ const path = route.startsWith('http') ? new URL(route).pathname : route;
53
+
54
+ const segments = path.split('/');
55
+
56
+ if (segments.length > 2) {
57
+ directories.add(segments.slice(0, segments.length - 1).join('/'));
58
+ }
59
+ }
60
+
61
+ return Array.from(directories);
62
+ }
63
+
64
+ /**
65
+ * Extracts dynamic parameters from the actual path based on the template path.
66
+ *
67
+ * @param templatePath - The template path (e.g., "/blog/[slug]")
68
+ * @param actualPath - The actual path (e.g., "/blog/my-post")
69
+ * @returns A record of extracted parameters (e.g., { slug: "my-post" })
70
+ */
71
+ private extractParams(templatePath: string, actualPath: string): Record<string, string> {
72
+ const templateSegments = templateSegmentsFromPath(templatePath);
73
+ const actualSegments = templateSegmentsFromPath(actualPath);
74
+ const params: Record<string, string> = {};
75
+
76
+ for (let i = 0; i < templateSegments.length; i++) {
77
+ const segment = templateSegments[i];
78
+ if (segment.startsWith('[') && segment.endsWith(']')) {
79
+ const paramName = segment.slice(1, -1).replace('...', '');
80
+ params[paramName] = actualSegments[i];
81
+ }
82
+ }
83
+
84
+ return params;
85
+ }
86
+
87
+ async generateStaticPages(router: FSRouter, baseUrl: string, routeRendererFactory?: RouteRendererFactory) {
88
+ const routes = Object.keys(router.routes).filter((route) => !route.includes('['));
89
+
90
+ appLogger.debug('Static Pages', routes);
91
+
92
+ const directories = this.getDirectories(routes);
93
+
94
+ for (const directory of directories) {
95
+ fileSystem.ensureDir(path.join(this.appConfig.rootDir, this.appConfig.distDir, directory));
96
+ }
97
+
98
+ for (const route of routes) {
99
+ try {
100
+ const { filePath, pathname: routePathname } = router.routes[route];
101
+ const ext = PathUtils.getEcoTemplateExtension(filePath);
102
+ const integration = this.appConfig.integrations.find((plugin) => plugin.extensions.includes(ext));
103
+ const strategy = integration?.staticBuildStep || 'render';
104
+
105
+ let contents: string | Buffer;
106
+
107
+ if (strategy === 'fetch') {
108
+ const fetchUrl = route.startsWith('http') ? route : `${baseUrl}${route}`;
109
+ const response = await fetch(fetchUrl);
110
+
111
+ if (!response.ok) {
112
+ appLogger.error(`Failed to fetch ${fetchUrl}. Status: ${response.status}`);
113
+ continue;
114
+ }
115
+ contents = await response.text();
116
+ } else {
117
+ if (!routeRendererFactory) {
118
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.ROUTE_RENDERER_FACTORY_REQUIRED);
119
+ }
120
+
121
+ let pathname = routePathname;
122
+ const pathnameSegments = pathname.split('/').filter(Boolean);
123
+
124
+ if (pathname === '/') {
125
+ pathname = '/index.html';
126
+ } else if (pathnameSegments.join('/').includes('[')) {
127
+ pathname = `${route.replace(router.origin, '')}.html`;
128
+ } else if (pathnameSegments.length >= 1 && directories.includes(`/${pathnameSegments.join('/')}`)) {
129
+ pathname = `${pathname.endsWith('/') ? pathname : `${pathname}/`}index.html`;
130
+ } else {
131
+ pathname += '.html';
132
+ }
133
+
134
+ const renderer = routeRendererFactory.createRenderer(filePath);
135
+ const params = this.extractParams(routePathname, pathname.replace('.html', ''));
136
+
137
+ const result = await renderer.createRoute({
138
+ file: filePath,
139
+ params,
140
+ });
141
+
142
+ const body = result.body;
143
+
144
+ if (typeof body === 'string' || Buffer.isBuffer(body)) {
145
+ contents = body;
146
+ } else if (body instanceof ReadableStream) {
147
+ contents = await new Response(body).text();
148
+ } else {
149
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.unsupportedBodyType(typeof body));
150
+ }
151
+ }
152
+
153
+ let pathname = routePathname;
154
+ const pathnameSegments = pathname.split('/').filter(Boolean);
155
+
156
+ if (pathname === '/') {
157
+ pathname = '/index.html';
158
+ } else if (pathnameSegments.join('/').includes('[')) {
159
+ pathname = `${route.replace(router.origin, '')}.html`;
160
+ } else if (pathnameSegments.length >= 1 && directories.includes(`/${pathnameSegments.join('/')}`)) {
161
+ pathname = `${pathname.endsWith('/') ? pathname : `${pathname}/`}index.html`;
162
+ } else {
163
+ pathname += '.html';
164
+ }
165
+
166
+ const outputPath = path.join(this.appConfig.rootDir, this.appConfig.distDir, pathname);
167
+ fileSystem.write(outputPath, contents);
168
+ } catch (error) {
169
+ appLogger.error(
170
+ `Error generating static page for ${route}:`,
171
+ error instanceof Error ? error : String(error),
172
+ );
173
+ }
174
+ }
175
+ }
176
+
177
+ async run({
178
+ router,
179
+ baseUrl,
180
+ routeRendererFactory,
181
+ staticRoutes,
182
+ }: {
183
+ router: FSRouter;
184
+ baseUrl: string;
185
+ routeRendererFactory?: RouteRendererFactory;
186
+ staticRoutes?: StaticRoute[];
187
+ }) {
188
+ this.generateRobotsTxt();
189
+ await this.generateStaticPages(router, baseUrl, routeRendererFactory);
190
+
191
+ if (staticRoutes && staticRoutes.length > 0 && routeRendererFactory) {
192
+ await this.generateExplicitStaticPages(staticRoutes, routeRendererFactory);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Generates static pages from explicit static routes registered via app.static().
198
+ * These routes use eco.page views via loader functions for HMR support.
199
+ */
200
+ private async generateExplicitStaticPages(
201
+ staticRoutes: StaticRoute[],
202
+ routeRendererFactory: RouteRendererFactory,
203
+ ): Promise<void> {
204
+ appLogger.debug(
205
+ 'Generating explicit static routes',
206
+ staticRoutes.map((r) => r.path),
207
+ );
208
+
209
+ for (const route of staticRoutes) {
210
+ try {
211
+ const mod = await route.loader();
212
+ const view = mod.default;
213
+
214
+ const isDynamic = route.path.includes(':') || route.path.includes('[');
215
+
216
+ if (isDynamic) {
217
+ await this.generateDynamicStaticRoute(route.path, view, routeRendererFactory);
218
+ } else {
219
+ await this.generateSingleStaticRoute(route.path, view, routeRendererFactory);
220
+ }
221
+ } catch (error) {
222
+ appLogger.error(
223
+ `Error generating explicit static page for ${route.path}:`,
224
+ error instanceof Error ? error : String(error),
225
+ );
226
+ }
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Generate a single static page for a non-dynamic route.
232
+ */
233
+ private async generateSingleStaticRoute(
234
+ routePath: string,
235
+ view: EcoPageComponent<any>,
236
+ routeRendererFactory: RouteRendererFactory,
237
+ ): Promise<void> {
238
+ const integrationName = view.config?.__eco?.integration;
239
+ if (!integrationName) {
240
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.missingIntegration(routePath));
241
+ }
242
+
243
+ const renderer = routeRendererFactory.getRendererByIntegration(integrationName);
244
+ if (!renderer) {
245
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.noRendererForIntegration(integrationName));
246
+ }
247
+
248
+ const props = view.staticProps
249
+ ? (
250
+ await view.staticProps({
251
+ pathname: { params: {} },
252
+ appConfig: this.appConfig,
253
+ runtimeOrigin: this.appConfig.baseUrl,
254
+ })
255
+ ).props
256
+ : {};
257
+
258
+ const response = await renderer.renderToResponse(view, props, {});
259
+ const contents = await response.text();
260
+
261
+ const outputPath = this.getOutputPath(routePath);
262
+ fileSystem.ensureDir(path.dirname(outputPath));
263
+ fileSystem.write(outputPath, contents);
264
+
265
+ appLogger.debug(`Generated static page: ${routePath} -> ${outputPath}`);
266
+ }
267
+
268
+ /**
269
+ * Generate static pages for a dynamic route using staticPaths.
270
+ */
271
+ private async generateDynamicStaticRoute(
272
+ routePath: string,
273
+ view: EcoPageComponent<any>,
274
+ routeRendererFactory: RouteRendererFactory,
275
+ ): Promise<void> {
276
+ if (!view.staticPaths) {
277
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.dynamicRouteRequiresStaticPaths(routePath));
278
+ }
279
+
280
+ const integrationName = view.config?.__eco?.integration;
281
+ if (!integrationName) {
282
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.missingIntegration(routePath));
283
+ }
284
+
285
+ const renderer = routeRendererFactory.getRendererByIntegration(integrationName);
286
+ if (!renderer) {
287
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.noRendererForIntegration(integrationName));
288
+ }
289
+
290
+ const { paths } = await view.staticPaths({
291
+ appConfig: this.appConfig,
292
+ runtimeOrigin: this.appConfig.baseUrl,
293
+ });
294
+
295
+ for (const { params } of paths) {
296
+ const resolvedPath = this.resolveRoutePath(routePath, params);
297
+
298
+ const props = view.staticProps
299
+ ? (
300
+ await view.staticProps({
301
+ pathname: { params },
302
+ appConfig: this.appConfig,
303
+ runtimeOrigin: this.appConfig.baseUrl,
304
+ })
305
+ ).props
306
+ : {};
307
+
308
+ const response = await renderer.renderToResponse(view, props, {});
309
+ const contents = await response.text();
310
+
311
+ const outputPath = this.getOutputPath(resolvedPath);
312
+ fileSystem.ensureDir(path.dirname(outputPath));
313
+ fileSystem.write(outputPath, contents);
314
+
315
+ appLogger.debug(`Generated static page: ${resolvedPath} -> ${outputPath}`);
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Resolve a route path template with actual params.
321
+ * Supports both :param and [param] syntax.
322
+ */
323
+ private resolveRoutePath(routePath: string, params: Record<string, string | string[]>): string {
324
+ let resolved = routePath;
325
+
326
+ for (const [key, value] of Object.entries(params)) {
327
+ const paramValue = Array.isArray(value) ? value.join('/') : value;
328
+ resolved = resolved.replace(`:${key}`, paramValue);
329
+ resolved = resolved.replace(`[${key}]`, paramValue);
330
+ resolved = resolved.replace(`[...${key}]`, paramValue);
331
+ }
332
+
333
+ return resolved;
334
+ }
335
+
336
+ /**
337
+ * Get the output file path for a given route.
338
+ */
339
+ private getOutputPath(routePath: string): string {
340
+ let outputName: string;
341
+
342
+ if (routePath === '/') {
343
+ outputName = 'index.html';
344
+ } else if (routePath.endsWith('/')) {
345
+ outputName = `${routePath}index.html`;
346
+ } else {
347
+ outputName = `${routePath}.html`;
348
+ }
349
+
350
+ return path.join(this.appConfig.rootDir, this.appConfig.distDir, outputName);
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Splits a path into segments, filtering out empty strings.
356
+ */
357
+ function templateSegmentsFromPath(path: string) {
358
+ return path.split('/').filter(Boolean);
359
+ }
@@ -0,0 +1 @@
1
+ export declare const css: (strings: TemplateStringsArray, ...values: any[]) => Promise<string>;
@@ -0,0 +1,7 @@
1
+ const css = async (strings, ...values) => {
2
+ const css2 = strings.reduce((acc, str, i) => acc + str + (values[i] || ""), "");
3
+ return css2;
4
+ };
5
+ export {
6
+ css
7
+ };