analyze-css
Advanced tools
Comparing version
@@ -10,8 +10,7 @@ #!/usr/bin/env node | ||
const { program } = require('commander'); | ||
var analyzer = require('./../lib/index'), | ||
debug = require('debug')('analyze-css:bin'), | ||
program = require('optimist'), | ||
runner = require('./../lib/runner'), | ||
cssString = '', | ||
argv = {}, | ||
runnerOpts = {}; | ||
@@ -21,57 +20,42 @@ | ||
program | ||
.usage('analyze-css --url <url> [options]') | ||
// mandatory | ||
.describe('url', 'Set URL of CSS to analyze').string('url') | ||
.describe('file', 'Set local CSS file to analyze').string('file') | ||
.describe('ignore-ssl-errors', 'Ignores SSL errors, such as expired or self-signed certificate errors').boolean('ignore-ssl-errors') | ||
.describe('pretty', 'Causes JSON with the results to be pretty-printed').boolean('pretty').alias('pretty', 'p') | ||
.describe('no-offenders', 'Show only the metrics without the offenders part').boolean('no-offenders').alias('no-offenders', 'N') | ||
.describe('auth-user', 'Sets the user name used for HTTP authentication').string('auth-user') | ||
.describe('auth-pass', 'Sets the password used for HTTP authentication').string('auth-pass') | ||
.describe('proxy', 'Sets the HTTP proxy').string('proxy').alias('proxy', 'x') | ||
// version / help | ||
.describe('version', 'Show version number and quit').boolean('version').alias('version', 'V') | ||
.describe('help', 'This help text').boolean('help').alias('help', 'h'); | ||
.version(analyzer.version) | ||
.usage('--url <url> [options]') | ||
// https://www.npmjs.com/package/commander#common-option-types-boolean-and-value | ||
.option('--url <url>', 'Set URL of CSS to analyze') | ||
.option('--file <file>', 'Set local CSS file to analyze') | ||
.option('--ignore-ssl-errors', 'Ignores SSL errors, such as expired or self-signed certificate errors') | ||
.option('-p, --pretty', 'Causes JSON with the results to be pretty-printed') | ||
.option('-N, --no-offenders', 'Show only the metrics without the offenders part') | ||
.option('--auth-user <user>', 'Sets the user name used for HTTP authentication') | ||
.option('--auth-pass <pass>', 'Sets the password used for HTTP authentication') | ||
.option('-x, --proxy <proxy>', 'Sets the HTTP proxy'); | ||
// parse it | ||
argv = program.parse(process.argv); | ||
program.parse(process.argv); | ||
debug('analyze-css v%s', analyzer.version); | ||
debug('argv: %j', argv); | ||
// show version number | ||
if (argv.version === true) { | ||
console.log('analyze-css v%s', analyzer.version); | ||
process.exit(0); | ||
} | ||
// show help | ||
if (argv.help === true) { | ||
program.showHelp(); | ||
process.exit(0); | ||
} | ||
// support stdin (issue #28) | ||
if (argv._ && argv._.indexOf('-') > -1) { | ||
if (process.argv.indexOf('-') > -1) { | ||
runnerOpts.stdin = true; | ||
} | ||
// --url | ||
else if (argv.url) { | ||
runnerOpts.url = argv.url; | ||
else if (program.url) { | ||
runnerOpts.url = program.url; | ||
} | ||
// --file | ||
else if (argv.file) { | ||
runnerOpts.file = argv.file; | ||
else if (program.file) { | ||
runnerOpts.file = program.file; | ||
} | ||
// either --url or --file or - (stdin) needs to be provided | ||
else { | ||
program.showHelp(); | ||
console.log(program.helpInformation()); | ||
process.exit(analyzer.EXIT_NEED_OPTIONS); | ||
} | ||
runnerOpts.ignoreSslErrors = argv['ignore-ssl-errors']; | ||
runnerOpts.noOffenders = argv['no-offenders'] || (argv.offenders === false); | ||
runnerOpts.authUser = argv['auth-user']; | ||
runnerOpts.authPass = argv['auth-pass']; | ||
runnerOpts.proxy = argv.proxy; | ||
runnerOpts.ignoreSslErrors = program['ignore-ssl-errors']; | ||
runnerOpts.noOffenders = program.offenders === false; | ||
runnerOpts.authUser = program['auth-user']; | ||
runnerOpts.authPass = program['auth-pass']; | ||
runnerOpts.proxy = program.proxy; | ||
@@ -104,3 +88,3 @@ debug('opts: %j', runnerOpts); | ||
// format the results | ||
if (argv.pretty === true) { | ||
if (program.pretty === true) { | ||
output = JSON.stringify(res, null, ' '); | ||
@@ -107,0 +91,0 @@ } else { |
{ | ||
"name": "analyze-css", | ||
"version": "0.12.9", | ||
"version": "0.12.10", | ||
"author": "Maciej Brencz <maciej.brencz@gmail.com> (https://github.com/macbre)", | ||
@@ -24,2 +24,3 @@ "description": "CSS selectors complexity and performance analyzer", | ||
"cli": "^1.0.1", | ||
"commander": "^5.1.0", | ||
"css": "^2.2.4", | ||
@@ -33,3 +34,2 @@ "css-shorthand-properties": "^1.1.1", | ||
"onecolor": "^3.1.0", | ||
"optimist": "0.6.x", | ||
"slick": "~1.12.1", | ||
@@ -41,6 +41,6 @@ "specificity": "^0.4.1" | ||
"browserslist": "^4.11.1", | ||
"istanbul": "^0.4.5", | ||
"js-beautify": "^1.11.0", | ||
"jshint": "^2.11.0", | ||
"mocha": "^7.1.1" | ||
"mocha": "^8.0.1", | ||
"nyc": "^15.1.0" | ||
}, | ||
@@ -53,6 +53,7 @@ "bin": "./bin/analyze-css.js", | ||
"beautify": "js-beautify -r rules/*.js test/*.js test/rules/*.js bin/*.js lib/*.js lib/preprocessors/*.js", | ||
"coverage": "istanbul cover _mocha -- -R spec", | ||
"coverage": "nyc mocha -R spec", | ||
"prefixes": "DEBUG=* node data/prefixes.js" | ||
}, | ||
"jshintConfig": { | ||
"esversion": 6, | ||
"node": true, | ||
@@ -59,0 +60,0 @@ "strict": true, |
@@ -9,3 +9,3 @@ exports.tests = [ | ||
{ | ||
css: '.foo { -webkit-animation: none }', | ||
css: '.foo { -webkit-filter: blur(5px) }', | ||
metrics: { | ||
@@ -12,0 +12,0 @@ oldPropertyPrefixes: 0 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
202492
0.29%71
1.43%4838
-0.37%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed