@adamlui/minify.js 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,18 +5,20 @@
5
5
  <img height=14 src="https://assets.minify-js.org/images/icons/earth/black/icon32.svg?v=ad67551">
6
6
  </picture>
7
7
  &nbsp;English |
8
- <a href="https://github.minify-js.org/tree/main/node.js/docs/zh-cn/#readme">简体中文</a> |
9
- <a href="https://github.minify-js.org/tree/main/node.js/docs/zh-tw/#readme">繁體中文</a> |
10
- <a href="https://github.minify-js.org/tree/main/node.js/docs/hi/#readme">हिंदी</a> |
11
- <a href="https://github.minify-js.org/tree/main/node.js/docs/bn/#readme">বাংলা</a> |
12
- <a href="https://github.minify-js.org/tree/main/node.js/docs/mr/#readme">मराठी</a> |
13
- <a href="https://github.minify-js.org/tree/main/node.js/docs/pa/#readme">ਪੰਜਾਬੀ</a> |
14
- <a href="https://github.minify-js.org/tree/main/node.js/docs/de/#readme">Deutsch</a> |
15
- <a href="https://github.minify-js.org/tree/main/node.js/docs/es/#readme">Español</a> |
16
- <a href="https://github.minify-js.org/tree/main/node.js/docs/fr/#readme">Français</a>
8
+ <a href="./docs/zh-cn/#readme">简体中文</a> |
9
+ <a href="./docs/zh-tw/#readme">繁體中文</a> |
10
+ <a href="./docs/hi/#readme">हिंदी</a> |
11
+ <a href="./docs/bn/#readme">বাংলা</a> |
12
+ <a href="./docs/mr/#readme">मराठी</a> |
13
+ <a href="./docs/pa/#readme">ਪੰਜਾਬੀ</a> |
14
+ <a href="./docs/de/#readme">Deutsch</a> |
15
+ <a href="./docs/es/#readme">Español</a> |
16
+ <a href="./docs/fr/#readme">Français</a>
17
17
  </h6>
18
18
  </div>
19
19
 
20
+ <a id="top"></a>
21
+
20
22
  # </> minify.js
21
23
 
22
24
  ### Recursively minify all JavaScript files.
@@ -24,17 +26,15 @@
24
26
  <a href="https://www.npmjs.com/package/@adamlui/minify.js">
25
27
  <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
28
  <a href="#%EF%B8%8F-mit-license">
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-v2.1.0">
29
- <img height=31 src="https://img.shields.io/badge/Latest_Build-2.1.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
29
+ <img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
30
+ <a href="https://github.com/adamlui/minify.js/releases/tag/node-v2.1.2">
31
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-2.1.2-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
30
32
  <a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code">
31
33
  <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
34
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js">
33
35
  <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>
34
36
  <a href="https://github.com/toolleeo/cli-apps#programming">
35
- <img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
36
- <a href="https://minify-js.org">
37
- <img height=31 src="https://img.shields.io/badge/web-minify--js.org-lightgrey?logo=dribbble&logoColor=white&labelColor=464646&style=for-the-badge"></a>
37
+ <img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-ff69b4?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
38
38
 
39
39
  <img src="https://cdn.jsdelivr.net/gh/adamlui/minify.js@3d56890/node.js/media/images/screenshots/cli/minify-js-docs-cmd-output.png">
40
40
 
@@ -172,13 +172,13 @@ You can also import **minify.js** into your app to use its API methods, both as
172
172
  #### ESM*:
173
173
 
174
174
  ```js
175
- import minifyJS from '@adamlui/minify.js';
175
+ import minifyJS from '@adamlui/minify.js'
176
176
  ```
177
177
 
178
178
  #### CJS:
179
179
 
180
180
  ```js
181
- const minifyJS = require('@adamlui/minify.js');
181
+ const minifyJS = require('@adamlui/minify.js')
182
182
  ```
183
183
 
184
184
  ###### _*Node.js version 14 or higher required_
@@ -193,10 +193,10 @@ If **source code** is passed, it is directly minified, then an object containing
193
193
 
194
194
  ```js
195
195
  const srcCode = 'function add(first, second) { return first + second; }',
196
- minifyResult = minifyJS.minify(srcCode);
196
+ minifyResult = minifyJS.minify(srcCode)
197
197
 
198
- console.log(minifyResult.error); // outputs runtime error, or `undefined` if no error
199
- console.log(minifyResult.code); // outputs minified JS: 'function add(n,d){return n+d}'
198
+ console.log(minifyResult.error) // outputs runtime error, or `undefined` if no error
199
+ console.log(minifyResult.code) // outputs minified JS: 'function add(n,d){return n+d}'
200
200
  ```
201
201
 
202
202
  If a **file path** is passed, the file's code is loaded then minified, returning an object like above.
