@adamlui/minify.js 1.4.5 → 1.4.6

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 CHANGED
@@ -10,7 +10,8 @@
10
10
  <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/hi#readme">हिंदी</a> |
11
11
  <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/bn#readme">বাংলা</a> |
12
12
  <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/mr#readme">मराठी</a> |
13
- <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/pa#readme">ਪੰਜਾਬੀ</a>
13
+ <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/pa#readme">ਪੰਜਾਬੀ</a> |
14
+ <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/de#readme">Deutsch</a>
14
15
  </h6>
15
16
  </div>
16
17
 
@@ -20,7 +21,7 @@
20
21
 
21
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>
22
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>
23
- <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.5-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.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
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>
25
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>
26
27
 
@@ -211,15 +212,18 @@ Searches for all unminified JavaScript files within the `searchDir` string passe
211
212
  Options are boolean, passed as object properties. For example:
212
213
 
213
214
  ```js
214
- // Search for unminified JS files in exactly `assets/js`:
215
+ // Search for unminified JS files in exactly assets/js:
215
216
  const searchResults = minifyJS.findJS('assets/js', { recursive: false });
216
217
  console.log(searchResults);
217
218
 
218
- /* outputs:
219
+ /* sample output:
220
+
219
221
  Searching for unminified JS files...
220
222
  Search complete. 2 files found.
221
- [ 'E:\\js\\utils\\minify.js\\assets\\js\\foo.js',
222
- 'E:\\js\\utils\\minify.js\\assets\\js\\bar.js' ]
223
+ [
224
+ 'E:\\js\\utils\\minify.js\\assets\\js\\foo.js',
225
+ 'E:\\js\\utils\\minify.js\\assets\\js\\bar.js'
226
+ ]
223
227
  */
224
228
  ```
225
229
 
package/docs/LICENSE.md CHANGED
@@ -10,7 +10,8 @@
10
10
  <a href="hi/LICENSE.md">हिंदी</a> |
11
11
  <a href="bn/LICENSE.md">বাংলা</a> |
12
12
  <a href="mr/LICENSE.md">मराठी</a> |
13
- <a href="pa/LICENSE.md">ਪੰਜਾਬੀ</a>
13
+ <a href="pa/LICENSE.md">ਪੰਜਾਬੀ</a> |
14
+ <a href="de/LICENSE.md">Deutsch</a>
14
15
  </h6>
15
16
  </div>
16
17
 
package/docs/SECURITY.md CHANGED
@@ -10,7 +10,8 @@
10
10
  <a href="hi/SECURITY.md">हिंदी</a> |
11
11
  <a href="bn/SECURITY.md">বাংলা</a> |
12
12
  <a href="mr/SECURITY.md">मराठी</a> |
13
- <a href="pa/SECURITY.md">ਪੰਜਾਬੀ</a>
13
+ <a href="pa/SECURITY.md">ਪੰਜਾਬੀ</a> |
14
+ <a href="de/SECURITY.md">Deutsch</a>
14
15
  </h6>
15
16
  </div>
16
17
 
package/minify.js CHANGED
@@ -15,13 +15,13 @@ function findJS(searchDir, options = {}) {
15
15
 
16
16
  // Validate searchDir
17
17
  if (!searchDir) return console.error(
18
- 'findJS() error: Please supply a `searchDir` arg.');
18
+ 'findJS() » ERROR: Please supply a `searchDir` as 1st arg.');
19
19
  else if (typeof searchDir !== 'string') return console.error(
20
- 'findJS() error: Arg `searchDir` must be a string.');
20
+ 'findJS() » ERROR: 1st arg `searchDir` must be a string.');
21
21
  else { // verify searchDir path existence
22
22
  const searchPath = path.resolve(process.cwd(), searchDir);
23
23
  if (!fs.existsSync(searchPath)) return console.error(
24
- 'findJS() error: Arg `searchDir` must be an existing directory.'
24
+ 'findJS() » ERROR: Arg `searchDir` must be an existing directory.'
25
25
  + `\n'${ searchPath }' does not exist.`);
26
26
  }
27
27
 
@@ -29,15 +29,16 @@ function findJS(searchDir, options = {}) {
29
29
  for (const key of Object.keys(options)) {
30
30
  if (!Object.prototype.hasOwnProperty.call(defaultOptions, key))
31
31
  if (key !== 'isRecursing') return console.error(
32
- `findJS() error: \`${ key }\` is an invalid option.`
33
- + `\nValid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
32
+ `findJS() » ERROR: \`${ key }\` is an invalid option.`
33
+ + `\nfindJS() » Valid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
34
34
  else if (typeof options[key] !== 'boolean') return console.error(
35
- `findJS() error: \`${ key }\` option must be set to \`true\` or \`false\`.`);
35
+ `findJS() » ERROR: \`${ key }\` option must be set to \`true\` or \`false\`.`);
36
36
  }
37
37
 
38
38
  // Search for unminified JS
39
39
  const dirFiles = fs.readdirSync(searchDir), jsFiles = [];
