ecto 4.4.0 → 4.4.1
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 +12 -12
- package/dist/ecto.js +73 -77
- package/package.json +8 -8
package/dist/ecto.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare class BaseEngine {
|
|
|
15
15
|
opts?: any;
|
|
16
16
|
engine: any;
|
|
17
17
|
rootTemplatePath?: string;
|
|
18
|
-
private
|
|
18
|
+
private _extensions;
|
|
19
19
|
getExtensions(): string[];
|
|
20
20
|
setExtensions(extensions: string[]): void;
|
|
21
21
|
deleteExtension(name: string): void;
|
|
@@ -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
|
@@ -59,23 +59,23 @@ var BaseEngine = class {
|
|
|
59
59
|
opts = void 0;
|
|
60
60
|
engine;
|
|
61
61
|
rootTemplatePath = void 0;
|
|
62
|
-
|
|
62
|
+
_extensions = new Array();
|
|
63
63
|
getExtensions() {
|
|
64
|
-
return this.
|
|
64
|
+
return this._extensions;
|
|
65
65
|
}
|
|
66
66
|
setExtensions(extensions) {
|
|
67
|
-
this.
|
|
67
|
+
this._extensions = new Array();
|
|
68
68
|
for (const extension of extensions) {
|
|
69
69
|
const newExtension = extension.trim().toLowerCase();
|
|
70
|
-
if (!this.
|
|
71
|
-
this.
|
|
70
|
+
if (!this._extensions.includes(newExtension)) {
|
|
71
|
+
this._extensions.push(newExtension);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
deleteExtension(name) {
|
|
76
|
-
for (const [index, extension] of this.
|
|
76
|
+
for (const [index, extension] of this._extensions.entries()) {
|
|
77
77
|
if (name.toLowerCase().trim() === extension) {
|
|
78
|
-
this.
|
|
78
|
+
this._extensions.splice(index, 1);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -298,19 +298,19 @@ var EctoEvents = /* @__PURE__ */ ((EctoEvents2) => {
|
|
|
298
298
|
return EctoEvents2;
|
|
299
299
|
})(EctoEvents || {});
|
|
300
300
|
var Ecto = class extends Hookified {
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
_mapping = new EngineMap();
|
|
302
|
+
_engines = new Array();
|
|
303
303
|
// Cacheable instance for caching rendered templates
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
_cache;
|
|
305
|
+
_cacheSync;
|
|
306
|
+
_defaultEngine = "ejs";
|
|
307
307
|
// Engines
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
308
|
+
_ejs;
|
|
309
|
+
_markdown;
|
|
310
|
+
_pug;
|
|
311
|
+
_nunjucks;
|
|
312
|
+
_handlebars;
|
|
313
|
+
_liquid;
|
|
314
314
|
/**
|
|
315
315
|
* Ecto constructor
|
|
316
316
|
* @param {EctoOptions} [options] - The options for the ecto engine
|
|
@@ -318,30 +318,26 @@ var Ecto = class extends Hookified {
|
|
|
318
318
|
// eslint-disable-next-line complexity
|
|
319
319
|
constructor(options) {
|
|
320
320
|
super();
|
|
321
|
-
this.
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
324
|
-
this.
|
|
325
|
-
this.
|
|
326
|
-
this.
|
|
327
|
-
this.
|
|
321
|
+
this._ejs = new EJS(options?.engineOptions?.ejs);
|
|
322
|
+
this._markdown = new Markdown(options?.engineOptions?.markdown);
|
|
323
|
+
this._pug = new Pug(options?.engineOptions?.pug);
|
|
324
|
+
this._nunjucks = new Nunjucks(options?.engineOptions?.nunjucks);
|
|
325
|
+
this._handlebars = new Handlebars(options?.engineOptions?.handlebars);
|
|
326
|
+
this._liquid = new Liquid(options?.engineOptions?.liquid);
|
|
327
|
+
this._engines.push(this._ejs, this._markdown, this._pug, this._nunjucks, this._handlebars, this._liquid);
|
|
328
328
|
this.registerEngineMappings();
|
|
329
|
-
if (options?.cache
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
this.__cache = options.cache;
|
|
334
|
-
}
|
|
329
|
+
if (options?.cache === true) {
|
|
330
|
+
this._cache = new Cacheable();
|
|
331
|
+
} else if (options?.cache instanceof Cacheable) {
|
|
332
|
+
this._cache = options.cache;
|
|
335
333
|
}
|
|
336
|
-
if (options?.cacheSync
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
this.__cacheSync = options.cacheSync;
|
|
341
|
-
}
|
|
334
|
+
if (options?.cacheSync === true) {
|
|
335
|
+
this._cacheSync = new CacheableMemory();
|
|
336
|
+
} else if (options?.cacheSync instanceof CacheableMemory) {
|
|
337
|
+
this._cacheSync = options.cacheSync;
|
|
342
338
|
}
|
|
343
339
|
if (options !== void 0 && this.isValidEngine(options.defaultEngine)) {
|
|
344
|
-
this.
|
|
340
|
+
this._defaultEngine = options.defaultEngine;
|
|
345
341
|
}
|
|
346
342
|
}
|
|
347
343
|
/**
|
|
@@ -349,7 +345,7 @@ var Ecto = class extends Hookified {
|
|
|
349
345
|
* @returns {string} - the engine name such as 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
|
|
350
346
|
*/
|
|
351
347
|
get defaultEngine() {
|
|
352
|
-
return this.
|
|
348
|
+
return this._defaultEngine;
|
|
353
349
|
}
|
|
354
350
|
/**
|
|
355
351
|
* Set the default engine
|
|
@@ -358,9 +354,9 @@ var Ecto = class extends Hookified {
|
|
|
358
354
|
set defaultEngine(value) {
|
|
359
355
|
value = value.toLowerCase().trim();
|
|
360
356
|
if (this.isValidEngine(value)) {
|
|
361
|
-
this.
|
|
357
|
+
this._defaultEngine = value;
|
|
362
358
|
} else {
|
|
363
|
-
this.emit("warn" /* warn */, `Invalid engine name: ${value}. Defaulting to ${this.
|
|
359
|
+
this.emit("warn" /* warn */, `Invalid engine name: ${value}. Defaulting to ${this._defaultEngine}.`);
|
|
364
360
|
}
|
|
365
361
|
}
|
|
366
362
|
/**
|
|
@@ -368,77 +364,77 @@ var Ecto = class extends Hookified {
|
|
|
368
364
|
* @returns {Cacheable | undefined} - The cacheable instance or undefined if caching is disabled
|
|
369
365
|
*/
|
|
370
366
|
get cache() {
|
|
371
|
-
return this.
|
|
367
|
+
return this._cache;
|
|
372
368
|
}
|
|
373
369
|
/**
|
|
374
370
|
* Set the cacheable instance
|
|
375
371
|
* @param {Cacheable | undefined} value - The cacheable instance to set. If set to undefined, caching will be disabled.
|
|
376
372
|
*/
|
|
377
373
|
set cache(value) {
|
|
378
|
-
this.
|
|
374
|
+
this._cache = value;
|
|
379
375
|
}
|
|
380
376
|
/**
|
|
381
377
|
* Get the cacheable memory instance
|
|
382
378
|
* @returns {CacheableMemory | undefined} - The cacheable memory instance or undefined if caching is disabled
|
|
383
379
|
*/
|
|
384
380
|
get cacheSync() {
|
|
385
|
-
return this.
|
|
381
|
+
return this._cacheSync;
|
|
386
382
|
}
|
|
387
383
|
/**
|
|
388
384
|
* Set the cacheable memory instance
|
|
389
385
|
* @param {CacheableMemory | undefined} value - The cacheable memory instance to set. If set to undefined, caching will be disabled.
|
|
390
386
|
*/
|
|
391
387
|
set cacheSync(value) {
|
|
392
|
-
this.
|
|
388
|
+
this._cacheSync = value;
|
|
393
389
|
}
|
|
394
390
|
/**
|
|
395
391
|
* Get the Engine Mappings. This is used to map file extensions to engines
|
|
396
392
|
* @returns {EngineMap}
|
|
397
393
|
*/
|
|
398
394
|
get mappings() {
|
|
399
|
-
return this.
|
|
395
|
+
return this._mapping;
|
|
400
396
|
}
|
|
401
397
|
/**
|
|
402
398
|
* Get the EJS Engine
|
|
403
399
|
* @returns {EJS}
|
|
404
400
|
*/
|
|
405
401
|
get ejs() {
|
|
406
|
-
return this.
|
|
402
|
+
return this._ejs;
|
|
407
403
|
}
|
|
408
404
|
/**
|
|
409
405
|
* Get the Markdown Engine
|
|
410
406
|
* @returns {Markdown}
|
|
411
407
|
*/
|
|
412
408
|
get markdown() {
|
|
413
|
-
return this.
|
|
409
|
+
return this._markdown;
|
|
414
410
|
}
|
|
415
411
|
/**
|
|
416
412
|
* Get the Pug Engine
|
|
417
413
|
* @returns {Pug}
|
|
418
414
|
*/
|
|
419
415
|
get pug() {
|
|
420
|
-
return this.
|
|
416
|
+
return this._pug;
|
|
421
417
|
}
|
|
422
418
|
/**
|
|
423
419
|
* Get the Nunjucks Engine
|
|
424
420
|
* @returns {Nunjucks}
|
|
425
421
|
*/
|
|
426
422
|
get nunjucks() {
|
|
427
|
-
return this.
|
|
423
|
+
return this._nunjucks;
|
|
428
424
|
}
|
|
429
425
|
/**
|
|
430
426
|
* Get the Handlebars Engine
|
|
431
427
|
* @returns {Handlebars}
|
|
432
428
|
*/
|
|
433
429
|
get handlebars() {
|
|
434
|
-
return this.
|
|
430
|
+
return this._handlebars;
|
|
435
431
|
}
|
|
436
432
|
/**
|
|
437
433
|
* Get the Liquid Engine
|
|
438
434
|
* @returns {Liquid}
|
|
439
435
|
*/
|
|
440
436
|
get liquid() {
|
|
441
|
-
return this.
|
|
437
|
+
return this._liquid;
|
|
442
438
|
}
|
|
443
439
|
/**
|
|
444
440
|
* Async render the source with the data
|
|
@@ -452,9 +448,9 @@ var Ecto = class extends Hookified {
|
|
|
452
448
|
// eslint-disable-next-line max-params
|
|
453
449
|
async render(source, data, engineName, rootTemplatePath, filePathOutput) {
|
|
454
450
|
try {
|
|
455
|
-
const cacheKey = `${engineName ?? this.
|
|
456
|
-
if (this.
|
|
457
|
-
const cachedResult = await this.
|
|
451
|
+
const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
|
|
452
|
+
if (this._cache) {
|
|
453
|
+
const cachedResult = await this._cache.get(cacheKey);
|
|
458
454
|
if (cachedResult) {
|
|
459
455
|
this.emit("cacheHit" /* cacheHit */, `Cache hit for key: ${cacheKey}`);
|
|
460
456
|
await this.writeFile(filePathOutput, cachedResult);
|
|
@@ -463,15 +459,15 @@ var Ecto = class extends Hookified {
|
|
|
463
459
|
this.emit("cacheMiss" /* cacheMiss */, `Cache miss for key: ${cacheKey}`);
|
|
464
460
|
}
|
|
465
461
|
let result = "";
|
|
466
|
-
let renderEngineName = this.
|
|
462
|
+
let renderEngineName = this._defaultEngine;
|
|
467
463
|
if (this.isValidEngine(engineName) && engineName !== void 0) {
|
|
468
464
|
renderEngineName = engineName;
|
|
469
465
|
}
|
|
470
466
|
const renderEngine = this.getRenderEngine(renderEngineName);
|
|
471
467
|
renderEngine.rootTemplatePath = rootTemplatePath;
|
|
472
468
|
result = await renderEngine.render(source, data);
|
|
473
|
-
if (this.
|
|
474
|
-
await this.
|
|
469
|
+
if (this._cache) {
|
|
470
|
+
await this._cache.set(cacheKey, result);
|
|
475
471
|
}
|
|
476
472
|
await this.writeFile(filePathOutput, result);
|
|
477
473
|
return result;
|
|
@@ -492,9 +488,9 @@ var Ecto = class extends Hookified {
|
|
|
492
488
|
// eslint-disable-next-line max-params
|
|
493
489
|
renderSync(source, data, engineName, rootTemplatePath, filePathOutput) {
|
|
494
490
|
try {
|
|
495
|
-
const cacheKey = `${engineName ?? this.
|
|
496
|
-
if (this.
|
|
497
|
-
const cachedResult = this.
|
|
491
|
+
const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
|
|
492
|
+
if (this._cacheSync) {
|
|
493
|
+
const cachedResult = this._cacheSync.get(cacheKey);
|
|
498
494
|
if (cachedResult) {
|
|
499
495
|
this.emit("cacheHit" /* cacheHit */, `Cache hit for key: ${cacheKey}`);
|
|
500
496
|
this.writeFileSync(filePathOutput, cachedResult);
|
|
@@ -503,15 +499,15 @@ var Ecto = class extends Hookified {
|
|
|
503
499
|
this.emit("cacheMiss" /* cacheMiss */, `Cache miss for key: ${cacheKey}`);
|
|
504
500
|
}
|
|
505
501
|
let result = "";
|
|
506
|
-
let renderEngineName = this.
|
|
502
|
+
let renderEngineName = this._defaultEngine;
|
|
507
503
|
if (this.isValidEngine(engineName) && engineName !== void 0) {
|
|
508
504
|
renderEngineName = engineName;
|
|
509
505
|
}
|
|
510
506
|
const renderEngine = this.getRenderEngine(renderEngineName);
|
|
511
507
|
renderEngine.rootTemplatePath = rootTemplatePath;
|
|
512
508
|
result = renderEngine.renderSync(source, data);
|
|
513
|
-
if (this.
|
|
514
|
-
this.
|
|
509
|
+
if (this._cacheSync) {
|
|
510
|
+
this._cacheSync.set(cacheKey, result);
|
|
515
511
|
}
|
|
516
512
|
this.writeFileSync(filePathOutput, result);
|
|
517
513
|
return result;
|
|
@@ -586,10 +582,10 @@ var Ecto = class extends Hookified {
|
|
|
586
582
|
* @returns {string} - will return the engine name such as 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
|
|
587
583
|
*/
|
|
588
584
|
getEngineByFilePath(filePath) {
|
|
589
|
-
let result = this.
|
|
585
|
+
let result = this._defaultEngine;
|
|
590
586
|
if (filePath !== void 0) {
|
|
591
587
|
const extension = filePath.includes(".") ? filePath.slice(filePath.lastIndexOf(".") + 1) : "";
|
|
592
|
-
const engExtension = this.
|
|
588
|
+
const engExtension = this._mapping.getName(extension);
|
|
593
589
|
if (engExtension !== void 0) {
|
|
594
590
|
result = engExtension;
|
|
595
591
|
}
|
|
@@ -637,7 +633,7 @@ var Ecto = class extends Hookified {
|
|
|
637
633
|
*/
|
|
638
634
|
isValidEngine(engineName) {
|
|
639
635
|
let result = false;
|
|
640
|
-
if (engineName !== void 0 && this.
|
|
636
|
+
if (engineName !== void 0 && this._mapping.get(engineName) !== void 0) {
|
|
641
637
|
result = true;
|
|
642
638
|
}
|
|
643
639
|
return result;
|
|
@@ -647,9 +643,9 @@ var Ecto = class extends Hookified {
|
|
|
647
643
|
* @returns {void}
|
|
648
644
|
*/
|
|
649
645
|
registerEngineMappings() {
|
|
650
|
-
for (const eng of this.
|
|
646
|
+
for (const eng of this._engines) {
|
|
651
647
|
for (const name of eng.names) {
|
|
652
|
-
this.
|
|
648
|
+
this._mapping.set(name, eng.getExtensions());
|
|
653
649
|
}
|
|
654
650
|
}
|
|
655
651
|
}
|
|
@@ -659,35 +655,35 @@ var Ecto = class extends Hookified {
|
|
|
659
655
|
* @returns {EngineInterface}
|
|
660
656
|
*/
|
|
661
657
|
getRenderEngine(engineName) {
|
|
662
|
-
let result = this.
|
|
658
|
+
let result = this._ejs;
|
|
663
659
|
const cleanEngineName = engineName.trim().toLowerCase();
|
|
664
660
|
switch (cleanEngineName) {
|
|
665
661
|
case "markdown": {
|
|
666
|
-
result = this.
|
|
662
|
+
result = this._markdown;
|
|
667
663
|
break;
|
|
668
664
|
}
|
|
669
665
|
case "pug": {
|
|
670
|
-
result = this.
|
|
666
|
+
result = this._pug;
|
|
671
667
|
break;
|
|
672
668
|
}
|
|
673
669
|
case "nunjucks": {
|
|
674
|
-
result = this.
|
|
670
|
+
result = this._nunjucks;
|
|
675
671
|
break;
|
|
676
672
|
}
|
|
677
673
|
case "mustache": {
|
|
678
|
-
result = this.
|
|
674
|
+
result = this._handlebars;
|
|
679
675
|
break;
|
|
680
676
|
}
|
|
681
677
|
case "handlebars": {
|
|
682
|
-
result = this.
|
|
678
|
+
result = this._handlebars;
|
|
683
679
|
break;
|
|
684
680
|
}
|
|
685
681
|
case "liquid": {
|
|
686
|
-
result = this.
|
|
682
|
+
result = this._liquid;
|
|
687
683
|
break;
|
|
688
684
|
}
|
|
689
685
|
default: {
|
|
690
|
-
result = this.
|
|
686
|
+
result = this._ejs;
|
|
691
687
|
break;
|
|
692
688
|
}
|
|
693
689
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ecto",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.1",
|
|
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",
|
|
@@ -47,28 +47,28 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@jaredwray/fumanchu": "^3.1.2",
|
|
50
|
-
"cacheable": "^1.10.
|
|
50
|
+
"cacheable": "^1.10.4",
|
|
51
51
|
"ejs": "^3.1.10",
|
|
52
|
-
"hookified": "^1.
|
|
52
|
+
"hookified": "^1.11.0",
|
|
53
53
|
"liquidjs": "^10.21.1",
|
|
54
54
|
"nunjucks": "^3.2.4",
|
|
55
55
|
"pug": "^3.0.3",
|
|
56
56
|
"underscore": "^1.13.7",
|
|
57
|
-
"writr": "^4.4.
|
|
57
|
+
"writr": "^4.4.6"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/ejs": "^3.1.5",
|
|
61
|
-
"@types/node": "^24.0
|
|
61
|
+
"@types/node": "^24.3.0",
|
|
62
62
|
"@types/nunjucks": "^3.2.6",
|
|
63
63
|
"@types/pug": "^2.0.10",
|
|
64
64
|
"@types/underscore": "^1.13.0",
|
|
65
65
|
"@vitest/coverage-v8": "^3.2.4",
|
|
66
|
-
"docula": "^0.
|
|
66
|
+
"docula": "^0.20.0",
|
|
67
67
|
"rimraf": "^6.0.1",
|
|
68
68
|
"tsup": "^8.5.0",
|
|
69
|
-
"typescript": "^5.
|
|
69
|
+
"typescript": "^5.9.2",
|
|
70
70
|
"vitest": "^3.2.4",
|
|
71
|
-
"webpack": "^5.
|
|
71
|
+
"webpack": "^5.101.3",
|
|
72
72
|
"xo": "^1.2.0"
|
|
73
73
|
},
|
|
74
74
|
"files": [
|