@adamlui/minify.js 2.1.4 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -4
- package/dist/cli/index.min.js +7 -19
- package/dist/cli/lib/data.min.js +4 -4
- package/dist/cli/lib/language.min.js +6 -4
- package/dist/cli/lib/log.min.js +23 -0
- package/dist/cli/lib/settings.min.js +8 -0
- package/dist/data/app.json +2 -1
- package/dist/data/messages.json +20 -4
- package/dist/data/minify.config.mjs +24 -0
- package/dist/minify.min.js +5 -5
- package/docs/README.md +33 -4
- package/package.json +6 -2
- package/dist/cli/lib/print.min.js +0 -17
package/README.md
CHANGED
|
@@ -27,8 +27,8 @@
|
|
|
27
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>
|
|
28
28
|
<a href="#%EF%B8%8F-mit-license">
|
|
29
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.
|
|
31
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.
|
|
30
|
+
<a href="https://github.com/adamlui/minify.js/releases/tag/node-v2.2.0">
|
|
31
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.2.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
32
32
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code">
|
|
33
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>
|
|
34
34
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js">
|
|
@@ -155,12 +155,41 @@ Parameter options:
|
|
|
155
155
|
--ignores="dir/,file1.js,file2.js" Files/directories to exclude from minification.
|
|
156
156
|
--comment="comment" Prepend header comment to minified code.
|
|
157
157
|
Separate by line using '\n'.
|
|
158
|
+
--config="path/to/file" Load custom config file.
|
|
158
159
|
|
|
159
|
-
|
|
160
|
+
Commands:
|
|
161
|
+
--init Create config file (in project root).
|
|
160
162
|
-h, --help Display help screen.
|
|
161
163
|
-v, --version Show version number.
|
|
162
164
|
```
|
|
163
165
|
|
|
166
|
+
#
|
|
167
|
+
|
|
168
|
+
### Configuration file
|
|
169
|
+
|
|
170
|
+
**minify.js** can be customized using a `minify.config.mjs` or `minify.config.js` placed in your project root.
|
|
171
|
+
|
|
172
|
+
Example defaults:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
export default {
|
|
176
|
+
dryRun: false, // don't actually minify the file(s), just show if they will be processed
|
|
177
|
+
includeDotFolders: false, // include dotfolders in file search
|
|
178
|
+
includeDotFiles: false, // include dotfiles in file search
|
|
179
|
+
noRecursion: false, // disable recursive file searching
|
|
180
|
+
noMangle: false, // disable mangling names
|
|
181
|
+
noFilenameChange: false, // disable changing file extension to .min.js
|
|
182
|
+
rewriteImports: false, // update import paths from .js to .min.js
|
|
183
|
+
copy: false, // copy minified code to clipboard instead of write to file if single file processed
|
|
184
|
+
relativeOutput: false, // output files relative to each src file instead of to input root
|
|
185
|
+
quietMode: false, // suppress all logging except errors
|
|
186
|
+
ignores: '', // files/dirs to exclude from minification
|
|
187
|
+
comment: '' // header comment to prepend to minified code
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
💡 Run `minify-js init` to generate a template `minify.config.mjs` in your project root.
|
|
192
|
+
|
|
164
193
|
<br>
|
|
165
194
|
|
|
166
195
|
<img height=6px width="100%" src="https://assets.minify-js.org/images/separators/aqua-gradient.png?v=ad67551">
|
|
@@ -192,7 +221,7 @@ const minifyJS = require('@adamlui/minify.js')
|
|
|
192
221
|
If **source code** is passed, it is directly minified, then an object containing `srcPath` + `code` + `error` is returned:
|
|
193
222
|
|
|
194
223
|
```js
|
|
195
|
-
const srcCode = 'function add(first, second) { return first + second
|
|
224
|
+
const srcCode = 'function add(first, second) { return first + second }',
|
|
196
225
|
minifyResult = minifyJS.minify(srcCode)
|
|
197
226
|
|
|
198
227
|
console.log(minifyResult.error) // outputs runtime error, or `undefined` if no error
|
package/dist/cli/index.min.js
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* © 2024–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
6
|
*/
|
|
7
|
-
(async()=>{globalThis.env={
|
|
8
|
-
|
|
9
|
-
${app.
|
|
10
|
-
${app.
|
|
11
|
-
${app.colors.br}${app.msgs.prefix_error}: `+app.msgs.error_firstArgNotExist+"."+`
|
|
12
|
-
${o} ${app.msgs.error_doesNotExist}.`+app.colors.nc),console.info(`
|
|
13
|
-
${app.colors.bg}${app.msgs.info_exampleValidCmd}: `+`
|
|
14
|
-
» minify-js . output.min.js`+app.colors.nc),l.helpCmdAndDocURL(),process.exit(1)));var r,g=o.endsWith(".js")&&!c.statSync(o).isDirectory()?[o]:p.findJS(o,{recursive:!app.config.noRecursion,verbose:!app.config.quietMode,ignores:(app.config.ignores?.split(",")??[]).map(e=>e.trim())});if(app.config.dryRun)g.length?(console.info(`
|
|
15
|
-
${app.colors.by}${app.msgs.info_filesToBeMinned}:`+app.colors.nc),g.forEach(e=>console.info(e))):console.info(`
|
|
16
|
-
${app.colors.by}${app.msgs.info_noFilesWillBeMinned}.`+app.colors.nc);else{let s=[],e=[];!app.config.relativeOutput&&c.statSync(o).isDirectory()?(r=p.minify(o,{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()):[]}))&&(r.error?s.push(o):e=[].concat(r)):e=g.map(e=>{var o=p.minify(e,{verbose:!app.config.quietMode,mangle:!app.config.noMangle,comment:app.config.comment?.replace(/\\n/g,"\n")});return o.error&&s.push(e),o}).filter(e=>!e.error),e?.length?(l.ifNotQuiet(`
|
|
17
|
-
${app.colors.bg}${app.msgs.info_minComplete}!`+app.colors.nc),l.ifNotQuiet(""+app.colors.bw+e.length+" "+app.msgs.info_file+`${1<e.length?"s":""} ${app.msgs.info_minified}.`+app.colors.nc)):l.ifNotQuiet(`
|
|
18
|
-
${app.colors.by}${app.msgs.info_noFilesProcessed}.`+app.colors.nc),s.length&&(l.ifNotQuiet(`
|
|
19
|
-
${app.colors.br}${s.length} `+app.msgs.info_file+`${1<s.length?"s":""} ${app.msgs.info_failedToMinify}:`+app.colors.nc),s.forEach(e=>l.ifNotQuiet(e))),e?.length&&(app.config.copy&&1==e?.length?(console.log(`
|
|
20
|
-
`+app.colors.bw+e[0].code+app.colors.nc),l.ifNotQuiet(`
|
|
21
|
-
${app.msgs.info_copying}...`),i.writeSync(e[0].code)):(l.ifNotQuiet(`
|
|
22
|
-
${app.msgs.info_writing}${1<e?.length?"s":""}...`),e?.forEach(({code:e,srcPath:s,relPath:i})=>{let p,r;if(!app.config.relativeOutput&&i){let e=t.resolve(process.cwd(),a||"min"),o=t.dirname(i);p="."!=o?t.join(e,o):e,r=t.basename(s,".js")+`${app.config.noFilenameChange?"":".min"}.js`}else p=t.join(t.dirname(s),a.endsWith(".js")?t.dirname(a):a||"min"),r=`${a.endsWith(".js")&&n.endsWith(".js")?t.basename(a).replace(/(\.min)?\.js$/,""):t.basename(s,".js")}${app.config.noFilenameChange?"":".min"}.js`;let o=t.join(p,r);c.existsSync(p)||c.mkdirSync(p,{recursive:!0}),c.writeFileSync(o,e,"utf8"),l.ifNotQuiet(` ${app.colors.bg}✓${app.colors.nc} `+t.relative(process.cwd(),o))})))}}})();
|
|
7
|
+
(async()=>{var e,i=process.argv.slice(2);globalThis.env={debugMode:i.some(e=>/^--?debug(?:-?mode)?$/.test(e)),devMode:/[\\/]src(?:[\\/]|$)/i.test(__dirname)};let o=require("node-clipboardy"),t=require("fs"),{generateRandomLang:n,getMsgs:s,getSysLang:r}=require(`./lib/language${env.devMode?"":".min"}.js`),p=require(`./lib/log${env.devMode?"":".min"}.js`),a=require(`../minify${env.devMode?"":".min"}.js`),c=require("path"),g=require(`./lib/settings${env.devMode?"":".min"}.js`);Object.assign(globalThis.app??={},require(`../${env.devMode?"../":"./data/"}app.json`)),p.debug(app.msgs=await s(env.debugMode?n({excludes:["en"]}):r())),app.urls.docs+="/#-command-line-usage";for(e of i){if(g.controls.init.regex.test(e))return g.initConfigFile();if(g.controls.help.regex.test(e))return p.help();if(g.controls.version.regex.test(e))return p.version()}let[l="",f=""]=i.filter(e=>!e.startsWith("-")).map(e=>e.replace(/^\/*/,"")),m=c.resolve(process.cwd(),l);l&&!t.existsSync(m)&&(i=m+".js",t.existsSync(i)?m=i:(p.error(`${app.msgs.error_firstArgNotExist}.\n${m} ${app.msgs.error_doesNotExist}.`),p.success(app.msgs.info_exampleValidCmd+`:
|
|
8
|
+
» minify-js . output.min.js`),p.helpCmdAndDocURL(),process.exit(1))),g.load();var d,i=m.endsWith(".js")&&!t.statSync(m).isDirectory()?[m]:a.findJS(m,{recursive:!app.config.noRecursion,verbose:!app.config.quietMode,ignores:(app.config.ignores?.split(",")??[]).map(e=>e.trim())});if(app.config.dryRun)i.length?(p.info(app.msgs.info_filesToBeMinned+":"),i.forEach(e=>console.info(e))):p.info(app.msgs.info_noFilesWillBeMinned+".");else{let n=[],e=[];!app.config.relativeOutput&&t.statSync(m).isDirectory()?(d=a.minify(m,{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()):[]}))&&(d.error?n.push(m):e=[].concat(d)):e=i.map(e=>{var i=a.minify(e,{verbose:!app.config.quietMode,mangle:!app.config.noMangle,comment:app.config.comment?.replace(/\\n/g,"\n")});return i.error&&n.push(e),i}).filter(e=>!e.error),app.config.quietMode||(e?.length?(p.success(app.msgs.info_minComplete+"!"),p.data(e.length+" "+app.msgs.info_file+`${1==e.length?"":"s"} ${app.msgs.info_minified}.`)):console.info(app.msgs.info_noFilesProcessed+"."),n.length&&(p.error(n.length+" "+app.msgs.info_file+(1==n.length?"":"s"),app.msgs.info_failedToMinify+":"),n.forEach(e=>console.info(e)))),e?.length&&(app.config.copy&&1==e?.length?(p.data(e[0].code),p.ifNotQuiet(`
|
|
9
|
+
${app.msgs.info_copying}...`),o.writeSync(e[0].code)):(p.ifNotQuiet(`
|
|
10
|
+
${app.msgs.info_writing}${1<e?.length?"s":""}...`),e?.forEach(({code:e,srcPath:n,relPath:o})=>{let s,r;if(!app.config.relativeOutput&&o){let e=c.resolve(process.cwd(),f||"min"),i=c.dirname(o);s="."!=i?c.join(e,i):e,r=`${c.basename(n,".js")}${app.config.noFilenameChange?"":".min"}.js`}else s=c.join(c.dirname(n),f.endsWith(".js")?c.dirname(f):f||"min"),r=`${f.endsWith(".js")&&l.endsWith(".js")?c.basename(f).replace(/(\.min)?\.js$/,""):c.basename(n,".js")}${app.config.noFilenameChange?"":".min"}.js`;let i=c.join(s,r);t.mkdirSync(s,{recursive:!0}),t.writeFileSync(i,e,"utf8"),p.ifNotQuiet(` ${p.colors.bg}✓${p.colors.nc} `+c.relative(process.cwd(),i))})))}})();
|
package/dist/cli/lib/data.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* © 2024–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
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}};
|
|
6
|
+
module.exports={fetch(n){return"undefined"==typeof fetch?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)}):fetch(n)},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}};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* © 2024–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
5
|
*/
|
|
6
|
-
module.exports={
|
|
6
|
+
module.exports={generateRandomLang({includes:e=[],excludes:r=[]}={}){let n=require("fs"),s=require(`./log${env.devMode?"":".min"}.js`),t=require("path"),a=e.length?e:(()=>{var e=t.join(__dirname,"..",".cache"),r=t.join(e,"locales.json");if(n.existsSync(r))try{return JSON.parse(n.readFileSync(r,"utf8"))}catch(e){}var s,a=t.resolve(process.cwd(),"_locales");return n.existsSync(a)?(a=n.readdirSync(a,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name).filter(e=>/^[a-z]{2}(?:_[A-Z]{2})?$/.test(e)),s=r+".tmp",n.mkdirSync(e,{recursive:!0}),n.writeFileSync(s,JSON.stringify(a,null,2)),n.renameSync(s,r),a):["en"]})(),l=new Set(r),i="en";return(a=a.filter(e=>!l.has(e))).length&&(i=a[Math.floor(Math.random()*a.length)]),s.debug(`
|
|
7
|
+
Random language: ${i}
|
|
8
|
+
`),i},async getMsgs(a="en"){var e=require(`./data${env.devMode?"":".min"}.js`);let n=e.flatten(require(`../../${env.devMode?"../../_locales/en/":"data/"}messages.json`),{key:"message"});if(!a.startsWith("en")){var t=`${app.urls.jsdelivr}@${app.commitHashes.locales}/_locales/`;let r=t+a.replace("-","_")+"/messages.json",s=0;for(;s<3;)try{n=e.flatten(await(await e.fetch(r)).json(),{key:"message"});break}catch(e){if(2<++s)break;r=a.includes("-")&&1==s?r.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):t+"en/messages.json"}}return n},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,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* © 2024–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={colors:{nc:"[0m",br:"[1;91m",by:"[1;33m",bo:"[38;5;214m",bg:"[1;92m",bw:"[1;97m",blk:"[30m",tlBG:"[106m"},configURL(){this.info(`
|
|
7
|
+
${app.msgs.info_exampleValidConfigFile}: `+app.urls.config)},configURLandExit(...s){this.error(...s),this.configURL(),process.exit(1)},data(s){console.log(`
|
|
8
|
+
`+this.colors.bw+s+this.colors.nc)},debug(s){env.debugMode&&console.log(s)},error(...s){console.error(`
|
|
9
|
+
${this.colors.br}${app.msgs.prefix_error}:`,...s,this.colors.nc)},errorAndExit(...s){this.error(...s),this.helpCmdAndDocURL(),process.exit(1)},ifNotQuiet(s){app.config.quietMode||console.info(s)},info(s){console.info(`
|
|
10
|
+
`+this.colors.by+s+this.colors.nc)},tip(s){console.info(""+this.colors.by+app.msgs.prefix_tip+": "+s+this.colors.nc)},success(s){console.log(`
|
|
11
|
+
`+this.colors.bg+s+this.colors.nc)},warn(...s){console.warn(`
|
|
12
|
+
${this.colors.bo}${app.msgs.prefix_warning}:`,...s,this.colors.nc)},help(s=["header","usage","pathArgs","flags","params","cmds"]){app.prefix=""+this.colors.tlBG+this.colors.blk+` ${app.name.replace(/^@[^/]+\//,"")} ${this.colors.nc} `;let o={header:[`
|
|
13
|
+
├ ${app.prefix}${app.msgs.appCopyright}.`,""+app.prefix+app.msgs.prefix_source+": "+app.urls.src],usage:[`
|
|
14
|
+
${this.colors.bw}o ${app.msgs.helpSection_usage}:`+this.colors.nc,` ${this.colors.bw}» `+this.colors.bg+app.cmdFormat+this.colors.nc],pathArgs:[`
|
|
15
|
+
${this.colors.bw}o ${app.msgs.helpSection_pathArgs}:`+this.colors.nc,` [inputPath] ${app.msgs.inputPathDesc_main}, ${app.msgs.inputPathDesc_extra}.`,` [outputPath] ${app.msgs.outputPathDesc_main}, ${app.msgs.outputPathDesc_extra}.`],flags:[`
|
|
16
|
+
${this.colors.bw}o ${app.msgs.helpSection_flags}:`+this.colors.nc,` -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}.`],params:[`
|
|
17
|
+
${this.colors.bw}o ${app.msgs.helpSection_params}:`+this.colors.nc,`--ignores="dir/,file1.js,file2.js" ${app.msgs.optionDesc_ignores}.`,`--comment="comment" ${app.msgs.optionDesc_commentMain}.`+` ${app.msgs.optionDesc_commentExtra}.`,` --config="path/to/file" ${app.msgs.optionDesc_config}.`],cmds:[`
|
|
18
|
+
${this.colors.bw}o ${app.msgs.helpSection_cmds}:`+this.colors.nc,` --init ${app.msgs.optionDesc_init}.`,` -h, --help ${app.msgs.optionDesc_help}.`,` -v, --version ${app.msgs.optionDesc_version}.`]};s.forEach(n=>o[n]?.forEach(o=>{{var t=/header|usage/.test(n)?1:37;let p=process.stdout.columns||80,s=o.match(/\S+|\s+/g),e=[],i="";s.forEach(s=>{var o=p-(e.length?t:0);i.length+"| ".length+s.length>o&&(e.push(e.length?i.trimStart():i),i=""),i+=s}),e.push(e.length?i.trimStart():i),e.forEach((s,o)=>console.info("| "+(0==o?s:" ".repeat(t)+s)))}})),console.info(`
|
|
19
|
+
${app.msgs.info_moreHelp}, ${app.msgs.info_visit}: `+this.colors.bw+app.urls.docs+this.colors.nc)},helpCmdAndDocURL(){console.info(`
|
|
20
|
+
${app.msgs.info_moreHelp}, ${app.msgs.info_type} ${app.name.split("/")[1]} --help' ${app.msgs.info_or} ${app.msgs.info_visit}
|
|
21
|
+
`+this.colors.bw+app.urls.docs+this.colors.nc)},version(){var s=require("path"),o=require("child_process").execSync(`npm view ${JSON.stringify(app.name)} version`).toString().trim()||"none";let p,e=process.cwd();for(;"/"!=e;){var i=s.join(e,"package.json");if(require("fs").existsSync(i)){i=require(i);p=(i.dependencies?.[app.name]||i.devDependencies?.[app.name])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}e=s.dirname(e)}console.info(`
|
|
22
|
+
${app.msgs.prefix_globalVer}: ${o}
|
|
23
|
+
${app.msgs.prefix_localVer}: `+p)}};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* © 2024–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
|
+
let fs=require("fs"),log=require(`./log${env.devMode?"":".min"}.js`),path=require("path");(globalThis.app??={}).config={},module.exports={configFilename:"minify.config.mjs",controls:{dryRun:{type:"flag",regex:/^--?(?:n|dry-?run)$/},includeDotFolders:{type:"flag",regex:/^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?=?(?:true|1)?)$/},includeDotFiles:{type:"flag",regex:/^--?(?:df|D|(?:include-?)?dot-?files?=?(?:true|1)?)$/},noRecursion:{type:"flag",regex:/^--?(?:R|(?:disable|no)-?recursi(?:on|ve)|recursi(?:on|ve)=(?:false|0))$/},noMangle:{type:"flag",regex:/^--?(?:M|(?:disable|no)-?mangle|mangle=(?:false|0))$/},noFilenameChange:{type:"flag",regex:/^--?(?:X|(?:disable|no)-?(?:file)?name-?change|(?:file)?name-?change=(?:false|0))$/},rewriteImports:{type:"param",regex:/^--?(?:i|rewrite-?imports?=?(?:true|1)?)$/},relativeOutput:{type:"param",regex:/^--?(?:r|relative-?output?=?(?:true|1)?)$/},copy:{type:"param",regex:/^--?c(?:opy)?$/},quietMode:{type:"param",regex:/^--?q(?:uiet)?(?:-?mode)?$/},ignores:{type:"param",regex:/^--?(?:ignores?|(?:ignore|skip|exclude)(?:d?-?files?)?)(?:=.*|$)/},comment:{type:"param",regex:/^--?comments?(?:=.*|$)/},config:{type:"param",regex:/^--?config(?:=.*|$)/},init:{type:"cmd",regex:/^-{0,2}init$/},help:{type:"cmd",regex:/^--?h(?:elp)?$/},version:{type:"cmd",regex:/^--?ve?r?s?i?o?n?$/}},initConfigFile(e=this.configFilename){var r=path.resolve(process.cwd(),e);if(fs.existsSync(r))return log.warn(app.msgs.warn_configFileExists+":",r);e=path.resolve(__dirname,"../../"+(env.devMode?"../":"./data/")+e);fs.existsSync(e)||(log.error(app.msgs.error_templateNotFound+":",e),process.exit(1)),fs.copyFileSync(e,r),log.success(app.msgs.info_configFileCreated+`: ${r}
|
|
7
|
+
`),log.tip(app.msgs.tip_editToSetDefaults+"."),log.tip(app.msgs.tip_cliArgsPrioritized+".")},load({args:e=process.argv.slice(2),ctrlKeys:s=Object.keys(this.controls)}={}){let r=null;var i=e.find(e=>this.controls.config.regex.test(e));if(i){/=/.test(i)||log.errorAndExit(`[${i}] `+app.msgs.error_mustIncludePath);i=i.split("=")[1];r=path.isAbsolute(i)?i:path.resolve(process.cwd(),i),fs.existsSync(r)||log.configURLandExit(app.msgs.error_configFileNotFound+":",r)}else for(var o of["mjs","cjs","js"]){o=path.resolve(process.cwd(),this.configFilename.replace(/\.[^.]+$/,"")+"."+o);if(fs.existsSync(o)){r=o;break}}if(r)try{var t=require(r),a=t?.default??t;a&&"object"==typeof a||log.configURLandExit(app.msgs.error_invalidConfigFile+"."),Object.assign(app.config,a)}catch(e){log.configURLandExit(app.msgs.error_failedToLoadConfigFile+":",r,`
|
|
8
|
+
`+e.message)}return e.forEach(r=>{if(!/^[^-]|--?(?:config|debug)/.test(r)){var i=s.find(e=>this.controls[e]?.regex?.test(r)),o=(i||log.errorAndExit(`[${r}] ${app.msgs.error_notRecognized}.`),this.controls[i]);if("cmd"!=o.type){let e="param"!=o.type||r.split("=")[1]?.trim();o.mode?app.config.mode=i.replace(/mode$/i,"").toLowerCase():((o=o.parser)&&(e=o(e),isNaN(e)||e<1)&&log.errorAndExit(`[${i}] ${app.msgs.error_nonPositiveNum}.`),app.config[i]=e)}}}),app.config}};
|
package/dist/data/app.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"copyrightYear": "2024–2026",
|
|
6
6
|
"cmdFormat": "minify-js [inputPath] [outputPath] [options]",
|
|
7
7
|
"urls": {
|
|
8
|
+
"config": "https://github.com/adamlui/minify.js/blob/main/node.js/minify.config.mjs",
|
|
8
9
|
"docs": "https://github.com/adamlui/minify.js/tree/main/node.js/docs",
|
|
9
10
|
"github": "https://github.com/adamlui/minify.js",
|
|
10
11
|
"jsdelivr": "https://cdn.jsdelivr.net/gh/adamlui/minify.js",
|
|
@@ -12,6 +13,6 @@
|
|
|
12
13
|
"src": "https://github.com/adamlui/minify.js/tree/main/node.js/src"
|
|
13
14
|
},
|
|
14
15
|
"commitHashes": {
|
|
15
|
-
"locales": "
|
|
16
|
+
"locales": "e0df8e9"
|
|
16
17
|
}
|
|
17
18
|
}
|
package/dist/data/messages.json
CHANGED
|
@@ -2,14 +2,23 @@
|
|
|
2
2
|
"appName": { "message": "minify.js" },
|
|
3
3
|
"appCopyright": { "message": "© 2024–2026 Adam Lui & contributors under the MIT license" },
|
|
4
4
|
"prefix_error": { "message": "ERROR" },
|
|
5
|
+
"prefix_tip": { "message": "TIP" },
|
|
6
|
+
"prefix_warning": { "message": "WARNING" },
|
|
5
7
|
"prefix_globalVer": { "message": "Global version" },
|
|
6
8
|
"prefix_localVer": { "message": "Local version" },
|
|
7
9
|
"prefix_source": { "message": "Source" },
|
|
8
10
|
"error_notRecognized": { "message": "not recognized" },
|
|
11
|
+
"error_nonPositiveNum": { "message": "argument can only be > 0" },
|
|
9
12
|
"error_invalidURL": { "message": "Invalid URL" },
|
|
13
|
+
"error_invalidConfigFile": { "message": "Config file must export an object" },
|
|
14
|
+
"error_configFileNotFound": { "message": "Config file not found" },
|
|
15
|
+
"error_failedToLoadConfigFile": { "message": "Failed to load config file" },
|
|
16
|
+
"error_mustIncludePath": { "message": "must include =path" },
|
|
17
|
+
"error_templateNotFound": { "message": "Template file not found at" },
|
|
18
|
+
"warn_configFileExists": { "message": "Config file already exists" },
|
|
19
|
+
"info_exampleValidConfigFile": { "message": "Example valid config file" },
|
|
10
20
|
"error_firstArgNotExist": { "message": "First argument can only be an existing file or directory" },
|
|
11
21
|
"error_doesNotExist": { "message": "does not exist" },
|
|
12
|
-
"info_validArgs": { "message": "Valid arguments are below" },
|
|
13
22
|
"info_exampleValidCmd": { "message": "Example valid command" },
|
|
14
23
|
"info_filesToBeMinned": { "message": "JS files to be minified" },
|
|
15
24
|
"info_noFilesWillBeMinned": { "message": "No JS files will be minified" },
|
|
@@ -17,16 +26,21 @@
|
|
|
17
26
|
"info_writing": { "message": "Writing to file" },
|
|
18
27
|
"info_minComplete": { "message": "Minification complete" },
|
|
19
28
|
"info_file": { "message": "file" },
|
|
20
|
-
"
|
|
29
|
+
"info_minified": { "message": "minified" },
|
|
21
30
|
"info_noFilesProcessed": { "message": "No unminified JavaScript files processed" },
|
|
22
31
|
"info_failedToMinify": { "message": "failed to minify" },
|
|
23
32
|
"info_moreHelp": { "message": "For more help" },
|
|
33
|
+
"info_type": { "message": "type" },
|
|
34
|
+
"info_or": { "message": "or" },
|
|
24
35
|
"info_visit": { "message": "visit" },
|
|
36
|
+
"info_configFileCreated": { "message": "Config file created" },
|
|
37
|
+
"tip_editToSetDefaults": { "message": "Edit this file to customize defaults" },
|
|
38
|
+
"tip_cliArgsPrioritized": { "message": "CLI arguments always override these values" },
|
|
25
39
|
"helpSection_usage": { "message": "Usage" },
|
|
26
40
|
"helpSection_pathArgs": { "message": "Path arguments" },
|
|
27
41
|
"helpSection_flags": { "message": "Boolean options" },
|
|
28
|
-
"
|
|
29
|
-
"
|
|
42
|
+
"helpSection_params": { "message": "Parameter options" },
|
|
43
|
+
"helpSection_cmds": { "message": "Commands" },
|
|
30
44
|
"inputPathDesc_main": { "message": "Path to JS file or directory containing JavaScript files to be minified" },
|
|
31
45
|
"inputPathDesc_extra": { "message": "relative to the current working directory" },
|
|
32
46
|
"outputPathDesc_main": { "message": "Path to file or directory where minified files will be stored" },
|
|
@@ -44,6 +58,8 @@
|
|
|
44
58
|
"optionDesc_ignores": { "message": "Files/directories to exclude from minification" },
|
|
45
59
|
"optionDesc_commentMain": { "message": "Prepend header comment to minified code" },
|
|
46
60
|
"optionDesc_commentExtra": { "message": "Separate by line using '\\n'" },
|
|
61
|
+
"optionDesc_config": { "message": "Load custom config file" },
|
|
62
|
+
"optionDesc_init": { "message": "Create config file (in project root)" },
|
|
47
63
|
"optionDesc_help": { "message": "Display help screen" },
|
|
48
64
|
"optionDesc_version": { "message": "Show version number" }
|
|
49
65
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* minify.config.mjs
|
|
3
|
+
*
|
|
4
|
+
* Optional config file for the minify-js CLI.
|
|
5
|
+
* Copy this file to your project root to set default options.
|
|
6
|
+
* CLI arguments always override these values.
|
|
7
|
+
*
|
|
8
|
+
* Docs: https://github.com/adamlui/minify.js/tree/main/node.js/#-command-line-usage
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
dryRun: false, // don't actually minify the file(s), just show if they will be processed
|
|
13
|
+
includeDotFolders: false, // include dotfolders in file search
|
|
14
|
+
includeDotFiles: false, // include dotfiles in file search
|
|
15
|
+
noRecursion: false, // disable recursive file searching
|
|
16
|
+
noMangle: false, // disable mangling names
|
|
17
|
+
noFilenameChange: false, // disable changing file extension to .min.js
|
|
18
|
+
rewriteImports: false, // update import paths from .js to .min.js
|
|
19
|
+
copy: false, // copy minified code to clipboard instead of write to file if single file processed
|
|
20
|
+
relativeOutput: false, // output files relative to each src file instead of to input root
|
|
21
|
+
quietMode: false, // suppress all logging except errors
|
|
22
|
+
ignores: '', // files/dirs to exclude from minification
|
|
23
|
+
comment: '' // header comment to prepend to minified code
|
|
24
|
+
}
|
package/dist/minify.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* © 2024–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
5
|
*/
|
|
6
|
-
let fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(i,s={}){var e="https://github.com/adamlui/minify.js/tree/main/node.js/docs/#findjssearchdir-options",o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,ignores:[]};if(log.prefix="findJS()","string"!=typeof i)return log.error("1st arg <searchDir> must be a string."),log.helpURL(e);var r=path.resolve(process.cwd(),i);if(!fs.existsSync(r))return log.error("1st arg <searchDir> must be an existing directory."),log.error(r+" does not exist."),log.helpURL(e);if(validateOptions({options:s,defaultOptions:o,helpURL:e,exampleCall:"findJS('assets/js', { verbose: false, dotFoldes: true })"})){(s={...o,...s}).ignoreFiles&&(s.ignores=[...s.ignores,...s.ignoreFiles]);let e=fs.readdirSync(i),r=[];return s.verbose&&!s.isRecursing&&log.info("Searching for unminified JS files..."),e.forEach(e=>{let o=path.resolve(i,e);s.ignores.some(r=>r.endsWith("/")?o.split(path.sep).some(e=>e==r.replace(/\/$/,"")):e==r)?s.verbose&&log.info(`** ${e} ignored`):fs.statSync(o).isDirectory()&&"node_modules"!=e&&s.recursive&&(s.dotFolders||!e.startsWith("."))?r.push(...findJS(o,{...s,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!s.dotFiles&&e.startsWith(".")||r.push(o)}),s.verbose&&!s.isRecursing&&(log.info("Search complete!",`${r.length||"No"} file${1==r.length?"":"s"} found.`),"minify"!=findJS.caller?.name)&&"undefined"!=typeof window&&log.info("Check returned array."),s.isRecursing||r.length?r:[]}}function minify(s,n={}){var r="https://github.com/adamlui/minify.js/tree/main/node.js/docs/#minifyinput-options",
|
|
6
|
+
let fs=require("fs"),path=require("path"),uglifyJS=require("uglify-js");function findJS(i,s={}){var e="https://github.com/adamlui/minify.js/tree/main/node.js/docs/#findjssearchdir-options",o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,ignores:[]};if(log.prefix="findJS()","string"!=typeof i)return log.error("1st arg <searchDir> must be a string."),log.helpURL(e);var r=path.resolve(process.cwd(),i);if(!fs.existsSync(r))return log.error("1st arg <searchDir> must be an existing directory."),log.error(r+" does not exist."),log.helpURL(e);if(validateOptions({options:s,defaultOptions:o,helpURL:e,exampleCall:"findJS('assets/js', { verbose: false, dotFoldes: true })"})){(s={...o,...s}).ignoreFiles&&(s.ignores=[...s.ignores,...s.ignoreFiles]);let e=fs.readdirSync(i),r=[];return s.verbose&&!s.isRecursing&&log.info("Searching for unminified JS files..."),e.forEach(e=>{let o=path.resolve(i,e);s.ignores.some(r=>r.endsWith("/")?o.split(path.sep).some(e=>e==r.replace(/\/$/,"")):e==r)?s.verbose&&log.info(`** ${e} ignored`):fs.statSync(o).isDirectory()&&"node_modules"!=e&&s.recursive&&(s.dotFolders||!e.startsWith("."))?r.push(...findJS(o,{...s,isRecursing:!0})):!/\.js(?<!\.min\.js)$/.test(e)||!s.dotFiles&&e.startsWith(".")||r.push(o)}),s.verbose&&!s.isRecursing&&(log.info("Search complete!",`${r.length||"No"} file${1==r.length?"":"s"} found.`),"minify"!=findJS.caller?.name)&&"undefined"!=typeof window&&log.info("Check returned array."),s.isRecursing||r.length?r:[]}}function minify(s,n={}){var r="https://github.com/adamlui/minify.js/tree/main/node.js/docs/#minifyinput-options",o={recursive:!0,verbose:!0,dotFolders:!1,dotFiles:!1,mangle:!0,rewriteImports:!1,relativeOutput:!1,ignores:[],comment:""};if(log.prefix="minify()","string"!=typeof s)return log.error("1st arg <input> must be a string."),log.helpURL(r);if(validateOptions({options:n,defaultOptions:o,helpURL:r,exampleCall:"minify('assets/js', { recursive: false, mangle: false })"})){(n={...o,...n}).ignoreFiles&&(n.ignores=[...n.ignores,...n.ignoreFiles]);let i={mangle:!!n.mangle&&{toplevel:!1}};try{var e,t=fs.openSync(s,fs.constants.O_RDONLY),l=fs.fstatSync(t);if(l.isFile()){if(!/\.[cm]?jsx?$/i.test(s))return e=new Error(s+" is not a JavaScript file (.js, .mjs, .cjs, .jsx)"),log.error(e.message),fs.closeSync(t),{code:"",srcPath:path.resolve(process.cwd(),s),error:e};n.verbose&&log.info(`** Minifying ${s}...`);var a=Buffer.alloc(l.size),f=(fs.readSync(t,a,0,l.size,0),fs.closeSync(t),uglifyJS.minify(a.toString("utf8"),i));return n.comment&&(f.code=prependComment(f.code,n.comment)),f.error?log.error(f.error.message):n.verbose&&"undefined"!=typeof window&&log.info("Minification complete! Check returned object."),{code:f.code,srcPath:path.resolve(process.cwd(),s),error:f.error}}fs.closeSync(t);var c=findJS(s,n)?.map(e=>{n.verbose&&log.info(`** Minifying ${e}...`);var r=fs.readFileSync(e,"utf8"),r=uglifyJS.minify(r,i),o=n.relativeOutput?void 0:path.relative(path.resolve(process.cwd(),s),e);return n.comment&&(r.code=prependComment(r.code,n.comment)),r.error&&log.error(r.error.message),{code:r.code,srcPath:e,relPath:o,error:r.error}}).filter(e=>!e.error);if(n.verbose&&(c.length&&"undefined"!=typeof window?log.info("Minification complete! Check returned object."):log.info("No unminified JavaScript files processed.")),n.rewriteImports&&c&&1<c.length){n.verbose&&log.info("** Rewriting import paths...");let e=c.map(e=>path.basename(e.srcPath,".js"));c.forEach(i=>e.forEach(e=>{var r=new RegExp(`(\\./?)?\\b${e}\\.js(['"])`,"g"),o=i.code;i.code=i.code.replace(r,`$1${e}.min.js$2`),o!=i.code&&n.verbose&&log.info(`Updated ${e}.js in `+path.basename(i.srcPath))})),n.verbose&&log.info("Import paths rewritten.")}return c}catch(e){if("ENOENT"==e.code)return r=process.argv.some(e=>e.includes("gulp")),n.verbose&&!r&&log.info("** Minifying passed source code..."),o=uglifyJS.minify(s,i),n.comment&&(o.code=prependComment(o.code,n.comment)),o.error?log.error(o.error.message):n.verbose&&!r&&log.info("Minification complete! Check returned object."),{code:o.code,srcPath:void 0,error:o.error};throw e}}}function prependComment(e,r){let o="";var i=e.match(/^#!.*\n/);return i&&(o=i[0],e=e.slice(o.length)),`${o}/**
|
|
7
7
|
${r.split("\n").map(e=>" * "+e).join("\n")}
|
|
8
8
|
*/
|
|
9
|
-
`+e}function validateOptions({options:e,defaultOptions:r,helpURL:o,exampleCall:i}){var s,n,t=Object.keys(r).filter(e=>"boolean"==typeof r[e]),l=Object.keys(r).filter(e=>Number.isInteger(r[e]));if("object"!=typeof e)return s=i.split(",").findIndex(e=>e.trim().startsWith("{"))+1,s+=["st","nd","rd"][s-1]||"th",log.error(`${"0th"==s?"[O":s+" arg [o"}ptions] can only be an object of key/vals.`),log.info("Example valid call:",i),log.validOptions(r),log.helpURL(o),!1;for(n in e)if("isRecursing"!=n&&Object.prototype.hasOwnProperty.call(r,n)){if(t.includes(n)&&"boolean"!=typeof e[n])return log.error(`[${n}] option can only be \`true\` or \`false\`.`),log.helpURL(o),!1;if(l.includes(n)&&(e[n]=parseInt(e[n],10),isNaN(e[n])||e[n]<1))return log.error(`[${n}] option can only be an integer > 0.`),log.helpURL(o),!1}return!0}Object.assign(globalThis.app??={},require(`${
|
|
9
|
+
`+e}function validateOptions({options:e,defaultOptions:r,helpURL:o,exampleCall:i}){var s,n,t=Object.keys(r).filter(e=>"boolean"==typeof r[e]),l=Object.keys(r).filter(e=>Number.isInteger(r[e]));if("object"!=typeof e)return s=i.split(",").findIndex(e=>e.trim().startsWith("{"))+1,s+=["st","nd","rd"][s-1]||"th",log.error(`${"0th"==s?"[O":s+" arg [o"}ptions] can only be an object of key/vals.`),log.info("Example valid call:",i),log.validOptions(r),log.helpURL(o),!1;for(n in e)if("isRecursing"!=n&&Object.prototype.hasOwnProperty.call(r,n)){if(t.includes(n)&&"boolean"!=typeof e[n])return log.error(`[${n}] option can only be \`true\` or \`false\`.`),log.helpURL(o),!1;if(l.includes(n)&&(e[n]=parseInt(e[n],10),isNaN(e[n])||e[n]<1))return log.error(`[${n}] option can only be an integer > 0.`),log.helpURL(o),!1}return!0}Object.assign(globalThis.app??={},require(`${/[\\/]src(?:[\\/]|$)/i.test(__dirname)?"../":"./data/"}app.json`)),app.aliases={minify:["build","Build","compile","Compile","compress","Compress","Minify"],findJS:["find","Find","findjs","findJs","Findjs","FindJs","FindJS","search","Search"]};let log={prefix:app.name,error(...e){console.error(this.prefix+" » ERROR:",...e)},helpURL(e=app.urls?.docs){this.info("For more help, please visit",e)},info(...e){console.info(this.prefix+" »",...e)},validOptions(e){var r=Object.keys(e).join(", "),e=JSON.stringify(e,void 0,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," ");this.info(`Valid options: [${r}]`),this.info("If omitted, default settings are: "+e)}};module.exports={minify:minify,findJS:findJS};for(let r in app.aliases)app.aliases[r].forEach(e=>module.exports[e]??=module.exports[r]);
|
package/docs/README.md
CHANGED
|
@@ -27,8 +27,8 @@
|
|
|
27
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>
|
|
28
28
|
<a href="#%EF%B8%8F-mit-license">
|
|
29
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.
|
|
31
|
-
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.
|
|
30
|
+
<a href="https://github.com/adamlui/minify.js/releases/tag/node-v2.2.0">
|
|
31
|
+
<img height=31 src="https://img.shields.io/badge/Latest_Build-2.2.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
32
32
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code">
|
|
33
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>
|
|
34
34
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_minify.js:node.js/src/minify.js">
|
|
@@ -155,12 +155,41 @@ Parameter options:
|
|
|
155
155
|
--ignores="dir/,file1.js,file2.js" Files/directories to exclude from minification.
|
|
156
156
|
--comment="comment" Prepend header comment to minified code.
|
|
157
157
|
Separate by line using '\n'.
|
|
158
|
+
--config="path/to/file" Load custom config file.
|
|
158
159
|
|
|
159
|
-
|
|
160
|
+
Commands:
|
|
161
|
+
--init Create config file (in project root).
|
|
160
162
|
-h, --help Display help screen.
|
|
161
163
|
-v, --version Show version number.
|
|
162
164
|
```
|
|
163
165
|
|
|
166
|
+
#
|
|
167
|
+
|
|
168
|
+
### Configuration file
|
|
169
|
+
|
|
170
|
+
**minify.js** can be customized using a `minify.config.mjs` or `minify.config.js` placed in your project root.
|
|
171
|
+
|
|
172
|
+
Example defaults:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
export default {
|
|
176
|
+
dryRun: false, // don't actually minify the file(s), just show if they will be processed
|
|
177
|
+
includeDotFolders: false, // include dotfolders in file search
|
|
178
|
+
includeDotFiles: false, // include dotfiles in file search
|
|
179
|
+
noRecursion: false, // disable recursive file searching
|
|
180
|
+
noMangle: false, // disable mangling names
|
|
181
|
+
noFilenameChange: false, // disable changing file extension to .min.js
|
|
182
|
+
rewriteImports: false, // update import paths from .js to .min.js
|
|
183
|
+
copy: false, // copy minified code to clipboard instead of write to file if single file processed
|
|
184
|
+
relativeOutput: false, // output files relative to each src file instead of to input root
|
|
185
|
+
quietMode: false, // suppress all logging except errors
|
|
186
|
+
ignores: '', // files/dirs to exclude from minification
|
|
187
|
+
comment: '' // header comment to prepend to minified code
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
💡 Run `minify-js init` to generate a template `minify.config.mjs` in your project root.
|
|
192
|
+
|
|
164
193
|
<br>
|
|
165
194
|
|
|
166
195
|
<img height=6px width="100%" src="https://assets.minify-js.org/images/separators/aqua-gradient.png?v=ad67551">
|
|
@@ -192,7 +221,7 @@ const minifyJS = require('@adamlui/minify.js')
|
|
|
192
221
|
If **source code** is passed, it is directly minified, then an object containing `srcPath` + `code` + `error` is returned:
|
|
193
222
|
|
|
194
223
|
```js
|
|
195
|
-
const srcCode = 'function add(first, second) { return first + second
|
|
224
|
+
const srcCode = 'function add(first, second) { return first + second }',
|
|
196
225
|
minifyResult = minifyJS.minify(srcCode)
|
|
197
226
|
|
|
198
227
|
console.log(minifyResult.error) // outputs runtime error, or `undefined` if no error
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/minify.js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Recursively minify all JavaScript files.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -44,7 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"test": "bash utils/test/minify-cli.test.sh",
|
|
47
|
-
"build": "
|
|
47
|
+
"build": "node utils/build",
|
|
48
|
+
"build:js": "node utils/build --js",
|
|
49
|
+
"build:data": "node utils/build --data",
|
|
50
|
+
"build:json": "node utils/build --json",
|
|
51
|
+
"debug": "node src/cli --debug",
|
|
48
52
|
"bump:patch": "bash utils/bump.sh patch",
|
|
49
53
|
"bump:minor": "bash utils/bump.sh minor",
|
|
50
54
|
"bump:major": "bash utils/bump.sh major",
|
|
@@ -1,17 +0,0 @@
|
|
|
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={helpCmdAndDocURL(){console.info(`
|
|
7
|
-
${app.msgs.info_moreHelp}, ${app.msgs.info_type} ${app.name.split("/")[1]} --help' ${app.msgs.info_or} ${app.msgs.info_visit}
|
|
8
|
-
`+app.colors.bw+app.urls.docs+app.colors.nc)},help(p=["header","usage","pathArgs","flags","paramOptions","infoCmds"]){app.prefix=""+app.colors.tlBG+app.colors.blk+` ${app.name.replace(/^@[^/]+\//,"")} ${app.colors.nc} `;let s={header:[`
|
|
9
|
-
├ ${app.prefix}${app.msgs.appCopyright||`© ${app.copyrightYear} ${app.author} under the ${app.license} license`}.`,""+app.prefix+app.msgs.prefix_source+": "+app.urls.src],usage:[`
|
|
10
|
-
${app.colors.bw}o ${app.msgs.helpSection_usage}:`+app.colors.nc,` ${app.colors.bw}» `+app.colors.bg+app.cmdFormat+app.colors.nc],pathArgs:[`
|
|
11
|
-
${app.colors.bw}o ${app.msgs.helpSection_pathArgs}:`+app.colors.nc," [inputPath] "+app.msgs.inputPathDesc_main+", "+app.msgs.inputPathDesc_extra+"."," [outputPath] "+app.msgs.outputPathDesc_main+", "+app.msgs.outputPathDesc_extra+"."],flags:[`
|
|
12
|
-
${app.colors.bw}o ${app.msgs.helpSection_flags}:`+app.colors.nc,` -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:[`
|
|
13
|
-
${app.colors.bw}o ${app.msgs.helpSection_paramOptions}:`+app.colors.nc,`--ignores="dir/,file1.js,file2.js" ${app.msgs.optionDesc_ignores}.`,`--comment="comment" ${app.msgs.optionDesc_commentMain}.`+` ${app.msgs.optionDesc_commentExtra}.`],infoCmds:[`
|
|
14
|
-
${app.colors.bw}o ${app.msgs.helpSection_infoCmds}:`+app.colors.nc," -h, --help "+app.msgs.optionDesc_help,` -v, --version ${app.msgs.optionDesc_version}.`]};p.forEach(r=>s[r]?.forEach(s=>{{var n=/header|usage/.test(r)?1:37;let o=process.stdout.columns||80,e=[],p=s.match(/\S+|\s+/g),a="";p.forEach(p=>{var s=o-(e.length?n:0);a.length+"| ".length+p.length>s&&(e.push(e.length?a.trimStart():a),a=""),a+=p}),e.push(e.length?a.trimStart():a),e.forEach((p,s)=>console.info("| "+(0==s?p:" ".repeat(n)+p)))}})),console.info(`
|
|
15
|
-
${app.msgs.info_moreHelp}, ${app.msgs.info_visit}: `+app.colors.bw+app.urls.docs+app.colors.nc)},ifNotQuiet(p){app.config.quietMode||console.info(p)},version(){var p=require("path"),s=require("child_process").execSync(`npm view ${JSON.stringify(app.name)} version`).toString().trim()||"none";let o,e=process.cwd();for(;"/"!=e;){var a=p.join(e,"package.json");if(require("fs").existsSync(a)){a=require(a);o=(a.dependencies?.[app.name]||a.devDependencies?.[app.name])?.match(/^[~^>=]?\d+\.\d+\.\d+$/)?.[1]||"none";break}e=p.dirname(e)}console.info(`
|
|
16
|
-
${app.msgs.prefix_globalVer}: ${s}
|
|
17
|
-
${app.msgs.prefix_localVer}: `+o)}};
|