@@ -496,54 +496,54 @@ function jsonToGo(json, options = {}) {
496496 }
497497}
498498
499- if ( typeof module != 'undefined' ) {
500- if ( ! module . parent ) {
501- let filename = null
502-
503- function jsonToGoWithErrorHandling ( json ) {
504- const output = jsonToGo ( json )
505- if ( output . error ) {
506- console . error ( output . error )
507- process . exitCode = 1
508- }
509- process . stdout . write ( output . go )
499+ if ( typeof module === 'undefined' || ! module . parent ) {
500+ let filename = null
501+
502+ function jsonToGoWithErrorHandling ( json ) {
503+ const output = jsonToGo ( json )
504+ if ( output . error ) {
505+ console . error ( output . error )
506+ process . exitCode = 1
510507 }
508+ process . stdout . write ( output . go )
509+ }
511510
512- process . argv . forEach ( ( val , index ) => {
513- if ( index < 2 )
514- return
515-
516- if ( ! val . startsWith ( '-' ) ) {
517- filename = val
518- return
519- }
520-
521- const argument = val . replace ( / - / g, '' )
522- if ( argument === "big" )
523- console . warn ( `Warning: The argument '${ argument } ' has been deprecated and has no effect anymore` )
524- else {
525- console . error ( `Unexpected argument ${ val } received` )
526- process . exit ( 1 )
527- }
528- } )
511+ process . argv . forEach ( ( val , index ) => {
512+ if ( index < 2 )
513+ return
529514
530- if ( filename ) {
531- const fs = require ( 'fs' ) ;
532- const json = fs . readFileSync ( filename , 'utf8' ) ;
533- jsonToGoWithErrorHandling ( json )
515+ if ( ! val . startsWith ( '-' ) ) {
516+ filename = val
517+ return
534518 }
535519
536- if ( ! filename ) {
537- bufs = [ ]
538- process . stdin . on ( 'data' , function ( buf ) {
539- bufs . push ( buf )
540- } )
541- process . stdin . on ( 'end' , function ( ) {
542- const json = Buffer . concat ( bufs ) . toString ( 'utf8' )
543- jsonToGoWithErrorHandling ( json )
544- } )
520+ const argument = val . replace ( / - / g, '' )
521+ if ( argument === "big" )
522+ console . warn ( `Warning: The argument '${ argument } ' has been deprecated and has no effect anymore` )
523+ else {
524+ console . error ( `Unexpected argument ${ val } received` )
525+ process . exit ( 1 )
545526 }
546- } else {
547- module . exports = jsonToGo
527+ } )
528+
529+ if ( filename ) {
530+ const fs = require ( 'fs' ) ;
531+ const json = fs . readFileSync ( filename , 'utf8' ) ;
532+ jsonToGoWithErrorHandling ( json )
533+ }
534+
535+ if ( ! filename ) {
536+ bufs = [ ]
537+ process . stdin . on ( 'data' , function ( buf ) {
538+ bufs . push ( buf )
539+ } )
540+ process . stdin . on ( 'end' , function ( ) {
541+ const json = Buffer . concat ( bufs ) . toString ( 'utf8' )
542+ jsonToGoWithErrorHandling ( json )
543+ } )
548544 }
549545}
546+
547+ if ( typeof module !== 'undefined' ) {
548+ module . exports = jsonToGo
549+ }
0 commit comments