1- #! /usr/bin/env node
2-
31'use strict' ;
42
5- const config = require ( './config' ) ;
63const intro = require ( './intro' ) ;
74const runner = require ( './runner' ) ;
85const localAppServer = require ( './localAppServer' ) ;
96const resultsPrinter = require ( './resultsPrinter' ) ;
107
11- intro ( ) ;
12-
13- const prerun = config . localAppServer
14- ? localAppServer . start ( config . localAppServer )
15- : Promise . resolve ( ) ;
16-
17- prerun . then ( runner )
18- . then ( results => resultsPrinter . printResults ( results ) )
19- . then ( onValidated ) . catch ( onError ) ;
20-
218function onValidated ( results ) {
22- const failed = hasErrors ( results ) ;
9+ const hasFailed = hasErrors ( results ) ;
2310
24- if ( ! failed ) {
11+ if ( ! hasFailed ) {
2512console . info ( 'Congratulations! Your HTML is valid!' ) ;
26- exit ( 0 ) ;
27- }
13+ }
2814
29- exit ( config . failHard ? 1 : 0 ) ;
15+ return hasFailed ;
3016}
3117
3218function hasErrors ( results ) {
@@ -35,14 +21,30 @@ function hasErrors(results) {
3521
3622function onError ( error ) {
3723console . error ( error ) ;
38- exit ( 1 ) ;
24+ exit ( true ) ;
3925}
4026
41- function exit ( exitCode ) {
27+ function exit ( hasFailed , config ) {
28+ const exitCode = hasFailed && config . failHard ? 1 : 0 ;
29+
4230if ( config . localAppServer ) {
4331localAppServer . stop ( ) ;
4432}
4533
4634resultsPrinter . resetStdout ( ) ;
4735process . exit ( exitCode ) ;
48- }
36+ }
37+
38+ module . exports = function valimate ( config ) {
39+ intro ( ) ;
40+
41+ const prerun = config . localAppServer
42+ ? localAppServer . start ( config . localAppServer )
43+ : Promise . resolve ( ) ;
44+
45+ return prerun . then ( runner )
46+ . then ( results => resultsPrinter . printResults ( results ) )
47+ . then ( onValidated )
48+ . then ( hasFailed => exit ( hasFailed , config ) )
49+ . catch ( ( ) => onError ( true , config ) ) ;
50+ } ;
0 commit comments