teambition / gulp-ssh

SSH and SFTP tasks for gulp
184 stars 38 forks source link

How to wait for ssh.dest to finish #60

Closed SDries closed 7 years ago

SDries commented 7 years ago

Hello,

I'm trying to write a deploy script that copies my files to a server using ssh.

I hope to achieve the following sequence:

I've been able to run the commands separately, but when I try to run them in succession the script fails because the rename happens before all the files have been copied.

gulp.task('deploy', function(){
    runSequence(['deploy_sshDist', 'deploy_removeOldBuild', 'deploy_rename']);
});
gulp.task('deploy_sshDist', function(){
    var ssh = validateSshConfig();
    if(ssh === false) return;
    return gulp.src([yeoman.dist + '/**']).pipe(ssh.dest(deployTargetLocation + '/_build'));
});
gulp.task('deploy_rename', function(){
    var ssh = validateSshConfig();
    if(ssh === false) return;
    return ssh.exec('mv ' + deployTargetLocation + '/_build ' + deployTargetLocation + '/build2', { filePath: 'deploy-mv.log' });
});
gulp.task('deploy_removeOldBuild', function(){
    var ssh = validateSshConfig();
    if(ssh === false) return;
    return ssh.exec('rm -rf ' + deployTargetLocation + '/build', { filePath: 'deploy-clean.log' });
});

my validateSshConfig function returns the instance of gulp-ssh that is configured using arguments from the gulp call.

Each of these works separately but not in succession, can anyone help?

SDries commented 7 years ago

My bad, i ended up using gulp dependencies and it resolved my issue.

gulp.task('deploy', function(){
    runSequence(['deploy_rename']);
});
gulp.task('deploy_sshDist', function(){
    var ssh = validateSshConfig();
    if(ssh === false) return;
    return gulp.src([yeoman.dist + '/**']).pipe(ssh.dest(deployTargetLocation + '/_build'));
});
gulp.task('deploy_rename', ['deploy_removeOldBuild'], function(){
    var ssh = validateSshConfig();
    if(ssh === false) return;
    return ssh.exec('mv ' + deployTargetLocation + '/_build ' + deployTargetLocation + '/build2', { filePath: 'deploy-mv.log' });
});
gulp.task('deploy_removeOldBuild', ['deploy_sshDist'], function(){
    var ssh = validateSshConfig();
    if(ssh === false) return;
    return ssh.exec('rm -rf ' + deployTargetLocation + '/build', { filePath: 'deploy-clean.log' });
});