@@ -5,60 +5,55 @@ const cli = require(`commander`)
55
66const { readFileSync } = require ( 'fs' )
77
8- async function main ( ) {
9-
10- cli
11- . version ( `0.1.0` )
12- . usage ( `[options] <file1> <file2>` )
13- . on ( `--help` , ( ) => {
14- console . log ( `` )
15- console . log ( ` Example:` )
16- console . log ( `` )
17- console . log ( ` $ splitdiff file1 file2` )
18- console . log ( ` $ git diff --no-pager file1 file2 | splitdiff` )
19- console . log ( `` )
8+ cli
9+ . version ( `0.1.0` )
10+ . usage ( `[options] <file1> <file2>` )
11+ . on ( `--help` , ( ) => {
12+ console . log ( `` )
13+ console . log ( ` Example:` )
14+ console . log ( `` )
15+ console . log ( ` $ splitdiff file1 file2` )
16+ console . log ( ` $ git diff --no-pager file1 file2 | splitdiff` )
17+ console . log ( `` )
18+ } )
19+ . parse ( process . argv )
20+
21+ try {
22+
23+ if ( cli . args . length < 2 ) {
24+
25+ process . stdin . setEncoding ( 'utf8' )
26+
27+ let data = ''
28+
29+ process . stdin . on ( 'readable' , ( ) => {
30+ const chunk = process . stdin . read ( )
31+ if ( chunk !== null ) {
32+ data += chunk
33+ }
34+ } )
35+ process . stdin . on ( 'end' , ( ) => {
36+ if ( data !== '' ) {
37+ console . log ( splitPatch ( data , { } ) )
38+ }
2039 } )
21- . parse ( process . argv )
22-
23- try {
24-
25- if ( cli . args . length < 2 ) {
26-
27- process . stdin . setEncoding ( 'utf8' )
28-
29- let data = ''
3040
31- process . stdin . on ( 'readable' , ( ) => {
32- const chunk = process . stdin . read ( )
33- if ( chunk !== null ) {
34- data += chunk
41+ }
42+ else {
43+ console . log (
44+ splitDiffStrings (
45+ cli . args [ 0 ] + `\n\n` + readFileSync ( cli . args [ 0 ] , { encoding : `utf8` } ) ,
46+ cli . args [ 1 ] + `\n\n` + readFileSync ( cli . args [ 1 ] , { encoding : `utf8` } ) ,
47+ {
48+ diffType : `diffLines` ,
49+ lineNumbers : true ,
50+ lineOffset : 2
3551 }
36- } )
37- process . stdin . on ( 'end' , ( ) => {
38- if ( data !== '' ) {
39- console . log ( splitPatch ( data , { } ) )
40- }
41- } )
42-
43- }
44- else {
45- console . log (
46- splitDiffStrings (
47- cli . args [ 0 ] + `\n\n` + readFileSync ( cli . args [ 0 ] , { encoding : `utf8` } ) ,
48- cli . args [ 1 ] + `\n\n` + readFileSync ( cli . args [ 1 ] , { encoding : `utf8` } ) ,
49- {
50- diffType : `diffLines` ,
51- lineNumbers : true ,
52- lineOffset : 2
53- }
54- )
5552 )
56- }
57-
58- } catch ( error ) {
59- console . log ( `splitdiff:` , error )
60- process . exit ( 1 )
53+ )
6154 }
62- }
6355
64- main ( )
56+ } catch ( error ) {
57+ console . log ( `splitdiff:` , error )
58+ process . exit ( 1 )
59+ }
0 commit comments