@kosatyi/ejs 0.0.109 → 0.0.111

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.
@@ -2,8 +2,8 @@
2
2
 
3
3
  var fs = require('node:fs/promises');
4
4
  var globWatch = require('glob-watcher');
5
- var glob = require('glob');
6
5
  var node_path = require('node:path');
6
+ var glob = require('glob');
7
7
  var index_js = require('./index.js');
8
8
 
9
9
  const symbolEntities = {
@@ -40,7 +40,7 @@ const bindContext = (object, methods = []) => {
40
40
  }
41
41
  };
42
42
 
43
- class Bundler {
43
+ class EjsBundler {
44
44
  #templates = {}
45
45
  #bundlerOptions = {
46
46
  target: [],
@@ -51,23 +51,27 @@ class Bundler {
51
51
  #ejsOptions
52
52
  #buildInProgress
53
53
  static exports = ['build', 'watch', 'concat', 'output']
54
+
54
55
  constructor(bundlerOptions = {}, ejsOptions = {}) {
55
56
  bindContext(this, this.constructor.exports);
56
57
  const { compile, configure } = index_js.create(ejsOptions);
57
58
  Object.assign(this.#bundlerOptions, bundlerOptions);
58
59
  this.#compile = compile;
59
- this.#ejsOptions = configure();
60
+ this.#ejsOptions = configure({});
60
61
  this.#buildInProgress = false;
61
62
  this.#templates = {};
62
63
  }
64
+
63
65
  async #stageRead(path) {
64
66
  return fs
65
67
  .readFile(node_path.join(this.#ejsOptions.path, path))
66
68
  .then((response) => response.toString())
67
69
  }
70
+
68
71
  #stageCompile(content, name) {
69
72
  return this.#compile(content, name).source
70
73
  }
74
+
71
75
  #getBundle() {
72
76
  const umd = this.#bundlerOptions.umd;
73
77
  const strict = this.#ejsOptions.strict;
@@ -102,6 +106,7 @@ class Bundler {
102
106
  }
103
107
  return out.join('\n')
104
108
  }
109
+
105
110
  async build() {
106
111
  if (this.#buildInProgress === true) return false
107
112
  this.#buildInProgress = true;
@@ -110,6 +115,7 @@ class Bundler {
110
115
  console.log('✅', 'bundle complete:', this.#bundlerOptions.target);
111
116
  this.#buildInProgress = false;
112
117
  }
118
+
113
119
  async watch() {
114
120
  console.log('🔍', 'watch directory:', this.#ejsOptions.path);
115
121
  const pattern = '**/*.'.concat(this.#ejsOptions.extension);
@@ -130,6 +136,7 @@ class Bundler {
130
136
  });
131
137
  });
132
138
  }
139
+
133
140
  async concat() {
134
141
  const pattern = '**/*.'.concat(this.#ejsOptions.extension);
135
142
  const list = await glob.glob(
@@ -144,6 +151,7 @@ class Bundler {
144
151
  this.#templates[template] = content;
145
152
  }
146
153
  }
154
+
147
155
  async output() {
148
156
  const target = [].concat(this.#bundlerOptions.target);
149
157
  const content = this.#getBundle();
@@ -162,11 +170,11 @@ class Bundler {
162
170
  }
163
171
 
164
172
  const bundler = (bundlerOptions = {}, ejsOptions = {}) => {
165
- return new Bundler(bundlerOptions, ejsOptions)
173
+ return new EjsBundler(bundlerOptions, ejsOptions)
166
174
  };
167
175
 
168
176
  const ejsRollupBundler = (bundlerOptions, ejsOptions) => {
169
- const bundle = new Bundler(bundlerOptions, ejsOptions);
177
+ const bundle = bundler(bundlerOptions, ejsOptions);
170
178
  return {
171
179
  name: 'ejs-bundler',
172
180
  async buildStart() {
@@ -178,6 +186,6 @@ const ejsRollupBundler = (bundlerOptions, ejsOptions) => {
178
186
  }
179
187
  };
180
188
 
181
- exports.Bundler = Bundler;
189
+ exports.EjsBundler = EjsBundler;
182
190
  exports.bundler = bundler;
183
191
  exports.ejsRollupBundler = ejsRollupBundler;
@@ -23,7 +23,7 @@ const entities = function () {
23
23
  let string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
24
24
  return ('' + string).replace(htmlEntitiesMatch, match => htmlEntities[match]);
25
25
  };
26
- const safeValue = (value, escape) => {
26
+ const escapeValue = (value, escape) => {
27
27
  const check = value;
28
28
  return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
29
29
  };
@@ -44,7 +44,7 @@ const eachAttribute = _ref => {
44
44
  const element = (tag, attrs, content) => {
45
45
  const result = [];
46
46
  const hasClosedTag = selfClosed.indexOf(tag) === -1;
47
- const attributes = Object.entries(attrs ?? {}).map(eachAttribute).filter(e => e).join(space);
47
+ const attributes = Object.entries(attrs !== null && attrs !== void 0 ? attrs : {}).map(eachAttribute).filter(e => e).join(space);
48
48
  result.push([lt, tag, space, attributes, gt].join(''));
49
49
  if (content && hasClosedTag) {
50
50
  result.push(Array.isArray(content) ? content.join('') : content);
@@ -56,4 +56,4 @@ const element = (tag, attrs, content) => {
56
56
  };
57
57
 
58
58
  exports.element = element;
59
- exports.safeValue = safeValue;
59
+ exports.escapeValue = escapeValue;