@adamlui/minify.js 1.8.6 → 1.9.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 CHANGED
@@ -24,9 +24,9 @@
24
24
  <a href="https://www.npmjs.com/package/@adamlui/minify.js">
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
- <img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
28
- <a href="https://github.com/adamlui/minify.js/releases/tag/node-v1.8.6">
29
- <img height=31 src="https://img.shields.io/badge/Latest_Build-1.8.6-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
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-v1.9.0">
29
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-1.9.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">
@@ -147,6 +147,7 @@ Boolean options:
147
147
  -c, --copy Copy minified code to clipboard instead
148
148
  of writing to file if single source file
149
149
  is processed.
150
+ -C, --clone-folders Preserve folder structure in output directory.
150
151
  -q, --quiet Suppress all logging except errors.
151
152
 
152
153
  Parameter options:
@@ -219,15 +220,16 @@ minifyJS.minify(input, { dotFiles: true });
219
220
 
220
221
  Available parameters (and their default settings) are:
221
222
 
222
- Name | Type | Desciption | Default value
223
- --------------|---------|--------------------------------------------------------------------------|---------------
224
- `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
225
- `verbose` | Boolean | Show logging in console/terminal. | `true`
226
- `dotFolders` | Boolean | Include dotfolders in file search. | `false`
227
- `dotFiles` | Boolean | Include dotfiles in file search. | `false`
228
- `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
229
- `ignoreFiles` | Array | Files (by name) to exclude from minification. | `[]`
230
- `comment` | String | Header comment to prepend to minified code. Separate by line using '\n'. | `''`
223
+ Name | Type | Desciption | Default value
224
+ ---------------|---------|--------------------------------------------------------------------------|---------------
225
+ `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
226
+ `verbose` | Boolean | Show logging in console/terminal. | `true`
227
+ `dotFolders` | Boolean | Include dotfolders in file search. | `false`
228
+ `dotFiles` | Boolean | Include dotfiles in file search. | `false`
229
+ `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
230
+ `cloneFolders` | Boolean | Preserve folder structure in output directory. | `false`
231
+ `ignoreFiles` | Array | Files (by name) to exclude from minification. | `[]`
232
+ `comment` | String | Header comment to prepend to minified code. Separate by line using '\n'. | `''`
231
233
 
232
234
  #
233
235
 
package/dist/cli.min.js CHANGED
@@ -4,28 +4,28 @@
4
4
  * Source: https://code.minify-js.org/node.js
5
5
  * Documentation: https://docs.minify-js.org/node.js
6
6
  */
