@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,227 @@
1
+ /**
2
+ * This module contains the ConfigBuilder class, which is used to build the EcoPagesAppConfig object.
3
+ * @module
4
+ */
5
+ import type { EcoBuildPlugin } from '../build/build-types.js';
6
+ import type { EcoPagesAppConfig, IncludesTemplates, RobotsPreference } from '../internal-types.js';
7
+ import type { IntegrationPlugin } from '../plugins/integration-plugin.js';
8
+ import type { Processor } from '../plugins/processor.js';
9
+ import type { PageMetadataProps } from '../public-types.js';
10
+ import type { CacheConfig } from '../services/cache/cache.types.js';
11
+ export declare const CONFIG_BUILDER_ERRORS: {
12
+ readonly DUPLICATE_INTEGRATION_NAMES: "Integrations names must be unique";
13
+ readonly DUPLICATE_INTEGRATION_EXTENSIONS: "Integrations extensions must be unique";
14
+ readonly MIXED_JSX_ENGINES: "Both kitajs and react integrations are enabled. Use per-file JSX import source/pragma consistently (e.g. `/** @jsxImportSource react */` for React files and `/** @jsxImportSource @kitajs/html */` for Kita files).";
15
+ readonly duplicateProcessorName: (name: string) => string;
16
+ readonly duplicateLoaderName: (name: string) => string;
17
+ };
18
+ /**
19
+ * A builder class for creating and configuring EcoPages application configuration.
20
+ * Provides a fluent interface for setting various configuration options and managing
21
+ * application settings.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const config = new ConfigBuilder()
26
+ * .setBaseUrl('https://example.com')
27
+ * .setRootDir('./myproject')
28
+ * .setSrcDir('source')
29
+ * .build();
30
+ * ```
31
+ *
32
+ * @remarks
33
+ * The ConfigBuilder follows the builder pattern and allows for:
34
+ * - Setting directory paths for various components (pages, includes, layouts, etc.)
35
+ * - Configuring templates and includes
36
+ * - Managing integrations and plugins
37
+ * - Setting up processors and loaders
38
+ * - Configuring API handlers
39
+ * - Managing metadata and robots.txt preferences
40
+ *
41
+ * All setter methods return the instance of the builder for method chaining.
42
+ * The configuration is finalized by calling the `build()` method, which performs
43
+ * validation and initialization of the configuration.
44
+ *
45
+ * @throws {Error} When building configuration without required fields (e.g., baseUrl)
46
+ * @throws {Error} When adding duplicate processors or loaders
47
+ */
48
+ export declare class ConfigBuilder {
49
+ config: EcoPagesAppConfig;
50
+ /**
51
+ * Sets the base URL for the application.
52
+ * This URL is used as the root URL for all pages and assets.
53
+ *
54
+ * @param baseUrl - The base URL for the application (e.g., 'https://example.com')
55
+ * @returns The ConfigBuilder instance for method chaining
56
+ */
57
+ setBaseUrl(baseUrl: string): this;
58
+ /**
59
+ * Sets the root directory of the project.
60
+ * This is the base directory from which all other paths are resolved.
61
+ *
62
+ * @param rootDir - The root directory path
63
+ * @returns The ConfigBuilder instance for method chaining
64
+ */
65
+ setRootDir(rootDir: string): this;
66
+ /**
67
+ * Sets the source directory relative to the root directory.
68
+ * This directory contains all the source files for the application.
69
+ *
70
+ * @param srcDir - The source directory name (default: 'src')
71
+ * @returns The ConfigBuilder instance for method chaining
72
+ */
73
+ setSrcDir(srcDir: string): this;
74
+ /**
75
+ * Sets the pages directory relative to the source directory.
76
+ * This directory contains all the page files for the application.
77
+ *
78
+ * @param pagesDir - The pages directory name (default: 'pages')
79
+ * @returns The ConfigBuilder instance for method chaining
80
+ */
81
+ setPagesDir(pagesDir: string): this;
82
+ /**
83
+ * Sets the includes directory relative to the source directory.
84
+ * This directory contains template includes and partials.
85
+ *
86
+ * @param includesDir - The includes directory name (default: 'includes')
87
+ * @returns The ConfigBuilder instance for method chaining
88
+ */
89
+ setIncludesDir(includesDir: string): this;
90
+ /**
91
+ * Sets the components directory relative to the source directory.
92
+ * This directory contains reusable components.
93
+ *
94
+ * @param componentsDir - The components directory name (default: 'components')
95
+ * @returns The ConfigBuilder instance for method chaining
96
+ */
97
+ setComponentsDir(componentsDir: string): this;
98
+ /**
99
+ * Sets the layouts directory relative to the source directory.
100
+ * This directory contains layout templates.
101
+ *
102
+ * @param layoutsDir - The layouts directory name (default: 'layouts')
103
+ * @returns The ConfigBuilder instance for method chaining
104
+ */
105
+ setLayoutsDir(layoutsDir: string): this;
106
+ /**
107
+ * Sets the public directory relative to the source directory.
108
+ * This directory contains static assets that should be served as-is.
109
+ *
110
+ * @param publicDir - The public directory name (default: 'public')
111
+ * @returns The ConfigBuilder instance for method chaining
112
+ */
113
+ setPublicDir(publicDir: string): this;
114
+ /**
115
+ * Sets the templates used for includes.
116
+ * These templates are used to build the HTML structure of pages.
117
+ *
118
+ * @param includesTemplates - An object containing the template file names
119
+ * @returns The ConfigBuilder instance for method chaining
120
+ */
121
+ setIncludesTemplates(includesTemplates: IncludesTemplates): this;
122
+ /**
123
+ * Sets the template file for the 404 error page.
124
+ *
125
+ * @param error404Template - The file name of the 404 error template (default: '404.ghtml.ts')
126
+ * @returns The ConfigBuilder instance for method chaining
127
+ */
128
+ setError404Template(error404Template: string): this;
129
+ /**
130
+ * Sets the robots.txt configuration.
131
+ * This determines which paths are allowed/disallowed for search engines.
132
+ *
133
+ * @param robotsTxt - The robots.txt configuration object
134
+ * @returns The ConfigBuilder instance for method chaining
135
+ */
136
+ setRobotsTxt(robotsTxt: {
137
+ preferences: RobotsPreference;
138
+ }): this;
139
+ /**
140
+ * Sets the integration plugins to use.
141
+ * These plugins provide additional functionality to the application.
142
+ *
143
+ * @param integrations - An array of integration plugins
144
+ * @returns The ConfigBuilder instance for method chaining
145
+ */
146
+ setIntegrations(integrations: IntegrationPlugin<unknown>[]): this;
147
+ /**
148
+ * Sets the output directory for the built application.
149
+ *
150
+ * @param distDir - The distribution directory name (default: '.eco')
151
+ * @returns The ConfigBuilder instance for method chaining
152
+ */
153
+ setDistDir(distDir: string): this;
154
+ /**
155
+ * Sets the default metadata for pages.
156
+ * This is used when a page doesn't specify its own metadata.
157
+ *
158
+ * @param defaultMetadata - The default metadata object
159
+ * @returns The ConfigBuilder instance for method chaining
160
+ */
161
+ setDefaultMetadata(defaultMetadata: PageMetadataProps): this;
162
+ /**
163
+ * Sets additional paths to watch for changes during development.
164
+ *
165
+ * @param additionalWatchPaths - An array of additional paths to watch
166
+ * @returns The ConfigBuilder instance for method chaining
167
+ */
168
+ setAdditionalWatchPaths(additionalWatchPaths: string[]): this;
169
+ /**
170
+ * Sets the processors to use for the application.
171
+ * This replaces any existing processors.
172
+ *
173
+ * @param processors - An array of processors
174
+ * @returns The ConfigBuilder instance for method chaining
175
+ */
176
+ setProcessors(processors: Processor<any>[]): this;
177
+ /**
178
+ * Adds a processor to the application.
179
+ *
180
+ * @param processor - The processor to add
181
+ * @returns The ConfigBuilder instance for method chaining
182
+ * @throws Error if a processor with the same name already exists
183
+ */
184
+ addProcessor(processor: Processor): this;
185
+ /**
186
+ * Sets the loaders to use for the application.
187
+ * This replaces any existing loaders.
188
+ *
189
+ * @param loaders - An array of build plugins to use as loaders
190
+ * @returns The ConfigBuilder instance for method chaining
191
+ */
192
+ setLoaders(loaders: EcoBuildPlugin[]): this;
193
+ /**
194
+ * Adds a loader to the application.
195
+ *
196
+ * @param name - The name of the loader
197
+ * @param loader - The build plugin to use as a loader
198
+ * @returns The ConfigBuilder instance for method chaining
199
+ * @throws Error if a loader with the same name already exists
200
+ */
201
+ addLoader(name: string, loader: EcoBuildPlugin): this;
202
+ /**
203
+ * Sets the cache configuration for ISR and page caching.
204
+ *
205
+ * @param cacheConfig - The cache configuration object
206
+ * @returns The ConfigBuilder instance for method chaining
207
+ */
208
+ setCacheConfig(cacheConfig: CacheConfig): this;
209
+ setExperimental(experimental: NonNullable<EcoPagesAppConfig['experimental']>): this;
210
+ private createAbsolutePaths;
211
+ private createIntegrationTemplatesExt;
212
+ private initializeProcessors;
213
+ /**
214
+ * Initializes default loaders that are required for EcoPages to function.
215
+ * This includes the eco-component-meta-plugin which auto-injects __eco metadata into component configs.
216
+ */
217
+ private initializeDefaultLoaders;
218
+ private reviewBaseUrl;
219
+ /**
220
+ * Builds and returns the final configuration object.
221
+ * This performs validation and initialization of the configuration.
222
+ *
223
+ * @returns A promise that resolves to the final EcoPagesAppConfig
224
+ * @throws Error if required configuration is missing (e.g., baseUrl)
225
+ */
226
+ build(): Promise<EcoPagesAppConfig>;
227
+ }
@@ -0,0 +1,392 @@
1
+ import path from "node:path";
2
+ import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from "../constants.js";
3
+ import { GHTML_PLUGIN_NAME, ghtmlPlugin } from "../integrations/ghtml/ghtml.plugin.js";
4
+ import { createEcoComponentMetaPlugin } from "../plugins/eco-component-meta-plugin.js";
5
+ import { invariant } from "../utils/invariant.js";
6
+ import { appLogger } from "../global/app-logger.js";
7
+ const CONFIG_BUILDER_ERRORS = {
8
+ DUPLICATE_INTEGRATION_NAMES: "Integrations names must be unique",
9
+ DUPLICATE_INTEGRATION_EXTENSIONS: "Integrations extensions must be unique",
10
+ MIXED_JSX_ENGINES: "Both kitajs and react integrations are enabled. Use per-file JSX import source/pragma consistently (e.g. `/** @jsxImportSource react */` for React files and `/** @jsxImportSource @kitajs/html */` for Kita files).",
11
+ duplicateProcessorName: (name) => `Processor with name "${name}" already exists`,
12
+ duplicateLoaderName: (name) => `Loader with name "${name}" already exists`
13
+ };
14
+ class ConfigBuilder {
15
+ config = {
16
+ baseUrl: "",
17
+ rootDir: ".",
18
+ srcDir: "src",
19
+ pagesDir: "pages",
20
+ includesDir: "includes",
21
+ componentsDir: "components",
22
+ layoutsDir: "layouts",
23
+ publicDir: "public",
24
+ includesTemplates: {
25
+ head: "head.ghtml.ts",
26
+ html: "html.ghtml.ts",
27
+ seo: "seo.ghtml.ts"
28
+ },
29
+ error404Template: "404.ghtml.ts",
30
+ robotsTxt: {
31
+ preferences: {
32
+ "*": []
33
+ }
34
+ },
35
+ integrations: [],
36
+ integrationsDependencies: [],
37
+ distDir: ".eco",
38
+ defaultMetadata: {
39
+ title: "Ecopages",
40
+ description: "This is a static site generated with Ecopages"
41
+ },
42
+ additionalWatchPaths: [],
43
+ templatesExt: [],
44
+ absolutePaths: {
45
+ config: "",
46
+ componentsDir: "",
47
+ distDir: "",
48
+ includesDir: "",
49
+ layoutsDir: "",
50
+ pagesDir: "",
51
+ projectDir: "",
52
+ publicDir: "",
53
+ srcDir: "",
54
+ htmlTemplatePath: "",
55
+ error404TemplatePath: ""
56
+ },
57
+ processors: /* @__PURE__ */ new Map(),
58
+ loaders: /* @__PURE__ */ new Map()
59
+ };
60
+ /**
61
+ * Sets the base URL for the application.
62
+ * This URL is used as the root URL for all pages and assets.
63
+ *
64
+ * @param baseUrl - The base URL for the application (e.g., 'https://example.com')
65
+ * @returns The ConfigBuilder instance for method chaining
66
+ */
67
+ setBaseUrl(baseUrl) {
68
+ this.config.baseUrl = baseUrl;
69
+ return this;
70
+ }
71
+ /**
72
+ * Sets the root directory of the project.
73
+ * This is the base directory from which all other paths are resolved.
74
+ *
75
+ * @param rootDir - The root directory path
76
+ * @returns The ConfigBuilder instance for method chaining
77
+ */
78
+ setRootDir(rootDir) {
79
+ this.config.rootDir = rootDir;
80
+ return this;
81
+ }
82
+ /**
83
+ * Sets the source directory relative to the root directory.
84
+ * This directory contains all the source files for the application.
85
+ *
86
+ * @param srcDir - The source directory name (default: 'src')
87
+ * @returns The ConfigBuilder instance for method chaining
88
+ */
89
+ setSrcDir(srcDir) {
90
+ this.config.srcDir = srcDir;
91
+ return this;
92
+ }
93
+ /**
94
+ * Sets the pages directory relative to the source directory.
95
+ * This directory contains all the page files for the application.
96
+ *
97
+ * @param pagesDir - The pages directory name (default: 'pages')
98
+ * @returns The ConfigBuilder instance for method chaining
99
+ */
100
+ setPagesDir(pagesDir) {
101
+ this.config.pagesDir = pagesDir;
102
+ return this;
103
+ }
104
+ /**
105
+ * Sets the includes directory relative to the source directory.
106
+ * This directory contains template includes and partials.
107
+ *
108
+ * @param includesDir - The includes directory name (default: 'includes')
109
+ * @returns The ConfigBuilder instance for method chaining
110
+ */
111
+ setIncludesDir(includesDir) {
112
+ this.config.includesDir = includesDir;
113
+ return this;
114
+ }
115
+ /**
116
+ * Sets the components directory relative to the source directory.
117
+ * This directory contains reusable components.
118
+ *
119
+ * @param componentsDir - The components directory name (default: 'components')
120
+ * @returns The ConfigBuilder instance for method chaining
121
+ */
122
+ setComponentsDir(componentsDir) {
123
+ this.config.componentsDir = componentsDir;
124
+ return this;
125
+ }
126
+ /**
127
+ * Sets the layouts directory relative to the source directory.
128
+ * This directory contains layout templates.
129
+ *
130
+ * @param layoutsDir - The layouts directory name (default: 'layouts')
131
+ * @returns The ConfigBuilder instance for method chaining
132
+ */
133
+ setLayoutsDir(layoutsDir) {
134
+ this.config.layoutsDir = layoutsDir;
135
+ return this;
136
+ }
137
+ /**
138
+ * Sets the public directory relative to the source directory.
139
+ * This directory contains static assets that should be served as-is.
140
+ *
141
+ * @param publicDir - The public directory name (default: 'public')
142
+ * @returns The ConfigBuilder instance for method chaining
143
+ */
144
+ setPublicDir(publicDir) {
145
+ this.config.publicDir = publicDir;
146
+ return this;
147
+ }
148
+ /**
149
+ * Sets the templates used for includes.
150
+ * These templates are used to build the HTML structure of pages.
151
+ *
152
+ * @param includesTemplates - An object containing the template file names
153
+ * @returns The ConfigBuilder instance for method chaining
154
+ */
155
+ setIncludesTemplates(includesTemplates) {
156
+ this.config.includesTemplates = includesTemplates;
157
+ return this;
158
+ }
159
+ /**
160
+ * Sets the template file for the 404 error page.
161
+ *
162
+ * @param error404Template - The file name of the 404 error template (default: '404.ghtml.ts')
163
+ * @returns The ConfigBuilder instance for method chaining
164
+ */
165
+ setError404Template(error404Template) {
166
+ this.config.error404Template = error404Template;
167
+ return this;
168
+ }
169
+ /**
170
+ * Sets the robots.txt configuration.
171
+ * This determines which paths are allowed/disallowed for search engines.
172
+ *
173
+ * @param robotsTxt - The robots.txt configuration object
174
+ * @returns The ConfigBuilder instance for method chaining
175
+ */
176
+ setRobotsTxt(robotsTxt) {
177
+ this.config.robotsTxt = robotsTxt;
178
+ return this;
179
+ }
180
+ /**
181
+ * Sets the integration plugins to use.
182
+ * These plugins provide additional functionality to the application.
183
+ *
184
+ * @param integrations - An array of integration plugins
185
+ * @returns The ConfigBuilder instance for method chaining
186
+ */
187
+ setIntegrations(integrations) {
188
+ this.config.integrations = integrations;
189
+ return this;
190
+ }
191
+ /**
192
+ * Sets the output directory for the built application.
193
+ *
194
+ * @param distDir - The distribution directory name (default: '.eco')
195
+ * @returns The ConfigBuilder instance for method chaining
196
+ */
197
+ setDistDir(distDir) {
198
+ this.config.distDir = distDir;
199
+ return this;
200
+ }
201
+ /**
202
+ * Sets the default metadata for pages.
203
+ * This is used when a page doesn't specify its own metadata.
204
+ *
205
+ * @param defaultMetadata - The default metadata object
206
+ * @returns The ConfigBuilder instance for method chaining
207
+ */
208
+ setDefaultMetadata(defaultMetadata) {
209
+ this.config.defaultMetadata = {
210
+ ...this.config.defaultMetadata,
211
+ ...defaultMetadata
212
+ };
213
+ return this;
214
+ }
215
+ /**
216
+ * Sets additional paths to watch for changes during development.
217
+ *
218
+ * @param additionalWatchPaths - An array of additional paths to watch
219
+ * @returns The ConfigBuilder instance for method chaining
220
+ */
221
+ setAdditionalWatchPaths(additionalWatchPaths) {
222
+ this.config.additionalWatchPaths = additionalWatchPaths;
223
+ return this;
224
+ }
225
+ /**
226
+ * Sets the processors to use for the application.
227
+ * This replaces any existing processors.
228
+ *
229
+ * @param processors - An array of processors
230
+ * @returns The ConfigBuilder instance for method chaining
231
+ */
232
+ setProcessors(processors) {
233
+ this.config.processors.clear();
234
+ for (const processor of processors) {
235
+ this.addProcessor(processor);
236
+ }
237
+ return this;
238
+ }
239
+ /**
240
+ * Adds a processor to the application.
241
+ *
242
+ * @param processor - The processor to add
243
+ * @returns The ConfigBuilder instance for method chaining
244
+ * @throws Error if a processor with the same name already exists
245
+ */
246
+ addProcessor(processor) {
247
+ if (this.config.processors.has(processor.name)) {
248
+ throw new Error(CONFIG_BUILDER_ERRORS.duplicateProcessorName(processor.name));
249
+ }
250
+ this.config.processors.set(processor.name, processor);
251
+ return this;
252
+ }
253
+ /**
254
+ * Sets the loaders to use for the application.
255
+ * This replaces any existing loaders.
256
+ *
257
+ * @param loaders - An array of build plugins to use as loaders
258
+ * @returns The ConfigBuilder instance for method chaining
259
+ */
260
+ setLoaders(loaders) {
261
+ this.config.loaders.clear();
262
+ for (const loader of loaders) {
263
+ this.addLoader(loader.name, loader);
264
+ }
265
+ return this;
266
+ }
267
+ /**
268
+ * Adds a loader to the application.
269
+ *
270
+ * @param name - The name of the loader
271
+ * @param loader - The build plugin to use as a loader
272
+ * @returns The ConfigBuilder instance for method chaining
273
+ * @throws Error if a loader with the same name already exists
274
+ */
275
+ addLoader(name, loader) {
276
+ if (this.config.loaders.has(name)) {
277
+ throw new Error(CONFIG_BUILDER_ERRORS.duplicateLoaderName(name));
278
+ }
279
+ this.config.loaders.set(name, loader);
280
+ return this;
281
+ }
282
+ /**
283
+ * Sets the cache configuration for ISR and page caching.
284
+ *
285
+ * @param cacheConfig - The cache configuration object
286
+ * @returns The ConfigBuilder instance for method chaining
287
+ */
288
+ setCacheConfig(cacheConfig) {
289
+ this.config.cache = cacheConfig;
290
+ return this;
291
+ }
292
+ setExperimental(experimental) {
293
+ this.config.experimental = experimental;
294
+ return this;
295
+ }
296
+ createAbsolutePaths(config) {
297
+ const {
298
+ srcDir,
299
+ componentsDir,
300
+ includesDir,
301
+ layoutsDir,
302
+ pagesDir,
303
+ publicDir,
304
+ distDir,
305
+ includesTemplates,
306
+ error404Template
307
+ } = config;
308
+ const projectDir = config.rootDir;
309
+ const absoluteSrcDir = path.resolve(projectDir, srcDir);
310
+ const absoluteDistDir = path.resolve(projectDir, distDir);
311
+ this.config.absolutePaths = {
312
+ config: path.join(projectDir, "eco.config.ts"),
313
+ projectDir,
314
+ srcDir: absoluteSrcDir,
315
+ distDir: absoluteDistDir,
316
+ componentsDir: path.join(absoluteSrcDir, componentsDir),
317
+ includesDir: path.join(absoluteSrcDir, includesDir),
318
+ layoutsDir: path.join(absoluteSrcDir, layoutsDir),
319
+ pagesDir: path.join(absoluteSrcDir, pagesDir),
320
+ publicDir: path.join(absoluteSrcDir, publicDir),
321
+ htmlTemplatePath: path.join(absoluteSrcDir, includesDir, includesTemplates.html),
322
+ error404TemplatePath: path.join(absoluteSrcDir, pagesDir, error404Template)
323
+ };
324
+ return this;
325
+ }
326
+ createIntegrationTemplatesExt(integrations) {
327
+ const integrationName = integrations.map((integration) => integration.name);
328
+ const uniqueName = new Set(integrationName);
329
+ invariant(integrationName.length === uniqueName.size, CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_NAMES);
330
+ const hasKitaJs = uniqueName.has("kitajs");
331
+ const hasReact = uniqueName.has("react");
332
+ if (hasKitaJs && hasReact) {
333
+ appLogger.warn(CONFIG_BUILDER_ERRORS.MIXED_JSX_ENGINES);
334
+ }
335
+ const integrationsExtensions = integrations.flatMap((integration) => integration.extensions);
336
+ const uniqueExtensions = new Set(integrationsExtensions);
337
+ invariant(
338
+ integrationsExtensions.length === uniqueExtensions.size,
339
+ CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_EXTENSIONS
340
+ );
341
+ this.config.templatesExt = integrationsExtensions;
342
+ }
343
+ initializeProcessors() {
344
+ for (const processor of this.config.processors.values()) {
345
+ processor.setContext(this.config);
346
+ }
347
+ }
348
+ /**
349
+ * Initializes default loaders that are required for EcoPages to function.
350
+ * This includes the eco-component-meta-plugin which auto-injects __eco metadata into component configs.
351
+ */
352
+ async initializeDefaultLoaders() {
353
+ const componentMetaPlugin = createEcoComponentMetaPlugin({ config: this.config });
354
+ if (!this.config.loaders.has(componentMetaPlugin.name)) {
355
+ this.config.loaders.set(componentMetaPlugin.name, componentMetaPlugin);
356
+ }
357
+ }
358
+ reviewBaseUrl(baseUrl) {
359
+ if (baseUrl) {
360
+ this.config.baseUrl = baseUrl;
361
+ return;
362
+ }
363
+ const envBaseUrl = process.env.ECOPAGES_BASE_URL;
364
+ if (envBaseUrl) {
365
+ this.config.baseUrl = envBaseUrl;
366
+ } else if (!this.config.baseUrl) {
367
+ this.config.baseUrl = `http://${DEFAULT_ECOPAGES_HOSTNAME}:${DEFAULT_ECOPAGES_PORT}`;
368
+ }
369
+ }
370
+ /**
371
+ * Builds and returns the final configuration object.
372
+ * This performs validation and initialization of the configuration.
373
+ *
374
+ * @returns A promise that resolves to the final EcoPagesAppConfig
375
+ * @throws Error if required configuration is missing (e.g., baseUrl)
376
+ */
377
+ async build() {
378
+ this.reviewBaseUrl(this.config.baseUrl);
379
+ if (!this.config.integrations.some((integration) => integration.name === GHTML_PLUGIN_NAME)) {
380
+ this.config.integrations.push(ghtmlPlugin());
381
+ }
382
+ this.createAbsolutePaths(this.config);
383
+ this.createIntegrationTemplatesExt(this.config.integrations);
384
+ await this.initializeDefaultLoaders();
385
+ this.initializeProcessors();
386
+ return this.config;
387
+ }
388
+ }
389
+ export {
390
+ CONFIG_BUILDER_ERRORS,
391
+ ConfigBuilder
392
+ };