Skip to content

Instantly share code, notes, and snippets.

@karrikas
Last active August 29, 2017 11:27
Show Gist options
  • Save karrikas/fd516db0960805c36e6b09763cffc817 to your computer and use it in GitHub Desktop.
Save karrikas/fd516db0960805c36e6b09763cffc817 to your computer and use it in GitHub Desktop.
Gulp deploy web by rsync
var gulp = require('gulp');
var shell = require('gulp-shell');
var prompt = require('gulp-prompt');
var init = {
ssh: {
user: "",
host: "",
port: "22",
path: ""
}
}
var rsync = function(env) {
if (env == 'sync') {
dest = '';
} else {
dest = 'n';
}
var cmd = "rsync --exclude-from='rsync_exclude' -e 'ssh -p "+init.ssh.port+"' --delete-after -razv"+dest+" . "+init.ssh.user+"@"+init.ssh.host+":"+init.ssh.path;
gulp.start(
shell.task(cmd)
);
}
gulp.task('rsync', function () {
return gulp.src('')
.pipe(prompt.prompt(
[{
type: 'input',
message: 'sync or test?',
name: 'confirm',
default: 'test'
}],
function(response){
return rsync(response.confirm);
}
));
});
gulp.task('db:url2prod', function(){
var date = new Date();
var now = date.YYYYMMDDHHMMSS();
gulp.start(
shell.task([
"wp search-replace 'localhost/project' 'project.com' --all-tables-with-prefix",
"wp db export build/db-url2prod."+now+".sql",
"wp search-replace 'project.com' 'localhost/project' --all-tables-with-prefix"
])
);
})
gulp.task('db:url2dev', function(){
gulp.start(
shell.task("wp search-replace 'project.com' 'localhost/project' --all-tables-with-prefix")
);
})
gulp.task('default', [ 'rsync' ]);
Object.defineProperty(Date.prototype, 'YYYYMMDDHHMMSS', {
value: function() {
function pad2(n) { // always returns a string
return (n < 10 ? '0' : '') + n;
}
return this.getFullYear() +
pad2(this.getMonth() + 1) +
pad2(this.getDate()) +
pad2(this.getHours()) +
pad2(this.getMinutes()) +
pad2(this.getSeconds());
}
});
{
"dependencies": {
"gulp": "^3.9.1",
"gulp-prompt": "^0.2.0",
"gulp-shell": "^0.6.3"
}
}
node_modules
.git*
.htaccess
/rsync_exclude
/gulpfile.js
/package.json
yarn*
/build*
wp-config.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment