@@ -4,8 +4,11 @@ var sshExec = require('../lib/sshExec');
44var config = require ( 'config' ) ;
55var gutil = require ( 'gulp-util' ) ;
66
7- // path/build must be initialized with:
8- // git clone -b production --single-branch git://sub.domain.com/repo.git
7+ /**
8+ * Init build & working copy.
9+ * Deletes and recreates everything.
10+ * @returns {Function }
11+ */
912module . exports = function ( ) {
1013
1114 var args = require ( 'yargs' )
@@ -18,22 +21,30 @@ module.exports = function() {
1821
1922 var client = yield * sshConnect ( args . host ) ;
2023
21- yield * client . run ( `rm -rf ${ config . deploy . buildPath } ` ) ;
22- yield * client . run ( `rm -rf ${ config . deploy . targetPath } ` ) ;
24+ try {
25+ yield * client . run ( `rm -rf ${ config . deploy . buildPath } ` ) ;
2326
24- // must make big --depth N, because `gut pull origin/master` may fail to auto-merge if depth is too small
25- // for safety not using --depth at all
26- // not using --single-branch, cause need master too
27- yield * client . run ( `git clone ${ config . deploy . repo } ${ config . deploy . buildPath } ` ) ;
28- // now master & production branches are created,
29- // using production for the build
30- yield * client . runInBuild ( `git checkout production` ) ;
31- //yield* client.runInBuild(`npm install`);
27+ // must make big --depth N, because `gut pull origin/master` may fail to auto-merge if depth is too small
28+ // for safety not using --depth at all
29+ // not using --single-branch, cause need master too
30+ yield * client . run ( `git clone ${ config . deploy . repo } ${ config . deploy . buildPath } ` ) ;
31+ // now master & production branches are created,
32+ // using production for the build
33+ yield * client . runInBuild ( `git checkout production` ) ;
34+ //yield* client.runInBuild(`npm install`);
3235
33- yield * client . run ( `mkdir -p ${ config . deploy . targetPath } ` ) ;
34- yield * client . run ( `cp -a ${ config . deploy . buildPath } ${ config . deploy . targetPath } ` ) ;
36+ yield * client . run ( `rm -rf ${ config . deploy . targetPath } ` ) ;
3537
36- client . end ( ) ;
38+ // create path to target dir
39+ yield * client . run ( `mkdir -p ${ config . deploy . targetPath } ` ) ;
40+
41+ // remove the target dir itself (will be copied)
42+ yield * client . run ( `rmdir ${ config . deploy . targetPath } ` ) ;
43+
44+ yield * client . run ( `cp -a ${ config . deploy . buildPath } ${ config . deploy . targetPath } ` ) ;
45+ } finally {
46+ client . end ( ) ;
47+ }
3748
3849 } ) ;
3950
0 commit comments