ecto 4.4.0 → 4.4.2
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/dist/ecto.d.ts +28 -28
- package/dist/ecto.js +184 -159
- package/package.json +14 -11
package/dist/ecto.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { HookifiedOptions, Hookified } from 'hookified';
|
|
2
1
|
import { Cacheable, CacheableMemory } from 'cacheable';
|
|
2
|
+
import { HookifiedOptions, Hookified } from 'hookified';
|
|
3
|
+
|
|
4
|
+
type EngineInterface = {
|
|
5
|
+
names: string[];
|
|
6
|
+
engine: any;
|
|
7
|
+
opts?: Record<string, unknown>;
|
|
8
|
+
rootTemplatePath?: string;
|
|
9
|
+
render(source: string, data?: Record<string, unknown>): Promise<string>;
|
|
10
|
+
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
11
|
+
};
|
|
3
12
|
|
|
4
13
|
declare class EngineMap {
|
|
5
14
|
private readonly _mappings;
|
|
@@ -12,26 +21,17 @@ declare class EngineMap {
|
|
|
12
21
|
|
|
13
22
|
declare class BaseEngine {
|
|
14
23
|
names: string[];
|
|
15
|
-
opts?:
|
|
24
|
+
opts?: Record<string, unknown>;
|
|
16
25
|
engine: any;
|
|
17
26
|
rootTemplatePath?: string;
|
|
18
|
-
private
|
|
27
|
+
private _extensions;
|
|
19
28
|
getExtensions(): string[];
|
|
20
29
|
setExtensions(extensions: string[]): void;
|
|
21
30
|
deleteExtension(name: string): void;
|
|
22
31
|
}
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
engine: any;
|
|
27
|
-
opts?: any;
|
|
28
|
-
rootTemplatePath?: string;
|
|
29
|
-
render(source: string, data?: Record<string, unknown>): Promise<string>;
|
|
30
|
-
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
declare class Markdown extends BaseEngine implements EngineInterface {
|
|
34
|
-
constructor(options?: any);
|
|
33
|
+
declare class EJS extends BaseEngine implements EngineInterface {
|
|
34
|
+
constructor(options?: Record<string, unknown>);
|
|
35
35
|
render(source: string, data?: Record<string, unknown>): Promise<string>;
|
|
36
36
|
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
37
37
|
}
|
|
@@ -45,13 +45,13 @@ declare class Handlebars extends BaseEngine implements EngineInterface {
|
|
|
45
45
|
registerPartials(partialsPath: string): boolean;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
declare class
|
|
48
|
+
declare class Liquid extends BaseEngine implements EngineInterface {
|
|
49
49
|
constructor(options?: Record<string, unknown>);
|
|
50
50
|
render(source: string, data?: Record<string, unknown>): Promise<string>;
|
|
51
51
|
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
declare class
|
|
54
|
+
declare class Markdown extends BaseEngine implements EngineInterface {
|
|
55
55
|
constructor(options?: Record<string, unknown>);
|
|
56
56
|
render(source: string, data?: Record<string, unknown>): Promise<string>;
|
|
57
57
|
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
@@ -63,7 +63,7 @@ declare class Nunjucks extends BaseEngine implements EngineInterface {
|
|
|
63
63
|
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
declare class
|
|
66
|
+
declare class Pug extends BaseEngine implements EngineInterface {
|
|
67
67
|
constructor(options?: Record<string, unknown>);
|
|
68
68
|
render(source: string, data?: Record<string, unknown>): Promise<string>;
|
|
69
69
|
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
@@ -113,17 +113,17 @@ declare enum EctoEvents {
|
|
|
113
113
|
error = "error"
|
|
114
114
|
}
|
|
115
115
|
declare class Ecto extends Hookified {
|
|
116
|
-
private readonly
|
|
117
|
-
private readonly
|
|
118
|
-
private
|
|
119
|
-
private
|
|
120
|
-
private
|
|
121
|
-
private readonly
|
|
122
|
-
private readonly
|
|
123
|
-
private readonly
|
|
124
|
-
private readonly
|
|
125
|
-
private readonly
|
|
126
|
-
private readonly
|
|
116
|
+
private readonly _mapping;
|
|
117
|
+
private readonly _engines;
|
|
118
|
+
private _cache;
|
|
119
|
+
private _cacheSync;
|
|
120
|
+
private _defaultEngine;
|
|
121
|
+
private readonly _ejs;
|
|
122
|
+
private readonly _markdown;
|
|
123
|
+
private readonly _pug;
|
|
124
|
+
private readonly _nunjucks;
|
|
125
|
+
private readonly _handlebars;
|
|
126
|
+
private readonly _liquid;
|
|
127
127
|
/**
|
|
128
128
|
* Ecto constructor
|
|
129
129
|
* @param {EctoOptions} [options] - The options for the ecto engine
|
package/dist/ecto.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/ecto.ts
|
|
2
2
|
import fs2 from "fs";
|
|
3
|
+
import { Cacheable, CacheableMemory } from "cacheable";
|
|
3
4
|
import { Hookified } from "hookified";
|
|
4
5
|
import { Writr as Writr2 } from "writr";
|
|
5
|
-
import { Cacheable, CacheableMemory } from "cacheable";
|
|
6
6
|
|
|
7
7
|
// src/engine-map.ts
|
|
8
8
|
var EngineMap = class {
|
|
9
9
|
_mappings = /* @__PURE__ */ new Map();
|
|
10
10
|
set(name, extensions) {
|
|
11
11
|
const engineName = name.trim().toLowerCase();
|
|
12
|
-
const engineExtensions =
|
|
12
|
+
const engineExtensions = [];
|
|
13
13
|
if (extensions.length > 0 && name !== "") {
|
|
14
14
|
for (let extension of extensions) {
|
|
15
15
|
extension = extension.trim().toLowerCase();
|
|
@@ -27,7 +27,7 @@ var EngineMap = class {
|
|
|
27
27
|
const engineName = name.trim().toLowerCase();
|
|
28
28
|
const extensions = this._mappings.get(engineName);
|
|
29
29
|
if (extensions) {
|
|
30
|
-
const engineExtensions =
|
|
30
|
+
const engineExtensions = [];
|
|
31
31
|
for (const extension_ of extensions) {
|
|
32
32
|
if (extension_ !== extension.trim().toLowerCase()) {
|
|
33
33
|
engineExtensions.push(extension_);
|
|
@@ -50,70 +50,77 @@ var EngineMap = class {
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
// src/engines/
|
|
54
|
-
import
|
|
53
|
+
// src/engines/ejs.ts
|
|
54
|
+
import * as ejs from "ejs";
|
|
55
55
|
|
|
56
56
|
// src/base-engine.ts
|
|
57
57
|
var BaseEngine = class {
|
|
58
|
-
names =
|
|
58
|
+
names = [];
|
|
59
59
|
opts = void 0;
|
|
60
|
+
// biome-ignore lint/suspicious/noExplicitAny: Different engines use different types, any is required for flexibility
|
|
60
61
|
engine;
|
|
61
62
|
rootTemplatePath = void 0;
|
|
62
|
-
|
|
63
|
+
_extensions = [];
|
|
63
64
|
getExtensions() {
|
|
64
|
-
return this.
|
|
65
|
+
return this._extensions;
|
|
65
66
|
}
|
|
66
67
|
setExtensions(extensions) {
|
|
67
|
-
this.
|
|
68
|
+
this._extensions = [];
|
|
68
69
|
for (const extension of extensions) {
|
|
69
70
|
const newExtension = extension.trim().toLowerCase();
|
|
70
|
-
if (!this.
|
|
71
|
-
this.
|
|
71
|
+
if (!this._extensions.includes(newExtension)) {
|
|
72
|
+
this._extensions.push(newExtension);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
deleteExtension(name) {
|
|
76
|
-
for (const [index, extension] of this.
|
|
77
|
+
for (const [index, extension] of this._extensions.entries()) {
|
|
77
78
|
if (name.toLowerCase().trim() === extension) {
|
|
78
|
-
this.
|
|
79
|
+
this._extensions.splice(index, 1);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
};
|
|
83
84
|
|
|
84
|
-
// src/engines/
|
|
85
|
-
var
|
|
85
|
+
// src/engines/ejs.ts
|
|
86
|
+
var EJS = class extends BaseEngine {
|
|
86
87
|
constructor(options) {
|
|
87
88
|
super();
|
|
88
|
-
this.names = ["
|
|
89
|
+
this.names = ["ejs"];
|
|
89
90
|
if (options) {
|
|
90
91
|
this.opts = options;
|
|
91
92
|
}
|
|
92
|
-
this.
|
|
93
|
-
this.setExtensions(["md", "markdown"]);
|
|
93
|
+
this.setExtensions(["ejs"]);
|
|
94
94
|
}
|
|
95
95
|
async render(source, data) {
|
|
96
|
-
this.engine
|
|
97
|
-
|
|
96
|
+
this.engine ??= ejs;
|
|
97
|
+
this.opts ??= {};
|
|
98
|
+
if (this.rootTemplatePath) {
|
|
99
|
+
this.opts.root = this.rootTemplatePath;
|
|
100
|
+
}
|
|
101
|
+
return ejs.render(source, data, this.opts);
|
|
98
102
|
}
|
|
99
103
|
renderSync(source, data) {
|
|
100
|
-
this.engine
|
|
101
|
-
|
|
104
|
+
this.engine ??= ejs;
|
|
105
|
+
this.opts ??= {};
|
|
106
|
+
if (this.rootTemplatePath) {
|
|
107
|
+
this.opts.root = this.rootTemplatePath;
|
|
108
|
+
}
|
|
109
|
+
return ejs.render(source, data, this.opts);
|
|
102
110
|
}
|
|
103
111
|
};
|
|
104
112
|
|
|
105
113
|
// src/engines/handlebars.ts
|
|
106
114
|
import fs from "fs";
|
|
115
|
+
import { fumanchu } from "@jaredwray/fumanchu";
|
|
107
116
|
import * as _ from "underscore";
|
|
108
|
-
import { helpers, handlebars } from "@jaredwray/fumanchu";
|
|
109
117
|
var Handlebars = class extends BaseEngine {
|
|
110
118
|
partialsPath = ["partials", "includes", "templates"];
|
|
111
119
|
constructor(options) {
|
|
112
120
|
super();
|
|
113
121
|
this.names = ["handlebars", "mustache"];
|
|
114
122
|
this.opts = options;
|
|
115
|
-
this.engine =
|
|
116
|
-
helpers({ handlebars }, this.opts);
|
|
123
|
+
this.engine = fumanchu();
|
|
117
124
|
this.setExtensions(["hbs", "hjs", "handlebars", "mustache"]);
|
|
118
125
|
}
|
|
119
126
|
async render(source, data) {
|
|
@@ -143,17 +150,23 @@ var Handlebars = class extends BaseEngine {
|
|
|
143
150
|
registerPartials(partialsPath) {
|
|
144
151
|
let result = false;
|
|
145
152
|
if (fs.existsSync(partialsPath)) {
|
|
146
|
-
const partials = fs.readdirSync(partialsPath, {
|
|
153
|
+
const partials = fs.readdirSync(partialsPath, {
|
|
154
|
+
recursive: true,
|
|
155
|
+
encoding: "utf8"
|
|
156
|
+
});
|
|
147
157
|
for (const p of partials) {
|
|
148
|
-
if (fs.statSync(partialsPath
|
|
149
|
-
const directoryPartials = fs.readdirSync(partialsPath
|
|
158
|
+
if (fs.statSync(`${partialsPath}/${p}`).isDirectory()) {
|
|
159
|
+
const directoryPartials = fs.readdirSync(`${partialsPath}/${p}`, {
|
|
160
|
+
recursive: true,
|
|
161
|
+
encoding: "utf8"
|
|
162
|
+
});
|
|
150
163
|
for (const dp of directoryPartials) {
|
|
151
|
-
const source = fs.readFileSync(partialsPath
|
|
152
|
-
const name = p
|
|
164
|
+
const source = fs.readFileSync(`${partialsPath}/${p}/${dp}`).toString();
|
|
165
|
+
const name = `${p}/${dp.split(".")[0]}`;
|
|
153
166
|
this.engine.registerPartial(name, this.engine.compile(source));
|
|
154
167
|
}
|
|
155
168
|
} else {
|
|
156
|
-
const source = fs.readFileSync(partialsPath
|
|
169
|
+
const source = fs.readFileSync(`${partialsPath}/${p}`, "utf8");
|
|
157
170
|
const name = p.split(".")[0];
|
|
158
171
|
this.engine.registerPartial(name, this.engine.compile(source));
|
|
159
172
|
}
|
|
@@ -164,62 +177,58 @@ var Handlebars = class extends BaseEngine {
|
|
|
164
177
|
}
|
|
165
178
|
};
|
|
166
179
|
|
|
167
|
-
// src/engines/
|
|
168
|
-
import
|
|
169
|
-
var
|
|
180
|
+
// src/engines/liquid.ts
|
|
181
|
+
import { Liquid as LiquidEngine } from "liquidjs";
|
|
182
|
+
var Liquid = class extends BaseEngine {
|
|
170
183
|
constructor(options) {
|
|
171
184
|
super();
|
|
172
|
-
this.names = ["
|
|
185
|
+
this.names = ["liquid"];
|
|
173
186
|
if (options) {
|
|
174
187
|
this.opts = options;
|
|
175
188
|
}
|
|
176
|
-
this.setExtensions(["
|
|
189
|
+
this.setExtensions(["liquid"]);
|
|
177
190
|
}
|
|
178
191
|
async render(source, data) {
|
|
179
|
-
this.engine ??= ejs;
|
|
180
|
-
this.opts ??= {};
|
|
181
192
|
if (this.rootTemplatePath) {
|
|
193
|
+
this.opts ??= {};
|
|
182
194
|
this.opts.root = this.rootTemplatePath;
|
|
183
195
|
}
|
|
184
|
-
|
|
196
|
+
if (!this.engine) {
|
|
197
|
+
this.engine = new LiquidEngine(this.opts);
|
|
198
|
+
}
|
|
199
|
+
return this.engine.parseAndRender(source, data);
|
|
185
200
|
}
|
|
186
201
|
renderSync(source, data) {
|
|
187
|
-
this.engine ??= ejs;
|
|
188
|
-
this.opts ??= {};
|
|
189
202
|
if (this.rootTemplatePath) {
|
|
203
|
+
this.opts ??= {};
|
|
190
204
|
this.opts.root = this.rootTemplatePath;
|
|
191
205
|
}
|
|
192
|
-
|
|
206
|
+
if (!this.engine) {
|
|
207
|
+
this.engine = new LiquidEngine(this.opts);
|
|
208
|
+
}
|
|
209
|
+
return this.engine.parseAndRenderSync(source, data);
|
|
193
210
|
}
|
|
194
211
|
};
|
|
195
212
|
|
|
196
|
-
// src/engines/
|
|
197
|
-
import
|
|
198
|
-
var
|
|
213
|
+
// src/engines/markdown.ts
|
|
214
|
+
import { Writr } from "writr";
|
|
215
|
+
var Markdown = class extends BaseEngine {
|
|
199
216
|
constructor(options) {
|
|
200
217
|
super();
|
|
201
|
-
this.names = ["
|
|
202
|
-
this.engine = pug;
|
|
218
|
+
this.names = ["markdown"];
|
|
203
219
|
if (options) {
|
|
204
220
|
this.opts = options;
|
|
205
221
|
}
|
|
206
|
-
this.
|
|
222
|
+
this.engine = new Writr(options);
|
|
223
|
+
this.setExtensions(["md", "markdown"]);
|
|
207
224
|
}
|
|
208
225
|
async render(source, data) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.opts.basedir = this.rootTemplatePath;
|
|
212
|
-
}
|
|
213
|
-
const template = pug.compile(source, this.opts);
|
|
214
|
-
return template(data);
|
|
226
|
+
this.engine.content = source;
|
|
227
|
+
return this.engine.render(data);
|
|
215
228
|
}
|
|
216
229
|
renderSync(source, data) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.opts.basedir = this.rootTemplatePath;
|
|
220
|
-
}
|
|
221
|
-
const template = pug.compile(source, this.opts);
|
|
222
|
-
return template(data);
|
|
230
|
+
this.engine.content = source;
|
|
231
|
+
return this.engine.renderSync(data);
|
|
223
232
|
}
|
|
224
233
|
};
|
|
225
234
|
|
|
@@ -238,7 +247,10 @@ var Nunjucks = class extends BaseEngine {
|
|
|
238
247
|
}
|
|
239
248
|
async render(source, data) {
|
|
240
249
|
if (this.rootTemplatePath) {
|
|
241
|
-
nunjucks.configure(
|
|
250
|
+
nunjucks.configure(
|
|
251
|
+
this.rootTemplatePath,
|
|
252
|
+
this.opts
|
|
253
|
+
);
|
|
242
254
|
} else {
|
|
243
255
|
nunjucks.configure(this.opts);
|
|
244
256
|
}
|
|
@@ -247,7 +259,10 @@ var Nunjucks = class extends BaseEngine {
|
|
|
247
259
|
}
|
|
248
260
|
renderSync(source, data) {
|
|
249
261
|
if (this.rootTemplatePath) {
|
|
250
|
-
nunjucks.configure(
|
|
262
|
+
nunjucks.configure(
|
|
263
|
+
this.rootTemplatePath,
|
|
264
|
+
this.opts
|
|
265
|
+
);
|
|
251
266
|
} else {
|
|
252
267
|
nunjucks.configure(this.opts);
|
|
253
268
|
}
|
|
@@ -256,36 +271,33 @@ var Nunjucks = class extends BaseEngine {
|
|
|
256
271
|
}
|
|
257
272
|
};
|
|
258
273
|
|
|
259
|
-
// src/engines/
|
|
260
|
-
import
|
|
261
|
-
var
|
|
274
|
+
// src/engines/pug.ts
|
|
275
|
+
import * as pug from "pug";
|
|
276
|
+
var Pug = class extends BaseEngine {
|
|
262
277
|
constructor(options) {
|
|
263
278
|
super();
|
|
264
|
-
this.names = ["
|
|
279
|
+
this.names = ["pug"];
|
|
280
|
+
this.engine = pug;
|
|
265
281
|
if (options) {
|
|
266
282
|
this.opts = options;
|
|
267
283
|
}
|
|
268
|
-
this.setExtensions(["
|
|
284
|
+
this.setExtensions(["pug", "jade"]);
|
|
269
285
|
}
|
|
270
286
|
async render(source, data) {
|
|
271
287
|
if (this.rootTemplatePath) {
|
|
272
288
|
this.opts ??= {};
|
|
273
|
-
this.opts.
|
|
274
|
-
}
|
|
275
|
-
if (!this.engine) {
|
|
276
|
-
this.engine = new LiquidEngine(this.opts);
|
|
289
|
+
this.opts.basedir = this.rootTemplatePath;
|
|
277
290
|
}
|
|
278
|
-
|
|
291
|
+
const template = pug.compile(source, this.opts);
|
|
292
|
+
return template(data);
|
|
279
293
|
}
|
|
280
294
|
renderSync(source, data) {
|
|
281
295
|
if (this.rootTemplatePath) {
|
|
282
296
|
this.opts ??= {};
|
|
283
|
-
this.opts.
|
|
284
|
-
}
|
|
285
|
-
if (!this.engine) {
|
|
286
|
-
this.engine = new LiquidEngine(this.opts);
|
|
297
|
+
this.opts.basedir = this.rootTemplatePath;
|
|
287
298
|
}
|
|
288
|
-
|
|
299
|
+
const template = pug.compile(source, this.opts);
|
|
300
|
+
return template(data);
|
|
289
301
|
}
|
|
290
302
|
};
|
|
291
303
|
|
|
@@ -298,50 +310,52 @@ var EctoEvents = /* @__PURE__ */ ((EctoEvents2) => {
|
|
|
298
310
|
return EctoEvents2;
|
|
299
311
|
})(EctoEvents || {});
|
|
300
312
|
var Ecto = class extends Hookified {
|
|
301
|
-
|
|
302
|
-
|
|
313
|
+
_mapping = new EngineMap();
|
|
314
|
+
_engines = [];
|
|
303
315
|
// Cacheable instance for caching rendered templates
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
316
|
+
_cache;
|
|
317
|
+
_cacheSync;
|
|
318
|
+
_defaultEngine = "ejs";
|
|
307
319
|
// Engines
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
320
|
+
_ejs;
|
|
321
|
+
_markdown;
|
|
322
|
+
_pug;
|
|
323
|
+
_nunjucks;
|
|
324
|
+
_handlebars;
|
|
325
|
+
_liquid;
|
|
314
326
|
/**
|
|
315
327
|
* Ecto constructor
|
|
316
328
|
* @param {EctoOptions} [options] - The options for the ecto engine
|
|
317
329
|
*/
|
|
318
|
-
// eslint-disable-next-line complexity
|
|
319
330
|
constructor(options) {
|
|
320
331
|
super();
|
|
321
|
-
this.
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
324
|
-
this.
|
|
325
|
-
this.
|
|
326
|
-
this.
|
|
327
|
-
this.
|
|
332
|
+
this._ejs = new EJS(options?.engineOptions?.ejs);
|
|
333
|
+
this._markdown = new Markdown(options?.engineOptions?.markdown);
|
|
334
|
+
this._pug = new Pug(options?.engineOptions?.pug);
|
|
335
|
+
this._nunjucks = new Nunjucks(options?.engineOptions?.nunjucks);
|
|
336
|
+
this._handlebars = new Handlebars(options?.engineOptions?.handlebars);
|
|
337
|
+
this._liquid = new Liquid(options?.engineOptions?.liquid);
|
|
338
|
+
this._engines.push(
|
|
339
|
+
this._ejs,
|
|
340
|
+
this._markdown,
|
|
341
|
+
this._pug,
|
|
342
|
+
this._nunjucks,
|
|
343
|
+
this._handlebars,
|
|
344
|
+
this._liquid
|
|
345
|
+
);
|
|
328
346
|
this.registerEngineMappings();
|
|
329
|
-
if (options?.cache
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
this.__cache = options.cache;
|
|
334
|
-
}
|
|
347
|
+
if (options?.cache === true) {
|
|
348
|
+
this._cache = new Cacheable();
|
|
349
|
+
} else if (options?.cache instanceof Cacheable) {
|
|
350
|
+
this._cache = options.cache;
|
|
335
351
|
}
|
|
336
|
-
if (options?.cacheSync
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
this.__cacheSync = options.cacheSync;
|
|
341
|
-
}
|
|
352
|
+
if (options?.cacheSync === true) {
|
|
353
|
+
this._cacheSync = new CacheableMemory();
|
|
354
|
+
} else if (options?.cacheSync instanceof CacheableMemory) {
|
|
355
|
+
this._cacheSync = options.cacheSync;
|
|
342
356
|
}
|
|
343
|
-
if (options
|
|
344
|
-
this.
|
|
357
|
+
if (options?.defaultEngine && this.isValidEngine(options.defaultEngine)) {
|
|
358
|
+
this._defaultEngine = options.defaultEngine;
|
|
345
359
|
}
|
|
346
360
|
}
|
|
347
361
|
/**
|
|
@@ -349,7 +363,7 @@ var Ecto = class extends Hookified {
|
|
|
349
363
|
* @returns {string} - the engine name such as 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
|
|
350
364
|
*/
|
|
351
365
|
get defaultEngine() {
|
|
352
|
-
return this.
|
|
366
|
+
return this._defaultEngine;
|
|
353
367
|
}
|
|
354
368
|
/**
|
|
355
369
|
* Set the default engine
|
|
@@ -358,9 +372,12 @@ var Ecto = class extends Hookified {
|
|
|
358
372
|
set defaultEngine(value) {
|
|
359
373
|
value = value.toLowerCase().trim();
|
|
360
374
|
if (this.isValidEngine(value)) {
|
|
361
|
-
this.
|
|
375
|
+
this._defaultEngine = value;
|
|
362
376
|
} else {
|
|
363
|
-
this.emit(
|
|
377
|
+
this.emit(
|
|
378
|
+
"warn" /* warn */,
|
|
379
|
+
`Invalid engine name: ${value}. Defaulting to ${this._defaultEngine}.`
|
|
380
|
+
);
|
|
364
381
|
}
|
|
365
382
|
}
|
|
366
383
|
/**
|
|
@@ -368,77 +385,77 @@ var Ecto = class extends Hookified {
|
|
|
368
385
|
* @returns {Cacheable | undefined} - The cacheable instance or undefined if caching is disabled
|
|
369
386
|
*/
|
|
370
387
|
get cache() {
|
|
371
|
-
return this.
|
|
388
|
+
return this._cache;
|
|
372
389
|
}
|
|
373
390
|
/**
|
|
374
391
|
* Set the cacheable instance
|
|
375
392
|
* @param {Cacheable | undefined} value - The cacheable instance to set. If set to undefined, caching will be disabled.
|
|
376
393
|
*/
|
|
377
394
|
set cache(value) {
|
|
378
|
-
this.
|
|
395
|
+
this._cache = value;
|
|
379
396
|
}
|
|
380
397
|
/**
|
|
381
398
|
* Get the cacheable memory instance
|
|
382
399
|
* @returns {CacheableMemory | undefined} - The cacheable memory instance or undefined if caching is disabled
|
|
383
400
|
*/
|
|
384
401
|
get cacheSync() {
|
|
385
|
-
return this.
|
|
402
|
+
return this._cacheSync;
|
|
386
403
|
}
|
|
387
404
|
/**
|
|
388
405
|
* Set the cacheable memory instance
|
|
389
406
|
* @param {CacheableMemory | undefined} value - The cacheable memory instance to set. If set to undefined, caching will be disabled.
|
|
390
407
|
*/
|
|
391
408
|
set cacheSync(value) {
|
|
392
|
-
this.
|
|
409
|
+
this._cacheSync = value;
|
|
393
410
|
}
|
|
394
411
|
/**
|
|
395
412
|
* Get the Engine Mappings. This is used to map file extensions to engines
|
|
396
413
|
* @returns {EngineMap}
|
|
397
414
|
*/
|
|
398
415
|
get mappings() {
|
|
399
|
-
return this.
|
|
416
|
+
return this._mapping;
|
|
400
417
|
}
|
|
401
418
|
/**
|
|
402
419
|
* Get the EJS Engine
|
|
403
420
|
* @returns {EJS}
|
|
404
421
|
*/
|
|
405
422
|
get ejs() {
|
|
406
|
-
return this.
|
|
423
|
+
return this._ejs;
|
|
407
424
|
}
|
|
408
425
|
/**
|
|
409
426
|
* Get the Markdown Engine
|
|
410
427
|
* @returns {Markdown}
|
|
411
428
|
*/
|
|
412
429
|
get markdown() {
|
|
413
|
-
return this.
|
|
430
|
+
return this._markdown;
|
|
414
431
|
}
|
|
415
432
|
/**
|
|
416
433
|
* Get the Pug Engine
|
|
417
434
|
* @returns {Pug}
|
|
418
435
|
*/
|
|
419
436
|
get pug() {
|
|
420
|
-
return this.
|
|
437
|
+
return this._pug;
|
|
421
438
|
}
|
|
422
439
|
/**
|
|
423
440
|
* Get the Nunjucks Engine
|
|
424
441
|
* @returns {Nunjucks}
|
|
425
442
|
*/
|
|
426
443
|
get nunjucks() {
|
|
427
|
-
return this.
|
|
444
|
+
return this._nunjucks;
|
|
428
445
|
}
|
|
429
446
|
/**
|
|
430
447
|
* Get the Handlebars Engine
|
|
431
448
|
* @returns {Handlebars}
|
|
432
449
|
*/
|
|
433
450
|
get handlebars() {
|
|
434
|
-
return this.
|
|
451
|
+
return this._handlebars;
|
|
435
452
|
}
|
|
436
453
|
/**
|
|
437
454
|
* Get the Liquid Engine
|
|
438
455
|
* @returns {Liquid}
|
|
439
456
|
*/
|
|
440
457
|
get liquid() {
|
|
441
|
-
return this.
|
|
458
|
+
return this._liquid;
|
|
442
459
|
}
|
|
443
460
|
/**
|
|
444
461
|
* Async render the source with the data
|
|
@@ -449,12 +466,11 @@ var Ecto = class extends Hookified {
|
|
|
449
466
|
* @param {string} [filePathOutput] - The file path to write the output
|
|
450
467
|
* @returns {Promise<string>}
|
|
451
468
|
*/
|
|
452
|
-
// eslint-disable-next-line max-params
|
|
453
469
|
async render(source, data, engineName, rootTemplatePath, filePathOutput) {
|
|
454
470
|
try {
|
|
455
|
-
const cacheKey = `${engineName ?? this.
|
|
456
|
-
if (this.
|
|
457
|
-
const cachedResult = await this.
|
|
471
|
+
const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
|
|
472
|
+
if (this._cache) {
|
|
473
|
+
const cachedResult = await this._cache.get(cacheKey);
|
|
458
474
|
if (cachedResult) {
|
|
459
475
|
this.emit("cacheHit" /* cacheHit */, `Cache hit for key: ${cacheKey}`);
|
|
460
476
|
await this.writeFile(filePathOutput, cachedResult);
|
|
@@ -463,15 +479,15 @@ var Ecto = class extends Hookified {
|
|
|
463
479
|
this.emit("cacheMiss" /* cacheMiss */, `Cache miss for key: ${cacheKey}`);
|
|
464
480
|
}
|
|
465
481
|
let result = "";
|
|
466
|
-
let renderEngineName = this.
|
|
482
|
+
let renderEngineName = this._defaultEngine;
|
|
467
483
|
if (this.isValidEngine(engineName) && engineName !== void 0) {
|
|
468
484
|
renderEngineName = engineName;
|
|
469
485
|
}
|
|
470
486
|
const renderEngine = this.getRenderEngine(renderEngineName);
|
|
471
487
|
renderEngine.rootTemplatePath = rootTemplatePath;
|
|
472
488
|
result = await renderEngine.render(source, data);
|
|
473
|
-
if (this.
|
|
474
|
-
await this.
|
|
489
|
+
if (this._cache) {
|
|
490
|
+
await this._cache.set(cacheKey, result);
|
|
475
491
|
}
|
|
476
492
|
await this.writeFile(filePathOutput, result);
|
|
477
493
|
return result;
|
|
@@ -489,12 +505,11 @@ var Ecto = class extends Hookified {
|
|
|
489
505
|
* @param {string} [filePathOutput] - The file path to write the output
|
|
490
506
|
* @returns {string}
|
|
491
507
|
*/
|
|
492
|
-
// eslint-disable-next-line max-params
|
|
493
508
|
renderSync(source, data, engineName, rootTemplatePath, filePathOutput) {
|
|
494
509
|
try {
|
|
495
|
-
const cacheKey = `${engineName ?? this.
|
|
496
|
-
if (this.
|
|
497
|
-
const cachedResult = this.
|
|
510
|
+
const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
|
|
511
|
+
if (this._cacheSync) {
|
|
512
|
+
const cachedResult = this._cacheSync.get(cacheKey);
|
|
498
513
|
if (cachedResult) {
|
|
499
514
|
this.emit("cacheHit" /* cacheHit */, `Cache hit for key: ${cacheKey}`);
|
|
500
515
|
this.writeFileSync(filePathOutput, cachedResult);
|
|
@@ -503,15 +518,15 @@ var Ecto = class extends Hookified {
|
|
|
503
518
|
this.emit("cacheMiss" /* cacheMiss */, `Cache miss for key: ${cacheKey}`);
|
|
504
519
|
}
|
|
505
520
|
let result = "";
|
|
506
|
-
let renderEngineName = this.
|
|
521
|
+
let renderEngineName = this._defaultEngine;
|
|
507
522
|
if (this.isValidEngine(engineName) && engineName !== void 0) {
|
|
508
523
|
renderEngineName = engineName;
|
|
509
524
|
}
|
|
510
525
|
const renderEngine = this.getRenderEngine(renderEngineName);
|
|
511
526
|
renderEngine.rootTemplatePath = rootTemplatePath;
|
|
512
527
|
result = renderEngine.renderSync(source, data);
|
|
513
|
-
if (this.
|
|
514
|
-
this.
|
|
528
|
+
if (this._cacheSync) {
|
|
529
|
+
this._cacheSync.set(cacheKey, result);
|
|
515
530
|
}
|
|
516
531
|
this.writeFileSync(filePathOutput, result);
|
|
517
532
|
return result;
|
|
@@ -529,12 +544,17 @@ var Ecto = class extends Hookified {
|
|
|
529
544
|
* @param {string} [engineName] - The engine to use for rendering
|
|
530
545
|
* @returns
|
|
531
546
|
*/
|
|
532
|
-
// eslint-disable-next-line max-params
|
|
533
547
|
async renderFromFile(filePath, data, rootTemplatePath, filePathOutput, engineName) {
|
|
534
548
|
let result = "";
|
|
535
549
|
engineName ??= this.getEngineByFilePath(filePath);
|
|
536
550
|
const source = await fs2.promises.readFile(filePath, "utf8");
|
|
537
|
-
result = await this.render(
|
|
551
|
+
result = await this.render(
|
|
552
|
+
source,
|
|
553
|
+
data,
|
|
554
|
+
engineName,
|
|
555
|
+
rootTemplatePath,
|
|
556
|
+
filePathOutput
|
|
557
|
+
);
|
|
538
558
|
return result;
|
|
539
559
|
}
|
|
540
560
|
/**
|
|
@@ -546,12 +566,17 @@ var Ecto = class extends Hookified {
|
|
|
546
566
|
* @param {string} [engineName] - The engine to use for rendering
|
|
547
567
|
* @returns {string}
|
|
548
568
|
*/
|
|
549
|
-
// eslint-disable-next-line max-params
|
|
550
569
|
renderFromFileSync(filePath, data, rootTemplatePath, filePathOutput, engineName) {
|
|
551
570
|
let result = "";
|
|
552
571
|
engineName ??= this.getEngineByFilePath(filePath);
|
|
553
572
|
const source = fs2.readFileSync(filePath, "utf8");
|
|
554
|
-
result = this.renderSync(
|
|
573
|
+
result = this.renderSync(
|
|
574
|
+
source,
|
|
575
|
+
data,
|
|
576
|
+
engineName,
|
|
577
|
+
rootTemplatePath,
|
|
578
|
+
filePathOutput
|
|
579
|
+
);
|
|
555
580
|
return result;
|
|
556
581
|
}
|
|
557
582
|
/**
|
|
@@ -586,10 +611,10 @@ var Ecto = class extends Hookified {
|
|
|
586
611
|
* @returns {string} - will return the engine name such as 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
|
|
587
612
|
*/
|
|
588
613
|
getEngineByFilePath(filePath) {
|
|
589
|
-
let result = this.
|
|
614
|
+
let result = this._defaultEngine;
|
|
590
615
|
if (filePath !== void 0) {
|
|
591
616
|
const extension = filePath.includes(".") ? filePath.slice(filePath.lastIndexOf(".") + 1) : "";
|
|
592
|
-
const engExtension = this.
|
|
617
|
+
const engExtension = this._mapping.getName(extension);
|
|
593
618
|
if (engExtension !== void 0) {
|
|
594
619
|
result = engExtension;
|
|
595
620
|
}
|
|
@@ -606,8 +631,8 @@ var Ecto = class extends Hookified {
|
|
|
606
631
|
let result = "";
|
|
607
632
|
const files = await fs2.promises.readdir(path);
|
|
608
633
|
for (const file of files) {
|
|
609
|
-
if (file.startsWith(templateName
|
|
610
|
-
result = path
|
|
634
|
+
if (file.startsWith(`${templateName}.`)) {
|
|
635
|
+
result = `${path}/${file}`;
|
|
611
636
|
break;
|
|
612
637
|
}
|
|
613
638
|
}
|
|
@@ -623,8 +648,8 @@ var Ecto = class extends Hookified {
|
|
|
623
648
|
let result = "";
|
|
624
649
|
const files = fs2.readdirSync(path);
|
|
625
650
|
for (const file of files) {
|
|
626
|
-
if (file.startsWith(templateName
|
|
627
|
-
result = path
|
|
651
|
+
if (file.startsWith(`${templateName}.`)) {
|
|
652
|
+
result = `${path}/${file}`;
|
|
628
653
|
break;
|
|
629
654
|
}
|
|
630
655
|
}
|
|
@@ -637,7 +662,7 @@ var Ecto = class extends Hookified {
|
|
|
637
662
|
*/
|
|
638
663
|
isValidEngine(engineName) {
|
|
639
664
|
let result = false;
|
|
640
|
-
if (engineName !== void 0 && this.
|
|
665
|
+
if (engineName !== void 0 && this._mapping.get(engineName) !== void 0) {
|
|
641
666
|
result = true;
|
|
642
667
|
}
|
|
643
668
|
return result;
|
|
@@ -647,9 +672,9 @@ var Ecto = class extends Hookified {
|
|
|
647
672
|
* @returns {void}
|
|
648
673
|
*/
|
|
649
674
|
registerEngineMappings() {
|
|
650
|
-
for (const eng of this.
|
|
675
|
+
for (const eng of this._engines) {
|
|
651
676
|
for (const name of eng.names) {
|
|
652
|
-
this.
|
|
677
|
+
this._mapping.set(name, eng.getExtensions());
|
|
653
678
|
}
|
|
654
679
|
}
|
|
655
680
|
}
|
|
@@ -659,35 +684,35 @@ var Ecto = class extends Hookified {
|
|
|
659
684
|
* @returns {EngineInterface}
|
|
660
685
|
*/
|
|
661
686
|
getRenderEngine(engineName) {
|
|
662
|
-
let result = this.
|
|
687
|
+
let result = this._ejs;
|
|
663
688
|
const cleanEngineName = engineName.trim().toLowerCase();
|
|
664
689
|
switch (cleanEngineName) {
|
|
665
690
|
case "markdown": {
|
|
666
|
-
result = this.
|
|
691
|
+
result = this._markdown;
|
|
667
692
|
break;
|
|
668
693
|
}
|
|
669
694
|
case "pug": {
|
|
670
|
-
result = this.
|
|
695
|
+
result = this._pug;
|
|
671
696
|
break;
|
|
672
697
|
}
|
|
673
698
|
case "nunjucks": {
|
|
674
|
-
result = this.
|
|
699
|
+
result = this._nunjucks;
|
|
675
700
|
break;
|
|
676
701
|
}
|
|
677
702
|
case "mustache": {
|
|
678
|
-
result = this.
|
|
703
|
+
result = this._handlebars;
|
|
679
704
|
break;
|
|
680
705
|
}
|
|
681
706
|
case "handlebars": {
|
|
682
|
-
result = this.
|
|
707
|
+
result = this._handlebars;
|
|
683
708
|
break;
|
|
684
709
|
}
|
|
685
710
|
case "liquid": {
|
|
686
|
-
result = this.
|
|
711
|
+
result = this._liquid;
|
|
687
712
|
break;
|
|
688
713
|
}
|
|
689
714
|
default: {
|
|
690
|
-
result = this.
|
|
715
|
+
result = this._ejs;
|
|
691
716
|
break;
|
|
692
717
|
}
|
|
693
718
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ecto",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"description": "Modern Template Consolidation Engine for EJS, Markdown, Pug, Nunjucks, Liquid, and Handlebars",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/ecto.js",
|
|
@@ -18,8 +18,11 @@
|
|
|
18
18
|
"author": "Jared Wray <me@jaredwray.com>",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"scripts": {
|
|
21
|
+
"lint": "biome check --write --error-on-warnings",
|
|
22
|
+
"lint:ci": "biome check --error-on-warnings",
|
|
21
23
|
"clean": "rimraf ./dist yarn.lock package-lock.json pnpm-lock.yaml ./coverage ./node_modules ./site/readme.md ./dist-site",
|
|
22
|
-
"test": "
|
|
24
|
+
"test": "pnpm lint && vitest run --coverage",
|
|
25
|
+
"test:ci": "pnpm lint:ci && vitest run --coverage",
|
|
23
26
|
"build": "rimraf ./dist && tsup src/ecto.ts --format esm --dts --clean",
|
|
24
27
|
"prepare": "pnpm build",
|
|
25
28
|
"website:build": "rimraf ./site/readme.md && npx -y docula build -s ./site -o ./dist-site",
|
|
@@ -46,30 +49,30 @@
|
|
|
46
49
|
"liquidjs"
|
|
47
50
|
],
|
|
48
51
|
"dependencies": {
|
|
49
|
-
"@jaredwray/fumanchu": "^
|
|
50
|
-
"cacheable": "^1.10.
|
|
52
|
+
"@jaredwray/fumanchu": "^4.0.1",
|
|
53
|
+
"cacheable": "^1.10.4",
|
|
51
54
|
"ejs": "^3.1.10",
|
|
52
|
-
"hookified": "^1.
|
|
55
|
+
"hookified": "^1.11.0",
|
|
53
56
|
"liquidjs": "^10.21.1",
|
|
54
57
|
"nunjucks": "^3.2.4",
|
|
55
58
|
"pug": "^3.0.3",
|
|
56
59
|
"underscore": "^1.13.7",
|
|
57
|
-
"writr": "^4.4.
|
|
60
|
+
"writr": "^4.4.6"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
63
|
+
"@biomejs/biome": "^2.2.4",
|
|
60
64
|
"@types/ejs": "^3.1.5",
|
|
61
|
-
"@types/node": "^24.0
|
|
65
|
+
"@types/node": "^24.3.0",
|
|
62
66
|
"@types/nunjucks": "^3.2.6",
|
|
63
67
|
"@types/pug": "^2.0.10",
|
|
64
68
|
"@types/underscore": "^1.13.0",
|
|
65
69
|
"@vitest/coverage-v8": "^3.2.4",
|
|
66
|
-
"docula": "^0.
|
|
70
|
+
"docula": "^0.20.0",
|
|
67
71
|
"rimraf": "^6.0.1",
|
|
68
72
|
"tsup": "^8.5.0",
|
|
69
|
-
"typescript": "^5.
|
|
73
|
+
"typescript": "^5.9.2",
|
|
70
74
|
"vitest": "^3.2.4",
|
|
71
|
-
"webpack": "^5.
|
|
72
|
-
"xo": "^1.2.0"
|
|
75
|
+
"webpack": "^5.101.3"
|
|
73
76
|
},
|
|
74
77
|
"files": [
|
|
75
78
|
"dist",
|