@@ -8,92 +8,95 @@ const HtmlDiffer = require('./index').HtmlDiffer;
88const diffLogger = require ( './logger' ) ;
99const defaults = require ( './defaults' ) ;
1010
11- module . exports = require ( 'coa' ) . Cmd ( )
12- . name ( process . argv [ 1 ] )
13- . helpful ( )
14- . title ( 'Compares two HTML' )
15- . opt ( )
16- . name ( 'version' )
17- . title ( 'Shows the version number' )
18- . short ( 'v' ) . long ( 'version' )
19- . flag ( )
20- . only ( )
21- . act ( function ( ) {
22- const p = require ( '../package.json' ) ;
23- return p . name + ' ' + p . version ;
24- } )
25- . end ( )
26- . opt ( )
27- . name ( 'config' )
28- . title ( 'Path to a configuration JSON file' )
29- . long ( 'config' )
30- . end ( )
31- . opt ( )
32- . name ( 'bem' )
33- . title ( 'Uses predefined options for BEM (deprecated)' )
34- . long ( 'bem' )
35- . flag ( )
36- . act ( function ( opts ) {
37- console . error ( 'Option ' + boldRed ( '--bem' ) + ' is deprecated, use '
38- + boldGreen ( '--preset=bem' ) + ' option instead.' ) ;
39- // support legacy
40- opts . preset = 'bem' ;
41- delete opts . bem ;
42- } )
43- . end ( )
44- . opt ( )
45- . name ( 'preset' )
46- . title ( 'Name of a preset' )
47- . short ( 'p' ) . long ( 'preset' )
48- . val ( function ( val ) {
49- if ( ! defaults . presets . hasOwnProperty ( val ) ) {
50- console . log ( boldRed ( val ) + ' is an invalid preset name. Available presets are: '
51- + Object . keys ( defaults . presets ) . map ( function ( preset ) {
52- return boldGreen ( preset ) ;
53- } ) . join ( ', ' ) + '.' ) ;
54- process . exit ( 1 ) ;
55- }
56- return val ;
57- } )
58- . end ( )
59- . opt ( )
60- . name ( 'charsAroundDiff' )
61- . title ( 'The number of characters around the diff (default: 40)' )
62- . long ( 'chars-around-diff' )
63- . def ( 40 )
64- . val ( function ( val ) {
65- return parseInt ( val , 10 ) ;
66- } )
67- . end ( )
68- . arg ( )
69- . name ( 'path1' )
70- . title ( 'Path to the 1-st HTML file' )
71- . req ( )
72- . end ( )
73- . arg ( )
74- . name ( 'path2' )
75- . title ( 'Path to the 2-nd HTML file' )
76- . req ( )
77- . end ( )
78- . act ( function ( opts , args ) {
79- return vow . all ( [
80- vfs . read ( path . resolve ( args . path1 ) , 'utf-8' ) ,
81- vfs . read ( path . resolve ( args . path2 ) , 'utf-8' ) ,
82- opts . config ? vfs . read ( path . resolve ( opts . config ) ) : undefined
83- ] ) . spread ( function ( html1 , html2 , config ) {
84- config = config ? JSON . parse ( config ) : { } ;
11+ module . exports = {
12+ run ( ) {
13+ require ( 'coa' ) . Cmd ( )
14+ . name ( process . argv [ 1 ] )
15+ . helpful ( )
16+ . title ( 'Compares two HTML' )
17+ . opt ( )
18+ . name ( 'version' )
19+ . title ( 'Shows the version number' )
20+ . short ( 'v' ) . long ( 'version' )
21+ . flag ( )
22+ . only ( )
23+ . act ( function ( ) {
24+ const p = require ( '../package.json' ) ;
25+ return p . name + ' ' + p . version ;
26+ } )
27+ . end ( )
28+ . opt ( )
29+ . name ( 'config' )
30+ . title ( 'Path to a configuration JSON file' )
31+ . long ( 'config' )
32+ . end ( )
33+ . opt ( )
34+ . name ( 'bem' )
35+ . title ( 'Uses predefined options for BEM (deprecated)' )
36+ . long ( 'bem' )
37+ . flag ( )
38+ . act ( function ( opts ) {
39+ console . error ( 'Option ' + boldRed ( '--bem' ) + ' is deprecated, use ' + boldGreen ( '--preset=bem' ) + ' option instead.' ) ;
40+ // support legacy
41+ opts . preset = 'bem' ;
42+ delete opts . bem ;
43+ } )
44+ . end ( )
45+ . opt ( )
46+ . name ( 'preset' )
47+ . title ( 'Name of a preset' )
48+ . short ( 'p' ) . long ( 'preset' )
49+ . val ( function ( val ) {
50+ if ( ! defaults . presets . hasOwnProperty ( val ) ) {
51+ console . log ( boldRed ( val ) + ' is an invalid preset name. Available presets are: '
52+ + Object . keys ( defaults . presets ) . map ( function ( preset ) {
53+ return boldGreen ( preset ) ;
54+ } ) . join ( ', ' ) + '.' ) ;
55+ process . exit ( 1 ) ;
56+ }
57+ return val ;
58+ } )
59+ . end ( )
60+ . opt ( )
61+ . name ( 'charsAroundDiff' )
62+ . title ( 'The number of characters around the diff (default: 40)' )
63+ . long ( 'chars-around-diff' )
64+ . def ( 40 )
65+ . val ( function ( val ) {
66+ return parseInt ( val , 10 ) ;
67+ } )
68+ . end ( )
69+ . arg ( )
70+ . name ( 'path1' )
71+ . title ( 'Path to the 1-st HTML file' )
72+ . req ( )
73+ . end ( )
74+ . arg ( )
75+ . name ( 'path2' )
76+ . title ( 'Path to the 2-nd HTML file' )
77+ . req ( )
78+ . end ( )
79+ . act ( function ( opts , args ) {
80+ return vow . all ( [
81+ vfs . read ( path . resolve ( args . path1 ) , 'utf-8' ) ,
82+ vfs . read ( path . resolve ( args . path2 ) , 'utf-8' ) ,
83+ opts . config ? vfs . read ( path . resolve ( opts . config ) ) : undefined
84+ ] ) . spread ( function ( html1 , html2 , config ) {
85+ config = config ? JSON . parse ( config ) : { } ;
8586
86- if ( opts . preset ) {
87- config . preset = opts . preset ;
88- }
87+ if ( opts . preset ) {
88+ config . preset = opts . preset ;
89+ }
8990
90- const options = defaults ( config ) ;
91- const loggerOptions = {
92- charsAroundDiff : opts . charsAroundDiff
93- } ;
94- const htmlDiffer = new HtmlDiffer ( options ) ;
91+ const options = defaults ( config ) ;
92+ const loggerOptions = {
93+ charsAroundDiff : opts . charsAroundDiff
94+ } ;
95+ const htmlDiffer = new HtmlDiffer ( options ) ;
9596
96- diffLogger . logDiffText ( htmlDiffer . diffHtml ( html1 , html2 ) , loggerOptions ) ;
97- } ) ;
98- } )
99- . run ( process . argv . slice ( 2 ) ) ;
97+ diffLogger . logDiffText ( htmlDiffer . diffHtml ( html1 , html2 ) , loggerOptions ) ;
98+ } ) ;
99+ } )
100+ . run ( process . argv . slice ( 2 ) ) ;
101+ }
102+ } ;
0 commit comments