@@ -11,7 +11,7 @@ const { CliUx } = require('@oclif/core');
1111const { extractPhrases } = require ( '../api/extract' ) ;
1212const { uploadPhrases, pollJob } = require ( '../api/upload' ) ;
1313const { mergePayload } = require ( '../api/merge' ) ;
14- const { stringToArray } = require ( '../api/utils' ) ;
14+ const { stringToArray, normalizeArray } = require ( '../api/utils' ) ;
1515
1616/**
1717 * Test if path is folder
@@ -162,37 +162,39 @@ class PushCommand extends Command {
162162
163163 this . log ( '' ) ;
164164
165- // --------- helpers to print verbose groups ----------
166- const normalizeArray = ( maybeArr ) => {
167- if ( ! maybeArr ) return [ ] ;
168- if ( Array . isArray ( maybeArr ) ) return maybeArr ;
169- if ( typeof maybeArr === 'string' ) {
170- try {
171- const parsed = JSON . parse ( maybeArr ) ;
172- return Array . isArray ( parsed ) ? parsed : [ ] ;
173- } catch ( _ ) {
174- return [ ] ;
175- }
176- }
177- return [ ] ;
178- } ;
179-
180- const printVerboseGroup = ( label , items ) => {
165+ /**
166+ * Print detailed verbose output for a group of items
167+ *
168+ * @param {String } label - Label for the group
169+ * @param {Array } items - Items to display
170+ * @param {String } groupColor - Color for the group label
171+ */
172+ const printVerboseGroup = ( label , items , groupColor = 'white' ) => {
181173 const arr = normalizeArray ( items ) ;
182174 if ( ! arr . length ) return ;
183- this . log ( ` ${ label } : ${ arr . length . toString ( ) . green } ` ) ;
175+ this . log ( ` ${ label } : ${ arr . length } ` [ groupColor ] ) ;
184176 arr . forEach ( ( item ) => {
185- const string = item ?. string ?? '' ;
186- const key = item ?. key ?? '' ;
187- const occurrences = Array . isArray ( item ?. occurrences ) ? item . occurrences : [ ] ;
188- const context = Array . isArray ( item ?. context ) ? item . context : [ ] ;
189- this . log ( ` └─ ${ JSON . stringify ( string ) } ` . white ) ;
190- this . log ( ` └─ key: ${ JSON . stringify ( key ) } ` . gray ) ;
191- this . log ( ` └─ occurrences: ${ JSON . stringify ( occurrences ) } ` . gray ) ;
192- this . log ( ` └─ context: ${ JSON . stringify ( context ) } ` . gray ) ;
177+ const {
178+ key = '' ,
179+ string = '' ,
180+ context = [ ] ,
181+ occurrences = [ ] ,
182+ } = item ;
183+ if ( string ) {
184+ if ( key !== string ) {
185+ this . log ( ` └─ ${ key } : ${ string . underline } ` ) ;
186+ } else {
187+ this . log ( ` └─ ${ string . underline } ` ) ;
188+ }
189+ if ( occurrences . length ) {
190+ this . log ( ` └─ occurrences: ${ occurrences . join ( ', ' ) } ` . gray ) ;
191+ }
192+ if ( context . length ) {
193+ this . log ( ` └─ context: ${ context } ` . gray ) ;
194+ }
195+ }
193196 } ) ;
194197 } ;
195- // ----------------------------------------------------------------------
196198
197199 CliUx . ux . action . start ( uploadMessage , '' , { stdout : true } ) ;
198200 try {
@@ -240,27 +242,28 @@ class PushCommand extends Command {
240242 if ( status === 'completed' ) {
241243 CliUx . ux . action . stop ( 'Success' . green ) ;
242244 this . log ( `${ '✓' . green } Successfully pushed strings to Transifex:` ) ;
243- if ( res . verbose ) {
244- printVerboseGroup ( 'Created strings' , res . verbose . created ) ;
245- printVerboseGroup ( 'Updated strings' , res . verbose . updated ) ;
246- printVerboseGroup ( 'Skipped strings' , res . verbose . skipped ) ;
247- printVerboseGroup ( 'Deleted strings' , res . verbose . deleted ) ;
248- printVerboseGroup ( 'Failed strings' , res . verbose . failed ) ;
245+
246+ if ( res . verbose && flags . verbose ) {
247+ printVerboseGroup ( 'Created strings' , res . verbose . created , 'green' ) ;
248+ printVerboseGroup ( 'Updated strings' , res . verbose . updated , 'yellow' ) ;
249+ printVerboseGroup ( 'Deleted strings' , res . verbose . deleted , 'red' ) ;
250+ printVerboseGroup ( 'Skipped strings' , res . verbose . skipped , 'green' ) ;
251+ printVerboseGroup ( 'Failed strings' , res . verbose . failed , 'red' ) ;
249252 } else {
250253 if ( res . created > 0 ) {
251- this . log ( ` Created strings: ${ res . created . toString ( ) . green } ` ) ;
254+ this . log ( ` Created strings: ${ res . created } ` . green ) ;
252255 }
253256 if ( res . updated > 0 ) {
254- this . log ( ` Updated strings: ${ res . updated . toString ( ) . green } ` ) ;
255- }
256- if ( res . skipped > 0 ) {
257- this . log ( ` Skipped strings: ${ res . skipped . toString ( ) . green } ` ) ;
257+ this . log ( ` Updated strings: ${ res . updated } ` . yellow ) ;
258258 }
259259 if ( res . deleted > 0 ) {
260- this . log ( ` Deleted strings: ${ res . deleted . toString ( ) . green } ` ) ;
260+ this . log ( ` Deleted strings: ${ res . deleted } ` . red ) ;
261+ }
262+ if ( res . skipped > 0 ) {
263+ this . log ( ` Skipped strings: ${ res . skipped } ` . green ) ;
261264 }
262265 if ( res . failed > 0 ) {
263- this . log ( ` Failed strings: ${ res . failed . toString ( ) . red } ` ) ;
266+ this . log ( ` Failed strings: ${ res . failed } ` . red ) ;
264267 }
265268 }
266269 } else {
0 commit comments