@tsed/platform-views 7.0.0-beta.3 → 7.0.0-beta.6
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/lib/cjs/decorators/view.js +2 -27
- package/lib/cjs/decorators/view.js.map +1 -1
- package/lib/cjs/index.js +6 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/PlatformViews.js +32 -28
- package/lib/cjs/services/PlatformViews.js.map +1 -1
- package/lib/esm/decorators/view.js +1 -26
- package/lib/esm/decorators/view.js.map +1 -1
- package/lib/esm/index.js +6 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/PlatformViews.js +9 -5
- package/lib/esm/services/PlatformViews.js.map +1 -1
- package/lib/types/decorators/view.d.ts +1 -23
- package/lib/types/index.d.ts +3 -0
- package/package.json +36 -16
- package/readme.md +1 -2
- package/tsconfig.compile.esm.json +1 -12
|
@@ -1,31 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.View = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
7
|
-
*
|
|
8
|
-
* * viewOptions, an object whose properties define local variables for the view.
|
|
9
|
-
*
|
|
10
|
-
* The view argument is a string that is the file path of the view file to render.
|
|
11
|
-
* This can be an absolute path, or a path relative to the views setting.
|
|
12
|
-
* If the path does not contain a file extension, then the view engine setting determines the file extension.
|
|
13
|
-
* If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
|
|
14
|
-
* and render it using the loaded module’s __express function.
|
|
15
|
-
*
|
|
16
|
-
* For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
|
|
17
|
-
*
|
|
18
|
-
* > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
|
|
19
|
-
* and as so for security reasons should not contain input from the end-user.
|
|
20
|
-
*
|
|
21
|
-
* @param path Relative path to the view file.
|
|
22
|
-
* @param options Additional options
|
|
23
|
-
* @decorator
|
|
24
|
-
* @operation
|
|
25
|
-
* @response
|
|
26
|
-
*/
|
|
27
|
-
function View(path, options) {
|
|
28
|
-
return (0, core_1.StoreSet)("view", { path, options });
|
|
29
|
-
}
|
|
30
|
-
exports.View = View;
|
|
4
|
+
var schema_1 = require("@tsed/schema");
|
|
5
|
+
Object.defineProperty(exports, "View", { enumerable: true, get: function () { return schema_1.View; } });
|
|
31
6
|
//# sourceMappingURL=view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../src/decorators/view.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../src/decorators/view.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAA1B,8FAAA,IAAI,OAAA","sourcesContent":["export {View} from \"@tsed/schema\";\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
tslib_1.__exportStar(require("./decorators/view"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./domain/PlatformViewsSettings"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./services/PlatformViews"), exports);
|
|
7
10
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,4DAAkC;AAClC,yEAA+C;AAC/C,mEAAyC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./decorators/view\";\nexport * from \"./domain/PlatformViewsSettings\";\nexport * from \"./services/PlatformViews\";\n"]}
|
|
@@ -5,19 +5,23 @@ exports.PlatformViews = void 0;
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const core_1 = require("@tsed/core");
|
|
7
7
|
const di_1 = require("@tsed/di");
|
|
8
|
-
const fs_1 =
|
|
8
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const PlatformViewsSettings_1 = require("../domain/PlatformViewsSettings");
|
|
11
|
-
function patchEJS(ejs) {
|
|
11
|
+
async function patchEJS(ejs) {
|
|
12
|
+
if (!ejs) {
|
|
13
|
+
const mod = await Promise.resolve().then(() => tslib_1.__importStar(require("ejs")));
|
|
14
|
+
ejs = mod.default;
|
|
15
|
+
}
|
|
12
16
|
return {
|
|
13
17
|
compile(str, { client, ...options }) {
|
|
14
|
-
return
|
|
18
|
+
return ejs.compile(str, options);
|
|
15
19
|
}
|
|
16
20
|
};
|
|
17
21
|
}
|
|
18
22
|
async function tryImport(name) {
|
|
19
23
|
try {
|
|
20
|
-
return await Promise.resolve().then(() =>
|
|
24
|
+
return await Promise.resolve().then(() => tslib_1.__importStar(require(name)));
|
|
21
25
|
}
|
|
22
26
|
catch (er) {
|
|
23
27
|
// istanbul ignore next
|
|
@@ -34,7 +38,7 @@ let PlatformViews = class PlatformViews {
|
|
|
34
38
|
}
|
|
35
39
|
async $onInit() {
|
|
36
40
|
if (!this.disabled) {
|
|
37
|
-
|
|
41
|
+
tslib_1.__classPrivateFieldSet(this, _PlatformViews_extensions, new Map(Object.entries({
|
|
38
42
|
...PlatformViewsSettings_1.PLATFORM_VIEWS_EXTENSIONS,
|
|
39
43
|
...this.extensionsOptions
|
|
40
44
|
})), "f");
|
|
@@ -48,8 +52,8 @@ let PlatformViews = class PlatformViews {
|
|
|
48
52
|
async loadFromConsolidate() {
|
|
49
53
|
const cons = await tryImport("consolidate");
|
|
50
54
|
if (cons) {
|
|
51
|
-
cons.requires.ejs = patchEJS(cons.requires.ejs);
|
|
52
|
-
|
|
55
|
+
cons.requires.ejs = await patchEJS(cons.requires.ejs);
|
|
56
|
+
tslib_1.__classPrivateFieldGet(this, _PlatformViews_extensions, "f").forEach((engineType) => {
|
|
53
57
|
if (cons[engineType]) {
|
|
54
58
|
const options = this.getEngineOptions(engineType);
|
|
55
59
|
if (options.requires) {
|
|
@@ -66,8 +70,8 @@ let PlatformViews = class PlatformViews {
|
|
|
66
70
|
async loadFromTsedEngines() {
|
|
67
71
|
const tsed = await tryImport("@tsed/engines");
|
|
68
72
|
if (tsed) {
|
|
69
|
-
tsed.requires.set("ejs", patchEJS(tsed.requires.get("ejs")));
|
|
70
|
-
|
|
73
|
+
tsed.requires.set("ejs", await patchEJS(tsed.requires.get("ejs")));
|
|
74
|
+
tslib_1.__classPrivateFieldGet(this, _PlatformViews_extensions, "f").forEach((engineType) => {
|
|
71
75
|
if (tsed.engines.has(engineType)) {
|
|
72
76
|
const options = this.getEngineOptions(engineType);
|
|
73
77
|
if (options.requires) {
|
|
@@ -82,7 +86,7 @@ let PlatformViews = class PlatformViews {
|
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
getEngines() {
|
|
85
|
-
return [...
|
|
89
|
+
return [...tslib_1.__classPrivateFieldGet(this, _PlatformViews_extensions, "f").entries()].map(([extension, engineType]) => {
|
|
86
90
|
const engine = this.getEngine(this.getExtension(engineType));
|
|
87
91
|
return {
|
|
88
92
|
extension,
|
|
@@ -91,17 +95,17 @@ let PlatformViews = class PlatformViews {
|
|
|
91
95
|
});
|
|
92
96
|
}
|
|
93
97
|
registerEngine(engineType, engine) {
|
|
94
|
-
|
|
98
|
+
tslib_1.__classPrivateFieldGet(this, _PlatformViews_engines, "f").set(engineType, engine);
|
|
95
99
|
return this;
|
|
96
100
|
}
|
|
97
101
|
getEngine(type) {
|
|
98
|
-
return
|
|
102
|
+
return tslib_1.__classPrivateFieldGet(this, _PlatformViews_engines, "f").get(tslib_1.__classPrivateFieldGet(this, _PlatformViews_extensions, "f").get(type) || type);
|
|
99
103
|
}
|
|
100
104
|
getEngineOptions(engineType) {
|
|
101
105
|
return (0, core_1.getValue)(this.engineOptions, engineType, {});
|
|
102
106
|
}
|
|
103
107
|
async render(viewPath, options = {}) {
|
|
104
|
-
const { path, extension } =
|
|
108
|
+
const { path, extension } = tslib_1.__classPrivateFieldGet(this, _PlatformViews_cachePaths, "f").get(viewPath) || tslib_1.__classPrivateFieldGet(this, _PlatformViews_cachePaths, "f").set(viewPath, this.resolve(viewPath)).get(viewPath);
|
|
105
109
|
const engine = this.getEngine(extension);
|
|
106
110
|
if (!engine) {
|
|
107
111
|
throw new Error(`Engine not found to render the following "${viewPath}"`);
|
|
@@ -127,35 +131,35 @@ let PlatformViews = class PlatformViews {
|
|
|
127
131
|
}
|
|
128
132
|
};
|
|
129
133
|
_PlatformViews_extensions = new WeakMap(), _PlatformViews_engines = new WeakMap(), _PlatformViews_cachePaths = new WeakMap();
|
|
130
|
-
|
|
134
|
+
tslib_1.__decorate([
|
|
131
135
|
(0, di_1.Constant)("env"),
|
|
132
|
-
|
|
136
|
+
tslib_1.__metadata("design:type", String)
|
|
133
137
|
], PlatformViews.prototype, "env", void 0);
|
|
134
|
-
|
|
138
|
+
tslib_1.__decorate([
|
|
135
139
|
(0, di_1.Constant)("views.root", `${process.cwd()}/views`),
|
|
136
|
-
|
|
140
|
+
tslib_1.__metadata("design:type", String)
|
|
137
141
|
], PlatformViews.prototype, "root", void 0);
|
|
138
|
-
|
|
142
|
+
tslib_1.__decorate([
|
|
139
143
|
(0, di_1.Constant)("views.cache"),
|
|
140
|
-
|
|
144
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
141
145
|
], PlatformViews.prototype, "cache", void 0);
|
|
142
|
-
|
|
146
|
+
tslib_1.__decorate([
|
|
143
147
|
(0, di_1.Constant)("views.disabled", false),
|
|
144
|
-
|
|
148
|
+
tslib_1.__metadata("design:type", String)
|
|
145
149
|
], PlatformViews.prototype, "disabled", void 0);
|
|
146
|
-
|
|
150
|
+
tslib_1.__decorate([
|
|
147
151
|
(0, di_1.Constant)("views.viewEngine", "ejs"),
|
|
148
|
-
|
|
152
|
+
tslib_1.__metadata("design:type", String)
|
|
149
153
|
], PlatformViews.prototype, "viewEngine", void 0);
|
|
150
|
-
|
|
154
|
+
tslib_1.__decorate([
|
|
151
155
|
(0, di_1.Constant)("views.extensions", {}),
|
|
152
|
-
|
|
156
|
+
tslib_1.__metadata("design:type", Object)
|
|
153
157
|
], PlatformViews.prototype, "extensionsOptions", void 0);
|
|
154
|
-
|
|
158
|
+
tslib_1.__decorate([
|
|
155
159
|
(0, di_1.Constant)("views.options", {}),
|
|
156
|
-
|
|
160
|
+
tslib_1.__metadata("design:type", Object)
|
|
157
161
|
], PlatformViews.prototype, "engineOptions", void 0);
|
|
158
|
-
PlatformViews =
|
|
162
|
+
PlatformViews = tslib_1.__decorate([
|
|
159
163
|
(0, di_1.Module)({
|
|
160
164
|
views: {
|
|
161
165
|
exists: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformViews.js","sourceRoot":"","sources":["../../../src/services/PlatformViews.ts"],"names":[],"mappings":";;;;;AAAA,qCAAyC;AACzC,iCAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"PlatformViews.js","sourceRoot":"","sources":["../../../src/services/PlatformViews.ts"],"names":[],"mappings":";;;;;AAAA,qCAAyC;AACzC,iCAA0C;AAC1C,oDAAoB;AACpB,+BAA4C;AAC5C,2EAKyC;AAEzC,KAAK,UAAU,QAAQ,CAAC,GAAQ;IAC9B,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,GAAG,GAAG,gEAAa,KAAK,GAAC,CAAC;QAChC,GAAG,GAAG,GAAG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AQ,EAAC,kBAAkB,EAAE,KAAK,CAAC;;iDACR;AAG5B;IADC,IAAA,aAAQ,EAAC,kBAAkB,EAAE,EAAE,CAAC;;wDACyB;AAG1D;IADC,IAAA,aAAQ,EAAC,eAAe,EAAE,EAAE,CAAC;;oDACsC;AApBzD,aAAa;IALzB,IAAA,WAAM,EAAC;QACN,KAAK,EAAE;YACL,MAAM,EAAE,IAAI;SACb;KACF,CAAC;GACW,aAAa,CAkJzB;AAlJY,sCAAa","sourcesContent":["import {Env, getValue} from \"@tsed/core\";\nimport {Constant, Module} from \"@tsed/di\";\nimport Fs from \"fs\";\nimport {extname, join, resolve} from \"path\";\nimport {\n PLATFORM_VIEWS_EXTENSIONS,\n PlatformViewEngine,\n PlatformViewsEngineOptions,\n PlatformViewsExtensionsTypes\n} from \"../domain/PlatformViewsSettings\";\n\nasync function patchEJS(ejs: any) {\n if (!ejs) {\n const mod = await import(\"ejs\");\n ejs = mod.default;\n }\n\n return {\n compile(str: string, {client, ...options}: any) {\n return ejs.compile(str, options);\n }\n };\n}\n\nasync function tryImport(name: string) {\n try {\n return await import(name);\n } catch (er) {\n // istanbul ignore next\n }\n}\n\n/**\n * @platform\n */\n@Module({\n views: {\n exists: true\n }\n})\nexport class PlatformViews {\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"views.root\", `${process.cwd()}/views`)\n readonly root: string;\n\n @Constant(\"views.cache\")\n readonly cache: boolean;\n\n @Constant(\"views.disabled\", false)\n readonly disabled: string;\n\n @Constant(\"views.viewEngine\", \"ejs\")\n readonly viewEngine: string;\n\n @Constant(\"views.extensions\", {})\n protected extensionsOptions: PlatformViewsExtensionsTypes;\n\n @Constant(\"views.options\", {})\n protected engineOptions: Record<string, PlatformViewsEngineOptions>;\n\n #extensions: Map<string, string>;\n #engines = new Map<string, PlatformViewEngine>();\n #cachePaths = new Map<string, {path: string; extension: string}>();\n\n async $onInit() {\n if (!this.disabled) {\n this.#extensions = new Map(\n Object.entries({\n ...PLATFORM_VIEWS_EXTENSIONS,\n ...this.extensionsOptions\n })\n );\n\n await this.loadFromConsolidate();\n await this.loadFromTsedEngines();\n }\n }\n\n /**\n * @deprecated\n */\n async loadFromConsolidate() {\n const cons = await tryImport(\"consolidate\");\n if (cons) {\n cons.requires.ejs = await patchEJS(cons.requires.ejs);\n\n this.#extensions.forEach((engineType) => {\n if ((cons as any)[engineType]) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n (cons.requires as any)[engineType] = options.requires;\n }\n\n this.registerEngine(engineType, {\n options,\n render: (cons as any)[engineType]\n });\n }\n });\n }\n }\n\n async loadFromTsedEngines() {\n const tsed = await tryImport(\"@tsed/engines\");\n\n if (tsed) {\n tsed.requires.set(\"ejs\", await patchEJS(tsed.requires.get(\"ejs\")));\n\n this.#extensions.forEach((engineType) => {\n if (tsed.engines.has(engineType)) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n tsed.requires.set(engineType, options.requires);\n }\n\n this.registerEngine(engineType, {\n options,\n render: tsed.getEngine(engineType)\n });\n }\n });\n }\n }\n\n getEngines() {\n return [...this.#extensions.entries()].map(([extension, engineType]) => {\n const engine = this.getEngine(this.getExtension(engineType))!;\n\n return {\n extension,\n engine\n };\n });\n }\n\n registerEngine(engineType: string, engine: PlatformViewEngine) {\n this.#engines.set(engineType, engine);\n\n return this;\n }\n\n getEngine(type: string) {\n return this.#engines.get(this.#extensions.get(type) || type);\n }\n\n getEngineOptions(engineType: string): PlatformViewsEngineOptions {\n return getValue(this.engineOptions, engineType, {});\n }\n\n async render(viewPath: string, options: any = {}): Promise<string> {\n const {path, extension} = this.#cachePaths.get(viewPath) || this.#cachePaths.set(viewPath, this.resolve(viewPath)).get(viewPath)!;\n const engine = this.getEngine(extension);\n\n if (!engine) {\n throw new Error(`Engine not found to render the following \"${viewPath}\"`);\n }\n\n return engine.render(path, Object.assign({cache: this.cache || this.env === Env.PROD}, engine.options, options));\n }\n\n protected getExtension(viewPath: string) {\n return (extname(viewPath) || this.viewEngine).replace(/\\./, \"\");\n }\n\n protected resolve(viewPath: string) {\n const extension = this.getExtension(viewPath);\n\n viewPath = viewPath.replace(extname(viewPath), \"\") + \".\" + extension;\n\n const path =\n [\n viewPath,\n resolve(join(this.root, viewPath)),\n resolve(join(process.cwd(), \"views\", viewPath)),\n resolve(join(process.cwd(), \"public\", viewPath))\n ].find((file) => Fs.existsSync(file)) || viewPath;\n\n return {\n path,\n extension\n };\n }\n}\n"]}
|
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
4
|
-
*
|
|
5
|
-
* * viewOptions, an object whose properties define local variables for the view.
|
|
6
|
-
*
|
|
7
|
-
* The view argument is a string that is the file path of the view file to render.
|
|
8
|
-
* This can be an absolute path, or a path relative to the views setting.
|
|
9
|
-
* If the path does not contain a file extension, then the view engine setting determines the file extension.
|
|
10
|
-
* If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
|
|
11
|
-
* and render it using the loaded module’s __express function.
|
|
12
|
-
*
|
|
13
|
-
* For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
|
|
14
|
-
*
|
|
15
|
-
* > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
|
|
16
|
-
* and as so for security reasons should not contain input from the end-user.
|
|
17
|
-
*
|
|
18
|
-
* @param path Relative path to the view file.
|
|
19
|
-
* @param options Additional options
|
|
20
|
-
* @decorator
|
|
21
|
-
* @operation
|
|
22
|
-
* @response
|
|
23
|
-
*/
|
|
24
|
-
export function View(path, options) {
|
|
25
|
-
return StoreSet("view", { path, options });
|
|
26
|
-
}
|
|
1
|
+
export { View } from "@tsed/schema";
|
|
27
2
|
//# sourceMappingURL=view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../src/decorators/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../src/decorators/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC","sourcesContent":["export {View} from \"@tsed/schema\";\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./decorators/view.js";
|
|
5
|
+
export * from "./domain/PlatformViewsSettings.js";
|
|
6
|
+
export * from "./services/PlatformViews.js";
|
|
4
7
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./decorators/view\";\nexport * from \"./domain/PlatformViewsSettings\";\nexport * from \"./services/PlatformViews\";\n"]}
|
|
@@ -4,11 +4,15 @@ import { Env, getValue } from "@tsed/core";
|
|
|
4
4
|
import { Constant, Module } from "@tsed/di";
|
|
5
5
|
import Fs from "fs";
|
|
6
6
|
import { extname, join, resolve } from "path";
|
|
7
|
-
import { PLATFORM_VIEWS_EXTENSIONS } from "../domain/PlatformViewsSettings";
|
|
8
|
-
function patchEJS(ejs) {
|
|
7
|
+
import { PLATFORM_VIEWS_EXTENSIONS } from "../domain/PlatformViewsSettings.js";
|
|
8
|
+
async function patchEJS(ejs) {
|
|
9
|
+
if (!ejs) {
|
|
10
|
+
const mod = await import("ejs");
|
|
11
|
+
ejs = mod.default;
|
|
12
|
+
}
|
|
9
13
|
return {
|
|
10
14
|
compile(str, { client, ...options }) {
|
|
11
|
-
return
|
|
15
|
+
return ejs.compile(str, options);
|
|
12
16
|
}
|
|
13
17
|
};
|
|
14
18
|
}
|
|
@@ -45,7 +49,7 @@ let PlatformViews = class PlatformViews {
|
|
|
45
49
|
async loadFromConsolidate() {
|
|
46
50
|
const cons = await tryImport("consolidate");
|
|
47
51
|
if (cons) {
|
|
48
|
-
cons.requires.ejs = patchEJS(cons.requires.ejs);
|
|
52
|
+
cons.requires.ejs = await patchEJS(cons.requires.ejs);
|
|
49
53
|
__classPrivateFieldGet(this, _PlatformViews_extensions, "f").forEach((engineType) => {
|
|
50
54
|
if (cons[engineType]) {
|
|
51
55
|
const options = this.getEngineOptions(engineType);
|
|
@@ -63,7 +67,7 @@ let PlatformViews = class PlatformViews {
|
|
|
63
67
|
async loadFromTsedEngines() {
|
|
64
68
|
const tsed = await tryImport("@tsed/engines");
|
|
65
69
|
if (tsed) {
|
|
66
|
-
tsed.requires.set("ejs", patchEJS(tsed.requires.get("ejs")));
|
|
70
|
+
tsed.requires.set("ejs", await patchEJS(tsed.requires.get("ejs")));
|
|
67
71
|
__classPrivateFieldGet(this, _PlatformViews_extensions, "f").forEach((engineType) => {
|
|
68
72
|
if (tsed.engines.has(engineType)) {
|
|
69
73
|
const options = this.getEngineOptions(engineType);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformViews.js","sourceRoot":"","sources":["../../../src/services/PlatformViews.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAC,OAAO,EAAE,IA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AE,QAAQ,CAAC,CAAC;YAC/C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;SACjD,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC;QAEpD,OAAO;YACL,IAAI;YACJ,SAAS;SACV,CAAC;IACJ,CAAC;CACF,CAAA;;AAhJC;IADC,QAAQ,CAAC,KAAK,CAAC;;0CACP;AAGT;IADC,QAAQ,CAAC,YAAY,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;;2CAC3B;AAGtB;IADC,QAAQ,CAAC,aAAa,CAAC;;4CACA;AAGxB;IADC,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC;;+CACR;AAG1B;IADC,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC;;iDACR;AAG5B;IADC,QAAQ,CAAC,kBAAkB,EAAE,EAAE,CAAC;;wDACyB;AAG1D;IADC,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC;;oDACsC;AApBzD,aAAa;IALzB,MAAM,CAAC;QACN,KAAK,EAAE;YACL,MAAM,EAAE,IAAI;SACb;KACF,CAAC;GACW,aAAa,CAkJzB;SAlJY,aAAa","sourcesContent":["import {Env, getValue} from \"@tsed/core\";\nimport {Constant, Module} from \"@tsed/di\";\nimport Fs from \"fs\";\nimport {extname, join, resolve} from \"path\";\nimport {\n PLATFORM_VIEWS_EXTENSIONS,\n PlatformViewEngine,\n PlatformViewsEngineOptions,\n PlatformViewsExtensionsTypes\n} from \"../domain/PlatformViewsSettings\";\n\nasync function patchEJS(ejs: any) {\n if (!ejs) {\n const mod = await import(\"ejs\");\n ejs = mod.default;\n }\n\n return {\n compile(str: string, {client, ...options}: any) {\n return ejs.compile(str, options);\n }\n };\n}\n\nasync function tryImport(name: string) {\n try {\n return await import(name);\n } catch (er) {\n // istanbul ignore next\n }\n}\n\n/**\n * @platform\n */\n@Module({\n views: {\n exists: true\n }\n})\nexport class PlatformViews {\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"views.root\", `${process.cwd()}/views`)\n readonly root: string;\n\n @Constant(\"views.cache\")\n readonly cache: boolean;\n\n @Constant(\"views.disabled\", false)\n readonly disabled: string;\n\n @Constant(\"views.viewEngine\", \"ejs\")\n readonly viewEngine: string;\n\n @Constant(\"views.extensions\", {})\n protected extensionsOptions: PlatformViewsExtensionsTypes;\n\n @Constant(\"views.options\", {})\n protected engineOptions: Record<string, PlatformViewsEngineOptions>;\n\n #extensions: Map<string, string>;\n #engines = new Map<string, PlatformViewEngine>();\n #cachePaths = new Map<string, {path: string; extension: string}>();\n\n async $onInit() {\n if (!this.disabled) {\n this.#extensions = new Map(\n Object.entries({\n ...PLATFORM_VIEWS_EXTENSIONS,\n ...this.extensionsOptions\n })\n );\n\n await this.loadFromConsolidate();\n await this.loadFromTsedEngines();\n }\n }\n\n /**\n * @deprecated\n */\n async loadFromConsolidate() {\n const cons = await tryImport(\"consolidate\");\n if (cons) {\n cons.requires.ejs = await patchEJS(cons.requires.ejs);\n\n this.#extensions.forEach((engineType) => {\n if ((cons as any)[engineType]) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n (cons.requires as any)[engineType] = options.requires;\n }\n\n this.registerEngine(engineType, {\n options,\n render: (cons as any)[engineType]\n });\n }\n });\n }\n }\n\n async loadFromTsedEngines() {\n const tsed = await tryImport(\"@tsed/engines\");\n\n if (tsed) {\n tsed.requires.set(\"ejs\", await patchEJS(tsed.requires.get(\"ejs\")));\n\n this.#extensions.forEach((engineType) => {\n if (tsed.engines.has(engineType)) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n tsed.requires.set(engineType, options.requires);\n }\n\n this.registerEngine(engineType, {\n options,\n render: tsed.getEngine(engineType)\n });\n }\n });\n }\n }\n\n getEngines() {\n return [...this.#extensions.entries()].map(([extension, engineType]) => {\n const engine = this.getEngine(this.getExtension(engineType))!;\n\n return {\n extension,\n engine\n };\n });\n }\n\n registerEngine(engineType: string, engine: PlatformViewEngine) {\n this.#engines.set(engineType, engine);\n\n return this;\n }\n\n getEngine(type: string) {\n return this.#engines.get(this.#extensions.get(type) || type);\n }\n\n getEngineOptions(engineType: string): PlatformViewsEngineOptions {\n return getValue(this.engineOptions, engineType, {});\n }\n\n async render(viewPath: string, options: any = {}): Promise<string> {\n const {path, extension} = this.#cachePaths.get(viewPath) || this.#cachePaths.set(viewPath, this.resolve(viewPath)).get(viewPath)!;\n const engine = this.getEngine(extension);\n\n if (!engine) {\n throw new Error(`Engine not found to render the following \"${viewPath}\"`);\n }\n\n return engine.render(path, Object.assign({cache: this.cache || this.env === Env.PROD}, engine.options, options));\n }\n\n protected getExtension(viewPath: string) {\n return (extname(viewPath) || this.viewEngine).replace(/\\./, \"\");\n }\n\n protected resolve(viewPath: string) {\n const extension = this.getExtension(viewPath);\n\n viewPath = viewPath.replace(extname(viewPath), \"\") + \".\" + extension;\n\n const path =\n [\n viewPath,\n resolve(join(this.root, viewPath)),\n resolve(join(process.cwd(), \"views\", viewPath)),\n resolve(join(process.cwd(), \"public\", viewPath))\n ].find((file) => Fs.existsSync(file)) || viewPath;\n\n return {\n path,\n extension\n };\n }\n}\n"]}
|
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
3
|
-
*
|
|
4
|
-
* * viewOptions, an object whose properties define local variables for the view.
|
|
5
|
-
*
|
|
6
|
-
* The view argument is a string that is the file path of the view file to render.
|
|
7
|
-
* This can be an absolute path, or a path relative to the views setting.
|
|
8
|
-
* If the path does not contain a file extension, then the view engine setting determines the file extension.
|
|
9
|
-
* If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
|
|
10
|
-
* and render it using the loaded module’s __express function.
|
|
11
|
-
*
|
|
12
|
-
* For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
|
|
13
|
-
*
|
|
14
|
-
* > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
|
|
15
|
-
* and as so for security reasons should not contain input from the end-user.
|
|
16
|
-
*
|
|
17
|
-
* @param path Relative path to the view file.
|
|
18
|
-
* @param options Additional options
|
|
19
|
-
* @decorator
|
|
20
|
-
* @operation
|
|
21
|
-
* @response
|
|
22
|
-
*/
|
|
23
|
-
export declare function View(path: string, options?: Object): MethodDecorator;
|
|
1
|
+
export { View } from "@tsed/schema";
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-views",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.6",
|
|
4
4
|
"description": "Views module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
8
9
|
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
"types": "./lib/types/index.d.ts",
|
|
@@ -13,35 +14,54 @@
|
|
|
13
14
|
"default": "./lib/esm/index.js"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
17
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
-
"build:esm": "tsc --build tsconfig.compile.esm.json"
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\""
|
|
19
21
|
},
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"consolidate": "^0.16.0",
|
|
22
24
|
"ejs": "^3.1.5",
|
|
23
|
-
"tslib": "2.
|
|
25
|
+
"tslib": "2.3.1"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@tsed/core": "7.0.0-beta.
|
|
27
|
-
"@tsed/di": "7.0.0-beta.
|
|
28
|
-
"@tsed/engines": "
|
|
29
|
-
"@tsed/exceptions": "7.0.0-beta.
|
|
30
|
-
"@tsed/schema": "7.0.0-beta.
|
|
31
|
-
"@types/consolidate": "0.14.
|
|
28
|
+
"@tsed/core": "7.0.0-beta.6",
|
|
29
|
+
"@tsed/di": "7.0.0-beta.6",
|
|
30
|
+
"@tsed/engines": "7.0.0-beta.6",
|
|
31
|
+
"@tsed/exceptions": "7.0.0-beta.6",
|
|
32
|
+
"@tsed/schema": "7.0.0-beta.6",
|
|
33
|
+
"@types/consolidate": "0.14.1",
|
|
34
|
+
"@types/ejs": "3.1.0"
|
|
32
35
|
},
|
|
33
36
|
"peerDependencies": {
|
|
34
|
-
"@tsed/core": "^7.0.0-beta.
|
|
35
|
-
"@tsed/di": "^7.0.0-beta.
|
|
36
|
-
"@tsed/engines": "^
|
|
37
|
-
"@tsed/exceptions": "^7.0.0-beta.
|
|
38
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
37
|
+
"@tsed/core": "^7.0.0-beta.6",
|
|
38
|
+
"@tsed/di": "^7.0.0-beta.6",
|
|
39
|
+
"@tsed/engines": "^7.0.0-beta.6",
|
|
40
|
+
"@tsed/exceptions": "^7.0.0-beta.6",
|
|
41
|
+
"@tsed/schema": "^7.0.0-beta.6"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@tsed/core": {
|
|
45
|
+
"optional": false
|
|
46
|
+
},
|
|
47
|
+
"@tsed/di": {
|
|
48
|
+
"optional": false
|
|
49
|
+
},
|
|
50
|
+
"@tsed/exceptions": {
|
|
51
|
+
"optional": false
|
|
52
|
+
},
|
|
53
|
+
"@tsed/schema": {
|
|
54
|
+
"optional": false
|
|
55
|
+
},
|
|
56
|
+
"@tsed/engines": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
39
59
|
},
|
|
40
60
|
"repository": "https://github.com/tsedio/tsed",
|
|
41
61
|
"bugs": {
|
|
42
62
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
43
63
|
},
|
|
44
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
64
|
+
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-views",
|
|
45
65
|
"author": "Romain Lenzotti",
|
|
46
66
|
"license": "MIT"
|
|
47
67
|
}
|
package/readme.md
CHANGED
|
@@ -36,18 +36,17 @@ npm install --save @tsed/core
|
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
## Contributors
|
|
39
|
+
|
|
39
40
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
40
41
|
|
|
41
42
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
42
43
|
|
|
43
|
-
|
|
44
44
|
## Backers
|
|
45
45
|
|
|
46
46
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
47
47
|
|
|
48
48
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
49
49
|
|
|
50
|
-
|
|
51
50
|
## Sponsors
|
|
52
51
|
|
|
53
52
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
10
|
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"test",
|
|
14
|
-
"lib",
|
|
15
|
-
"benchmark",
|
|
16
|
-
"coverage",
|
|
17
|
-
"spec",
|
|
18
|
-
"**/*.benchmark.ts",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"keys",
|
|
21
|
-
"jest.config.js"
|
|
22
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|