@@ -35,6 +35,11 @@ cacheCommand.builder = function(cli) {
3535 "Remove all cached UI5 data without confirmation (CI mode)" ) ;
3636} ;
3737
38+ const LABEL_FRAMEWORK = "UI5 Framework packages" ;
39+ const LABEL_BUILD = "Build cache (DB)" ;
40+ // Pad labels to equal width for two-column alignment
41+ const LABEL_WIDTH = Math . max ( LABEL_FRAMEWORK . length , LABEL_BUILD . length ) ;
42+
3843/**
3944 * Format a byte size as a human-readable string.
4045 *
@@ -52,6 +57,26 @@ function formatSize(bytes) {
5257 return `${ ( bytes / ( 1024 * 1024 * 1024 ) ) . toFixed ( 1 ) } GB` ;
5358}
5459
60+ /**
61+ * Format a count with its singular/plural word, e.g. "340 files" or "1 file".
62+ *
63+ * @param {number } count
64+ * @returns {string }
65+ */
66+ function formatFileCount ( count ) {
67+ return `${ count } ${ count === 1 ? "file" : "files" } ` ;
68+ }
69+
70+ /**
71+ * Pad a label to the shared column width.
72+ *
73+ * @param {string } label
74+ * @returns {string }
75+ */
76+ function padLabel ( label ) {
77+ return label . padEnd ( LABEL_WIDTH ) ;
78+ }
79+
5580async function handleCache ( argv ) {
5681 // Resolve UI5 data directory
5782 let ui5DataDir = process . env . UI5_DATA_DIR ;
@@ -76,30 +101,29 @@ async function handleCache(argv) {
76101 }
77102
78103 // Check what items exist before cleaning (orchestrate both domains)
79- const items = [ ] ;
80104 const frameworkInfo = await frameworkCache . getCacheInfo ( ui5DataDir ) ;
81- if ( frameworkInfo ) {
82- items . push ( frameworkInfo ) ;
83- }
84105 const buildInfo = await CacheManager . getCacheInfo ( ui5DataDir ) ;
85- if ( buildInfo ) {
86- items . push ( buildInfo ) ;
87- }
88106
89- if ( items . length === 0 ) {
107+ if ( ! frameworkInfo && ! buildInfo ) {
90108 process . stderr . write ( "Nothing to clean\n" ) ;
91109 return ;
92110 }
93111
94112 // Display items that will be removed
95- process . stderr . write ( chalk . bold ( "\nThe following items from cache will be removed:\n" ) ) ;
96- let totalSize = 0 ;
97- for ( const item of items ) {
98- totalSize += item . size ;
99- const sizeStr = item . size > 0 ? ` (${ formatSize ( item . size ) } )` : "" ;
100- process . stderr . write ( ` ${ chalk . yellow ( "•" ) } ${ item . path } ${ sizeStr } \n` ) ;
113+ process . stderr . write ( chalk . bold ( "\nThe following cached data will be removed:\n \n" ) ) ;
114+ if ( frameworkInfo ) {
115+ const detail = formatFileCount ( frameworkInfo . count ) ;
116+ process . stderr . write (
117+ ` ${ chalk . yellow ( "•" ) } ${ padLabel ( LABEL_FRAMEWORK ) } ${ frameworkInfo . path } (${ detail } )\n`
118+ ) ;
101119 }
102- process . stderr . write ( chalk . bold ( `\nTotal: ${ formatSize ( totalSize ) } \n\n` ) ) ;
120+ if ( buildInfo ) {
121+ const detail = buildInfo . size > 0 ? formatSize ( buildInfo . size ) : "" ;
122+ process . stderr . write (
123+ ` ${ chalk . yellow ( "•" ) } ${ padLabel ( LABEL_BUILD ) } ${ buildInfo . path } (${ detail } )\n`
124+ ) ;
125+ }
126+ process . stderr . write ( "\n" ) ;
103127
104128 // Ask for confirmation (skip with --yes)
105129 if ( ! argv . yes ) {
@@ -115,27 +139,34 @@ async function handleCache(argv) {
115139 }
116140
117141 // Perform the actual cleanup (orchestrate both domains)
118- const removed = [ ] ;
119142 const frameworkResult = await frameworkCache . cleanCache ( ui5DataDir ) ;
143+ const buildResult = await CacheManager . cleanCache ( ui5DataDir ) ;
144+
145+ process . stderr . write ( "\n" ) ;
120146 if ( frameworkResult ) {
121- removed . push ( frameworkResult ) ;
147+ const detail = formatFileCount ( frameworkResult . count ) ;
148+ process . stderr . write (
149+ `${ chalk . green ( "✓" ) } Removed ${ chalk . bold ( LABEL_FRAMEWORK ) } ` +
150+ ` (${ frameworkResult . path } · ${ detail } )\n`
151+ ) ;
122152 }
123- const buildResult = await CacheManager . cleanCache ( ui5DataDir ) ;
124153 if ( buildResult ) {
125- removed . push ( buildResult ) ;
154+ const detail = buildResult . size > 0 ? formatSize ( buildResult . size ) : "" ;
155+ process . stderr . write (
156+ `${ chalk . green ( "✓" ) } Removed ${ chalk . bold ( LABEL_BUILD ) } ` +
157+ ` (${ buildResult . path } ${ detail ? ` · ${ detail } ` : "" } )\n`
158+ ) ;
126159 }
127160
128- process . stderr . write ( "\n" ) ;
129- for ( const entry of removed ) {
130- const sizeStr = entry . size > 0 ? ` ( ${ formatSize ( entry . size ) } )` : "" ;
131- process . stderr . write ( ` ${ chalk . green ( "✓" ) } Removed ${ chalk . bold ( entry . path ) } ${ sizeStr } \n` ) ;
161+ // Success summary
162+ const cleaned = [ ] ;
163+ if ( frameworkResult ) {
164+ cleaned . push ( LABEL_FRAMEWORK ) ;
132165 }
133-
134- const totalRemoved = removed . reduce ( ( sum , entry ) => sum + entry . size , 0 ) ;
135- process . stderr . write (
136- `\n${ chalk . green ( "Success:" ) } Cleaned ${ removed . length } ${ removed . length === 1 ? "entry" : "entries" } ` +
137- ( totalRemoved > 0 ? `, freed ${ formatSize ( totalRemoved ) } ` : "" ) + "\n"
138- ) ;
166+ if ( buildResult ) {
167+ cleaned . push ( LABEL_BUILD ) ;
168+ }
169+ process . stderr . write ( `\n${ chalk . green ( "Success:" ) } Cleaned ${ cleaned . join ( " and " ) } \n` ) ;
139170}
140171
141172export default cacheCommand ;
0 commit comments