@adamlui/minify.js 1.4.6 → 1.4.7

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 -3
  2. package/minify.js +19 -24
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  <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&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
23
23
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
- <a href="https://github.com/adamlui/js-utils/releases/tag/minify.js-1.4.6"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.6-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
+ <a href="https://github.com/adamlui/js-utils/releases/tag/minify.js-1.4.7"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.7-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
25
25
  <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>
26
26
  <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>
27
27
 
@@ -218,8 +218,9 @@ console.log(searchResults);
218
218
 
219
219
  /* sample output:
220
220
 
221
- Searching for unminified JS files...
222
- Search complete. 2 files found.
221
+ findJS() » Searching for unminified JS files...
222
+ findJS() » Search complete! 2 files found.
223
+ findJS() » Check returned array.
223
224
  [
224
225
  'E:\\js\\utils\\minify.js\\assets\\js\\foo.js',
225
226
  'E:\\js\\utils\\minify.js\\assets\\js\\bar.js'
package/minify.js CHANGED
@@ -14,25 +14,23 @@ function findJS(searchDir, options = {}) {
14
14
  options = { ...defaultOptions, ...options };
15
15
 
16
16
  // Validate searchDir
17
- if (!searchDir) return console.error(
18
- 'findJS() » ERROR: Please supply a `searchDir` as 1st arg.');
19
- else if (typeof searchDir !== 'string') return console.error(
20
- 'findJS() » ERROR: 1st arg `searchDir` must be a string.');
17
+ if (typeof searchDir !== 'string') return console.error(
18
+ 'findJS() » ERROR: 1st arg <searchDir> must be a string.');
21
19
  else { // verify searchDir path existence
22
20
  const searchPath = path.resolve(process.cwd(), searchDir);
23
21
  if (!fs.existsSync(searchPath)) return console.error(
24
- 'findJS() » ERROR: Arg `searchDir` must be an existing directory.'
25
- + `\n'${ searchPath }' does not exist.`);
22
+ 'findJS() » ERROR: 1st arg <searchDir> must be an existing directory.\n'
23
+ + `findJS() » ${ searchPath } does not exist.`);
26
24
  }
27
25
 
28
26
  // Validate options
29
27
  for (const key of Object.keys(options)) {
30
28
  if (!Object.prototype.hasOwnProperty.call(defaultOptions, key))
31
29
  if (key !== 'isRecursing') return console.error(
32
- `findJS() » ERROR: \`${ key }\` is an invalid option.`
33
- + `\nfindJS() » Valid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
30
+ `findJS() » ERROR: \`${ key }\` is an invalid option.\n`
31
+ + `findJS() » Valid options: [ ${ Object.keys(defaultOptions).join(', ') } ]`);
34
32
  else if (typeof options[key] !== 'boolean') return console.error(
35
- `findJS() » ERROR: \`${ key }\` option must be set to \`true\` or \`false\`.`);
33
+ `findJS() » ERROR: \`${ key }\` option can only be set to \`true\` or \`false\`.`);
36
34
  }
37
35
 
38
36
  // Search for unminified JS
@@ -51,12 +49,11 @@ function findJS(searchDir, options = {}) {
51
49
  });
52
50
 
53
51
  // Log/return final result
54
- if (!options.isRecursing && options.verbose) {
55
- console.info('findJS() » Search complete. '
56
- + ( jsFiles.length === 0 ? 'No' : jsFiles.length )
57
- + ` file${ jsFiles.length > 1 ? 's' : '' } found.`
58
- + ( findJS.caller.name !== 'minify' ? '\nfindJS() » Check returned object.' : '' ));
59
- }
52
+ if (!options.isRecursing && options.verbose) console.info(
53
+ 'findJS() » Search complete! ' + ( jsFiles.length === 0 ? 'No' : jsFiles.length )
54
+ + ` file${ jsFiles.length > 1 ? 's' : '' } found.`
55
+ + ( findJS.caller.name !== 'minify' && require.main !== module ?
56
+ '\nfindJS() » Check returned array.' : '' ));
60
57
  return options.isRecursing || jsFiles.length > 0 ? jsFiles : [];
61
58
  }
62
59
 
@@ -69,15 +66,15 @@ function minify(input, options = {}) {
69
66
 
70
67
  // Validate input
71
68
  if (typeof input !== 'string') return console.error(
72
- 'minify() » ERROR: Arg `input` must be a string.');
69
+ 'minify() » ERROR: 1st arg <input> must be a string.');
73
70
 
74
71
  // Validate options
75
72
  for (const key of Object.keys(options)) {
76
73
  if (!Object.prototype.hasOwnProperty.call(defaultOptions, key)) return console.error(
77
- `minify() » ERROR: \`${ key }\` is an invalid option.`
78
- + `\nminify() » Valid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
74
+ `minify() » ERROR: \`${ key }\` is an invalid option.\n`
75
+ + `minify() » Valid options: [ ${ Object.keys(defaultOptions).join(', ') } ]`);
79
76
  else if (typeof options[key] !== 'boolean') return console.error(
80
- `minify() » ERROR: \`${ key }\` option must be set to \`true\` or \`false\`.`);
77
+ `minify() » ERROR: \`${ key }\` option can only be set to \`true\` or \`false\`.`);
81
78
  }
82
79
 
83
80
  // Minify JS based on input
@@ -87,7 +84,6 @@ function minify(input, options = {}) {
87
84
  if (options.verbose) console.info(`minify() » Minifying ${ input }...`);
88
85
  const minifyResult = uglifyJS.minify(fs.readFileSync(input, 'utf8'), minifyOptions);
89
86
  if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
90
- else console.info('minify() » Minification complete! Check returned object.');
91
87
  return { code: minifyResult.code, srcPath: path.resolve(process.cwd(), input),
92
88
  error: minifyResult.error };
93
89
  } else { // dir path passed
@@ -98,7 +94,6 @@ function minify(input, options = {}) {
98
94
  const srcCode = fs.readFileSync(jsPath, 'utf8'),
99
95
  minifyResult = uglifyJS.minify(srcCode, minifyOptions);
100
96
  if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
101
- else console.info('minify() » Minification complete! Check returned object.');
102
97
  return { code: minifyResult.code, srcPath: jsPath, error: minifyResult.error };
103
98
  }).filter(data => !data.error); // filter out failed minifications
104
99
  }
@@ -106,7 +101,7 @@ function minify(input, options = {}) {
106
101
  if (options.verbose) console.info('minify() » Minifying passed source code...');
107
102
  const minifyResult = uglifyJS.minify(input, minifyOptions);
108
103
  if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
109
- else console.info('minify() » Minification complete! Check returned object.');
104
+
110
105
  return { code: minifyResult.code, srcPath: undefined, error: minifyResult.error };
111
106
  }
112
107
  }
@@ -164,8 +159,8 @@ else { // run as CLI utility
164
159
  // Validate input arg (output arg can be anything)
165
160
  const inputPath = path.resolve(process.cwd(), inputArg);
166
161
  if (inputArg && !fs.existsSync(inputPath)) {
167
- console.error(`\n${br}Error: First argument must be an existing file or directory.`
168
- + `\n'${ inputPath }' does not exist.${nc}`
162
+ console.error(`\n${br}Error: First argument can only be an existing file or directory.`
163
+ + `\n${ inputPath } does not exist.${nc}`
169
164
  + `\n\n${bg}Example valid command: \n>> minify-js . output.min.js${nc}`
170
165
  + `\n\n${by}For all command options: \n>> minify-js --help${nc}`);
171
166
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",