@@ -28,7 +28,18 @@ tree.builder = function(cli) {
2828 describe :
2929 "Overrides the framework version defined by the project. Only supported in combination with --full" ,
3030 type : "string"
31- } ) . check ( ( argv ) => {
31+ } )
32+ . option ( "x-graph-mode" , {
33+ describe : "Uses an experimental project graph instead of a dependency tree" ,
34+ default : false ,
35+ type : "boolean"
36+ } )
37+ . option ( "x-perf" , {
38+ describe : "Outputs performance measurements" ,
39+ default : false ,
40+ type : "boolean"
41+ } )
42+ . check ( ( argv ) => {
3243 if ( argv . frameworkVersion && ! argv . full ) {
3344 throw new Error ( `"framework-version" can only be used in combination with option "--full"` ) ;
3445 } else {
@@ -42,6 +53,7 @@ tree.builder = function(cli) {
4253tree . handler = async function ( argv ) {
4354 const normalizer = require ( "@ui5/project" ) . normalizer ;
4455 const treeify = require ( "treeify" ) ;
56+ const chalk = require ( "chalk" ) ;
4557
4658 const options = {
4759 translatorName : argv . translator ,
@@ -57,15 +69,91 @@ tree.handler = async function(argv) {
5769 } ;
5870 }
5971
60- let projectTree ;
61- if ( argv . full ) {
62- projectTree = await normalizer . generateProjectTree ( options ) ;
72+ let startTime ;
73+ let elapsedTime ;
74+ if ( argv . xPerf ) {
75+ startTime = process . hrtime ( ) ;
76+ }
77+ if ( argv . xGraphMode ) {
78+ const graph = await normalizer . generateProjectGraph ( options ) ;
79+
80+ if ( argv . xPerf ) {
81+ elapsedTime = getElapsedTime ( startTime ) ;
82+ }
83+
84+ const projects = { } ;
85+ const indentWidth = 4 ;
86+ await graph . traverseBreadthFirst ( async ( { project, getDependencies} ) => {
87+ const deps = getDependencies ( ) . map ( ( dep ) => {
88+ return dep . getName ( ) ;
89+ } ) ;
90+ projects [ project . getName ( ) ] = {
91+ render : function ( indentation , connectorIndices , lastChild ) {
92+ let baseString = " " . repeat ( indentation * indentWidth ) ;
93+ connectorIndices . forEach ( ( idx ) => {
94+ baseString = `${ baseString . slice ( 0 , idx ) } │${ baseString . slice ( idx + 1 ) } ` ;
95+ } ) ;
96+ const connectorString = lastChild ? "╰─" : "├─" ;
97+ console . log (
98+ `${ baseString } ${ connectorString } ${ chalk . bold ( project . getName ( ) ) } ` +
99+ chalk . dim ( `(${ project . getVersion ( ) } , ${ project . getType ( ) } ) ` ) +
100+ chalk . dim . italic ( `${ project . getPath ( ) } ` )
101+ ) ;
102+
103+ const lastIdx = deps . length - 1 ;
104+ const newConnectorIndices = [ ...connectorIndices ] ;
105+ if ( ! lastChild ) {
106+ newConnectorIndices . push ( indentation * indentWidth ) ;
107+ }
108+ deps . forEach ( ( dep , i ) => {
109+ projects [ dep ] . render ( indentation + 1 , newConnectorIndices , i === lastIdx ) ;
110+ } ) ;
111+ }
112+ } ;
113+ } ) ;
114+
115+ const projectKeys = Object . keys ( projects ) ;
116+ console . log ( chalk . bold . underline ( `Dependencies (${ projectKeys . length } ):` ) ) ;
117+ projects [ projectKeys [ 0 ] ] . render ( 0 , [ ] , true ) ;
118+ console . log ( "" ) ;
119+
120+ const extensions = Object . entries ( graph . getAllExtensions ( ) ) ;
121+ console . log ( chalk . bold . underline ( `Extensions (${ extensions . length } ):` ) ) ;
122+ if ( extensions . length ) {
123+ extensions . forEach ( ( extension ) => {
124+ console . log (
125+ `${ " " . repeat ( indentWidth ) } ├─ ${ extension . getName ( ) } ` +
126+ chalk . dim ( `(${ extension . getVersion ( ) } , ${ extension . getType ( ) } ) ` ) +
127+ chalk . dim . italic ( `${ extension . getPath ( ) } ` ) ) ;
128+ } ) ;
129+ } else {
130+ console . log ( chalk . italic ( `None` ) ) ;
131+ }
63132 } else {
64- projectTree = await normalizer . generateDependencyTree ( options ) ;
133+ let projectTree ;
134+ if ( argv . full ) {
135+ projectTree = await normalizer . generateProjectTree ( options ) ;
136+ } else {
137+ projectTree = await normalizer . generateDependencyTree ( options ) ;
138+ }
139+ if ( argv . xPerf ) {
140+ elapsedTime = getElapsedTime ( startTime ) ;
141+ }
142+
143+
144+ const output = argv . json ? JSON . stringify ( projectTree , null , 4 ) : treeify . asTree ( projectTree , true ) ;
145+ console . log ( output ) ;
65146 }
66147
67- const output = argv . json ? JSON . stringify ( projectTree , null , 4 ) : treeify . asTree ( projectTree , true ) ;
68- console . log ( output ) ;
148+ if ( argv . xPerf ) {
149+ console . log ( "" ) ;
150+ console . log ( chalk . red ( `Graph generation took ${ elapsedTime } ` ) ) ;
151+ }
69152} ;
70153
154+ function getElapsedTime ( startTime ) {
155+ const timeDiff = process . hrtime ( startTime ) ;
156+ const prettyHrtime = require ( "pretty-hrtime" ) ;
157+ return prettyHrtime ( timeDiff ) ;
158+ }
71159module . exports = tree ;
0 commit comments