Skip to content

Commit 2b075f2

Browse files
committed
Add --throw-error (-e) flag to cli
It's common to require an exit 1 code to fail builds on CI servers. This flag stops the need for a config file just to achieve that.
1 parent eff33c5 commit 2b075f2

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### HEAD
22

3+
* Add `--throw-error` (`-e`) to CLI
34
* Enable `lint` option by default
45
* Add `postcss-apply`
56
* Add `postcss-color-function`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Options:
4747
-m, --minify minify output with cssnano
4848
-L, --no-lint disable stylelint and postcss-bem-linter
4949
-i, --import-root [path] the root directory for imported css files
50+
-e, --throw-error throw an error when any warnings are found
5051
-c, --config [path] a custom PostCSS config file
5152
-v, --verbose log verbose output for debugging
5253
-w, --watch watch the input file and any imports for changes

bin/suitcss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ program
2222
.option('-m, --minify', 'minify output with cssnano')
2323
.option('-L, --no-lint', 'disable stylelint and postcss-bem-linter')
2424
.option('-i, --import-root [path]', 'the root directory for imported css files')
25+
.option('-e, --throw-error', 'throw an error when any warnings are found')
2526
.option('-c, --config [path]', 'a custom PostCSS config file')
2627
.option('-v, --verbose', 'log verbose output for debugging')
2728
.option('-w, --watch', 'watch the input file and any imports for changes');
@@ -113,6 +114,14 @@ function run() {
113114
lint: program.lint
114115
}, config);
115116

117+
if (program.throwError) {
118+
assign(opts, {
119+
'postcss-reporter': {
120+
throwError: true
121+
}
122+
});
123+
}
124+
116125
suitcss(css, opts).then(function(result) {
117126
if (output) {
118127
writeFileSync(output, result.css + '\n');

test/error.config.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ describe('cli', function() {
413413
});
414414
});
415415

416-
it('should output an error to stderr on conformance failure when throwError is set', function(done) {
417-
exec('node bin/suitcss -i test/fixtures -c test/error.config.json test/fixtures/import-error.css test/fixtures/cli/output.css', function(err, stdout, stderr) {
416+
it('should output an error to stderr on conformance failure when --throw-error is set', function(done) {
417+
exec('node bin/suitcss -i test/fixtures -e test/fixtures/import-error.css test/fixtures/cli/output.css', function(err, stdout, stderr) {
418418
expect(err).to.be.an('error');
419419
expect(err.code).to.equal(1);
420420
expect(stderr).to.contain('postcss-reporter: warnings or errors were found');

0 commit comments

Comments
 (0)