@@ -205,18 +205,18 @@ If a **directory path** is passed, JavaScript files are searched for (recursivel
205
205
 
206
206
  ```js
207
207
  // Outputs paths to source JS files in working directory + all nested directories
208
- const minifyResults = minifyJS.minify('.');
209
- minifyResults.forEach(result => console.log(result.srcPath));
208
+ const minifyResults = minifyJS.minify('.')
209
+ minifyResults.forEach(result => console.log(result.srcPath))
210
210
 
211
211
  // Outputs minified code of 2nd JS file if found, or `undefined` if not found
212
- console.log(minifyResults[1].code);
212
+ console.log(minifyResults[1].code)
213
213
  ```
214
214
 
215
215
  Options are boolean, passed as object properties. For example:
216
216
 
217
217
  ```js
218
218
  // Returns array of data objects where dotfiles are also processed if `input` is a path
219
- minifyJS.minify(input, { dotFiles: true });
219
+ minifyJS.minify(input, { dotFiles: true })
220
220
  ```
221
221
 
222
222
  Available parameters (and their default settings) are:
@@ -243,8 +243,8 @@ Options are boolean, passed as object properties. For example:
243
243
 
244
244
  ```js
245
245
  // Search for unminified JS files in exactly assets/js
246
- const searchResults = minifyJS.findJS('assets/js', { recursive: false });
247
- console.log(searchResults);
246
+ const searchResults = minifyJS.findJS('assets/js', { recursive: false })
247
+ console.log(searchResults)
248
248
 
249
249
  /* sample output:
250
250
 
@@ -288,11 +288,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
288
288
 
289
289
  ## 🛠️ Related utilities
290
290
 
291
- ### [</> minify.js (Gulp)](https://gulp.minify-js.org) &nbsp;<a href="https://github.com/toolleeo/cli-apps#programming"><img height=18 src="https://assets.minify-js.org/images/badges/awesome/badge.svg?v=63bbeed"></a>
291
+ ### [</> minify.js (Gulp)](https://github.com/adamlui/minify.js/tree/main/gulp/) &nbsp;<a href="https://github.com/toolleeo/cli-apps#programming"><img height=18 src="https://assets.minify-js.org/images/badges/awesome/badge.svg?v=63bbeed"></a>
292
292
 
293
293
  > Gulp plug-in to recursively minify all JavaScript files.
294
- <br>[Install](https://gulp.minify-js.org/#-installation) /
295
- [Readme](https://gulp.minify-js.org/#readme) /
294
+ <br>[Install](https://github.com/adamlui/minify.js/tree/main/gulp/#-installation) /
295
+ [Readme](https://github.com/adamlui/minify.js/tree/main/gulp/#readme) /
296
296
  [Discuss](https://github.com/adamlui/minify.js/discussions)
297
297
 
298
298
  ### [{ } scss-to-css](https://scsstocss.org) &nbsp;<a href="https://github.com/toolleeo/cli-apps#conversion"><img height=18 src="https://assets.minify-js.org/images/badges/awesome/badge.svg?v=63bbeed"></a>
@@ -310,4 +310,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
310
310
 
311
311
  <picture><source media="(prefers-color-scheme: dark)" srcset="https://assets.minify-js.org/images/icons/home/white/icon32x27.png?v=ad67551"><img height=13 src="https://assets.minify-js.org/images/icons/home/dark-gray/icon32x27.png?v=ad67551"></picture> <a href="https://js-utils.org">**More JavaScript utilities**</a> /
312
312
  <a href="https://github.com/adamlui/minify.js/discussions">Discuss</a> /
313
- <a href="#-minifyjs">Back to top ↑</a>
313
+ <a href="#top">Back to top ↑</a>
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * © 2023–2026 Adam Lui & contributors under the MIT license.
4
+ * Source: https://github.com/adamlui/minify.js/tree/main/node.js/src
5
+ * Documentation: https://github.com/adamlui/minify.js/tree/main/node.js/docs
6
+ */
7
+ (async()=>{globalThis.env={devMode:__dirname.match(/[\\/]src/)};let o=require("node-clipboardy"),p=require("child_process").execSync,t=require("fs"),{getMsgs:e,getSysLang:s}=require(`./lib/language${env.devMode?"":".min"}.js`),n=require(`../minify${env.devMode?"":".min"}.js`),m=require("path"),i=(globalThis.app=require(`../${env.devMode?"../":"./data/"}app.json`),app.urls.docs+="/#-command-line-usage",app.msgs=await e(s()),app.regex={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?|(?:ignore|skip|exclude)(?:d?-?files?)?)(?:=.*|$)/,comment:/^--?comments?(?:=.*|$)/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/},version:/^[~^>=]?\d+\.\d+\.\d+$/},""),c="",g="",l="",f="";if(app.config={},process.argv.forEach(s=>{var e,p,o;s.startsWith("-")&&(e=Object.keys(app.regex.paramOptions).find(e=>app.regex.paramOptions[e].test(s)),o=Object.keys(app.regex.flags).find(e=>app.regex.flags[e].test(s)),p=Object.keys(app.regex.infoCmds).find(e=>app.regex.infoCmds[e].test(s)),o?app.config[o]=!0:e?(/=.+/.test(s)||(console.error(`
8
+ ${c}${app.msgs.prefix_error}: Arg [--${s.replace(/-/g,"")}] ${app.msgs.error_noEqual}.`),u(),process.exit(1)),o=s.split("=")[1],app.config[e]=parseInt(o)||o):p||(console.error(`
9
+ ${c}${app.msgs.prefix_error}: Arg [${s}] ${app.msgs.error_notRecognized}.`),console.info(`
10
+ ${g}${app.msgs.info_validArgs}.`),r(["paramOptions","flags","infoCmds"]),process.exit(1)))}),process.argv.some(e=>app.regex.infoCmds.help.test(e)))r();else if(process.argv.some(e=>app.regex.infoCmds.version.test(e))){var d=p(`npm view ${JSON.stringify(app.name)} version`).toString().trim()||"none";let e,s=process.cwd();for(;"/"!=s;){var a=m.join(s,"package.json");if(t.existsSync(a)){a=require(a);e=(a.dependencies?.[app.name]||a.devDependencies?.[app.name])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}s=m.dirname(s)}console.info(`
11
+ ${app.msgs.prefix_globalVer}: `+d),console.info(app.msgs.prefix_localVer+": "+e)}else{let[a="",r=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),s=m.resolve(process.cwd(),a);a&&!t.existsSync(s)&&(d=s+".js",t.existsSync(d)?s=d:(console.error(`
12
+ ${c}${app.msgs.prefix_error}: `+app.msgs.error_firstArgNotExist+"."+`
13
+ ${s} ${app.msgs.error_doesNotExist}.`),console.info(`
14
+ ${l}${app.msgs.info_exampleValidCmd}: `+`
15
+ » minify-js . output.min.js`),u(),process.exit(1)));var $,d=s.endsWith(".js")&&!t.statSync(s).isDirectory()?[s]:n.findJS(s,{recursive:!app.config.noRecursion,verbose:!app.config.quietMode,ignores:(app.config.ignores?.split(",")??[]).map(e=>e.trim())});if(app.config.dryRun)d.length?(console.info(`
16
+ ${g}${app.msgs.info_filesToBeMinned}:`),d.forEach(e=>console.info(e))):console.info(`
17
+ ${g}${app.msgs.info_noFilesWillBeMinned}.`);else{let p=[],e=[];!app.config.relativeOutput&&t.statSync(s).isDirectory()?($=n.minify(s,{verbose:!1,mangle:!app.config.noMangle,comment:app.config.comment?.replace(/\\n/g,"\n"),relativeOutput:!1,recursive:!app.config.noRecursion,dotFolders:!!app.config.includeDotFolders,dotFiles:!!app.config.includeDotFiles,rewriteImports:!!app.config.rewriteImports,ignores:app.config.ignores?app.config.ignores.split(",").map(e=>e.trim()):[]}))&&($.error?p.push(s):e=[].concat($)):e=d.map(e=>{var s=n.minify(e,{verbose:!app.config.quietMode,mangle:!app.config.noMangle,comment:app.config.comment?.replace(/\\n/g,"\n")});return s.error&&p.push(e),s}).filter(e=>!e.error),e?.length?(h(`
18
+ ${l}${app.msgs.info_minComplete}!`),h(f+e.length+" "+app.msgs.info_file+`${1<e.length?"s":""} ${app.msgs.info_minified}.${i}`)):h(`
19
+ ${g}${app.msgs.info_noFilesProcessed}.`),p.length&&(h(`
20
+ ${c+p.length} `+app.msgs.info_file+`${1<p.length?"s":""} ${app.msgs.info_failedToMinify}:${i}`),p.forEach(e=>h(e))),e?.length&&(app.config.copy&&1==e?.length?(console.log(`
21
+ ${f}${e[0].code}`),h(`
22
+ ${app.msgs.info_copying}...`),o.writeSync(e[0].code)):(h(`
23
+ ${app.msgs.info_writing}${1<e?.length?"s":""}...`),e?.forEach(({code:e,srcPath:p,relPath:o})=>{let n,i;if(!app.config.relativeOutput&&o){let e=m.resolve(process.cwd(),r||"min"),s=m.dirname(o);n="."!=s?m.join(e,s):e,i=m.basename(p,".js")+`${app.config.noFilenameChange?"":".min"}.js`}else n=m.join(m.dirname(p),r.endsWith(".js")?m.dirname(r):r||"min"),i=`${r.endsWith(".js")&&a.endsWith(".js")?m.basename(r).replace(/(\.min)?\.js$/,""):m.basename(p,".js")}${app.config.noFilenameChange?"":".min"}.js`;let s=m.join(n,i);t.existsSync(n)||t.mkdirSync(n,{recursive:!0}),t.writeFileSync(s,e,"utf8"),h(` ${l}✓ `+m.relative(process.cwd(),s))})))}}function u(){console.info(`
24
+ ${app.msgs.info_moreHelp}, ${app.msgs.info_type} ${app.name.split("/")[1]} --help' ${app.msgs.info_or} ${app.msgs.info_visit}
25
+ ${f}${app.urls.docs}`)}function r(e=["header","usage","pathArgs","flags","paramOptions","infoCmds"]){app.prefix=` ${app.name.replace(/^@[^/]+\//,"")}  `;let s={header:[`
26
+ ├ ${app.prefix}${app.msgs.appCopyright||`© ${app.copyrightYear} ${app.author} under the ${app.license} license`}.`,""+app.prefix+app.msgs.prefix_source+": "+app.urls.src],usage:[`
27
+ ${f}o ${app.msgs.helpSection_usage}:`,` ${f}» ${l}${app.cmdFormat}`],pathArgs:[`
28
+ ${f}o ${app.msgs.helpSection_pathArgs}:`," [inputPath] "+app.msgs.inputPathDesc_main+", "+app.msgs.inputPathDesc_extra+"."," [outputPath] "+app.msgs.outputPathDesc_main+", "+app.msgs.outputPathDesc_extra+"."],flags:[`
29
+ ${f}o ${app.msgs.helpSection_flags}:`,` -n, --dry-run ${app.msgs.optionDesc_dryRun}.`,` -d, --include-dotfolders ${app.msgs.optionDesc_dotfolders}.`,` -D, --include-dotfiles ${app.msgs.optionDesc_dotfiles}.`,` -R, --no-recursion ${app.msgs.optionDesc_noRecursion}.`,` -M, --no-mangle ${app.msgs.optionDesc_noMangle}.`," -X, --no-filename-change "+app.msgs.optionDesc_noFilenameChange,` -i, --rewrite-imports ${app.msgs.optionDesc_rewriteImports}.`,` -c, --copy ${app.msgs.optionDesc_copy}.`,` -r, --relative-output ${app.msgs.optionDesc_relativeOutput}.`,` -q, --quiet ${app.msgs.optionDesc_quiet}.`],paramOptions:[`
30
+ ${f}o ${app.msgs.helpSection_paramOptions}:`,`--ignores="dir/,file1.js,file2.js" ${app.msgs.optionDesc_ignores}.`,`--comment="comment" ${app.msgs.optionDesc_commentMain}.`+` ${app.msgs.optionDesc_commentExtra}.`],infoCmds:[`
31
+ ${f}o ${app.msgs.helpSection_infoCmds}:`," -h, --help "+app.msgs.optionDesc_help,` -v, --version ${app.msgs.optionDesc_version}.`]};e.forEach(a=>s[a]?.forEach(s=>{{var i=/header|usage/.test(a)?1:37;let p=process.stdout.columns||80,o=[],e=s.match(/\S+|\s+/g),n="";e.forEach(e=>{var s=p-(o.length?i:0);n.length+"| ".length+e.length>s&&(o.push(o.length?n.trimStart():n),n=""),n+=e}),o.push(o.length?n.trimStart():n),o.forEach((e,s)=>console.info("| "+(0==s?e:" ".repeat(i)+e)))}})),console.info(`
32
+ ${app.msgs.info_moreHelp}, ${app.msgs.info_visit}: ${f}${app.urls.docs}`)}function h(e){app.config.quietMode||console.info(e)}})();
@@ -0,0 +1,6 @@
1
+ /**
2
+ * © 2023–2026 Adam Lui & contributors under the MIT license.
3
+ * Source: https://github.com/adamlui/minify.js/tree/main/node.js/src
4
+ * Documentation: https://github.com/adamlui/minify.js/tree/main/node.js/docs
5
+ */
6
+ module.exports={fetch(n){return new Promise((t,e)=>{var r=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(r)||e(new Error(app.msgs.error_invalidURL+".")),require(r).get(n,e=>{let r="";e.on("data",e=>r+=e),e.on("end",()=>t({json:()=>JSON.parse(r)}))}).on("error",e)})},flatten(e,{key:r="message"}={}){var t,n={};for(t in e)n[t]="object"==typeof e[t]&&r in e[t]?e[t][r]:e[t];return n}};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * © 2023–2026 Adam Lui & contributors under the MIT license.
3
+ * Source: https://github.com/adamlui/minify.js/tree/main/node.js/src
4
+ * Documentation: https://github.com/adamlui/minify.js/tree/main/node.js/docs
5
+ */
6
+ module.exports={async getMsgs(r="en"){var e=require(`./data${env.devMode?"":".min"}.js`);let t=e.flatten(require(`../../${env.devMode?"../../_locales/en/":"data/"}messages.json`),{key:"message"});if(!r.startsWith("en")){var n=`${app.urls.jsdelivr}@${app.commitHashes.locales}/_locales/`;let s=n+`${r?r.replace("-","_"):"en"}/`+"messages.json",a=0;for(;a<3;)try{t=e.flatten(await(await e.fetch(s)).json(),{key:"message"});break}catch(e){if(3==++a)break;s=r.includes("-")&&1==a?s.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):n+"en/messages.json"}}return t},getSysLang(){var e;if("win32"!=process.platform)return((e=process.env).LANG||e.LANGUAGE||e.LC_ALL||e.LC_MESSAGES||e.LC_NAME||"en").split(".")[0];try{return require("child_process").execSync("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){return console.error("ERROR loading system language:",e.message),"en"}}};
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@adamlui/minify.js",
3
+ "author": "Adam Lui & contributors",
4
+ "license": "MIT",
5
+ "copyrightYear": "2024–2026",
6
+ "cmdFormat": "minify-js [inputPath] [outputPath] [options]",
7
+ "urls": {
8
+ "docs": "https://github.com/adamlui/minify.js/tree/main/node.js/docs",
9
+ "github": "https://github.com/adamlui/minify.js",
10
+ "jsdelivr": "https://cdn.jsdelivr.net/gh/adamlui/minify.js",
11
+ "npm": "https://www.npmjs.com/package/@adamlui/minify.js",
12
+ "src": "https://github.com/adamlui/minify.js/tree/main/node.js/src"
13
+ },
14
+ "commitHashes": {
15
+ "locales": "589eb64"
16
+ }
17
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "appName": { "message": "minify.js" },
3
+ "appCopyright": { "message": "© 2024–2026 Adam Lui & contributors under the MIT license" },
4
+ "prefix_error": { "message": "ERROR" },
5
+ "prefix_globalVer": { "message": "Global version" },
6
+ "prefix_localVer": { "message": "Local version" },
7
+ "prefix_source": { "message": "Source" },
8
+ "error_notRecognized": { "message": "not recognized" },
9
+ "error_invalidURL": { "message": "Invalid URL" },
10
+ "error_firstArgNotExist": { "message": "First argument can only be an existing file or directory" },
11
+ "error_doesNotExist": { "message": "does not exist" },
12
+ "info_validArgs": { "message": "Valid arguments are below" },
13
+ "info_exampleValidCmd": { "message": "Example valid command" },
14
+ "info_filesToBeMinned": { "message": "JS files to be minified" },
15
+ "info_noFilesWillBeMinned": { "message": "No JS files will be minified" },
16
+ "info_copying": { "message": "Copying to clipboard" },
17
+ "info_writing": { "message": "Writing to file" },
18
+ "info_minComplete": { "message": "Minification complete" },
19
+ "info_file": { "message": "file" },
20
+ "info_mininified": { "message": "minified" },
21
+ "info_noFilesProcessed": { "message": "No unminified JavaScript files processed" },
22
+ "info_failedToMinify": { "message": "failed to minify" },
23
+ "info_moreHelp": { "message": "For more help" },
24
+ "info_visit": { "message": "visit" },
25
+ "helpSection_usage": { "message": "Usage" },
26
+ "helpSection_pathArgs": { "message": "Path arguments" },
27
+ "helpSection_flags": { "message": "Boolean options" },
28
+ "helpSection_paramOptions": { "message": "Parameter options" },
29
+ "helpSection_infoCmds": { "message": "Info commands" },
30
+ "inputPathDesc_main": { "message": "Path to JS file or directory containing JavaScript files to be minified" },
31
+ "inputPathDesc_extra": { "message": "relative to the current working directory" },
32
+ "outputPathDesc_main": { "message": "Path to file or directory where minified files will be stored" },
33
+ "outputPathDesc_extra": { "message": "relative to original file location (if not provided, min/ is used)" },
34
+ "optionDesc_dryRun": { "message": "Don't actually minify the file(s), just show if they will be processed" },
35
+ "optionDesc_dotfolders": { "message": "Include dotfolders in file search" },
36
+ "optionDesc_dotfiles": { "message": "Include dotfiles in file search" },
37
+ "optionDesc_noRecursion": { "message": "Disable recursive file searching" },
38
+ "optionDesc_noMangle": { "message": "Disable mangling names" },
39
+ "optionDesc_noFilenameChange": { "message": "Disable changing file extension to .min.js" },
40
+ "optionDesc_copy": { "message": "Copy minified code to clipboard instead of writing to file if single source file is processed" },
41
+ "optionDesc_relativeOutput": { "message": "Output files relative to each source file instead of to input root" },
42
+ "optionDesc_rewriteImports": { "message": "Update import paths from .js to .min.js" },
43
+ "optionDesc_quiet": { "message": "Suppress all logging except errors" },
44
+ "optionDesc_ignores": { "message": "Files/directories to exclude from minification" },
45
+ "optionDesc_commentMain": { "message": "Prepend header comment to minified code" },
46
+ "optionDesc_commentExtra": { "message": "Separate by line using '\\n'" },
47
+ "optionDesc_help": { "message": "Display help screen" },
48
+ "optionDesc_version": { "message": "Show version number" }
49
+ }
@@ -1,12 +1,12 @@
1
- let fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(s,i={}){let e="https://docs.minify-js.org/node.js/#findjssearchdir-options",n="findJS() » ";var r={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,ignores:[]};if("string"!=typeof s)console.error(n+"ERROR: 1st arg <searchDir> must be a string."),console.info(n+"For more help, please visit "+e);else{var o=path.resolve(process.cwd(),s);if(fs.existsSync(o)){if(validateOptions(i,r,e,"findJS('assets/js', { verbose: false, dotFoldes: true })")){(i={...r,...i}).ignoreFiles&&(i.ignores=i.ignoreFiles);let e=fs.readdirSync(s),o=[];return i.verbose&&!i.isRecursing&&console.info(n+"Searching for unminified JS files..."),e.forEach(e=>{let r=path.resolve(s,e);i.ignores.some(o=>o.endsWith("/")?r.split(path.sep).some(e=>e==o.replace(/\/$/,"")):e==o)?i.verbose&&console.info(n+`** ${e} ignored`):fs.statSync(r).isDirectory()&&"node_modules"!=e&&i.recursive&&(i.dotFolders||!e.startsWith("."))?o.push(...findJS(r,{...i,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!i.dotFiles&&e.startsWith(".")||o.push(r)}),i.verbose&&!i.isRecursing&&(console.info(n+"Search complete! "+`${o.length||"No"} file${1==o.length?"":"s"} found.`),"minify"!=findJS.caller?.name)&&"undefined"!=typeof window&&console.info(n+"Check returned array."),i.isRecursing||o.length?o:[]}}else console.error(n+"ERROR: 1st arg <searchDir> must be an existing directory."),console.error(n+o+" does not exist."),console.info(n+"For more help, please visit "+e)}}function minify(i,n={}){let e="https://docs.minify-js.org/node.js/#minifyinput-options",t="minify() » ";var o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,rewriteImports:!1,relativeOutput:!1,ignores:[],comment:""};if("string"!=typeof i)console.error(t+"ERROR: 1st arg <input> must be a string."),console.info(t+"For more help, please visit "+e);else if(validateOptions(n,o,e,"minify('assets/js', { recursive: false, mangle: false })")){(n={...o,...n}).ignoreFiles&&(n.ignores=n.ignoreFiles);let s={mangle:!!n.mangle&&{toplevel:!1}};try{var r,c=fs.openSync(i,fs.constants.O_RDONLY),l=fs.fstatSync(c);if(l.isFile()){if(!/\.[cm]?jsx?$/i.test(i))return r=new Error(t+`ERROR: ${i} is not a JavaScript file (.js, .mjs, .cjs, .jsx)`),console.error(r.message),fs.closeSync(c),{code:"",srcPath:path.resolve(process.cwd(),i),error:r};n.verbose&&console.info(t+`** Minifying ${i}...`);var a=Buffer.alloc(l.size),f=(fs.readSync(c,a,0,l.size,0),fs.closeSync(c),uglifyJS.minify(a.toString("utf8"),s));return n.comment&&(f.code=p(f.code,n.comment)),f.error?console.error(t+"ERROR: "+f.error.message):n.verbose&&"undefined"!=typeof window&&console.info(t+"Minification complete! Check returned object."),{code:f.code,srcPath:path.resolve(process.cwd(),i),error:f.error}}fs.closeSync(c);var d=findJS(i,n)?.map(e=>{n.verbose&&console.info(t+`** Minifying ${e}...`);var o=fs.readFileSync(e,"utf8"),o=uglifyJS.minify(o,s);let r;return n.comment&&(o.code=p(o.code,n.comment)),o.error&&console.error(t+"ERROR: "+o.error.message),n.relativeOutput||(r=path.relative(path.resolve(process.cwd(),i),e)),{code:o.code,srcPath:e,relPath:r,error:o.error}}).filter(e=>!e.error);if(n.verbose&&(d.length&&"undefined"!=typeof window?console.info(t+"Minification complete! Check returned object."):console.info(t+"No unminified JavaScript files processed.")),n.rewriteImports&&d&&1<d.length){n.verbose&&console.info(t+"** Rewriting import paths...");let e=d.map(e=>path.basename(e.srcPath,".js"));d.forEach(s=>e.forEach(e=>{var o=new RegExp(`(\\./?)?\\b${e}\\.js(['"])`,"g"),r=s.code;s.code=s.code.replace(o,`$1${e}.min.js$2`),r!=s.code&&n.verbose&&console.info(t+`Updated ${e}.js in `+path.basename(s.srcPath))})),n.verbose&&console.info(t+"Import paths rewritten.")}return d}catch(e){if("ENOENT"==e.code)return n.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info(t+"** Minifying passed source code..."),o=uglifyJS.minify(i,s),n.comment&&(o.code=p(o.code,n.comment)),o.error?console.error(t+"ERROR: "+o.error.message):n.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info(t+"Minification complete! Check returned object."),{code:o.code,srcPath:void 0,error:o.error};throw e}function p(e,o){var o=o.split("\n").map(e=>" * "+e).join("\n"),r=e.indexOf("#!");return 0<=r?(r=e.indexOf("\n",r)+1,e.slice(0,r)+`/**
1
+ let fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(s,i={}){let e=app.urls.docs+"/#findjssearchdir-options",n="findJS() » ";var r={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,ignores:[]};if("string"!=typeof s)console.error(n+"ERROR: 1st arg <searchDir> must be a string."),console.info(n+"For more help, please visit "+e);else{var o=path.resolve(process.cwd(),s);if(fs.existsSync(o)){if(validateOptions(i,r,e,"findJS('assets/js', { verbose: false, dotFoldes: true })")){(i={...r,...i}).ignoreFiles&&(i.ignores=[...i.ignores??[],...i.ignoreFiles]);let e=fs.readdirSync(s),o=[];return i.verbose&&!i.isRecursing&&console.info(n+"Searching for unminified JS files..."),e.forEach(e=>{let r=path.resolve(s,e);i.ignores.some(o=>o.endsWith("/")?r.split(path.sep).some(e=>e==o.replace(/\/$/,"")):e==o)?i.verbose&&console.info(n+`** ${e} ignored`):fs.statSync(r).isDirectory()&&"node_modules"!=e&&i.recursive&&(i.dotFolders||!e.startsWith("."))?o.push(...findJS(r,{...i,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!i.dotFiles&&e.startsWith(".")||o.push(r)}),i.verbose&&!i.isRecursing&&(console.info(n+"Search complete! "+`${o.length||"No"} file${1==o.length?"":"s"} found.`),"minify"!=findJS.caller?.name)&&"undefined"!=typeof window&&console.info(n+"Check returned array."),i.isRecursing||o.length?o:[]}}else console.error(n+"ERROR: 1st arg <searchDir> must be an existing directory."),console.error(n+o+" does not exist."),console.info(n+"For more help, please visit "+e)}}function minify(i,n={}){let e=app.urls.docs+"/#minifyinput-options",t="minify() » ";var o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,rewriteImports:!1,relativeOutput:!1,ignores:[],comment:""};if("string"!=typeof i)console.error(t+"ERROR: 1st arg <input> must be a string."),console.info(t+"For more help, please visit "+e);else if(validateOptions(n,o,e,"minify('assets/js', { recursive: false, mangle: false })")){(n={...o,...n}).ignoreFiles&&(n.ignores=[...n.ignores??[],...n.ignoreFiles]);let s={mangle:!!n.mangle&&{toplevel:!1}};try{var r,c=fs.openSync(i,fs.constants.O_RDONLY),l=fs.fstatSync(c);if(l.isFile()){if(!/\.[cm]?jsx?$/i.test(i))return r=new Error(t+`ERROR: ${i} is not a JavaScript file (.js, .mjs, .cjs, .jsx)`),console.error(r.message),fs.closeSync(c),{code:"",srcPath:path.resolve(process.cwd(),i),error:r};n.verbose&&console.info(t+`** Minifying ${i}...`);var a=Buffer.alloc(l.size),f=(fs.readSync(c,a,0,l.size,0),fs.closeSync(c),uglifyJS.minify(a.toString("utf8"),s));return n.comment&&(f.code=p(f.code,n.comment)),f.error?console.error(t+"ERROR: "+f.error.message):n.verbose&&"undefined"!=typeof window&&console.info(t+"Minification complete! Check returned object."),{code:f.code,srcPath:path.resolve(process.cwd(),i),error:f.error}}fs.closeSync(c);var d=findJS(i,n)?.map(e=>{n.verbose&&console.info(t+`** Minifying ${e}...`);var o=fs.readFileSync(e,"utf8"),o=uglifyJS.minify(o,s),r=n.relativeOutput?void 0:path.relative(path.resolve(process.cwd(),i),e);return n.comment&&(o.code=p(o.code,n.comment)),o.error&&console.error(t+"ERROR: "+o.error.message),{code:o.code,srcPath:e,relPath:r,error:o.error}}).filter(e=>!e.error);if(n.verbose&&(d.length&&"undefined"!=typeof window?console.info(t+"Minification complete! Check returned object."):console.info(t+"No unminified JavaScript files processed.")),n.rewriteImports&&d&&1<d.length){n.verbose&&console.info(t+"** Rewriting import paths...");let e=d.map(e=>path.basename(e.srcPath,".js"));d.forEach(s=>e.forEach(e=>{var o=new RegExp(`(\\./?)?\\b${e}\\.js(['"])`,"g"),r=s.code;s.code=s.code.replace(o,`$1${e}.min.js$2`),r!=s.code&&n.verbose&&console.info(t+`Updated ${e}.js in `+path.basename(s.srcPath))})),n.verbose&&console.info(t+"Import paths rewritten.")}return d}catch(e){if("ENOENT"==e.code)return n.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info(t+"** Minifying passed source code..."),o=uglifyJS.minify(i,s),n.comment&&(o.code=p(o.code,n.comment)),o.error?console.error(t+"ERROR: "+o.error.message):n.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info(t+"Minification complete! Check returned object."),{code:o.code,srcPath:void 0,error:o.error};throw e}function p(e,o){var o=o.split("\n").map(e=>" * "+e).join("\n"),r=e.indexOf("#!");return 0<=r?(r=e.indexOf("\n",r)+1,e.slice(0,r)+`/**
2
2
  /**
3
3
  * © 2023–2026 Adam Lui & contributors under the MIT license.
4
- * Source: https://code.minify-js.org/node.js
5
- * Documentation: https://docs.minify-js.org/node.js
4
+ * Source: https://github.com/adamlui/minify.js/tree/main/node.js/src
5
+ * Documentation: https://github.com/adamlui/minify.js/tree/main/node.js/docs
6
6
  */
7
7
  ${o}
8
8
  */
9
9
  `+e.slice(r)):`/**
10
10
  ${o}
11
11
  */
12
- `+e}}}function validateOptions(e,o,r,s){let i=JSON.stringify(o,void 0,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(o).join(", "),t=Object.keys(o).filter(e=>"boolean"==typeof o[e]),c=Object.keys(o).filter(e=>Number.isInteger(o[e])),l=Object.keys(o).filter(e=>Array.isArray(o[e])),a=`${validateOptions.caller?.name||"validateOptions"}() » `;var f,d=s.split(",").findIndex(e=>e.trim().startsWith("{"))+1,p=(d+=["st","nd","rd"][d-1]||"th",()=>{console.info(a+"For more help, please visit "+r)});if("object"!=typeof e)return console.error(a+`ERROR: ${"0th"==d?"[O":d+" arg [o"}ptions] can only be an object of key/values.`),console.info(a+"Example valid call: "+s),console.info(a+`Valid options: [ ${n} ]`),console.info(a+"If omitted, default settings are: "+i),p(),!1;for(f in e)if("isRecursing"==f||Object.prototype.hasOwnProperty.call(o,f)){if(t.includes(f)&&"boolean"!=typeof e[f])return console.error(a+`ERROR: [${f}] option can only be \`true\` or \`false\`.`),p(),!1;if(c.includes(f)){if(e[f]=parseInt(e[f],10),isNaN(e[f])||e[f]<1)return console.error(a+`ERROR: [${f}] option can only be an integer > 0.`),p(),!1}else if(l.includes(f))if("string"!=typeof e[f]||e[f].includes(",")){if(!Array.isArray(e[f]))return console.error(a+`ERROR: [${f}] option can only be an array.`),p(),!1}else e[f]=[e[f]]}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 o in mjsAliases)mjsAliases[o].forEach(e=>module.exports[e]=module.exports[o]);
12
+ `+e}}}function validateOptions(e,o,r,s){let i=JSON.stringify(o,void 0,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(o).join(", "),t=Object.keys(o).filter(e=>"boolean"==typeof o[e]),c=Object.keys(o).filter(e=>Number.isInteger(o[e])),l=Object.keys(o).filter(e=>Array.isArray(o[e])),a=`${validateOptions.caller?.name||"validateOptions"}() » `;var f,d=s.split(",").findIndex(e=>e.trim().startsWith("{"))+1;function p(){console.info(a+"For more help, please visit "+r)}if(d+=["st","nd","rd"][d-1]||"th","object"!=typeof e)return console.error(a+`ERROR: ${"0th"==d?"[O":d+" arg [o"}ptions] can only be an object of key/values.`),console.info(a+"Example valid call: "+s),console.info(a+`Valid options: [ ${n} ]`),console.info(a+"If omitted, default settings are: "+i),p(),!1;for(f in e)if("isRecursing"==f||Object.prototype.hasOwnProperty.call(o,f)){if(t.includes(f)&&"boolean"!=typeof e[f])return console.error(a+`ERROR: [${f}] option can only be \`true\` or \`false\`.`),p(),!1;if(c.includes(f)){if(e[f]=parseInt(e[f],10),isNaN(e[f])||e[f]<1)return console.error(a+`ERROR: [${f}] option can only be an integer > 0.`),p(),!1}else if(l.includes(f))if("string"!=typeof e[f]||e[f].includes(",")){if(!Array.isArray(e[f]))return console.error(a+`ERROR: [${f}] option can only be an array.`),p(),!1}else e[f]=[e[f]]}return!0}globalThis.app=require(`${__dirname.match(/[\\/]src/)?"../":"./data/"}app.json`);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 o in mjsAliases)mjsAliases[o].forEach(e=>module.exports[e]=module.exports[o]);
package/docs/README.md CHANGED
@@ -5,18 +5,20 @@
5
5
  <img height=14 src="https://assets.minify-js.org/images/icons/earth/black/icon32.svg?v=ad67551">
6
6
  </picture>
7
7
  &nbsp;English |
8
- <a href="https://github.minify-js.org/tree/main/node.js/docs/zh-cn/#readme">简体中文</a> |
9
- <a href="https://github.minify-js.org/tree/main/node.js/docs/zh-tw/#readme">繁體中文</a> |
10
- <a href="https://github.minify-js.org/tree/main/node.js/docs/hi/#readme">हिंदी</a> |
11
- <a href="https://github.minify-js.org/tree/main/node.js/docs/bn/#readme">বাংলা</a> |
12
- <a href="https://github.minify-js.org/tree/main/node.js/docs/mr/#readme">मराठी</a> |
13
- <a href="https://github.minify-js.org/tree/main/node.js/docs/pa/#readme">ਪੰਜਾਬੀ</a> |
14
- <a href="https://github.minify-js.org/tree/main/node.js/docs/de/#readme">Deutsch</a> |
15
- <a href="https://github.minify-js.org/tree/main/node.js/docs/es/#readme">Español</a> |
16
- <a href="https://github.minify-js.org/tree/main/node.js/docs/fr/#readme">Français</a>
8
+ <a href="./docs/zh-cn/#readme">简体中文</a> |
9
+ <a href="./docs/zh-tw/#readme">繁體中文</a> |
10
+ <a href="./docs/hi/#readme">हिंदी</a> |
11
+ <a href="./docs/bn/#readme">বাংলা</a> |
12
+ <a href="./docs/mr/#readme">मराठी</a> |
13
+ <a href="./docs/pa/#readme">ਪੰਜਾਬੀ</a> |
14
+ <a href="./docs/de/#readme">Deutsch</a> |
15
+ <a href="./docs/es/#readme">Español</a> |
16
+ <a href="./docs/fr/#readme">Français</a>
17
17
  </h6>
18
18
  </div>
19
19
 
20
+ <a id="top"></a>
21
+
20
22
  # </> minify.js
21
23
 
22
24
  ### Recursively minify all JavaScript files.
@@ -24,17 +26,15 @@
24
26
  <a href="https://www.npmjs.com/package/@adamlui/minify.js">
25
27
  <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
28
  <a href="#%EF%B8%8F-mit-license">
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-v2.1.0">
29
- <img height=31 src="https://img.shields.io/badge/Latest_Build-2.1.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
29
+ <img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
30
+ <a href="https://github.com/adamlui/minify.js/releases/tag/node-v2.1.2">
31
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-2.1.2-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
30
32
  <a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code">
31
33
  <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
34
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js">
33
35
  <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>
34
36
  <a href="https://github.com/toolleeo/cli-apps#programming">
35
- <img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
36
- <a href="https://minify-js.org">
37
- <img height=31 src="https://img.shields.io/badge/web-minify--js.org-lightgrey?logo=dribbble&logoColor=white&labelColor=464646&style=for-the-badge"></a>
37
+ <img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-ff69b4?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
38
38
 
39
39
  <img src="https://cdn.jsdelivr.net/gh/adamlui/minify.js@3d56890/node.js/media/images/screenshots/cli/minify-js-docs-cmd-output.png">
40
40
 
@@ -172,13 +172,13 @@ You can also import **minify.js** into your app to use its API methods, both as
172
172
  #### ESM*:
173
173
 
174
174
  ```js
175
- import minifyJS from '@adamlui/minify.js';
175
+ import minifyJS from '@adamlui/minify.js'
176
176
  ```
177
177
 
178
178
  #### CJS:
179
179
 
180
180
  ```js
181
- const minifyJS = require('@adamlui/minify.js');
181
+ const minifyJS = require('@adamlui/minify.js')
182
182
  ```
183
183
 
184
184
  ###### _*Node.js version 14 or higher required_
@@ -193,10 +193,10 @@ If **source code** is passed, it is directly minified, then an object containing
193
193
 
194
194
  ```js
195
195
  const srcCode = 'function add(first, second) { return first + second; }',
196
- minifyResult = minifyJS.minify(srcCode);
196
+ minifyResult = minifyJS.minify(srcCode)
197
197
 
198
- console.log(minifyResult.error); // outputs runtime error, or `undefined` if no error
199
- console.log(minifyResult.code); // outputs minified JS: 'function add(n,d){return n+d}'
198
+ console.log(minifyResult.error) // outputs runtime error, or `undefined` if no error
199
+ console.log(minifyResult.code) // outputs minified JS: 'function add(n,d){return n+d}'
200
200
  ```
201
201
 
202
202
  If a **file path** is passed, the file's code is loaded then minified, returning an object like above.
@@ -205,18 +205,18 @@ If a **directory path** is passed, JavaScript files are searched for (recursivel
205
205
 
206
206
  ```js
207
207
  // Outputs paths to source JS files in working directory + all nested directories
208
- const minifyResults = minifyJS.minify('.');
209
- minifyResults.forEach(result => console.log(result.srcPath));
208
+ const minifyResults = minifyJS.minify('.')
209
+ minifyResults.forEach(result => console.log(result.srcPath))
210
210
 
211
211
  // Outputs minified code of 2nd JS file if found, or `undefined` if not found
212
- console.log(minifyResults[1].code);
212
+ console.log(minifyResults[1].code)
213
213
  ```
214
214
 
215
215
  Options are boolean, passed as object properties. For example:
216
216
 
217
217
  ```js
218
218
  // Returns array of data objects where dotfiles are also processed if `input` is a path
219
- minifyJS.minify(input, { dotFiles: true });
219
+ minifyJS.minify(input, { dotFiles: true })
220
220
  ```
221
221
 
222
222
  Available parameters (and their default settings) are:
@@ -243,8 +243,8 @@ Options are boolean, passed as object properties. For example:
243
243
 
244
244
  ```js
245
245
  // Search for unminified JS files in exactly assets/js
246
- const searchResults = minifyJS.findJS('assets/js', { recursive: false });
247
- console.log(searchResults);
246
+ const searchResults = minifyJS.findJS('assets/js', { recursive: false })
247
+ console.log(searchResults)
248
248
 
249
249
  /* sample output:
250
250
 
@@ -288,11 +288,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
288
288
 
289
289
  ## 🛠️ Related utilities
290
290
 
291
- ### [</> minify.js (Gulp)](https://gulp.minify-js.org) &nbsp;<a href="https://github.com/toolleeo/cli-apps#programming"><img height=18 src="https://assets.minify-js.org/images/badges/awesome/badge.svg?v=63bbeed"></a>
291
+ ### [</> minify.js (Gulp)](https://github.com/adamlui/minify.js/tree/main/gulp/) &nbsp;<a href="https://github.com/toolleeo/cli-apps#programming"><img height=18 src="https://assets.minify-js.org/images/badges/awesome/badge.svg?v=63bbeed"></a>
292
292
 
293
293
  > Gulp plug-in to recursively minify all JavaScript files.
294
- <br>[Install](https://gulp.minify-js.org/#-installation) /
295
- [Readme](https://gulp.minify-js.org/#readme) /
294
+ <br>[Install](https://github.com/adamlui/minify.js/tree/main/gulp/#-installation) /
295
+ [Readme](https://github.com/adamlui/minify.js/tree/main/gulp/#readme) /
296
296
  [Discuss](https://github.com/adamlui/minify.js/discussions)
297
297
 
298
298
  ### [{ } scss-to-css](https://scsstocss.org) &nbsp;<a href="https://github.com/toolleeo/cli-apps#conversion"><img height=18 src="https://assets.minify-js.org/images/badges/awesome/badge.svg?v=63bbeed"></a>
@@ -310,4 +310,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
310
310
 
311
311
  <picture><source media="(prefers-color-scheme: dark)" srcset="https://assets.minify-js.org/images/icons/home/white/icon32x27.png?v=ad67551"><img height=13 src="https://assets.minify-js.org/images/icons/home/dark-gray/icon32x27.png?v=ad67551"></picture> <a href="https://js-utils.org">**More JavaScript utilities**</a> /
312
312
  <a href="https://github.com/adamlui/minify.js/discussions">Discuss</a> /
313
- <a href="#-minifyjs">Back to top ↑</a>
313
+ <a href="#top">Back to top ↑</a>
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "2.1.0",
4
- "description": "Recursively minify all JavaScript files",
3
+ "version": "2.1.2",
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://minify-js.org",
10
+ "homepage": "https://github.com/adamlui/minify.js",
11
11
  "license": "MIT",
12
12
  "funding": [
13
13
  {
@@ -29,12 +29,13 @@
29
29
  ],
30
30
  "main": "dist/minify.min.js",
31
31
  "files": [
32
+ "dist/",
32
33
  "docs/",
33
34
  "!docs/*/"
34
35
  ],
35
36
  "bin": {
36
- "minifyjs": "dist/cli.min.js",
37
- "minify-js": "dist/cli.min.js"
37
+ "minifyjs": "dist/cli/index.min.js",
38
+ "minify-js": "dist/cli/index.min.js"
38
39
  },
39
40
  "directories": {
40
41
  "lib": "./dist",
@@ -64,7 +65,7 @@
64
65
  "utils"
65
66
  ],
66
67
  "bugs": {
67
- "url": "https://support.minify-js.org"
68
+ "url": "https://github.com/adamlui/minify.js/issues"
68
69
  },
69
70
  "dependencies": {
70
71
  "node-clipboardy": "^1.0.3",
package/dist/cli.min.js DELETED
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * © 2023–2026 Adam Lui & contributors under the MIT license.
4
- * Source: https://code.minify-js.org/node.js
5
- * Documentation: https://docs.minify-js.org/node.js
6
- */
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="589eb64";(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="",m="",p="",f="",d="",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@e6402d8a3fad4c1dc6ddaa84cb26fc0608e2dc1a/_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?|(?: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(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"}.`),console.info(`
10
- ${p+(h.info_validArgs||"Valid arguments are below")}.`),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"}.`),console.info(`
14
- ${f}${h.info_exampleValidCmd||"Example valid command"}: `+`
15
- » minify-js . output.min.js`),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")}:`),g.forEach(e=>console.info(e))):console.info(`
17
- ${p+(h.info_noFilesWillBeMinned||"No JS files will be minified")}.`);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?(b(`
18
- ${f+(h.info_minComplete||"Minification complete")}!`),b(d+e.length+" "+(h.info_file||"file")+`${1<e.length?"s":""} ${h.info_minified||"minified"}.${r}`)):b(`
19
- ${p+(h.info_noFilesProcessed||"No unminified JavaScript files processed")}.`),o.length&&(b(`
20
- ${m+o.length} `+(h.info_file||"file")+`${1<o.length?"s":""} ${h.info_failedToMinify||"failed to minify"}:${r}`),o.forEach(e=>b(e))),0!=e?.length&&($.copy&&1==e?.length?(console.log(`
21
- ${d}${e[0].code}`),b(`
22
- ${h.info_copying||"Copying to clipboard"}...`),t.writeSync(e[0].code)):(b(`
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"),b(` ${f}✓ `+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=` ${pkgName.replace(/^@[^/]+\//,"")}  `;let o={header:[`
24
- ├ `+i+(h.appCopyright||copyright),i+(h.prefix_source||"Source")+": "+srcURL],usage:[`
25
- ${d}o ${h.helpSection_usage||"Usage"}:`,` ${d}» ${f}${cmdFormat}`],pathArgs:[`
26
- ${d}o ${h.helpSection_pathArgs||"Path arguments"}:`," [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"}:`," -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"}:`,`--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"}:`," -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}`)}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}`)}function b(e){$.quietMode||console.info(e)}})();