Skip to content

Commit

Permalink
Add JSON output option in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Dec 15, 2014
1 parent 73aeba4 commit f1eba90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ doiuse --browsers "ie >= 9, > 1%, last 2 versions" main.css
```
**Sample output:**
```
/projects/website/main.css: line 5, col 3 - CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css: line 6, col 3 - CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css: line 8, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 9, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 10, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 11, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 12, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 13, col 3 - Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css: line 14, col 3 - Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css: line 32, col 3 - CSS3 Transforms not supported by: IE (8)
/projects/website/main.css:5:3: CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css:6:3: CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css:8:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:9:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:10:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:11:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:12:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:13:3: Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css:14:3: Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css:32:3: CSS3 Transforms not supported by: IE (8)
```

Use `--json` to get output as (newline-delimited) JSON objects.


## JS
```javascript
Expand All @@ -53,14 +55,14 @@ Refer to the data in /src/data/features.coffee.
value matches one of those values.

TODO:
- [ ] Support @-rules
- [x] Support @-rules
- [ ] Allow each feature to have multiple instances of the match criteria laid
out above, so that different, disjoint (property, value) combinations can
be used to detect a feature.
out above, so that different, disjoint (property, value) combinations can
be used to detect a feature.
- [ ] Subfeatures, in to allow a slightly looser coupling with caniuse-db's
structure (for handling, e.g., partial support, the different flexbox versions, etc.)
structure (for handling, e.g., partial support, the different flexbox versions, etc.)
- [ ] Prefix-aware testing: i.e., pass along a list of prefixes used with a
given feature. (This is low priority: just use autoprefixer.)
given feature. (This is low priority: just use autoprefixer.)


# API Details:
Expand Down
18 changes: 14 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,31 @@ var yargs = require('yargs')
description: 'Verbose output. Multiple levels available.'
})
.count('verbose')
.options('j', {
alias: 'json',
description: 'Output JSON instead of string linter-like messages.'
})
.boolean('j')
.help('h', 'Show help message.')
.alias('h', 'help');

var argv = yargs.argv;

// Callback to report each unsupported feature usage.
function report(usageInfo) {
console.log(argv.json ? JSON.stringify(usageInfo) : usageInfo.message);
}


var report = console.log.bind(console);
// Set up the linter instance
var linter = doiuse({
browserSelection: argv.b.split(',').map(function(s){return s.trim();}),
onUnsupportedFeatureUse: function(usageInfo) {
report(usageInfo.message);
}
onUnsupportedFeatureUse: report
});
var processor = postcss(linter);



// Informational output
if(argv.l) { argv.v = ++argv.verbose; }
if(argv.verbose >= 1) {
Expand Down

0 comments on commit f1eba90

Please sign in to comment.