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 1
1
import { flags } from "@oclif/command"
2
2
import chalk from "chalk"
3
3
4
+ const JSON_INDENT = 2
5
+
4
6
export enum DiffTypes {
5
7
ALL = 'all' ,
6
8
ADDED = 'added' ,
7
9
REMOVED = 'removed' ,
10
+ JSON = 'json' ,
8
11
}
9
12
10
13
export interface DiffList {
@@ -30,11 +33,24 @@ export const DIFF_FLAGS = {
30
33
} ) ,
31
34
}
32
35
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
+
33
44
export function printDiffList (
34
45
diffs : DiffList [ ] ,
35
46
type : DiffTypes ,
36
47
callback : ( message ?: string ) => void ,
37
48
) {
49
+ if ( type === DiffTypes . JSON ) {
50
+ callback ( stringify ( diffs ) )
51
+ return
52
+ }
53
+
38
54
let showAdded = [ DiffTypes . ALL , DiffTypes . ADDED ] . includes ( type )
39
55
let showRemoved = [ DiffTypes . ALL , DiffTypes . REMOVED ] . includes ( type )
40
56
@@ -57,6 +73,11 @@ export function printDiffMap(
57
73
type : DiffTypes ,
58
74
callback : ( message ?: string ) => void ,
59
75
) {
76
+ if ( type === DiffTypes . JSON ) {
77
+ callback ( stringify ( diffs ) )
78
+ return
79
+ }
80
+
60
81
let showAddedAndModified = [ DiffTypes . ALL , DiffTypes . ADDED ] . includes ( type )
61
82
let showRemoved = [ DiffTypes . ALL , DiffTypes . REMOVED ] . includes ( type )
62
83
You can’t perform that action at this time.
0 commit comments