@adamlui/minify.js 1.4.9 → 1.4.10

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
@@ -19,9 +19,9 @@
19
19
 
20
20
  ### Recursively minify all JavaScript files.
21
21
 
22
- <a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fminify.js?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
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.4.9"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.9-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
+ <a href="https://github.com/adamlui/js-utils/releases/tag/minify.js-1.4.10"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.10-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_js-utils:minify.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_js-utils%3Aminify.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
 
package/dist/cli.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const o=require("fs"),s=require("path"),n=require("./minify"),r="",t="",l="",e="",c={},a={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)?$/,help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/};if(process.argv.forEach(i=>{var e;i.startsWith("-")&&((e=Object.keys(a).find(e=>a[e].test(i)))?c[e]=!0:(console.error(`
2
+ const n=require(__dirname.match(/src/)?"./minify":"./minify.min"),o=require("fs"),s=require("path"),r="",t="",l="",e="",c={},a={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)?$/,help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/};if(process.argv.forEach(i=>{var e;i.startsWith("-")&&((e=Object.keys(a).find(e=>a[e].test(i)))?c[e]=!0:(console.error(`
3
3
  ${t}ERROR: Arg [${i}] not recognized.`+r),console.info(`
4
4
  ${l}Valid arguments are below.`+r),d(["configOptions","infoCmds"]),process.exit(1)))}),process.argv.some(e=>a.help.test(e)))d();else if(process.argv.some(e=>a.version.test(e)))console.info("v"+require("./package.json").version);else{const[f="",m=""]=process.argv.slice(2).filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),u=s.resolve(process.cwd(),f),h=(f&&!o.existsSync(u)&&(console.error(`
5
5
  ${t}Error: First argument can only be an existing file or directory.`+`
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const a=require("fs"),d=require("path"),f=require("uglify-js");function y(o,i={}){var e={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1};if("string"!=typeof o)return console.error("findJS() » ERROR: 1st arg <searchDir> must be a string.");var r=d.resolve(process.cwd(),o);if(a.existsSync(r)){const s=JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),t=Object.keys(e).join(", ");var n=()=>{console.info(`findJS() » Valid options: [ ${t} ]`),console.info("findJS() » If omitted, default settings are: "+s)};if("object"==typeof i){for(const f in i){if(!Object.prototype.hasOwnProperty.call(e,f)&&"isRecursing"!==f)return console.error(`findJS() » ERROR: \`${f}\` is an invalid option.`),void n();if("boolean"!=typeof i[f])return console.error(`findJS() » ERROR: [${f}] option can only be \`true\` or \`false\`.`)}i={...e,...i};const l=a.readdirSync(o),c=[];return i.verbose&&!i.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),l.forEach(e=>{var r=d.resolve(o,e);a.statSync(r).isDirectory()&&"node_modules"!=e&&(i.dotFolders||!e.startsWith("."))&&i.recursive?c.push(...y(r,{...i,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!i.dotFiles&&e.startsWith(".")||c.push(r)}),!i.isRecursing&&i.verbose&&(console.info("findJS() » Search complete! "+(0===c.length?"No":c.length)+` file${1<c.length?"s":""} found.`),"minify"===y.caller.name||require.main.filename.endsWith("cli.js")||console.info("findJS() » Check returned array.")),i.isRecursing||0<c.length?c:[]}console.error("findJS() » ERROR: 2nd arg [options] can only be an object of key/values."),console.info("findJS() » Example valid call: findJS('assets/js', { verbose: false, dotFolders: true })"),n()}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${r} does not exist.`)}function e(e,o={}){var r={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0};if("string"!=typeof e)return console.error("minify() » ERROR: 1st arg <input> must be a string.");const i=JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(r).join(", ");var s,t=()=>{console.info(`minify() » Valid options: [ ${n} ]`),console.info("minify() » If omitted, default settings are: "+i)};if("object"==typeof o){for(const c in o){if(!Object.prototype.hasOwnProperty.call(r,c))return console.error(`minify() » ERROR: \`${c}\` is an invalid option.`),void t();if("boolean"!=typeof o[c])return console.error(`minify() » ERROR: [${c}] option can only be \`true\` or \`false\`.`)}const l={mangle:!!(o={...r,...o}).mangle&&{toplevel:!0}};return a.existsSync(e)?e.endsWith(".js")?(o.verbose&&console.info(`minify() » Minifying ${e}...`),(s=f.minify(a.readFileSync(e,"utf8"),l)).error&&console.error("minify() » ERROR: "+s.error.message),{code:s.code,srcPath:d.resolve(process.cwd(),e),error:s.error}):y(e,{recursive:o.recursive,verbose:o.verbose,dotFolders:o.dotFolders,dotFiles:o.dotFiles})?.map(e=>{o.verbose&&console.info(`minify() » Minifying ${e}...`);var r=a.readFileSync(e,"utf8"),r=f.minify(r,l);return r.error&&console.error("minify() » ERROR: "+r.error.message),{code:r.code,srcPath:e,error:r.error}}).filter(e=>!e.error):(o.verbose&&console.info("minify() » Minifying passed source code..."),(s=f.minify(e,l)).error&&console.error("minify() » ERROR: "+s.error.message),{code:s.code,srcPath:void 0,error:s.error})}console.error("minify() » ERROR: 2nd arg [options] can only be an object of key/values."),console.info("minify() » Example valid call: minify('assets/js', { recursive: false, mangle: false })"),t()}module.exports={minify:e,findJS:y};
2
+ const t=require("fs"),l=require("path"),i=require("uglify-js");function c(o,s={}){var e={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1};if("string"!=typeof o)return console.error("findJS() » ERROR: 1st arg <searchDir> must be a string.");var r=l.resolve(process.cwd(),o);if(t.existsSync(r)){if(f(s,e,"findJS('assets/js', { verbose: false, dotFolders: true })")){s={...e,...s};const i=t.readdirSync(o),n=[];return s.verbose&&!s.isRecursing&&console.info("findJS() » Searching for unminified JS files..."),i.forEach(e=>{var r=l.resolve(o,e);t.statSync(r).isDirectory()&&"node_modules"!=e&&(s.dotFolders||!e.startsWith("."))&&s.recursive?n.push(...c(r,{...s,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!s.dotFiles&&e.startsWith(".")||n.push(r)}),!s.isRecursing&&s.verbose&&(console.info("findJS() » Search complete! "+(0===n.length?"No":n.length)+` file${1<n.length?"s":""} found.`),"minify"===c.caller.name||require.main.filename.endsWith("cli.js")||console.info("findJS() » Check returned array.")),s.isRecursing||0<n.length?n:[]}}else console.error("findJS() » ERROR: 1st arg <searchDir> must be an existing directory."),console.error(`findJS() » ${r} does not exist.`)}function e(e,o={}){var r={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0};if("string"!=typeof e)return console.error("minify() » ERROR: 1st arg <input> must be a string.");if(f(o,r,"minify('assets/js', { recursive: false, mangle: false })")){const s={mangle:!!(o={...r,...o}).mangle&&{toplevel:!0}};return t.existsSync(e)?e.endsWith(".js")?(o.verbose&&console.info(`minify() » Minifying ${e}...`),(r=i.minify(t.readFileSync(e,"utf8"),s)).error&&console.error("minify() » ERROR: "+r.error.message),{code:r.code,srcPath:l.resolve(process.cwd(),e),error:r.error}):c(e,{recursive:o.recursive,verbose:o.verbose,dotFolders:o.dotFolders,dotFiles:o.dotFiles})?.map(e=>{o.verbose&&console.info(`minify() » Minifying ${e}...`);var r=t.readFileSync(e,"utf8"),r=i.minify(r,s);return r.error&&console.error("minify() » ERROR: "+r.error.message),{code:r.code,srcPath:e,error:r.error}}).filter(e=>!e.error):(o.verbose&&console.info("minify() » Minifying passed source code..."),(r=i.minify(e,s)).error&&console.error("minify() » ERROR: "+r.error.message),{code:r.code,srcPath:void 0,error:r.error})}}function f(e,r,o){const s=(f.caller?.name||"validateOptions")+"() » ",i=JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(r).join(", "),t=Object.keys(r).filter(e=>"boolean"==typeof r[e]),l=Object.keys(r).filter(e=>Number.isInteger(r[e]));var c=()=>{console.info(s+`Valid options: [ ${n} ]`),console.info(s+"If omitted, default settings are: "+i)};if("object"!=typeof e)return console.error(s+"ERROR: [options] can only be an object of key/values."),console.info(s+"Example valid call: "+o),c(),!1;for(const a in e){if("isRecursing"!=a&&!Object.prototype.hasOwnProperty.call(r,a))return console.error(s+`ERROR: \`${a}\` is an invalid option.`),c(),!1;if(t.includes(a)&&"boolean"!=typeof e[a])return console.error(s+`ERROR: [${a}] option can only be \`true\` or \`false\`.`),!1;if(l.includes(a)&&(e[a]=parseInt(e[a],10),isNaN(e[a])||e[a]<1))return console.error(s+`ERROR: [${a}] option can only be an integer > 0.`),!1}return!0}module.exports={minify:e,findJS:c};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -30,6 +30,7 @@
30
30
  "bump:patch": "bash utils/bump.sh patch",
31
31
  "bump:minor": "bash utils/bump.sh minor",
32
32
  "bump:major": "bash utils/bump.sh major",
33
+ "prepublishOnly": "npm test",
33
34
  "publish:patch": "bash utils/bump.sh patch --publish",
34
35
  "publish:minor": "bash utils/bump.sh minor --publish",
35
36
  "publish:major": "bash utils/bump.sh major --publish"