@@ -10,7 +10,7 @@ import {
1010 success ,
1111 updateStatus ,
1212} from "@cloudflare/cli" ;
13- import { bold , brandColor , dim , green , red } from "@cloudflare/cli/colors" ;
13+ import { bold , brandColor , dim , green } from "@cloudflare/cli/colors" ;
1414import {
1515 ApiError ,
1616 ApplicationsService ,
@@ -23,9 +23,9 @@ import {
2323} from "@cloudflare/containers-shared" ;
2424import { cleanForInstanceType , promiseSpinner } from "../cloudchamber/common" ;
2525import {
26- createLine ,
2726 diffLines ,
2827 printLine ,
28+ renderDiff ,
2929 sortObjectRecursive ,
3030 stripUndefined ,
3131} from "../cloudchamber/helpers/diff" ;
@@ -380,78 +380,7 @@ export async function apply(
380380 `${ brandColor . underline ( "EDIT" ) } ${ application . name } ` ,
381381 false
382382 ) ;
383-
384- let printedLines : string [ ] = [ ] ;
385- let printedDiff = false ;
386- // prints the lines we accumulated to bring context to the edited line
387- const printContext = ( ) => {
388- let index = 0 ;
389- for ( let i = printedLines . length - 1 ; i >= 0 ; i -- ) {
390- if ( printedLines [ i ] . trim ( ) . startsWith ( "[" ) ) {
391- log ( "" ) ;
392- index = i ;
393- break ;
394- }
395- }
396-
397- for ( let i = index ; i < printedLines . length ; i ++ ) {
398- log ( printedLines [ i ] ) ;
399- if ( printedLines . length - i > 2 ) {
400- i = printedLines . length - 2 ;
401- printLine ( dim ( "..." ) , " " ) ;
402- }
403- }
404-
405- printedLines = [ ] ;
406- } ;
407-
408- // go line by line and print diff results
409- for ( const lines of results ) {
410- const trimmedLines = ( lines . value ?? "" )
411- . split ( "\n" )
412- . map ( ( e ) => e . trim ( ) )
413- . filter ( ( e ) => e !== "" ) ;
414-
415- for ( const l of trimmedLines ) {
416- if ( lines . added ) {
417- printContext ( ) ;
418- if ( l . startsWith ( "[" ) ) {
419- printLine ( "" ) ;
420- }
421-
422- printedDiff = true ;
423- printLine ( l , green ( "+ " ) ) ;
424- } else if ( lines . removed ) {
425- printContext ( ) ;
426- if ( l . startsWith ( "[" ) ) {
427- printLine ( "" ) ;
428- }
429-
430- printedDiff = true ;
431- printLine ( l , red ( "- " ) ) ;
432- } else {
433- // if we had printed a diff before this line, print a little bit more
434- // so the user has a bit more context on where the edit happens
435- if ( printedDiff ) {
436- let printDots = false ;
437- if ( l . startsWith ( "[" ) ) {
438- printLine ( "" ) ;
439- printDots = true ;
440- }
441-
442- printedDiff = false ;
443- printLine ( l , " " ) ;
444- if ( printDots ) {
445- printLine ( dim ( "..." ) , " " ) ;
446- }
447- continue ;
448- }
449-
450- printedLines . push ( createLine ( l , " " ) ) ;
451- }
452- }
453- }
454-
383+ renderDiff ( results ) ;
455384 if ( appConfigNoDefaults . rollout_kind !== "none" ) {
456385 actions . push ( {
457386 action : "modify" ,
0 commit comments