jimpex 7.0.2 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/LICENSE +1 -1
- package/README.md +447 -435
- package/dist/app/index.d.mts +14 -0
- package/dist/app/index.d.ts +14 -0
- package/dist/app/index.js +23 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/jimpex.d.mts +14 -0
- package/dist/app/jimpex.d.ts +14 -0
- package/dist/app/jimpex.js +665 -0
- package/dist/app/jimpex.js.map +1 -0
- package/dist/controllers/common/config.d.mts +79 -0
- package/dist/controllers/common/config.d.ts +79 -0
- package/dist/controllers/common/config.js +107 -0
- package/dist/controllers/common/config.js.map +1 -0
- package/dist/controllers/common/health.d.mts +83 -0
- package/dist/controllers/common/health.d.ts +83 -0
- package/dist/controllers/common/health.js +115 -0
- package/dist/controllers/common/health.js.map +1 -0
- package/dist/controllers/common/index.d.mts +21 -0
- package/dist/controllers/common/index.d.ts +21 -0
- package/dist/controllers/common/index.js +27 -0
- package/dist/controllers/common/index.js.map +1 -0
- package/dist/controllers/common/statics.d.mts +215 -0
- package/dist/controllers/common/statics.d.ts +215 -0
- package/dist/controllers/common/statics.js +253 -0
- package/dist/controllers/common/statics.js.map +1 -0
- package/dist/controllers/index.d.mts +24 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +25 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/utils/gateway.d.mts +725 -0
- package/dist/controllers/utils/gateway.d.ts +725 -0
- package/dist/controllers/utils/gateway.js +577 -0
- package/dist/controllers/utils/gateway.js.map +1 -0
- package/dist/controllers/utils/index.d.mts +17 -0
- package/dist/controllers/utils/index.d.ts +17 -0
- package/dist/controllers/utils/index.js +23 -0
- package/dist/controllers/utils/index.js.map +1 -0
- package/dist/esm/app/index.js +2 -0
- package/dist/esm/app/index.js.map +1 -0
- package/dist/esm/app/jimpex.js +636 -0
- package/dist/esm/app/jimpex.js.map +1 -0
- package/dist/esm/chunk-2B2CG5KL.js +11 -0
- package/dist/esm/chunk-2B2CG5KL.js.map +1 -0
- package/dist/esm/controllers/common/config.js +80 -0
- package/dist/esm/controllers/common/config.js.map +1 -0
- package/dist/esm/controllers/common/health.js +88 -0
- package/dist/esm/controllers/common/health.js.map +1 -0
- package/dist/esm/controllers/common/index.js +4 -0
- package/dist/esm/controllers/common/index.js.map +1 -0
- package/dist/esm/controllers/common/statics.js +220 -0
- package/dist/esm/controllers/common/statics.js.map +1 -0
- package/dist/esm/controllers/index.js +3 -0
- package/dist/esm/controllers/index.js.map +1 -0
- package/dist/esm/controllers/utils/gateway.js +556 -0
- package/dist/esm/controllers/utils/gateway.js.map +1 -0
- package/dist/esm/controllers/utils/index.js +2 -0
- package/dist/esm/controllers/utils/index.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middlewares/common/errorHandler.js +116 -0
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
- package/dist/esm/middlewares/common/forceHTTPS.js +53 -0
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/esm/middlewares/common/hsts.js +74 -0
- package/dist/esm/middlewares/common/hsts.js.map +1 -0
- package/dist/esm/middlewares/common/index.js +4 -0
- package/dist/esm/middlewares/common/index.js.map +1 -0
- package/dist/esm/middlewares/html/fastHTML.js +158 -0
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
- package/dist/esm/middlewares/html/index.js +3 -0
- package/dist/esm/middlewares/html/index.js.map +1 -0
- package/dist/esm/middlewares/html/showHTML.js +100 -0
- package/dist/esm/middlewares/html/showHTML.js.map +1 -0
- package/dist/esm/middlewares/index.js +4 -0
- package/dist/esm/middlewares/index.js.map +1 -0
- package/dist/esm/middlewares/utils/index.js +2 -0
- package/dist/esm/middlewares/utils/index.js.map +1 -0
- package/dist/esm/middlewares/utils/versionValidator.js +135 -0
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/esm/services/common/appError.js +98 -0
- package/dist/esm/services/common/appError.js.map +1 -0
- package/dist/esm/services/common/httpError.js +28 -0
- package/dist/esm/services/common/httpError.js.map +1 -0
- package/dist/esm/services/common/index.js +17 -0
- package/dist/esm/services/common/index.js.map +1 -0
- package/dist/esm/services/common/sendFile.js +27 -0
- package/dist/esm/services/common/sendFile.js.map +1 -0
- package/dist/esm/services/frontend/frontendFs.js +66 -0
- package/dist/esm/services/frontend/frontendFs.js.map +1 -0
- package/dist/esm/services/frontend/index.js +11 -0
- package/dist/esm/services/frontend/index.js.map +1 -0
- package/dist/esm/services/html/htmlGenerator.js +194 -0
- package/dist/esm/services/html/htmlGenerator.js.map +1 -0
- package/dist/esm/services/html/index.js +11 -0
- package/dist/esm/services/html/index.js.map +1 -0
- package/dist/esm/services/http/apiClient.js +97 -0
- package/dist/esm/services/http/apiClient.js.map +1 -0
- package/dist/esm/services/http/http.js +174 -0
- package/dist/esm/services/http/http.js.map +1 -0
- package/dist/esm/services/http/index.js +17 -0
- package/dist/esm/services/http/index.js.map +1 -0
- package/dist/esm/services/http/responsesBuilder.js +152 -0
- package/dist/esm/services/http/responsesBuilder.js.map +1 -0
- package/dist/esm/services/index.js +6 -0
- package/dist/esm/services/index.js.map +1 -0
- package/dist/esm/services/utils/ensureBearerToken.js +94 -0
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/esm/services/utils/index.js +11 -0
- package/dist/esm/services/utils/index.js.map +1 -0
- package/dist/esm/types/events.js +1 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/express.js +1 -0
- package/dist/esm/types/express.js.map +1 -0
- package/dist/esm/types/http.js +1 -0
- package/dist/esm/types/http.js.map +1 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/options.js.map +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/types/utils.js.map +1 -0
- package/dist/esm/types/wootils.js +1 -0
- package/dist/esm/types/wootils.js.map +1 -0
- package/dist/esm/utils/fns/index.js +5 -0
- package/dist/esm/utils/fns/index.js.map +1 -0
- package/dist/esm/utils/fns/others.js +6 -0
- package/dist/esm/utils/fns/others.js.map +1 -0
- package/dist/esm/utils/fns/routes.js +25 -0
- package/dist/esm/utils/fns/routes.js.map +1 -0
- package/dist/esm/utils/fns/statuses.js +6 -0
- package/dist/esm/utils/fns/statuses.js.map +1 -0
- package/dist/esm/utils/fns/text.js +6 -0
- package/dist/esm/utils/fns/text.js.map +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/wrappers.js +41 -0
- package/dist/esm/utils/wrappers.js.map +1 -0
- package/dist/index-b2a04c78.d.ts +1282 -0
- package/dist/index-efeb437e.d.ts +1282 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/common/errorHandler.d.mts +132 -0
- package/dist/middlewares/common/errorHandler.d.ts +132 -0
- package/dist/middlewares/common/errorHandler.js +143 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -0
- package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +69 -0
- package/dist/middlewares/common/forceHTTPS.js +80 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/middlewares/common/hsts.d.mts +110 -0
- package/dist/middlewares/common/hsts.d.ts +110 -0
- package/dist/middlewares/common/hsts.js +101 -0
- package/dist/middlewares/common/hsts.js.map +1 -0
- package/dist/middlewares/common/index.d.mts +22 -0
- package/dist/middlewares/common/index.d.ts +22 -0
- package/dist/middlewares/common/index.js +27 -0
- package/dist/middlewares/common/index.js.map +1 -0
- package/dist/middlewares/html/fastHTML.d.mts +180 -0
- package/dist/middlewares/html/fastHTML.d.ts +180 -0
- package/dist/middlewares/html/fastHTML.js +185 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -0
- package/dist/middlewares/html/index.d.mts +21 -0
- package/dist/middlewares/html/index.d.ts +21 -0
- package/dist/middlewares/html/index.js +25 -0
- package/dist/middlewares/html/index.js.map +1 -0
- package/dist/middlewares/html/showHTML.d.mts +127 -0
- package/dist/middlewares/html/showHTML.d.ts +127 -0
- package/dist/middlewares/html/showHTML.js +127 -0
- package/dist/middlewares/html/showHTML.js.map +1 -0
- package/dist/middlewares/index.d.mts +30 -0
- package/dist/middlewares/index.d.ts +30 -0
- package/dist/middlewares/index.js +27 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/utils/index.d.mts +20 -0
- package/dist/middlewares/utils/index.d.ts +20 -0
- package/dist/middlewares/utils/index.js +23 -0
- package/dist/middlewares/utils/index.js.map +1 -0
- package/dist/middlewares/utils/versionValidator.d.mts +215 -0
- package/dist/middlewares/utils/versionValidator.d.ts +215 -0
- package/dist/middlewares/utils/versionValidator.js +162 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/services/common/appError.d.mts +139 -0
- package/dist/services/common/appError.d.ts +139 -0
- package/dist/services/common/appError.js +126 -0
- package/dist/services/common/appError.js.map +1 -0
- package/dist/services/common/httpError.d.mts +80 -0
- package/dist/services/common/httpError.d.ts +80 -0
- package/dist/services/common/httpError.js +53 -0
- package/dist/services/common/httpError.js.map +1 -0
- package/dist/services/common/index.d.mts +47 -0
- package/dist/services/common/index.d.ts +47 -0
- package/dist/services/common/index.js +44 -0
- package/dist/services/common/index.js.map +1 -0
- package/dist/services/common/sendFile.d.mts +102 -0
- package/dist/services/common/sendFile.d.ts +102 -0
- package/dist/services/common/sendFile.js +51 -0
- package/dist/services/common/sendFile.js.map +1 -0
- package/dist/services/frontend/frontendFs.d.mts +96 -0
- package/dist/services/frontend/frontendFs.d.ts +96 -0
- package/dist/services/frontend/frontendFs.js +103 -0
- package/dist/services/frontend/frontendFs.js.map +1 -0
- package/dist/services/frontend/index.d.mts +40 -0
- package/dist/services/frontend/index.d.ts +40 -0
- package/dist/services/frontend/index.js +36 -0
- package/dist/services/frontend/index.js.map +1 -0
- package/dist/services/html/htmlGenerator.d.mts +237 -0
- package/dist/services/html/htmlGenerator.d.ts +237 -0
- package/dist/services/html/htmlGenerator.js +221 -0
- package/dist/services/html/htmlGenerator.js.map +1 -0
- package/dist/services/html/index.d.mts +43 -0
- package/dist/services/html/index.d.ts +43 -0
- package/dist/services/html/index.js +36 -0
- package/dist/services/html/index.js.map +1 -0
- package/dist/services/http/apiClient.d.mts +170 -0
- package/dist/services/http/apiClient.d.ts +170 -0
- package/dist/services/http/apiClient.js +122 -0
- package/dist/services/http/apiClient.js.map +1 -0
- package/dist/services/http/http.d.mts +176 -0
- package/dist/services/http/http.d.ts +176 -0
- package/dist/services/http/http.js +211 -0
- package/dist/services/http/http.js.map +1 -0
- package/dist/services/http/index.d.mts +51 -0
- package/dist/services/http/index.d.ts +51 -0
- package/dist/services/http/index.js +44 -0
- package/dist/services/http/index.js.map +1 -0
- package/dist/services/http/responsesBuilder.d.mts +179 -0
- package/dist/services/http/responsesBuilder.d.ts +179 -0
- package/dist/services/http/responsesBuilder.js +179 -0
- package/dist/services/http/responsesBuilder.js.map +1 -0
- package/dist/services/index.d.mts +33 -0
- package/dist/services/index.d.ts +33 -0
- package/dist/services/index.js +31 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/utils/ensureBearerToken.d.mts +158 -0
- package/dist/services/utils/ensureBearerToken.d.ts +158 -0
- package/dist/services/utils/ensureBearerToken.js +121 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/services/utils/index.d.mts +44 -0
- package/dist/services/utils/index.d.ts +44 -0
- package/dist/services/utils/index.js +36 -0
- package/dist/services/utils/index.js.map +1 -0
- package/dist/types/events.d.mts +14 -0
- package/dist/types/events.d.ts +14 -0
- package/dist/types/events.js +17 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/express.d.mts +10 -0
- package/dist/types/express.d.ts +10 -0
- package/dist/types/express.js +17 -0
- package/dist/types/express.js.map +1 -0
- package/dist/types/http.d.mts +79 -0
- package/dist/types/http.d.ts +79 -0
- package/dist/types/http.js +17 -0
- package/dist/types/http.js.map +1 -0
- package/dist/types/index.d.mts +14 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.mts +14 -0
- package/dist/types/options.d.ts +14 -0
- package/dist/types/options.js +17 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/utils.d.mts +48 -0
- package/dist/types/utils.d.ts +48 -0
- package/dist/types/utils.js +17 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types/wootils.d.mts +4 -0
- package/dist/types/wootils.d.ts +4 -0
- package/dist/types/wootils.js +17 -0
- package/dist/types/wootils.js.map +1 -0
- package/dist/utils/fns/index.d.mts +5 -0
- package/dist/utils/fns/index.d.ts +5 -0
- package/dist/utils/fns/index.js +29 -0
- package/dist/utils/fns/index.js.map +1 -0
- package/dist/utils/fns/others.d.mts +17 -0
- package/dist/utils/fns/others.d.ts +17 -0
- package/dist/utils/fns/others.js +29 -0
- package/dist/utils/fns/others.js.map +1 -0
- package/dist/utils/fns/routes.d.mts +39 -0
- package/dist/utils/fns/routes.d.ts +39 -0
- package/dist/utils/fns/routes.js +51 -0
- package/dist/utils/fns/routes.js.map +1 -0
- package/dist/utils/fns/statuses.d.mts +45 -0
- package/dist/utils/fns/statuses.d.ts +45 -0
- package/dist/utils/fns/statuses.js +39 -0
- package/dist/utils/fns/statuses.js.map +1 -0
- package/dist/utils/fns/text.d.mts +9 -0
- package/dist/utils/fns/text.d.ts +9 -0
- package/dist/utils/fns/text.js +29 -0
- package/dist/utils/fns/text.js.map +1 -0
- package/dist/utils/index.d.mts +19 -0
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.js +25 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/wrappers.d.mts +14 -0
- package/dist/utils/wrappers.d.ts +14 -0
- package/dist/utils/wrappers.js +68 -0
- package/dist/utils/wrappers.js.map +1 -0
- package/examples/basic/404.html +12 -0
- package/examples/basic/README.md +30 -0
- package/examples/basic/app.ts +18 -0
- package/examples/basic/controller.ts +45 -0
- package/examples/basic/index.ts +19 -0
- package/examples/basic/middleware.ts +13 -0
- package/examples/basic/service.ts +11 -0
- package/package.json +60 -39
- package/src/app/index.ts +1 -0
- package/src/app/jimpex.ts +743 -0
- package/src/controllers/common/config.ts +115 -0
- package/src/controllers/common/health.ts +128 -0
- package/src/controllers/common/index.ts +3 -0
- package/src/controllers/common/statics.ts +380 -0
- package/src/controllers/index.ts +2 -0
- package/src/controllers/utils/gateway.ts +1186 -0
- package/src/controllers/utils/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/middlewares/common/errorHandler.ts +203 -0
- package/src/middlewares/common/forceHTTPS.ts +83 -0
- package/src/middlewares/common/hsts.ts +135 -0
- package/src/middlewares/common/index.ts +3 -0
- package/src/middlewares/html/fastHTML.ts +255 -0
- package/src/middlewares/html/index.ts +2 -0
- package/src/middlewares/html/showHTML.ts +165 -0
- package/src/middlewares/index.ts +3 -0
- package/src/middlewares/utils/index.ts +1 -0
- package/src/middlewares/utils/versionValidator.ts +289 -0
- package/src/services/common/appError.ts +158 -0
- package/src/services/common/httpError.ts +74 -0
- package/src/services/common/index.ts +29 -0
- package/src/services/common/sendFile.ts +106 -0
- package/src/services/frontend/frontendFs.ts +101 -0
- package/src/services/frontend/index.ts +21 -0
- package/src/services/html/htmlGenerator.ts +356 -0
- package/src/services/html/index.ts +21 -0
- package/src/services/http/apiClient.ts +221 -0
- package/src/services/http/http.ts +286 -0
- package/src/services/http/index.ts +29 -0
- package/src/services/http/responsesBuilder.ts +265 -0
- package/src/services/index.ts +5 -0
- package/src/services/utils/ensureBearerToken.ts +202 -0
- package/src/services/utils/index.ts +21 -0
- package/src/types/events.ts +303 -0
- package/src/types/express.ts +21 -0
- package/src/types/http.ts +77 -0
- package/src/types/index.ts +6 -0
- package/src/types/options.ts +248 -0
- package/src/types/utils.ts +52 -0
- package/src/types/wootils.ts +4 -0
- package/src/utils/fns/index.ts +4 -0
- package/src/utils/fns/others.ts +15 -0
- package/src/utils/fns/routes.ts +64 -0
- package/src/utils/fns/statuses.ts +44 -0
- package/src/utils/fns/text.ts +8 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/wrappers.ts +537 -0
- package/tsconfig.json +5 -8
- package/tsup.config.ts +10 -0
- package/src/app/index.js +0 -692
- package/src/constants/eventNames.js +0 -48
- package/src/constants/index.js +0 -7
- package/src/controllers/common/configuration.js +0 -116
- package/src/controllers/common/health.js +0 -79
- package/src/controllers/common/index.js +0 -7
- package/src/controllers/common/statics.js +0 -336
- package/src/controllers/index.js +0 -9
- package/src/controllers/utils/gateway.js +0 -1039
- package/src/controllers/utils/index.js +0 -3
- package/src/index.js +0 -30
- package/src/middlewares/common/errorHandler.js +0 -185
- package/src/middlewares/common/forceHTTPS.js +0 -80
- package/src/middlewares/common/hsts.js +0 -122
- package/src/middlewares/common/index.js +0 -7
- package/src/middlewares/html/fastHTML.js +0 -298
- package/src/middlewares/html/index.js +0 -5
- package/src/middlewares/html/showHTML.js +0 -167
- package/src/middlewares/index.js +0 -11
- package/src/middlewares/utils/index.js +0 -3
- package/src/middlewares/utils/versionValidator.js +0 -261
- package/src/services/common/appError.js +0 -136
- package/src/services/common/httpError.js +0 -60
- package/src/services/common/index.js +0 -25
- package/src/services/common/sendFile.js +0 -68
- package/src/services/frontend/frontendFs.js +0 -85
- package/src/services/frontend/index.js +0 -17
- package/src/services/html/htmlGenerator.js +0 -391
- package/src/services/html/index.js +0 -17
- package/src/services/http/apiClient.js +0 -148
- package/src/services/http/http.js +0 -256
- package/src/services/http/index.js +0 -25
- package/src/services/http/responsesBuilder.js +0 -193
- package/src/services/index.js +0 -15
- package/src/services/utils/ensureBearerToken.js +0 -147
- package/src/services/utils/index.js +0 -19
- package/src/types.js +0 -377
- package/src/utils/functions.js +0 -78
- package/src/utils/wrappers.js +0 -131
- package/types/app/index.d.ts +0 -417
- package/types/constants/eventNames.d.ts +0 -93
- package/types/constants/index.d.ts +0 -2
- package/types/controllers/common/configuration.d.ts +0 -71
- package/types/controllers/common/health.d.ts +0 -55
- package/types/controllers/common/index.d.ts +0 -4
- package/types/controllers/common/statics.d.ts +0 -271
- package/types/controllers/index.d.ts +0 -3
- package/types/controllers/utils/gateway.d.ts +0 -947
- package/types/controllers/utils/index.d.ts +0 -2
- package/types/index.d.ts +0 -15
- package/types/middlewares/common/errorHandler.d.ts +0 -143
- package/types/middlewares/common/forceHTTPS.d.ts +0 -64
- package/types/middlewares/common/hsts.d.ts +0 -111
- package/types/middlewares/common/index.d.ts +0 -4
- package/types/middlewares/html/fastHTML.d.ts +0 -238
- package/types/middlewares/html/index.d.ts +0 -3
- package/types/middlewares/html/showHTML.d.ts +0 -128
- package/types/middlewares/index.d.ts +0 -4
- package/types/middlewares/utils/index.d.ts +0 -2
- package/types/middlewares/utils/versionValidator.d.ts +0 -247
- package/types/services/common/appError.d.ts +0 -89
- package/types/services/common/httpError.d.ts +0 -37
- package/types/services/common/index.d.ts +0 -18
- package/types/services/common/sendFile.d.ts +0 -56
- package/types/services/frontend/frontendFs.d.ts +0 -72
- package/types/services/frontend/index.d.ts +0 -3
- package/types/services/html/htmlGenerator.d.ts +0 -298
- package/types/services/html/index.d.ts +0 -3
- package/types/services/http/apiClient.d.ts +0 -141
- package/types/services/http/http.d.ts +0 -159
- package/types/services/http/index.d.ts +0 -18
- package/types/services/http/responsesBuilder.d.ts +0 -140
- package/types/services/index.d.ts +0 -6
- package/types/services/utils/ensureBearerToken.d.ts +0 -137
- package/types/services/utils/index.d.ts +0 -16
- package/types/types.d.ts +0 -280
- package/types/utils/functions.d.ts +0 -55
- package/types/utils/wrappers.d.ts +0 -127
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { providers } from '../../utils';
|
|
2
|
+
import { appErrorProvider } from './appError';
|
|
3
|
+
import { httpErrorProvider } from './httpError';
|
|
4
|
+
import { sendFileProvider } from './sendFile';
|
|
5
|
+
/**
|
|
6
|
+
* Registers all the common services on the container.
|
|
7
|
+
*
|
|
8
|
+
* - {@link AppError | appError}
|
|
9
|
+
* - {@link HTTPError | httpError}
|
|
10
|
+
* - {@link SendFile | sendFile}
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* // Register the collection on the container
|
|
15
|
+
* container.register(commonServicesProvider);
|
|
16
|
+
* // Getting access to one the services instance
|
|
17
|
+
* const sendFile = container.get<SendFile>('sendFile');
|
|
18
|
+
*
|
|
19
|
+
* @group Providers
|
|
20
|
+
*/
|
|
21
|
+
export const commonServicesProvider = providers({
|
|
22
|
+
appErrorProvider,
|
|
23
|
+
httpErrorProvider,
|
|
24
|
+
sendFileProvider,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export * from './appError';
|
|
28
|
+
export * from './httpError';
|
|
29
|
+
export * from './sendFile';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { provider } from '../../utils';
|
|
2
|
+
import type { Response, NextFunction, PathUtils } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* The options to create a {@link SendFile} function.
|
|
5
|
+
*
|
|
6
|
+
* @group Services/SendFile
|
|
7
|
+
*/
|
|
8
|
+
export type SendFileGeneratorOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* A dictionary with the dependencies to inject.
|
|
11
|
+
*/
|
|
12
|
+
inject: {
|
|
13
|
+
pathUtils: PathUtils;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The options for the function that actually serves a file.
|
|
18
|
+
*
|
|
19
|
+
* @group Services/SendFile
|
|
20
|
+
*/
|
|
21
|
+
export type SendFileOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* The response object sent by the application. Necessary to write the file.
|
|
24
|
+
*/
|
|
25
|
+
res: Response;
|
|
26
|
+
/**
|
|
27
|
+
* The path of the file to serve. Depending on the `from` option, it will be either
|
|
28
|
+
* relative to the project root, or the application executable.
|
|
29
|
+
*/
|
|
30
|
+
filepath: string;
|
|
31
|
+
/**
|
|
32
|
+
* The name of a location on the `pathUtils` service from where the `filepath` is
|
|
33
|
+
* relative to. It can be `app` for the directory containing the application executable,
|
|
34
|
+
* or `project` for the project root. It could also be any other location that the
|
|
35
|
+
* implementation may have registered.
|
|
36
|
+
*
|
|
37
|
+
* @default 'app'
|
|
38
|
+
*/
|
|
39
|
+
from?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The function to move to the next middleware. It can be used to report an error in
|
|
42
|
+
* case the file can't be served.
|
|
43
|
+
*
|
|
44
|
+
* @default {() => {}}
|
|
45
|
+
*/
|
|
46
|
+
next?: NextFunction;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The type of the function that serves a file.
|
|
50
|
+
* This is exported to make it easy to type the dependency injection.
|
|
51
|
+
*
|
|
52
|
+
* @group Services/SendFile
|
|
53
|
+
*/
|
|
54
|
+
export type SendFile = (options: SendFileOptions) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Generates a function to send files on the application response.
|
|
57
|
+
*
|
|
58
|
+
* @param options To inject the required dependencies.
|
|
59
|
+
* @example
|
|
60
|
+
*
|
|
61
|
+
* <caption>Basic usage</caption>
|
|
62
|
+
*
|
|
63
|
+
* // Let's say this is inside an Express middleware.
|
|
64
|
+
* // Get the function
|
|
65
|
+
* const send = sendFile(pathUtils);
|
|
66
|
+
* send({ res, filepath: 'some-file.html', next });
|
|
67
|
+
* // If your app is on "/app/index.js", this will send "/app/some-file.html".
|
|
68
|
+
*
|
|
69
|
+
* @group Services
|
|
70
|
+
* @group Services/SendFile
|
|
71
|
+
*/
|
|
72
|
+
export const sendFile =
|
|
73
|
+
({ inject: { pathUtils } }: SendFileGeneratorOptions): SendFile =>
|
|
74
|
+
({ res, filepath, from = 'app', next = () => {} }) => {
|
|
75
|
+
res.sendFile(pathUtils.joinFrom(from, filepath), (error) => {
|
|
76
|
+
if (error) {
|
|
77
|
+
next(error);
|
|
78
|
+
} else {
|
|
79
|
+
res.end();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The service provider that once registered on the container will set the result of
|
|
86
|
+
* {@link sendFile} as the `sendFile` service.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* // Register it on the container
|
|
91
|
+
* container.register(sendFileProvider);
|
|
92
|
+
* // Getting access to the service instance
|
|
93
|
+
* const sendFile = container.get<SendFile>('sendFile');
|
|
94
|
+
*
|
|
95
|
+
* @group Providers
|
|
96
|
+
* @group Services/SendFile
|
|
97
|
+
*/
|
|
98
|
+
export const sendFileProvider = provider((app) => {
|
|
99
|
+
app.set('sendFile', () =>
|
|
100
|
+
sendFile({
|
|
101
|
+
inject: {
|
|
102
|
+
pathUtils: app.get('pathUtils'),
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import { provider } from '../../utils';
|
|
3
|
+
import type { PathUtils } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* The options to construct a {@link FrontendFs}.
|
|
6
|
+
*
|
|
7
|
+
* @group Services/FrontendFs
|
|
8
|
+
*/
|
|
9
|
+
export type FrontendFsOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* A dictionary with the dependencies to inject.
|
|
12
|
+
*/
|
|
13
|
+
inject: {
|
|
14
|
+
pathUtils: PathUtils;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* This service allows the application to easily work with the filesystem. The idea behind
|
|
19
|
+
* centralizing this functionalities into a service is that is pretty common to have
|
|
20
|
+
* bundling tools to generate the frontend, and on that process files can have different
|
|
21
|
+
* paths or not even be generated all. The service can be extended/overwritten to
|
|
22
|
+
* accommodate any requirements and avoid having to update or add `if`s to every `fs` call
|
|
23
|
+
* the application does.
|
|
24
|
+
* Another _'feature'_ of this service is that all the paths are relative to the directory
|
|
25
|
+
* where the app executable is located, so you don't have to remember the relative path
|
|
26
|
+
* from the place you are accessing a file to the place where it's located.
|
|
27
|
+
*
|
|
28
|
+
* @group Services
|
|
29
|
+
* @group Services/FrontendFs
|
|
30
|
+
*/
|
|
31
|
+
export class FrontendFs {
|
|
32
|
+
/**
|
|
33
|
+
* The service that generates the relative paths.
|
|
34
|
+
*/
|
|
35
|
+
protected readonly _pathUtils: PathUtils;
|
|
36
|
+
/**
|
|
37
|
+
* @param options The options to construct the service.
|
|
38
|
+
*/
|
|
39
|
+
constructor({ inject: { pathUtils } }: FrontendFsOptions) {
|
|
40
|
+
this._pathUtils = pathUtils;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Deletes a file from the file system.
|
|
44
|
+
*
|
|
45
|
+
* @param filepath The path to the file.
|
|
46
|
+
*/
|
|
47
|
+
delete(filepath: string): Promise<void> {
|
|
48
|
+
return fs.unlink(this.getAppPath(filepath));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Reads a file from the file system.
|
|
52
|
+
*
|
|
53
|
+
* @param filepath The path to the file.
|
|
54
|
+
* @param encoding The text encoding in which the file should be read.
|
|
55
|
+
*/
|
|
56
|
+
read(filepath: string, encoding: BufferEncoding = 'utf-8'): Promise<string> {
|
|
57
|
+
return fs.readFile(this.getAppPath(filepath), encoding);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Writes a file on the file system.
|
|
61
|
+
*
|
|
62
|
+
* @param filepath The path to the file.
|
|
63
|
+
* @param content The contents of the file.
|
|
64
|
+
*/
|
|
65
|
+
write(filepath: string, content: Parameters<typeof fs.writeFile>[1]): Promise<void> {
|
|
66
|
+
return fs.writeFile(this.getAppPath(filepath), content);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Utility method to get the path of a file relative to the application executable.
|
|
70
|
+
*
|
|
71
|
+
* @param filepath The path to the file.
|
|
72
|
+
*/
|
|
73
|
+
protected getAppPath(filepath: string): string {
|
|
74
|
+
return this._pathUtils.joinFrom('app', filepath);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The service provider that once registered on the container will set an instance of
|
|
79
|
+
* {@link FrontendFs} as the `frontendFs` service.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
*
|
|
83
|
+
* // Register it on the container
|
|
84
|
+
* container.register(frontendFsProvider);
|
|
85
|
+
* // Getting access to the service instance
|
|
86
|
+
* const frontendFs = container.get<FrontendFs>('frontendFs');
|
|
87
|
+
*
|
|
88
|
+
* @group Providers
|
|
89
|
+
* @group Services/FrontendFs
|
|
90
|
+
*/
|
|
91
|
+
export const frontendFsProvider = provider((app) => {
|
|
92
|
+
app.set(
|
|
93
|
+
'frontendFs',
|
|
94
|
+
() =>
|
|
95
|
+
new FrontendFs({
|
|
96
|
+
inject: {
|
|
97
|
+
pathUtils: app.get<PathUtils>('pathUtils'),
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { providers } from '../../utils';
|
|
2
|
+
import { frontendFsProvider } from './frontendFs';
|
|
3
|
+
/**
|
|
4
|
+
* Registers all the frontend services on the container.
|
|
5
|
+
*
|
|
6
|
+
* - {@link FrontendFs | frontendFs}
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* // Register the collection on the container
|
|
11
|
+
* container.register(frontendServicesProvider);
|
|
12
|
+
* // Getting access to one the services instance
|
|
13
|
+
* const frontendFs = container.get<FrontendFs>('frontendFs');
|
|
14
|
+
*
|
|
15
|
+
* @group Providers
|
|
16
|
+
*/
|
|
17
|
+
export const frontendServicesProvider = providers({
|
|
18
|
+
frontendFsProvider,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export * from './frontendFs';
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { get } from '@homer0/object-utils';
|
|
2
|
+
import { deepAssignWithOverwrite } from '@homer0/deep-assign';
|
|
3
|
+
import { deferred, type DeferredPromise } from '@homer0/deferred';
|
|
4
|
+
import { providerCreator } from '../../utils';
|
|
5
|
+
import type { Config, Logger } from '../../types';
|
|
6
|
+
import type { FrontendFs } from '../frontend';
|
|
7
|
+
/**
|
|
8
|
+
* The options to customize a {@link HTMLGenerator} instance.
|
|
9
|
+
*
|
|
10
|
+
* @group Services/HTMLGenerator
|
|
11
|
+
*/
|
|
12
|
+
export type HTMLGeneratorOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The name of the file it should use as template.
|
|
15
|
+
*
|
|
16
|
+
* @default 'index.tpl.html'
|
|
17
|
+
*/
|
|
18
|
+
template: string;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the generated file.
|
|
21
|
+
*
|
|
22
|
+
* @default 'index.html'
|
|
23
|
+
*/
|
|
24
|
+
file: string;
|
|
25
|
+
/**
|
|
26
|
+
* If `true`, it won't log messages on the terminal when generating the file.
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
silent: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether or not to delete the tempalte after generating the file.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
deleteTemplateAfter: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The placeholder string where the information will be written.
|
|
39
|
+
*
|
|
40
|
+
* @default /\{\{appConfi(?:guration)?\}\}/
|
|
41
|
+
*/
|
|
42
|
+
replacePlaceholder: string | RegExp;
|
|
43
|
+
/**
|
|
44
|
+
* A regular expression for dynamic placeholders that will be replaced by values when
|
|
45
|
+
* the file is generated.
|
|
46
|
+
*
|
|
47
|
+
* @default /\{\{(.*?)\}\}/gi
|
|
48
|
+
*/
|
|
49
|
+
placeholderExpression: RegExp;
|
|
50
|
+
/**
|
|
51
|
+
* The name of the variable that will have the information on the file.
|
|
52
|
+
*
|
|
53
|
+
* @default 'appConfig'
|
|
54
|
+
*/
|
|
55
|
+
variableName: string;
|
|
56
|
+
/**
|
|
57
|
+
* A list of settings from the app configuration that will be used as the information to
|
|
58
|
+
* inject on the file.
|
|
59
|
+
*
|
|
60
|
+
* @default ['features', 'version', 'postMessagesPrefix']
|
|
61
|
+
*/
|
|
62
|
+
configKeys: string[];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* An external service that can be used to provide the values the generator will replace
|
|
66
|
+
* in the template.
|
|
67
|
+
*
|
|
68
|
+
* @group Services/HTMLGenerator
|
|
69
|
+
*/
|
|
70
|
+
export type HTMLGeneratorValuesService = {
|
|
71
|
+
/**
|
|
72
|
+
* A function that will be called to get the values to replace in the template.
|
|
73
|
+
*
|
|
74
|
+
* @param options The service customization options.
|
|
75
|
+
*/
|
|
76
|
+
getValues: (options: HTMLGeneratorOptions) => Promise<Record<string, unknown>>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The options to construct a {@link HTMLGenerator}.
|
|
80
|
+
*
|
|
81
|
+
* @group Services/HTMLGenerator
|
|
82
|
+
*/
|
|
83
|
+
export type HTMLGeneratorConstructorOptions = Partial<HTMLGeneratorOptions> & {
|
|
84
|
+
/**
|
|
85
|
+
* A dictionary with the dependencies to inject.
|
|
86
|
+
*/
|
|
87
|
+
inject: {
|
|
88
|
+
config: Config;
|
|
89
|
+
logger: Logger;
|
|
90
|
+
frontendFs: FrontendFs;
|
|
91
|
+
/**
|
|
92
|
+
* A service that can provide the values to replace in the template. If specified, the
|
|
93
|
+
* values from `configKeys` will be ignored.
|
|
94
|
+
*/
|
|
95
|
+
valuesService?: HTMLGeneratorValuesService;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Custom options for the provider that will register an instance of {@link HTMLGenerator}
|
|
100
|
+
* as a service.
|
|
101
|
+
*
|
|
102
|
+
* @group Services/HTMLGenerator
|
|
103
|
+
*/
|
|
104
|
+
export type HTMLGeneratorProviderOptions = Partial<HTMLGeneratorOptions> & {
|
|
105
|
+
/**
|
|
106
|
+
* The name that will be used to register the service on the container. This is to allow
|
|
107
|
+
* multiple "instances" of the service to be created.
|
|
108
|
+
*
|
|
109
|
+
* @default 'htmlGenerator'
|
|
110
|
+
*/
|
|
111
|
+
serviceName?: string;
|
|
112
|
+
/**
|
|
113
|
+
* The name of a service that the generator will use in order to read the values that
|
|
114
|
+
* will be replaced on the template. If the service is available, the values from
|
|
115
|
+
* `configKeys` will be ignored.
|
|
116
|
+
*
|
|
117
|
+
* @default 'htmlGeneratorValues'
|
|
118
|
+
*/
|
|
119
|
+
valuesServiceName?: string;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* This is a utility service that generates an HTML file with custom information when the
|
|
123
|
+
* application is started.
|
|
124
|
+
*
|
|
125
|
+
* @group Services
|
|
126
|
+
* @group Services/HTMLGenerator
|
|
127
|
+
*/
|
|
128
|
+
export class HTMLGenerator {
|
|
129
|
+
/**
|
|
130
|
+
* The service customization options.
|
|
131
|
+
*/
|
|
132
|
+
protected readonly _options: HTMLGeneratorOptions;
|
|
133
|
+
/**
|
|
134
|
+
* The application configuration service, to get the settings specified by the
|
|
135
|
+
* `configKeys` option.
|
|
136
|
+
*/
|
|
137
|
+
protected readonly _config: Config;
|
|
138
|
+
/**
|
|
139
|
+
* The service that logs messages on the terminal, in case the `silent` option is `false`.
|
|
140
|
+
*/
|
|
141
|
+
protected readonly _logger: Logger;
|
|
142
|
+
/**
|
|
143
|
+
* The service that interacts with the filesystem.
|
|
144
|
+
*/
|
|
145
|
+
protected readonly _frontendFs: FrontendFs;
|
|
146
|
+
/**
|
|
147
|
+
* A service that can provide values to be replaced in the template.
|
|
148
|
+
*/
|
|
149
|
+
protected readonly _valuesService?: HTMLGeneratorValuesService;
|
|
150
|
+
/**
|
|
151
|
+
* Whether or not the file was already generated.
|
|
152
|
+
*/
|
|
153
|
+
protected _fileReady: boolean = false;
|
|
154
|
+
/**
|
|
155
|
+
* A deferred promise to return when another service asks if the file has been
|
|
156
|
+
* generated. Once this sevice finishes generating the file, the promise will be
|
|
157
|
+
* resolved for all implementations that hold a reference to this deferred.
|
|
158
|
+
*/
|
|
159
|
+
protected _fileDeferred?: DeferredPromise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* @param options The options to construct the class.
|
|
162
|
+
* @throws If `valuesService` is specified but it doesn't have a `getValues`
|
|
163
|
+
* method.
|
|
164
|
+
*/
|
|
165
|
+
constructor({
|
|
166
|
+
inject: { config, logger, frontendFs, valuesService },
|
|
167
|
+
...options
|
|
168
|
+
}: HTMLGeneratorConstructorOptions) {
|
|
169
|
+
this._config = config;
|
|
170
|
+
this._logger = logger;
|
|
171
|
+
this._frontendFs = frontendFs;
|
|
172
|
+
this._valuesService = valuesService;
|
|
173
|
+
this._options = deepAssignWithOverwrite(
|
|
174
|
+
{
|
|
175
|
+
template: 'index.tpl.html',
|
|
176
|
+
file: 'index.html',
|
|
177
|
+
silent: false,
|
|
178
|
+
deleteTemplateAfter: true,
|
|
179
|
+
replacePlaceholder: /\{\{appConfig(?:uration)?\}\}/,
|
|
180
|
+
placeholderExpression: /\{\{(.*?)\}\}/gi,
|
|
181
|
+
variableName: 'appConfig',
|
|
182
|
+
configKeys: ['features', 'version', 'postMessagesPrefix'],
|
|
183
|
+
},
|
|
184
|
+
options,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
if (this._valuesService && typeof this._valuesService.getValues !== 'function') {
|
|
188
|
+
throw new Error('The HTMLGenerator values service must have a `getValues` method');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Gets a promise that will be resolved when the file has been generated.
|
|
193
|
+
*/
|
|
194
|
+
whenReady(): Promise<void> {
|
|
195
|
+
return this._fileDeferred ? this._fileDeferred.promise : Promise.resolve();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Generates the HTML file.
|
|
199
|
+
*/
|
|
200
|
+
async generateHTML(): Promise<void> {
|
|
201
|
+
// The file is already generated, and since this is async, return the promise.
|
|
202
|
+
if (this._fileReady) return undefined;
|
|
203
|
+
// If the file is not ready, but the deferred exists, return the reference to the promise.
|
|
204
|
+
if (this._fileDeferred) return this._fileDeferred.promise;
|
|
205
|
+
// Create the deferred promise.
|
|
206
|
+
this._fileDeferred = deferred<void>();
|
|
207
|
+
const { template, deleteTemplateAfter, file, silent } = this._options;
|
|
208
|
+
try {
|
|
209
|
+
// Get the template.
|
|
210
|
+
const templateContents = await this._frontendFs.read(template);
|
|
211
|
+
// Get the values to replace.
|
|
212
|
+
const values = await this._getValues();
|
|
213
|
+
// Replace/process the template.
|
|
214
|
+
const html = this._processHTML(templateContents, values);
|
|
215
|
+
// Write it in the filesystem.
|
|
216
|
+
await this._frontendFs.write(file, html);
|
|
217
|
+
if (!silent) {
|
|
218
|
+
this._logger.success(`The HTML file was successfully generated (${file})`);
|
|
219
|
+
}
|
|
220
|
+
// Delete the template, if specified by the options.
|
|
221
|
+
if (deleteTemplateAfter) {
|
|
222
|
+
await this._frontendFs.delete(template);
|
|
223
|
+
if (!silent) {
|
|
224
|
+
this._logger.info(`The HTML template was successfully removed (${template})`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Switch the flag, resolve the deferred promise, and delete it.
|
|
229
|
+
this._fileReady = true;
|
|
230
|
+
this._fileDeferred!.resolve();
|
|
231
|
+
this._fileDeferred = undefined;
|
|
232
|
+
return undefined;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
this._fileDeferred!.reject(error);
|
|
235
|
+
this._fileDeferred = undefined;
|
|
236
|
+
if (!silent) {
|
|
237
|
+
this._logger.error('There was an error while generating the HTML');
|
|
238
|
+
}
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Gets the customization options.
|
|
244
|
+
*/
|
|
245
|
+
get options(): Readonly<HTMLGeneratorOptions> {
|
|
246
|
+
return deepAssignWithOverwrite({}, this._options);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Helper method to get the values that will be replaced in the template. If a "values
|
|
250
|
+
* service" was specified in the constructor, it will get the values from there,
|
|
251
|
+
* otherwise, it will use the `configKeys` option to get the values from the
|
|
252
|
+
* application configuration.
|
|
253
|
+
*/
|
|
254
|
+
protected _getValues(): Promise<Record<string, unknown>> {
|
|
255
|
+
if (this._valuesService) {
|
|
256
|
+
return this._valuesService.getValues(this._options);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const { configKeys } = this._options;
|
|
260
|
+
if (configKeys && configKeys.length) {
|
|
261
|
+
return Promise.resolve(this._config.get(configKeys));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return Promise.resolve({});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Processes the HTML template by replacing the placeholders with the actual values.
|
|
268
|
+
*
|
|
269
|
+
* @param template The template for the HTML file.
|
|
270
|
+
* @param values The values dictionary that should be replaced in the template.
|
|
271
|
+
*/
|
|
272
|
+
protected _processHTML(template: string, values: Record<string, unknown>) {
|
|
273
|
+
const { replacePlaceholder, placeholderExpression, variableName } = this._options;
|
|
274
|
+
const htmlObject = JSON.stringify(values);
|
|
275
|
+
let code = template.replace(
|
|
276
|
+
replacePlaceholder,
|
|
277
|
+
`window.${variableName} = ${htmlObject}`,
|
|
278
|
+
);
|
|
279
|
+
const matches: Array<{ string: string; value: string }> = [];
|
|
280
|
+
let match = placeholderExpression.exec(code);
|
|
281
|
+
while (match) {
|
|
282
|
+
const [string, value] = match;
|
|
283
|
+
if (string && value) {
|
|
284
|
+
matches.push({
|
|
285
|
+
string,
|
|
286
|
+
value,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
match = placeholderExpression.exec(code);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
matches.forEach((info) => {
|
|
294
|
+
code = code.replace(info.string, String(get(values, info.value)));
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
return code;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* The service provider that once registered on the container will set an instance of
|
|
302
|
+
* {@link HTMLGenerator} as the `htmlGenerator` service. it will also hook itself to the
|
|
303
|
+
* `after-start` event of the application in order to trigger the generator of the HTML
|
|
304
|
+
* file.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
*
|
|
308
|
+
* <caption>Basic usage</caption>
|
|
309
|
+
*
|
|
310
|
+
* // Register it on the container
|
|
311
|
+
* container.register(htmlGeneratorProvider);
|
|
312
|
+
* // Getting access to the service instance
|
|
313
|
+
* const htmlGenerator = container.get<HTMLGenerator>('htmlGenerator');
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
*
|
|
317
|
+
* <caption>Using with custom options</caption>
|
|
318
|
+
*
|
|
319
|
+
* container.register(
|
|
320
|
+
* htmlGeneratorProvider({
|
|
321
|
+
* serviceName: 'myHtmlGenerator',
|
|
322
|
+
* valuesServiceName: 'myValuesService',
|
|
323
|
+
* template: 'my-template.tpl.html',
|
|
324
|
+
* }),
|
|
325
|
+
* );
|
|
326
|
+
*
|
|
327
|
+
* @group Providers
|
|
328
|
+
* @group Services/HTMLGenerator
|
|
329
|
+
*/
|
|
330
|
+
export const htmlGeneratorProvider = providerCreator(
|
|
331
|
+
(options: HTMLGeneratorProviderOptions = {}) =>
|
|
332
|
+
(app) => {
|
|
333
|
+
const {
|
|
334
|
+
serviceName = 'htmlGenerator',
|
|
335
|
+
valuesServiceName = 'htmlGeneratorValues',
|
|
336
|
+
...rest
|
|
337
|
+
} = options;
|
|
338
|
+
app.set(
|
|
339
|
+
serviceName,
|
|
340
|
+
() =>
|
|
341
|
+
new HTMLGenerator({
|
|
342
|
+
inject: {
|
|
343
|
+
config: app.get('config'),
|
|
344
|
+
logger: app.get('logger'),
|
|
345
|
+
frontendFs: app.get('frontendFs'),
|
|
346
|
+
valuesService: app.try(valuesServiceName),
|
|
347
|
+
},
|
|
348
|
+
...rest,
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
app.once('afterStart', () => {
|
|
353
|
+
app.get<HTMLGenerator>(serviceName).generateHTML();
|
|
354
|
+
});
|
|
355
|
+
},
|
|
356
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { providers } from '../../utils';
|
|
2
|
+
import { htmlGeneratorProvider } from './htmlGenerator';
|
|
3
|
+
/**
|
|
4
|
+
* Registers all the HTML services on the container.
|
|
5
|
+
*
|
|
6
|
+
* - {@link HTMLGenerator | htmlGenerator}
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* // Register the collection on the container
|
|
11
|
+
* container.register(htmlServicesProvider);
|
|
12
|
+
* // Getting access to one the services instance
|
|
13
|
+
* const htmlGenerator = container.get<HTMLGenerator>('htmlGenerator');
|
|
14
|
+
*
|
|
15
|
+
* @group Providers
|
|
16
|
+
*/
|
|
17
|
+
export const htmlServicesProvider = providers({
|
|
18
|
+
htmlGeneratorProvider,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export * from './htmlGenerator';
|