1- import nodeify from 'nodeify-ts ' ;
2- import * as child_process from 'child_process' ;
3- const execFile = child_process . execFile ;
1+ import * as child_process from 'child_process ' ;
2+
3+ import nodeify from 'nodeify-ts' ;
44
5+ const execFile = child_process . execFile ;
6+ const exec = child_process . exec ;
57
68const extractResult = ( result : Result ) : Result => {
79 try {
@@ -22,64 +24,78 @@ export class Aws {
2224 } ) { }
2325
2426 public command ( command : string , callback ?: ( err : any , data : any ) => void ) : Promise < any > {
25-
26-
27- const promise = Promise . resolve ( ) . then ( ( ) => {
28-
29-
30- const env_vars = ( 'HOME PATH AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY ' +
31- 'AWS_SESSION_TOKEN AWS_DEFAULT_REGION ' +
32- 'AWS_DEFAULT_PROFILE AWS_CONFIG_FILE' ) . split ( ' ' ) ;
33-
34-
35- const env = env_vars . reduce ( ( result : any , value : string ) => {
36- if ( process . env [ value ] ) {
37- result [ value ] = process . env [ value ] ;
38- }
39- return result ;
40- } , { } ) ;
4127
42- env [ 'DEBUG' ] = '' ;
28+ const execCommand = `${ this . options . cliPath } ${ command } ` ;
29+
30+ const env_vars = ( 'HOME PATH AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY ' +
31+ 'AWS_SESSION_TOKEN AWS_DEFAULT_REGION ' +
32+ 'AWS_DEFAULT_PROFILE AWS_CONFIG_FILE' ) . split ( ' ' ) ;
4333
44- if ( this . options . accessKey ) {
45- env [ 'AWS_ACCESS_KEY_ID' ] = this . options . accessKey ;
46- }
4734
48- if ( this . options . secretKey ) {
49- env [ 'AWS_SECRET_ACCESS_KEY' ] = this . options . secretKey ;
35+ const env = env_vars . reduce ( ( result : any , value : string ) => {
36+ if ( process . env [ value ] ) {
37+ result [ value ] = process . env [ value ] ;
5038 }
51-
52- if ( this . options . sessionToken ) {
53- env [ 'AWS_SESSION_TOKEN' ] = this . options . sessionToken ;
54- }
55-
56- const execOptions = {
57- cwd : this . options . currentWorkingDirectory ,
58- env : env ,
59- maxBuffer : 200 * 1024 * 1024 ,
60- } ;
61-
62- //console.log('exec options =', execOptions);
63- //console.log('options.cliPath =', this.options.cliPath);
64- let cmd = [ ...command . split ( ' ' ) ] ;
65- cmd = cmd . filter ( v => v . length > 0 ) ;
66- //console.log('cmd2 = ', cmd);
67-
68- return new Promise < { stderr : string , stdout : string } > ( ( resolve , reject ) => {
69- execFile ( this . options . cliPath , cmd , execOptions , ( error : Error | null , stdout : string , stderr : string ) => {
70- if ( error ) {
71- const message = `error: '${ error } ' stdout = '${ stdout } ' stderr = '${ stderr } '` ;
72- //console.error(message);
73- reject ( message ) ;
74- }
75- //console.log(`stdout: ${stdout}`);
76- resolve ( { stderr : stderr , stdout : stdout } ) ;
77- } ) ;
39+ return result ;
40+ } , { } ) ;
41+
42+ env [ 'DEBUG' ] = '' ;
43+
44+ if ( this . options . accessKey ) {
45+ env [ 'AWS_ACCESS_KEY_ID' ] = this . options . accessKey ;
46+ }
47+
48+ if ( this . options . secretKey ) {
49+ env [ 'AWS_SECRET_ACCESS_KEY' ] = this . options . secretKey ;
50+ }
51+
52+ if ( this . options . sessionToken ) {
53+ env [ 'AWS_SESSION_TOKEN' ] = this . options . sessionToken ;
54+ }
55+
56+ const execOptions = {
57+ cwd : this . options . currentWorkingDirectory ,
58+ env : env ,
59+ maxBuffer : 200 * 1024 * 1024 ,
60+ } ;
61+
62+
63+ const promise = Promise . resolve ( ) . then ( ( ) => {
64+
65+
66+ return new Promise < { stderr : string , stdout : string } > ( ( resolve , reject ) => {
67+
68+ if ( command . indexOf ( '"' ) < 0 ) {
69+ let cmd = [ ...command . split ( ' ' ) ] ;
70+ cmd = cmd . filter ( v => v . length > 0 ) ;
71+ //console.log('execFile');
72+ execFile ( this . options . cliPath , cmd , execOptions , ( error : Error | null , stdout : string , stderr : string ) => {
73+ if ( error ) {
74+ const message = `error: '${ error } ' stdout = '${ stdout } ' stderr = '${ stderr } '` ;
75+ //console.error(message);
76+ reject ( message ) ;
77+ }
78+ //console.log(`stdout: ${stdout}`);
79+ resolve ( { stderr : stderr , stdout : stdout } ) ;
80+ } ) ;
81+ } else {
82+ //console.log('exec');
83+ exec ( execCommand , execOptions , ( error : Error | null , stdout : string , stderr : string ) => {
84+ if ( error ) {
85+ const message = `error: '${ error } ' stdout = '${ stdout } ' stderr = '${ stderr } '` ;
86+ //console.error(message);
87+ reject ( message ) ;
88+ }
89+ //console.log(`stdout: ${stdout}`);
90+ resolve ( { stderr : stderr , stdout : stdout } ) ;
91+ } ) ;
92+ }
7893 } ) ;
94+
7995 } ) . then ( ( data : { stderr : string , stdout : string } ) => {
8096
8197 const result : Result = {
82- command,
98+ command : execCommand ,
8399 error : data . stderr ,
84100 object : null ,
85101 raw : data . stdout ,
0 commit comments