@adamlui/minify.js 1.5.1 → 1.5.3

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
@@ -21,11 +21,11 @@
21
21
 
22
22
  <a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dm/%40adamlui%2Fminify.js?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
23
23
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
- <a href="https://github.com/adamlui/js-utils/releases/tag/minify.js-1.5.1"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.5.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
+ <a href="https://github.com/adamlui/minify.js/releases/tag/node-v1.5.3"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.5.3-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
25
25
  <a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fminify.js?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
26
26
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_minify.js%3Anode.js%2Fsrc%2Fminify.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
27
27
  <a href="https://github.com/toolleeo/cli-apps#programming"><img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
28
- <a href="https://minify-js.org"><img src="https://img.shields.io/badge/web-minify--js.org-lightgrey?logo=dribbble&logoColor=white&labelColor=464646&style=for-the-badge"></a>
28
+ <a href="https://minify-js.org"><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>
29
29
 
30
30
  <img src="https://raw.githubusercontent.com/adamlui/minify.js/main/node.js/media/images/screenshots/cli-minify-js-docs.png">
31
31
 
@@ -135,7 +135,8 @@ Boolean options:
135
135
  -q, --quiet Suppress all logging except errors.
136
136
 
137
137
  Parameter options:
138
- --comment=comment Prepend comment to minified code.
138
+ --comment="comment" Prepend comment to minified code. Separate
139
+ by line using '\n'.
139
140
 
140
141
  Info commands:
141
142
  -h, --help Display help screen.
@@ -202,14 +203,14 @@ minifyJS.minify(input, { dotFiles: true });
202
203
 
203
204
  Available parameters (and their default settings) are:
204
205
 
205
- Name | Type | Desciption | Default value
206
- -------------|---------|---------------------------------------------------------|---------------
207
- `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
208
- `verbose` | Boolean | Show logging in console/terminal. | `true`
209
- `dotFolders` | Boolean | Include dotfolders in file search. | `false`
210
- `dotFiles` | Boolean | Include dotfiles in file search. | `false`
211
- `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
212
- `comment` | String | Comment to prepend to minified code. | `''`
206
+ Name | Type | Desciption | Default value
207
+ -------------|---------|-------------------------------------------------------------------|---------------
208
+ `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
209
+ `verbose` | Boolean | Show logging in console/terminal. | `true`
210
+ `dotFolders` | Boolean | Include dotfolders in file search. | `false`
211
+ `dotFiles` | Boolean | Include dotfiles in file search. | `false`
212
+ `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
213
+ `comment` | String | Comment to prepend to minified code. Separate by line using '\n'. | `''`
213
214
 
214
215
  #
215
216
 
package/dist/cli.min.js CHANGED
@@ -1,17 +1,23 @@
1
1
  #!/usr/bin/env node
