Comparing version
31
cli.js
#!/usr/bin/env node | ||
var FILE_NOT_FOUND = 'ENOENT' | ||
var fs = require('fs') | ||
@@ -7,2 +9,4 @@ var ldjson = require('ldjson-stream') | ||
var browserslist = require('browserslist') | ||
var path = require('path') | ||
var _ = require('lodash') | ||
@@ -35,2 +39,7 @@ var formatBrowserName = require('./lib/util').formatBrowserName | ||
}) | ||
.options('c', { | ||
alias: 'config', | ||
description: 'Provide options through config file' | ||
}) | ||
.string('verbose') | ||
.options('v', { | ||
@@ -51,5 +60,23 @@ alias: 'verbose', | ||
argv.browsers = argv.browsers.split(',').map(function (s) {return s.trim()}) | ||
argv.ignore = argv.ignore.split(',').map(function (s) {return s.trim()}) | ||
// Config file reading | ||
if (argv.config) { | ||
try { | ||
var fileData = fs.readFileSync(path.resolve(argv.config), 'utf8') | ||
var config = JSON.parse(fileData) | ||
_.forEach(_.keys(config), function (key) { | ||
var value = config[key] | ||
if (key === 'browsers') { | ||
if (_.isArray(value)) value = value.join(',') | ||
} | ||
argv[key] = value | ||
}) | ||
} catch (err) { | ||
if (err.code === FILE_NOT_FOUND) console.error('Config file not found', err) | ||
else console.error(err) | ||
} | ||
} | ||
argv.browsers = argv.browsers.split(',').map(function (s) { return s.trim() }) | ||
argv.ignore = argv.ignore.split(',').map(function (s) { return s.trim() }) | ||
// Informational output | ||
@@ -56,0 +83,0 @@ if (argv.l) { argv.v = ++argv.verbose } |
@@ -226,3 +226,3 @@ var list = require('postcss/lib/list') | ||
matchOutsideOfBrackets(/\*/), | ||
matchOutsideOfBrackets(/\>/), | ||
matchOutsideOfBrackets(/>/), | ||
matchOutsideOfBrackets(/\+/), | ||
@@ -229,0 +229,0 @@ matchOutsideOfBrackets(/\./), |
@@ -107,3 +107,2 @@ 'use strict'; | ||
if (_.startsWith(text, PLUGIN_OPTION_COMMENT)) { | ||
var option = text.split(' ', 1)[0]; | ||
@@ -110,0 +109,0 @@ var value = text.replace(option, '').trim(); |
{ | ||
"name": "doiuse", | ||
"version": "2.4.1", | ||
"version": "2.5.0", | ||
"description": "Lint CSS for browser support against caniuse database.", | ||
@@ -46,5 +46,5 @@ "main": "lib/doiuse.js", | ||
"postcss-import": "^7.1.3", | ||
"standard": "^4.3.1", | ||
"standard": "^8.1.0", | ||
"tape": "^4.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
var cp_exec = require('child_process').exec | ||
var cpExec = require('child_process').exec | ||
var path = require('path') | ||
@@ -10,7 +10,8 @@ | ||
var expected_css_gradients = '<streaming css input>:8:1: CSS Gradients not supported by: IE (8,9) (css-gradients)\n' + | ||
var expectedCssGradients = '<streaming css input>:8:1: CSS Gradients not supported by: IE (8,9) (css-gradients)\n' + | ||
'<streaming css input>:12:1: CSS Gradients not supported by: IE (8,9) (css-gradients)\n' | ||
var expected_css_repeating_gradients = '<streaming css input>:16:1: CSS Repeating Gradients not supported by: IE (8,9) (css-repeating-gradients)\n' + | ||
var expectedCssRepeatingGradients = '<streaming css input>:16:1: CSS Repeating Gradients not supported by: IE (8,9) (css-repeating-gradients)\n' + | ||
'<streaming css input>:20:1: CSS Repeating Gradients not supported by: IE (8,9) (css-repeating-gradients)\n' | ||
var expected = expected_css_gradients + expected_css_repeating_gradients | ||
var expected = expectedCssGradients + expectedCssRepeatingGradients | ||
var commands = { | ||
@@ -21,4 +22,4 @@ cat: catCss, | ||
var expected_with_ignore = expected_css_repeating_gradients | ||
var commands_with_ignore = { | ||
var expectedWithIgnore = expectedCssRepeatingGradients | ||
var commandsWithIgnore = { | ||
cat: catCss, | ||
@@ -30,3 +31,3 @@ doiuse: pathToCli + ' --browsers="IE >= 8" --ignore="css-gradients" ' | ||
console.log(cmd) | ||
cp_exec(cmd, cb) | ||
cpExec(cmd, cb) | ||
} | ||
@@ -49,4 +50,4 @@ | ||
test('cli command with ignore: piped input', function (t) { | ||
exec(commands_with_ignore.cat + ' | ' + commands_with_ignore.doiuse, function (error, stdout, stderr) { | ||
t.equal(stdout, expected_with_ignore) | ||
exec(commandsWithIgnore.cat + ' | ' + commandsWithIgnore.doiuse, function (error, stdout, stderr) { | ||
t.equal(stdout, expectedWithIgnore) | ||
t.end(error) | ||
@@ -57,4 +58,4 @@ }) | ||
test('should take filename as input with ignore', function (t) { | ||
exec(commands_with_ignore.doiuse + cssFile, function (error, stdout, stderr) { | ||
t.equal(stdout, expected_with_ignore.replace(/<streaming css input>/g, cssFile)) | ||
exec(commandsWithIgnore.doiuse + cssFile, function (error, stdout, stderr) { | ||
t.equal(stdout, expectedWithIgnore.replace(/<streaming css input>/g, cssFile)) | ||
t.end(error) | ||
@@ -86,1 +87,12 @@ }) | ||
}) | ||
test('-c config file should work as input parameters', function (t) { | ||
var configFile = path.join(__dirname, '/fixtures/doiuse.config.json') | ||
var overflowWrapCssFile = path.join(__dirname, '/cases/overflow-wrap.css') | ||
var expectedOverflowWrapConfig = '<streaming css input>:7:1: CSS3 Overflow-wrap only partially supported by: IE (11) (wordwrap)\n' | ||
exec(commands.doiuse + '-c ' + configFile + ' ' + overflowWrapCssFile, function (error, stdout, stderr) { | ||
t.equal(stdout, expectedOverflowWrapConfig.replace(/<streaming css input>/g, overflowWrapCssFile)) | ||
t.end(error) | ||
}) | ||
}) |
@@ -92,3 +92,3 @@ var fs = require('fs') | ||
var caseFiles = fs.readdirSync(path.join(__dirname, '/cases')) | ||
.filter(function (tc) { return /\.css$/.test(tc)}) | ||
.filter(function (tc) { return /\.css$/.test(tc) }) | ||
@@ -95,0 +95,0 @@ var cases = [] |
@@ -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 @@ [ |
@@ -35,5 +35,5 @@ var fs = require('fs') | ||
.process(css).then(function () { | ||
t.equal(count, 4) | ||
t.end() | ||
}) | ||
t.equal(count, 4) | ||
t.end() | ||
}) | ||
}) | ||
@@ -57,5 +57,5 @@ | ||
.process(css).then(function () { | ||
t.equal(count, 2) | ||
t.end() | ||
}) | ||
t.equal(count, 2) | ||
t.end() | ||
}) | ||
}) | ||
@@ -71,8 +71,8 @@ | ||
return postcss(doiuse({ | ||
browsers: ['ie 6'], | ||
ignoreFiles: ['**/ignore-file.css'], | ||
onFeatureUsage: function (usageInfo) { | ||
run = true | ||
} | ||
})) | ||
browsers: ['ie 6'], | ||
ignoreFiles: ['**/ignore-file.css'], | ||
onFeatureUsage: function (usageInfo) { | ||
run = true | ||
} | ||
})) | ||
} | ||
@@ -106,3 +106,3 @@ | ||
} | ||
})]) | ||
})]) | ||
.process(css, {from: cssPath}) | ||
@@ -131,3 +131,3 @@ .then(function () { | ||
} | ||
})]) | ||
})]) | ||
@@ -134,0 +134,0 @@ processor.process(ignoreCss, {from: ignoreCssPath}) |
@@ -11,3 +11,3 @@ var stream = require('../stream') | ||
var expected_with_ignore = [ | ||
var expectedWithIgnore = [ | ||
'background-img-opts' | ||
@@ -33,7 +33,7 @@ ] | ||
s.pipe(through.obj(function (usage, enc, next) { | ||
t.equal(usage.feature, expected_with_ignore.shift()) | ||
t.equal(usage.feature, expectedWithIgnore.shift()) | ||
next() | ||
}, function (next) { | ||
next() | ||
t.equal(expected_with_ignore.length, 0) | ||
t.equal(expectedWithIgnore.length, 0) | ||
t.end() | ||
@@ -40,0 +40,0 @@ })) |
68512
1.92%72
1.41%1904
1.93%