@adamlui/minify.js 1.4.0 → 1.4.1
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/README.md +5 -3
- package/minify.js +9 -11
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fminify.js?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
21
21
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-red.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
22
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.
|
|
22
|
+
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.1-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
23
23
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fminify.js?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
24
24
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:minify.js/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Aminify.js%2Fminify.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
25
25
|
|
|
@@ -179,7 +179,8 @@ minifyJS.minify(input, { dotFiles: true });
|
|
|
179
179
|
Possible parameters (and their default settings) are:
|
|
180
180
|
|
|
181
181
|
```
|
|
182
|
-
recursive (true) Recursively search for nested files if dir path
|
|
182
|
+
recursive (true) Recursively search for nested files if dir path
|
|
183
|
+
passed.
|
|
183
184
|
verbose (true) Show logging in console/terminal.
|
|
184
185
|
dotFolders (false) Include dotfolders in file search.
|
|
185
186
|
dotFiles (false) Include dotfiles in file search.
|
|
@@ -200,7 +201,8 @@ minifyJS.findJS(searchDir, { recursive: false });
|
|
|
200
201
|
Possible parameters (and their default settings) are:
|
|
201
202
|
|
|
202
203
|
```
|
|
203
|
-
recursive (true) Recursively search for nested files if dir path
|
|
204
|
+
recursive (true) Recursively search for nested files if dir path
|
|
205
|
+
passed.
|
|
204
206
|
verbose (false) Show logging in console/terminal.
|
|
205
207
|
dotFolders (false) Include dotfolders in file search.
|
|
206
208
|
dotFiles (false) Include dotfiles in file search.
|
package/minify.js
CHANGED
|
@@ -17,12 +17,13 @@ function findJS(searchDir, options = {}) {
|
|
|
17
17
|
(options.dotFolders || !file.startsWith('.')) && options.recursive) {
|
|
18
18
|
if (options.verbose) console.info(`Searching for unminified JS files in: ${filePath}...`);
|
|
19
19
|
jsFiles.push( // recursively find unminified JS in eligible dir
|
|
20
|
-
...findJS(filePath));
|
|
20
|
+
...findJS(filePath, { ...options, isRecursing: true }));
|
|
21
21
|
} else if (/\.js(?<!\.min\.js)$/.test(file) &&
|
|
22
22
|
(options.dotFiles || !file.startsWith('.')))
|
|
23
23
|
jsFiles.push(filePath); // store eligible unminified JS file for minification
|
|
24
24
|
});
|
|
25
|
-
return jsFiles;
|
|
25
|
+
if (options.isRecursing || jsFiles.length > 0) return jsFiles;
|
|
26
|
+
else console.info('\nNo unminified JavaScript files found.');
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function minify(input, options = {}) {
|
|
@@ -42,7 +43,7 @@ function minify(input, options = {}) {
|
|
|
42
43
|
} else { // dir path passed
|
|
43
44
|
return findJS(input, { recursive: options.recursive,
|
|
44
45
|
dotFolders: options.dotFolders, dotFiles: options.dotFiles })
|
|
45
|
-
|
|
46
|
+
?.map(jsPath => { // minify found JS files
|
|
46
47
|
if (options.verbose) console.info(`Minifying ${ jsPath }...`);
|
|
47
48
|
const srcCode = fs.readFileSync(jsPath, 'utf8'),
|
|
48
49
|
minifyResult = uglifyJS.minify(srcCode, minifyOptions);
|
|
@@ -132,26 +133,23 @@ else { // run as CLI tool
|
|
|
132
133
|
const unminnedJSfiles = inputArg.endsWith('.js') ? [inputPath]
|
|
133
134
|
: findJS(inputPath, { recursive: !config.noRecursion });
|
|
134
135
|
|
|
135
|
-
if (unminnedJSfiles
|
|
136
|
-
printIfNotQuiet(`\n${by}No unminified JavaScript files found.${nc}`);
|
|
137
|
-
|
|
138
|
-
} else if (config.dryRun) { // print files to be processed
|
|
136
|
+
if (config.dryRun && unminnedJSfiles?.length > 0) { // print files to be processed
|
|
139
137
|
console.info(`\n${by}JS files to be minified:${nc}`);
|
|
140
|
-
unminnedJSfiles
|
|
138
|
+
unminnedJSfiles?.forEach(file => console.info(file));
|
|
141
139
|
|
|
142
140
|
} else { // actually minify JavaScript files
|
|
143
141
|
printIfNotQuiet(''); // line break before first log
|
|
144
142
|
|
|
145
143
|
// Build array of minification data
|
|
146
144
|
const failedPaths = [];
|
|
147
|
-
const minifyData = unminnedJSfiles
|
|
145
|
+
const minifyData = unminnedJSfiles?.map(jsPath => {
|
|
148
146
|
const minifyResult = minify(jsPath, { verbose: !config.quietMode, mangle: !config.noMangle });
|
|
149
147
|
if (minifyResult.error) failedPaths.push(jsPath);
|
|
150
148
|
return minifyResult;
|
|
151
149
|
}).filter(minifyResult => !minifyResult.error); // filter out failed minifications
|
|
152
150
|
|
|
153
151
|
// Write array data to files
|
|
154
|
-
minifyData
|
|
152
|
+
minifyData?.forEach(({ code, srcPath }) => {
|
|
155
153
|
const outputDir = path.join(
|
|
156
154
|
path.dirname(srcPath), // path of file to be minified
|
|
157
155
|
/so?u?rce?$/.test(path.dirname(srcPath)) ? '../min' // + ../min/ if in *(src|source)/
|
|
@@ -169,7 +167,7 @@ else { // run as CLI tool
|
|
|
169
167
|
});
|
|
170
168
|
|
|
171
169
|
// Print final summary
|
|
172
|
-
if (minifyData
|
|
170
|
+
if (minifyData?.length > 0) {
|
|
173
171
|
printIfNotQuiet(`\n${bg}Minification complete!${nc}`);
|
|
174
172
|
printIfNotQuiet(
|
|
175
173
|
`${ minifyData.length } file${ minifyData.length > 1 ? 's' : '' } minified.`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/minify.js",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Recursively minify all JavaScript files",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -29,11 +29,13 @@
|
|
|
29
29
|
},
|
|
30
30
|
"keywords": [
|
|
31
31
|
"javascript",
|
|
32
|
-
"js",
|
|
33
|
-
"js-utils",
|
|
34
|
-
"utils",
|
|
35
32
|
"utilities",
|
|
36
|
-
"
|
|
33
|
+
"js-utils",
|
|
34
|
+
"minifier",
|
|
35
|
+
"api",
|
|
36
|
+
"js",
|
|
37
|
+
"cli",
|
|
38
|
+
"utils"
|
|
37
39
|
],
|
|
38
40
|
"bugs": {
|
|
39
41
|
"url": "https://github.com/adamlui/js-utils/issues"
|