jimpex 8.0.0 → 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 +13 -0
- package/README.md +2 -2
- package/dist/app/index.d.mts +14 -0
- package/dist/app/index.d.ts +5 -4
- package/dist/app/index.js +4 -0
- package/dist/app/jimpex.d.mts +14 -0
- package/dist/app/jimpex.d.ts +3 -2
- package/dist/app/jimpex.js +225 -0
- package/dist/app/jimpex.js.map +1 -1
- package/dist/controllers/common/config.d.mts +79 -0
- package/dist/controllers/common/config.d.ts +3 -2
- package/dist/controllers/common/config.js +18 -0
- package/dist/controllers/common/config.js.map +1 -1
- package/dist/controllers/common/health.d.mts +83 -0
- package/dist/controllers/common/health.d.ts +4 -3
- package/dist/controllers/common/health.js +18 -0
- package/dist/controllers/common/health.js.map +1 -1
- package/dist/controllers/common/index.d.mts +21 -0
- package/dist/controllers/common/index.d.ts +4 -4
- package/dist/controllers/common/index.js +6 -0
- package/dist/controllers/common/statics.d.mts +215 -0
- package/dist/controllers/common/statics.d.ts +4 -4
- package/dist/controllers/common/statics.js +51 -0
- package/dist/controllers/common/statics.js.map +1 -1
- package/dist/controllers/index.d.mts +24 -0
- package/dist/controllers/index.d.ts +4 -4
- package/dist/controllers/index.js +5 -0
- package/dist/controllers/utils/gateway.d.mts +725 -0
- package/dist/controllers/utils/gateway.d.ts +4 -3
- package/dist/controllers/utils/gateway.js +152 -0
- package/dist/controllers/utils/gateway.js.map +1 -1
- package/dist/controllers/utils/index.d.mts +17 -0
- package/dist/controllers/utils/index.d.ts +4 -3
- package/dist/controllers/utils/index.js +4 -0
- package/dist/esm/app/jimpex.js +222 -1
- package/dist/esm/app/jimpex.js.map +1 -1
- package/dist/esm/{chunk-T2T6Q22Z.js → chunk-2B2CG5KL.js} +1 -1
- package/dist/esm/controllers/common/config.js +19 -1
- package/dist/esm/controllers/common/config.js.map +1 -1
- package/dist/esm/controllers/common/health.js +19 -1
- package/dist/esm/controllers/common/health.js.map +1 -1
- package/dist/esm/controllers/common/statics.js +48 -1
- package/dist/esm/controllers/common/statics.js.map +1 -1
- package/dist/esm/controllers/utils/gateway.js +153 -1
- package/dist/esm/controllers/utils/gateway.js.map +1 -1
- package/dist/esm/middlewares/common/errorHandler.js +25 -1
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -1
- package/dist/esm/middlewares/common/forceHTTPS.js +13 -1
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/esm/middlewares/common/hsts.js +22 -1
- package/dist/esm/middlewares/common/hsts.js.map +1 -1
- package/dist/esm/middlewares/html/fastHTML.js +55 -1
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -1
- package/dist/esm/middlewares/html/showHTML.js +33 -1
- package/dist/esm/middlewares/html/showHTML.js.map +1 -1
- package/dist/esm/middlewares/utils/versionValidator.js +35 -1
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/esm/services/common/appError.js +48 -2
- package/dist/esm/services/common/appError.js.map +1 -1
- package/dist/esm/services/common/httpError.js +10 -1
- package/dist/esm/services/common/httpError.js.map +1 -1
- package/dist/esm/services/common/index.js +1 -1
- package/dist/esm/services/common/sendFile.js +1 -1
- package/dist/esm/services/frontend/frontendFs.js +29 -1
- package/dist/esm/services/frontend/frontendFs.js.map +1 -1
- package/dist/esm/services/frontend/index.js +1 -1
- package/dist/esm/services/html/htmlGenerator.js +51 -1
- package/dist/esm/services/html/htmlGenerator.js.map +1 -1
- package/dist/esm/services/html/index.js +1 -1
- package/dist/esm/services/http/apiClient.js +27 -1
- package/dist/esm/services/http/apiClient.js.map +1 -1
- package/dist/esm/services/http/http.js +50 -1
- package/dist/esm/services/http/http.js.map +1 -1
- package/dist/esm/services/http/index.js +1 -1
- package/dist/esm/services/http/responsesBuilder.js +49 -2
- package/dist/esm/services/http/responsesBuilder.js.map +1 -1
- package/dist/esm/services/utils/ensureBearerToken.js +17 -1
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/esm/services/utils/index.js +1 -1
- package/dist/esm/utils/fns/others.js +1 -1
- package/dist/esm/utils/fns/routes.js +1 -1
- package/dist/esm/utils/fns/routes.js.map +1 -1
- package/dist/esm/utils/fns/statuses.js +1 -1
- package/dist/esm/utils/fns/text.js +1 -1
- package/dist/esm/utils/wrappers.js +1 -1
- package/dist/{jimpex-7eaee271.d.ts → index-b2a04c78.d.ts} +9 -5
- package/dist/index-efeb437e.d.ts +1282 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -0
- package/dist/middlewares/common/errorHandler.d.mts +132 -0
- package/dist/middlewares/common/errorHandler.d.ts +4 -3
- package/dist/middlewares/common/errorHandler.js +24 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -1
- package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +5 -4
- package/dist/middlewares/common/forceHTTPS.js +12 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/middlewares/common/hsts.d.mts +110 -0
- package/dist/middlewares/common/hsts.d.ts +5 -4
- package/dist/middlewares/common/hsts.js +21 -0
- package/dist/middlewares/common/hsts.js.map +1 -1
- package/dist/middlewares/common/index.d.mts +22 -0
- package/dist/middlewares/common/index.d.ts +4 -3
- package/dist/middlewares/common/index.js +6 -0
- package/dist/middlewares/html/fastHTML.d.mts +180 -0
- package/dist/middlewares/html/fastHTML.d.ts +4 -4
- package/dist/middlewares/html/fastHTML.js +54 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -1
- package/dist/middlewares/html/index.d.mts +21 -0
- package/dist/middlewares/html/index.d.ts +4 -4
- package/dist/middlewares/html/index.js +5 -0
- package/dist/middlewares/html/showHTML.d.mts +127 -0
- package/dist/middlewares/html/showHTML.d.ts +4 -4
- package/dist/middlewares/html/showHTML.js +32 -0
- package/dist/middlewares/html/showHTML.js.map +1 -1
- package/dist/middlewares/index.d.mts +30 -0
- package/dist/middlewares/index.d.ts +4 -4
- package/dist/middlewares/index.js +6 -0
- package/dist/middlewares/utils/index.d.mts +20 -0
- package/dist/middlewares/utils/index.d.ts +4 -3
- package/dist/middlewares/utils/index.js +4 -0
- package/dist/middlewares/utils/versionValidator.d.mts +215 -0
- package/dist/middlewares/utils/versionValidator.d.ts +4 -3
- package/dist/middlewares/utils/versionValidator.js +34 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/services/common/appError.d.mts +139 -0
- package/dist/services/common/appError.d.ts +4 -3
- package/dist/services/common/appError.js +47 -1
- package/dist/services/common/appError.js.map +1 -1
- package/dist/services/common/httpError.d.mts +80 -0
- package/dist/services/common/httpError.d.ts +4 -3
- package/dist/services/common/httpError.js +9 -0
- package/dist/services/common/httpError.js.map +1 -1
- package/dist/services/common/index.d.mts +47 -0
- package/dist/services/common/index.d.ts +4 -4
- package/dist/services/common/index.js +4 -1
- package/dist/services/common/sendFile.d.mts +102 -0
- package/dist/services/common/sendFile.d.ts +3 -3
- package/dist/services/frontend/frontendFs.d.mts +96 -0
- package/dist/services/frontend/frontendFs.d.ts +3 -3
- package/dist/services/frontend/frontendFs.js +32 -0
- package/dist/services/frontend/frontendFs.js.map +1 -1
- package/dist/services/frontend/index.d.mts +40 -0
- package/dist/services/frontend/index.d.ts +4 -4
- package/dist/services/frontend/index.js +2 -1
- package/dist/services/html/htmlGenerator.d.mts +237 -0
- package/dist/services/html/htmlGenerator.d.ts +2 -2
- package/dist/services/html/htmlGenerator.js +50 -0
- package/dist/services/html/htmlGenerator.js.map +1 -1
- package/dist/services/html/index.d.mts +43 -0
- package/dist/services/html/index.d.ts +4 -4
- package/dist/services/html/index.js +2 -1
- package/dist/services/http/apiClient.d.mts +170 -0
- package/dist/services/http/apiClient.d.ts +4 -3
- package/dist/services/http/apiClient.js +26 -0
- package/dist/services/http/apiClient.js.map +1 -1
- package/dist/services/http/http.d.mts +176 -0
- package/dist/services/http/http.d.ts +4 -3
- package/dist/services/http/http.js +53 -0
- package/dist/services/http/http.js.map +1 -1
- package/dist/services/http/index.d.mts +51 -0
- package/dist/services/http/index.d.ts +4 -3
- package/dist/services/http/index.js +4 -1
- package/dist/services/http/responsesBuilder.d.mts +179 -0
- package/dist/services/http/responsesBuilder.d.ts +3 -2
- package/dist/services/http/responsesBuilder.js +48 -1
- package/dist/services/http/responsesBuilder.js.map +1 -1
- package/dist/services/index.d.mts +33 -0
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +8 -0
- package/dist/services/utils/ensureBearerToken.d.mts +158 -0
- package/dist/services/utils/ensureBearerToken.d.ts +5 -4
- package/dist/services/utils/ensureBearerToken.js +16 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/services/utils/index.d.mts +44 -0
- package/dist/services/utils/index.d.ts +4 -3
- package/dist/services/utils/index.js +2 -1
- package/dist/types/events.d.mts +14 -0
- package/dist/types/events.d.ts +5 -4
- package/dist/types/express.d.mts +10 -0
- package/dist/types/http.d.mts +79 -0
- package/dist/types/index.d.mts +14 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +9 -0
- package/dist/types/options.d.mts +14 -0
- package/dist/types/options.d.ts +4 -3
- package/dist/types/utils.d.mts +48 -0
- package/dist/types/wootils.d.mts +4 -0
- package/dist/utils/fns/index.d.mts +5 -0
- package/dist/utils/fns/index.js +7 -0
- package/dist/utils/fns/others.d.mts +17 -0
- package/dist/utils/fns/routes.d.mts +39 -0
- package/dist/utils/fns/routes.js.map +1 -1
- package/dist/utils/fns/statuses.d.mts +45 -0
- package/dist/utils/fns/statuses.js +4 -0
- package/dist/utils/fns/statuses.js.map +1 -1
- package/dist/utils/fns/text.d.mts +9 -0
- package/dist/utils/index.d.mts +19 -0
- package/dist/utils/index.d.ts +5 -4
- package/dist/utils/index.js +5 -0
- package/dist/utils/wrappers.d.mts +14 -0
- package/dist/utils/wrappers.d.ts +4 -3
- package/package.json +43 -43
- /package/dist/esm/{chunk-T2T6Q22Z.js.map → chunk-2B2CG5KL.js.map} +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-efeb437e.js';
|
|
3
|
+
import { PathUtils } from '@homer0/path-utils';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import '../../types/express.mjs';
|
|
6
|
+
import 'express';
|
|
7
|
+
import '../../types/http.mjs';
|
|
8
|
+
import 'https';
|
|
9
|
+
import 'http';
|
|
10
|
+
import 'spdy';
|
|
11
|
+
import 'node-fetch';
|
|
12
|
+
import '../../types/utils.mjs';
|
|
13
|
+
import '@homer0/simple-logger';
|
|
14
|
+
import '@homer0/simple-config';
|
|
15
|
+
import '@homer0/events-hub';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The options to construct a {@link FrontendFs}.
|
|
19
|
+
*
|
|
20
|
+
* @group Services/FrontendFs
|
|
21
|
+
*/
|
|
22
|
+
type FrontendFsOptions = {
|
|
23
|
+
/**
|
|
24
|
+
* A dictionary with the dependencies to inject.
|
|
25
|
+
*/
|
|
26
|
+
inject: {
|
|
27
|
+
pathUtils: PathUtils;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* This service allows the application to easily work with the filesystem. The idea behind
|
|
32
|
+
* centralizing this functionalities into a service is that is pretty common to have
|
|
33
|
+
* bundling tools to generate the frontend, and on that process files can have different
|
|
34
|
+
* paths or not even be generated all. The service can be extended/overwritten to
|
|
35
|
+
* accommodate any requirements and avoid having to update or add `if`s to every `fs` call
|
|
36
|
+
* the application does.
|
|
37
|
+
* Another _'feature'_ of this service is that all the paths are relative to the directory
|
|
38
|
+
* where the app executable is located, so you don't have to remember the relative path
|
|
39
|
+
* from the place you are accessing a file to the place where it's located.
|
|
40
|
+
*
|
|
41
|
+
* @group Services
|
|
42
|
+
* @group Services/FrontendFs
|
|
43
|
+
*/
|
|
44
|
+
declare class FrontendFs {
|
|
45
|
+
/**
|
|
46
|
+
* The service that generates the relative paths.
|
|
47
|
+
*/
|
|
48
|
+
protected readonly _pathUtils: PathUtils;
|
|
49
|
+
/**
|
|
50
|
+
* @param options The options to construct the service.
|
|
51
|
+
*/
|
|
52
|
+
constructor({ inject: { pathUtils } }: FrontendFsOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Deletes a file from the file system.
|
|
55
|
+
*
|
|
56
|
+
* @param filepath The path to the file.
|
|
57
|
+
*/
|
|
58
|
+
delete(filepath: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Reads a file from the file system.
|
|
61
|
+
*
|
|
62
|
+
* @param filepath The path to the file.
|
|
63
|
+
* @param encoding The text encoding in which the file should be read.
|
|
64
|
+
*/
|
|
65
|
+
read(filepath: string, encoding?: BufferEncoding): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Writes a file on the file system.
|
|
68
|
+
*
|
|
69
|
+
* @param filepath The path to the file.
|
|
70
|
+
* @param content The contents of the file.
|
|
71
|
+
*/
|
|
72
|
+
write(filepath: string, content: Parameters<typeof fs.writeFile>[1]): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Utility method to get the path of a file relative to the application executable.
|
|
75
|
+
*
|
|
76
|
+
* @param filepath The path to the file.
|
|
77
|
+
*/
|
|
78
|
+
protected getAppPath(filepath: string): string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The service provider that once registered on the container will set an instance of
|
|
82
|
+
* {@link FrontendFs} as the `frontendFs` service.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
*
|
|
86
|
+
* // Register it on the container
|
|
87
|
+
* container.register(frontendFsProvider);
|
|
88
|
+
* // Getting access to the service instance
|
|
89
|
+
* const frontendFs = container.get<FrontendFs>('frontendFs');
|
|
90
|
+
*
|
|
91
|
+
* @group Providers
|
|
92
|
+
* @group Services/FrontendFs
|
|
93
|
+
*/
|
|
94
|
+
declare const frontendFsProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
95
|
+
|
|
96
|
+
export { FrontendFs, FrontendFsOptions, frontendFsProvider };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex } from '../../
|
|
2
|
+
import { J as Jimpex } from '../../index-b2a04c78.js';
|
|
3
3
|
import { PathUtils } from '@homer0/path-utils';
|
|
4
4
|
import fs from 'fs/promises';
|
|
5
|
-
import '@homer0/events-hub';
|
|
6
5
|
import '../../types/express.js';
|
|
7
6
|
import 'express';
|
|
8
7
|
import '../../types/http.js';
|
|
@@ -10,9 +9,10 @@ import 'https';
|
|
|
10
9
|
import 'http';
|
|
11
10
|
import 'spdy';
|
|
12
11
|
import 'node-fetch';
|
|
13
|
-
import '@homer0/simple-config';
|
|
14
12
|
import '../../types/utils.js';
|
|
15
13
|
import '@homer0/simple-logger';
|
|
14
|
+
import '@homer0/simple-config';
|
|
15
|
+
import '@homer0/events-hub';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* The options to construct a {@link FrontendFs}.
|
|
@@ -19,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
return to;
|
|
20
20
|
};
|
|
21
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
26
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
27
|
mod
|
|
24
28
|
));
|
|
@@ -36,19 +40,47 @@ module.exports = __toCommonJS(frontendFs_exports);
|
|
|
36
40
|
var import_promises = __toESM(require("fs/promises"));
|
|
37
41
|
var import_utils = require("../../utils");
|
|
38
42
|
class FrontendFs {
|
|
43
|
+
/**
|
|
44
|
+
* @param options The options to construct the service.
|
|
45
|
+
*/
|
|
39
46
|
constructor({ inject: { pathUtils } }) {
|
|
47
|
+
/**
|
|
48
|
+
* The service that generates the relative paths.
|
|
49
|
+
*/
|
|
40
50
|
__publicField(this, "_pathUtils");
|
|
41
51
|
this._pathUtils = pathUtils;
|
|
42
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Deletes a file from the file system.
|
|
55
|
+
*
|
|
56
|
+
* @param filepath The path to the file.
|
|
57
|
+
*/
|
|
43
58
|
delete(filepath) {
|
|
44
59
|
return import_promises.default.unlink(this.getAppPath(filepath));
|
|
45
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Reads a file from the file system.
|
|
63
|
+
*
|
|
64
|
+
* @param filepath The path to the file.
|
|
65
|
+
* @param encoding The text encoding in which the file should be read.
|
|
66
|
+
*/
|
|
46
67
|
read(filepath, encoding = "utf-8") {
|
|
47
68
|
return import_promises.default.readFile(this.getAppPath(filepath), encoding);
|
|
48
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Writes a file on the file system.
|
|
72
|
+
*
|
|
73
|
+
* @param filepath The path to the file.
|
|
74
|
+
* @param content The contents of the file.
|
|
75
|
+
*/
|
|
49
76
|
write(filepath, content) {
|
|
50
77
|
return import_promises.default.writeFile(this.getAppPath(filepath), content);
|
|
51
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Utility method to get the path of a file relative to the application executable.
|
|
81
|
+
*
|
|
82
|
+
* @param filepath The path to the file.
|
|
83
|
+
*/
|
|
52
84
|
getAppPath(filepath) {
|
|
53
85
|
return this._pathUtils.joinFrom("app", filepath);
|
|
54
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/frontend/frontendFs.ts"],"sourcesContent":["import fs from 'fs/promises';\nimport { provider } from '../../utils';\nimport type { PathUtils } from '../../types';\n/**\n * The options to construct a {@link FrontendFs}.\n *\n * @group Services/FrontendFs\n */\nexport type FrontendFsOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n pathUtils: PathUtils;\n };\n};\n/**\n * This service allows the application to easily work with the filesystem. The idea behind\n * centralizing this functionalities into a service is that is pretty common to have\n * bundling tools to generate the frontend, and on that process files can have different\n * paths or not even be generated all. The service can be extended/overwritten to\n * accommodate any requirements and avoid having to update or add `if`s to every `fs` call\n * the application does.\n * Another _'feature'_ of this service is that all the paths are relative to the directory\n * where the app executable is located, so you don't have to remember the relative path\n * from the place you are accessing a file to the place where it's located.\n *\n * @group Services\n * @group Services/FrontendFs\n */\nexport class FrontendFs {\n /**\n * The service that generates the relative paths.\n */\n protected readonly _pathUtils: PathUtils;\n /**\n * @param options The options to construct the service.\n */\n constructor({ inject: { pathUtils } }: FrontendFsOptions) {\n this._pathUtils = pathUtils;\n }\n /**\n * Deletes a file from the file system.\n *\n * @param filepath The path to the file.\n */\n delete(filepath: string): Promise<void> {\n return fs.unlink(this.getAppPath(filepath));\n }\n /**\n * Reads a file from the file system.\n *\n * @param filepath The path to the file.\n * @param encoding The text encoding in which the file should be read.\n */\n read(filepath: string, encoding: BufferEncoding = 'utf-8'): Promise<string> {\n return fs.readFile(this.getAppPath(filepath), encoding);\n }\n /**\n * Writes a file on the file system.\n *\n * @param filepath The path to the file.\n * @param content The contents of the file.\n */\n write(filepath: string, content: Parameters<typeof fs.writeFile>[1]): Promise<void> {\n return fs.writeFile(this.getAppPath(filepath), content);\n }\n /**\n * Utility method to get the path of a file relative to the application executable.\n *\n * @param filepath The path to the file.\n */\n protected getAppPath(filepath: string): string {\n return this._pathUtils.joinFrom('app', filepath);\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link FrontendFs} as the `frontendFs` service.\n *\n * @example\n *\n * // Register it on the container\n * container.register(frontendFsProvider);\n * // Getting access to the service instance\n * const frontendFs = container.get<FrontendFs>('frontendFs');\n *\n * @group Providers\n * @group Services/FrontendFs\n */\nexport const frontendFsProvider = provider((app) => {\n app.set(\n 'frontendFs',\n () =>\n new FrontendFs({\n inject: {\n pathUtils: app.get<PathUtils>('pathUtils'),\n },\n }),\n );\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/services/frontend/frontendFs.ts"],"sourcesContent":["import fs from 'fs/promises';\nimport { provider } from '../../utils';\nimport type { PathUtils } from '../../types';\n/**\n * The options to construct a {@link FrontendFs}.\n *\n * @group Services/FrontendFs\n */\nexport type FrontendFsOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n pathUtils: PathUtils;\n };\n};\n/**\n * This service allows the application to easily work with the filesystem. The idea behind\n * centralizing this functionalities into a service is that is pretty common to have\n * bundling tools to generate the frontend, and on that process files can have different\n * paths or not even be generated all. The service can be extended/overwritten to\n * accommodate any requirements and avoid having to update or add `if`s to every `fs` call\n * the application does.\n * Another _'feature'_ of this service is that all the paths are relative to the directory\n * where the app executable is located, so you don't have to remember the relative path\n * from the place you are accessing a file to the place where it's located.\n *\n * @group Services\n * @group Services/FrontendFs\n */\nexport class FrontendFs {\n /**\n * The service that generates the relative paths.\n */\n protected readonly _pathUtils: PathUtils;\n /**\n * @param options The options to construct the service.\n */\n constructor({ inject: { pathUtils } }: FrontendFsOptions) {\n this._pathUtils = pathUtils;\n }\n /**\n * Deletes a file from the file system.\n *\n * @param filepath The path to the file.\n */\n delete(filepath: string): Promise<void> {\n return fs.unlink(this.getAppPath(filepath));\n }\n /**\n * Reads a file from the file system.\n *\n * @param filepath The path to the file.\n * @param encoding The text encoding in which the file should be read.\n */\n read(filepath: string, encoding: BufferEncoding = 'utf-8'): Promise<string> {\n return fs.readFile(this.getAppPath(filepath), encoding);\n }\n /**\n * Writes a file on the file system.\n *\n * @param filepath The path to the file.\n * @param content The contents of the file.\n */\n write(filepath: string, content: Parameters<typeof fs.writeFile>[1]): Promise<void> {\n return fs.writeFile(this.getAppPath(filepath), content);\n }\n /**\n * Utility method to get the path of a file relative to the application executable.\n *\n * @param filepath The path to the file.\n */\n protected getAppPath(filepath: string): string {\n return this._pathUtils.joinFrom('app', filepath);\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link FrontendFs} as the `frontendFs` service.\n *\n * @example\n *\n * // Register it on the container\n * container.register(frontendFsProvider);\n * // Getting access to the service instance\n * const frontendFs = container.get<FrontendFs>('frontendFs');\n *\n * @group Providers\n * @group Services/FrontendFs\n */\nexport const frontendFsProvider = provider((app) => {\n app.set(\n 'frontendFs',\n () =>\n new FrontendFs({\n inject: {\n pathUtils: app.get<PathUtils>('pathUtils'),\n },\n }),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAe;AACf,mBAAyB;AA6BlB,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAQtB,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAsB;AAJ1D;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,aAAa;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,UAAiC;AACtC,WAAO,gBAAAA,QAAG,OAAO,KAAK,WAAW,QAAQ,CAAC;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAK,UAAkB,WAA2B,SAA0B;AAC1E,WAAO,gBAAAA,QAAG,SAAS,KAAK,WAAW,QAAQ,GAAG,QAAQ;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,UAAkB,SAA4D;AAClF,WAAO,gBAAAA,QAAG,UAAU,KAAK,WAAW,QAAQ,GAAG,OAAO;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,WAAW,UAA0B;AAC7C,WAAO,KAAK,WAAW,SAAS,OAAO,QAAQ;AAAA,EACjD;AACF;AAeO,MAAM,yBAAqB,uBAAS,CAAC,QAAQ;AAClD,MAAI;AAAA,IACF;AAAA,IACA,MACE,IAAI,WAAW;AAAA,MACb,QAAQ;AAAA,QACN,WAAW,IAAI,IAAe,WAAW;AAAA,MAC3C;AAAA,IACF,CAAC;AAAA,EACL;AACF,CAAC;","names":["fs"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-efeb437e.js';
|
|
3
|
+
export { FrontendFs, FrontendFsOptions, frontendFsProvider } from './frontendFs.mjs';
|
|
4
|
+
import '../../types/express.mjs';
|
|
5
|
+
import 'express';
|
|
6
|
+
import '../../types/http.mjs';
|
|
7
|
+
import 'https';
|
|
8
|
+
import 'http';
|
|
9
|
+
import 'spdy';
|
|
10
|
+
import 'node-fetch';
|
|
11
|
+
import '../../types/utils.mjs';
|
|
12
|
+
import '@homer0/path-utils';
|
|
13
|
+
import '@homer0/simple-logger';
|
|
14
|
+
import '@homer0/simple-config';
|
|
15
|
+
import '@homer0/events-hub';
|
|
16
|
+
import 'fs/promises';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Registers all the frontend services on the container.
|
|
20
|
+
*
|
|
21
|
+
* - {@link FrontendFs | frontendFs}
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
*
|
|
25
|
+
* // Register the collection on the container
|
|
26
|
+
* container.register(frontendServicesProvider);
|
|
27
|
+
* // Getting access to one the services instance
|
|
28
|
+
* const frontendFs = container.get<FrontendFs>('frontendFs');
|
|
29
|
+
*
|
|
30
|
+
* @group Providers
|
|
31
|
+
*/
|
|
32
|
+
declare const frontendServicesProvider: {
|
|
33
|
+
frontendFsProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
34
|
+
} & Record<string, _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>> & {
|
|
35
|
+
provider: true;
|
|
36
|
+
} & {
|
|
37
|
+
register: _homer0_jimple.ProviderRegisterFn<Jimpex>;
|
|
38
|
+
} & Record<string, unknown>;
|
|
39
|
+
|
|
40
|
+
export { frontendServicesProvider };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex } from '../../
|
|
2
|
+
import { J as Jimpex } from '../../index-b2a04c78.js';
|
|
3
3
|
export { FrontendFs, FrontendFsOptions, frontendFsProvider } from './frontendFs.js';
|
|
4
|
-
import '@homer0/events-hub';
|
|
5
4
|
import '../../types/express.js';
|
|
6
5
|
import 'express';
|
|
7
6
|
import '../../types/http.js';
|
|
@@ -9,10 +8,11 @@ import 'https';
|
|
|
9
8
|
import 'http';
|
|
10
9
|
import 'spdy';
|
|
11
10
|
import 'node-fetch';
|
|
12
|
-
import '@homer0/simple-config';
|
|
13
11
|
import '../../types/utils.js';
|
|
14
|
-
import '@homer0/simple-logger';
|
|
15
12
|
import '@homer0/path-utils';
|
|
13
|
+
import '@homer0/simple-logger';
|
|
14
|
+
import '@homer0/simple-config';
|
|
15
|
+
import '@homer0/events-hub';
|
|
16
16
|
import 'fs/promises';
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -30,6 +30,7 @@ const frontendServicesProvider = (0, import_utils.providers)({
|
|
|
30
30
|
});
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
33
|
-
frontendServicesProvider
|
|
33
|
+
frontendServicesProvider,
|
|
34
|
+
...require("./frontendFs")
|
|
34
35
|
});
|
|
35
36
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-efeb437e.js';
|
|
3
|
+
import { SimpleLogger } from '@homer0/simple-logger';
|
|
4
|
+
import { SimpleConfig } from '@homer0/simple-config';
|
|
5
|
+
import { FrontendFs } from '../frontend/frontendFs.mjs';
|
|
6
|
+
import { DeferredPromise } from '@homer0/deferred';
|
|
7
|
+
import '../../types/express.mjs';
|
|
8
|
+
import 'express';
|
|
9
|
+
import '../../types/http.mjs';
|
|
10
|
+
import 'https';
|
|
11
|
+
import 'http';
|
|
12
|
+
import 'spdy';
|
|
13
|
+
import 'node-fetch';
|
|
14
|
+
import '../../types/utils.mjs';
|
|
15
|
+
import '@homer0/path-utils';
|
|
16
|
+
import '@homer0/events-hub';
|
|
17
|
+
import 'fs/promises';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The options to customize a {@link HTMLGenerator} instance.
|
|
21
|
+
*
|
|
22
|
+
* @group Services/HTMLGenerator
|
|
23
|
+
*/
|
|
24
|
+
type HTMLGeneratorOptions = {
|
|
25
|
+
/**
|
|
26
|
+
* The name of the file it should use as template.
|
|
27
|
+
*
|
|
28
|
+
* @default 'index.tpl.html'
|
|
29
|
+
*/
|
|
30
|
+
template: string;
|
|
31
|
+
/**
|
|
32
|
+
* The name of the generated file.
|
|
33
|
+
*
|
|
34
|
+
* @default 'index.html'
|
|
35
|
+
*/
|
|
36
|
+
file: string;
|
|
37
|
+
/**
|
|
38
|
+
* If `true`, it won't log messages on the terminal when generating the file.
|
|
39
|
+
*
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
silent: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether or not to delete the tempalte after generating the file.
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
deleteTemplateAfter: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The placeholder string where the information will be written.
|
|
51
|
+
*
|
|
52
|
+
* @default /\{\{appConfi(?:guration)?\}\}/
|
|
53
|
+
*/
|
|
54
|
+
replacePlaceholder: string | RegExp;
|
|
55
|
+
/**
|
|
56
|
+
* A regular expression for dynamic placeholders that will be replaced by values when
|
|
57
|
+
* the file is generated.
|
|
58
|
+
*
|
|
59
|
+
* @default /\{\{(.*?)\}\}/gi
|
|
60
|
+
*/
|
|
61
|
+
placeholderExpression: RegExp;
|
|
62
|
+
/**
|
|
63
|
+
* The name of the variable that will have the information on the file.
|
|
64
|
+
*
|
|
65
|
+
* @default 'appConfig'
|
|
66
|
+
*/
|
|
67
|
+
variableName: string;
|
|
68
|
+
/**
|
|
69
|
+
* A list of settings from the app configuration that will be used as the information to
|
|
70
|
+
* inject on the file.
|
|
71
|
+
*
|
|
72
|
+
* @default ['features', 'version', 'postMessagesPrefix']
|
|
73
|
+
*/
|
|
74
|
+
configKeys: string[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* An external service that can be used to provide the values the generator will replace
|
|
78
|
+
* in the template.
|
|
79
|
+
*
|
|
80
|
+
* @group Services/HTMLGenerator
|
|
81
|
+
*/
|
|
82
|
+
type HTMLGeneratorValuesService = {
|
|
83
|
+
/**
|
|
84
|
+
* A function that will be called to get the values to replace in the template.
|
|
85
|
+
*
|
|
86
|
+
* @param options The service customization options.
|
|
87
|
+
*/
|
|
88
|
+
getValues: (options: HTMLGeneratorOptions) => Promise<Record<string, unknown>>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The options to construct a {@link HTMLGenerator}.
|
|
92
|
+
*
|
|
93
|
+
* @group Services/HTMLGenerator
|
|
94
|
+
*/
|
|
95
|
+
type HTMLGeneratorConstructorOptions = Partial<HTMLGeneratorOptions> & {
|
|
96
|
+
/**
|
|
97
|
+
* A dictionary with the dependencies to inject.
|
|
98
|
+
*/
|
|
99
|
+
inject: {
|
|
100
|
+
config: SimpleConfig;
|
|
101
|
+
logger: SimpleLogger;
|
|
102
|
+
frontendFs: FrontendFs;
|
|
103
|
+
/**
|
|
104
|
+
* A service that can provide the values to replace in the template. If specified, the
|
|
105
|
+
* values from `configKeys` will be ignored.
|
|
106
|
+
*/
|
|
107
|
+
valuesService?: HTMLGeneratorValuesService;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Custom options for the provider that will register an instance of {@link HTMLGenerator}
|
|
112
|
+
* as a service.
|
|
113
|
+
*
|
|
114
|
+
* @group Services/HTMLGenerator
|
|
115
|
+
*/
|
|
116
|
+
type HTMLGeneratorProviderOptions = Partial<HTMLGeneratorOptions> & {
|
|
117
|
+
/**
|
|
118
|
+
* The name that will be used to register the service on the container. This is to allow
|
|
119
|
+
* multiple "instances" of the service to be created.
|
|
120
|
+
*
|
|
121
|
+
* @default 'htmlGenerator'
|
|
122
|
+
*/
|
|
123
|
+
serviceName?: string;
|
|
124
|
+
/**
|
|
125
|
+
* The name of a service that the generator will use in order to read the values that
|
|
126
|
+
* will be replaced on the template. If the service is available, the values from
|
|
127
|
+
* `configKeys` will be ignored.
|
|
128
|
+
*
|
|
129
|
+
* @default 'htmlGeneratorValues'
|
|
130
|
+
*/
|
|
131
|
+
valuesServiceName?: string;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* This is a utility service that generates an HTML file with custom information when the
|
|
135
|
+
* application is started.
|
|
136
|
+
*
|
|
137
|
+
* @group Services
|
|
138
|
+
* @group Services/HTMLGenerator
|
|
139
|
+
*/
|
|
140
|
+
declare class HTMLGenerator {
|
|
141
|
+
/**
|
|
142
|
+
* The service customization options.
|
|
143
|
+
*/
|
|
144
|
+
protected readonly _options: HTMLGeneratorOptions;
|
|
145
|
+
/**
|
|
146
|
+
* The application configuration service, to get the settings specified by the
|
|
147
|
+
* `configKeys` option.
|
|
148
|
+
*/
|
|
149
|
+
protected readonly _config: SimpleConfig;
|
|
150
|
+
/**
|
|
151
|
+
* The service that logs messages on the terminal, in case the `silent` option is `false`.
|
|
152
|
+
*/
|
|
153
|
+
protected readonly _logger: SimpleLogger;
|
|
154
|
+
/**
|
|
155
|
+
* The service that interacts with the filesystem.
|
|
156
|
+
*/
|
|
157
|
+
protected readonly _frontendFs: FrontendFs;
|
|
158
|
+
/**
|
|
159
|
+
* A service that can provide values to be replaced in the template.
|
|
160
|
+
*/
|
|
161
|
+
protected readonly _valuesService?: HTMLGeneratorValuesService;
|
|
162
|
+
/**
|
|
163
|
+
* Whether or not the file was already generated.
|
|
164
|
+
*/
|
|
165
|
+
protected _fileReady: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* A deferred promise to return when another service asks if the file has been
|
|
168
|
+
* generated. Once this sevice finishes generating the file, the promise will be
|
|
169
|
+
* resolved for all implementations that hold a reference to this deferred.
|
|
170
|
+
*/
|
|
171
|
+
protected _fileDeferred?: DeferredPromise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* @param options The options to construct the class.
|
|
174
|
+
* @throws If `valuesService` is specified but it doesn't have a `getValues`
|
|
175
|
+
* method.
|
|
176
|
+
*/
|
|
177
|
+
constructor({ inject: { config, logger, frontendFs, valuesService }, ...options }: HTMLGeneratorConstructorOptions);
|
|
178
|
+
/**
|
|
179
|
+
* Gets a promise that will be resolved when the file has been generated.
|
|
180
|
+
*/
|
|
181
|
+
whenReady(): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Generates the HTML file.
|
|
184
|
+
*/
|
|
185
|
+
generateHTML(): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Gets the customization options.
|
|
188
|
+
*/
|
|
189
|
+
get options(): Readonly<HTMLGeneratorOptions>;
|
|
190
|
+
/**
|
|
191
|
+
* Helper method to get the values that will be replaced in the template. If a "values
|
|
192
|
+
* service" was specified in the constructor, it will get the values from there,
|
|
193
|
+
* otherwise, it will use the `configKeys` option to get the values from the
|
|
194
|
+
* application configuration.
|
|
195
|
+
*/
|
|
196
|
+
protected _getValues(): Promise<Record<string, unknown>>;
|
|
197
|
+
/**
|
|
198
|
+
* Processes the HTML template by replacing the placeholders with the actual values.
|
|
199
|
+
*
|
|
200
|
+
* @param template The template for the HTML file.
|
|
201
|
+
* @param values The values dictionary that should be replaced in the template.
|
|
202
|
+
*/
|
|
203
|
+
protected _processHTML(template: string, values: Record<string, unknown>): string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The service provider that once registered on the container will set an instance of
|
|
207
|
+
* {@link HTMLGenerator} as the `htmlGenerator` service. it will also hook itself to the
|
|
208
|
+
* `after-start` event of the application in order to trigger the generator of the HTML
|
|
209
|
+
* file.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
*
|
|
213
|
+
* <caption>Basic usage</caption>
|
|
214
|
+
*
|
|
215
|
+
* // Register it on the container
|
|
216
|
+
* container.register(htmlGeneratorProvider);
|
|
217
|
+
* // Getting access to the service instance
|
|
218
|
+
* const htmlGenerator = container.get<HTMLGenerator>('htmlGenerator');
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
*
|
|
222
|
+
* <caption>Using with custom options</caption>
|
|
223
|
+
*
|
|
224
|
+
* container.register(
|
|
225
|
+
* htmlGeneratorProvider({
|
|
226
|
+
* serviceName: 'myHtmlGenerator',
|
|
227
|
+
* valuesServiceName: 'myValuesService',
|
|
228
|
+
* template: 'my-template.tpl.html',
|
|
229
|
+
* }),
|
|
230
|
+
* );
|
|
231
|
+
*
|
|
232
|
+
* @group Providers
|
|
233
|
+
* @group Services/HTMLGenerator
|
|
234
|
+
*/
|
|
235
|
+
declare const htmlGeneratorProvider: _homer0_jimple.ResourceCreator<"provider", "register", (options?: HTMLGeneratorProviderOptions) => (app: Jimpex) => void, _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
236
|
+
|
|
237
|
+
export { HTMLGenerator, HTMLGeneratorConstructorOptions, HTMLGeneratorOptions, HTMLGeneratorProviderOptions, HTMLGeneratorValuesService, htmlGeneratorProvider };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex } from '../../
|
|
2
|
+
import { J as Jimpex } from '../../index-b2a04c78.js';
|
|
3
3
|
import { SimpleLogger } from '@homer0/simple-logger';
|
|
4
4
|
import { SimpleConfig } from '@homer0/simple-config';
|
|
5
5
|
import { FrontendFs } from '../frontend/frontendFs.js';
|
|
6
6
|
import { DeferredPromise } from '@homer0/deferred';
|
|
7
|
-
import '@homer0/events-hub';
|
|
8
7
|
import '../../types/express.js';
|
|
9
8
|
import 'express';
|
|
10
9
|
import '../../types/http.js';
|
|
@@ -14,6 +13,7 @@ import 'spdy';
|
|
|
14
13
|
import 'node-fetch';
|
|
15
14
|
import '../../types/utils.js';
|
|
16
15
|
import '@homer0/path-utils';
|
|
16
|
+
import '@homer0/events-hub';
|
|
17
17
|
import 'fs/promises';
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -32,16 +32,45 @@ var import_deep_assign = require("@homer0/deep-assign");
|
|
|
32
32
|
var import_deferred = require("@homer0/deferred");
|
|
33
33
|
var import_utils = require("../../utils");
|
|
34
34
|
class HTMLGenerator {
|
|
35
|
+
/**
|
|
36
|
+
* @param options The options to construct the class.
|
|
37
|
+
* @throws If `valuesService` is specified but it doesn't have a `getValues`
|
|
38
|
+
* method.
|
|
39
|
+
*/
|
|
35
40
|
constructor({
|
|
36
41
|
inject: { config, logger, frontendFs, valuesService },
|
|
37
42
|
...options
|
|
38
43
|
}) {
|
|
44
|
+
/**
|
|
45
|
+
* The service customization options.
|
|
46
|
+
*/
|
|
39
47
|
__publicField(this, "_options");
|
|
48
|
+
/**
|
|
49
|
+
* The application configuration service, to get the settings specified by the
|
|
50
|
+
* `configKeys` option.
|
|
51
|
+
*/
|
|
40
52
|
__publicField(this, "_config");
|
|
53
|
+
/**
|
|
54
|
+
* The service that logs messages on the terminal, in case the `silent` option is `false`.
|
|
55
|
+
*/
|
|
41
56
|
__publicField(this, "_logger");
|
|
57
|
+
/**
|
|
58
|
+
* The service that interacts with the filesystem.
|
|
59
|
+
*/
|
|
42
60
|
__publicField(this, "_frontendFs");
|
|
61
|
+
/**
|
|
62
|
+
* A service that can provide values to be replaced in the template.
|
|
63
|
+
*/
|
|
43
64
|
__publicField(this, "_valuesService");
|
|
65
|
+
/**
|
|
66
|
+
* Whether or not the file was already generated.
|
|
67
|
+
*/
|
|
44
68
|
__publicField(this, "_fileReady", false);
|
|
69
|
+
/**
|
|
70
|
+
* A deferred promise to return when another service asks if the file has been
|
|
71
|
+
* generated. Once this sevice finishes generating the file, the promise will be
|
|
72
|
+
* resolved for all implementations that hold a reference to this deferred.
|
|
73
|
+
*/
|
|
45
74
|
__publicField(this, "_fileDeferred");
|
|
46
75
|
this._config = config;
|
|
47
76
|
this._logger = logger;
|
|
@@ -64,9 +93,15 @@ class HTMLGenerator {
|
|
|
64
93
|
throw new Error("The HTMLGenerator values service must have a `getValues` method");
|
|
65
94
|
}
|
|
66
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets a promise that will be resolved when the file has been generated.
|
|
98
|
+
*/
|
|
67
99
|
whenReady() {
|
|
68
100
|
return this._fileDeferred ? this._fileDeferred.promise : Promise.resolve();
|
|
69
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Generates the HTML file.
|
|
104
|
+
*/
|
|
70
105
|
async generateHTML() {
|
|
71
106
|
if (this._fileReady)
|
|
72
107
|
return void 0;
|
|
@@ -101,9 +136,18 @@ class HTMLGenerator {
|
|
|
101
136
|
throw error;
|
|
102
137
|
}
|
|
103
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Gets the customization options.
|
|
141
|
+
*/
|
|
104
142
|
get options() {
|
|
105
143
|
return (0, import_deep_assign.deepAssignWithOverwrite)({}, this._options);
|
|
106
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Helper method to get the values that will be replaced in the template. If a "values
|
|
147
|
+
* service" was specified in the constructor, it will get the values from there,
|
|
148
|
+
* otherwise, it will use the `configKeys` option to get the values from the
|
|
149
|
+
* application configuration.
|
|
150
|
+
*/
|
|
107
151
|
_getValues() {
|
|
108
152
|
if (this._valuesService) {
|
|
109
153
|
return this._valuesService.getValues(this._options);
|
|
@@ -114,6 +158,12 @@ class HTMLGenerator {
|
|
|
114
158
|
}
|
|
115
159
|
return Promise.resolve({});
|
|
116
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Processes the HTML template by replacing the placeholders with the actual values.
|
|
163
|
+
*
|
|
164
|
+
* @param template The template for the HTML file.
|
|
165
|
+
* @param values The values dictionary that should be replaced in the template.
|
|
166
|
+
*/
|
|
117
167
|
_processHTML(template, values) {
|
|
118
168
|
const { replacePlaceholder, placeholderExpression, variableName } = this._options;
|
|
119
169
|
const htmlObject = JSON.stringify(values);
|