@spinajs/templates 2.0.481 → 2.0.482
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/CompiledTemplateRenderer.d.ts +41 -0
- package/lib/cjs/CompiledTemplateRenderer.d.ts.map +1 -0
- package/lib/cjs/CompiledTemplateRenderer.js +83 -0
- package/lib/cjs/CompiledTemplateRenderer.js.map +1 -0
- package/lib/cjs/cli/renderHelpers.d.ts +26 -0
- package/lib/cjs/cli/renderHelpers.d.ts.map +1 -0
- package/lib/cjs/cli/renderHelpers.js +101 -0
- package/lib/cjs/cli/renderHelpers.js.map +1 -0
- package/lib/cjs/config/templates.d.ts +3 -1
- package/lib/cjs/config/templates.d.ts.map +1 -1
- package/lib/cjs/config/templates.js +15 -3
- package/lib/cjs/config/templates.js.map +1 -1
- package/lib/cjs/index.d.ts +21 -4
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +35 -20
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +52 -9
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +101 -5
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/io.d.ts +3 -0
- package/lib/cjs/io.d.ts.map +1 -0
- package/lib/cjs/io.js +46 -0
- package/lib/cjs/io.js.map +1 -0
- package/lib/cjs/progress.d.ts +57 -0
- package/lib/cjs/progress.d.ts.map +1 -0
- package/lib/cjs/progress.js +23 -0
- package/lib/cjs/progress.js.map +1 -0
- package/lib/mjs/CompiledTemplateRenderer.d.ts +41 -0
- package/lib/mjs/CompiledTemplateRenderer.d.ts.map +1 -0
- package/lib/mjs/CompiledTemplateRenderer.js +46 -0
- package/lib/mjs/CompiledTemplateRenderer.js.map +1 -0
- package/lib/mjs/cli/renderHelpers.d.ts +26 -0
- package/lib/mjs/cli/renderHelpers.d.ts.map +1 -0
- package/lib/mjs/cli/renderHelpers.js +62 -0
- package/lib/mjs/cli/renderHelpers.js.map +1 -0
- package/lib/mjs/config/templates.d.ts +3 -1
- package/lib/mjs/config/templates.d.ts.map +1 -1
- package/lib/mjs/config/templates.js +15 -3
- package/lib/mjs/config/templates.js.map +1 -1
- package/lib/mjs/index.d.ts +21 -4
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +36 -21
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +52 -9
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +101 -5
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/io.d.ts +3 -0
- package/lib/mjs/io.d.ts.map +1 -0
- package/lib/mjs/io.js +10 -0
- package/lib/mjs/io.js.map +1 -0
- package/lib/mjs/progress.d.ts +57 -0
- package/lib/mjs/progress.d.ts.map +1 -0
- package/lib/mjs/progress.js +20 -0
- package/lib/mjs/progress.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +16 -16
package/lib/cjs/interfaces.js
CHANGED
|
@@ -10,18 +10,110 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.TemplateRenderer = void 0;
|
|
13
|
-
const configuration_1 = require("@spinajs/configuration");
|
|
14
13
|
const di_1 = require("@spinajs/di");
|
|
14
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
15
15
|
const log_1 = require("@spinajs/log");
|
|
16
|
+
const fs_1 = require("@spinajs/fs");
|
|
17
|
+
const promises_1 = require("fs/promises");
|
|
18
|
+
const path_1 = require("path");
|
|
16
19
|
class TemplateRenderer extends di_1.AsyncService {
|
|
17
20
|
constructor() {
|
|
18
21
|
super(...arguments);
|
|
19
|
-
this.
|
|
22
|
+
this.Cache = new Map();
|
|
20
23
|
}
|
|
21
24
|
get ServiceName() {
|
|
22
25
|
// we map this service by extension
|
|
23
26
|
return this.Extension;
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Explicit config wins; otherwise dev mode implies always-recompile.
|
|
30
|
+
*/
|
|
31
|
+
get CacheMode() {
|
|
32
|
+
if (this.ConfiguredCacheMode) {
|
|
33
|
+
return this.ConfiguredCacheMode;
|
|
34
|
+
}
|
|
35
|
+
return this.DevMode ? 'always' : 'cache';
|
|
36
|
+
}
|
|
37
|
+
isUri(template) {
|
|
38
|
+
return /^fs:\/\//.test(template);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Bare paths are normalized as before. URIs must be left alone - path.normalize
|
|
42
|
+
* would turn fs://name/x into fs:\name\x on windows and break URI parsing.
|
|
43
|
+
*/
|
|
44
|
+
normalizeTemplate(template) {
|
|
45
|
+
return this.isUri(template) ? template : (0, path_1.normalize)(template);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Template source as text. Bare paths read from local disk exactly as before -
|
|
49
|
+
* routing them through the default provider would re-resolve relative paths
|
|
50
|
+
* against its basePath and break existing callers.
|
|
51
|
+
*/
|
|
52
|
+
async resolveContent(template) {
|
|
53
|
+
if (!this.isUri(template)) {
|
|
54
|
+
return await (0, promises_1.readFile)(template, 'utf-8');
|
|
55
|
+
}
|
|
56
|
+
const content = await fs_1.fs.read(new fs_1.URI(template), 'utf-8');
|
|
57
|
+
return Buffer.isBuffer(content) ? content.toString('utf-8') : content;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A real local path. For renderers that cannot compile from a string (pug),
|
|
61
|
+
* remote sources are materialised to temp storage.
|
|
62
|
+
*/
|
|
63
|
+
async resolveLocalPath(template) {
|
|
64
|
+
if (!this.isUri(template)) {
|
|
65
|
+
return template;
|
|
66
|
+
}
|
|
67
|
+
return await fs_1.fs.download(new fs_1.URI(template));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Opaque token that changes when the source changes. Null means "cannot tell" -
|
|
71
|
+
* callers must then trust whatever they already have cached.
|
|
72
|
+
*/
|
|
73
|
+
async changeToken(template) {
|
|
74
|
+
try {
|
|
75
|
+
if (this.isUri(template)) {
|
|
76
|
+
return this.tokenFromStat(await fs_1.fs.stat(new fs_1.URI(template)));
|
|
77
|
+
}
|
|
78
|
+
const s = await (0, promises_1.stat)(template);
|
|
79
|
+
return `${s.mtimeMs}|${s.size}`;
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
this.Log.warn(`Cannot stat template ${template}, serving cached version. ${err}`);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
tokenFromStat(s) {
|
|
87
|
+
if (s.Version) {
|
|
88
|
+
return s.Version;
|
|
89
|
+
}
|
|
90
|
+
return `${s.ModifiedTime?.toMillis() ?? 0}|${s.Size ?? 0}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Compiled-template cache honouring CacheMode. `compile` runs only on a miss.
|
|
94
|
+
*/
|
|
95
|
+
async withCache(template, compile) {
|
|
96
|
+
const mode = this.CacheMode;
|
|
97
|
+
if (mode === 'always') {
|
|
98
|
+
return await compile();
|
|
99
|
+
}
|
|
100
|
+
const key = this.normalizeTemplate(template);
|
|
101
|
+
const entry = this.Cache.get(key);
|
|
102
|
+
let token = null;
|
|
103
|
+
if (mode === 'revalidate') {
|
|
104
|
+
token = await this.changeToken(template);
|
|
105
|
+
// null token => stat failed; prefer a stale entry over failing the render
|
|
106
|
+
if (entry && (token === null || token === entry.token)) {
|
|
107
|
+
return entry.compiled;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (entry) {
|
|
111
|
+
return entry.compiled;
|
|
112
|
+
}
|
|
113
|
+
const compiled = await compile();
|
|
114
|
+
this.Cache.set(key, { compiled, token });
|
|
115
|
+
return compiled;
|
|
116
|
+
}
|
|
25
117
|
}
|
|
26
118
|
exports.TemplateRenderer = TemplateRenderer;
|
|
27
119
|
__decorate([
|
|
@@ -29,7 +121,11 @@ __decorate([
|
|
|
29
121
|
__metadata("design:type", log_1.Log)
|
|
30
122
|
], TemplateRenderer.prototype, "Log", void 0);
|
|
31
123
|
__decorate([
|
|
32
|
-
(0, configuration_1.Config)('
|
|
33
|
-
__metadata("design:type",
|
|
34
|
-
], TemplateRenderer.prototype, "
|
|
124
|
+
(0, configuration_1.Config)('templates.cache.mode'),
|
|
125
|
+
__metadata("design:type", String)
|
|
126
|
+
], TemplateRenderer.prototype, "ConfiguredCacheMode", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
(0, configuration_1.Config)('configuration.isDevelopment', { defaultValue: false }),
|
|
129
|
+
__metadata("design:type", Boolean)
|
|
130
|
+
], TemplateRenderer.prototype, "DevMode", void 0);
|
|
35
131
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,0DAAgD;AAChD,
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAA2C;AAC3C,0DAAgD;AAChD,sCAA2C;AAC3C,oCAA6C;AAC7C,0CAA0D;AAC1D,+BAAiC;AAsBjC,MAAsB,gBAAiB,SAAQ,iBAAY;IAA3D;;QAUY,UAAK,GAAqC,IAAI,GAAG,EAA+B,CAAC;IAuH7F,CAAC;IAjHC,IAAW,WAAW;QACpB,mCAAmC;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAKD;;OAEG;IACH,IAAc,SAAS;QACrB,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3C,CAAC;IAES,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C7B,CAAC;QACH,CAAC;aAAM,IAAI,KAAK,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC,QAAa,CAAC;QAC7B,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QAEzC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAjID,4CAiIC;AA/HW;IADT,IAAA,YAAM,EAAC,UAAU,CAAC;8BACJ,SAAG;6CAAC;AAGT;IADT,IAAA,sBAAM,EAAC,sBAAsB,CAAC;;6DACkB;AAGvC;IADT,IAAA,sBAAM,EAAC,6BAA6B,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;;iDACpC"}
|
package/lib/cjs/io.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/io.ts"],"names":[],"mappings":"AAGA,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAKtD"}
|
package/lib/cjs/io.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ensureParentDir = ensureParentDir;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
/** Ensure the parent directory of `filePath` exists, creating it recursively if needed. */
|
|
40
|
+
function ensureParentDir(filePath) {
|
|
41
|
+
const dir = path.dirname(filePath);
|
|
42
|
+
if (!fs.existsSync(dir)) {
|
|
43
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/io.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,0CAKC;AATD,uCAAyB;AACzB,2CAA6B;AAE7B,2FAA2F;AAC3F,SAAgB,eAAe,CAAC,QAAgB;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Milestones a (puppeteer) render passes through. Text engines complete
|
|
3
|
+
* synchronously and do not report phases.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum RenderPhase {
|
|
6
|
+
/** Local static server + pooled browser + page are being set up. */
|
|
7
|
+
Starting = "starting",
|
|
8
|
+
/** HTML is being built (template compiled / raw HTML injected) - before load. */
|
|
9
|
+
Preparing = "preparing",
|
|
10
|
+
/** Page content is loading - external resources (images, css, fonts) downloading. */
|
|
11
|
+
Loading = "loading",
|
|
12
|
+
/** The output is being produced (page.pdf() / screenshot). */
|
|
13
|
+
Rendering = "rendering",
|
|
14
|
+
/** Render finished successfully. */
|
|
15
|
+
Done = "done",
|
|
16
|
+
/** Render failed - `message` carries the reason. */
|
|
17
|
+
Failed = "failed"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A single progress snapshot delivered to a {@link RenderProgressCallback}.
|
|
21
|
+
* Resource counters are meaningful only for network-backed engines (puppeteer);
|
|
22
|
+
* they stay at 0 otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export interface IRenderProgress {
|
|
25
|
+
/** Current render phase. */
|
|
26
|
+
phase: RenderPhase;
|
|
27
|
+
/** Best-effort completion, 0..100, weighted per phase. */
|
|
28
|
+
percent: number;
|
|
29
|
+
/** Resources whose response completed since loading started. */
|
|
30
|
+
resourcesLoaded: number;
|
|
31
|
+
/** Resources requested but not yet finished or failed. */
|
|
32
|
+
resourcesPending: number;
|
|
33
|
+
/** Resources that failed to load (e.g. broken images). */
|
|
34
|
+
resourcesFailed: number;
|
|
35
|
+
/** Milliseconds elapsed since the render started. */
|
|
36
|
+
elapsedMs: number;
|
|
37
|
+
/** Output file being produced. */
|
|
38
|
+
filePath: string;
|
|
39
|
+
/** Short human-readable status line. */
|
|
40
|
+
message?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Progress listener. Invoked fire-and-forget by the renderer - it is never
|
|
44
|
+
* awaited and any thrown error / rejected promise is swallowed, so a slow or
|
|
45
|
+
* faulty listener can neither stall nor break a render. Emissions are throttled.
|
|
46
|
+
*/
|
|
47
|
+
export type RenderProgressCallback = (progress: IRenderProgress) => void | Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Optional per-render options threaded through the {@link TemplateRenderer}
|
|
50
|
+
* contract and the {@link Templates} facade. All fields are optional; engines
|
|
51
|
+
* that do not support a given field ignore it.
|
|
52
|
+
*/
|
|
53
|
+
export interface IRenderOptions {
|
|
54
|
+
/** Receives throttled progress updates during the render. */
|
|
55
|
+
onProgress?: RenderProgressCallback;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/progress.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,WAAW;IACrB,oEAAoE;IACpE,QAAQ,aAAa;IACrB,iFAAiF;IACjF,SAAS,cAAc;IACvB,qFAAqF;IACrF,OAAO,YAAY;IACnB,8DAA8D;IAC9D,SAAS,cAAc;IACvB,oCAAoC;IACpC,IAAI,SAAS;IACb,oDAAoD;IACpD,MAAM,WAAW;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,4BAA4B;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,eAAe,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,gBAAgB,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,eAAe,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzF;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,UAAU,CAAC,EAAE,sBAAsB,CAAC;CACrC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RenderPhase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Milestones a (puppeteer) render passes through. Text engines complete
|
|
6
|
+
* synchronously and do not report phases.
|
|
7
|
+
*/
|
|
8
|
+
var RenderPhase;
|
|
9
|
+
(function (RenderPhase) {
|
|
10
|
+
/** Local static server + pooled browser + page are being set up. */
|
|
11
|
+
RenderPhase["Starting"] = "starting";
|
|
12
|
+
/** HTML is being built (template compiled / raw HTML injected) - before load. */
|
|
13
|
+
RenderPhase["Preparing"] = "preparing";
|
|
14
|
+
/** Page content is loading - external resources (images, css, fonts) downloading. */
|
|
15
|
+
RenderPhase["Loading"] = "loading";
|
|
16
|
+
/** The output is being produced (page.pdf() / screenshot). */
|
|
17
|
+
RenderPhase["Rendering"] = "rendering";
|
|
18
|
+
/** Render finished successfully. */
|
|
19
|
+
RenderPhase["Done"] = "done";
|
|
20
|
+
/** Render failed - `message` carries the reason. */
|
|
21
|
+
RenderPhase["Failed"] = "failed";
|
|
22
|
+
})(RenderPhase || (exports.RenderPhase = RenderPhase = {}));
|
|
23
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/progress.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,WAaX;AAbD,WAAY,WAAW;IACrB,oEAAoE;IACpE,oCAAqB,CAAA;IACrB,iFAAiF;IACjF,sCAAuB,CAAA;IACvB,qFAAqF;IACrF,kCAAmB,CAAA;IACnB,8DAA8D;IAC9D,sCAAuB,CAAA;IACvB,oCAAoC;IACpC,4BAAa,CAAA;IACb,oDAAoD;IACpD,gCAAiB,CAAA;AACnB,CAAC,EAbW,WAAW,2BAAX,WAAW,QAatB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TemplateRenderer } from './interfaces.js';
|
|
2
|
+
/**
|
|
3
|
+
* A compiled template delegate: takes a locals/context object and returns the
|
|
4
|
+
* rendered string. Both pug's `compileTemplate` and handlebars' template
|
|
5
|
+
* delegate satisfy this shape.
|
|
6
|
+
*/
|
|
7
|
+
export type CompiledTemplate = (locals: any) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Base class for template engines that compile a template file into a reusable
|
|
10
|
+
* delegate (pug, handlebars). It captures the render skeleton - validation,
|
|
11
|
+
* lazy compile + caching, language resolution, timing/logging and writing to
|
|
12
|
+
* file - leaving engines to supply only what actually differs:
|
|
13
|
+
*
|
|
14
|
+
* - {@link buildContext} - the locals object passed to the compiled delegate
|
|
15
|
+
* (model merged with engine-specific helpers).
|
|
16
|
+
* - {@link compile} - how a template source is compiled into a delegate.
|
|
17
|
+
*
|
|
18
|
+
* Caching (including dev-mode recompilation) is owned by the base
|
|
19
|
+
* {@link TemplateRenderer.withCache} machinery, not this class.
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class CompiledTemplateRenderer<TDelegate extends CompiledTemplate = CompiledTemplate> extends TemplateRenderer {
|
|
22
|
+
renderToFile(template: string, model: unknown, filePath: string, language?: string): Promise<void>;
|
|
23
|
+
render(templateName: string, model: unknown, language?: string): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Effective language for a render: explicit argument, else the ambient
|
|
26
|
+
* (async-context) language, else the framework default.
|
|
27
|
+
*/
|
|
28
|
+
protected resolveLanguage(language?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Build the locals object passed to the compiled template - the model merged
|
|
31
|
+
* with any engine-specific helpers (translation functions, `lang`, ...).
|
|
32
|
+
*/
|
|
33
|
+
protected abstract buildContext(model: unknown, language: string): Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Compile the template identified by `template` (a bare path or `fs://` URI)
|
|
36
|
+
* into a reusable delegate. Called only on a cache miss; the returned delegate
|
|
37
|
+
* is cached by {@link TemplateRenderer.withCache}.
|
|
38
|
+
*/
|
|
39
|
+
protected abstract compile(template: string): Promise<TDelegate>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=CompiledTemplateRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompiledTemplateRenderer.d.ts","sourceRoot":"","sources":["../../src/CompiledTemplateRenderer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC;AAEvD;;;;;;;;;;;;GAYG;AACH,8BAAsB,wBAAwB,CAAC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,CAAE,SAAQ,gBAAgB;IAC/G,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMlG,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkB7F;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAIpD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE1F;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CACjE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { InvalidArgument } from '@spinajs/exceptions';
|
|
2
|
+
import { guessLanguage, defaultLanguage } from '@spinajs/intl';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { TemplateRenderer } from './interfaces.js';
|
|
5
|
+
import { ensureParentDir } from './io.js';
|
|
6
|
+
/**
|
|
7
|
+
* Base class for template engines that compile a template file into a reusable
|
|
8
|
+
* delegate (pug, handlebars). It captures the render skeleton - validation,
|
|
9
|
+
* lazy compile + caching, language resolution, timing/logging and writing to
|
|
10
|
+
* file - leaving engines to supply only what actually differs:
|
|
11
|
+
*
|
|
12
|
+
* - {@link buildContext} - the locals object passed to the compiled delegate
|
|
13
|
+
* (model merged with engine-specific helpers).
|
|
14
|
+
* - {@link compile} - how a template source is compiled into a delegate.
|
|
15
|
+
*
|
|
16
|
+
* Caching (including dev-mode recompilation) is owned by the base
|
|
17
|
+
* {@link TemplateRenderer.withCache} machinery, not this class.
|
|
18
|
+
*/
|
|
19
|
+
export class CompiledTemplateRenderer extends TemplateRenderer {
|
|
20
|
+
async renderToFile(template, model, filePath, language) {
|
|
21
|
+
const content = await this.render(template, model, language);
|
|
22
|
+
ensureParentDir(filePath);
|
|
23
|
+
fs.writeFileSync(filePath, content);
|
|
24
|
+
}
|
|
25
|
+
async render(templateName, model, language) {
|
|
26
|
+
if (!templateName) {
|
|
27
|
+
throw new InvalidArgument('template parameter cannot be null or empty');
|
|
28
|
+
}
|
|
29
|
+
const label = `${this.constructor.name}.render.${templateName}`;
|
|
30
|
+
this.Log.trace(`Rendering template ${templateName}`);
|
|
31
|
+
this.Log.timeStart(label);
|
|
32
|
+
const delegate = await this.withCache(templateName, () => this.compile(templateName));
|
|
33
|
+
const content = delegate(this.buildContext(model, this.resolveLanguage(language)));
|
|
34
|
+
const time = this.Log.timeEnd(label);
|
|
35
|
+
this.Log.trace(`Rendering template ${templateName} ended, (${time} ms)`);
|
|
36
|
+
return content;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Effective language for a render: explicit argument, else the ambient
|
|
40
|
+
* (async-context) language, else the framework default.
|
|
41
|
+
*/
|
|
42
|
+
resolveLanguage(language) {
|
|
43
|
+
return (language ? language : guessLanguage()) ?? defaultLanguage();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=CompiledTemplateRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompiledTemplateRenderer.js","sourceRoot":"","sources":["../../src/CompiledTemplateRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAS1C;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,wBAAgF,SAAQ,gBAAgB;IACrH,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,KAAc,EAAE,QAAgB,EAAE,QAAiB;QAC7F,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC7D,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC1B,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,YAAoB,EAAE,KAAc,EAAE,QAAiB;QACzE,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,eAAe,CAAC,4CAA4C,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,WAAW,YAAY,EAAE,CAAC;QAChE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,sBAAsB,YAAY,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;QACtF,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAEnF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,sBAAsB,YAAY,YAAY,IAAI,MAAM,CAAC,CAAC;QAEzE,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;OAGG;IACO,eAAe,CAAC,QAAiB;QACzC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;IACtE,CAAC;CAcF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IRenderProgress, RenderProgressCallback } from '../progress.js';
|
|
2
|
+
/** Load an optional JSON model file, returning an empty object when no readable file is given. */
|
|
3
|
+
export declare function loadJsonModel(modelPath?: string): Record<string, unknown>;
|
|
4
|
+
export interface IResolveHtmlOptions {
|
|
5
|
+
template?: boolean;
|
|
6
|
+
model?: string;
|
|
7
|
+
lang?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the HTML for a CLI render. In template mode the input is rendered
|
|
11
|
+
* through the text engine selected by its file extension (pug/handlebars/...);
|
|
12
|
+
* in raw mode the input file is read as-is.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveInputHtml(input: string, options: IResolveHtmlOptions): Promise<string>;
|
|
15
|
+
/** Format one progress snapshot as a compact single line. */
|
|
16
|
+
export declare function formatProgressLine(p: IRenderProgress): string;
|
|
17
|
+
/**
|
|
18
|
+
* A progress callback for one-shot CLI commands. On a TTY it rewrites a single
|
|
19
|
+
* live line; otherwise (piped / CI) it prints one line per phase change. The
|
|
20
|
+
* live line is terminated with a newline on Done/Failed.
|
|
21
|
+
*
|
|
22
|
+
* @param write - sink for output (defaults to stdout); injectable for testing.
|
|
23
|
+
* @param isTty - whether to use the live single-line mode (defaults to stdout's TTY state).
|
|
24
|
+
*/
|
|
25
|
+
export declare function cliProgressReporter(write?: (s: string) => void, isTty?: boolean): RenderProgressCallback;
|
|
26
|
+
//# sourceMappingURL=renderHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderHelpers.d.ts","sourceRoot":"","sources":["../../../src/cli/renderHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAe,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEtF,kGAAkG;AAClG,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMzE;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAWnG;AASD,6DAA6D;AAC7D,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,CAG7D;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,GAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAA0C,EAChE,KAAK,GAAE,OAAgC,GACtC,sBAAsB,CAiBxB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DI } from '@spinajs/di';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { Templates } from '../index.js';
|
|
4
|
+
import { RenderPhase } from '../progress.js';
|
|
5
|
+
/** Load an optional JSON model file, returning an empty object when no readable file is given. */
|
|
6
|
+
export function loadJsonModel(modelPath) {
|
|
7
|
+
if (modelPath && fs.existsSync(modelPath)) {
|
|
8
|
+
return JSON.parse(fs.readFileSync(modelPath, { encoding: 'utf-8' }));
|
|
9
|
+
}
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the HTML for a CLI render. In template mode the input is rendered
|
|
14
|
+
* through the text engine selected by its file extension (pug/handlebars/...);
|
|
15
|
+
* in raw mode the input file is read as-is.
|
|
16
|
+
*/
|
|
17
|
+
export async function resolveInputHtml(input, options) {
|
|
18
|
+
if (options.template) {
|
|
19
|
+
const templates = await DI.resolve(Templates);
|
|
20
|
+
return templates.render(input, loadJsonModel(options.model), options.lang);
|
|
21
|
+
}
|
|
22
|
+
if (!fs.existsSync(input)) {
|
|
23
|
+
throw new Error(`Input HTML file ${input} does not exist`);
|
|
24
|
+
}
|
|
25
|
+
return fs.readFileSync(input, { encoding: 'utf-8' });
|
|
26
|
+
}
|
|
27
|
+
const PROGRESS_BAR_WIDTH = 20;
|
|
28
|
+
function progressBar(percent) {
|
|
29
|
+
const filled = Math.max(0, Math.min(PROGRESS_BAR_WIDTH, Math.round((percent / 100) * PROGRESS_BAR_WIDTH)));
|
|
30
|
+
return '█'.repeat(filled) + '·'.repeat(PROGRESS_BAR_WIDTH - filled);
|
|
31
|
+
}
|
|
32
|
+
/** Format one progress snapshot as a compact single line. */
|
|
33
|
+
export function formatProgressLine(p) {
|
|
34
|
+
const secs = (p.elapsedMs / 1000).toFixed(1);
|
|
35
|
+
return `[${progressBar(p.percent)}] ${String(p.percent).padStart(3)}% ${p.phase.padEnd(9)} ${p.message ?? ''} ${secs}s`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A progress callback for one-shot CLI commands. On a TTY it rewrites a single
|
|
39
|
+
* live line; otherwise (piped / CI) it prints one line per phase change. The
|
|
40
|
+
* live line is terminated with a newline on Done/Failed.
|
|
41
|
+
*
|
|
42
|
+
* @param write - sink for output (defaults to stdout); injectable for testing.
|
|
43
|
+
* @param isTty - whether to use the live single-line mode (defaults to stdout's TTY state).
|
|
44
|
+
*/
|
|
45
|
+
export function cliProgressReporter(write = (s) => void process.stdout.write(s), isTty = !!process.stdout.isTTY) {
|
|
46
|
+
let lastPhase;
|
|
47
|
+
return (p) => {
|
|
48
|
+
const line = formatProgressLine(p);
|
|
49
|
+
const finished = p.phase === RenderPhase.Done || p.phase === RenderPhase.Failed;
|
|
50
|
+
if (isTty) {
|
|
51
|
+
write(`\r${line.padEnd(80)}`);
|
|
52
|
+
if (finished) {
|
|
53
|
+
write('\n');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (p.phase !== lastPhase) {
|
|
57
|
+
lastPhase = p.phase;
|
|
58
|
+
write(`${line}\n`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=renderHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderHelpers.js","sourceRoot":"","sources":["../../../src/cli/renderHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,E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AC;QACH,CAAC;aAAM,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC;YACpB,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/config/templates.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/config/templates.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,SAAS;;;;;;;;;CAmBd,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -2,18 +2,30 @@ import { join, normalize, resolve } from 'path';
|
|
|
2
2
|
function dir(path) {
|
|
3
3
|
const inCommonJs = typeof module !== 'undefined';
|
|
4
4
|
return [
|
|
5
|
-
resolve(normalize(join(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), 'node_modules', '@spinajs', '
|
|
5
|
+
resolve(normalize(join(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), 'node_modules', '@spinajs', 'templates', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
|
|
6
6
|
// one up if we run from app or build folder
|
|
7
|
-
resolve(normalize(join(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), '../', 'node_modules', '@spinajs', '
|
|
7
|
+
resolve(normalize(join(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), '../', 'node_modules', '@spinajs', 'templates', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
|
|
8
8
|
];
|
|
9
9
|
}
|
|
10
10
|
const templates = {
|
|
11
11
|
system: {
|
|
12
12
|
dirs: {
|
|
13
|
-
templates: [...dir('templates')],
|
|
14
13
|
cli: [...dir('cli')],
|
|
15
14
|
},
|
|
16
15
|
},
|
|
16
|
+
templates: {
|
|
17
|
+
cache: {
|
|
18
|
+
// How aggressively compiled templates are reused. Accepts:
|
|
19
|
+
// 'cache' - compile once, reuse forever.
|
|
20
|
+
// 'revalidate' - stat() the source and recompile only when it changes.
|
|
21
|
+
// 'always' - recompile on every render.
|
|
22
|
+
// Intentionally left unset: when no mode is configured the renderer falls
|
|
23
|
+
// back to 'always' in development and 'cache' in production (see
|
|
24
|
+
// TemplateRenderer.CacheMode). Shipping a concrete value here would defeat
|
|
25
|
+
// that dev/prod fallback.
|
|
26
|
+
// mode: 'cache',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
17
29
|
};
|
|
18
30
|
export default templates;
|
|
19
31
|
//# sourceMappingURL=templates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/config/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACjD,OAAO;QACL,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/config/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACjD,OAAO;QACL,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QAE5J,4CAA4C;QAC5C,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;KACpK,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG;IAChB,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;SACrB;KACF;IACD,SAAS,EAAE;QACT,KAAK,EAAE;QACL,2DAA2D;QAC3D,gDAAgD;QAChD,yEAAyE;QACzE,8CAA8C;QAC9C,0EAA0E;QAC1E,iEAAiE;QACjE,2EAA2E;QAC3E,0BAA0B;QAC1B,iBAAiB;SAClB;KACF;CACF,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { AsyncService } from '@spinajs/di';
|
|
2
2
|
import { Log } from '@spinajs/log';
|
|
3
3
|
import { TemplateRenderer } from './interfaces.js';
|
|
4
|
+
import { IRenderOptions } from './progress.js';
|
|
4
5
|
export * from './interfaces.js';
|
|
6
|
+
export * from './progress.js';
|
|
7
|
+
export * from './io.js';
|
|
8
|
+
export * from './CompiledTemplateRenderer.js';
|
|
9
|
+
export * from './cli/renderHelpers.js';
|
|
5
10
|
/**
|
|
6
11
|
* Inject INTL module for language support. We does nothing but to initialize module for use in templates.
|
|
7
12
|
*/
|
|
@@ -9,7 +14,7 @@ export declare class Templates extends AsyncService {
|
|
|
9
14
|
protected Log: Log;
|
|
10
15
|
protected Renderers: TemplateRenderer[];
|
|
11
16
|
getRendererFor(extname: string): TemplateRenderer;
|
|
12
|
-
compileToFile(template: string, renderer: string, model: unknown, filePath: string, language?: string): Promise<void>;
|
|
17
|
+
compileToFile(template: string, renderer: string, model: unknown, filePath: string, language?: string, options?: IRenderOptions): Promise<void>;
|
|
13
18
|
/**
|
|
14
19
|
*
|
|
15
20
|
* Renders template with given model and language. Returns compiled content
|
|
@@ -18,9 +23,10 @@ export declare class Templates extends AsyncService {
|
|
|
18
23
|
* @param renderer
|
|
19
24
|
* @param model
|
|
20
25
|
* @param language
|
|
26
|
+
* @param options - optional render options (e.g. progress reporting)
|
|
21
27
|
* @returns
|
|
22
28
|
*/
|
|
23
|
-
compile(template: string, renderer: string, model: unknown, language?: string): Promise<string>;
|
|
29
|
+
compile(template: string, renderer: string, model: unknown, language?: string, options?: IRenderOptions): Promise<string>;
|
|
24
30
|
/**
|
|
25
31
|
*
|
|
26
32
|
* Renders template with given model and language. Returns compiled content
|
|
@@ -29,9 +35,20 @@ export declare class Templates extends AsyncService {
|
|
|
29
35
|
* @param template
|
|
30
36
|
* @param model
|
|
31
37
|
* @param language
|
|
38
|
+
* @param options - optional render options (e.g. progress reporting)
|
|
32
39
|
* @returns
|
|
33
40
|
*/
|
|
34
|
-
render(template: string, model: unknown, language?: string): Promise<string>;
|
|
35
|
-
renderToFile(template: string, model: unknown, filePath: string, language?: string): Promise<void>;
|
|
41
|
+
render(template: string, model: unknown, language?: string, options?: IRenderOptions): Promise<string>;
|
|
42
|
+
renderToFile(template: string, model: unknown, filePath: string, language?: string, options?: IRenderOptions): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Finds the renderer registered under the given renderer type (e.g. `handlebars`,
|
|
45
|
+
* `pdf`), throwing if none is registered.
|
|
46
|
+
*/
|
|
47
|
+
private engineByType;
|
|
48
|
+
/**
|
|
49
|
+
* Finds the renderer matching the template file's extension, throwing if none
|
|
50
|
+
* is registered for that extension.
|
|
51
|
+
*/
|
|
52
|
+
private engineByExtension;
|
|
36
53
|
}
|
|
37
54
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/mjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAgB,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AAEvC;;GAEG;AACH,qBACa,SAAU,SAAQ,YAAY;IAEzC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAGnB,SAAS,CAAC,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAEjC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB;IAI3C,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5J;;;;;;;;;;OAUG;IACU,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAA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