@kosatyi/ejs 0.0.96 → 0.0.98

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.
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs');
3
+ var node_fs = require('node:fs');
4
+ var node_path = require('node:path');
4
5
  var glob = require('glob');
5
6
  var watch = require('glob-watcher');
6
- var path = require('path');
7
7
  var index_js = require('./index.js');
8
8
 
9
- const isPlainObject = function(obj) {
9
+ const isPlainObject = function (obj) {
10
10
  return Object.prototype.toString.call(obj) === '[object Object]'
11
11
  };
12
12
 
@@ -21,7 +21,7 @@ class Bundler {
21
21
  options = {
22
22
  target: [],
23
23
  umd: true,
24
- minify: true
24
+ minify: true,
25
25
  }
26
26
  /**
27
27
  * @type {EjsConfig}
@@ -40,9 +40,9 @@ class Bundler {
40
40
  this.templates = {};
41
41
  }
42
42
 
43
- stageRead(path$1) {
44
- return fs.promises
45
- .readFile(path.join(this.config.path, path$1))
43
+ stageRead(path) {
44
+ return node_fs.promises
45
+ .readFile(node_path.join(this.config.path, path))
46
46
  .then((response) => response.toString())
47
47
  }
48
48
 
@@ -57,10 +57,16 @@ class Bundler {
57
57
  const out = [];
58
58
  if (umd) {
59
59
  out.push('(function(global,factory){');
60
- out.push('typeof exports === "object" && typeof module !== "undefined" ?');
60
+ out.push(
61
+ 'typeof exports === "object" && typeof module !== "undefined" ?'
62
+ );
61
63
  out.push('module.exports = factory():');
62
- out.push('typeof define === "function" && define.amd ? define(factory):');
63
- out.push('(global = typeof globalThis !== "undefined" ? globalThis:');
64
+ out.push(
65
+ 'typeof define === "function" && define.amd ? define(factory):'
66
+ );
67
+ out.push(
68
+ '(global = typeof globalThis !== "undefined" ? globalThis:'
69
+ );
64
70
  out.push(`global || self,global["${module}"] = factory())`);
65
71
  out.push('})(this,(function(){');
66
72
  }
@@ -84,16 +90,16 @@ class Bundler {
84
90
  const watcher = watch(pattern, { cwd: this.config.path });
85
91
  const state = { build: null };
86
92
  watcher.on('change', (path) => {
87
- if(state.build) return;
88
- console.log('⟳','file change:',path);
89
- state.build = this.build().then(()=>{
93
+ if (state.build) return
94
+ console.log('⟳', 'file change:', path);
95
+ state.build = this.build().then(() => {
90
96
  state.build = null;
91
97
  });
92
98
  });
93
99
  watcher.on('add', (path) => {
94
- if(state.build) return;
95
- console.log('+','file added:',path);
96
- state.build = this.build().then(()=>{
100
+ if (state.build) return
101
+ console.log('+', 'file added:', path);
102
+ state.build = this.build().then(() => {
97
103
  state.build = null;
98
104
  });
99
105
  });
@@ -104,7 +110,7 @@ class Bundler {
104
110
  this.buildInProgress = true;
105
111
  await this.concat().catch(console.error);
106
112
  await this.output().catch(console.error);
107
- console.log('✅','bundle complete:',this.options.target);
113
+ console.log('✅', 'bundle complete:', this.options.target);
108
114
  this.buildInProgress = false;
109
115
  }
110
116
 
@@ -122,15 +128,15 @@ class Bundler {
122
128
  const target = [].concat(this.options.target);
123
129
  const content = this.getBundle();
124
130
  for (let file of target) {
125
- const folderPath = path.dirname(file);
126
- const folderExists = await fs.promises
131
+ const folderPath = node_path.dirname(file);
132
+ const folderExists = await node_fs.promises
127
133
  .stat(folderPath)
128
134
  .then(() => true)
129
135
  .catch(() => false);
130
136
  if (folderExists === false) {
131
- await fs.promises.mkdir(folderPath, { recursive: true });
137
+ await node_fs.promises.mkdir(folderPath, { recursive: true });
132
138
  }
133
- await fs.promises.writeFile(file, content);
139
+ await node_fs.promises.writeFile(file, content);
134
140
  }
135
141
  }
136
142
  }
@@ -144,7 +150,7 @@ const ejsBundler = (options, config) => {
144
150
  },
145
151
  async buildEnd() {
146
152
  await bundler.output();
147
- }
153
+ },
148
154
  }
149
155
  };
150
156
 
@@ -54,6 +54,13 @@ var map = function map(object, callback, context) {
54
54
  });
55
55
  return result;
56
56
  };
57
+
58
+ /**
59
+ *
60
+ * @param object
61
+ * @param prop
62
+ * @return {boolean}
63
+ */
57
64
  var hasProp = function hasProp(object, prop) {
58
65
  return object && object.hasOwnProperty(prop);
59
66
  };
@@ -74,7 +81,7 @@ var element = function element(tag, attrs, content) {
74
81
  }
75
82
  }).join(space);
76
83
  result.push([lt, tag, space, attributes, gt].join(''));
77
- if (content) {
84
+ if (content && hasClosedTag) {
78
85
  result.push(content instanceof Array ? content.join('') : content);
79
86
  }
80
87
  if (hasClosedTag) {