Skip to content

Commit 1c16da3

Browse files
committed
separated cli stuff from generator, renamed package
1 parent a6346a1 commit 1c16da3

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"func-names": 0,
77
"object-shorthand": 0,
88
"camelcase": 0,
9-
"new-cap": 0
9+
"new-cap": 0,
10+
"strict": 0
1011
}
1112
}

index.js renamed to cli.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ if (!program.args[0]) {
2323
require('find-java-home')(function (err, java_home) {
2424
var validator;
2525
if (!err) {
26-
validator = new W3CValidator(program.args[0], java_home);
26+
validator = new W3CValidator({
27+
url: program.args[0],
28+
query: program.query,
29+
verbose: program.verbose,
30+
log: program.log,
31+
max: program.max,
32+
}, java_home);
2733
validator.start();
2834
} else {
2935
console.error(chalk.red.bold('Error: Java is required to use w3c-validator!'));

lib/W3CValidator.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
var path = require('path');
44
var Crawler = require('simplecrawler');
5-
var program = require('commander');
65
var chalk = require('chalk');
76
var exec = require('child_process').exec;
87
var _ = {
@@ -13,7 +12,7 @@ var Spinner = require('cli-spinner').Spinner;
1312
var URL = require('url-parse');
1413
var fs = require('fs');
1514

16-
function W3CValidator(url, java_home) {
15+
function W3CValidator(options, java_home) {
1716
var port = 80;
1817
var exclude = ['swf', 'pdf', 'ps', 'dwf', 'kml', 'kmz', 'gpx', 'hwp',
1918
'ppt', 'pptx', 'doc', 'docx', 'odp', 'ods', 'odt', 'rtf', 'wri', 'svg',
@@ -23,6 +22,7 @@ function W3CValidator(url, java_home) {
2322
var exts = exclude.join('|');
2423
var regex = new RegExp('\.(' + exts + ')', 'i');
2524

25+
this.options = options;
2626
this.chunk = [];
2727
this.count = 0;
2828
this.valid = 0;
@@ -31,7 +31,7 @@ function W3CValidator(url, java_home) {
3131
this.logData = '';
3232
this.httpProxy = false;
3333

34-
this.uri = new URL(url);
34+
this.uri = new URL(this.options.url);
3535
this.crawler = new Crawler(this.uri.host);
3636

3737
this.logFileName = 'w3c-check-' + +new Date() + '-' + this.uri.host;
@@ -66,7 +66,7 @@ function W3CValidator(url, java_home) {
6666
this.crawler.initialProtocol = this.uri.protocol.replace(':', '');
6767
this.crawler.userAgent = 'Node/W3CValidator';
6868

69-
if (!program.query) {
69+
if (!this.options.query) {
7070
this.crawler.stripQuerystring = true;
7171
}
7272

@@ -103,13 +103,13 @@ W3CValidator.prototype.checkURL = function () {
103103
this.invalid++;
104104
console.log(chalk.red.bold('×', url));
105105

106-
if (program.verbose) {
106+
if (this.options.verbose) {
107107
_.forEach(errors.messages, function (m) {
108108
console.log(' Line ' + m.lastLine + ': ' + m.message);
109109
});
110110
}
111111

112-
if (program.log && errors.messages) {
112+
if (this.options.log && errors.messages) {
113113
this.logData += '\n' + url + '\n';
114114
_.forEach(errors.messages, function (m) {
115115
this.logData += ' Line ' + m.lastLine + ': ' + m.message;
@@ -126,7 +126,7 @@ W3CValidator.prototype.checkURL = function () {
126126
process.exit();
127127
};
128128

129-
if (program.log) {
129+
if (this.options.log) {
130130
fs.writeFile(path.join('./', this.logFileName + '.txt'),
131131
this.logData, function () {
132132
console.log('Wrote logged error data to \'%s.txt\'.', this.logFileName);
@@ -148,7 +148,7 @@ W3CValidator.prototype.start = function () {
148148

149149
this.crawler.on('fetchcomplete', function (item) {
150150
this.chunk.push(item.url);
151-
if (program.max && this.chunk.length >= program.max) {
151+
if (this.options.max && this.chunk.length >= this.options.max) {
152152
this.crawler.emit('complete');
153153
this.crawler.stop();
154154
}
@@ -161,7 +161,7 @@ W3CValidator.prototype.start = function () {
161161
if (!_.isEmpty(this.chunk)) {
162162
this.checkURL();
163163
} else {
164-
console.error(chalk.red.bold('Error: Site "%s" could not be found.'), program.args[0]);
164+
console.error(chalk.red.bold('Error: Site "%s" could not be found.'), this.options.url);
165165
process.exit(1);
166166
}
167167
}.bind(this));

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "w3c-validator",
3-
"version": "3.2.0",
2+
"name": "w3c-validator-cli",
3+
"version": "3.3.0",
44
"description": "Crawls a given site and checks for W3C validity.",
5-
"homepage": "https://github.com/lgraubner/node-w3c-validator",
5+
"homepage": "https://github.com/lgraubner/node-w3c-validator-cli",
66
"author": {
77
"name": "Lars Graubner",
88
"email": "mail@larsgraubner.de",
@@ -15,15 +15,16 @@
1515
"w3c",
1616
"validator",
1717
"crawler",
18-
"check"
18+
"check",
19+
"ecosystem:node"
1920
],
20-
"main": "index.js",
21+
"main": "cli.js",
2122
"repository": {
2223
"type": "git",
23-
"url": "https://github.com/lgraubner/node-w3c-validator.git"
24+
"url": "https://github.com/lgraubner/node-w3c-validator-cli.git"
2425
},
2526
"bugs": {
26-
"url": "https://github.com/lgraubner/node-w3c-validator/issues"
27+
"url": "https://github.com/lgraubner/node-w3c-validator-cli/issues"
2728
},
2829
"dependencies": {
2930
"simplecrawler": "^0.5.4",
@@ -39,11 +40,11 @@
3940
"node": ">=0.12"
4041
},
4142
"bin": {
42-
"w3c-validator": "index.js"
43+
"w3c-validator": "cli.js"
4344
},
4445
"license": "MIT",
4546
"scripts": {
46-
"test": "eslint index.js lib/** && NODE_ENV=development mocha test"
47+
"test": "eslint cli.js lib/** && NODE_ENV=development mocha test"
4748
},
4849
"devDependencies": {
4950
"chai": "^3.4.1",

test/cli.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('$ w3c-validator invalid', function () {
1313
var _stderr;
1414

1515
before(function (done) {
16-
exec('node ./index.js illegal', function cmd(error, stdout, stderr) {
16+
exec('node ./cli.js illegal', function cmd(error, stdout, stderr) {
1717
_error = error;
1818
_stderr = stderr;
1919
done();
@@ -37,7 +37,7 @@ describe('$ w3c-validator 127.0.0.1', function () {
3737
this.timeout(10000);
3838

3939
before(function (done) {
40-
exec('node ./index.js 127.0.0.1', function cmd(error, stdout, stderr) {
40+
exec('node ./cli.js 127.0.0.1', function cmd(error, stdout, stderr) {
4141
_error = error;
4242
_stdout = stdout;
4343
_stderr = stderr;
@@ -61,7 +61,7 @@ describe('$ w3c-validator --log 127.0.0.1', function () {
6161
});
6262

6363
before(function (done) {
64-
exec('node ./index.js --log', function cmd() {
64+
exec('node ./cli.js --log', function cmd() {
6565
done();
6666
});
6767
});

0 commit comments

Comments
 (0)