@adamlui/minify.js 1.4.5 → 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.
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.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>
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,19 @@ 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
- Searching for unminified JS files...
220
- 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' ]
219
+ /* sample output:
220
+
221
+ findJS() » Searching for unminified JS files...
222
+ findJS() » Search complete! 2 files found.
223
+ findJS() » Check returned array.
224
+ [
225
+ 'E:\\js\\utils\\minify.js\\assets\\js\\foo.js',
226
+ 'E:\\js\\utils\\minify.js\\assets\\js\\bar.js'
227
+ ]
223
228
  */
224
229
  ```
225
230
 
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
@@ -14,30 +14,29 @@ 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` arg.');
19
- else if (typeof searchDir !== 'string') return console.error(
20
- 'findJS() error: 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
- + `\nValid 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
39
37
  const dirFiles = fs.readdirSync(searchDir), jsFiles = [];
40
- if (options.verbose && !options.isRecursing) console.info('\nSearching for unminified JS files...');
38
+ if (options.verbose && !options.isRecursing) console.info(
39
+ '\nfindJS() » Searching for unminified JS files...');
41
40
  dirFiles.forEach(file => {
42
41
  const filePath = path.resolve(searchDir, file);
43
42
  if (fs.statSync(filePath).isDirectory() && file != 'node_modules'
@@ -50,11 +49,11 @@ function findJS(searchDir, options = {}) {
50
49
  });
51
50
 
52
51
  // Log/return final result
53
- if (!options.isRecursing && options.verbose) {
54
- console.info('Search complete. '
55
- + ( jsFiles.length === 0 ? 'No' : jsFiles.length )
56
- + ` file${ jsFiles.length > 1 ? 's' : '' } found.`);
57
- }
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.' : '' ));
58
57
  return options.isRecursing || jsFiles.length > 0 ? jsFiles : [];
59
58
  }
60
59
 
@@ -67,41 +66,42 @@ function minify(input, options = {}) {
67
66
 
68
67
  // Validate input
69
68
  if (typeof input !== 'string') return console.error(
70
- 'minify() error: Arg `inputPath` must be a string.');
69
+ 'minify() » ERROR: 1st arg <input> must be a string.');
71
70
 
72
71
  // Validate options
73
72
  for (const key of Object.keys(options)) {
74
73
  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(', ')} ]`);
74
+ `minify() » ERROR: \`${ key }\` is an invalid option.\n`
75
+ + `minify() » Valid options: [ ${ Object.keys(defaultOptions).join(', ') } ]`);
77
76
  else if (typeof options[key] !== 'boolean') return console.error(
78
- `findJS() error: \`${ key }\` option must be set to \`true\` or \`false\`.`);
77
+ `minify() » ERROR: \`${ key }\` option can only be set to \`true\` or \`false\`.`);
79
78
  }
80
79
 
81
80
  // Minify JS based on input
82
81
  const minifyOptions = { mangle: options.mangle ? { toplevel: true } : false };
83
82
  if (fs.existsSync(input)) { // minify based on path arg
84
83
  if (input.endsWith('.js')) { // file path passed
85
- if (options.verbose) console.info(`Minifying ${ input }...`);
84
+ if (options.verbose) console.info(`minify() » Minifying ${ input }...`);
86
85
  const minifyResult = uglifyJS.minify(fs.readFileSync(input, 'utf8'), minifyOptions);
87
- if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
86
+ if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
88
87
  return { code: minifyResult.code, srcPath: path.resolve(process.cwd(), input),
89
88
  error: minifyResult.error };
90
89
  } else { // dir path passed
91
90
  return findJS(input, { recursive: options.recursive, verbose: options.verbose,
92
91
  dotFolders: options.dotFolders, dotFiles: options.dotFiles
93
92
  })?.map(jsPath => { // minify found JS files
94
- if (options.verbose) console.info(`Minifying ${ jsPath }...`);
93
+ if (options.verbose) console.info(`minify() » Minifying ${ jsPath }...`);
95
94
  const srcCode = fs.readFileSync(jsPath, 'utf8'),
96
95
  minifyResult = uglifyJS.minify(srcCode, minifyOptions);
97
- if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
96
+ if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
98
97
  return { code: minifyResult.code, srcPath: jsPath, error: minifyResult.error };
99
98
  }).filter(data => !data.error); // filter out failed minifications
100
99
  }
101
100
  } else { // minify based on src code arg
102
- if (options.verbose) console.info('Minifying passed source code...');
101
+ if (options.verbose) console.info('minify() » Minifying passed source code...');
103
102
  const minifyResult = uglifyJS.minify(input, minifyOptions);
104
- if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
103
+ if (minifyResult.error) console.error(`minify() » ERROR: ${ minifyResult.error.message }`);
104
+
105
105
  return { code: minifyResult.code, srcPath: undefined, error: minifyResult.error };
106
106
  }
107
107
  }
@@ -123,7 +123,7 @@ else { // run as CLI utility
123
123
  'dryRun': /^--?(?:n|dry-?run)$/,
124
124
  'includeDotFolders': /^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?=?(?:true|1)?)$/,
125
125
  'includeDotFiles': /^--?(?:df|D|(?:include-?)?dot-?files?=?(?:true|1)?)$/,
126
- 'noRecursion': /^--?(?:R|(?:disable|no)-?recursion|recursion=(?:false|0))$/,
126
+ 'noRecursion': /^--?(?:R|(?:disable|no)-?recursi(?:on|ve)|recursi(?:on|ve)=(?:false|0))$/,
127
127
  'noMangle': /^--?(?:M|(?:disable|no)-?mangle|mangle=(?:false|0))$/,
128
128
  'quietMode': /^--?q(?:uiet)?(?:-?mode)?$/,
129
129
  'help': /^--?h(?:elp)?$/,
@@ -159,8 +159,8 @@ else { // run as CLI utility
159
159
  // Validate input arg (output arg can be anything)
160
160
  const inputPath = path.resolve(process.cwd(), inputArg);
161
161
  if (inputArg && !fs.existsSync(inputPath)) {
162
- console.error(`\n${br}Error: First argument must be an existing file or directory.`
163
- + `\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}`
164
164
  + `\n\n${bg}Example valid command: \n>> minify-js . output.min.js${nc}`
165
165
  + `\n\n${by}For all command options: \n>> minify-js --help${nc}`);
166
166
  process.exit(1);
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.7",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",