@@ -52,17 +52,19 @@ if (program.folder) {
52
52
53
53
function actionsToDo ( ) {
54
54
55
- if ( program . output === 'console' ) {
55
+ if ( ! program . output || program . output === 'console' ) {
56
56
if ( program . type === 'xpaths' ) {
57
57
return function ( path ) {
58
- console . log ( `${ path } ${ results [ path ] . count } ${ program . attributes ? JSON . stringify ( results [ path ] . attributes ) : '' } ` )
58
+ let nbOfAttr = program . attributes ? Object . keys ( results [ path ] . attributes ) . length : 0 ;
59
+ console . log ( `${ path } ${ results [ path ] . count } ${ nbOfAttr ? JSON . stringify ( results [ path ] . attributes ) : '' } ` )
59
60
} ;
60
61
}
61
62
//tree
62
63
return function ( path ) {
63
64
let elements = path . split ( '/' ) ,
64
65
elementName = elements [ elements . length - 1 ] ;
65
- console . log ( `${ '│ ' . repeat ( results [ path ] . level ) } ├── ${ elementName } ${ results [ path ] . count } ${ program . attributes ? JSON . stringify ( results [ path ] . attributes ) : '' } ` )
66
+ let nbOfAttr = program . attributes ? Object . keys ( results [ path ] . attributes ) . length : 0 ;
67
+ console . log ( `${ '│ ' . repeat ( results [ path ] . level ) } ├── ${ elementName } ${ results [ path ] . count } ${ nbOfAttr ? JSON . stringify ( results [ path ] . attributes ) : '' } ` )
66
68
} ;
67
69
}
68
70
// Write file, no output
@@ -75,29 +77,27 @@ function actionsToDo() {
75
77
if ( program . type === 'xpaths' ) {
76
78
xpathsFile = writeStream ( 'xpaths' , program . output , 'csv' ) ;
77
79
return function ( path ) {
78
- xpathsFile . write ( `${ path } ;${ results [ path ] . count } ` )
79
- if ( program . attributes ) {
80
- for ( var attr in results [ path ] . attributes ) {
81
- xpathsFile . write ( `;"${ attr } => ${ results [ path ] . attributes [ attr ] . join ( '\n' ) } "` )
82
- }
83
- }
84
- xpathsFile . write ( '\n' ) ;
80
+ let nbOfAttr = program . attributes ? Object . keys ( results [ path ] . attributes ) . length : 0 ;
81
+ xpathsFile . write ( `${ path } ${ results [ path ] . count } ${ nbOfAttr ? JSON . stringify ( results [ path ] . attributes ) : '' } \n` )
85
82
}
86
83
}
87
84
if ( program . type === 'tree' ) {
88
85
treeFile = writeStream ( 'tree' , program . output , 'txt' ) ;
89
86
return function ( path ) {
90
- treeFile . write ( `${ '│ ' . repeat ( results [ path ] . level ) } ├── ${ path } ${ results [ path ] . count } ${ program . attributes ? JSON . stringify ( results [ path ] . attributes ) : '' } \n` ) ;
87
+ let nbOfAttr = program . attributes ? Object . keys ( results [ path ] . attributes ) . length : 0 ;
88
+ treeFile . write ( `${ '│ ' . repeat ( results [ path ] . level ) } ├── ${ path } ${ results [ path ] . count } ${ nbOfAttr ? JSON . stringify ( results [ path ] . attributes ) : '' } \n` ) ;
91
89
}
92
90
}
93
91
//both
94
92
xpathsFile = writeStream ( 'xpaths' , program . output , 'csv' ) ;
95
93
treeFile = writeStream ( 'tree' , program . output , 'txt' ) ;
96
94
return function ( path ) {
97
- xpathsFile . write ( `${ path } ${ results [ path ] . count } \n` )
98
- treeFile . write ( `${ '│ ' . repeat ( results [ path ] . level ) } ├── ${ path } ${ results [ path ] . count } \n` ) ;
95
+ let nbOfAttr = program . attributes ? Object . keys ( results [ path ] . attributes ) . length : 0 ;
96
+ xpathsFile . write ( `${ path } ${ results [ path ] . count } ${ nbOfAttr ? JSON . stringify ( results [ path ] . attributes ) : '' } \n` )
97
+ treeFile . write ( `${ '│ ' . repeat ( results [ path ] . level ) } ├── ${ path } ${ results [ path ] . count } ${ nbOfAttr ? JSON . stringify ( results [ path ] . attributes ) : '' } \n` ) ;
99
98
}
100
99
}
100
+
101
101
}
102
102
103
103
function writeStream ( type , output , extension ) {
0 commit comments