@node-minify/utils 6.1.0 → 7.0.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 +84 -75
- 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
|
|
|
@@ -54,11 +54,20 @@ utils.writeFile = ({
|
|
|
54
54
|
|
|
55
55
|
return content;
|
|
56
56
|
};
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @param {
|
|
61
|
-
* @returns {
|
|
57
|
+
/**
|
|
58
|
+
* Delete file.
|
|
59
|
+
*
|
|
60
|
+
* @param {String} file
|
|
61
|
+
* @returns {String}
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
utils.deleteFile = file => _fs.default.unlinkSync(file);
|
|
66
|
+
/**
|
|
67
|
+
* Builds arguments array based on an object.
|
|
68
|
+
*
|
|
69
|
+
* @param {Object} options
|
|
70
|
+
* @returns {Array}
|
|
62
71
|
*/
|
|
63
72
|
|
|
64
73
|
|
|
@@ -75,19 +84,19 @@ utils.buildArgs = options => {
|
|
|
75
84
|
});
|
|
76
85
|
return args;
|
|
77
86
|
};
|
|
78
|
-
/**
|
|
79
|
-
* Clone an object.
|
|
80
|
-
*
|
|
81
|
-
* @param {Object} obj
|
|
82
|
-
* @returns {Object}
|
|
87
|
+
/**
|
|
88
|
+
* Clone an object.
|
|
89
|
+
*
|
|
90
|
+
* @param {Object} obj
|
|
91
|
+
* @returns {Object}
|
|
83
92
|
*/
|
|
84
93
|
|
|
85
94
|
|
|
86
95
|
utils.clone = obj => JSON.parse(JSON.stringify(obj));
|
|
87
|
-
/**
|
|
88
|
-
* Get the file size in bytes.
|
|
89
|
-
*
|
|
90
|
-
* @returns {String}
|
|
96
|
+
/**
|
|
97
|
+
* Get the file size in bytes.
|
|
98
|
+
*
|
|
99
|
+
* @returns {String}
|
|
91
100
|
*/
|
|
92
101
|
|
|
93
102
|
|
|
@@ -97,10 +106,10 @@ utils.getFilesizeInBytes = file => {
|
|
|
97
106
|
const fileSizeInBytes = stats.size;
|
|
98
107
|
return utils.prettyBytes(fileSizeInBytes);
|
|
99
108
|
};
|
|
100
|
-
/**
|
|
101
|
-
* Get the gzipped file size in bytes.
|
|
102
|
-
*
|
|
103
|
-
* @returns {Promise.<String>}
|
|
109
|
+
/**
|
|
110
|
+
* Get the gzipped file size in bytes.
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise.<String>}
|
|
104
113
|
*/
|
|
105
114
|
|
|
106
115
|
|
|
@@ -113,11 +122,11 @@ utils.getFilesizeGzippedInBytes = file => {
|
|
|
113
122
|
});
|
|
114
123
|
});
|
|
115
124
|
};
|
|
116
|
-
/**
|
|
117
|
-
* Get the size in human readable.
|
|
118
|
-
* From https://github.com/sindresorhus/pretty-bytes
|
|
119
|
-
*
|
|
120
|
-
* @returns {String}
|
|
125
|
+
/**
|
|
126
|
+
* Get the size in human readable.
|
|
127
|
+
* From https://github.com/sindresorhus/pretty-bytes
|
|
128
|
+
*
|
|
129
|
+
* @returns {String}
|
|
121
130
|
*/
|
|
122
131
|
|
|
123
132
|
|
|
@@ -143,15 +152,15 @@ utils.prettyBytes = num => {
|
|
|
143
152
|
const unit = UNITS[exponent];
|
|
144
153
|
return (neg ? '-' : '') + numStr + ' ' + unit;
|
|
145
154
|
};
|
|
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}
|
|
155
|
+
/**
|
|
156
|
+
* Set the file name as minified.
|
|
157
|
+
* eg. file.js returns file.min.js
|
|
158
|
+
*
|
|
159
|
+
* @param {String} file
|
|
160
|
+
* @param {String} output
|
|
161
|
+
* @param {String} publicFolder
|
|
162
|
+
* @param {Boolean} replaceInPlace
|
|
163
|
+
* @returns {String}
|
|
155
164
|
*/
|
|
156
165
|
|
|
157
166
|
|
|
@@ -170,10 +179,10 @@ utils.setFileNameMin = (file, output, publicFolder, replaceInPlace) => {
|
|
|
170
179
|
|
|
171
180
|
return output.replace('$1', fileWithoutExtension);
|
|
172
181
|
};
|
|
173
|
-
/**
|
|
174
|
-
* Compress a single file.
|
|
175
|
-
*
|
|
176
|
-
* @param {Object} settings
|
|
182
|
+
/**
|
|
183
|
+
* Compress a single file.
|
|
184
|
+
*
|
|
185
|
+
* @param {Object} settings
|
|
177
186
|
*/
|
|
178
187
|
|
|
179
188
|
|
|
@@ -187,11 +196,11 @@ utils.compressSingleFile = settings => {
|
|
|
187
196
|
content
|
|
188
197
|
});
|
|
189
198
|
};
|
|
190
|
-
/**
|
|
191
|
-
* Concatenate all input files and get the data.
|
|
192
|
-
*
|
|
193
|
-
* @param {String|Array} input
|
|
194
|
-
* @return {String}
|
|
199
|
+
/**
|
|
200
|
+
* Concatenate all input files and get the data.
|
|
201
|
+
*
|
|
202
|
+
* @param {String|Array} input
|
|
203
|
+
* @return {String}
|
|
195
204
|
*/
|
|
196
205
|
|
|
197
206
|
|
|
@@ -202,13 +211,13 @@ utils.getContentFromFiles = input => {
|
|
|
202
211
|
|
|
203
212
|
return input.map(path => !_fs.default.existsSync(path) || _fs.default.existsSync(path) && !_fs.default.lstatSync(path).isDirectory() ? _fs.default.readFileSync(path, 'utf8') : '').join('\n');
|
|
204
213
|
};
|
|
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}
|
|
214
|
+
/**
|
|
215
|
+
* Run compressor in sync.
|
|
216
|
+
*
|
|
217
|
+
* @param {Object} settings
|
|
218
|
+
* @param {String} content
|
|
219
|
+
* @param {Number} index - index of the file being processed
|
|
220
|
+
* @return {String}
|
|
212
221
|
*/
|
|
213
222
|
|
|
214
223
|
|
|
@@ -222,13 +231,13 @@ utils.runSync = ({
|
|
|
222
231
|
callback: null,
|
|
223
232
|
index
|
|
224
233
|
});
|
|
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}
|
|
234
|
+
/**
|
|
235
|
+
* Run compressor in async.
|
|
236
|
+
*
|
|
237
|
+
* @param {Object} settings
|
|
238
|
+
* @param {String} content
|
|
239
|
+
* @param {Number} index - index of the file being processed
|
|
240
|
+
* @return {Promise}
|
|
232
241
|
*/
|
|
233
242
|
|
|
234
243
|
|
|
@@ -252,6 +261,6 @@ utils.runAsync = ({
|
|
|
252
261
|
});
|
|
253
262
|
});
|
|
254
263
|
};
|
|
255
|
-
/**
|
|
256
|
-
* Expose `utils`.
|
|
264
|
+
/**
|
|
265
|
+
* Expose `utils`.
|
|
257
266
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.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": ">=14.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": "8b5bda6f1ac9fe7180006f2a19ec3253e8fff4ec"
|
|
38
38
|
}
|