2
- const e="https://docs.minify-js.org/#-command-line-usage",n=require(__dirname.match(/src/)?"./minify":"./minify.min"),o=require("fs"),s=require("path"),r="",t="",l="",i="",a={},c={flags:{dryRun:/^--?(?:n|dry-?run)$/,includeDotFolders:/^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?=?(?:true|1)?)$/,includeDotFiles:/^--?(?:df|D|(?:include-?)?dot-?files?=?(?:true|1)?)$/,noRecursion:/^--?(?:R|(?:disable|no)-?recursi(?:on|ve)|recursi(?:on|ve)=(?:false|0))$/,noMangle:/^--?(?:M|(?:disable|no)-?mangle|mangle=(?:false|0))$/,quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},paramOptions:{comment:/^--?comments?(?:=.*|$)/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(i=>{var e,n,o;i.startsWith("-")&&(e=Object.keys(c.paramOptions).find(e=>c.paramOptions[e].test(i)),o=Object.keys(c.flags).find(e=>c.flags[e].test(i)),n=Object.keys(c.infoCmds).find(e=>c.infoCmds[e].test(i)),o?a[o]=!0:e?(i.includes("=")||(console.error(`
3
- ${t}ERROR: Arg [--${i.replace(/-/g,"")}] requires '=' followed by a value.`+r),d(),process.exit(1)),o=i.split("=")[1],a[e]=parseInt(o)||o):n||(console.error(`
4
- ${t}ERROR: Arg [${i}] not recognized.`+r),console.info(`
5
- ${l}Valid arguments are below.`+r),m(["flags","paramOptions","infoCmds"]),d(),process.exit(1)))}),process.argv.some(e=>c.infoCmds.help.test(e)))m();else if(process.argv.some(e=>c.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{const[u="",p=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),h=s.resolve(process.cwd(),u),g=(u&&!o.existsSync(h)&&(console.error(`
6
- ${t}Error: First argument can only be an existing file or directory.`+`
7
- ${h} does not exist.`+r+`
2
+ /**
3
+ * © 2023–2024 Adam Lui & contributors under the MIT license.
4
+ * Source: https://github.minify-js.org/tree/main/node.js/src
5
+ * Documentation: https://docs.minify-js.org
6
+ */
7
+ const pkgName="@adamlui/minify.js",docURL="https://docs.minify-js.org/#-command-line-usage",minifyJS=require(__dirname.match(/src/)?"./minify":"./minify.min"),fs=require("fs"),path=require("path"),execSync=require("child_process")["execSync"],nc="",br="",by="",bg="",config={},argRegex={flags:{dryRun:/^--?(?:n|dry-?run)$/,includeDotFolders:/^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?=?(?:true|1)?)$/,includeDotFiles:/^--?(?:df|D|(?:include-?)?dot-?files?=?(?:true|1)?)$/,noRecursion:/^--?(?:R|(?:disable|no)-?recursi(?:on|ve)|recursi(?:on|ve)=(?:false|0))$/,noMangle:/^--?(?:M|(?:disable|no)-?mangle|mangle=(?:false|0))$/,quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},paramOptions:{comment:/^--?comments?(?:=.*|$)/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(n=>{var e,i,o;n.startsWith("-")&&(e=Object.keys(argRegex.paramOptions).find(e=>argRegex.paramOptions[e].test(n)),o=Object.keys(argRegex.flags).find(e=>argRegex.flags[e].test(n)),i=Object.keys(argRegex.infoCmds).find(e=>argRegex.infoCmds[e].test(n)),o?config[o]=!0:e?(n.includes("=")||(console.error(`
8
+ ${br}ERROR: Arg [--${n.replace(/-/g,"")}] requires '=' followed by a value.`+nc),printHelpCmdAndDocURL(),process.exit(1)),o=n.split("=")[1],config[e]=parseInt(o)||o):i||(console.error(`
9
+ ${br}ERROR: Arg [${n}] not recognized.`+nc),console.info(`
10
+ ${by}Valid arguments are below.`+nc),printHelpSections(["flags","paramOptions","infoCmds"]),printHelpCmdAndDocURL(),process.exit(1)))}),process.argv.some(e=>argRegex.infoCmds.help.test(e)))printHelpSections();else if(process.argv.some(e=>argRegex.infoCmds.version.test(e))){const k=execSync(`npm view ${pkgName} version`).toString().trim()||"none";let e,i=process.cwd();for(;"/"!=i;){const n=path.join(i,"package.json");if(fs.existsSync(n)){const o=require(n);e=(o.dependencies?.[pkgName]||o.devDependencies?.[pkgName])?.match(/(\d+\.\d+\.\d+)/)[0]||"none";break}i=path.dirname(i)}console.info(`
11
+ Global version: `+k),console.info("Local version: "+e)}else{const[p="",q=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),r=path.resolve(process.cwd(),p),s=(p&&!fs.existsSync(r)&&(console.error(`
12
+ ${br}Error: First argument can only be an existing file or directory.`+`
13
+ ${r} does not exist.`+nc+`
8
14
 
9
- ${i}Example valid command:
10
- » minify-js . output.min.js`+r),d(),process.exit(1)),u.endsWith(".js")?[h]:n.findJS(h,{recursive:!a.noRecursion,verbose:!a.quietMode}));if(a.dryRun)0<g.length?(console.info(`
11
- ${l}JS files to be minified:`+r),g.forEach(e=>console.info(e))):console.info(l+`
12
- No JS files will be minified.`+r);else{const v=[],y=g.map(e=>{var i=n.minify(e,{verbose:!a.quietMode,mangle:!a.noMangle,comment:a.comment});return i.error&&v.push(e),i}).filter(e=>!e.error);y?.forEach(({code:e,srcPath:i})=>{var n=s.join(s.dirname(i),(/so?u?rce?$/.test(s.dirname(i))?"../":"")+(p.endsWith(".js")?s.dirname(p):p||"min")),i=(p.endsWith(".js")&&u.endsWith(".js")?s.basename(p).replace(/(\.min)?\.js$/,""):s.basename(i,".js"))+".min.js",i=s.join(n,i);o.existsSync(n)||o.mkdirSync(n,{recursive:!0}),o.writeFileSync(i,e,"utf8")}),0<y?.length?(f(`
13
- ${i}Minification complete!`+r),f(`${y.length} file${1<y.length?"s":""} minified.`)):f(l+"No unminified JavaScript files processed."+r),0<v.length&&(f(`
14
- `+t+v.length+" file"+(1<v.length?"s":"")+" failed to minify:"+r),v.forEach(e=>f(e)))}}function m(e=["cmdFormat","pathArgs","flags","paramOptions","infoCmds"]){const i={cmdFormat:[`
15
- ${l}minify-js [inputPath] [outputPath] [options]`+r],pathArgs:["\nPath arguments:"," [inputPath] Path to JS file or directory containing JS files to be minified, relative to the current working directory."," [outputPath] Path to file or directory where minified files will be stored, relative to original file location (if not provided, min/ is used)."],flags:["\nBoolean options:"," -n, --dry-run Don't actually minify the file(s), just show if they will be processed."," -d, --include-dotfolders Include dotfolders in file search."," -D, --include-dotfiles Include dotfiles in file search."," -R, --no-recursion Disable recursive file searching."," -M, --no-mangle Disable mangling names."," -q, --quiet Suppress all logging except errors."],paramOptions:["\nParameter options:"," --comment=comment Prepend comment to minified code."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{i[e]?.forEach(e=>{{const o=process.stdout.columns||80,s=[],i=e.match(/\S+|\s+/g);let n="";i.forEach(e=>{var i=o-(0===s.length?0:29);n.length+e.length>i&&(s.push(0===s.length?n:n.trimStart()),n=""),n+=e}),s.push(0===s.length?n:n.trimStart()),s.forEach((e,i)=>console.info(0===i?e:" ".repeat(29)+e))}})})}function d(){console.info(`
16
- ${l}For more help, type 'minify-js --help' or visit
17
- `+(e+r))}function f(e){a.quietMode||console.info(e)}
15
+ ${bg}Example valid command:
16
+ » minify-js . output.min.js`+nc),printHelpCmdAndDocURL(),process.exit(1)),p.endsWith(".js")?[r]:minifyJS.findJS(r,{recursive:!config.noRecursion,verbose:!config.quietMode}));if(config.dryRun)0<s.length?(console.info(`
17
+ ${by}JS files to be minified:`+nc),s.forEach(e=>console.info(e))):console.info(by+`
18
+ No JS files will be minified.`+nc);else{const w=[],x=s.map(e=>{var n=minifyJS.minify(e,{verbose:!config.quietMode,mangle:!config.noMangle,comment:config.comment?.replace(/\\n/g,"\n")});return n.error&&w.push(e),n}).filter(e=>!e.error);x?.forEach(({code:e,srcPath:n})=>{var i=path.join(path.dirname(n),(/so?u?rce?$/.test(path.dirname(n))?"../":"")+(q.endsWith(".js")?path.dirname(q):q||"min")),n=(q.endsWith(".js")&&p.endsWith(".js")?path.basename(q).replace(/(\.min)?\.js$/,""):path.basename(n,".js"))+".min.js",n=path.join(i,n);fs.existsSync(i)||fs.mkdirSync(i,{recursive:!0}),fs.writeFileSync(n,e,"utf8")}),0<x?.length?(printIfNotQuiet(`
19
+ ${bg}Minification complete!`+nc),printIfNotQuiet(`${x.length} file${1<x.length?"s":""} minified.`)):printIfNotQuiet(by+"No unminified JavaScript files processed."+nc),0<w.length&&(printIfNotQuiet(`
20
+ `+br+w.length+" file"+(1<w.length?"s":"")+" failed to minify:"+nc),w.forEach(e=>printIfNotQuiet(e)))}}function printHelpSections(e=["cmdFormat","pathArgs","flags","paramOptions","infoCmds"]){const n={cmdFormat:[`
21
+ ${by}minify-js [inputPath] [outputPath] [options]`+nc],pathArgs:["\nPath arguments:"," [inputPath] Path to JS file or directory containing JS files to be minified, relative to the current working directory."," [outputPath] Path to file or directory where minified files will be stored, relative to original file location (if not provided, min/ is used)."],flags:["\nBoolean options:"," -n, --dry-run Don't actually minify the file(s), just show if they will be processed."," -d, --include-dotfolders Include dotfolders in file search."," -D, --include-dotfiles Include dotfiles in file search."," -R, --no-recursion Disable recursive file searching."," -M, --no-mangle Disable mangling names."," -q, --quiet Suppress all logging except errors."],paramOptions:["\nParameter options:",' --comment="comment" Prepend comment to minified code.'],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{n[e]?.forEach(e=>{{const o=process.stdout.columns||80,t=[],n=e.match(/\S+|\s+/g);let i="";n.forEach(e=>{var n=o-(0==t.length?0:29);i.length+e.length>n&&(t.push(0==t.length?i:i.trimStart()),i=""),i+=e}),t.push(0==t.length?i:i.trimStart()),t.forEach((e,n)=>console.info(0==n?e:" ".repeat(29)+e))}})})}function printHelpCmdAndDocURL(){console.info(`
22
+ ${by}For more help, type 'minify-js --help' or visit
23
+ `+(docURL+nc))}function printIfNotQuiet(e){config.quietMode||console.info(e)}
@@ -1,5 +1,13 @@
1
1
  #!/usr/bin/env node
2
- const c=require("fs"),l=require("path"),t=require("uglify-js");function f(r,i={}){var e="https://docs.minify-js.org/#findjssearchdir-options",o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1};if("string"!=typeof r)console.error("findJS() » ERROR: 1st arg <searchDir> must be a string."),console.info("findJS() » For more help, please visit "+e);else{var n=l.resolve(process.cwd(),r);if(c.existsSync(n)){if(m(i,o,e,"findJS('assets/js', { verbose: false, dotFoldes: true })")){i={...o,...i};const s=c.readdirSync(r),t=[];return i.verbose&&!i.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),s.forEach(e=>{var o=l.resolve(r,e);c.statSync(o).isDirectory()&&"node_modules"!=e&&(i.dotFolders||!e.startsWith("."))&&i.recursive?t.push(...f(o,{...i,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!i.dotFiles&&e.startsWith(".")||t.push(o)}),!i.isRecursing&&i.verbose&&(console.info("findJS() » Search complete! "+(0===t.length?"No":t.length)+` file${0==t.length||1<t.length?"s":""} found.`),"minify"===f.caller.name||process.argv.some(e=>e.includes("gulp"))||/cli(?:\.min)?\.js$/.test(require.main.filename)||console.info("findJS() » Check returned array.")),i.isRecursing||0<t.length?t:[]}}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${n} does not exist.`),console.info("findJS() » For more help, please visit "+e)}}function e(e,r={}){var o="https://docs.minify-js.org/#minifyinput-options",i={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,comment:""};if("string"!=typeof e)console.error("minify() » ERROR: 1st arg <input> must be a string."),console.info("minify() » For more help, please visit "+o);else if(m(r,i,o,"minify('assets/js', { recursive: false, mangle: false })")){const s={mangle:!!(r={...i,...r}).mangle&&{toplevel:!0}};return c.existsSync(e)?e.endsWith(".js")?(r.verbose&&console.info(`minify() » Minifying ${e}...`),o=t.minify(c.readFileSync(e,"utf8"),s),r.comment&&(o.code=n(o.code)),o.error?console.error("minify() » ERROR: "+o.error.message):!r.verbose||process.argv.some(e=>e.includes("gulp"))||/cli(?:\.min)?\.js$/.test(require.main.filename)||console.info("minify() » Minification complete. Check returned object."),{code:o.code,srcPath:l.resolve(process.cwd(),e),error:o.error}):(i=f(e,{recursive:r.recursive,verbose:r.verbose,dotFolders:r.dotFolders,dotFiles:r.dotFiles})?.map(e=>{r.verbose&&console.info(`minify() » Minifying ${e}...`);var o=c.readFileSync(e,"utf8"),o=t.minify(o,s);return r.comment&&(o.code=n(o.code)),o.error&&console.error("minify() » ERROR: "+o.error.message),{code:o.code,srcPath:e,error:o.error}}).filter(e=>!e.error),r.verbose&&(0<i.length?console.info("minify() » Minification complete. Check returned object."):console.info("minify() » No unminified JavaScript files processed.")),i):(r.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » Minifying passed source code..."),o=t.minify(e,s),r.comment&&(o.code=n(o.code)),o.error?console.error("minify() » ERROR: "+o.error.message):r.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » Minification complete. Check returned object."),{code:o.code,srcPath:void 0,error:o.error});function n(e){return`/*
3
- ${r.comment}
4
- */
5
- `+e}}}function m(e,o,r,i){const n=JSON.stringify(o,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),s=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=(m.caller?.name||"validateOptions")+"() » ";var f=()=>{console.info(l+`Valid options: [ ${s} ]`),console.info(l+"If omitted, default settings are: "+n)},a=()=>{console.info(l+"For more help, please visit "+r)};if("object"!=typeof e)return console.error(l+"ERROR: [options] can only be an object of key/values."),console.info(l+"Example valid call: "+i),f(),a(),!1;for(const d in e){if("isRecursing"!=d&&!Object.prototype.hasOwnProperty.call(o,d))return console.error(l+`ERROR: \`${d}\` is an invalid option.`),f(),a(),!1;if(t.includes(d)&&"boolean"!=typeof e[d])return console.error(l+`ERROR: [${d}] option can only be \`true\` or \`false\`.`),a(),!1;if(c.includes(d)&&(e[d]=parseInt(e[d],10),isNaN(e[d])||e[d]<1))return console.error(l+`ERROR: [${d}] option can only be an integer > 0.`),a(),!1}return!0}module.exports={minify:e,find:f,findJS:f};
2
+ /**
3
+ * © 2023–2024 Adam Lui & contributors under the MIT license.
4
+ * Source: https://github.minify-js.org/tree/main/node.js/src
5
+ * Documentation: https://docs.minify-js.org
6
+ */
7
+ const fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(i,r={}){var e="https://docs.minify-js.org/#findjssearchdir-options",o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1};if("string"!=typeof i)console.error("findJS() » ERROR: 1st arg <searchDir> must be a string."),console.info("findJS() » For more help, please visit "+e);else{var n=path.resolve(process.cwd(),i);if(fs.existsSync(n)){if(validateOptions(r,o,e,"findJS('assets/js', { verbose: false, dotFoldes: true })")){r={...o,...r};const s=fs.readdirSync(i),t=[];return r.verbose&&!r.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),s.forEach(e=>{var o=path.resolve(i,e);fs.statSync(o).isDirectory()&&"node_modules"!=e&&(r.dotFolders||!e.startsWith("."))&&r.recursive?t.push(...findJS(o,{...r,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!r.dotFiles&&e.startsWith(".")||t.push(o)}),!r.isRecursing&&r.verbose&&(console.info("findJS() » Search complete! "+(0==t.length?"No":t.length)+` file${0==t.length||1<t.length?"s":""} found.`),"minify"==findJS.caller.name||process.argv.some(e=>e.includes("gulp"))||/cli(?:\.min)?\.js$/.test(require.main.filename)||console.info("findJS() » Check returned array.")),r.isRecursing||0<t.length?t:[]}}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${n} does not exist.`),console.info("findJS() » For more help, please visit "+e)}}function minify(e,r={}){var o="https://docs.minify-js.org/#minifyinput-options",i={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,comment:""};if("string"!=typeof e)console.error("minify() » ERROR: 1st arg <input> must be a string."),console.info("minify() » For more help, please visit "+o);else if(validateOptions(r,i,o,"minify('assets/js', { recursive: false, mangle: false })")){const s={mangle:(r={...i,...r}).mangle};return fs.existsSync(e)?e.endsWith(".js")?(r.verbose&&console.info(`minify() » Minifying ${e}...`),o=uglifyJS.minify(fs.readFileSync(e,"utf8"),s),r.comment&&(o.code=n(o.code)),o.error?console.error("minify() » ERROR: "+o.error.message):!r.verbose||process.argv.some(e=>e.includes("gulp"))||/cli(?:\.min)?\.js$/.test(require.main.filename)||console.info("minify() » Minification complete. Check returned object."),{code:o.code,srcPath:path.resolve(process.cwd(),e),error:o.error}):(i=findJS(e,{recursive:r.recursive,verbose:r.verbose,dotFolders:r.dotFolders,dotFiles:r.dotFiles})?.map(e=>{r.verbose&&console.info(`minify() » Minifying ${e}...`);var o=fs.readFileSync(e,"utf8"),o=uglifyJS.minify(o,s);return r.comment&&(o.code=n(o.code)),o.error&&console.error("minify() » ERROR: "+o.error.message),{code:o.code,srcPath:e,error:o.error}}).filter(e=>!e.error),r.verbose&&(0<i.length?console.info("minify() » Minification complete. Check returned object."):console.info("minify() » No unminified JavaScript files processed.")),i):(r.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » Minifying passed source code..."),o=uglifyJS.minify(e,s),r.comment&&(o.code=n(o.code)),o.error?console.error("minify() » ERROR: "+o.error.message):r.verbose&&!process.argv.some(e=>e.includes("gulp"))&&console.info("minify() » Minification complete. Check returned object."),{code:o.code,srcPath:void 0,error:o.error});function n(e){var o=r.comment.split("\n").map(e=>" * "+e).join("\n"),i=e.indexOf("#!");return 0<=i?(i=e.indexOf("\n",i)+1,e.slice(0,i)+`/**
8
+ ${o}
9
+ */
10
+ `+e.slice(i)):`/**
11
+ ${o}
12
+ */
13
+ `+e}}}function validateOptions(e,o,i,r){const n=JSON.stringify(o,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),s=Object.keys(o).join(", "),t=Object.keys(o).filter(e=>"boolean"==typeof o[e]),l=Object.keys(o).filter(e=>Number.isInteger(o[e])),c=(validateOptions.caller?.name||"validateOptions")+"() » ";var f=()=>{console.info(c+`Valid options: [ ${s} ]`),console.info(c+"If omitted, default settings are: "+n)},a=()=>{console.info(c+"For more help, please visit "+i)};if("object"!=typeof e)return console.error(c+"ERROR: [options] can only be an object of key/values."),console.info(c+"Example valid call: "+r),f(),a(),!1;for(const m in e){if("isRecursing"!=m&&!Object.prototype.hasOwnProperty.call(o,m))return console.error(c+`ERROR: \`${m}\` is an invalid option.`),f(),a(),!1;if(t.includes(m)){if("mangle"==m){var d=()=>console.error(c+"ERROR: [mangle] option can only be `true`, `false`, or an object w/ key [toplevel] set to `true` or `false`.");if("object"==typeof e.mangle){for(const u in e.mangle)if(!["toplevel"].includes(u)||"boolean"!=typeof e.mangle[u])return d(),a(),!1}else if("boolean"!=typeof e.mangle)return d(),a(),!1}else if("boolean"!=typeof e[m])return console.error(c+`ERROR: [${m}] option can only be \`true\` or \`false\`.`),a(),!1}else if(l.includes(m)&&(e[m]=parseInt(e[m],10),isNaN(e[m])||e[m]<1))return console.error(c+`ERROR: [${m}] option can only be an integer > 0.`),a(),!1}return!0}module.exports={minify:minify,find:findJS,findJS:findJS};
package/docs/README.md CHANGED
@@ -21,11 +21,11 @@
21
21
 
22
22
  <a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dm/%40adamlui%2Fminify.js?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
23
23
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
- <a href="https://github.com/adamlui/js-utils/releases/tag/minify.js-1.5.1"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.5.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
+ <a href="https://github.com/adamlui/minify.js/releases/tag/node-v1.5.3"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.5.3-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
25
25
  <a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fminify.js?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
26
26
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_minify.js%3Anode.js%2Fsrc%2Fminify.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
27
27
  <a href="https://github.com/toolleeo/cli-apps#programming"><img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
28
- <a href="https://minify-js.org"><img src="https://img.shields.io/badge/web-minify--js.org-lightgrey?logo=dribbble&logoColor=white&labelColor=464646&style=for-the-badge"></a>
28
+ <a href="https://minify-js.org"><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>
29
29
 
30
30
  <img src="https://raw.githubusercontent.com/adamlui/minify.js/main/node.js/media/images/screenshots/cli-minify-js-docs.png">
31
31
 
@@ -135,7 +135,8 @@ Boolean options:
135
135
  -q, --quiet Suppress all logging except errors.
136
136
 
137
137
  Parameter options:
138
- --comment=comment Prepend comment to minified code.
138
+ --comment="comment" Prepend comment to minified code. Separate
139
+ by line using '\n'.
139
140
 
140
141
  Info commands:
141
142
  -h, --help Display help screen.
@@ -202,14 +203,14 @@ minifyJS.minify(input, { dotFiles: true });
202
203
 
203
204
  Available parameters (and their default settings) are:
204
205
 
205
- Name | Type | Desciption | Default value
206
- -------------|---------|---------------------------------------------------------|---------------
207
- `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
208
- `verbose` | Boolean | Show logging in console/terminal. | `true`
209
- `dotFolders` | Boolean | Include dotfolders in file search. | `false`
210
- `dotFiles` | Boolean | Include dotfiles in file search. | `false`
211
- `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
212
- `comment` | String | Comment to prepend to minified code. | `''`
206
+ Name | Type | Desciption | Default value
207
+ -------------|---------|-------------------------------------------------------------------|---------------
208
+ `recursive` | Boolean | Recursively search for nested files if dir path passed. | `true`
209
+ `verbose` | Boolean | Show logging in console/terminal. | `true`
210
+ `dotFolders` | Boolean | Include dotfolders in file search. | `false`
211
+ `dotFiles` | Boolean | Include dotfiles in file search. | `false`
212
+ `mangle` | Boolean | Shorten variable names (typically to one character). | `true`
213
+ `comment` | String | Comment to prepend to minified code. Separate by line using '\n'. | `''`
213
214
 
214
215
  #
215
216
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "scripts": {
28
28
  "test": "bash utils/test/minify-cli.test.sh",
29
- "build": "node src/cli src dist",
29
+ "build": "bash utils/build.sh",
30
30
  "bump:patch": "bash utils/bump.sh patch",
31
31
  "bump:minor": "bash utils/bump.sh minor",
32
32
  "bump:major": "bash utils/bump.sh major",