40
- if (options.verbose && !options.isRecursing) console.info('\nSearching for unminified JS files...');
40
+ if (options.verbose && !options.isRecursing) console.info(
41
+ '\nfindJS() » Searching for unminified JS files...');
41
42
  dirFiles.forEach(file => {
42
43
  const filePath = path.resolve(searchDir, file);
43
44
  if (fs.statSync(filePath).isDirectory() && file != 'node_modules'
@@ -51,9 +52,10 @@ function findJS(searchDir, options = {}) {
51
52
 
52
53
  // Log/return final result
53
54
  if (!options.isRecursing && options.verbose) {
54
- console.info('Search complete. '
55
+ console.info('findJS() » Search complete. '
55
56
  + ( jsFiles.length === 0 ? 'No' : jsFiles.length )
56
- + ` file${ jsFiles.length > 1 ? 's' : '' } found.`);
57
+ + ` file${ jsFiles.length > 1 ? 's' : '' } found.`
58
+ + ( findJS.caller.name !== 'minify' ? '\nfindJS() » Check returned object.' : '' ));
57
59
  }
58
60
  return options.isRecursing || jsFiles.length > 0 ? jsFiles : [];
59
61
  }
@@ -67,41 +69,44 @@ function minify(input, options = {}) {
67
69
 
68
70
  // Validate input
69
71
  if (typeof input !== 'string') return console.error(
70
- 'minify() error: Arg `inputPath` must be a string.');
72
+ 'minify() » ERROR: Arg `input` must be a string.');
71
73
 
72
74
  // Validate options
73
75
  for (const key of Object.keys(options)) {
74
76
  if (!Object.prototype.hasOwnProperty.call(defaultOptions, key)) return console.error(
75
- `findJS() error: \`${ key }\` is an invalid option.`
76
- + `\nValid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
77
+ `minify() » ERROR: \`${ key }\` is an invalid option.`
78
+ + `\nminify() » Valid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
77
79
  else if (typeof options[key] !== 'boolean') return console.error(
78
- `findJS() error: \`${ key }\` option must be set to \`true\` or \`false\`.`);
80
+ `minify() » ERROR: \`${ key }\` option must be set to \`true\` or \`false\`.`);
79
81
  }
80
82
 
81
83
  // Minify JS based on input
82
84
  const minifyOptions = { mangle: options.mangle ? { toplevel: true } : false };
83
85
  if (fs.existsSync(input)) { // minify based on path arg
84
86
  if (input.endsWith('.js')) { // file path passed
85
- if (options.verbose) console.info(`Minifying ${ input }...`);
87
+ if (options.verbose) console.info(`minify() » Minifying ${ input }...`);
86
88
  const minifyResult = uglifyJS.minify(fs.readFileSync(input, 'utf8'), minifyOptions);
87
- if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
89
+ if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
90
+ else console.info('minify() » Minification complete! Check returned object.');
88
91
  return { code: minifyResult.code, srcPath: path.resolve(process.cwd(), input),
89
92
  error: minifyResult.error };
90
93
  } else { // dir path passed
91
94
  return findJS(input, { recursive: options.recursive, verbose: options.verbose,
92
95
  dotFolders: options.dotFolders, dotFiles: options.dotFiles
93
96
  })?.map(jsPath => { // minify found JS files
94
- if (options.verbose) console.info(`Minifying ${ jsPath }...`);
97
+ if (options.verbose) console.info(`minify() » Minifying ${ jsPath }...`);
95
98
  const srcCode = fs.readFileSync(jsPath, 'utf8'),
96
99
  minifyResult = uglifyJS.minify(srcCode, minifyOptions);
97
- if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
100
+ if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
101
+ else console.info('minify() » Minification complete! Check returned object.');
98
102
  return { code: minifyResult.code, srcPath: jsPath, error: minifyResult.error };
99
103
  }).filter(data => !data.error); // filter out failed minifications
100
104
  }
101
105
  } else { // minify based on src code arg
102
- if (options.verbose) console.info('Minifying passed source code...');
106
+ if (options.verbose) console.info('minify() » Minifying passed source code...');
103
107
  const minifyResult = uglifyJS.minify(input, minifyOptions);
104
- if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
108
+ if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
109
+ else console.info('minify() » Minification complete! Check returned object.');
105
110
  return { code: minifyResult.code, srcPath: undefined, error: minifyResult.error };
106
111
  }
107
112
  }
@@ -123,7 +128,7 @@ else { // run as CLI utility
123
128
  'dryRun': /^--?(?:n|dry-?run)$/,
124
129
  'includeDotFolders': /^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?=?(?:true|1)?)$/,
125
130
  'includeDotFiles': /^--?(?:df|D|(?:include-?)?dot-?files?=?(?:true|1)?)$/,
126
- 'noRecursion': /^--?(?:R|(?:disable|no)-?recursion|recursion=(?:false|0))$/,
131
+ 'noRecursion': /^--?(?:R|(?:disable|no)-?recursi(?:on|ve)|recursi(?:on|ve)=(?:false|0))$/,
127
132
  'noMangle': /^--?(?:M|(?:disable|no)-?mangle|mangle=(?:false|0))$/,
128
133
  'quietMode': /^--?q(?:uiet)?(?:-?mode)?$/,
129
134
  'help': /^--?h(?:elp)?$/,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",