@@ -114,7 +114,7 @@ const args = parseArgs(process.argv.slice(2));
114114
115115if ( process . stdin . isTTY ) {
116116 // If the script is run with a TTY, process the command-line arguments
117- run ( args . kind , args . value , args . output , args . countryCodes , args . phoneNumbers , args . download , args . filename ) ;
117+ run ( args . kind , args . value , args . output , args . countryCodes , args . phoneNumbers , args . download , args . filename , '\n' ) ;
118118} else {
119119 // If data is being piped into the script, capture it
120120 let content = '' ;
@@ -126,16 +126,16 @@ if (process.stdin.isTTY) {
126126 content = content . trim ( ) ;
127127
128128 if ( ! content ) {
129- run ( args . kind , args . value , args . output , args . countryCodes , args . phoneNumbers , args . download , args . filename ) ;
129+ run ( args . kind , args . value , args . output , args . countryCodes , args . phoneNumbers , args . download , args . filename , '' ) ;
130130 } else {
131- run ( args . kind , content , args . output , args . countryCodes , args . phoneNumbers , args . download , args . filename ) ;
131+ run ( args . kind , content , args . output , args . countryCodes , args . phoneNumbers , args . download , args . filename , '' ) ;
132132 }
133133 } ) ;
134134}
135135
136- async function run ( kind , value , output , countryCodes , phoneNumbers , download , filename ) {
136+ async function run ( kind , value , output , countryCodes , phoneNumbers , download , filename , newline ) {
137137 if ( ! value && kind !== 'version' ) {
138- process . stderr . write ( 'Value is required\n' ) ;
138+ process . stderr . write ( 'Value is required' + newline ) ;
139139 process . exit ( 1 ) ;
140140 }
141141
@@ -148,44 +148,44 @@ async function run(kind, value, output, countryCodes, phoneNumbers, download, fi
148148 const packageJsonPath = path . join ( __dirname , '../package.json' ) ;
149149 const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf8' ) ) ;
150150 const version = packageJson . version ;
151- process . stdout . write ( version ) ;
151+ process . stdout . write ( version + newline ) ;
152152 process . exit ( 0 ) ;
153153 } else if ( kind === 'encode' || kind === 'e' ) {
154154 if ( download ) {
155155 const filenm = await txms . downloadMessage ( value , filename ? filename : undefined , output ) ;
156- process . stdout . write ( `TxMS file was downloaded as "${ filenm } ".\n ` ) ;
156+ process . stdout . write ( `TxMS file was downloaded as "${ filenm } ".${ newline } ` ) ;
157157 } else {
158158 const encoded = txms . encode ( value ) ;
159- process . stdout . write ( encoded ) ;
159+ process . stdout . write ( encoded + newline ) ;
160160 }
161161 process . exit ( 0 ) ;
162162 } else if ( kind === 'decode' || kind === 'd' ) {
163163 const decoded = txms . decode ( value ) ;
164- process . stdout . write ( decoded ) ;
164+ process . stdout . write ( decoded + newline ) ;
165165 process . exit ( 0 ) ;
166166 } else if ( kind === 'getendpoint' || kind === 'g' ) {
167167 const endpoint = txms . getEndpoint ( value , countryCodes ) ;
168168 let endpointString = Object . keys ( endpoint ) . map ( key => {
169169 const numbers = endpoint [ key ] . join ( ',' ) ;
170170 return `${ key } :${ numbers } ` ;
171171 } ) . join ( ';' ) ;
172- process . stdout . write ( endpointString ) ;
172+ process . stdout . write ( endpointString + newline ) ;
173173 process . exit ( 0 ) ;
174174 } else if ( kind === 'sms' ) {
175175 const message = txms . encode ( value ) ;
176176 const sms = txms . sms ( phoneNumbers ? phoneNumbers . split ( ',' ) : true , message ) ;
177- process . stdout . write ( sms ) ;
177+ process . stdout . write ( sms + newline ) ;
178178 process . exit ( 0 ) ;
179179 } else if ( kind === 'mms' ) {
180180 const message = txms . encode ( value ) ;
181181 const mms = txms . mms ( phoneNumbers ? phoneNumbers . split ( ',' ) : true , message ) ;
182- process . stdout . write ( mms ) ;
182+ process . stdout . write ( mms + newline ) ;
183183 process . exit ( 0 ) ;
184184 } else {
185- throw new Error ( 'Invalid type specified.' ) ;
185+ throw new Error ( 'Invalid type specified.' + newline ) ;
186186 }
187187 } catch ( err ) {
188- process . stderr . write ( `${ err . message } \n ` ) ;
188+ process . stderr . write ( `${ err . message } ${ newline } ` ) ;
189189 process . exit ( 1 ) ;
190190 }
191191}
0 commit comments