22
33var path = require ( 'path' ) ;
44var Crawler = require ( 'simplecrawler' ) ;
5- var program = require ( 'commander' ) ;
65var chalk = require ( 'chalk' ) ;
76var exec = require ( 'child_process' ) . exec ;
87var _ = {
@@ -13,7 +12,7 @@ var Spinner = require('cli-spinner').Spinner;
1312var URL = require ( 'url-parse' ) ;
1413var 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 ) ) ;
0 commit comments