@@ -73,20 +73,16 @@ module.exports = function deployCommit(api, args, deployConfig) {
7373 fs . mkdirSync ( deployDir ) ;
7474
7575 if ( fs . statSync ( deployDir ) . isDirectory ( ) ) {
76- return runDeploy ( api , args , deployConfig , { deployDir, gitPath, gitBranch, commitHash, gitUser, currBranch, gitMessage } ) . then ( ( ) => {
77- if ( fs . existsSync ( deployDir ) ) {
78- shelljs . rm ( '-rf' , deployDir ) ;
79- }
80-
81- api . applyPluginHooks ( 'afterCommandDeploy' , { args, config : deployConfig } ) ;
82- } ) . catch ( ( ) => {
83- if ( fs . existsSync ( deployDir ) ) {
84- shelljs . rm ( '-rf' , deployDir ) ;
85- }
76+ const bSuccessful = runDeploy ( api , args , deployConfig , { deployDir, gitPath, gitBranch, commitHash, gitUser, currBranch, gitMessage } ) ;
77+ if ( ! bSuccessful ) {
8678 logger . error ( 'Fail! Check your config, please' ) ;
79+ }
80+ if ( fs . existsSync ( deployDir ) ) {
81+ shelljs . rm ( '-rf' , deployDir ) ;
82+ }
8783
88- api . applyPluginHooks ( 'afterCommandDeploy' , { args, config : deployConfig } ) ;
89- } ) ;
84+ api . applyPluginHooks ( 'afterCommandDeploy' , { args, config : deployConfig } ) ;
85+ return ;
9086 }
9187 }
9288
@@ -123,7 +119,7 @@ function runDeploy(api, args, deployConfig, { deployDir, gitPath, gitBranch, com
123119 if ( gitp === ngitp ) {
124120 // not change
125121 logger . warn ( 'NOT MODIFIED!' ) ;
126- return Promise . resolve ( ) ;
122+ return true ;
127123 }
128124 if ( ngitp ) {
129125 if ( dependencies [ MICRO_APP_CONFIG_NAME ] ) {
@@ -153,29 +149,25 @@ function runDeploy(api, args, deployConfig, { deployDir, gitPath, gitBranch, com
153149
154150 if ( ! message ) {
155151 logger . error ( 'modifyCommandDeployMessage() must be retrun { message } !!!' ) ;
156- return Promise . reject ( ) ;
152+ return false ;
157153 }
158154
159- return new Promise ( ( resolve , reject ) => {
160- const spinner = logger . spinner ( 'Auto Deploy...' ) ;
161- spinner . start ( ) ;
162- shelljs . exec ( `git commit -a -m "${ message } "` , { cwd : deployDir } , function ( code , stdout , stderr ) {
163- if ( code === 0 ) {
164- shelljs . exec ( 'git push' , { cwd : deployDir } , function ( code , stdout , stderr ) {
165- if ( code === 0 ) {
166- spinner . succeed ( chalk . green ( 'Success !' ) ) ;
167- return resolve ( ) ;
168- }
169- spinner . fail ( chalk . red ( 'Fail !' ) + stderr ) ;
170- return reject ( stderr ) ;
171- } ) ;
172- }
173- spinner . fail ( chalk . red ( 'Fail !' ) + stderr ) ;
174- return reject ( stderr ) ;
175- } ) ;
176- } ) ;
155+ const spinner = logger . spinner ( 'Auto Deploy...' ) ;
156+ spinner . start ( ) ;
157+ const { code, stderr } = shelljs . exec ( `git commit -a -m "${ message } "` , { cwd : deployDir } ) ;
158+ if ( code === 0 ) {
159+ const { code, stderr } = shelljs . exec ( 'git push' , { cwd : deployDir } ) ;
160+ if ( code === 0 ) {
161+ spinner . succeed ( chalk . green ( 'Success !' ) ) ;
162+ return true ;
163+ }
164+ spinner . fail ( chalk . red ( 'Fail !' ) + stderr ) ;
165+ } else {
166+ spinner . fail ( chalk . red ( 'Fail !' ) + stderr ) ;
167+ }
168+ return false ;
177169 }
178170 }
179171 }
180- return Promise . resolve ( ) ;
172+ return true ;
181173}
0 commit comments