@adamlui/minify.js 1.4.0 → 1.4.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 CHANGED
@@ -9,17 +9,18 @@
9
9
  <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/zh-tw#readme">繁體中文</a> |
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
- <a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/mr#readme">मराठी</a>
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
14
  </h6>
14
15
  </div>
15
16
 
16
- # </> minify.js
17
+ # </> minify.js
17
18
 
18
19
  ### Recursively minify all JavaScript files.
19
20
 
20
21
  <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>
21
22
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-red.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
22
- <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.0-fc7811.svg?logo=icinga&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.2-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
23
24
  <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>
24
25
  <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>
25
26
 
@@ -164,9 +165,8 @@ If a **directory path** is passed, JavaScript files are searched for (recursivel
164
165
  ```js
165
166
  const results = minifyJS.minify('.');
166
167
  results.forEach(result =>
167
- console.log(result.srcPath) // paths to JS files in working directory + all nested directories
168
- );
169
- console.log(results[1].code) // minified code of 2nd JS file if found, or `undefined` if not found
168
+ console.log(result.srcPath)); // paths to JS files in working directory + all nested directories
169
+ console.log(results[1].code); // minified code of 2nd JS file if found, or `undefined` if not found
170
170
  ```
171
171
 
172
172
  Options are boolean, passed as object properties. For example:
@@ -179,7 +179,8 @@ minifyJS.minify(input, { dotFiles: true });
179
179
  Possible parameters (and their default settings) are:
180
180
 
181
181
  ```
182
- recursive (true) Recursively search for nested files if dir path passed.
182
+ recursive (true) Recursively search for nested files if dir path
183
+ passed.
183
184
  verbose (true) Show logging in console/terminal.
184
185
  dotFolders (false) Include dotfolders in file search.
185
186
  dotFiles (false) Include dotfiles in file search.
@@ -200,7 +201,8 @@ minifyJS.findJS(searchDir, { recursive: false });
200
201
  Possible parameters (and their default settings) are:
201
202
 
202
203
  ```
203
- recursive (true) Recursively search for nested files if dir path passed.
204
+ recursive (true) Recursively search for nested files if dir path
205
+ passed.
204
206
  verbose (false) Show logging in console/terminal.
205
207
  dotFolders (false) Include dotfolders in file search.
206
208
  dotFiles (false) Include dotfiles in file search.
@@ -215,7 +217,7 @@ Please consider [giving a GitHub ⭐](https://github.com/adamlui/js-utils) if th
215
217
 
216
218
  ## 🏛️ MIT License
217
219
 
218
- **Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui)**
220
+ **Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui) & contributors**
219
221
 
220
222
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
221
223
 
package/docs/LICENSE.md CHANGED
@@ -9,13 +9,14 @@
9
9
  <a href="zh-tw/LICENSE.md">繁體中文</a> |
10
10
  <a href="hi/LICENSE.md">हिंदी</a> |
11
11
  <a href="bn/LICENSE.md">বাংলা</a> |
12
- <a href="mr/LICENSE.md">मराठी</a>
12
+ <a href="mr/LICENSE.md">मराठी</a> |
13
+ <a href="pa/LICENSE.md">ਪੰਜਾਬੀ</a>
13
14
  </h6>
14
15
  </div>
15
16
 
16
17
  # 🏛️ MIT License
17
18
 
18
- **Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui)**
19
+ **Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui) & contributors**
19
20
 
20
21
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
21
22
 
package/docs/SECURITY.md CHANGED
@@ -9,7 +9,8 @@
9
9
  <a href="zh-tw/SECURITY.md">繁體中文</a> |
10
10
  <a href="hi/SECURITY.md">हिंदी</a> |
11
11
  <a href="bn/SECURITY.md">বাংলা</a> |
12
- <a href="mr/SECURITY.md">मराठी</a>
12
+ <a href="mr/SECURITY.md">मराठी</a> |
13
+ <a href="pa/SECURITY.md">ਪੰਜਾਬੀ</a>
13
14
  </h6>
14
15
  </div>
15
16
 
package/minify.js CHANGED
@@ -13,16 +13,17 @@ function findJS(searchDir, options = {}) {
13
13
  const dirFiles = fs.readdirSync(searchDir), jsFiles = [];
14
14
  dirFiles.forEach(file => {
15
15
  const filePath = path.resolve(searchDir, file);
16
- if (fs.statSync(filePath).isDirectory() && file != 'node_modules' &&
17
- (options.dotFolders || !file.startsWith('.')) && options.recursive) {
16
+ if (fs.statSync(filePath).isDirectory() && file != 'node_modules'
17
+ && (options.dotFolders || !file.startsWith('.')) && options.recursive) {
18
18
  if (options.verbose) console.info(`Searching for unminified JS files in: ${filePath}...`);
19
19
  jsFiles.push( // recursively find unminified JS in eligible dir
20
- ...findJS(filePath));
21
- } else if (/\.js(?<!\.min\.js)$/.test(file) &&
22
- (options.dotFiles || !file.startsWith('.')))
20
+ ...findJS(filePath, { ...options, isRecursing: true }));
21
+ } else if (/\.js(?<!\.min\.js)$/.test(file)
22
+ && (options.dotFiles || !file.startsWith('.')))
23
23
  jsFiles.push(filePath); // store eligible unminified JS file for minification
24
24
  });
