@adamlui/minify.js 1.4.9 → 1.5.0
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 +28 -22
- package/dist/cli.min.js +13 -13
- package/dist/minify.min.js +4 -1
- package/docs/README.md +268 -0
- package/docs/SECURITY.md +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
6
|
</picture>
|
|
7
7
|
English |
|
|
8
|
-
<a href="
|
|
9
|
-
<a href="
|
|
10
|
-
<a href="
|
|
11
|
-
<a href="
|
|
12
|
-
<a href="
|
|
13
|
-
<a href="
|
|
14
|
-
<a href="
|
|
8
|
+
<a href="http://minify-js.org/docs/zh-cn#readme">简体中文</a> |
|
|
9
|
+
<a href="http://minify-js.org/docs/zh-tw#readme">繁體中文</a> |
|
|
10
|
+
<a href="http://minify-js.org/docs/hi#readme">हिंदी</a> |
|
|
11
|
+
<a href="http://minify-js.org/docs/bn#readme">বাংলা</a> |
|
|
12
|
+
<a href="http://minify-js.org/docs/mr#readme">मराठी</a> |
|
|
13
|
+
<a href="http://minify-js.org/docs/pa#readme">ਪੰਜਾਬੀ</a> |
|
|
14
|
+
<a href="http://minify-js.org/docs/de#readme">Deutsch</a>
|
|
15
15
|
</h6>
|
|
16
16
|
</div>
|
|
17
17
|
|
|
@@ -19,13 +19,15 @@
|
|
|
19
19
|
|
|
20
20
|
### Recursively minify all JavaScript files.
|
|
21
21
|
|
|
22
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/
|
|
22
|
+
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dm/%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.
|
|
24
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/minify.js-1.5.0"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.5.0-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
|
-
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=
|
|
26
|
+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_minify.js%3Anode.js%2Fsrc%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
|
+
<a href="https://github.com/toolleeo/cli-apps#programming"><img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
28
|
+
<a href="https://minify-js.org"><img src="https://img.shields.io/badge/web-minify--js.org-lightgrey?logo=dribbble&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
27
29
|
|
|
28
|
-
<img src="https://
|
|
30
|
+
<img src="https://raw.githubusercontent.com/adamlui/minify.js/main/node.js/media/images/screenshots/cli-minify-js-docs.png">
|
|
29
31
|
|
|
30
32
|
<br>
|
|
31
33
|
|
|
@@ -123,7 +125,7 @@ $ minify-js input_folder output_folder
|
|
|
123
125
|
### Command line options
|
|
124
126
|
|
|
125
127
|
```
|
|
126
|
-
|
|
128
|
+
Boolean options:
|
|
127
129
|
-n, --dry-run Don't actually minify the file(s), just show
|
|
128
130
|
if they will be processed.
|
|
129
131
|
-d, --include-dotfolders Include dotfolders in file search.
|
|
@@ -132,6 +134,9 @@ Config options:
|
|
|
132
134
|
-M, --no-mangle Disable mangling names.
|
|
133
135
|
-q, --quiet Suppress all logging except errors.
|
|
134
136
|
|
|
137
|
+
Parameter options:
|
|
138
|
+
--comment=comment Prepend comment to minified code.
|
|
139
|
+
|
|
135
140
|
Info commands:
|
|
136
141
|
-h, --help Display help screen.
|
|
137
142
|
-v, --version Show version number.
|
|
@@ -197,13 +202,14 @@ minifyJS.minify(input, { dotFiles: true });
|
|
|
197
202
|
|
|
198
203
|
Available parameters (and their default settings) are:
|
|
199
204
|
|
|
200
|
-
Name | Desciption | Default value
|
|
201
|
-
|
|
202
|
-
`recursive` | Recursively search for nested files if dir path passed. | `true`
|
|
203
|
-
`verbose` | Show logging in console/terminal. | `true`
|
|
204
|
-
`dotFolders` | Include dotfolders in file search. | `false`
|
|
205
|
-
`dotFiles` | Include dotfiles in file search. | `false`
|
|
206
|
-
`mangle` | Shorten variable names (typically to one character). | `true`
|
|
205
|
+
Name | Type | Desciption | Default value
|
|
206
|
+
-------------|---------|---------------------------------------------------------|---------------
|
|
207
|
+
`recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
|
|
208
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
209
|
+
`dotFolders` | Boolean | Include dotfolders in file search. | `false`
|
|
210
|
+
`dotFiles` | Boolean | Include dotfiles in file search. | `false`
|
|
211
|
+
`mangle` | Boolean | Shorten variable names (typically to one character). | `true`
|
|
212
|
+
`comment` | String | Comment to prepend to minified code. | `''`
|
|
207
213
|
|
|
208
214
|
#
|
|
209
215
|
|
|
@@ -245,7 +251,7 @@ Name | Desciption | Defau
|
|
|
245
251
|
|
|
246
252
|
## 🏛️ MIT License
|
|
247
253
|
|
|
248
|
-
**Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui) & contributors
|
|
254
|
+
**Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui) & contributors.**
|
|
249
255
|
|
|
250
256
|
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:
|
|
251
257
|
|
|
@@ -257,6 +263,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
257
263
|
|
|
258
264
|
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
259
265
|
|
|
260
|
-
<
|
|
261
|
-
<a href="https://
|
|
266
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=13 src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
267
|
+
<a href="https://js-utils.com/discussions">Discuss</a> /
|
|
262
268
|
<a href="#-minifyjs">Back to top ↑</a>
|
package/dist/cli.min.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const e="https://docs.minify-js.org/#-command-line-usage",n=require(__dirname.match(/src/)?"./minify":"./minify.min"),o=require("fs"),s=require("path"),r="[0m",t="[1;91m",l="[1;33m",i="[1;92m",a={},c={flags:{dryRun:/^--?(?:n|dry-?run)$/,includeDotFolders:/^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?=?(?:true|1)?)$/,includeDotFiles:/^--?(?:df|D|(?:include-?)?dot-?files?=?(?:true|1)?)$/,noRecursion:/^--?(?:R|(?:disable|no)-?recursi(?:on|ve)|recursi(?:on|ve)=(?:false|0))$/,noMangle:/^--?(?:M|(?:disable|no)-?mangle|mangle=(?:false|0))$/,quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},paramOptions:{comment:/^--?comments?(?:=.*|$)/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(i=>{var e,n,o;i.startsWith("-")&&(e=Object.keys(c.paramOptions).find(e=>c.paramOptions[e].test(i)),o=Object.keys(c.flags).find(e=>c.flags[e].test(i)),n=Object.keys(c.infoCmds).find(e=>c.infoCmds[e].test(i)),o?a[o]=!0:e?(i.includes("=")||(console.error(`
|
|
3
|
+
${t}ERROR: Arg [--${i.replace(/-/g,"")}] requires '=' followed by a value.`+r),d(),process.exit(1)),o=i.split("=")[1],a[e]=parseInt(o)||o):n||(console.error(`
|
|
3
4
|
${t}ERROR: Arg [${i}] not recognized.`+r),console.info(`
|
|
4
|
-
${l}Valid arguments are below.`+r),
|
|
5
|
+
${l}Valid arguments are below.`+r),m(["paramOptions","flags","infoCmds"]),d(),process.exit(1)))}),process.argv.some(e=>c.infoCmds.help.test(e)))m();else if(process.argv.some(e=>c.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{const[u="",p=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),h=s.resolve(process.cwd(),u),g=(u&&!o.existsSync(h)&&(console.error(`
|
|
5
6
|
${t}Error: First argument can only be an existing file or directory.`+`
|
|
6
|
-
${
|
|
7
|
+
${h} does not exist.`+r+`
|
|
7
8
|
|
|
8
|
-
${
|
|
9
|
-
» minify-js . output.min.js`+r
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
${
|
|
16
|
-
`+
|
|
17
|
-
${l}minify-js [inputPath] [outputPath] [options]`+r],pathArgs:["\nPath arguments:"," [inputPath] Path to JS file or directory containing JS files to be minified, relative to the current working directory."," [outputPath] Path to file or directory where minified files will be stored, relative to original file location (if not provided, min/ is used)."],configOptions:["\nConfig options:"," -n, --dry-run Don't actually minify the file(s), just show if they will be processed."," -d, --include-dotfolders Include dotfolders in file search."," -D, --include-dotfiles Include dotfiles in file search."," -R, --no-recursion Disable recursive file searching."," -M, --no-mangle Disable mangling names."," -q, --quiet Suppress all logging except errors."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{i[e]?.forEach(e=>{{const o=process.stdout.columns||80,s=[],i=e.match(/\S+|\s+/g);let n="";i.forEach(e=>{var i=o-(0===s.length?0:29);n.length+e.length>i&&(s.push(0===s.length?n:n.trimStart()),n=""),n+=e}),s.push(0===s.length?n:n.trimStart()),s.forEach((e,i)=>console.info(0===i?e:" ".repeat(29)+e))}})})}function i(e){c.quietMode||console.info(e)}
|
|
9
|
+
${i}Example valid command:
|
|
10
|
+
» minify-js . output.min.js`+r),d(),process.exit(1)),u.endsWith(".js")?[h]:n.findJS(h,{recursive:!a.noRecursion,verbose:!a.quietMode}));if(a.dryRun)0<g.length?(console.info(`
|
|
11
|
+
${l}JS files to be minified:`+r),g.forEach(e=>console.info(e))):console.info(l+`
|
|
12
|
+
No JS files will be minified.`+r);else{const v=[],y=g.map(e=>{var i=n.minify(e,{verbose:!a.quietMode,mangle:!a.noMangle,comment:a.comment});return i.error&&v.push(e),i}).filter(e=>!e.error);y?.forEach(({code:e,srcPath:i})=>{var n=s.join(s.dirname(i),(/so?u?rce?$/.test(s.dirname(i))?"../":"")+(p.endsWith(".js")?s.dirname(p):p||"min")),i=(p.endsWith(".js")&&u.endsWith(".js")?s.basename(p).replace(/(\.min)?\.js$/,""):s.basename(i,".js"))+".min.js",i=s.join(n,i);o.existsSync(n)||o.mkdirSync(n,{recursive:!0}),o.writeFileSync(i,e,"utf8")}),0<y?.length?(f(`
|
|
13
|
+
${i}Minification complete!`+r),f(`${y.length} file${1<y.length?"s":""} minified.`)):f(l+"No unminified JavaScript files processed."+r),0<v.length&&(f(`
|
|
14
|
+
`+t+v.length+" file"+(1<v.length?"s":"")+" failed to minify:"+r),v.forEach(e=>f(e)))}}function m(e=["cmdFormat","pathArgs","flags","paramOptions","infoCmds"]){const i={cmdFormat:[`
|
|
15
|
+
${l}minify-js [inputPath] [outputPath] [options]`+r],pathArgs:["\nPath arguments:"," [inputPath] Path to JS file or directory containing JS files to be minified, relative to the current working directory."," [outputPath] Path to file or directory where minified files will be stored, relative to original file location (if not provided, min/ is used)."],flags:["\nBoolean options:"," -n, --dry-run Don't actually minify the file(s), just show if they will be processed."," -d, --include-dotfolders Include dotfolders in file search."," -D, --include-dotfiles Include dotfiles in file search."," -R, --no-recursion Disable recursive file searching."," -M, --no-mangle Disable mangling names."," -q, --quiet Suppress all logging except errors."],paramOptions:["\nParameter options:"," --comment=comment Prepend comment to minified code."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{i[e]?.forEach(e=>{{const o=process.stdout.columns||80,s=[],i=e.match(/\S+|\s+/g);let n="";i.forEach(e=>{var i=o-(0===s.length?0:29);n.length+e.length>i&&(s.push(0===s.length?n:n.trimStart()),n=""),n+=e}),s.push(0===s.length?n:n.trimStart()),s.forEach((e,i)=>console.info(0===i?e:" ".repeat(29)+e))}})})}function d(){console.info(`
|
|
16
|
+
${l}For more help, type 'minify-js --help' or visit
|
|
17
|
+
`+(e+r))}function f(e){a.quietMode||console.info(e)}
|
package/dist/minify.min.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const c=require("fs"),l=require("path"),s=require("uglify-js");function f(r,i={}){var e="https://docs.minify-js.org/#findjssearchdir-options",o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1};if("string"!=typeof r)console.error("findJS() » ERROR: 1st arg <searchDir> must be a string."),console.info("findJS() » For more help, please visit "+e);else{var n=l.resolve(process.cwd(),r);if(c.existsSync(n)){if(d(i,o,"findJS('assets/js', { verbose: false, dotFoldes: true })")){i={...o,...i};const s=c.readdirSync(r),t=[];return i.verbose&&!i.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),s.forEach(e=>{var o=l.resolve(r,e);c.statSync(o).isDirectory()&&"node_modules"!=e&&(i.dotFolders||!e.startsWith("."))&&i.recursive?t.push(...f(o,{...i,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!i.dotFiles&&e.startsWith(".")||t.push(o)}),!i.isRecursing&&i.verbose&&(console.info("findJS() » Search complete! "+(0===t.length?"No":t.length)+` file${0==t.length||1<t.length?"s":""} found.`),"minify"===f.caller.name||require.main.filename.endsWith("cli.js")||console.info("findJS() » Check returned array.")),i.isRecursing||0<t.length?t:[]}}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${n} does not exist.`),console.info("findJS() » For more help, please visit "+e)}}function e(e,r={}){var o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,comment:""};if("string"!=typeof e)console.error("minify() » ERROR: 1st arg <input> must be a string."),console.info("minify() » For more help, please visit https://docs.minify-js.org/#minifyinput-options");else if(d(r,o,"minify('assets/js', { recursive: false, mangle: false })")){const n={mangle:!!(r={...o,...r}).mangle&&{toplevel:!0}};return c.existsSync(e)?e.endsWith(".js")?(r.verbose&&console.info(`minify() » Minifying ${e}...`),o=s.minify(c.readFileSync(e,"utf8"),n),r.comment&&(o.code=i(o.code)),o.error?console.error("minify() » ERROR: "+o.error.message):r.verbose&&!require.main.filename.endsWith("cli.js")&&console.info("minify() » Minification complete. Check returned object."),{code:o.code,srcPath:l.resolve(process.cwd(),e),error:o.error}):(o=f(e,{recursive:r.recursive,verbose:r.verbose,dotFolders:r.dotFolders,dotFiles:r.dotFiles})?.map(e=>{r.verbose&&console.info(`minify() » Minifying ${e}...`);var o=c.readFileSync(e,"utf8"),o=s.minify(o,n);return r.comment&&(o.code=i(o.code)),o.error&&console.error("minify() » ERROR: "+o.error.message),{code:o.code,srcPath:e,error:o.error}}).filter(e=>!e.error),r.verbose&&(0<o.length?console.info("minify() » Minification complete. Check returned object."):console.info("minify() » No unminified JavaScript files processed.")),o):(r.verbose&&console.info("minify() » Minifying passed source code..."),o=s.minify(e,n),r.comment&&(o.code=i(o.code)),o.error?console.error("minify() » ERROR: "+o.error.message):r.verbose&&console.info("minify() » Minification complete. Check returned object."),{code:o.code,srcPath:void 0,error:o.error});function i(e){return`/*
|
|
3
|
+
${r.comment}
|
|
4
|
+
*/
|
|
5
|
+
`+e}}}function d(e,o,r){const i=JSON.stringify(o,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(o).join(", "),s=Object.keys(o).filter(e=>"boolean"==typeof o[e]),t=Object.keys(o).filter(e=>Number.isInteger(o[e])),c=(d.caller?.name||"validateOptions")+"() » ";var l=()=>{console.info(c+`Valid options: [ ${n} ]`),console.info(c+"If omitted, default settings are: "+i)},f=()=>{console.info(c+"For more help, please visit https://docs.minify-js.org/#-api-usage")};if("object"!=typeof e)return console.error(c+"ERROR: [options] can only be an object of key/values."),console.info(c+"Example valid call: "+r),l(),f(),!1;for(const a in e){if("isRecursing"!=a&&!Object.prototype.hasOwnProperty.call(o,a))return console.error(c+`ERROR: \`${a}\` is an invalid option.`),l(),f(),!1;if(s.includes(a)&&"boolean"!=typeof e[a])return console.error(c+`ERROR: [${a}] option can only be \`true\` or \`false\`.`),f(),!1;if(t.includes(a)&&(e[a]=parseInt(e[a],10),isNaN(e[a])||e[a]<1))return console.error(c+`ERROR: [${a}] option can only be an integer > 0.`),f(),!1}return!0}module.exports={minify:e,find:f,findJS:f};
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
English |
|
|
8
|
+
<a href="http://minify-js.org/docs/zh-cn#readme">简体中文</a> |
|
|
9
|
+
<a href="http://minify-js.org/docs/zh-tw#readme">繁體中文</a> |
|
|
10
|
+
<a href="http://minify-js.org/docs/hi#readme">हिंदी</a> |
|
|
11
|
+
<a href="http://minify-js.org/docs/bn#readme">বাংলা</a> |
|
|
12
|
+
<a href="http://minify-js.org/docs/mr#readme">मराठी</a> |
|
|
13
|
+
<a href="http://minify-js.org/docs/pa#readme">ਪੰਜਾਬੀ</a> |
|
|
14
|
+
<a href="http://minify-js.org/docs/de#readme">Deutsch</a>
|
|
15
|
+
</h6>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
# </> minify.js
|
|
19
|
+
|
|
20
|
+
### Recursively minify all JavaScript files.
|
|
21
|
+
|
|
22
|
+
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dm/%40adamlui%2Fminify.js?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
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.5.0"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.5.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
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
|
+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_minify.js%3Anode.js%2Fsrc%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
|
+
<a href="https://github.com/toolleeo/cli-apps#programming"><img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
28
|
+
<a href="https://minify-js.org"><img src="https://img.shields.io/badge/web-minify--js.org-lightgrey?logo=dribbble&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
29
|
+
|
|
30
|
+
<img src="https://raw.githubusercontent.com/adamlui/minify.js/main/node.js/media/images/screenshots/cli-minify-js-docs.png">
|
|
31
|
+
|
|
32
|
+
<br>
|
|
33
|
+
|
|
34
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
35
|
+
|
|
36
|
+
## ⚡ Installation
|
|
37
|
+
|
|
38
|
+
As a **global utility**:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
$ npm install -g @adamlui/minify.js
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
As a **dev dependency** (e.g. for build scripts), from your project root:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
$ npm install -D @adamlui/minify.js
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
As a **runtime dependency** (e.g. for on-the-fly minification), from your project root:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
$ npm install @adamlui/minify.js
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
<br>
|
|
57
|
+
|
|
58
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
59
|
+
|
|
60
|
+
## 💻 Command line usage
|
|
61
|
+
|
|
62
|
+
The basic **global command** is:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
$ minify-js
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**💡 Note:** Pass `-n` or `--dry-run` to only see what files will be processed.
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
|
|
72
|
+
To specify **input/output** paths:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
$ minify-js [input_path] [output_path]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- `[input_path]`: Path to JS file or directory containing JS files to be minified, relative to the current working directory.
|
|
79
|
+
- `[output_path]`: Path to file or directory where minified files will be stored, relative to original file location (if not provided, `min/` is used).
|
|
80
|
+
|
|
81
|
+
**💡 Note:** If folders are passed, files will be processed recursively unless `-R` or `--no-recursion` is passed.
|
|
82
|
+
|
|
83
|
+
#
|
|
84
|
+
|
|
85
|
+
To use as a **package script**, in your project's `package.json`:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
"scripts": {
|
|
89
|
+
"build:js": "<minify-js-cmd>"
|
|
90
|
+
},
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Replace `<minify-js-cmd>` with `minify-js` + optional args. Then, `npm run build:js` can be used to run the command.
|
|
94
|
+
|
|
95
|
+
#
|
|
96
|
+
|
|
97
|
+
### Example commands
|
|
98
|
+
|
|
99
|
+
Minify all JavaScript files in the **current directory** (outputs to `min/`):
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
$ minify-js
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory/min/`):
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
$ minify-js path/to/your/directory
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Minify a **specific file** (outputs to `path/to/your/min/file.min.js`):
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
$ minify-js path/to/your/file.js
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Specify both **input and output** directories (outputs to `output_folder/`):
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
$ minify-js input_folder output_folder
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#
|
|
124
|
+
|
|
125
|
+
### Command line options
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
Boolean options:
|
|
129
|
+
-n, --dry-run Don't actually minify the file(s), just show
|
|
130
|
+
if they will be processed.
|
|
131
|
+
-d, --include-dotfolders Include dotfolders in file search.
|
|
132
|
+
-D, --include-dotfiles Include dotfiles in file search.
|
|
133
|
+
-R, --no-recursion Disable recursive file searching.
|
|
134
|
+
-M, --no-mangle Disable mangling names.
|
|
135
|
+
-q, --quiet Suppress all logging except errors.
|
|
136
|
+
|
|
137
|
+
Parameter options:
|
|
138
|
+
--comment=comment Prepend comment to minified code.
|
|
139
|
+
|
|
140
|
+
Info commands:
|
|
141
|
+
-h, --help Display help screen.
|
|
142
|
+
-v, --version Show version number.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
<br>
|
|
146
|
+
|
|
147
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
148
|
+
|
|
149
|
+
## 🔌 API usage
|
|
150
|
+
|
|
151
|
+
You can also import **minify.js** into your app to use its API methods, both as an ECMAScript module or a CommonJS module.
|
|
152
|
+
|
|
153
|
+
#### ESM*:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
import * as minifyJS from '@adamlui/minify.js';
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### CJS:
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
const minifyJS = require('@adamlui/minify.js');
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
###### _*Node.js version 14 or higher required_
|
|
166
|
+
|
|
167
|
+
#
|
|
168
|
+
|
|
169
|
+
### `minify(input[, options])`
|
|
170
|
+
|
|
171
|
+
Minifies JavaScript code based on the string input supplied.
|
|
172
|
+
|
|
173
|
+
If **source code** is passed, it is directly minified, then an object containing `srcPath` + `code` + `error` is returned:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
const srcCode = 'function add(first, second) { return first + second; }',
|
|
177
|
+
minifyResult = minifyJS.minify(srcCode);
|
|
178
|
+
|
|
179
|
+
console.log(minifyResult.error); // outputs runtime error, or `undefined` if no error
|
|
180
|
+
console.log(minifyResult.code); // outputs minified JS: 'function add(n,d){return n+d}'
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
If a **file path** is passed, the file's code is loaded then minified, returning an object like above.
|
|
184
|
+
|
|
185
|
+
If a **directory path** is passed, JavaScript files are searched for (recursively by default), each one's code is loaded then minified, then an array of objects containing `srcPath` + `code` + `error` is returned:
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
// Outputs paths to source JS files in working directory + all nested directories
|
|
189
|
+
const minifyResults = minifyJS.minify('.');
|
|
190
|
+
minifyResults.forEach(result => console.log(result.srcPath));
|
|
191
|
+
|
|
192
|
+
// Outputs minified code of 2nd JS file if found, or `undefined` if not found
|
|
193
|
+
console.log(minifyResults[1].code);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Options are boolean, passed as object properties. For example:
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
// Returns data object where dotfiles are also processed if `input` is a path
|
|
200
|
+
minifyJS.minify(input, { dotFiles: true });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Available parameters (and their default settings) are:
|
|
204
|
+
|
|
205
|
+
Name | Type | Desciption | Default value
|
|
206
|
+
-------------|---------|---------------------------------------------------------|---------------
|
|
207
|
+
`recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
|
|
208
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
209
|
+
`dotFolders` | Boolean | Include dotfolders in file search. | `false`
|
|
210
|
+
`dotFiles` | Boolean | Include dotfiles in file search. | `false`
|
|
211
|
+
`mangle` | Boolean | Shorten variable names (typically to one character). | `true`
|
|
212
|
+
`comment` | String | Comment to prepend to minified code. | `''`
|
|
213
|
+
|
|
214
|
+
#
|
|
215
|
+
|
|
216
|
+
### `findJS(searchDir[, options])`
|
|
217
|
+
|
|
218
|
+
Searches for all unminified JavaScript files within the `searchDir` string passed (useful for discovering what files [`minify()`](#minifyinput-options) will process) and returns an array containing their filepaths.
|
|
219
|
+
|
|
220
|
+
Options are boolean, passed as object properties. For example:
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
// Search for unminified JS files in exactly assets/js:
|
|
224
|
+
const searchResults = minifyJS.findJS('assets/js', { recursive: false });
|
|
225
|
+
console.log(searchResults);
|
|
226
|
+
|
|
227
|
+
/* sample output:
|
|
228
|
+
|
|
229
|
+
findJS() » Searching for unminified JS files...
|
|
230
|
+
findJS() » Search complete! 2 files found.
|
|
231
|
+
findJS() » Check returned array.
|
|
232
|
+
[
|
|
233
|
+
'E:\\js\\utils\\minify.js\\assets\\js\\foo.js',
|
|
234
|
+
'E:\\js\\utils\\minify.js\\assets\\js\\bar.js'
|
|
235
|
+
]
|
|
236
|
+
*/
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Available parameters (and their default settings) are:
|
|
240
|
+
|
|
241
|
+
Name | Desciption | Default value
|
|
242
|
+
-------------|-----------------------------------------------------------|---------------
|
|
243
|
+
`recursive` | Recursively search for nested files in searchDir passed. | `true`
|
|
244
|
+
`verbose` | Show logging in console/terminal. | `true`
|
|
245
|
+
`dotFolders` | Include dotfolders in file search. | `false`
|
|
246
|
+
`dotFiles` | Include dotfiles in file search. | `false`
|
|
247
|
+
|
|
248
|
+
<br>
|
|
249
|
+
|
|
250
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
251
|
+
|
|
252
|
+
## 🏛️ MIT License
|
|
253
|
+
|
|
254
|
+
**Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui) & contributors.**
|
|
255
|
+
|
|
256
|
+
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:
|
|
257
|
+
|
|
258
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
259
|
+
|
|
260
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
261
|
+
|
|
262
|
+
<br>
|
|
263
|
+
|
|
264
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
265
|
+
|
|
266
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=13 src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
267
|
+
<a href="https://js-utils.com/discussions">Discuss</a> /
|
|
268
|
+
<a href="#-minifyjs">Back to top ↑</a>
|
package/docs/SECURITY.md
CHANGED
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
# 🛡️ Security Policy
|
|
19
19
|
|
|
20
|
-
If you find a vulnerability, please open a [draft security advisory](https://github.com/adamlui/js
|
|
20
|
+
If you find a vulnerability, please open a [draft security advisory](https://github.com/adamlui/minify.js/security/advisories/new).
|
|
21
21
|
|
|
22
22
|
Pull requests are also welcome, but for safety reasons, send an email to <adam@kudoai.com> and wait for a response before making it public.
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/minify.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Recursively minify all JavaScript files",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
7
7
|
"email": "adam@kudoai.com",
|
|
8
8
|
"url": "https://github.com/adamlui"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://js
|
|
10
|
+
"homepage": "https://minify-js.org",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"main": "dist/minify.min.js",
|
|
13
13
|
"files": [
|
|
@@ -30,13 +30,14 @@
|
|
|
30
30
|
"bump:patch": "bash utils/bump.sh patch",
|
|
31
31
|
"bump:minor": "bash utils/bump.sh minor",
|
|
32
32
|
"bump:major": "bash utils/bump.sh major",
|
|
33
|
+
"prepublishOnly": "npm test",
|
|
33
34
|
"publish:patch": "bash utils/bump.sh patch --publish",
|
|
34
35
|
"publish:minor": "bash utils/bump.sh minor --publish",
|
|
35
36
|
"publish:major": "bash utils/bump.sh major --publish"
|
|
36
37
|
},
|
|
37
38
|
"repository": {
|
|
38
39
|
"type": "git",
|
|
39
|
-
"url": "git+https://github.com/adamlui/js
|
|
40
|
+
"url": "git+https://github.com/adamlui/minify.js.git"
|
|
40
41
|
},
|
|
41
42
|
"keywords": [
|
|
42
43
|
"javascript",
|