7
- const pkgName="@adamlui/minify.js",copyright="© 2024–2025 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="55480ff";(async()=>{const o=require(__dirname.match(/src/)?"./minify":"./minify.min"),n=require("fs"),s=require("path"),i=require("node-clipboardy"),t=require("child_process")["execSync"],r="",a="",l="",c="",m="";let f="en";if("win32"==process.platform)try{f=t("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){v("Error loading system language: "+e)}else{var d=process.env;f=(d.LANG||d.LANGUAGE||d.LC_ALL||d.LC_MESSAGES||d.LC_NAME||"en").split(".")[0]}let p={};d=new Promise((t,r)=>{const a=`https://cdn.jsdelivr.net/gh/adamlui/minify.js@4b4ef9ec6a56f685d2f38a4692be638f77fb93e3/_locales/`,e=`${f?f.replace("-","_"):"en"}/`;let l=a+e+"messages.json",c=0;$(l).then(async function i(e){try{const o=await e.json(),n={};for(const s in o)"object"==typeof o[s]&&"message"in o[s]&&(n[s]=o[s].message);t(n)}catch(e){if(3==++c)return t({});$(l=f.includes("-")&&1==c?l.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):a+"en/messages.json").then(i).catch(r)}}).catch(r)});try{p=await d}catch(e){v("Error fetching messages: "+e)}const g={},h={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))$/,copy:/^--?c(?:opy)?$/,quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},paramOptions:{ignoreFiles:/^--?(?:ignore|skip|exclude)(?:d?-?files?)?(?:=.*|$)/,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(h.flags).find(e=>h.flags[e].test(i)),e=Object.keys(h.paramOptions).find(e=>h.paramOptions[e].test(i)),o=Object.keys(h.infoCmds).find(e=>h.infoCmds[e].test(i)),n?g[n]=!0:e?(/=.+/.test(i)||(console.error(`
8
- ${a+(p.prefix_error||"ERROR")}: `+`Arg [--${i.replace(/-/g,"")}] `+`${p.error_noEqual||"requires '=' followed by a value"}.${r}`),_(),process.exit(1)),n=i.split("=")[1],g[e]=parseInt(n)||n):o||(console.error(`
9
- ${a+(p.prefix_error||"ERROR")}: `+`Arg [${i}] ${p.error_notRecognized||"not recognized"}.`),console.info(`
10
- ${l+(p.info_validArgs||"Valid arguments are below")}.`),y(["flags","paramOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>h.infoCmds.help.test(e)))y();else if(process.argv.some(e=>h.infoCmds.version.test(e))){d=t(`npm view ${pkgName} version`).toString().trim()||"none";let e,i=process.cwd();for(;"/"!=i;){var u=s.join(i,"package.json");if(n.existsSync(u)){u=require(u);e=(u.dependencies?.[pkgName]||u.devDependencies?.[pkgName])?.match(/^\d+\.\d+\.\d+$/)?.[0]||"none";break}i=s.dirname(i)}console.info(`
11
- ${p.prefix_globalVer||"Global version"}: `+d),console.info(`${p.prefix_localVer||"Local version"}: `+e)}else{const[j="",S=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,""));let e=s.resolve(process.cwd(),j);j&&!n.existsSync(e)&&(d=e+".js",n.existsSync(d)?e=d:(console.error(`
12
- ${a+(p.prefix_error||"ERROR")}: `+`${p.error_firstArgNotExist||"First argument can only be an existing file or directory"}.`+`
13
- ${e} ${p.error_doesNotExist||"does not exist"}.`),console.info(`
14
- ${c}${p.info_exampleValidCmd||"Example valid command"}: `+`
15
- » minify-js . output.min.js`),_(),process.exit(1)));d=e.endsWith(".js")&&!n.statSync(e).isDirectory()?[e]:o.findJS(e,{recursive:!g.noRecursion,verbose:!g.quietMode,ignoreFiles:(g.ignoreFiles?.split(",")??[]).map(e=>e.trim())});if(g.dryRun)0<d.length?(console.info(`
16
- ${l+(p.info_filesToBeMinned||"JS files to be minified")}:`),d.forEach(e=>console.info(e))):console.info(`
17
- ${l+(p.info_noFilesWillBeMinned||"No JS files will be minified")}.`);else{const b=[];d=d.map(e=>{var i=o.minify(e,{verbose:!g.quietMode,mangle:!g.noMangle,comment:g.comment?.replace(/\\n/g,"\n")});return i.error&&b.push(e),i}).filter(e=>!e.error);0<d?.length?(v(`
18
- ${c+(p.info_minComplete||"Minification complete")}!`),v(m+d.length+" "+(p.info_file||"file")+`${1<d.length?"s":""} ${p.info_minified||"minified"}.${r}`)):v(`
19
- ${l+(p.info_noFilesProcessed||"No unminified JavaScript files processed")}.`),0<b.length&&(v(`
20
- ${a+b.length} `+(p.info_file||"file")+`${1<b.length?"s":""} ${p.info_failedToMinify||"failed to minify"}:${r}`),b.forEach(e=>v(e))),0!=d?.length&&(g.copy&&1==d?.length?(console.log(`
21
- `+m+d[0].code+r),v(`
22
- ${p.info_copying||"Copying to clipboard"}...`),i.writeSync(d[0].code)):(v(`
23
- ${p.info_writing||"Writing to file"}${1<d?.length?"s":""}...`),d?.forEach(({code:e,srcPath:i})=>{var o=s.join(s.dirname(i),(/so?u?rce?$/.test(s.dirname(i))?"../":"")+(S.endsWith(".js")?s.dirname(S):S||"min")),i=(S.endsWith(".js")&&j.endsWith(".js")?s.basename(S).replace(/(\.min)?\.js$/,""):s.basename(i,".js"))+`${g.noFilenameChange?"":".min"}.js`,i=s.join(o,i);n.existsSync(o)||n.mkdirSync(o,{recursive:!0}),n.writeFileSync(i,e,"utf8")})))}}function $(n){return new Promise((o,e)=>{var i=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(i)||e(new Error(`${p.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 y(e=["header","usage","pathArgs","flags","paramOptions","infoCmds"]){var i=` ${pkgName.replace(/^@[^/]+\//,"")}  `;const o={header:["\n├ "+i+(p.appCopyright||copyright),i+(p.prefix_source||"Source")+": "+srcURL],usage:[`
24
- ${m}o ${p.helpSection_usage||"Usage"}:`,` ${m}» `+c+cmdFormat+r],pathArgs:[`
25
- ${m}o ${p.helpSection_pathArgs||"Path arguments"}:`," [inputPath] "+`${p.inputPathDesc_main||"Path to JS file or directory containing JS files to be minified"}, `+`${p.inputPathDesc_extra||"relative to the current working directory"}.`," [outputPath] "+`${p.outputPathDesc_main||"Path to file or directory where minified files will be stored"}, `+`${p.outputPathDesc_extra||"relative to original file location (if not provided, min/ is used)"}.`],flags:[`
26
- ${m}o ${p.helpSection_flags||"Boolean options"}:`," -n, --dry-run "+`${p.optionDesc_dryRun||"Don't actually minify the file(s), just show if they will be processed"}.`,` -d, --include-dotfolders ${p.optionDesc_dotfolders||"Include dotfolders in file search"}.`,` -D, --include-dotfiles ${p.optionDesc_dotfiles||"Include dotfiles in file search"}.`,` -R, --no-recursion ${p.optionDesc_noRecursion||"Disable recursive file searching"}.`,` -M, --no-mangle ${p.optionDesc_noMangle||"Disable mangling names"}.`," -X, --no-filename-change "+(p.optionDesc_noFilenameChange||"Disable changing file extension to .min.js"),` -c, --copy ${p.optionDesc_copy||"Copy minified code to clipboard instead of writing to file if single source file is processed"}.`,` -q, --quiet ${p.optionDesc_quiet||"Suppress all logging except errors"}.`],paramOptions:[`
27
- ${m}o ${p.helpSection_paramOptions||"Parameter options"}:`,`--ignore-files="file1.js,file2.js" ${p.optionDesc_ignoreFiles||"Files to exclude from minification"}.`,`--comment="comment" ${p.optionDesc_commentMain||"Prepend header comment to minified code"}.`+` ${p.optionDesc_commentExtra||"Separate by line using '\\n'"}.`],infoCmds:[`
28
- ${m}o ${p.helpSection_infoCmds||"Info commands"}:`," -h, --help "+(p.optionDesc_help||"Display help screen."),` -v, --version ${p.optionDesc_version||"Show version number"}.`]};e.forEach(r=>o[r]?.forEach(e=>{{var n=/header|usage/.test(r)?1:37;const s=process.stdout.columns||80,t=[],i=e.match(/\S+|\s+/g);let o="";i.forEach(e=>{var i=s-(t.length?n:0);o.length+"| ".length+e.length>i&&(t.push(t.length?o.trimStart():o),o=""),o+=e}),t.push(t.length?o.trimStart():o),t.forEach((e,i)=>console.info("| "+(0==i?e:" ".repeat(n)+e)))}})),console.info(`
29
- ${p.info_moreHelp||"For more help"}, ${p.info_visit||"visit"}: `+m+docURL+r)}function _(){console.info(`
30
- ${p.info_moreHelp||"For more help"}, ${p.info_type||"type"} minify-js --help' ${p.info_or||"or"} ${p.info_visit||"visit"}
31
- `+m+docURL+r)}function v(e){g.quietMode||console.info(e)}})();
7
+ let pkgName="@adamlui/minify.js",copyright="© 2024–2025 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="b84f3d2";(async()=>{let n=require(__dirname.match(/src/)?"./minify":"./minify.min"),a=require("fs"),c=require("path"),s=require("node-clipboardy"),i=require("child_process").execSync,r="",m="",d="",f="",p="",g="en";if("win32"==process.platform)try{g=i("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){b("Error loading system language: "+e)}else{var h=process.env;g=(h.LANG||h.LANGUAGE||h.LC_ALL||h.LC_MESSAGES||h.LC_NAME||"en").split(".")[0]}let u={};h=new Promise((s,r)=>{let t=`https://cdn.jsdelivr.net/gh/adamlui/minify.js@7d9303ba4d54953b22ec7136a557df2923069fc4/_locales/`,e=`${g?g.replace("-","_"):"en"}/`,l=t+e+"messages.json",a=0;_(l).then(async function o(i){try{let e=await i.json(),o={};for(var n in e)"object"==typeof e[n]&&"message"in e[n]&&(o[n]=e[n].message);s(o)}catch(e){if(3==++a)return s({});_(l=g.includes("-")&&1==a?l.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):t+"en/messages.json").then(o).catch(r)}}).catch(r)});try{u=await h}catch(e){b("Error fetching messages: "+e)}let $={},t={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))$/,cloneFolders:/^--?(?:C|clone-?folders?=?(?:true|1)?)$/,copy:/^--?c(?:opy)?$/,quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},paramOptions:{ignoreFiles:/^--?(?:ignore|skip|exclude)(?:d?-?files?)?(?:=.*|$)/,comment:/^--?comments?(?:=.*|$)/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(o=>{var e,i,n;o.startsWith("-")&&(n=Object.keys(t.flags).find(e=>t.flags[e].test(o)),e=Object.keys(t.paramOptions).find(e=>t.paramOptions[e].test(o)),i=Object.keys(t.infoCmds).find(e=>t.infoCmds[e].test(o)),n?$[n]=!0:e?(/=.+/.test(o)||(console.error(`
8
+ ${m+(u.prefix_error||"ERROR")}: `+`Arg [--${o.replace(/-/g,"")}] `+`${u.error_noEqual||"requires '=' followed by a value"}.${r}`),j(),process.exit(1)),n=o.split("=")[1],$[e]=parseInt(n)||n):i||(console.error(`
9
+ ${m+(u.prefix_error||"ERROR")}: `+`Arg [${o}] ${u.error_notRecognized||"not recognized"}.`),console.info(`
10
+ ${d+(u.info_validArgs||"Valid arguments are below")}.`),v(["flags","paramOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>t.infoCmds.help.test(e)))v();else if(process.argv.some(e=>t.infoCmds.version.test(e))){h=i(`npm view ${pkgName} version`).toString().trim()||"none";let e,o=process.cwd();for(;"/"!=o;){var l=c.join(o,"package.json");if(a.existsSync(l)){l=require(l);e=(l.dependencies?.[pkgName]||l.devDependencies?.[pkgName])?.match(/^\d+\.\d+\.\d+$/)?.[0]||"none";break}o=c.dirname(o)}console.info(`
11
+ ${u.prefix_globalVer||"Global version"}: `+h),console.info(`${u.prefix_localVer||"Local version"}: `+e)}else{let[t="",l=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),o=c.resolve(process.cwd(),t);t&&!a.existsSync(o)&&(h=o+".js",a.existsSync(h)?o=h:(console.error(`
12
+ ${m+(u.prefix_error||"ERROR")}: `+`${u.error_firstArgNotExist||"First argument can only be an existing file or directory"}.`+`
13
+ ${o} ${u.error_doesNotExist||"does not exist"}.`),console.info(`
14
+ ${f}${u.info_exampleValidCmd||"Example valid command"}: `+`
15
+ » minify-js . output.min.js`),j(),process.exit(1)));var y,h=o.endsWith(".js")&&!a.statSync(o).isDirectory()?[o]:n.findJS(o,{recursive:!$.noRecursion,verbose:!$.quietMode,ignoreFiles:($.ignoreFiles?.split(",")??[]).map(e=>e.trim())});if($.dryRun)h.length?(console.info(`
16
+ ${d+(u.info_filesToBeMinned||"JS files to be minified")}:`),h.forEach(e=>console.info(e))):console.info(`
17
+ ${d+(u.info_noFilesWillBeMinned||"No JS files will be minified")}.`);else{let i=[],e=[];$.cloneFolders&&a.statSync(o).isDirectory()?(y=n.minify(o,{verbose:!$.quietMode,mangle:!$.noMangle,comment:$.comment?.replace(/\\n/g,"\n"),cloneFolders:!0,recursive:!$.noRecursion,dotFolders:!!$.includeDotFolders,dotFiles:!!$.includeDotFiles,ignoreFiles:$.ignoreFiles?$.ignoreFiles.split(",").map(e=>e.trim()):[]}),Array.isArray(y)?e=y:y&&y.error?i.push(o):y&&(e=[y])):e=h.map(e=>{var o=n.minify(e,{verbose:!$.quietMode,mangle:!$.noMangle,comment:$.comment?.replace(/\\n/g,"\n")});return o.error&&i.push(e),o}).filter(e=>!e.error),e?.length?(b(`
18
+ ${f+(u.info_minComplete||"Minification complete")}!`),b(p+e.length+" "+(u.info_file||"file")+`${1<e.length?"s":""} ${u.info_minified||"minified"}.${r}`)):b(`
19
+ ${d+(u.info_noFilesProcessed||"No unminified JavaScript files processed")}.`),i.length&&(b(`
20
+ ${m+i.length} `+(u.info_file||"file")+`${1<i.length?"s":""} ${u.info_failedToMinify||"failed to minify"}:${r}`),i.forEach(e=>b(e))),0!=e?.length&&($.copy&&1==e?.length?(console.log(`
21
+ `+p+e[0].code+r),b(`
22
+ ${u.info_copying||"Copying to clipboard"}...`),s.writeSync(e[0].code)):(b(`
23
+ ${u.info_writing||"Writing to file"}${1<e?.length?"s":""}...`),e?.forEach(({code:e,srcPath:i,relPath:n})=>{let s,r;if($.cloneFolders&&n&&l){let e=c.resolve(process.cwd(),l),o=c.dirname(n);s="."!=o?c.join(e,o):e,r=c.basename(i,".js")+`${$.noFilenameChange?"":".min"}.js`}else s=c.join(c.dirname(i),(/so?u?rce?$/.test(c.dirname(i))?"../":"")+(l.endsWith(".js")?c.dirname(l):l||"min")),r=(l.endsWith(".js")&&t.endsWith(".js")?c.basename(l).replace(/(\.min)?\.js$/,""):c.basename(i,".js"))+`${$.noFilenameChange?"":".min"}.js`;let o=c.join(s,r);a.existsSync(s)||a.mkdirSync(s,{recursive:!0}),a.writeFileSync(o,e,"utf8"),b(` ${f}✓ `+c.relative(process.cwd(),o))})))}}function _(n){return new Promise((i,e)=>{var o=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(o)||e(new Error(`${u.error_invalidURL||"Invalid URL"}.`)),require(o).get(n,e=>{let o="";e.on("data",e=>o+=e),e.on("end",()=>i({json:()=>JSON.parse(o)}))}).on("error",e)})}function v(e=["header","usage","pathArgs","flags","paramOptions","infoCmds"]){var o=` ${pkgName.replace(/^@[^/]+\//,"")}  `;let i={header:["\n├ "+o+(u.appCopyright||copyright),o+(u.prefix_source||"Source")+": "+srcURL],usage:[`
24
+ ${p}o ${u.helpSection_usage||"Usage"}:`,` ${p}» `+f+cmdFormat+r],pathArgs:[`
25
+ ${p}o ${u.helpSection_pathArgs||"Path arguments"}:`," [inputPath] "+`${u.inputPathDesc_main||"Path to JS file or directory containing JS files to be minified"}, `+`${u.inputPathDesc_extra||"relative to the current working directory"}.`," [outputPath] "+`${u.outputPathDesc_main||"Path to file or directory where minified files will be stored"}, `+`${u.outputPathDesc_extra||"relative to original file location (if not provided, min/ is used)"}.`],flags:[`
26
+ ${p}o ${u.helpSection_flags||"Boolean options"}:`," -n, --dry-run "+`${u.optionDesc_dryRun||"Don't actually minify the file(s), just show if they will be processed"}.`,` -d, --include-dotfolders ${u.optionDesc_dotfolders||"Include dotfolders in file search"}.`,` -D, --include-dotfiles ${u.optionDesc_dotfiles||"Include dotfiles in file search"}.`,` -R, --no-recursion ${u.optionDesc_noRecursion||"Disable recursive file searching"}.`,` -M, --no-mangle ${u.optionDesc_noMangle||"Disable mangling names"}.`," -X, --no-filename-change "+(u.optionDesc_noFilenameChange||"Disable changing file extension to .min.js"),` -c, --copy ${u.optionDesc_copy||"Copy minified code to clipboard instead of writing to file if single source file is processed"}.`,` -C, --clone-folders ${u.optionDesc_cloneFolders||"Preserve folder structure in output directory"}.`,` -q, --quiet ${u.optionDesc_quiet||"Suppress all logging except errors"}.`],paramOptions:[`
27
+ ${p}o ${u.helpSection_paramOptions||"Parameter options"}:`,`--ignore-files="file1.js,file2.js" ${u.optionDesc_ignoreFiles||"Files to exclude from minification"}.`,`--comment="comment" ${u.optionDesc_commentMain||"Prepend header comment to minified code"}.`+` ${u.optionDesc_commentExtra||"Separate by line using '\\n'"}.`],infoCmds:[`
28
+ ${p}o ${u.helpSection_infoCmds||"Info commands"}:`," -h, --help "+(u.optionDesc_help||"Display help screen."),` -v, --version ${u.optionDesc_version||"Show version number"}.`]};e.forEach(t=>i[t]?.forEach(o=>{{var r=/header|usage/.test(t)?1:37;let i=process.stdout.columns||80,n=[],e=o.match(/\S+|\s+/g),s="";e.forEach(e=>{var o=i-(n.length?r:0);s.length+"| ".length+e.length>o&&(n.push(n.length?s.trimStart():s),s=""),s+=e}),n.push(n.length?s.trimStart():s),n.forEach((e,o)=>console.info("| "+(0==o?e:" ".repeat(r)+e)))}})),console.info(`
29
+ ${u.info_moreHelp||"For more help"}, ${u.info_visit||"visit"}: `+p+docURL+r)}function j(){console.info(`
30
+ ${u.info_moreHelp||"For more help"}, ${u.info_type||"type"} minify-js --help' ${u.info_or||"or"} ${u.info_visit||"visit"}
31
+ `+p+docURL+r)}function b(e){$.quietMode||console.info(e)}})();
@@ -1,13 +1,12 @@
1
- #!/usr/bin/env node
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",i={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,ignoreFiles:[]};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 o=path.resolve(process.cwd(),r);if(fs.existsSync(o)){if(validateOptions(n,i,e,"findJS('assets/js', { verbose: false, dotFoldes: true })")){n={...i,...n};let e=fs.readdirSync(r),o=[];return n.verbose&&!n.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),e.forEach(e=>{var i=path.resolve(r,e);fs.statSync(i).isDirectory()&&"node_modules"!=e&&n.recursive&&(n.dotFolders||!e.startsWith("."))?o.push(...findJS(i,{...n,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!n.dotFiles&&e.startsWith(".")||n.ignoreFiles.includes(e)?n.verbose&&n.ignoreFiles.includes(e)&&console.info(`findJS() » ** ${e} ignored due to [options.ignoreFiles]`):o.push(i)}),n.verbose&&!n.isRecursing&&(console.info("findJS() » Search complete! "+(0==o.length?"No":o.length)+` file${1==o.length?"":"s"} found.`),"minify"!=findJS.caller?.name)&&"undefined"!=typeof window&&console.info("findJS() » Check returned array."),n.isRecursing||o.length?o:[]}}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${o} 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,cloneFolders:!1,ignoreFiles:[],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}};return fs.existsSync(n)?n.endsWith(".js")?(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,{recursive:s.recursive,verbose:s.verbose,dotFolders:s.dotFolders,dotFiles:s.dotFiles,ignoreFiles:s.ignoreFiles})?.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.cloneFolders&&(o=path.relative(path.resolve(process.cwd(),n),e)),{code:i.code,srcPath:e,relPath:o,error:i.error}}).filter(e=>!e.error),s.verbose&&(i.length&&"undefined"!=typeof window?console.info("minify() » Minification complete! Check returned object."):console.info("minify() » No unminified JavaScript files processed.")),i):(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
3
  * © 2023–2025 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
- const fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(o,n={}){var e="https://docs.minify-js.org/node.js/#findjssearchdir-options",i={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,ignoreFiles:[]};if("string"!=typeof o)console.error("findJS() » ERROR: 1st arg <searchDir> must be a string."),console.info("findJS() » For more help, please visit "+e);else{var r=path.resolve(process.cwd(),o);if(fs.existsSync(r)){if(validateOptions(n,i,e,"findJS('assets/js', { verbose: false, dotFoldes: true })")){n={...i,...n};const s=fs.readdirSync(o),t=[];return n.verbose&&!n.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),s.forEach(e=>{var i=path.resolve(o,e);fs.statSync(i).isDirectory()&&"node_modules"!=e&&n.recursive&&(n.dotFolders||!e.startsWith("."))?t.push(...findJS(i,{...n,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!n.dotFiles&&e.startsWith(".")||n.ignoreFiles.includes(e)?n.verbose&&n.ignoreFiles.includes(e)&&console.info(`findJS() » ** ${e} ignored due to [options.ignoreFiles]`):t.push(i)}),n.verbose&&!n.isRecursing&&(console.info("findJS() » Search complete! "+(0==t.length?"No":t.length)+` file${1==t.length?"":"s"} found.`),"minify"!=findJS.caller.name)&&"undefined"!=typeof window&&console.info("findJS() » Check returned array."),n.isRecursing||0<t.length?t:[]}}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${r} does not exist.`),console.info("findJS() » For more help, please visit "+e)}}function minify(e,o={}){var i="https://docs.minify-js.org/node.js/#minifyinput-options",n={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,ignoreFiles:[],comment:""};if("string"!=typeof e)console.error("minify() » ERROR: 1st arg <input> must be a string."),console.info("minify() » For more help, please visit "+i);else if(validateOptions(o,n,i,"minify('assets/js', { recursive: false, mangle: false })")){const s={mangle:!!(o={...n,...o}).mangle&&{toplevel:!1}};return fs.existsSync(e)?e.endsWith(".js")?(o.verbose&&console.info(`minify() » ** Minifying ${e}...`),i=uglifyJS.minify(fs.readFileSync(e,"utf8"),s),o.comment&&(i.code=r(i.code,o.comment)),i.error?console.error("minify() » ERROR: "+i.error.message):o.verbose&&"undefined"!=typeof window&&console.info("minify() » Minification complete! Check returned object."),{code:i.code,srcPath:path.resolve(process.cwd(),e),error:i.error}):(n=findJS(e,{recursive:o.recursive,verbose:o.verbose,dotFolders:o.dotFolders,dotFiles:o.dotFiles,ignoreFiles:o.ignoreFiles})?.map(e=>{o.verbose&&console.info(`minify() » ** Minifying ${e}...`);var i=fs.readFileSync(e,"utf8"),i=uglifyJS.minify(i,s);return o.comment&&(i.code=r(i.code,o.comment)),i.error&&console.error("minify() » ERROR: "+i.error.message),{code:i.code,srcPath:e,error:i.error}}).filter(e=>!e.error),o.verbose&&(0<n.length&&"undefined"!=typeof window?console.info("minify() » Minification complete! Check returned object."):console.info("minify() » No unminified JavaScript files processed.")),n):(o.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » ** Minifying passed source code..."),i=uglifyJS.minify(e,s),o.comment&&(i.code=r(i.code,o.comment)),i.error?console.error("minify() » ERROR: "+i.error.message):o.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » Minification complete! Check returned object."),{code:i.code,srcPath:void 0,error:i.error});function r(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)+`/**
8
7
  ${i}
9
8
  */
10
9
  `+e.slice(o)):`/**
11
10
  ${i}
12
11
  */
13
- `+e}}}function validateOptions(e,i,o,n){const r=JSON.stringify(i,null,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])),c=Object.keys(i).filter(e=>Array.isArray(i[e])),f=`${validateOptions.caller?.name||"validateOptions"}() » `;var d=n.split(",").findIndex(e=>e.trim().startsWith("{"))+1,a=(d+=["st","nd","rd"][d-1]||"th",()=>{console.info(f+`Valid options: [ ${s} ]`),console.info(f+"If omitted, default settings are: "+r)}),m=()=>{console.info(f+"For more help, please visit "+o)};if("object"!=typeof e)return console.error(f+`ERROR: ${"0th"==d?"[O":d+" arg [o"}ptions] can only be an object of key/values.`),console.info(f+"Example valid call: "+n),a(),m(),!1;for(const u in e){if("isRecursing"!=u&&!Object.prototype.hasOwnProperty.call(i,u))return console.error(f+`ERROR: \`${u}\` is an invalid option.`),a(),m(),!1;if(t.includes(u)&&"boolean"!=typeof e[u])return console.error(f+`ERROR: [${u}] option can only be \`true\` or \`false\`.`),m(),!1;if(l.includes(u)){if(e[u]=parseInt(e[u],10),isNaN(e[u])||e[u]<1)return console.error(f+`ERROR: [${u}] option can only be an integer > 0.`),m(),!1}else if(c.includes(u))if("string"!=typeof e[u]||e[u].includes(",")){if(!Array.isArray(e[u]))return console.error(f+`ERROR: [${u}] option can only be an array.`),m(),!1}else e[u]=[e[u]]}return!0}const 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(const Y in mjsAliases)mjsAliases[Y].forEach(e=>module.exports[e]=module.exports[Y]);
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])),c=Object.keys(i).filter(e=>Array.isArray(i[e])),f=`${validateOptions.caller?.name||"validateOptions"}() » `;var d,a=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1,m=(a+=["st","nd","rd"][a-1]||"th",()=>{console.info(f+`Valid options: [ ${s} ]`),console.info(f+"If omitted, default settings are: "+n)}),p=()=>{console.info(f+"For more help, please visit "+o)};if("object"!=typeof e)return console.error(f+`ERROR: ${"0th"==a?"[O":a+" arg [o"}ptions] can only be an object of key/values.`),console.info(f+"Example valid call: "+r),m(),p(),!1;for(d in e){if("isRecursing"!=d&&!Object.prototype.hasOwnProperty.call(i,d))return console.error(f+`ERROR: \`${d}\` is an invalid option.`),m(),p(),!1;if(t.includes(d)&&"boolean"!=typeof e[d])return console.error(f+`ERROR: [${d}] option can only be \`true\` or \`false\`.`),p(),!1;if(l.includes(d)){if(e[d]=parseInt(e[d],10),isNaN(e[d])||e[d]<1)return console.error(f+`ERROR: [${d}] option can only be an integer > 0.`),p(),!1}else if(c.includes(d))if("string"!=typeof e[d]||e[d].includes(",")){if(!Array.isArray(e[d]))return console.error(f+`ERROR: [${d}] option can only be an array.`),p(),!1}else e[d]=[e[d]]}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/README.md CHANGED
@@ -24,9 +24,9 @@
24
24
  <a href="https://www.npmjs.com/package/@adamlui/minify.js">
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
- <img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
28
- <a href="https://github.com/adamlui/minify.js/releases/tag/node-v1.8.6">
29
- <img height=31 src="https://img.shields.io/badge/Latest_Build-1.8.6-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
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-v1.9.0">
29
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-1.9.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">
@@ -147,6 +147,7 @@ Boolean options:
147
147
  -c, --copy Copy minified code to clipboard instead
