Comparing version 1.0.1 to 1.0.2
54
cli.js
#!/usr/bin/env node | ||
var fs = require('fs'), | ||
ldjson = require('ldjson-stream'), | ||
jsonfilter = require('jsonfilter'), | ||
through = require('through2'), | ||
browserslist = require('browserslist') | ||
var fs = require('fs') | ||
var ldjson = require('ldjson-stream') | ||
var through = require('through2') | ||
var browserslist = require('browserslist') | ||
var formatBrowserName = require('./lib/util').formatBrowserName, | ||
defaultBrowsers = require('./').default, | ||
doiuse = require('./stream') | ||
var formatBrowserName = require('./lib/util').formatBrowserName | ||
var defaultBrowsers = require('./').default | ||
var doiuse = require('./stream') | ||
@@ -44,16 +43,16 @@ var yargs = require('yargs') | ||
argv.browsers = argv.browsers.split(',').map(function (s) {return s.trim();}) | ||
argv.browsers = argv.browsers.split(',').map(function (s) {return s.trim()}) | ||
// Informational output | ||
if(argv.l) { argv.v = ++argv.verbose; } | ||
if(argv.verbose >= 1) { | ||
browsers = browserslist(argv.browsers) | ||
if (argv.l) { argv.v = ++argv.verbose } | ||
if (argv.verbose >= 1) { | ||
var browsers = browserslist(argv.browsers) | ||
.map(function (b) { | ||
b = b.split(' ') | ||
b[0] = formatBrowserName(b[0]) | ||
b[1] = parseInt(b[1]) | ||
b[1] = parseInt(b[1], 10) | ||
return b | ||
}) | ||
.sort(function (a, b) { return (a[0] !== b[0]) ? a[0] > b[0] : a[1] > b[1] }) | ||
.map(function (b) { return b.join(' '); }) | ||
.map(function (b) { return b.join(' ') }) | ||
.join(', ') | ||
@@ -63,8 +62,8 @@ console.log('[doiuse] Browsers: ' + browsers) | ||
if(argv.verbose >= 2) { | ||
features = linter.info().features | ||
if (argv.verbose >= 2) { | ||
var features = require('./')(argv.browsers).info().features | ||
console.log('\n[doiuse] Unsupported features:') | ||
for (feat in features) { | ||
for (var feat in features) { | ||
var out = [features[feat].caniuseData.title] | ||
if(argv.verbose >= 3) { | ||
if (argv.verbose >= 3) { | ||
out.push('\n', features[feat].missing.join(', '), '\n') | ||
@@ -75,6 +74,6 @@ } | ||
} | ||
if(argv.l) { process.exit(); } | ||
if (argv.l) { process.exit() } | ||
// Process the CSS | ||
if(argv.help || (argv._.length == 0 && process.stdin.isTTY)) { | ||
if (argv.help || (argv._.length === 0 && process.stdin.isTTY)) { | ||
yargs.showHelp() | ||
@@ -84,9 +83,7 @@ process.exit() | ||
var options = {messages: !argv.json} | ||
var out | ||
if(argv.json) { | ||
if (argv.json) { | ||
out = ldjson.serialize() | ||
} | ||
if(!argv.json) { | ||
if (!argv.json) { | ||
out = through.obj(function (usage, enc, next) { | ||
@@ -98,11 +95,12 @@ next(null, usage.message + '\n') | ||
if(argv._.length > 0) | ||
if (argv._.length > 0) { | ||
argv._.forEach(function (file) { | ||
fs.createReadStream(file) | ||
.pipe(doiuse(argv.browsers, file)) | ||
.pipe(out) | ||
.pipe(doiuse(argv.browsers, file)) | ||
.pipe(out) | ||
}) | ||
else | ||
} else { | ||
process.stdin | ||
.pipe(doiuse(argv.browsers)) | ||
.pipe(out) | ||
} |
@@ -1,2 +0,2 @@ | ||
## `doiuse` is an **OPEN Open Source Project** | ||
## `doiuse` is an **[OPEN Open Source Project](http://openopensource.org/)** | ||
----------------------------------------- | ||
@@ -3,0 +3,0 @@ |
@@ -15,2 +15,3 @@ 'use strict'; | ||
function isFoundIn(str) { | ||
str = stripUrls(str); | ||
return function find(searchfor) { | ||
@@ -22,3 +23,11 @@ if (searchfor instanceof RegExp) return searchfor.test(str);else if (_.isFunction(searchfor)) return searchfor(str);else return str && str.indexOf(searchfor) >= 0; | ||
/* | ||
* postcss the use of any of a given list of CSS features. | ||
* Strip the contents of url literals so they aren't matched | ||
* by our naive substring matching. | ||
*/ | ||
function stripUrls(str) { | ||
return str.replace(/url\([^\)]*\)/g, 'url()'); | ||
} | ||
/** | ||
* Detect the use of any of a given list of CSS features. | ||
* ``` | ||
@@ -39,3 +48,2 @@ * var detector = new Detector(featureList) | ||
*/ | ||
module.exports = (function () { | ||
@@ -42,0 +50,0 @@ function Detector(featureList) { |
{ | ||
"name": "doiuse", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Lint CSS for browser support against caniuse database.", | ||
"main": "lib/doiuse.js", | ||
"scripts": { | ||
"test": "tape test/*.js", | ||
"test": "standard && tape test/*.js", | ||
"babel": "babel -d lib/ src/", | ||
@@ -44,4 +44,5 @@ "pretest": "npm run babel", | ||
"babel": "^5.2.13", | ||
"standard": "^4.3.1", | ||
"tape": "^4.0.0" | ||
} | ||
} |
@@ -137,3 +137,3 @@ [![Build Status](https://travis-ci.org/anandthakker/doiuse.svg?branch=master)](https://travis-ci.org/anandthakker/doiuse) | ||
doiuse is an OPEN Open Source Project. This means that: | ||
doiuse is an [OPEN Open Source](http://openopensource.org/) Project. This means that: | ||
@@ -140,0 +140,0 @@ Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. |
@@ -1,8 +0,8 @@ | ||
var through = require('through2'), | ||
duplexer = require('duplexer2'), | ||
rules = require('css-rule-stream'), | ||
sourcemap = require('source-map') | ||
var through = require('through2') | ||
var duplexer = require('duplexer2') | ||
var rules = require('css-rule-stream') | ||
var sourcemap = require('source-map') | ||
var postcss = require('postcss'), | ||
doiuse = require('./') | ||
var postcss = require('postcss') | ||
var doiuse = require('./') | ||
@@ -13,3 +13,3 @@ module.exports = stream | ||
* @param {Array<string>} browsers the browserslist browser selection | ||
* @param {string} [filename] Filename for outputting source code locations. | ||
* @param {string} [filename] Filename for outputting source code locations. | ||
*/ | ||
@@ -30,3 +30,4 @@ function stream (browsers, filename) { | ||
var lines = rule.content.split('\n') | ||
var oline = rule.line, ocol = rule.column | ||
var oline = rule.line | ||
var ocol = rule.column | ||
for (var line = 0; line < lines.length; line++) { | ||
@@ -33,0 +34,0 @@ mapper.addMapping({ |
@@ -1,3 +0,3 @@ | ||
var cp_exec = require('child_process').exec, | ||
path = require('path') | ||
var cp_exec = require('child_process').exec | ||
var path = require('path') | ||
@@ -4,0 +4,0 @@ var test = require('tape') |
@@ -18,11 +18,11 @@ var fs = require('fs') | ||
matches[2].split('\n') | ||
.filter(function (s) { | ||
return s.trim().length > 0 | ||
}) | ||
.forEach(function (s) { | ||
var line = s.replace(/\s*/, '').split(':') | ||
var feat = line[0] | ||
var count = +line[1] | ||
features[feat] = count | ||
}) | ||
.filter(function (s) { | ||
return s.trim().length > 0 | ||
}) | ||
.forEach(function (s) { | ||
var line = s.replace(/\s*/, '').split(':') | ||
var feat = line[0] | ||
var count = +line[1] | ||
features[feat] = count | ||
}) | ||
@@ -79,6 +79,9 @@ if (Object.keys(features).length > 0) { | ||
var res = Object.keys(cb.results).sort() | ||
t.deepEqual(res, features) | ||
for (var feature in expected) { | ||
t.equal(cb.results[feature].length, expected[feature], 'count of ' + feature) | ||
if (expected[feature] === 0) { | ||
t.notOk(cb.results[feature]) | ||
} else { | ||
t.deepEqual(res, features) | ||
t.equal(cb.results[feature].length, expected[feature], 'count of ' + feature) | ||
} | ||
} | ||
@@ -112,2 +115,1 @@ | ||
}) | ||
@@ -9,4 +9,4 @@ var test = require('tape') | ||
.browsers.sort(function (a, b) { | ||
return Number(a[1]) - Number(b[1]) | ||
}) | ||
return Number(a[1]) - Number(b[1]) | ||
}) | ||
t.deepEqual(data, [ | ||
@@ -13,0 +13,0 @@ [ |
@@ -33,3 +33,3 @@ var fs = require('fs') | ||
})) | ||
.process(css).then(function () { | ||
.process(css).then(function () { | ||
t.equal(count, 4) | ||
@@ -36,0 +36,0 @@ t.end() |
@@ -1,3 +0,3 @@ | ||
var stream = require('../stream'), | ||
through = require('through2') | ||
var stream = require('../stream') | ||
var through = require('through2') | ||
@@ -4,0 +4,0 @@ var test = require('tape') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54997
67
1564
3