 # Gulp
-gulp        = require "gulp"
-coffee      = require "gulp-coffee"
-concat      = require "gulp-concat"
-exec        = require "gulp-exec"
-minifyCSS   = require "gulp-minify-css"
-plumber     = require "gulp-plumber"
-rename      = require "gulp-rename"
-sass        = require "gulp-sass"
-uglify      = require "gulp-uglify"
-gutil       = require "gulp-util"
-watch       = require "gulp-watch"
-shell       = require "gulp-shell"
-browserSync = require "browser-sync"
-reload      = browserSync.reload
-imagemin    = require "gulp-imagemin"
-pngquant    = require "imagemin-pngquant"
-rsync 			= require "gulp-rsync"
+gulp        	= require "gulp"
+coffee      	= require "gulp-coffee"
+concat      	= require "gulp-concat"
+exec        	= require "gulp-exec"
+minifyCSS   	= require "gulp-minify-css"
+plumber     	= require "gulp-plumber"
+rename      	= require "gulp-rename"
+sass        	= require "gulp-sass"
+uglify      	= require "gulp-uglify"
+gutil       	= require "gulp-util"
+watch       	= require "gulp-watch"
+shell       	= require "gulp-shell"
+browserSync 	= require "browser-sync"
+reload      	= browserSync.reload
+imagemin    	= require "gulp-imagemin"
+pngquant    	= require "imagemin-pngquant"
+rsyncwrapper	= require "rsyncwrapper"
+rsync 				= rsyncwrapper.rsync
 
 # Extra
-extend 			= require "extend"
-
-pkg = require './package.json'
-conf = require './Gulpconfig.json'
+extend 				= require "extend"
+
+pkg   = require './package.json'
+conf  = require './Gulpconfig.json'
 try
 	pvt = require './private.json'
 catch err

# grunt's devUpdate:check alternative
# grunt's devUpdate:ask alternative
# grunt's devUpdate:up alternative

#   $RSYNC
#*------------------------------------*/
# rsync files to and from production

# dry-run down
gulp.task "rsync:downdry", () ->
	rsyncDown = {
		dest: conf.rsyncFolders.localFolder,
		src: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder
	}
	opts = extend rsyncDown, conf.rsyncOpts, conf.rsyncDry
	rsync opts, (error, stdout, stderr, cmd) ->
		gutil.log stdout


# sync down
gulp.task "rsync:down", () ->
	rsyncDown = {
		dest: conf.rsyncFolders.localFolder,
		src: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder
	}
	opts = extend rsyncDown, conf.rsyncOpts
	rsync opts, (error, stdout, stderr, cmd) ->
		gutil.log stdout


# staging dry-run down
gulp.task "rsync:staging-downdry", () ->
	rsyncDown = {
		dest: conf.rsyncFolders.localFolder,
		src: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder + "/staging"
	}
	opts = extend rsyncDown, conf.rsyncOpts, conf.rsyncDry
	rsync opts, (error, stdout, stderr, cmd) ->
		gutil.log stdout


# sync staging to local
gulp.task "rsync:staging-down", () ->
	rsyncDown = {
		dest: conf.rsyncFolders.localFolder,
		src: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder + "/staging"
	}
	opts = extend rsyncDown, conf.rsyncOpts
	rsync opts, (error, stdout, stderr, cmd) ->
		gutil.log stdout


# dry-run sync to prod
gulp.task "rsync:updry", () ->
	rsyncUp = {
		dest: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder
		src: conf.rsyncFolders.localFolder,
	}
	opts = extend rsyncUp, conf.rsyncOpts, conf.rsyncDry
	rsync opts, (error, stdout, stderr, cmd) ->
    gutil.log stdout


# sync to production
gulp.task 'rsync:up', () ->
	rsyncUp = {
		src: conf.rsyncFolders.localFolder,
		dest: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder
	}
	opts = extend rsyncUp, conf.rsyncOpts
	rsync opts, (error, stdout, stderr, cmd) ->
    gutil.log stdout

# dry-run deploy to staging
gulp.task "rsync:staging-updry", () ->
	rsyncUp = {
		dest: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder + "/staging"
		src: conf.rsyncFolders.localFolder,
	}
	opts = extend rsyncUp, conf.rsyncOpts, conf.rsyncDry
	rsync opts, (error, stdout, stderr, cmd) ->
    gutil.log stdout


# deploy local changes to staging
gulp.task "rsync:staging-up", () ->
	rsyncUp = {
		dest: pvt.username + '@' + pvt.domain + ':' + conf.rsyncFolders.hostFolder + "/staging"
		src: conf.rsyncFolders.localFolder,
	}
	opts = extend rsyncUp, conf.rsyncOpts
	rsync opts, (error, stdout, stderr, cmd) ->
    gutil.log stdout


#*------------------------------------*\
