-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
280 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "0.12" | ||
- "iojs" | ||
after_success: | ||
- npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,49 @@ | ||
[![Build Status](https://travis-ci.org/zrrrzzt/html-validator-cli.svg?branch=master)](https://travis-ci.org/zrrrzzt/html-validator-cli) | ||
[![Coverage Status](https://coveralls.io/repos/zrrrzzt/html-validator-cli/badge.svg?branch=master&service=github)](https://coveralls.io/github/zrrrzzt/html-validator-cli?branch=master) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
# html-validator-cli | ||
CLI for validating html using validator.w3.org/nu | ||
CLI for validating html using [validator.w3.org/nu](http://validator.w3.org/nu/) | ||
|
||
## Installation | ||
|
||
```sh | ||
$ npm install html-validator-cli -g | ||
``` | ||
|
||
## Usage | ||
|
||
Pass in <url> or --file and optional --format or --validator. | ||
|
||
### Examples | ||
|
||
With url | ||
|
||
```sh | ||
$ html-validator <url> | ||
``` | ||
|
||
With file | ||
|
||
```sh | ||
$ html-validator --file=path-to-file | ||
``` | ||
|
||
Optional pass in format for returned data. | ||
|
||
Valid options: json, html, xhtml, xml, gnu and text (default). | ||
|
||
```sh | ||
$ html-validator <url> --format=gnu | ||
``` | ||
|
||
Optional pass in another validator. | ||
|
||
It needs to expose the same REST interface. | ||
|
||
```sh | ||
$ html-validator <url> --validator='http://html5.validator.nu' | ||
``` | ||
|
||
## Related | ||
|
||
- [html-validator](https://github.com/zrrrzzt/html-validator) API for this module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env node | ||
'use strict' | ||
|
||
var fs = require('fs') | ||
var validator = require('html-validator') | ||
var getHelpText = require('./lib/getHelpText') | ||
var pkg = require('./package.json') | ||
var query = process.argv[2] | ||
var argv = require('minimist')((process.argv.slice(2))) | ||
var opts = {format: 'text'} | ||
|
||
if (!query || process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) { | ||
console.log(getHelpText()) | ||
process.exit(0) | ||
} | ||
|
||
if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) { | ||
console.log(pkg.version) | ||
process.exit(0) | ||
} | ||
|
||
if (query.indexOf('http') !== -1) { | ||
opts.url = argv._[0] | ||
} | ||
|
||
if (argv.format) { | ||
opts.format = argv.format | ||
} | ||
|
||
if (argv.url) { | ||
opts.url = argv.url | ||
} | ||
|
||
if (argv.file) { | ||
opts.data = fs.readFileSync(argv.file) | ||
} | ||
|
||
validator(opts, function (err, data) { | ||
if (err) { | ||
throw err | ||
} else { | ||
console.log(opts.format === 'json' ? JSON.stringify(data) : data) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
function getHelptext () { | ||
var help = require('./helptext.json') | ||
return help.join('\n') | ||
} | ||
|
||
module.exports = getHelptext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
"Usage: ", | ||
"", | ||
"$ html-validator <url>", | ||
"", | ||
"or", | ||
"$ html-validator --file=<file>", | ||
"", | ||
"Optional, specify format of returned data", | ||
"Valid options: json, html, xhtml, xml, gnu and text (default)", | ||
"", | ||
"$ html-validator <url> --format=<format>" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "html-validator-cli", | ||
"version": "1.0.0", | ||
"description": "CLI for validating html using validator.w3.org/nu", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Geir Gåsodden", | ||
"email": "geir.gasodden@pythonia.no", | ||
"url": "https://github.com/zrrrzzt" | ||
}, | ||
"main": "index.js", | ||
"bin": { | ||
"html-validator": "index.js" | ||
}, | ||
"engines": { | ||
"node": ">=0.12.0" | ||
}, | ||
"scripts": { | ||
"setup": "npm install && node setup.js", | ||
"test": "standard && tap --reporter=spec test/*.js", | ||
"coverage": "tap test/*.js --coverage", | ||
"coveralls": "tap --cov --coverage-report=lcov test/*.js && cat coverage/lcov.info | coveralls" | ||
}, | ||
"keywords": [ | ||
"html-validator", | ||
"validation", | ||
"cli" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/zrrrzzt/html-validator-cli.git" | ||
}, | ||
"bugs": { | ||
"url": "http://github.com/zrrrzzt/html-validator-cli/issues" | ||
}, | ||
"dependencies": { | ||
"minimist": "^1.2.0", | ||
"html-validator": "^0.0.8" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.11.4", | ||
"standard": "^5.3.1", | ||
"tap": "^1.4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
console.log('Everything\'s shiny, Cap\'n. Not to fret.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict' | ||
|
||
var exec = require('child_process').execFile | ||
var tap = require('tap') | ||
var getHelpText = require('../lib/getHelpText') | ||
var pkgVersion = require('../package.json').version | ||
|
||
tap.test('It returns helptext with -h flag', function helpTextWithH (test) { | ||
exec('./index.js', ['-h'], function helpTextWithH (error, stdout, stderr) { | ||
if (error) { | ||
console.error(stderr.toString()) | ||
throw error | ||
} else { | ||
test.equal(stdout.toString().trim(), getHelpText().toString().trim()) | ||
test.end() | ||
} | ||
}) | ||
}) | ||
|
||
tap.test('It returns helptext with --help flag', function helpTextWithH (test) { | ||
exec('./index.js', ['--help'], function helpTextWithH (error, stdout, stderr) { | ||
if (error) { | ||
console.error(stderr.toString()) | ||
throw error | ||
} else { | ||
test.equal(stdout.toString().trim(), getHelpText().toString().trim()) | ||
test.end() | ||
} | ||
}) | ||
}) | ||
|
||
tap.test('It returns version with -v flag', function versionWithV (test) { | ||
exec('./index.js', ['-v'], function versionWithV (error, stdout, stderr) { | ||
if (error) { | ||
console.error(stderr.toString()) | ||
throw error | ||
} else { | ||
test.equal(stdout.toString().trim(), pkgVersion) | ||
test.end() | ||
} | ||
}) | ||
}) | ||
|
||
tap.test('It returns error on error', function testError (test) { | ||
exec('./index.js', ['npmlovesyou-do-you-love-npm'], function versionWithV (error, stdout, stderr) { | ||
test.ok(error, 'Error OK') | ||
test.end() | ||
}) | ||
}) | ||
|
||
tap.test('It returns data if url supplied', function testError (test) { | ||
exec('./index.js', ['https://www.github.com'], function versionWithV (error, stdout, stderr) { | ||
if (error) { | ||
throw error | ||
} | ||
test.ok(stdout.toString().trim(), 'Data OK') | ||
test.end() | ||
}) | ||
}) | ||
|
||
tap.test('It returns data if file supplied', function testError (test) { | ||
exec('./index.js', ['--file=test/data/invalid.html'], function versionWithV (error, stdout, stderr) { | ||
if (error) { | ||
throw error | ||
} | ||
test.ok(stdout.toString().trim(), 'Data OK') | ||
test.end() | ||
}) | ||
}) | ||
|
||
tap.test('It returns data on supplied supplied format', function testError (test) { | ||
exec('./index.js', ['--file=test/data/invalid.html', '--format=json'], function versionWithV (error, stdout, stderr) { | ||
if (error) { | ||
throw error | ||
} | ||
test.equal(JSON.parse(stdout.toString().trim()).messages.length, 3) | ||
test.end() | ||
}) | ||
}) | ||
|
||
tap.test('You can supply url by flag', function testError (test) { | ||
exec('./index.js', ['--url=https://www.github.com'], function versionWithV (error, stdout, stderr) { | ||
if (error) { | ||
throw error | ||
} | ||
test.ok(stdout.toString().trim(), 'Data OK') | ||
test.end() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>Invalid</title> | ||
</head> | ||
<body> | ||
<p>I'm baaaaaaaaaaaad code</div></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
var tap = require('tap') | ||
var getHelpText = require('../lib/getHelpText') | ||
var helpText = require('../lib/helptext.json').join('\n') | ||
|
||
tap.equal(helpText, getHelpText(), 'It returns correct helptext') |