@node-minify/utils 6.0.0 → 6.4.0
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/LICENSE +1 -1
- package/lib/utils.js +81 -77
- package/package.json +4 -4
package/LICENSE
CHANGED
package/lib/utils.js
CHANGED
|
@@ -11,33 +11,33 @@ var _gzipSize = _interopRequireDefault(require("gzip-size"));
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
/*!
|
|
15
|
-
* node-minify
|
|
16
|
-
* Copyright(c) 2011-
|
|
17
|
-
* MIT Licensed
|
|
14
|
+
/*!
|
|
15
|
+
* node-minify
|
|
16
|
+
* Copyright(c) 2011-2022 Rodolphe Stoclin
|
|
17
|
+
* MIT Licensed
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* Module dependencies.
|
|
20
|
+
/**
|
|
21
|
+
* Module dependencies.
|
|
22
22
|
*/
|
|
23
23
|
const utils = {};
|
|
24
|
-
/**
|
|
25
|
-
* Read content from file.
|
|
26
|
-
*
|
|
27
|
-
* @param {String} file
|
|
28
|
-
* @returns {String}
|
|
24
|
+
/**
|
|
25
|
+
* Read content from file.
|
|
26
|
+
*
|
|
27
|
+
* @param {String} file
|
|
28
|
+
* @returns {String}
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
exports.utils = utils;
|
|
32
32
|
|
|
33
33
|
utils.readFile = file => _fs.default.readFileSync(file, 'utf8');
|
|
34
|
-
/**
|
|
35
|
-
* Write content into file.
|
|
36
|
-
*
|
|
37
|
-
* @param {String} file
|
|
38
|
-
* @param {String} content
|
|
39
|
-
* @param {Number} index - index of the file being processed
|
|
40
|
-
* @returns {String}
|
|
34
|
+
/**
|
|
35
|
+
* Write content into file.
|
|
36
|
+
*
|
|
37
|
+
* @param {String} file
|
|
38
|
+
* @param {String} content
|
|
39
|
+
* @param {Number} index - index of the file being processed
|
|
40
|
+
* @returns {String}
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
|
|
@@ -46,15 +46,19 @@ utils.writeFile = ({
|
|
|
46
46
|
content,
|
|
47
47
|
index
|
|
48
48
|
}) => {
|
|
49
|
-
|
|
49
|
+
const _file = index !== undefined ? file[index] : file;
|
|
50
|
+
|
|
51
|
+
if (!_fs.default.existsSync(_file) || _fs.default.existsSync(_file) && !_fs.default.lstatSync(_file).isDirectory()) {
|
|
52
|
+
_fs.default.writeFileSync(_file, content, 'utf8');
|
|
53
|
+
}
|
|
50
54
|
|
|
51
55
|
return content;
|
|
52
56
|
};
|
|
53
|
-
/**
|
|
54
|
-
* Builds arguments array based on an object.
|
|
55
|
-
*
|
|
56
|
-
* @param {Object} options
|
|
57
|
-
* @returns {Array}
|
|
57
|
+
/**
|
|
58
|
+
* Builds arguments array based on an object.
|
|
59
|
+
*
|
|
60
|
+
* @param {Object} options
|
|
61
|
+
* @returns {Array}
|
|
58
62
|
*/
|
|
59
63
|
|
|
60
64
|
|
|
@@ -71,19 +75,19 @@ utils.buildArgs = options => {
|
|
|
71
75
|
});
|
|
72
76
|
return args;
|
|
73
77
|
};
|
|
74
|
-
/**
|
|
75
|
-
* Clone an object.
|
|
76
|
-
*
|
|
77
|
-
* @param {Object} obj
|
|
78
|
-
* @returns {Object}
|
|
78
|
+
/**
|
|
79
|
+
* Clone an object.
|
|
80
|
+
*
|
|
81
|
+
* @param {Object} obj
|
|
82
|
+
* @returns {Object}
|
|
79
83
|
*/
|
|
80
84
|
|
|
81
85
|
|
|
82
86
|
utils.clone = obj => JSON.parse(JSON.stringify(obj));
|
|
83
|
-
/**
|
|
84
|
-
* Get the file size in bytes.
|
|
85
|
-
*
|
|
86
|
-
* @returns {String}
|
|
87
|
+
/**
|
|
88
|
+
* Get the file size in bytes.
|
|
89
|
+
*
|
|
90
|
+
* @returns {String}
|
|
87
91
|
*/
|
|
88
92
|
|
|
89
93
|
|
|
@@ -93,10 +97,10 @@ utils.getFilesizeInBytes = file => {
|
|
|
93
97
|
const fileSizeInBytes = stats.size;
|
|
94
98
|
return utils.prettyBytes(fileSizeInBytes);
|
|
95
99
|
};
|
|
96
|
-
/**
|
|
97
|
-
* Get the gzipped file size in bytes.
|
|
98
|
-
*
|
|
99
|
-
* @returns {Promise.<String>}
|
|
100
|
+
/**
|
|
101
|
+
* Get the gzipped file size in bytes.
|
|
102
|
+
*
|
|
103
|
+
* @returns {Promise.<String>}
|
|
100
104
|
*/
|
|
101
105
|
|
|
102
106
|
|
|
@@ -109,11 +113,11 @@ utils.getFilesizeGzippedInBytes = file => {
|
|
|
109
113
|
});
|
|
110
114
|
});
|
|
111
115
|
};
|
|
112
|
-
/**
|
|
113
|
-
* Get the size in human readable.
|
|
114
|
-
* From https://github.com/sindresorhus/pretty-bytes
|
|
115
|
-
*
|
|
116
|
-
* @returns {String}
|
|
116
|
+
/**
|
|
117
|
+
* Get the size in human readable.
|
|
118
|
+
* From https://github.com/sindresorhus/pretty-bytes
|
|
119
|
+
*
|
|
120
|
+
* @returns {String}
|
|
117
121
|
*/
|
|
118
122
|
|
|
119
123
|
|
|
@@ -139,15 +143,15 @@ utils.prettyBytes = num => {
|
|
|
139
143
|
const unit = UNITS[exponent];
|
|
140
144
|
return (neg ? '-' : '') + numStr + ' ' + unit;
|
|
141
145
|
};
|
|
142
|
-
/**
|
|
143
|
-
* Set the file name as minified.
|
|
144
|
-
* eg. file.js returns file.min.js
|
|
145
|
-
*
|
|
146
|
-
* @param {String} file
|
|
147
|
-
* @param {String} output
|
|
148
|
-
* @param {String} publicFolder
|
|
149
|
-
* @param {Boolean} replaceInPlace
|
|
150
|
-
* @returns {String}
|
|
146
|
+
/**
|
|
147
|
+
* Set the file name as minified.
|
|
148
|
+
* eg. file.js returns file.min.js
|
|
149
|
+
*
|
|
150
|
+
* @param {String} file
|
|
151
|
+
* @param {String} output
|
|
152
|
+
* @param {String} publicFolder
|
|
153
|
+
* @param {Boolean} replaceInPlace
|
|
154
|
+
* @returns {String}
|
|
151
155
|
*/
|
|
152
156
|
|
|
153
157
|
|
|
@@ -166,10 +170,10 @@ utils.setFileNameMin = (file, output, publicFolder, replaceInPlace) => {
|
|
|
166
170
|
|
|
167
171
|
return output.replace('$1', fileWithoutExtension);
|
|
168
172
|
};
|
|
169
|
-
/**
|
|
170
|
-
* Compress a single file.
|
|
171
|
-
*
|
|
172
|
-
* @param {Object} settings
|
|
173
|
+
/**
|
|
174
|
+
* Compress a single file.
|
|
175
|
+
*
|
|
176
|
+
* @param {Object} settings
|
|
173
177
|
*/
|
|
174
178
|
|
|
175
179
|
|
|
@@ -183,11 +187,11 @@ utils.compressSingleFile = settings => {
|
|
|
183
187
|
content
|
|
184
188
|
});
|
|
185
189
|
};
|
|
186
|
-
/**
|
|
187
|
-
* Concatenate all input files and get the data.
|
|
188
|
-
*
|
|
189
|
-
* @param {String|Array} input
|
|
190
|
-
* @return {String}
|
|
190
|
+
/**
|
|
191
|
+
* Concatenate all input files and get the data.
|
|
192
|
+
*
|
|
193
|
+
* @param {String|Array} input
|
|
194
|
+
* @return {String}
|
|
191
195
|
*/
|
|
192
196
|
|
|
193
197
|
|
|
@@ -196,15 +200,15 @@ utils.getContentFromFiles = input => {
|
|
|
196
200
|
return _fs.default.readFileSync(input, 'utf8');
|
|
197
201
|
}
|
|
198
202
|
|
|
199
|
-
return input.map(path => _fs.default.readFileSync(path, 'utf8')).join('\n');
|
|
203
|
+
return input.map(path => !_fs.default.existsSync(path) || _fs.default.existsSync(path) && !_fs.default.lstatSync(path).isDirectory() ? _fs.default.readFileSync(path, 'utf8') : '').join('\n');
|
|
200
204
|
};
|
|
201
|
-
/**
|
|
202
|
-
* Run compressor in sync.
|
|
203
|
-
*
|
|
204
|
-
* @param {Object} settings
|
|
205
|
-
* @param {String} content
|
|
206
|
-
* @param {Number} index - index of the file being processed
|
|
207
|
-
* @return {String}
|
|
205
|
+
/**
|
|
206
|
+
* Run compressor in sync.
|
|
207
|
+
*
|
|
208
|
+
* @param {Object} settings
|
|
209
|
+
* @param {String} content
|
|
210
|
+
* @param {Number} index - index of the file being processed
|
|
211
|
+
* @return {String}
|
|
208
212
|
*/
|
|
209
213
|
|
|
210
214
|
|
|
@@ -218,13 +222,13 @@ utils.runSync = ({
|
|
|
218
222
|
callback: null,
|
|
219
223
|
index
|
|
220
224
|
});
|
|
221
|
-
/**
|
|
222
|
-
* Run compressor in async.
|
|
223
|
-
*
|
|
224
|
-
* @param {Object} settings
|
|
225
|
-
* @param {String} content
|
|
226
|
-
* @param {Number} index - index of the file being processed
|
|
227
|
-
* @return {Promise}
|
|
225
|
+
/**
|
|
226
|
+
* Run compressor in async.
|
|
227
|
+
*
|
|
228
|
+
* @param {Object} settings
|
|
229
|
+
* @param {String} content
|
|
230
|
+
* @param {Number} index - index of the file being processed
|
|
231
|
+
* @return {Promise}
|
|
228
232
|
*/
|
|
229
233
|
|
|
230
234
|
|
|
@@ -248,6 +252,6 @@ utils.runAsync = ({
|
|
|
248
252
|
});
|
|
249
253
|
});
|
|
250
254
|
};
|
|
251
|
-
/**
|
|
252
|
-
* Expose `utils`.
|
|
255
|
+
/**
|
|
256
|
+
* Expose `utils`.
|
|
253
257
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "utils for @node-minify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compressor",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "lib/utils.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=12.0.0"
|
|
16
16
|
},
|
|
17
17
|
"directories": {
|
|
18
18
|
"lib": "lib",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"url": "https://github.com/srod/node-minify/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"gzip-size": "
|
|
35
|
+
"gzip-size": "6.0.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "d529747a661487597e9be510d3d9e2df1bc0f556"
|
|
38
38
|
}
|