11var path = require ( 'path' ) ,
22 vow = require ( 'vow' ) ,
33 vfs = require ( 'vow-fs' ) ,
4+ colors = require ( 'colors' ) ,
45 HtmlDiffer = require ( './index' ) . HtmlDiffer ,
56 diffLogger = require ( './logger' ) ,
67 defaults = require ( './utils/defaults' ) ;
@@ -28,18 +29,37 @@ module.exports = require('coa').Cmd()
2829 . end ( )
2930 . opt ( )
3031 . name ( 'bem' )
31- . title ( 'Uses predefined options for BEM' )
32+ . title ( 'Uses predefined options for BEM (deprecated) ' )
3233 . long ( 'bem' )
3334 . flag ( )
35+ . act ( function ( opts ) {
36+ console . error ( 'Option ' + '--bem' . bold . red + ' is deprecated, use ' +
37+ '--preset=bem' . bold . green + ' option instead.' ) ;
38+ // support legacy
39+ opts . preset = 'bem' ;
40+ delete opts . bem ;
41+ } )
42+ . end ( )
43+ . opt ( )
44+ . name ( 'preset' )
45+ . title ( 'Name of preset' )
46+ . short ( 'p' ) . long ( 'preset' )
47+ . val ( function ( val ) {
48+ if ( ! defaults . presets . hasOwnProperty ( val ) ) {
49+ console . log ( val . bold . red + ' is an invalid preset name. Available presets are: ' +
50+ Object . keys ( defaults . presets ) . map ( colors . green ) . map ( colors . bold ) . join ( ', ' ) + '.' ) ;
51+ process . exit ( 1 ) ;
52+ }
53+ return val ;
54+ } )
3455 . end ( )
3556 . opt ( )
3657 . name ( 'charsAroundDiff' )
3758 . title ( 'The number of characters around the diff (default: 40)' )
3859 . long ( 'chars-around-diff' )
3960 . def ( 40 )
4061 . val ( function ( val ) {
41- /*jshint es3:false */
42- return parseInt ( val ) ;
62+ return parseInt ( val , 10 ) ;
4363 } )
4464 . end ( )
4565 . arg ( )
@@ -58,10 +78,10 @@ module.exports = require('coa').Cmd()
5878 vfs . read ( path . resolve ( args . path2 ) , 'utf-8' ) ,
5979 opts . config ? vfs . read ( path . resolve ( opts . config ) ) : undefined
6080 ] ) . spread ( function ( html1 , html2 , config ) {
61- if ( ! opts . bem ) {
62- config = config ? JSON . parse ( config ) : { } ;
63- } else {
64- config = 'bem' ;
81+ config = config ? JSON . parse ( config ) : { } ;
82+
83+ if ( opts . preset ) {
84+ config . preset = opts . preset ;
6585 }
6686
6787 var options = defaults ( config ) ,
0 commit comments