@adamlui/minify.js 1.9.0 → 2.0.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 +21 -19
- package/dist/cli.min.js +27 -26
- package/dist/minify.min.js +3 -3
- package/docs/LICENSE.md +1 -1
- package/docs/README.md +21 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
<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>
|
|
26
26
|
<a href="#%EF%B8%8F-mit-license">
|
|
27
27
|
<img height=31 src="https://img.shields.io/badge/License-MIT-fc4f2d.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
28
|
-
<a href="https://github.com/adamlui/minify.js/releases/tag/node-
|
|
29
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-
|
|
28
|
+
<a href="https://github.com/adamlui/minify.js/releases/tag/node-v2.0.0">
|
|
29
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
30
30
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code">
|
|
31
31
|
<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>
|
|
32
32
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js">
|
|
@@ -87,7 +87,7 @@ $ minify-js [input_path] [output_path]
|
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
- `[input_path]`: Path to JS file or directory containing JS files to be minified, relative to the current working directory.
|
|
90
|
-
- `[output_path]`: Path to file or directory where minified files will be stored, relative to
|
|
90
|
+
- `[output_path]`: Path to file or directory where minified files will be stored, relative to input root (if not provided, `min/` is used).
|
|
91
91
|
|
|
92
92
|
**📝 Note:** If folders are passed, files will be processed recursively unless `-R` or `--no-recursion` is passed.
|
|
93
93
|
|
|
@@ -113,13 +113,13 @@ Minify all JavaScript files in the **current directory** (outputs to `min/`):
|
|
|
113
113
|
$ minify-js
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory
|
|
116
|
+
Minify all JavaScript files in a **specific directory** (outputs to `min/path/to/your/directory/`):
|
|
117
117
|
|
|
118
118
|
```
|
|
119
119
|
$ minify-js path/to/your/directory
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
Minify a **specific file** (outputs to `path/to/your/
|
|
122
|
+
Minify a **specific file** (outputs to `min/path/to/your/file.min.js`):
|
|
123
123
|
|
|
124
124
|
```
|
|
125
125
|
$ minify-js path/to/your/file.js
|
|
@@ -144,14 +144,15 @@ Boolean options:
|
|
|
144
144
|
-R, --no-recursion Disable recursive file searching.
|
|
145
145
|
-M, --no-mangle Disable mangling names.
|
|
146
146
|
-X, --no-filename-change Disable changing file extension to .min.js
|
|
147
|
+
-i, --rewrite-imports Update import paths from .js to .min.js
|
|
147
148
|
-c, --copy Copy minified code to clipboard instead
|
|
148
149
|
of writing to file if single source file
|
|
149
150
|
is processed.
|
|
150
|
-
-
|
|
151
|
+
-r, --relative-output Output files relative to each source file instead of to input root.
|
|
151
152
|
-q, --quiet Suppress all logging except errors.
|
|
152
153
|
|
|
153
154
|
Parameter options:
|
|
154
|
-
--
|
|
155
|
+
--ignores="dir/,file1.js,file2.js" Files/directories to exclude from minification.
|
|
155
156
|
--comment="comment" Prepend header comment to minified code.
|
|
156
157
|
Separate by line using '\n'.
|
|
157
158
|
|
|
@@ -220,16 +221,17 @@ minifyJS.minify(input, { dotFiles: true });
|
|
|
220
221
|
|
|
221
222
|
Available parameters (and their default settings) are:
|
|
222
223
|
|
|
223
|
-
Name
|
|
224
|
-
|
|
225
|
-
`recursive`
|
|
226
|
-
`verbose`
|
|
227
|
-
`dotFolders`
|
|
228
|
-
`dotFiles`
|
|
229
|
-
`mangle`
|
|
230
|
-
`
|
|
231
|
-
`
|
|
232
|
-
`
|
|
224
|
+
Name | Type | Desciption | Default value
|
|
225
|
+
-----------------|---------|--------------------------------------------------------------------------|---------------
|
|
226
|
+
`recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
|
|
227
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
228
|
+
`dotFolders` | Boolean | Include dotfolders in file search. | `false`
|
|
229
|
+
`dotFiles` | Boolean | Include dotfiles in file search. | `false`
|
|
230
|
+
`mangle` | Boolean | Shorten variable names (typically to one character). | `true`
|
|
231
|
+
`rewriteImports` | Boolean | Update import paths from .js to .min.js | `false`
|
|
232
|
+
`relativeOutput` | Boolean | Output files relative to each source file instead of to input root. | `false`
|
|
233
|
+
`ignores` | Array | Files/dirs to exclude from minification. | `[]`
|
|
234
|
+
`comment` | String | Header comment to prepend to minified code. Separate by line using '\n'. | `''`
|
|
233
235
|
|
|
234
236
|
#
|
|
235
237
|
|
|
@@ -264,7 +266,7 @@ Name | Type | Desciption
|
|
|
264
266
|
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
265
267
|
`dotFolders` | Boolean | Include dotfolders in file search. | `false`
|
|
266
268
|
`dotFiles` | Boolean | Include dotfiles in file search. | `false`
|
|
267
|
-
`
|
|
269
|
+
`ignores` | Array | Files/dirs to exclude from search results. | `[]`
|
|
268
270
|
|
|
269
271
|
<br>
|
|
270
272
|
|
|
@@ -272,7 +274,7 @@ Name | Type | Desciption
|
|
|
272
274
|
|
|
273
275
|
## 🏛️ MIT License
|
|
274
276
|
|
|
275
|
-
**Copyright © 2023–
|
|
277
|
+
**Copyright © 2023–2026 [Adam Lui](https://github.com/adamlui) & contributors.**
|
|
276
278
|
|
|
277
279
|
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:
|
|
278
280
|
|
package/dist/cli.min.js
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* © 2023–
|
|
3
|
+
* © 2023–2026 Adam Lui & contributors under the MIT license.
|
|
4
4
|
* Source: https://code.minify-js.org/node.js
|
|
5
5
|
* Documentation: https://docs.minify-js.org/node.js
|
|
6
6
|
*/
|
|
7
|
-
let pkgName="@adamlui/minify.js",copyright="© 2024–
|
|
8
|
-
${m+(
|
|
9
|
-
${m+(
|
|
10
|
-
${
|
|
11
|
-
${
|
|
12
|
-
${m+(
|
|
13
|
-
${
|
|
14
|
-
${f}${
|
|
15
|
-
» minify-js . output.min.js[0m`),j(),process.exit(1)));var y,
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
-
${f+(
|
|
19
|
-
${
|
|
20
|
-
${m+
|
|
21
|
-
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
|
|
25
|
-
${
|
|
26
|
-
${
|
|
27
|
-
${
|
|
28
|
-
${
|
|
29
|
-
${
|
|
30
|
-
${
|
|
31
|
-
|
|
7
|
+
let pkgName="@adamlui/minify.js",copyright="© 2024–2026 Adam Lui & contributors under the MIT license.",cmdFormat="minify-js [inputPath] [outputPath] [options]",srcURL="https://code.minify-js.org/node.js",docURL="https://docs.minify-js.org/node.js/#-command-line-usage",latestLocaleCommitHash="5f87114";(async()=>{let n=require(__dirname.match(/src/)?"./minify":"./minify.min"),l=require("fs"),c=require("path"),t=require("node-clipboardy"),o=require("child_process").execSync,r="[0m",m="[1;91m",p="[1;33m",f="[1;92m",d="[1;97m",u="en";if("win32"==process.platform)try{u=o("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){console.error("ERROR loading system language: "+e.message)}else{var g=process.env;u=(g.LANG||g.LANGUAGE||g.LC_ALL||g.LC_MESSAGES||g.LC_NAME||"en").split(".")[0]}let h={};g=new Promise((t,r)=>{let s=`https://cdn.jsdelivr.net/gh/adamlui/minify.js@31e05d0ca0b45729e9c7b0cc6e72a3335ee547a3/_locales/`,e=`${u?u.replace("-","_"):"en"}/`,a=s+e+"messages.json",l=0;_(a).then(async function i(o){try{let e=await o.json(),i={};for(var n in e)"object"==typeof e[n]&&"message"in e[n]&&(i[n]=e[n].message);t(i)}catch(e){if(3==++l)return t({});_(a=u.includes("-")&&1==l?a.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):s+"en/messages.json").then(i).catch(r)}}).catch(r)});try{h=await g}catch(e){console.error("ERROR fetching messages: "+e.message)}let $={},s={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))$/,noFilenameChange:/^--?(?:X|(?:disable|no)-?(?:file)?name-?change|(?:file)?name-?change=(?:false|0))$/,rewriteImports:/^--?(?:i|rewrite-?imports?=?(?:true|1)?)$/,relativeOutput:/^--?(?:r|relative-?output?=?(?:true|1)?)$/,copy:/^--?c(?:opy)?$/,quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},paramOptions:{ignores:/^--?ignores?(?:=.*|$)/,comment:/^--?comments?(?:=.*|$)/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(i=>{var e,o,n;i.startsWith("-")&&(n=Object.keys(s.flags).find(e=>s.flags[e].test(i)),e=Object.keys(s.paramOptions).find(e=>s.paramOptions[e].test(i)),o=Object.keys(s.infoCmds).find(e=>s.infoCmds[e].test(i)),n?$[n]=!0:e?(/=.+/.test(i)||(console.error(`
|
|
8
|
+
${m+(h.prefix_error||"ERROR")}: `+`Arg [--${i.replace(/-/g,"")}] `+`${h.error_noEqual||"requires '=' followed by a value"}.${r}`),j(),process.exit(1)),n=i.split("=")[1],$[e]=parseInt(n)||n):o||(console.error(`
|
|
9
|
+
${m+(h.prefix_error||"ERROR")}: `+`Arg [${i}] ${h.error_notRecognized||"not recognized"}.[0m`),console.info(`
|
|
10
|
+
${p+(h.info_validArgs||"Valid arguments are below")}.[0m`),v(["flags","paramOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>s.infoCmds.help.test(e)))v();else if(process.argv.some(e=>s.infoCmds.version.test(e))){g=o(`npm view ${pkgName} version`).toString().trim()||"none";let e,i=process.cwd();for(;"/"!=i;){var a=c.join(i,"package.json");if(l.existsSync(a)){a=require(a);e=(a.dependencies?.[pkgName]||a.devDependencies?.[pkgName])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}i=c.dirname(i)}console.info(`
|
|
11
|
+
${h.prefix_globalVer||"Global version"}: `+g),console.info(`${h.prefix_localVer||"Local version"}: `+e)}else{let[s="",a=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),i=c.resolve(process.cwd(),s);s&&!l.existsSync(i)&&(g=i+".js",l.existsSync(g)?i=g:(console.error(`
|
|
12
|
+
${m+(h.prefix_error||"ERROR")}: `+`${h.error_firstArgNotExist||"First argument can only be an existing file or directory"}.`+`
|
|
13
|
+
${i} ${h.error_doesNotExist||"does not exist"}.[0m`),console.info(`
|
|
14
|
+
${f}${h.info_exampleValidCmd||"Example valid command"}: `+`
|
|
15
|
+
» minify-js . output.min.js[0m`),j(),process.exit(1)));var y,g=i.endsWith(".js")&&!l.statSync(i).isDirectory()?[i]:n.findJS(i,{recursive:!$.noRecursion,verbose:!$.quietMode,ignores:($.ignores?.split(",")??[]).map(e=>e.trim())});if($.dryRun)g.length?(console.info(`
|
|
16
|
+
${p+(h.info_filesToBeMinned||"JS files to be minified")}:[0m`),g.forEach(e=>console.info(e))):console.info(`
|
|
17
|
+
${p+(h.info_noFilesWillBeMinned||"No JS files will be minified")}.[0m`);else{let o=[],e=[];!$.relativeOutput&&l.statSync(i).isDirectory()?(y=n.minify(i,{verbose:!1,mangle:!$.noMangle,comment:$.comment?.replace(/\\n/g,"\n"),relativeOutput:!1,recursive:!$.noRecursion,dotFolders:!!$.includeDotFolders,dotFiles:!!$.includeDotFiles,rewriteImports:!!$.rewriteImports,ignores:$.ignores?$.ignores.split(",").map(e=>e.trim()):[]}))&&(y.error?o.push(i):e=[].concat(y)):e=g.map(e=>{var i=n.minify(e,{verbose:!$.quietMode,mangle:!$.noMangle,comment:$.comment?.replace(/\\n/g,"\n")});return i.error&&o.push(e),i}).filter(e=>!e.error),e?.length?(S(`
|
|
18
|
+
${f+(h.info_minComplete||"Minification complete")}![0m`),S(d+e.length+" "+(h.info_file||"file")+`${1<e.length?"s":""} ${h.info_minified||"minified"}.${r}`)):S(`
|
|
19
|
+
${p+(h.info_noFilesProcessed||"No unminified JavaScript files processed")}.[0m`),o.length&&(S(`
|
|
20
|
+
${m+o.length} `+(h.info_file||"file")+`${1<o.length?"s":""} ${h.info_failedToMinify||"failed to minify"}:${r}`),o.forEach(e=>S(e))),0!=e?.length&&($.copy&&1==e?.length?(console.log(`
|
|
21
|
+
${d}${e[0].code}[0m`),S(`
|
|
22
|
+
${h.info_copying||"Copying to clipboard"}...`),t.writeSync(e[0].code)):(S(`
|
|
23
|
+
${h.info_writing||"Writing to file"}${1<e?.length?"s":""}...`),e?.forEach(({code:e,srcPath:o,relPath:n})=>{let t,r;if(!$.relativeOutput&&n){let e=c.resolve(process.cwd(),a||"min"),i=c.dirname(n);t="."!=i?c.join(e,i):e,r=c.basename(o,".js")+`${$.noFilenameChange?"":".min"}.js`}else t=c.join(c.dirname(o),a.endsWith(".js")?c.dirname(a):a||"min"),r=(a.endsWith(".js")&&s.endsWith(".js")?c.basename(a).replace(/(\.min)?\.js$/,""):c.basename(o,".js"))+`${$.noFilenameChange?"":".min"}.js`;let i=c.join(t,r);l.existsSync(t)||l.mkdirSync(t,{recursive:!0}),l.writeFileSync(i,e,"utf8"),S(` ${f}✓[0m `+c.relative(process.cwd(),i))})))}}function _(n){return new Promise((o,e)=>{var i=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(i)||e(new Error(`${h.error_invalidURL||"Invalid URL"}.`)),require(i).get(n,e=>{let i="";e.on("data",e=>i+=e),e.on("end",()=>o({json:()=>JSON.parse(i)}))}).on("error",e)})}function v(e=["header","usage","pathArgs","flags","paramOptions","infoCmds"]){var i=`[106m[30m ${pkgName.replace(/^@[^/]+\//,"")} [0m `;let o={header:[`
|
|
24
|
+
├ `+i+(h.appCopyright||copyright),i+(h.prefix_source||"Source")+": "+srcURL],usage:[`
|
|
25
|
+
${d}o ${h.helpSection_usage||"Usage"}:[0m`,` ${d}» ${f}${cmdFormat}[0m`],pathArgs:[`
|
|
26
|
+
${d}o ${h.helpSection_pathArgs||"Path arguments"}:[0m`," [inputPath] "+`${h.inputPathDesc_main||"Path to JS file or directory containing JS files to be minified"}, `+`${h.inputPathDesc_extra||"relative to the current working directory"}.`," [outputPath] "+`${h.outputPathDesc_main||"Path to file or directory where minified files will be stored"}, `+`${h.outputPathDesc_extra||"relative to original file location (if not provided, min/ is used)"}.`],flags:[`
|
|
27
|
+
${d}o ${h.helpSection_flags||"Boolean options"}:[0m`," -n, --dry-run "+`${h.optionDesc_dryRun||"Don't actually minify the file(s), just show if they will be processed"}.`,` -d, --include-dotfolders ${h.optionDesc_dotfolders||"Include dotfolders in file search"}.`,` -D, --include-dotfiles ${h.optionDesc_dotfiles||"Include dotfiles in file search"}.`,` -R, --no-recursion ${h.optionDesc_noRecursion||"Disable recursive file searching"}.`,` -M, --no-mangle ${h.optionDesc_noMangle||"Disable mangling names"}.`," -X, --no-filename-change "+(h.optionDesc_noFilenameChange||"Disable changing file extension to .min.js"),` -i, --rewrite-imports ${h.optionDesc_rewriteImports||"Update import paths from .js to .min.js"}.`,` -c, --copy ${h.optionDesc_copy||"Copy minified code to clipboard instead of writing to file if single source file is processed"}.`,` -r, --relative-output ${h.optionDesc_relativeOutput||"Output files relative to each source file instead of to input root"}.`,` -q, --quiet ${h.optionDesc_quiet||"Suppress all logging except errors"}.`],paramOptions:[`
|
|
28
|
+
${d}o ${h.helpSection_paramOptions||"Parameter options"}:[0m`,`--ignores="dir/,file1.js,file2.js" ${h.optionDesc_ignores||"Files/directories to exclude from minification"}.`,`--comment="comment" ${h.optionDesc_commentMain||"Prepend header comment to minified code"}.`+` ${h.optionDesc_commentExtra||"Separate by line using '\\n'"}.`],infoCmds:[`
|
|
29
|
+
${d}o ${h.helpSection_infoCmds||"Info commands"}:[0m`," -h, --help "+(h.optionDesc_help||"Display help screen."),` -v, --version ${h.optionDesc_version||"Show version number"}.`]};e.forEach(s=>o[s]?.forEach(i=>{{var r=/header|usage/.test(s)?1:37;let o=process.stdout.columns||80,n=[],e=i.match(/\S+|\s+/g),t="";e.forEach(e=>{var i=o-(n.length?r:0);t.length+"| ".length+e.length>i&&(n.push(n.length?t.trimStart():t),t=""),t+=e}),n.push(n.length?t.trimStart():t),n.forEach((e,i)=>console.info("| "+(0==i?e:" ".repeat(r)+e)))}})),console.info(`
|
|
30
|
+
${h.info_moreHelp||"For more help"}, ${h.info_visit||"visit"}: ${d}${docURL}[0m`)}function j(){console.info(`
|
|
31
|
+
${h.info_moreHelp||"For more help"}, ${h.info_type||"type"} minify-js --help' ${h.info_or||"or"} ${h.info_visit||"visit"}
|
|
32
|
+
${d}${docURL}[0m`)}function S(e){$.quietMode||console.info(e)}})();
|
package/dist/minify.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
let fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(r,n={}){var e="https://docs.minify-js.org/node.js/#findjssearchdir-options",
|
|
1
|
+
let fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(r,n={}){var e="https://docs.minify-js.org/node.js/#findjssearchdir-options",o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,ignores:[]};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 i=path.resolve(process.cwd(),r);if(fs.existsSync(i)){if(validateOptions(n,o,e,"findJS('assets/js', { verbose: false, dotFoldes: true })")){n={...o,...n};let e=fs.readdirSync(r),i=[];return n.verbose&&!n.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),e.forEach(e=>{let o=path.resolve(r,e);n.ignores.some(i=>i.endsWith("/")?o.split(path.sep).some(e=>e==i.replace(/\/$/,"")):e==i)?n.verbose&&console.info(`findJS() » ** ${e} ignored`):fs.statSync(o).isDirectory()&&"node_modules"!=e&&n.recursive&&(n.dotFolders||!e.startsWith("."))?i.push(...findJS(o,{...n,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!n.dotFiles&&e.startsWith(".")||i.push(o)}),n.verbose&&!n.isRecursing&&(console.info("findJS() » Search complete! "+(0==i.length?"No":i.length)+` file${1==i.length?"":"s"} found.`),"minify"!=findJS.caller?.name)&&"undefined"!=typeof window&&console.info("findJS() » Check returned array."),n.isRecursing||i.length?i:[]}}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${i} does not exist.`),console.info("findJS() » For more help, please visit "+e)}}function minify(n,s={}){var e="https://docs.minify-js.org/node.js/#minifyinput-options",i={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,rewriteImports:!1,relativeOutput:!1,ignores:[],comment:""};if("string"!=typeof n)console.error("minify() » ERROR: 1st arg <input> must be a string."),console.info("minify() » For more help, please visit "+e);else if(validateOptions(s,i,e,"minify('assets/js', { recursive: false, mangle: false })")){let r={mangle:!!(s={...i,...s}).mangle&&{toplevel:!1}};if(fs.existsSync(n)){if(n.endsWith(".js"))return s.verbose&&console.info(`minify() » ** Minifying ${n}...`),e=uglifyJS.minify(fs.readFileSync(n,"utf8"),r),s.comment&&(e.code=t(e.code,s.comment)),e.error?console.error("minify() » ERROR: "+e.error.message):s.verbose&&"undefined"!=typeof window&&console.info("minify() » Minification complete! Check returned object."),{code:e.code,srcPath:path.resolve(process.cwd(),n),error:e.error};i=findJS(n,s)?.map(e=>{s.verbose&&console.info(`minify() » ** Minifying ${e}...`);var i=fs.readFileSync(e,"utf8"),i=uglifyJS.minify(i,r);let o;return s.comment&&(i.code=t(i.code,s.comment)),i.error&&console.error("minify() » ERROR: "+i.error.message),s.relativeOutput||(o=path.relative(path.resolve(process.cwd(),n),e)),{code:i.code,srcPath:e,relPath:o,error:i.error}}).filter(e=>!e.error);if(s.verbose&&(i.length&&"undefined"!=typeof window?console.info("minify() » Minification complete! Check returned object."):console.info("minify() » No unminified JavaScript files processed.")),s.rewriteImports&&i&&1<i.length){s.verbose&&console.info("minify() » ** Rewriting import paths...");let e=i.map(e=>path.basename(e.srcPath,".js"));i.forEach(r=>e.forEach(e=>{var i=new RegExp(`(\\./?)?\\b${e}\\.js(['"])`,"g"),o=r.code;r.code=r.code.replace(i,`$1${e}.min.js$2`),o!=r.code&&s.verbose&&console.info(`minify() » Updated ${e}.js in `+path.basename(r.srcPath))})),s.verbose&&console.info("minify() » Import paths rewritten.")}return i}return s.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » ** Minifying passed source code..."),e=uglifyJS.minify(n,r),s.comment&&(e.code=t(e.code,s.comment)),e.error?console.error("minify() » ERROR: "+e.error.message):s.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » Minification complete! Check returned object."),{code:e.code,srcPath:void 0,error:e.error};function t(e,i){var i=i.split("\n").map(e=>" * "+e).join("\n"),o=e.indexOf("#!");return 0<=o?(o=e.indexOf("\n",o)+1,e.slice(0,o)+`/**
|
|
2
2
|
/**
|
|
3
|
-
* © 2023–
|
|
3
|
+
* © 2023–2026 Adam Lui & contributors under the MIT license.
|
|
4
4
|
* Source: https://code.minify-js.org/node.js
|
|
5
5
|
* Documentation: https://docs.minify-js.org/node.js
|
|
6
6
|
*/
|
|
@@ -9,4 +9,4 @@ ${i}
|
|
|
9
9
|
`+e.slice(o)):`/**
|
|
10
10
|
${i}
|
|
11
11
|
*/
|
|
12
|
-
`+e}}}function validateOptions(e,i,o,r){let n=JSON.stringify(i,void 0,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),s=Object.keys(i).join(", "),t=Object.keys(i).filter(e=>"boolean"==typeof i[e]),l=Object.keys(i).filter(e=>Number.isInteger(i[e])),
|
|
12
|
+
`+e}}}function validateOptions(e,i,o,r){let n=JSON.stringify(i,void 0,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),s=Object.keys(i).join(", "),t=Object.keys(i).filter(e=>"boolean"==typeof i[e]),l=Object.keys(i).filter(e=>Number.isInteger(i[e])),f=Object.keys(i).filter(e=>Array.isArray(i[e])),c=`${validateOptions.caller?.name||"validateOptions"}() » `;var a,d=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1,p=(d+=["st","nd","rd"][d-1]||"th",()=>{console.info(c+"For more help, please visit "+o)});if("object"!=typeof e)return console.error(c+`ERROR: ${"0th"==d?"[O":d+" arg [o"}ptions] can only be an object of key/values.`),console.info(c+"Example valid call: "+r),console.info(c+`Valid options: [ ${s} ]`),console.info(c+"If omitted, default settings are: "+n),p(),!1;for(a in e)if("isRecursing"==a||Object.prototype.hasOwnProperty.call(i,a)){if(t.includes(a)&&"boolean"!=typeof e[a])return console.error(c+`ERROR: [${a}] option can only be \`true\` or \`false\`.`),p(),!1;if(l.includes(a)){if(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.`),p(),!1}else if(f.includes(a))if("string"!=typeof e[a]||e[a].includes(",")){if(!Array.isArray(e[a]))return console.error(c+`ERROR: [${a}] option can only be an array.`),p(),!1}else e[a]=[e[a]]}return!0}let mjsAliases={minify:["build","Build","compile","Compile","compress","Compress","Minify"],findJS:["find","Find","findjs","findJs","Findjs","FindJs","FindJS","search","Search"]};module.exports={minify:minify,findJS:findJS};for(let i in mjsAliases)mjsAliases[i].forEach(e=>module.exports[e]=module.exports[i]);
|
package/docs/LICENSE.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
# 🏛️ MIT License
|
|
21
21
|
|
|
22
|
-
**Copyright © 2023–
|
|
22
|
+
**Copyright © 2023–2026 [Adam Lui](https://github.com/adamlui) & contributors.**
|
|
23
23
|
|
|
24
24
|
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:
|
|
25
25
|
|
package/docs/README.md
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
<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>
|
|
26
26
|
<a href="#%EF%B8%8F-mit-license">
|
|
27
27
|
<img height=31 src="https://img.shields.io/badge/License-MIT-fc4f2d.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
28
|
-
<a href="https://github.com/adamlui/minify.js/releases/tag/node-
|
|
29
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-
|
|
28
|
+
<a href="https://github.com/adamlui/minify.js/releases/tag/node-v2.0.0">
|
|
29
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
30
30
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code">
|
|
31
31
|
<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>
|
|
32
32
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js">
|
|
@@ -87,7 +87,7 @@ $ minify-js [input_path] [output_path]
|
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
- `[input_path]`: Path to JS file or directory containing JS files to be minified, relative to the current working directory.
|
|
90
|
-
- `[output_path]`: Path to file or directory where minified files will be stored, relative to
|
|
90
|
+
- `[output_path]`: Path to file or directory where minified files will be stored, relative to input root (if not provided, `min/` is used).
|
|
91
91
|
|
|
92
92
|
**📝 Note:** If folders are passed, files will be processed recursively unless `-R` or `--no-recursion` is passed.
|
|
93
93
|
|
|
@@ -113,13 +113,13 @@ Minify all JavaScript files in the **current directory** (outputs to `min/`):
|
|
|
113
113
|
$ minify-js
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory
|
|
116
|
+
Minify all JavaScript files in a **specific directory** (outputs to `min/path/to/your/directory/`):
|
|
117
117
|
|
|
118
118
|
```
|
|
119
119
|
$ minify-js path/to/your/directory
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
Minify a **specific file** (outputs to `path/to/your/
|
|
122
|
+
Minify a **specific file** (outputs to `min/path/to/your/file.min.js`):
|
|
123
123
|
|
|
124
124
|
```
|
|
125
125
|
$ minify-js path/to/your/file.js
|
|
@@ -144,14 +144,15 @@ Boolean options:
|
|
|
144
144
|
-R, --no-recursion Disable recursive file searching.
|
|
145
145
|
-M, --no-mangle Disable mangling names.
|
|
146
146
|
-X, --no-filename-change Disable changing file extension to .min.js
|
|
147
|
+
-i, --rewrite-imports Update import paths from .js to .min.js
|
|
147
148
|
-c, --copy Copy minified code to clipboard instead
|
|
148
149
|
of writing to file if single source file
|
|
149
150
|
is processed.
|
|
150
|
-
-
|
|
151
|
+
-r, --relative-output Output files relative to each source file instead of to input root.
|
|
151
152
|
-q, --quiet Suppress all logging except errors.
|
|
152
153
|
|
|
153
154
|
Parameter options:
|
|
154
|
-
--
|
|
155
|
+
--ignores="dir/,file1.js,file2.js" Files/directories to exclude from minification.
|
|
155
156
|
--comment="comment" Prepend header comment to minified code.
|
|
156
157
|
Separate by line using '\n'.
|
|
157
158
|
|
|
@@ -220,16 +221,17 @@ minifyJS.minify(input, { dotFiles: true });
|
|
|
220
221
|
|
|
221
222
|
Available parameters (and their default settings) are:
|
|
222
223
|
|
|
223
|
-
Name
|
|
224
|
-
|
|
225
|
-
`recursive`
|
|
226
|
-
`verbose`
|
|
227
|
-
`dotFolders`
|
|
228
|
-
`dotFiles`
|
|
229
|
-
`mangle`
|
|
230
|
-
`
|
|
231
|
-
`
|
|
232
|
-
`
|
|
224
|
+
Name | Type | Desciption | Default value
|
|
225
|
+
-----------------|---------|--------------------------------------------------------------------------|---------------
|
|
226
|
+
`recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
|
|
227
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
228
|
+
`dotFolders` | Boolean | Include dotfolders in file search. | `false`
|
|
229
|
+
`dotFiles` | Boolean | Include dotfiles in file search. | `false`
|
|
230
|
+
`mangle` | Boolean | Shorten variable names (typically to one character). | `true`
|
|
231
|
+
`rewriteImports` | Boolean | Update import paths from .js to .min.js | `false`
|
|
232
|
+
`relativeOutput` | Boolean | Output files relative to each source file instead of to input root. | `false`
|
|
233
|
+
`ignores` | Array | Files/dirs to exclude from minification. | `[]`
|
|
234
|
+
`comment` | String | Header comment to prepend to minified code. Separate by line using '\n'. | `''`
|
|
233
235
|
|
|
234
236
|
#
|
|
235
237
|
|
|
@@ -264,7 +266,7 @@ Name | Type | Desciption
|
|
|
264
266
|
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
265
267
|
`dotFolders` | Boolean | Include dotfolders in file search. | `false`
|
|
266
268
|
`dotFiles` | Boolean | Include dotfiles in file search. | `false`
|
|
267
|
-
`
|
|
269
|
+
`ignores` | Array | Files/dirs to exclude from search results. | `[]`
|
|
268
270
|
|
|
269
271
|
<br>
|
|
270
272
|
|
|
@@ -272,7 +274,7 @@ Name | Type | Desciption
|
|
|
272
274
|
|
|
273
275
|
## 🏛️ MIT License
|
|
274
276
|
|
|
275
|
-
**Copyright © 2023–
|
|
277
|
+
**Copyright © 2023–2026 [Adam Lui](https://github.com/adamlui) & contributors.**
|
|
276
278
|
|
|
277
279
|
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:
|
|
278
280
|
|