@kosatyi/ejs 0.0.86 → 0.0.88

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/bin/bundler.js CHANGED
@@ -8,7 +8,6 @@ const schema = argv(process.argv.slice(2))
8
8
 
9
9
  const params = schema({
10
10
  target: null,
11
- minify: false,
12
11
  umd: false,
13
12
  withObject: false,
14
13
  export: 'ejsPrecompiled',
@@ -429,31 +429,88 @@ var element = function element(tag, attrs, content) {
429
429
  return result.join('');
430
430
  };
431
431
 
432
+ /**
433
+ * @extends Error
434
+ * @property code
435
+ * @param {string} message
436
+ * @constructor
437
+ */
432
438
  function TemplateError(message) {
433
- this.code = 1;
434
439
  this.name = 'TemplateError';
435
440
  this.message = message;
436
441
  Error.call(this);
437
442
  }
438
- Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
443
+
444
+ /**
445
+ *
446
+ */
447
+ Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
448
+ Object.assign(TemplateError.prototype, {
449
+ code: 1
450
+ });
451
+ /**
452
+ *
453
+ * @return {number}
454
+ */
455
+ TemplateError.prototype.getCode = function () {
456
+ return this.code;
457
+ };
458
+ /**
459
+ *
460
+ * @return {string}
461
+ */
462
+ TemplateError.prototype.getMessage = function () {
463
+ return this.message;
464
+ };
465
+ /**
466
+ * @return {string}
467
+ */
468
+ TemplateError.prototype.toString = function () {
469
+ return this.getMessage();
470
+ };
471
+
472
+ /**
473
+ * @extends TemplateError
474
+ * @param {string} message
475
+ * @constructor
476
+ */
439
477
  function TemplateNotFound(message) {
440
478
  TemplateError.call(this);
441
- this.code = 404;
442
479
  this.name = 'TemplateNotFound';
443
480
  this.message = message;
444
481
  }
482
+
483
+ /**
484
+ *
485
+ */
445
486
  Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
487
+ Object.assign(TemplateNotFound.prototype, {
488
+ code: 404
489
+ });
490
+ /**
491
+ * @extends TemplateError
492
+ * @param {string} message
493
+ * @constructor
494
+ */
446
495
  function TemplateSyntaxError(message) {
447
496
  TemplateError.call(this);
448
- this.code = 500;
449
497
  this.name = 'TemplateSyntaxError';
450
498
  this.message = message;
451
499
  }
500
+
501
+ /**
502
+ *
503
+ */
452
504
  Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
505
+ Object.assign(TemplateSyntaxError.prototype, {
506
+ code: 500
507
+ });
453
508
 
454
509
  function resolve(list) {
455
510
  return Promise.all(list || []).then(function (list) {
456
511
  return list.join('');
512
+ })["catch"](function (e) {
513
+ return e;
457
514
  });
458
515
  }
459
516
  function reject(error) {
@@ -885,6 +942,9 @@ var render = ejs.render,
885
942
  configure = ejs.configure,
886
943
  create = ejs.create;
887
944
 
945
+ exports.TemplateError = TemplateError;
946
+ exports.TemplateNotFound = TemplateNotFound;
947
+ exports.TemplateSyntaxError = TemplateSyntaxError;
888
948
  exports.compile = compile;
889
949
  exports.configure = configure;
890
950
  exports.context = context;
@@ -4,7 +4,6 @@ var fs = require('fs');
4
4
  var glob = require('glob');
5
5
  var watch = require('glob-watcher');
6
6
  var path = require('path');
7
- var terser = require('terser');
8
7
  var index_js = require('./index.js');
9
8
 
10
9
  const isPlainObject = function(obj) {
@@ -45,9 +44,9 @@ class Bundler {
45
44
  return index_js.compile(content, name).source
46
45
  }
47
46
 
48
- stageWrapper(content){
47
+ getBundle() {
49
48
  const umd = this.options.umd;
50
- const minify = this.options.minify;
49
+ const strict = this.config.withObject === false;
51
50
  const module = this.config.export;
52
51
  const out = [];
53
52
  if (umd) {
@@ -59,35 +58,18 @@ class Bundler {
59
58
  out.push(`global || self,global["${module}"] = factory())`);
60
59
  out.push('})(this,(function(){');
61
60
  }
62
- out.push(content);
63
- if (umd) {
64
- out.push('return templates}))');
65
- } else {
66
- out.push('export default templates');
67
- }
68
- return out.join(minify ? '' : '\n')
69
- }
70
- async stageMinify(content) {
71
- if (this.options.minify === false) return content
72
- const config = {
73
- compress: {
74
- dead_code: false,
75
- side_effects: false
76
- }
77
- };
78
- const response = await terser.minify(content, config);
79
- return response.code
80
- }
81
-
82
- getBundle() {
83
- const out = [];
84
- if (this.config.withObject === false) out.push(`'use strict'`);
61
+ if (strict) out.push(`'use strict'`);
85
62
  out.push('const templates = {}');
86
63
  Object.entries(this.templates).forEach(([name, content]) => {
87
64
  name = JSON.stringify(name);
88
65
  content = String(content);
89
66
  out.push(`templates[${name}] = ${content}`);
90
67
  });
68
+ if (umd) {
69
+ out.push('return templates}))');
70
+ } else {
71
+ out.push('export default templates');
72
+ }
91
73
  return out.join('\n')
92
74
  }
93
75
  async watch() {
@@ -133,11 +115,7 @@ class Bundler {
133
115
 
134
116
  async output() {
135
117
  const target = [].concat(this.options.target);
136
- let content = this.getBundle();
137
- if (this.options.minify) {
138
- content = await this.stageMinify(content);
139
- }
140
- content = this.stageWrapper(content);
118
+ const content = this.getBundle();
141
119
  for (let file of target) {
142
120
  const folderPath = path.dirname(file);
143
121
  const folderExists = await fs.promises
package/dist/cjs/index.js CHANGED
@@ -432,31 +432,88 @@ var element = function element(tag, attrs, content) {
432
432
  return result.join('');
433
433
  };
434
434
 
435
+ /**
436
+ * @extends Error
437
+ * @property code
438
+ * @param {string} message
439
+ * @constructor
440
+ */
435
441
  function TemplateError(message) {
436
- this.code = 1;
437
442
  this.name = 'TemplateError';
438
443
  this.message = message;
439
444
  Error.call(this);
440
445
  }
441
- Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
446
+
447
+ /**
448
+ *
449
+ */
450
+ Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
451
+ Object.assign(TemplateError.prototype, {
452
+ code: 1
453
+ });
454
+ /**
455
+ *
456
+ * @return {number}
457
+ */
458
+ TemplateError.prototype.getCode = function () {
459
+ return this.code;
460
+ };
461
+ /**
462
+ *
463
+ * @return {string}
464
+ */
465
+ TemplateError.prototype.getMessage = function () {
466
+ return this.message;
467
+ };
468
+ /**
469
+ * @return {string}
470
+ */
471
+ TemplateError.prototype.toString = function () {
472
+ return this.getMessage();
473
+ };
474
+
475
+ /**
476
+ * @extends TemplateError
477
+ * @param {string} message
478
+ * @constructor
479
+ */
442
480
  function TemplateNotFound(message) {
443
481
  TemplateError.call(this);
444
- this.code = 404;
445
482
  this.name = 'TemplateNotFound';
446
483
  this.message = message;
447
484
  }
485
+
486
+ /**
487
+ *
488
+ */
448
489
  Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
490
+ Object.assign(TemplateNotFound.prototype, {
491
+ code: 404
492
+ });
493
+ /**
494
+ * @extends TemplateError
495
+ * @param {string} message
496
+ * @constructor
497
+ */
449
498
  function TemplateSyntaxError(message) {
450
499
  TemplateError.call(this);
451
- this.code = 500;
452
500
  this.name = 'TemplateSyntaxError';
453
501
  this.message = message;
454
502
  }
503
+
504
+ /**
505
+ *
506
+ */
455
507
  Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
508
+ Object.assign(TemplateSyntaxError.prototype, {
509
+ code: 500
510
+ });
456
511
 
457
512
  function resolve(list) {
458
513
  return Promise.all(list || []).then(function (list) {
459
514
  return list.join('');
515
+ })["catch"](function (e) {
516
+ return e;
460
517
  });
461
518
  }
462
519
  function reject(error) {
@@ -921,6 +978,9 @@ var render = ejs.render,
921
978
  create = ejs.create;
922
979
  var __express = expressRenderer(ejs);
923
980
 
981
+ exports.TemplateError = TemplateError;
982
+ exports.TemplateNotFound = TemplateNotFound;
983
+ exports.TemplateSyntaxError = TemplateSyntaxError;
924
984
  exports.__express = __express;
925
985
  exports.compile = compile;
926
986
  exports.configure = configure;
@@ -750,31 +750,88 @@ var element = function element(tag, attrs, content) {
750
750
  return result.join('');
751
751
  };
752
752
 
753
+ /**
754
+ * @extends Error
755
+ * @property code
756
+ * @param {string} message
757
+ * @constructor
758
+ */
753
759
  function TemplateError(message) {
754
- this.code = 1;
755
760
  this.name = 'TemplateError';
756
761
  this.message = message;
757
762
  Error.call(this);
758
763
  }
759
- Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
764
+
765
+ /**
766
+ *
767
+ */
768
+ Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
769
+ Object.assign(TemplateError.prototype, {
770
+ code: 1
771
+ });
772
+ /**
773
+ *
774
+ * @return {number}
775
+ */
776
+ TemplateError.prototype.getCode = function () {
777
+ return this.code;
778
+ };
779
+ /**
780
+ *
781
+ * @return {string}
782
+ */
783
+ TemplateError.prototype.getMessage = function () {
784
+ return this.message;
785
+ };
786
+ /**
787
+ * @return {string}
788
+ */
789
+ TemplateError.prototype.toString = function () {
790
+ return this.getMessage();
791
+ };
792
+
793
+ /**
794
+ * @extends TemplateError
795
+ * @param {string} message
796
+ * @constructor
797
+ */
760
798
  function TemplateNotFound(message) {
761
799
  TemplateError.call(this);
762
- this.code = 404;
763
800
  this.name = 'TemplateNotFound';
764
801
  this.message = message;
765
802
  }
803
+
804
+ /**
805
+ *
806
+ */
766
807
  Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
808
+ Object.assign(TemplateNotFound.prototype, {
809
+ code: 404
810
+ });
811
+ /**
812
+ * @extends TemplateError
813
+ * @param {string} message
814
+ * @constructor
815
+ */
767
816
  function TemplateSyntaxError(message) {
768
817
  TemplateError.call(this);
769
- this.code = 500;
770
818
  this.name = 'TemplateSyntaxError';
771
819
  this.message = message;
772
820
  }
821
+
822
+ /**
823
+ *
824
+ */
773
825
  Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
826
+ Object.assign(TemplateSyntaxError.prototype, {
827
+ code: 500
828
+ });
774
829
 
775
830
  function resolve(list) {
776
831
  return Promise.all(list || []).then(function (list) {
777
832
  return list.join('');
833
+ })["catch"](function (e) {
834
+ return e;
778
835
  });
779
836
  }
780
837
  function reject(error) {
@@ -1213,6 +1270,7 @@ function setTemplates(list) {
1213
1270
  /**
1214
1271
  * @typedef {Object<string,any>} HonoContext
1215
1272
  * @property {function(*):Promise<Response>} html
1273
+ * @property {function():Promise<Response>} notFound
1216
1274
  * @property {function(name:string,data:{}):Promise<string>} render
1217
1275
  * @property {function(name:string,data:{}):Promise<string>} ejs
1218
1276
  * @property {ContextScope} data
@@ -1228,6 +1286,7 @@ function setRenderer(_ref) {
1228
1286
  secure = _ref$secure === void 0 ? true : _ref$secure,
1229
1287
  _ref$version = _ref.version,
1230
1288
  version = _ref$version === void 0 ? '1.0' : _ref$version;
1289
+ _ref.errorHandler;
1231
1290
  return /*#__PURE__*/function () {
1232
1291
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(c, next) {
1233
1292
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -1263,6 +1322,9 @@ var render = ejs.render,
1263
1322
  configure = ejs.configure,
1264
1323
  create = ejs.create;
1265
1324
 
1325
+ exports.TemplateError = TemplateError;
1326
+ exports.TemplateNotFound = TemplateNotFound;
1327
+ exports.TemplateSyntaxError = TemplateSyntaxError;
1266
1328
  exports.compile = compile;
1267
1329
  exports.configure = configure;
1268
1330
  exports.context = context;
@@ -503,34 +503,79 @@ const element = (tag, attrs, content) => {
503
503
  return result.join('')
504
504
  };
505
505
 
506
+ /**
507
+ * @extends Error
508
+ * @property code
509
+ * @param {string} message
510
+ * @constructor
511
+ */
506
512
  function TemplateError(message) {
507
- this.code = 1;
508
513
  this.name = 'TemplateError';
509
514
  this.message = message;
510
515
  Error.call(this);
511
516
  }
512
- Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
513
517
 
518
+ /**
519
+ *
520
+ */
521
+ Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
522
+ Object.assign(TemplateError.prototype, { code: 1 });
523
+ /**
524
+ *
525
+ * @return {number}
526
+ */
527
+ TemplateError.prototype.getCode = function() {
528
+ return this.code
529
+ };
530
+ /**
531
+ *
532
+ * @return {string}
533
+ */
534
+ TemplateError.prototype.getMessage = function() {
535
+ return this.message
536
+ };
537
+ /**
538
+ * @return {string}
539
+ */
540
+ TemplateError.prototype.toString = function() {
541
+ return this.getMessage()
542
+ };
543
+
544
+ /**
545
+ * @extends TemplateError
546
+ * @param {string} message
547
+ * @constructor
548
+ */
514
549
  function TemplateNotFound(message) {
515
550
  TemplateError.call(this);
516
- this.code = 404;
517
551
  this.name = 'TemplateNotFound';
518
552
  this.message = message;
519
553
  }
520
554
 
555
+ /**
556
+ *
557
+ */
521
558
  Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
522
-
559
+ Object.assign(TemplateNotFound.prototype, { code: 404 });
560
+ /**
561
+ * @extends TemplateError
562
+ * @param {string} message
563
+ * @constructor
564
+ */
523
565
  function TemplateSyntaxError(message) {
524
566
  TemplateError.call(this);
525
- this.code = 500;
526
567
  this.name = 'TemplateSyntaxError';
527
568
  this.message = message;
528
569
  }
529
570
 
571
+ /**
572
+ *
573
+ */
530
574
  Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
575
+ Object.assign(TemplateSyntaxError.prototype, { code: 500 });
531
576
 
532
577
  function resolve(list) {
533
- return Promise.all(list || []).then((list) => list.join(''))
578
+ return Promise.all(list || []).then((list) => list.join('')).catch((e) => e)
534
579
  }
535
580
 
536
581
  function reject(error) {
@@ -540,25 +585,27 @@ function reject(error) {
540
585
  function createBuffer() {
541
586
  let store = [],
542
587
  array = [];
588
+
543
589
  function buffer(value) {
544
590
  array.push(value);
545
591
  }
546
- buffer.start = function () {
592
+
593
+ buffer.start = function() {
547
594
  array = [];
548
595
  };
549
- buffer.backup = function () {
596
+ buffer.backup = function() {
550
597
  store.push(array.concat());
551
598
  array = [];
552
599
  };
553
- buffer.restore = function () {
600
+ buffer.restore = function() {
554
601
  const result = array.concat();
555
602
  array = store.pop();
556
603
  return resolve(result)
557
604
  };
558
- buffer.error = function (e) {
605
+ buffer.error = function(e) {
559
606
  return reject(e)
560
607
  };
561
- buffer.end = function () {
608
+ buffer.end = function() {
562
609
  return resolve(array)
563
610
  };
564
611
  return buffer
@@ -1004,4 +1051,4 @@ const ejs = new EJS({ resolver: httpRequest });
1004
1051
 
1005
1052
  const { render, context, compile, helpers, preload, configure, create } = ejs;
1006
1053
 
1007
- export { compile, configure, context, create, helpers, preload, render };
1054
+ export { TemplateError, TemplateNotFound, TemplateSyntaxError, compile, configure, context, create, helpers, preload, render };
@@ -2,7 +2,6 @@ import { promises } from 'fs';
2
2
  import { glob } from 'glob';
3
3
  import watch from 'glob-watcher';
4
4
  import { join, dirname } from 'path';
5
- import { minify } from 'terser';
6
5
  import { configure, compile } from './index.js';
7
6
 
8
7
  const isPlainObject = function(obj) {
@@ -43,9 +42,9 @@ class Bundler {
43
42
  return compile(content, name).source
44
43
  }
45
44
 
46
- stageWrapper(content){
45
+ getBundle() {
47
46
  const umd = this.options.umd;
48
- const minify = this.options.minify;
47
+ const strict = this.config.withObject === false;
49
48
  const module = this.config.export;
50
49
  const out = [];
51
50
  if (umd) {
@@ -57,35 +56,18 @@ class Bundler {
57
56
  out.push(`global || self,global["${module}"] = factory())`);
58
57
  out.push('})(this,(function(){');
59
58
  }
60
- out.push(content);
61
- if (umd) {
62
- out.push('return templates}))');
63
- } else {
64
- out.push('export default templates');
65
- }
66
- return out.join(minify ? '' : '\n')
67
- }
68
- async stageMinify(content) {
69
- if (this.options.minify === false) return content
70
- const config = {
71
- compress: {
72
- dead_code: false,
73
- side_effects: false
74
- }
75
- };
76
- const response = await minify(content, config);
77
- return response.code
78
- }
79
-
80
- getBundle() {
81
- const out = [];
82
- if (this.config.withObject === false) out.push(`'use strict'`);
59
+ if (strict) out.push(`'use strict'`);
83
60
  out.push('const templates = {}');
84
61
  Object.entries(this.templates).forEach(([name, content]) => {
85
62
  name = JSON.stringify(name);
86
63
  content = String(content);
87
64
  out.push(`templates[${name}] = ${content}`);
88
65
  });
66
+ if (umd) {
67
+ out.push('return templates}))');
68
+ } else {
69
+ out.push('export default templates');
70
+ }
89
71
  return out.join('\n')
90
72
  }
91
73
  async watch() {
@@ -131,11 +113,7 @@ class Bundler {
131
113
 
132
114
  async output() {
133
115
  const target = [].concat(this.options.target);
134
- let content = this.getBundle();
135
- if (this.options.minify) {
136
- content = await this.stageMinify(content);
137
- }
138
- content = this.stageWrapper(content);
116
+ const content = this.getBundle();
139
117
  for (let file of target) {
140
118
  const folderPath = dirname(file);
141
119
  const folderExists = await promises