File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed
Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ Options:
4747 --css minify css
4848 --html minify html
4949 --auto auto detect format
50+ --fail-on-error exit with code 1 when minification fails
5051```
5152
5253The bash command below creates a code snippet saved as ` hello.js ` .
@@ -76,6 +77,14 @@ You can capture the output with the following:
7677$ minify hello.js > hello.min.js
7778```
7879
80+ Use ` --fail-on-error ` to get a non-zero exit code when minification fails (useful in build scripts and CI):
81+
82+ ``` sh
83+ $ minify broken.js --fail-on-error > broken.min.js
84+ $ echo $?
85+ 1
86+ ```
87+
7988You can pass input using ` cat ` :
8089
8190``` sh
Original file line number Diff line number Diff line change @@ -16,13 +16,18 @@ const log = function(...args) {
1616} ;
1717
1818const Argv = process . argv ;
19- const files = Argv . slice ( 2 ) ;
19+ const allArgs = Argv . slice ( 2 ) ;
20+ const failOnError = allArgs . includes ( '--fail-on-error' ) ;
21+ const files = allArgs . filter ( ( f ) => f !== '--fail-on-error' ) ;
2022const [ In ] = files ;
2123
2224log . error = ( e ) => {
2325 console . error ( e ) ;
2426 process . stdin . pause ( ) ;
2527 process . exit ( 1 ) ;
28+
29+ if ( failOnError )
30+ process . exit ( 1 ) ;
2631} ;
2732
2833process . on ( 'uncaughtException' , ( error ) => {
Original file line number Diff line number Diff line change 44 "--js " : " minify javascript" ,
55 "--css " : " minify css" ,
66 "--html " : " minify html" ,
7- "--auto " : " auto detect format"
7+ "--auto " : " auto detect format" ,
8+ "--fail-on-error " : " exit with code 1 when minification fails"
89}
You can’t perform that action at this time.
0 commit comments