@@ -64,9 +64,14 @@ exports.builder = {
6464 alias : 'o' ,
6565 description : 'Open deployed project in browser after upload' ,
6666 } ,
67+ verbose : {
68+ alias : 'v' ,
69+ description : 'Verbose mode; will output more information' ,
70+ } ,
6771} ;
6872exports . handler = async ( args = { } ) => {
6973 const deployToken = args . token ;
74+ const { verbose} = args ;
7075
7176 // exit if not logged in and no token provided
7277 if ( ! deployToken && ! isLoggedIn ( ) ) {
@@ -100,6 +105,8 @@ exports.handler = async (args = {}) => {
100105 } catch ( e ) {
101106 const defaultConfig = JSON . stringify ( { name : folderName } ) ;
102107 fs . writeFileSync ( configPath , defaultConfig , 'utf-8' ) ;
108+ // if in verbose mode - log config creation
109+ verbose && console . log ( 'Create new default config:' , defaultConfig ) ;
103110 }
104111
105112 // show loader
@@ -119,6 +126,8 @@ exports.handler = async (args = {}) => {
119126 const tarStream = tar . pack ( workdir , {
120127 ignore : name => ig . ignores ( name ) ,
121128 } ) ;
129+ // if in verbose mode - log ignores
130+ verbose && console . log ( '\nIgnoring following paths:' , ignores ) ;
122131
123132 let token = userConfig . token ;
124133 if ( deployToken ) {
@@ -133,7 +142,10 @@ exports.handler = async (args = {}) => {
133142
134143 // pipe stream to remote
135144 try {
136- const res = await streamToResponse ( { tarStream, remoteUrl, options} ) ;
145+ const res = await streamToResponse ( { tarStream, remoteUrl, options, verbose} ) ;
146+ // if in verbose mode - log response
147+ verbose && console . log ( '\nGot response from server:' , res ) ;
148+ // check deployments
137149 if ( ! res . deployments || ! res . deployments . length ) {
138150 throw new Error ( 'Something went wrong!' ) ;
139151 }
@@ -168,13 +180,21 @@ exports.handler = async (args = {}) => {
168180 return ;
169181 }
170182
171- const reason = e . response . result ? e . response . result . error : e . toString ( ) ;
172- console . log ( chalk . red ( 'Error deploying project:' ) , reason ) ;
183+ const response = e . response || { } ;
184+ const reason = response . result ? response . result . error : e . toString ( ) ;
185+ console . log ( chalk . red ( 'Error deploying project:' ) , reason || 'Unknown reason' ) ;
173186 console . log ( 'Build log:\n' ) ;
174- e . response . result . log
175- . filter ( l => l !== undefined )
176- . map ( l => l . trim ( ) )
177- . filter ( l => l && l . length > 0 )
178- . forEach ( line => console . log ( line ) ) ;
187+ response . result
188+ ? ( response . result . log || [ 'No log available' ] )
189+ . filter ( l => l !== undefined )
190+ . map ( l => l . trim ( ) )
191+ . filter ( l => l && l . length > 0 )
192+ . forEach ( line => console . log ( line ) )
193+ : console . log ( 'No log available' ) ;
194+
195+ // if in verbose mode - log original error and response
196+ verbose && console . log ( '' ) ;
197+ verbose && console . log ( 'Original error:' , e ) ;
198+ verbose && console . log ( 'Original response:' , e . response ) ;
179199 }
180200} ;
0 commit comments