@adamlui/minify.js 1.2.1 → 1.2.2
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 +4 -2
- package/minify.js +38 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<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>
|
|
6
6
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-fcde7b.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.2.
|
|
7
|
+
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.2.2-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
8
8
|
<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"></a>
|
|
9
9
|
|
|
10
10
|
<img src="https://github.com/adamlui/js-utils/blob/main/minify.js/media/images/minify.js-docs-demo.png">
|
|
@@ -35,6 +35,8 @@ The basic **global command** is:
|
|
|
35
35
|
minifyjs
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
**💡 Note:** Pass `-n` or `--dry-run` to only see what files will be processed.
|
|
39
|
+
|
|
38
40
|
#
|
|
39
41
|
|
|
40
42
|
To specify **input/output** paths:
|
|
@@ -50,7 +52,7 @@ minifyjs [input_path] [output_path]
|
|
|
50
52
|
|
|
51
53
|
#
|
|
52
54
|
|
|
53
|
-
To use as a **package script**,
|
|
55
|
+
To use as a **package script**, in your project's `package.json`:
|
|
54
56
|
|
|
55
57
|
```json
|
|
56
58
|
"scripts": {
|
package/minify.js
CHANGED
|
@@ -24,11 +24,13 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
24
24
|
+ 'Path to file or directory where minified files will be stored,'
|
|
25
25
|
+ ' relative to original file location (if not provided, min/ is used).');
|
|
26
26
|
console.info('\nConfig options:');
|
|
27
|
+
printWrappedMsg(' -n, --dry-run Don\'t actually minify the file(s),'
|
|
28
|
+
+ ' just show if they will be processed.');
|
|
27
29
|
printWrappedMsg(' -dd, --include-dotfolders Include dotfolders in file search.');
|
|
28
30
|
printWrappedMsg(' -df, --include-dotfilles Include dotfiles in file search.');
|
|
29
31
|
console.info('\nInfo commands:');
|
|
30
|
-
printWrappedMsg('
|
|
31
|
-
printWrappedMsg('
|
|
32
|
+
printWrappedMsg(' -h, --help Display this help screen.');
|
|
33
|
+
printWrappedMsg(' -v, --version Show version number.');
|
|
32
34
|
|
|
33
35
|
// Show VERSION number if -v or --version passed
|
|
34
36
|
} else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
|
|
@@ -54,6 +56,7 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
54
56
|
|
|
55
57
|
// Load flag settings
|
|
56
58
|
const config = {
|
|
59
|
+
dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
|
|
57
60
|
includeDotFolders: process.argv.some(arg =>
|
|
58
61
|
/^--?(?:dd|(?:include-)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
|
|
59
62
|
includeDotFiles: process.argv.some(arg =>
|
|
@@ -76,34 +79,40 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
76
79
|
});
|
|
77
80
|
})(inputPath);
|
|
78
81
|
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
if (config.dryRun) { // print files to be processed
|
|
83
|
+
console.info('\nJS files to be minified:');
|
|
84
|
+
jsFiles.forEach(file => console.info(file));
|
|
85
|
+
|
|
86
|
+
} else { // actually minify JavaScript files
|
|
87
|
+
|
|
88
|
+
let minifiedCnt = 0;
|
|
89
|
+
console.log(''); // line break before first log
|
|
90
|
+
jsFiles.forEach(jsPath => {
|
|
91
|
+
console.info(`Minifying ${ jsPath }...`);
|
|
92
|
+
const outputDir = path.join(
|
|
93
|
+
path.dirname(jsPath), // path of file to be minified
|
|
94
|
+
/so?u?rce?$/.test(path.dirname(jsPath)) ? '../min' // + ../min/ if in *(src|source)/
|
|
95
|
+
: outputArg.endsWith('.js') ? path.dirname(outputArg) // or path from file output arg
|
|
96
|
+
: outputArg || 'min' // or path from folder output arg or min/ if no output arg passed
|
|
97
|
+
);
|
|
98
|
+
const outputFilename = (
|
|
99
|
+
outputArg.endsWith('.js') && inputArg.endsWith('.js')
|
|
100
|
+
? path.basename(outputArg).replace(/(\.min)?\.js$/, '')
|
|
101
|
+
: path.basename(jsPath, '.js')
|
|
102
|
+
) + '.min.js';
|
|
103
|
+
const outputPath = path.join(outputDir, outputFilename),
|
|
104
|
+
minifiedCode = uglifyJS.minify(fs.readFileSync(jsPath, 'utf8')).code;
|
|
105
|
+
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
106
|
+
fs.writeFileSync(outputPath, minifiedCode, 'utf8');
|
|
107
|
+
minifiedCnt++;
|
|
108
|
+
});
|
|
101
109
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
// Print final summary
|
|
111
|
+
if (minifiedCnt) {
|
|
112
|
+
console.info(`\n${bg}Minification complete!${nc}`);
|
|
113
|
+
console.info(`${ minifiedCnt } file${ minifiedCnt > 1 ? 's' : '' } minified.`);
|
|
114
|
+
} else console.info(`${by}No unminified JavaScript files found.${nc}`);
|
|
115
|
+
}
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
function printWrappedMsg(msg) { // truncates msg, indents 2nd+ lines
|