@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.
- package/CHANGELOG.md +89 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/package.json +279 -0
- package/src/adapters/abstract/application-adapter.d.ts +168 -0
- package/src/adapters/abstract/application-adapter.js +109 -0
- package/src/adapters/abstract/application-adapter.ts +337 -0
- package/src/adapters/abstract/router-adapter.d.ts +26 -0
- package/src/adapters/abstract/router-adapter.js +5 -0
- package/src/adapters/abstract/router-adapter.ts +30 -0
- package/src/adapters/abstract/server-adapter.d.ts +69 -0
- package/src/adapters/abstract/server-adapter.js +15 -0
- package/src/adapters/abstract/server-adapter.ts +79 -0
- package/src/adapters/bun/client-bridge.d.ts +34 -0
- package/src/adapters/bun/client-bridge.js +48 -0
- package/src/adapters/bun/client-bridge.ts +62 -0
- package/src/adapters/bun/create-app.d.ts +60 -0
- package/src/adapters/bun/create-app.js +117 -0
- package/src/adapters/bun/create-app.ts +189 -0
- package/src/adapters/bun/define-api-handler.d.ts +61 -0
- package/src/adapters/bun/define-api-handler.js +15 -0
- package/src/adapters/bun/define-api-handler.ts +114 -0
- package/src/adapters/bun/hmr-manager.d.ts +84 -0
- package/src/adapters/bun/hmr-manager.js +227 -0
- package/src/adapters/bun/hmr-manager.ts +281 -0
- package/src/adapters/bun/index.d.ts +3 -0
- package/src/adapters/bun/index.js +8 -0
- package/src/adapters/bun/index.ts +3 -0
- package/src/adapters/bun/server-adapter.d.ts +155 -0
- package/src/adapters/bun/server-adapter.js +368 -0
- package/src/adapters/bun/server-adapter.ts +492 -0
- package/src/adapters/bun/server-lifecycle.d.ts +52 -0
- package/src/adapters/bun/server-lifecycle.js +120 -0
- package/src/adapters/bun/server-lifecycle.ts +154 -0
- package/src/adapters/index.d.ts +6 -0
- package/src/adapters/index.js +14 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/node/create-app.d.ts +21 -0
- package/src/adapters/node/create-app.js +143 -0
- package/src/adapters/node/create-app.ts +179 -0
- package/src/adapters/node/index.d.ts +4 -0
- package/src/adapters/node/index.js +8 -0
- package/src/adapters/node/index.ts +9 -0
- package/src/adapters/node/node-client-bridge.d.ts +26 -0
- package/src/adapters/node/node-client-bridge.js +66 -0
- package/src/adapters/node/node-client-bridge.ts +79 -0
- package/src/adapters/node/node-hmr-manager.d.ts +62 -0
- package/src/adapters/node/node-hmr-manager.js +221 -0
- package/src/adapters/node/node-hmr-manager.ts +271 -0
- package/src/adapters/node/server-adapter.d.ts +190 -0
- package/src/adapters/node/server-adapter.js +420 -0
- package/src/adapters/node/server-adapter.ts +561 -0
- package/src/adapters/node/static-content-server.d.ts +24 -0
- package/src/adapters/node/static-content-server.js +166 -0
- package/src/adapters/node/static-content-server.ts +203 -0
- package/src/adapters/shared/api-response.d.ts +52 -0
- package/src/adapters/shared/api-response.js +96 -0
- package/src/adapters/shared/api-response.ts +104 -0
- package/src/adapters/shared/application-adapter.d.ts +18 -0
- package/src/adapters/shared/application-adapter.js +90 -0
- package/src/adapters/shared/application-adapter.ts +199 -0
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +38 -0
- package/src/adapters/shared/explicit-static-route-matcher.js +100 -0
- package/src/adapters/shared/explicit-static-route-matcher.ts +134 -0
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +65 -0
- package/src/adapters/shared/file-route-middleware-pipeline.js +98 -0
- package/src/adapters/shared/file-route-middleware-pipeline.ts +123 -0
- package/src/adapters/shared/fs-server-response-factory.d.ts +19 -0
- package/src/adapters/shared/fs-server-response-factory.js +97 -0
- package/src/adapters/shared/fs-server-response-factory.ts +118 -0
- package/src/adapters/shared/fs-server-response-matcher.d.ts +71 -0
- package/src/adapters/shared/fs-server-response-matcher.js +155 -0
- package/src/adapters/shared/fs-server-response-matcher.ts +198 -0
- package/src/adapters/shared/render-context.d.ts +14 -0
- package/src/adapters/shared/render-context.js +69 -0
- package/src/adapters/shared/render-context.ts +105 -0
- package/src/adapters/shared/server-adapter.d.ts +87 -0
- package/src/adapters/shared/server-adapter.js +353 -0
- package/src/adapters/shared/server-adapter.ts +442 -0
- package/src/adapters/shared/server-route-handler.d.ts +89 -0
- package/src/adapters/shared/server-route-handler.js +120 -0
- package/src/adapters/shared/server-route-handler.ts +166 -0
- package/src/adapters/shared/server-static-builder.d.ts +38 -0
- package/src/adapters/shared/server-static-builder.js +46 -0
- package/src/adapters/shared/server-static-builder.ts +82 -0
- package/src/build/build-adapter.d.ts +74 -0
- package/src/build/build-adapter.js +54 -0
- package/src/build/build-adapter.ts +132 -0
- package/src/build/build-types.d.ts +57 -0
- package/src/build/build-types.js +0 -0
- package/src/build/build-types.ts +83 -0
- package/src/build/esbuild-build-adapter.d.ts +69 -0
- package/src/build/esbuild-build-adapter.js +390 -0
- package/src/build/esbuild-build-adapter.ts +510 -0
- package/src/config/config-builder.d.ts +227 -0
- package/src/config/config-builder.js +392 -0
- package/src/config/config-builder.ts +474 -0
- package/src/constants.d.ts +32 -0
- package/src/constants.js +21 -0
- package/src/constants.ts +39 -0
- package/src/create-app.d.ts +17 -0
- package/src/create-app.js +66 -0
- package/src/create-app.ts +87 -0
- package/src/declarations.d.ts +26 -0
- package/src/define-api-handler.d.ts +25 -0
- package/src/define-api-handler.js +15 -0
- package/src/define-api-handler.ts +66 -0
- package/src/dev/sc-server.d.ts +30 -0
- package/src/dev/sc-server.js +111 -0
- package/src/dev/sc-server.ts +143 -0
- package/src/eco/README.md +636 -0
- package/src/eco/component-render-context.d.ts +105 -0
- package/src/eco/component-render-context.js +77 -0
- package/src/eco/component-render-context.ts +202 -0
- package/src/eco/eco.d.ts +9 -0
- package/src/eco/eco.js +110 -0
- package/src/eco/eco.ts +221 -0
- package/src/eco/eco.types.d.ts +170 -0
- package/src/eco/eco.types.js +0 -0
- package/src/eco/eco.types.ts +202 -0
- package/src/eco/eco.utils.d.ts +40 -0
- package/src/eco/eco.utils.js +40 -0
- package/src/eco/eco.utils.ts +89 -0
- package/src/eco/global-injector-map.d.ts +16 -0
- package/src/eco/global-injector-map.js +80 -0
- package/src/eco/global-injector-map.ts +112 -0
- package/src/eco/lazy-injector-map.d.ts +8 -0
- package/src/eco/lazy-injector-map.js +70 -0
- package/src/eco/lazy-injector-map.ts +120 -0
- package/src/eco/module-dependencies.d.ts +18 -0
- package/src/eco/module-dependencies.js +49 -0
- package/src/eco/module-dependencies.ts +75 -0
- package/src/env.d.ts +20 -0
- package/src/errors/http-error.d.ts +31 -0
- package/src/errors/http-error.js +50 -0
- package/src/errors/http-error.ts +72 -0
- package/src/errors/index.d.ts +2 -0
- package/src/errors/index.js +4 -0
- package/src/errors/index.ts +2 -0
- package/src/errors/locals-access-error.d.ts +4 -0
- package/src/errors/locals-access-error.js +9 -0
- package/src/errors/locals-access-error.ts +7 -0
- package/src/global/app-logger.d.ts +2 -0
- package/src/global/app-logger.js +6 -0
- package/src/global/app-logger.ts +4 -0
- 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
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
- package/src/hmr/client/hmr-runtime.d.ts +10 -0
- package/src/hmr/client/hmr-runtime.js +86 -0
- package/src/hmr/client/hmr-runtime.ts +121 -0
- package/src/hmr/hmr-strategy.d.ts +159 -0
- package/src/hmr/hmr-strategy.js +29 -0
- package/src/hmr/hmr-strategy.ts +172 -0
- package/src/hmr/hmr.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.test.e2e.js +50 -0
- package/src/hmr/hmr.test.e2e.ts +75 -0
- package/src/hmr/strategies/default-hmr-strategy.d.ts +43 -0
- package/src/hmr/strategies/default-hmr-strategy.js +34 -0
- package/src/hmr/strategies/default-hmr-strategy.ts +60 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +136 -0
- package/src/hmr/strategies/js-hmr-strategy.js +179 -0
- package/src/hmr/strategies/js-hmr-strategy.ts +308 -0
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +4 -0
- package/src/index.browser.ts +3 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +10 -0
- package/src/index.ts +5 -0
- package/src/integrations/ghtml/ghtml-renderer.d.ts +15 -0
- package/src/integrations/ghtml/ghtml-renderer.js +60 -0
- package/src/integrations/ghtml/ghtml-renderer.ts +93 -0
- package/src/integrations/ghtml/ghtml.plugin.d.ts +20 -0
- package/src/integrations/ghtml/ghtml.plugin.js +21 -0
- package/src/integrations/ghtml/ghtml.plugin.ts +32 -0
- package/src/internal-types.d.ts +200 -0
- package/src/internal-types.js +0 -0
- package/src/internal-types.ts +212 -0
- package/src/plugins/alias-resolver-plugin.d.ts +2 -0
- package/src/plugins/alias-resolver-plugin.js +39 -0
- package/src/plugins/alias-resolver-plugin.ts +45 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +95 -0
- package/src/plugins/eco-component-meta-plugin.js +157 -0
- package/src/plugins/eco-component-meta-plugin.ts +474 -0
- package/src/plugins/integration-plugin.d.ts +102 -0
- package/src/plugins/integration-plugin.js +100 -0
- package/src/plugins/integration-plugin.ts +184 -0
- package/src/plugins/processor.d.ts +82 -0
- package/src/plugins/processor.js +122 -0
- package/src/plugins/processor.ts +220 -0
- package/src/public-types.d.ts +1094 -0
- package/src/public-types.js +0 -0
- package/src/public-types.ts +1255 -0
- package/src/route-renderer/GRAPH.md +387 -0
- package/src/route-renderer/README.md +135 -0
- package/src/route-renderer/component-graph-executor.d.ts +32 -0
- package/src/route-renderer/component-graph-executor.js +31 -0
- package/src/route-renderer/component-graph-executor.ts +84 -0
- package/src/route-renderer/component-graph.d.ts +42 -0
- package/src/route-renderer/component-graph.js +72 -0
- package/src/route-renderer/component-graph.ts +159 -0
- package/src/route-renderer/component-marker.d.ts +52 -0
- package/src/route-renderer/component-marker.js +46 -0
- package/src/route-renderer/component-marker.ts +117 -0
- package/src/route-renderer/dependency-resolver.d.ts +24 -0
- package/src/route-renderer/dependency-resolver.js +428 -0
- package/src/route-renderer/dependency-resolver.ts +596 -0
- package/src/route-renderer/html-post-processing.service.d.ts +40 -0
- package/src/route-renderer/html-post-processing.service.js +86 -0
- package/src/route-renderer/html-post-processing.service.ts +103 -0
- package/src/route-renderer/integration-renderer.d.ts +339 -0
- package/src/route-renderer/integration-renderer.js +526 -0
- package/src/route-renderer/integration-renderer.ts +696 -0
- package/src/route-renderer/marker-graph-resolver.d.ts +76 -0
- package/src/route-renderer/marker-graph-resolver.js +93 -0
- package/src/route-renderer/marker-graph-resolver.ts +153 -0
- package/src/route-renderer/page-module-loader.d.ts +61 -0
- package/src/route-renderer/page-module-loader.js +102 -0
- package/src/route-renderer/page-module-loader.ts +153 -0
- package/src/route-renderer/render-execution.service.d.ts +69 -0
- package/src/route-renderer/render-execution.service.js +91 -0
- package/src/route-renderer/render-execution.service.ts +158 -0
- package/src/route-renderer/render-preparation.service.d.ts +112 -0
- package/src/route-renderer/render-preparation.service.js +243 -0
- package/src/route-renderer/render-preparation.service.ts +358 -0
- package/src/route-renderer/route-renderer.d.ts +26 -0
- package/src/route-renderer/route-renderer.js +68 -0
- package/src/route-renderer/route-renderer.ts +80 -0
- package/src/router/fs-router-scanner.d.ts +41 -0
- package/src/router/fs-router-scanner.js +155 -0
- package/src/router/fs-router-scanner.ts +217 -0
- package/src/router/fs-router.d.ts +26 -0
- package/src/router/fs-router.js +100 -0
- package/src/router/fs-router.ts +122 -0
- package/src/services/asset-processing-service/asset-processing.service.d.ts +41 -0
- package/src/services/asset-processing-service/asset-processing.service.js +250 -0
- package/src/services/asset-processing-service/asset-processing.service.ts +306 -0
- package/src/services/asset-processing-service/asset.factory.d.ts +17 -0
- package/src/services/asset-processing-service/asset.factory.js +82 -0
- package/src/services/asset-processing-service/asset.factory.ts +105 -0
- package/src/services/asset-processing-service/assets.types.d.ts +88 -0
- package/src/services/asset-processing-service/assets.types.js +0 -0
- package/src/services/asset-processing-service/assets.types.ts +112 -0
- package/src/services/asset-processing-service/index.d.ts +3 -0
- package/src/services/asset-processing-service/index.js +3 -0
- package/src/services/asset-processing-service/index.ts +3 -0
- package/src/services/asset-processing-service/processor.interface.d.ts +22 -0
- package/src/services/asset-processing-service/processor.interface.js +6 -0
- package/src/services/asset-processing-service/processor.interface.ts +27 -0
- package/src/services/asset-processing-service/processor.registry.d.ts +8 -0
- package/src/services/asset-processing-service/processor.registry.js +15 -0
- package/src/services/asset-processing-service/processor.registry.ts +18 -0
- package/src/services/asset-processing-service/processors/base/base-processor.d.ts +24 -0
- package/src/services/asset-processing-service/processors/base/base-processor.js +59 -0
- package/src/services/asset-processing-service/processors/base/base-processor.ts +76 -0
- package/src/services/asset-processing-service/processors/base/base-script-processor.d.ts +16 -0
- package/src/services/asset-processing-service/processors/base/base-script-processor.js +80 -0
- package/src/services/asset-processing-service/processors/base/base-script-processor.ts +105 -0
- package/src/services/asset-processing-service/processors/index.d.ts +5 -0
- package/src/services/asset-processing-service/processors/index.js +5 -0
- package/src/services/asset-processing-service/processors/index.ts +5 -0
- package/src/services/asset-processing-service/processors/script/content-script.processor.d.ts +5 -0
- package/src/services/asset-processing-service/processors/script/content-script.processor.js +57 -0
- package/src/services/asset-processing-service/processors/script/content-script.processor.ts +66 -0
- package/src/services/asset-processing-service/processors/script/file-script.processor.d.ts +8 -0
- package/src/services/asset-processing-service/processors/script/file-script.processor.js +76 -0
- package/src/services/asset-processing-service/processors/script/file-script.processor.ts +88 -0
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.d.ts +7 -0
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.js +74 -0
- package/src/services/asset-processing-service/processors/script/node-module-script.processor.ts +84 -0
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +5 -0
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +25 -0
- package/src/services/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts +27 -0
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +9 -0
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +63 -0
- package/src/services/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts +77 -0
- package/src/services/cache/cache.types.d.ts +107 -0
- package/src/services/cache/cache.types.js +0 -0
- package/src/services/cache/cache.types.ts +126 -0
- package/src/services/cache/index.d.ts +7 -0
- package/src/services/cache/index.js +7 -0
- package/src/services/cache/index.ts +18 -0
- package/src/services/cache/memory-cache-store.d.ts +42 -0
- package/src/services/cache/memory-cache-store.js +98 -0
- package/src/services/cache/memory-cache-store.ts +130 -0
- package/src/services/cache/page-cache-service.d.ts +70 -0
- package/src/services/cache/page-cache-service.js +152 -0
- package/src/services/cache/page-cache-service.ts +202 -0
- package/src/services/html-transformer.service.d.ts +50 -0
- package/src/services/html-transformer.service.js +163 -0
- package/src/services/html-transformer.service.ts +217 -0
- package/src/services/page-module-import.service.d.ts +37 -0
- package/src/services/page-module-import.service.js +88 -0
- package/src/services/page-module-import.service.ts +129 -0
- package/src/services/page-request-cache-coordinator.service.d.ts +75 -0
- package/src/services/page-request-cache-coordinator.service.js +107 -0
- package/src/services/page-request-cache-coordinator.service.ts +128 -0
- package/src/services/schema-validation-service.d.ts +122 -0
- package/src/services/schema-validation-service.js +101 -0
- package/src/services/schema-validation-service.ts +204 -0
- package/src/services/validation/standard-schema.types.d.ts +65 -0
- package/src/services/validation/standard-schema.types.js +0 -0
- package/src/services/validation/standard-schema.types.ts +68 -0
- package/src/static-site-generator/static-site-generator.d.ts +57 -0
- package/src/static-site-generator/static-site-generator.js +272 -0
- package/src/static-site-generator/static-site-generator.ts +359 -0
- package/src/utils/css.d.ts +1 -0
- package/src/utils/css.js +7 -0
- package/src/utils/css.ts +5 -0
- package/src/utils/deep-merge.d.ts +14 -0
- package/src/utils/deep-merge.js +32 -0
- package/src/utils/deep-merge.ts +47 -0
- package/src/utils/hash.d.ts +1 -0
- package/src/utils/hash.js +7 -0
- package/src/utils/hash.ts +5 -0
- package/src/utils/html.d.ts +1 -0
- package/src/utils/html.js +4 -0
- package/src/utils/html.ts +1 -0
- package/src/utils/invariant.d.ts +5 -0
- package/src/utils/invariant.js +11 -0
- package/src/utils/invariant.ts +15 -0
- package/src/utils/locals-utils.d.ts +15 -0
- package/src/utils/locals-utils.js +24 -0
- package/src/utils/locals-utils.ts +37 -0
- package/src/utils/parse-cli-args.d.ts +24 -0
- package/src/utils/parse-cli-args.js +47 -0
- package/src/utils/parse-cli-args.ts +83 -0
- package/src/utils/path-utils.module.d.ts +5 -0
- package/src/utils/path-utils.module.js +14 -0
- package/src/utils/path-utils.module.ts +14 -0
- package/src/utils/runtime.d.ts +11 -0
- package/src/utils/runtime.js +40 -0
- package/src/utils/runtime.ts +44 -0
- package/src/utils/server-utils.module.d.ts +19 -0
- package/src/utils/server-utils.module.js +56 -0
- package/src/utils/server-utils.module.ts +67 -0
- package/src/watchers/project-watcher.d.ts +120 -0
- package/src/watchers/project-watcher.js +238 -0
- package/src/watchers/project-watcher.test-helpers.d.ts +4 -0
- package/src/watchers/project-watcher.test-helpers.js +51 -0
- package/src/watchers/project-watcher.test-helpers.ts +40 -0
- package/src/watchers/project-watcher.ts +306 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module contains the ConfigBuilder class, which is used to build the EcoPagesAppConfig object.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from '../constants.ts';
|
|
8
|
+
import type { EcoBuildPlugin } from '../build/build-types.ts';
|
|
9
|
+
import { GHTML_PLUGIN_NAME, ghtmlPlugin } from '../integrations/ghtml/ghtml.plugin.ts';
|
|
10
|
+
import type { EcoPagesAppConfig, IncludesTemplates, RobotsPreference } from '../internal-types.ts';
|
|
11
|
+
import { createEcoComponentMetaPlugin } from '../plugins/eco-component-meta-plugin.ts';
|
|
12
|
+
import type { IntegrationPlugin } from '../plugins/integration-plugin.ts';
|
|
13
|
+
import type { Processor } from '../plugins/processor.ts';
|
|
14
|
+
import type { PageMetadataProps } from '../public-types.ts';
|
|
15
|
+
import type { CacheConfig } from '../services/cache/cache.types.ts';
|
|
16
|
+
import { invariant } from '../utils/invariant.ts';
|
|
17
|
+
import { appLogger } from '../global/app-logger.ts';
|
|
18
|
+
|
|
19
|
+
export const CONFIG_BUILDER_ERRORS = {
|
|
20
|
+
DUPLICATE_INTEGRATION_NAMES: 'Integrations names must be unique',
|
|
21
|
+
DUPLICATE_INTEGRATION_EXTENSIONS: 'Integrations extensions must be unique',
|
|
22
|
+
MIXED_JSX_ENGINES:
|
|
23
|
+
'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).',
|
|
24
|
+
duplicateProcessorName: (name: string) => `Processor with name "${name}" already exists`,
|
|
25
|
+
duplicateLoaderName: (name: string) => `Loader with name "${name}" already exists`,
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A builder class for creating and configuring EcoPages application configuration.
|
|
30
|
+
* Provides a fluent interface for setting various configuration options and managing
|
|
31
|
+
* application settings.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const config = new ConfigBuilder()
|
|
36
|
+
* .setBaseUrl('https://example.com')
|
|
37
|
+
* .setRootDir('./myproject')
|
|
38
|
+
* .setSrcDir('source')
|
|
39
|
+
* .build();
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* The ConfigBuilder follows the builder pattern and allows for:
|
|
44
|
+
* - Setting directory paths for various components (pages, includes, layouts, etc.)
|
|
45
|
+
* - Configuring templates and includes
|
|
46
|
+
* - Managing integrations and plugins
|
|
47
|
+
* - Setting up processors and loaders
|
|
48
|
+
* - Configuring API handlers
|
|
49
|
+
* - Managing metadata and robots.txt preferences
|
|
50
|
+
*
|
|
51
|
+
* All setter methods return the instance of the builder for method chaining.
|
|
52
|
+
* The configuration is finalized by calling the `build()` method, which performs
|
|
53
|
+
* validation and initialization of the configuration.
|
|
54
|
+
*
|
|
55
|
+
* @throws {Error} When building configuration without required fields (e.g., baseUrl)
|
|
56
|
+
* @throws {Error} When adding duplicate processors or loaders
|
|
57
|
+
*/
|
|
58
|
+
export class ConfigBuilder {
|
|
59
|
+
public config: EcoPagesAppConfig = {
|
|
60
|
+
baseUrl: '',
|
|
61
|
+
rootDir: '.',
|
|
62
|
+
srcDir: 'src',
|
|
63
|
+
pagesDir: 'pages',
|
|
64
|
+
includesDir: 'includes',
|
|
65
|
+
componentsDir: 'components',
|
|
66
|
+
layoutsDir: 'layouts',
|
|
67
|
+
publicDir: 'public',
|
|
68
|
+
includesTemplates: {
|
|
69
|
+
head: 'head.ghtml.ts',
|
|
70
|
+
html: 'html.ghtml.ts',
|
|
71
|
+
seo: 'seo.ghtml.ts',
|
|
72
|
+
},
|
|
73
|
+
error404Template: '404.ghtml.ts',
|
|
74
|
+
robotsTxt: {
|
|
75
|
+
preferences: {
|
|
76
|
+
'*': [],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
integrations: [],
|
|
80
|
+
integrationsDependencies: [],
|
|
81
|
+
distDir: '.eco',
|
|
82
|
+
defaultMetadata: {
|
|
83
|
+
title: 'Ecopages',
|
|
84
|
+
description: 'This is a static site generated with Ecopages',
|
|
85
|
+
},
|
|
86
|
+
additionalWatchPaths: [],
|
|
87
|
+
templatesExt: [],
|
|
88
|
+
absolutePaths: {
|
|
89
|
+
config: '',
|
|
90
|
+
componentsDir: '',
|
|
91
|
+
distDir: '',
|
|
92
|
+
includesDir: '',
|
|
93
|
+
layoutsDir: '',
|
|
94
|
+
pagesDir: '',
|
|
95
|
+
projectDir: '',
|
|
96
|
+
publicDir: '',
|
|
97
|
+
srcDir: '',
|
|
98
|
+
htmlTemplatePath: '',
|
|
99
|
+
error404TemplatePath: '',
|
|
100
|
+
},
|
|
101
|
+
processors: new Map(),
|
|
102
|
+
loaders: new Map(),
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Sets the base URL for the application.
|
|
107
|
+
* This URL is used as the root URL for all pages and assets.
|
|
108
|
+
*
|
|
109
|
+
* @param baseUrl - The base URL for the application (e.g., 'https://example.com')
|
|
110
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
111
|
+
*/
|
|
112
|
+
setBaseUrl(baseUrl: string): this {
|
|
113
|
+
this.config.baseUrl = baseUrl;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Sets the root directory of the project.
|
|
119
|
+
* This is the base directory from which all other paths are resolved.
|
|
120
|
+
*
|
|
121
|
+
* @param rootDir - The root directory path
|
|
122
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
123
|
+
*/
|
|
124
|
+
setRootDir(rootDir: string): this {
|
|
125
|
+
this.config.rootDir = rootDir;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Sets the source directory relative to the root directory.
|
|
131
|
+
* This directory contains all the source files for the application.
|
|
132
|
+
*
|
|
133
|
+
* @param srcDir - The source directory name (default: 'src')
|
|
134
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
135
|
+
*/
|
|
136
|
+
setSrcDir(srcDir: string): this {
|
|
137
|
+
this.config.srcDir = srcDir;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sets the pages directory relative to the source directory.
|
|
143
|
+
* This directory contains all the page files for the application.
|
|
144
|
+
*
|
|
145
|
+
* @param pagesDir - The pages directory name (default: 'pages')
|
|
146
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
147
|
+
*/
|
|
148
|
+
setPagesDir(pagesDir: string): this {
|
|
149
|
+
this.config.pagesDir = pagesDir;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Sets the includes directory relative to the source directory.
|
|
155
|
+
* This directory contains template includes and partials.
|
|
156
|
+
*
|
|
157
|
+
* @param includesDir - The includes directory name (default: 'includes')
|
|
158
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
159
|
+
*/
|
|
160
|
+
setIncludesDir(includesDir: string): this {
|
|
161
|
+
this.config.includesDir = includesDir;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Sets the components directory relative to the source directory.
|
|
167
|
+
* This directory contains reusable components.
|
|
168
|
+
*
|
|
169
|
+
* @param componentsDir - The components directory name (default: 'components')
|
|
170
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
171
|
+
*/
|
|
172
|
+
setComponentsDir(componentsDir: string): this {
|
|
173
|
+
this.config.componentsDir = componentsDir;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Sets the layouts directory relative to the source directory.
|
|
179
|
+
* This directory contains layout templates.
|
|
180
|
+
*
|
|
181
|
+
* @param layoutsDir - The layouts directory name (default: 'layouts')
|
|
182
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
183
|
+
*/
|
|
184
|
+
setLayoutsDir(layoutsDir: string): this {
|
|
185
|
+
this.config.layoutsDir = layoutsDir;
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Sets the public directory relative to the source directory.
|
|
191
|
+
* This directory contains static assets that should be served as-is.
|
|
192
|
+
*
|
|
193
|
+
* @param publicDir - The public directory name (default: 'public')
|
|
194
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
195
|
+
*/
|
|
196
|
+
setPublicDir(publicDir: string): this {
|
|
197
|
+
this.config.publicDir = publicDir;
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Sets the templates used for includes.
|
|
203
|
+
* These templates are used to build the HTML structure of pages.
|
|
204
|
+
*
|
|
205
|
+
* @param includesTemplates - An object containing the template file names
|
|
206
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
207
|
+
*/
|
|
208
|
+
setIncludesTemplates(includesTemplates: IncludesTemplates): this {
|
|
209
|
+
this.config.includesTemplates = includesTemplates;
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Sets the template file for the 404 error page.
|
|
215
|
+
*
|
|
216
|
+
* @param error404Template - The file name of the 404 error template (default: '404.ghtml.ts')
|
|
217
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
218
|
+
*/
|
|
219
|
+
setError404Template(error404Template: string): this {
|
|
220
|
+
this.config.error404Template = error404Template;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Sets the robots.txt configuration.
|
|
226
|
+
* This determines which paths are allowed/disallowed for search engines.
|
|
227
|
+
*
|
|
228
|
+
* @param robotsTxt - The robots.txt configuration object
|
|
229
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
230
|
+
*/
|
|
231
|
+
setRobotsTxt(robotsTxt: { preferences: RobotsPreference }): this {
|
|
232
|
+
this.config.robotsTxt = robotsTxt;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Sets the integration plugins to use.
|
|
238
|
+
* These plugins provide additional functionality to the application.
|
|
239
|
+
*
|
|
240
|
+
* @param integrations - An array of integration plugins
|
|
241
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
242
|
+
*/
|
|
243
|
+
setIntegrations(integrations: IntegrationPlugin<unknown>[]): this {
|
|
244
|
+
this.config.integrations = integrations;
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Sets the output directory for the built application.
|
|
250
|
+
*
|
|
251
|
+
* @param distDir - The distribution directory name (default: '.eco')
|
|
252
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
253
|
+
*/
|
|
254
|
+
setDistDir(distDir: string): this {
|
|
255
|
+
this.config.distDir = distDir;
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Sets the default metadata for pages.
|
|
261
|
+
* This is used when a page doesn't specify its own metadata.
|
|
262
|
+
*
|
|
263
|
+
* @param defaultMetadata - The default metadata object
|
|
264
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
265
|
+
*/
|
|
266
|
+
setDefaultMetadata(defaultMetadata: PageMetadataProps): this {
|
|
267
|
+
this.config.defaultMetadata = {
|
|
268
|
+
...this.config.defaultMetadata,
|
|
269
|
+
...defaultMetadata,
|
|
270
|
+
};
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Sets additional paths to watch for changes during development.
|
|
276
|
+
*
|
|
277
|
+
* @param additionalWatchPaths - An array of additional paths to watch
|
|
278
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
279
|
+
*/
|
|
280
|
+
setAdditionalWatchPaths(additionalWatchPaths: string[]): this {
|
|
281
|
+
this.config.additionalWatchPaths = additionalWatchPaths;
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Sets the processors to use for the application.
|
|
287
|
+
* This replaces any existing processors.
|
|
288
|
+
*
|
|
289
|
+
* @param processors - An array of processors
|
|
290
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
291
|
+
*/
|
|
292
|
+
setProcessors(processors: Processor<any>[]): this {
|
|
293
|
+
this.config.processors.clear();
|
|
294
|
+
for (const processor of processors) {
|
|
295
|
+
this.addProcessor(processor);
|
|
296
|
+
}
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Adds a processor to the application.
|
|
302
|
+
*
|
|
303
|
+
* @param processor - The processor to add
|
|
304
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
305
|
+
* @throws Error if a processor with the same name already exists
|
|
306
|
+
*/
|
|
307
|
+
addProcessor(processor: Processor): this {
|
|
308
|
+
if (this.config.processors.has(processor.name)) {
|
|
309
|
+
throw new Error(CONFIG_BUILDER_ERRORS.duplicateProcessorName(processor.name));
|
|
310
|
+
}
|
|
311
|
+
this.config.processors.set(processor.name, processor);
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Sets the loaders to use for the application.
|
|
317
|
+
* This replaces any existing loaders.
|
|
318
|
+
*
|
|
319
|
+
* @param loaders - An array of build plugins to use as loaders
|
|
320
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
321
|
+
*/
|
|
322
|
+
setLoaders(loaders: EcoBuildPlugin[]): this {
|
|
323
|
+
this.config.loaders.clear();
|
|
324
|
+
for (const loader of loaders) {
|
|
325
|
+
this.addLoader(loader.name, loader);
|
|
326
|
+
}
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Adds a loader to the application.
|
|
332
|
+
*
|
|
333
|
+
* @param name - The name of the loader
|
|
334
|
+
* @param loader - The build plugin to use as a loader
|
|
335
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
336
|
+
* @throws Error if a loader with the same name already exists
|
|
337
|
+
*/
|
|
338
|
+
addLoader(name: string, loader: EcoBuildPlugin): this {
|
|
339
|
+
if (this.config.loaders.has(name)) {
|
|
340
|
+
throw new Error(CONFIG_BUILDER_ERRORS.duplicateLoaderName(name));
|
|
341
|
+
}
|
|
342
|
+
this.config.loaders.set(name, loader);
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Sets the cache configuration for ISR and page caching.
|
|
348
|
+
*
|
|
349
|
+
* @param cacheConfig - The cache configuration object
|
|
350
|
+
* @returns The ConfigBuilder instance for method chaining
|
|
351
|
+
*/
|
|
352
|
+
setCacheConfig(cacheConfig: CacheConfig): this {
|
|
353
|
+
this.config.cache = cacheConfig;
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
setExperimental(experimental: NonNullable<EcoPagesAppConfig['experimental']>): this {
|
|
358
|
+
this.config.experimental = experimental;
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
private createAbsolutePaths(config: EcoPagesAppConfig): this {
|
|
363
|
+
const {
|
|
364
|
+
srcDir,
|
|
365
|
+
componentsDir,
|
|
366
|
+
includesDir,
|
|
367
|
+
layoutsDir,
|
|
368
|
+
pagesDir,
|
|
369
|
+
publicDir,
|
|
370
|
+
distDir,
|
|
371
|
+
includesTemplates,
|
|
372
|
+
error404Template,
|
|
373
|
+
} = config;
|
|
374
|
+
|
|
375
|
+
const projectDir = config.rootDir;
|
|
376
|
+
|
|
377
|
+
const absoluteSrcDir = path.resolve(projectDir, srcDir);
|
|
378
|
+
const absoluteDistDir = path.resolve(projectDir, distDir);
|
|
379
|
+
|
|
380
|
+
this.config.absolutePaths = {
|
|
381
|
+
config: path.join(projectDir, 'eco.config.ts'),
|
|
382
|
+
projectDir: projectDir,
|
|
383
|
+
srcDir: absoluteSrcDir,
|
|
384
|
+
distDir: absoluteDistDir,
|
|
385
|
+
componentsDir: path.join(absoluteSrcDir, componentsDir),
|
|
386
|
+
includesDir: path.join(absoluteSrcDir, includesDir),
|
|
387
|
+
layoutsDir: path.join(absoluteSrcDir, layoutsDir),
|
|
388
|
+
pagesDir: path.join(absoluteSrcDir, pagesDir),
|
|
389
|
+
publicDir: path.join(absoluteSrcDir, publicDir),
|
|
390
|
+
htmlTemplatePath: path.join(absoluteSrcDir, includesDir, includesTemplates.html),
|
|
391
|
+
error404TemplatePath: path.join(absoluteSrcDir, pagesDir, error404Template),
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
return this;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
private createIntegrationTemplatesExt(integrations: EcoPagesAppConfig['integrations']) {
|
|
398
|
+
const integrationName = integrations.map((integration) => integration.name);
|
|
399
|
+
const uniqueName = new Set(integrationName);
|
|
400
|
+
|
|
401
|
+
invariant(integrationName.length === uniqueName.size, CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_NAMES);
|
|
402
|
+
|
|
403
|
+
const hasKitaJs = uniqueName.has('kitajs');
|
|
404
|
+
const hasReact = uniqueName.has('react');
|
|
405
|
+
if (hasKitaJs && hasReact) {
|
|
406
|
+
appLogger.warn(CONFIG_BUILDER_ERRORS.MIXED_JSX_ENGINES);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const integrationsExtensions = integrations.flatMap((integration) => integration.extensions);
|
|
410
|
+
const uniqueExtensions = new Set(integrationsExtensions);
|
|
411
|
+
|
|
412
|
+
invariant(
|
|
413
|
+
integrationsExtensions.length === uniqueExtensions.size,
|
|
414
|
+
CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_EXTENSIONS,
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
this.config.templatesExt = integrationsExtensions;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private initializeProcessors(): void {
|
|
421
|
+
for (const processor of this.config.processors.values()) {
|
|
422
|
+
processor.setContext(this.config);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Initializes default loaders that are required for EcoPages to function.
|
|
428
|
+
* This includes the eco-component-meta-plugin which auto-injects __eco metadata into component configs.
|
|
429
|
+
*/
|
|
430
|
+
private async initializeDefaultLoaders(): Promise<void> {
|
|
431
|
+
const componentMetaPlugin = createEcoComponentMetaPlugin({ config: this.config });
|
|
432
|
+
if (!this.config.loaders.has(componentMetaPlugin.name)) {
|
|
433
|
+
this.config.loaders.set(componentMetaPlugin.name, componentMetaPlugin);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private reviewBaseUrl(baseUrl: string): void {
|
|
438
|
+
if (baseUrl) {
|
|
439
|
+
this.config.baseUrl = baseUrl;
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const envBaseUrl = process.env.ECOPAGES_BASE_URL;
|
|
444
|
+
|
|
445
|
+
if (envBaseUrl) {
|
|
446
|
+
this.config.baseUrl = envBaseUrl;
|
|
447
|
+
} else if (!this.config.baseUrl) {
|
|
448
|
+
this.config.baseUrl = `http://${DEFAULT_ECOPAGES_HOSTNAME}:${DEFAULT_ECOPAGES_PORT}`;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Builds and returns the final configuration object.
|
|
454
|
+
* This performs validation and initialization of the configuration.
|
|
455
|
+
*
|
|
456
|
+
* @returns A promise that resolves to the final EcoPagesAppConfig
|
|
457
|
+
* @throws Error if required configuration is missing (e.g., baseUrl)
|
|
458
|
+
*/
|
|
459
|
+
async build(): Promise<EcoPagesAppConfig> {
|
|
460
|
+
this.reviewBaseUrl(this.config.baseUrl);
|
|
461
|
+
|
|
462
|
+
if (!this.config.integrations.some((integration) => integration.name === GHTML_PLUGIN_NAME)) {
|
|
463
|
+
this.config.integrations.push(ghtmlPlugin());
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
this.createAbsolutePaths(this.config);
|
|
467
|
+
this.createIntegrationTemplatesExt(this.config.integrations);
|
|
468
|
+
|
|
469
|
+
await this.initializeDefaultLoaders();
|
|
470
|
+
this.initializeProcessors();
|
|
471
|
+
|
|
472
|
+
return this.config;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains constants used throughout the project.
|
|
3
|
+
* @module constants
|
|
4
|
+
**/
|
|
5
|
+
/**
|
|
6
|
+
* Collection of status messages used in the application.
|
|
7
|
+
*/
|
|
8
|
+
export declare const STATUS_MESSAGE: {
|
|
9
|
+
404: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
*Variables used to determine if the app is running on Bun
|
|
13
|
+
*/
|
|
14
|
+
export declare const IS_BUN: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Directory used for storing assets.
|
|
17
|
+
*/
|
|
18
|
+
export declare const RESOLVED_ASSETS_DIR = "assets";
|
|
19
|
+
/**
|
|
20
|
+
* Directory used for storing vendor assets.
|
|
21
|
+
* This is a subdirectory of the assets directory.
|
|
22
|
+
*/
|
|
23
|
+
export declare const RESOLVED_ASSETS_VENDORS_DIR: string;
|
|
24
|
+
/**
|
|
25
|
+
* Base paths for generated project files.
|
|
26
|
+
*/
|
|
27
|
+
export declare const GENERATED_BASE_PATHS: {
|
|
28
|
+
readonly types: "node_modules/@types";
|
|
29
|
+
readonly cache: "cache";
|
|
30
|
+
};
|
|
31
|
+
export declare const DEFAULT_ECOPAGES_PORT = 3000;
|
|
32
|
+
export declare const DEFAULT_ECOPAGES_HOSTNAME = "localhost";
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const STATUS_MESSAGE = {
|
|
2
|
+
404: "404 Not Found"
|
|
3
|
+
};
|
|
4
|
+
const IS_BUN = typeof Bun !== "undefined";
|
|
5
|
+
const RESOLVED_ASSETS_DIR = "assets";
|
|
6
|
+
const RESOLVED_ASSETS_VENDORS_DIR = `${RESOLVED_ASSETS_DIR}/vendors`;
|
|
7
|
+
const GENERATED_BASE_PATHS = {
|
|
8
|
+
types: "node_modules/@types",
|
|
9
|
+
cache: "cache"
|
|
10
|
+
};
|
|
11
|
+
const DEFAULT_ECOPAGES_PORT = 3e3;
|
|
12
|
+
const DEFAULT_ECOPAGES_HOSTNAME = "localhost";
|
|
13
|
+
export {
|
|
14
|
+
DEFAULT_ECOPAGES_HOSTNAME,
|
|
15
|
+
DEFAULT_ECOPAGES_PORT,
|
|
16
|
+
GENERATED_BASE_PATHS,
|
|
17
|
+
IS_BUN,
|
|
18
|
+
RESOLVED_ASSETS_DIR,
|
|
19
|
+
RESOLVED_ASSETS_VENDORS_DIR,
|
|
20
|
+
STATUS_MESSAGE
|
|
21
|
+
};
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains constants used throughout the project.
|
|
3
|
+
* @module constants
|
|
4
|
+
**/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Collection of status messages used in the application.
|
|
8
|
+
*/
|
|
9
|
+
export const STATUS_MESSAGE = {
|
|
10
|
+
404: '404 Not Found',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*Variables used to determine if the app is running on Bun
|
|
15
|
+
*/
|
|
16
|
+
export const IS_BUN = typeof Bun !== 'undefined';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Directory used for storing assets.
|
|
20
|
+
*/
|
|
21
|
+
export const RESOLVED_ASSETS_DIR = 'assets';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Directory used for storing vendor assets.
|
|
25
|
+
* This is a subdirectory of the assets directory.
|
|
26
|
+
*/
|
|
27
|
+
export const RESOLVED_ASSETS_VENDORS_DIR: string = `${RESOLVED_ASSETS_DIR}/vendors`;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Base paths for generated project files.
|
|
31
|
+
*/
|
|
32
|
+
export const GENERATED_BASE_PATHS = {
|
|
33
|
+
types: 'node_modules/@types',
|
|
34
|
+
cache: 'cache',
|
|
35
|
+
} as const;
|
|
36
|
+
|
|
37
|
+
export const DEFAULT_ECOPAGES_PORT = 3000;
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_ECOPAGES_HOSTNAME = 'localhost';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EcopagesAppOptions as BunOptions } from './adapters/bun/create-app.js';
|
|
2
|
+
import type { EcopagesAppOptions as NodeOptions } from './adapters/node/create-app.js';
|
|
3
|
+
import { AbstractApplicationAdapter } from './adapters/abstract/application-adapter.js';
|
|
4
|
+
import { SharedApplicationAdapter } from './adapters/shared/application-adapter.js';
|
|
5
|
+
export type EcopagesAppOptions = BunOptions | NodeOptions;
|
|
6
|
+
export type UniversalEcopagesApp = AbstractApplicationAdapter<EcopagesAppOptions, any, Request>;
|
|
7
|
+
export declare function createApp<WebSocketData = undefined>(options: EcopagesAppOptions): Promise<UniversalEcopagesApp>;
|
|
8
|
+
export declare class EcopagesApp extends SharedApplicationAdapter<EcopagesAppOptions, unknown, Request> {
|
|
9
|
+
private readonly appOptions;
|
|
10
|
+
private runtimeApp;
|
|
11
|
+
private runtimeAppPromise;
|
|
12
|
+
constructor(options: EcopagesAppOptions);
|
|
13
|
+
private getRuntimeApp;
|
|
14
|
+
protected initializeServerAdapter(): Promise<UniversalEcopagesApp>;
|
|
15
|
+
start(): Promise<unknown>;
|
|
16
|
+
fetch(request: Request): Promise<Response>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AbstractApplicationAdapter } from "./adapters/abstract/application-adapter.js";
|
|
2
|
+
import { SharedApplicationAdapter } from "./adapters/shared/application-adapter.js";
|
|
3
|
+
async function createRuntimeApp(options) {
|
|
4
|
+
const bun = globalThis.Bun;
|
|
5
|
+
if (bun) {
|
|
6
|
+
const { createApp: createBunApp } = await import("./adapters/bun/create-app.js");
|
|
7
|
+
return await createBunApp(options);
|
|
8
|
+
}
|
|
9
|
+
const { createNodeApp } = await import("./adapters/node/create-app.js");
|
|
10
|
+
return await createNodeApp(options);
|
|
11
|
+
}
|
|
12
|
+
async function createApp(options) {
|
|
13
|
+
return createRuntimeApp(options);
|
|
14
|
+
}
|
|
15
|
+
class EcopagesApp extends SharedApplicationAdapter {
|
|
16
|
+
appOptions;
|
|
17
|
+
runtimeApp = null;
|
|
18
|
+
runtimeAppPromise = null;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super(options);
|
|
21
|
+
this.appOptions = options;
|
|
22
|
+
}
|
|
23
|
+
async getRuntimeApp() {
|
|
24
|
+
if (this.runtimeApp) {
|
|
25
|
+
return this.runtimeApp;
|
|
26
|
+
}
|
|
27
|
+
if (!this.runtimeAppPromise) {
|
|
28
|
+
this.runtimeAppPromise = createRuntimeApp({
|
|
29
|
+
...this.appOptions,
|
|
30
|
+
clearOutput: false
|
|
31
|
+
}).then((app) => {
|
|
32
|
+
for (const handler of this.apiHandlers) {
|
|
33
|
+
app.add(handler);
|
|
34
|
+
}
|
|
35
|
+
for (const route of this.staticRoutes) {
|
|
36
|
+
app.static(route.path, route.loader);
|
|
37
|
+
}
|
|
38
|
+
if (this.errorHandler) {
|
|
39
|
+
app.onError(this.errorHandler);
|
|
40
|
+
}
|
|
41
|
+
this.runtimeApp = app;
|
|
42
|
+
return app;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return this.runtimeAppPromise;
|
|
46
|
+
}
|
|
47
|
+
async initializeServerAdapter() {
|
|
48
|
+
return this.getRuntimeApp();
|
|
49
|
+
}
|
|
50
|
+
async start() {
|
|
51
|
+
const runtimeApp = await this.getRuntimeApp();
|
|
52
|
+
return runtimeApp.start();
|
|
53
|
+
}
|
|
54
|
+
async fetch(request) {
|
|
55
|
+
const runtimeApp = await this.getRuntimeApp();
|
|
56
|
+
const candidate = runtimeApp;
|
|
57
|
+
if (!candidate.fetch) {
|
|
58
|
+
throw new Error("The selected runtime adapter does not expose fetch()");
|
|
59
|
+
}
|
|
60
|
+
return candidate.fetch(request);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
EcopagesApp,
|
|
65
|
+
createApp
|
|
66
|
+
};
|