148
148
  of writing to file if single source file
149
149
  is processed.
150
+ -C, --clone-folders Preserve folder structure in output directory.
150
151
  -q, --quiet Suppress all logging except errors.
151
152
 
152
153
  Parameter options:
@@ -219,15 +220,16 @@ minifyJS.minify(input, { dotFiles: true });
219
220
 
220
221
  Available parameters (and their default settings) are:
221
222
 
222
- Name | Type | Desciption | Default value
223
- --------------|---------|--------------------------------------------------------------------------|---------------
224
- `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
225
- `verbose` | Boolean | Show logging in console/terminal. | `true`
226
- `dotFolders` | Boolean | Include dotfolders in file search. | `false`
227
- `dotFiles` | Boolean | Include dotfiles in file search. | `false`
228
- `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
229
- `ignoreFiles` | Array | Files (by name) to exclude from minification. | `[]`
230
- `comment` | String | Header comment to prepend to minified code. Separate by line using '\n'. | `''`
223
+ Name | Type | Desciption | Default value
224
+ ---------------|---------|--------------------------------------------------------------------------|---------------
225
+ `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
226
+ `verbose` | Boolean | Show logging in console/terminal. | `true`
227
+ `dotFolders` | Boolean | Include dotfolders in file search. | `false`
228
+ `dotFiles` | Boolean | Include dotfiles in file search. | `false`
229
+ `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
230
+ `cloneFolders` | Boolean | Preserve folder structure in output directory. | `false`
231
+ `ignoreFiles` | Array | Files (by name) to exclude from minification. | `[]`
232
+ `comment` | String | Header comment to prepend to minified code. Separate by line using '\n'. | `''`
231
233
 
232
234
  #
233
235
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.8.6",
3
+ "version": "1.9.0",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -10,6 +10,10 @@
10
10
  "homepage": "https://minify-js.org",
11
11
  "license": "MIT",
12
12
  "funding": [
13
+ {
14
+ "type": "cashapp",
15
+ "url": "https://cash.app/$AdamLui"
16
+ },
13
17
  {
14
18
  "type": "github",
15
19
  "url": "http://github.com/sponsors/adamlui"
@@ -17,6 +21,10 @@
17
21
  {
18
22
  "type": "ko-fi",
19
23
  "url": "https://ko-fi.com/adamlui"
24
+ },
25
+ {
26
+ "type": "paypal",
27
+ "url": "https://paypal.me/adamlui"
20
28
  }
21
29
  ],
22
30
  "main": "dist/minify.min.js",