File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 11import { flags } from "@oclif/command"
22import chalk from "chalk"
33
4+ const JSON_INDENT = 2
5+
46export enum DiffTypes {
57 ALL = 'all' ,
68 ADDED = 'added' ,
79 REMOVED = 'removed' ,
10+ JSON = 'json' ,
811}
912
1013export interface DiffList {
@@ -30,11 +33,24 @@ export const DIFF_FLAGS = {
3033 } ) ,
3134}
3235
36+ function stringify ( object : object ) {
37+ return JSON . stringify (
38+ object ,
39+ ( _key , value ) => value instanceof Map ? Object . fromEntries ( value ) : value ,
40+ JSON_INDENT ,
41+ )
42+ }
43+
3344export function printDiffList (
3445 diffs : DiffList [ ] ,
3546 type : DiffTypes ,
3647 callback : ( message ?: string ) => void ,
3748) {
49+ if ( type === DiffTypes . JSON ) {
50+ callback ( stringify ( diffs ) )
51+ return
52+ }
53+
3854 let showAdded = [ DiffTypes . ALL , DiffTypes . ADDED ] . includes ( type )
3955 let showRemoved = [ DiffTypes . ALL , DiffTypes . REMOVED ] . includes ( type )
4056
@@ -57,6 +73,11 @@ export function printDiffMap(
5773 type : DiffTypes ,
5874 callback : ( message ?: string ) => void ,
5975) {
76+ if ( type === DiffTypes . JSON ) {
77+ callback ( stringify ( diffs ) )
78+ return
79+ }
80+
6081 let showAddedAndModified = [ DiffTypes . ALL , DiffTypes . ADDED ] . includes ( type )
6182 let showRemoved = [ DiffTypes . ALL , DiffTypes . REMOVED ] . includes ( type )
6283
You can’t perform that action at this time.
0 commit comments