Skip to content

Commit 6dcaeca

Browse files
AronNovakcoderaiser
authored andcommitted
feature: we should know if minification fail (#145)
1 parent a98be67 commit 6dcaeca

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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

5253
The 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+
7988
You can pass input using `cat`:
8089

8190
```sh

bin/minify.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ const log = function(...args) {
1616
};
1717

1818
const 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');
2022
const [In] = files;
2123

2224
log.error = (e) => {
2325
console.error(e);
2426
process.stdin.pause();
2527
process.exit(1);
28+
29+
if (failOnError)
30+
process.exit(1);
2631
};
2732

2833
process.on('uncaughtException', (error) => {

help.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
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
}

0 commit comments

Comments
 (0)