25
- return jsFiles;
25
+ if (options.isRecursing || jsFiles.length > 0) return jsFiles;
26
+ else if (options.verbose) console.info('\nNo unminified JavaScript files found.');
26
27
  }
27
28
 
28
29
  function minify(input, options = {}) {
@@ -40,9 +41,10 @@ function minify(input, options = {}) {
40
41
  if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
41
42
  return { code: minifyResult.code, srcPath: input, error: minifyResult.error };
42
43
  } else { // dir path passed
44
+ if (options.verbose) console.info('Searching for unminified JS files...');
43
45
  return findJS(input, { recursive: options.recursive,
44
46
  dotFolders: options.dotFolders, dotFiles: options.dotFiles })
45
- .map(jsPath => { // minify found JS files
47
+ ?.map(jsPath => { // minify found JS files
46
48
  if (options.verbose) console.info(`Minifying ${ jsPath }...`);
47
49
  const srcCode = fs.readFileSync(jsPath, 'utf8'),
48
50
  minifyResult = uglifyJS.minify(srcCode, minifyOptions);
@@ -129,29 +131,26 @@ else { // run as CLI tool
129
131
  }
130
132
 
131
133
  // Find all eligible JavaScript files or arg-passed file
134
+ printIfNotQuiet('Searching for unminified JS files...');
132
135
  const unminnedJSfiles = inputArg.endsWith('.js') ? [inputPath]
133
136
  : findJS(inputPath, { recursive: !config.noRecursion });
134
137
 
135
- if (unminnedJSfiles.length === 0) { // print nothing found
136
- printIfNotQuiet(`\n${by}No unminified JavaScript files found.${nc}`);
137
-
138
- } else if (config.dryRun) { // print files to be processed
138
+ if (config.dryRun && unminnedJSfiles?.length > 0) { // print files to be processed
139
139
  console.info(`\n${by}JS files to be minified:${nc}`);
140
- unminnedJSfiles.forEach(file => console.info(file));
140
+ unminnedJSfiles?.forEach(file => console.info(file));
141
141
 
142
142
  } else { // actually minify JavaScript files
143
- printIfNotQuiet(''); // line break before first log
144
143
 
145
144
  // Build array of minification data
146
145
  const failedPaths = [];
147
- const minifyData = unminnedJSfiles.map(jsPath => {
146
+ const minifyData = unminnedJSfiles?.map(jsPath => {
148
147
  const minifyResult = minify(jsPath, { verbose: !config.quietMode, mangle: !config.noMangle });
149
148
  if (minifyResult.error) failedPaths.push(jsPath);
150
149
  return minifyResult;
151
150
  }).filter(minifyResult => !minifyResult.error); // filter out failed minifications
152
151
 
153
152
  // Write array data to files
154
- minifyData.forEach(({ code, srcPath }) => {
153
+ minifyData?.forEach(({ code, srcPath }) => {
155
154
  const outputDir = path.join(
156
155
  path.dirname(srcPath), // path of file to be minified
157
156
  /so?u?rce?$/.test(path.dirname(srcPath)) ? '../min' // + ../min/ if in *(src|source)/
@@ -169,7 +168,7 @@ else { // run as CLI tool
169
168
  });
170
169
 
171
170
  // Print final summary
172
- if (minifyData.length > 0) {
171
+ if (minifyData?.length > 0) {
173
172
  printIfNotQuiet(`\n${bg}Minification complete!${nc}`);
174
173
  printIfNotQuiet(
175
174
  `${ minifyData.length } file${ minifyData.length > 1 ? 's' : '' } minified.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -29,11 +29,13 @@
29
29
  },
30
30
  "keywords": [
31
31
  "javascript",
32
- "js",
33
- "js-utils",
34
- "utils",
35
32
  "utilities",
36
- "minifier"
33
+ "js-utils",
34
+ "minifier",
35
+ "api",
36
+ "js",
37
+ "cli",
38
+ "utils"
37
39
  ],
38
40
  "bugs": {
39
41
  "url": "https://github.com/adamlui/js-utils/issues"