@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.
Files changed (3) hide show
  1. package/README.md +4 -2
  2. package/minify.js +38 -29
  3. 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.1-fc7811.svg?logo=icinga&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.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**, edit your project's `package.json` like this:
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(' -h, --help Display this help screen.');
31
- printWrappedMsg(' -v, --version Show version number.');
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
- // Minify JavaScript files
80
- let minifiedCnt = 0;
81
- console.log(''); // line break before first log
82
- jsFiles.forEach(jsPath => {
83
- console.info(`Minifying ${ jsPath }...`);
84
- const outputDir = path.join(
85
- path.dirname(jsPath), // path of file to be minified
86
- /so?u?rce?$/.test(path.dirname(jsPath)) ? '../min' // + ../min/ if in *(src|source)/
87
- : outputArg.endsWith('.js') ? path.dirname(outputArg) // or path from file output arg
88
- : outputArg || 'min' // or path from folder output arg or min/ if no output arg passed
89
- );
90
- const outputFilename = (
91
- outputArg.endsWith('.js') && inputArg.endsWith('.js')
92
- ? path.basename(outputArg).replace(/(\.min)?\.js$/, '')
93
- : path.basename(jsPath, '.js')
94
- ) + '.min.js';
95
- const outputPath = path.join(outputDir, outputFilename),
96
- minifiedCode = uglifyJS.minify(fs.readFileSync(jsPath, 'utf8')).code;
97
- if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
98
- fs.writeFileSync(outputPath, minifiedCode, 'utf8');
99
- minifiedCnt++;
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
- // Print final summary
103
- if (minifiedCnt) {
104
- console.info(`\n${bg}Minification complete!${nc}`);
105
- console.info(`${ minifiedCnt } file${ minifiedCnt > 1 ? 's' : '' } minified.`);
106
- } else console.info(`${by}No unminified JavaScript files found.${nc}`);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",