Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "grunt-wordpress-deploy",
"description": "Deploy Wordpress without pain using Grunt.",
"version": "0.0.6",
"homepage": "https://github.com/webrain/grunt-wordpress-deploy",
"version": "0.0.1",
"homepage": "https://github.com/stefnw/grunt-wordpress-deploy",
"author": {
"name": "Dario Ghilardi",
"email": "darioghilardi@webrain.it",
"url": "http://www.webrain.it"
"email": "info@snapz.de",
"url": "http://www.snapz.de"
},
"repository": {
"type": "git",
"url": "git@github.com:webrain/grunt-wordpress-deploy.git"
},
"bugs": {
"url": "https://github.com/webrain/grunt-wordpress-deploy/issues"
"url": "https://github.com/stefnw/grunt-wordpress-deploy/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/webrain/grunt-wordpress-deploy/blob/master/LICENSE-MIT"
"url": "https://github.com/stefnw/grunt-wordpress-deploy/blob/master/LICENSE-MIT"
}
],
"main": "Gruntfile.js",
Expand Down
25 changes: 25 additions & 0 deletions tasks/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ exports.init = function (grunt) {
grunt.log.oklns("Sync completed successfully.");
};

exports.rsync_dump = function (config) {
grunt.log.oklns("Dumping data from '" + config.from + "' to '" + config.to + "' with rsync.");

var cmd = exports.rsync_dump_cmd(config);
grunt.log.writeln(cmd);

shell.exec(cmd);

grunt.log.oklns("Sync completed successfully.");
};

exports.generate_backup_paths = function(target, task_options) {

var backups_dir = task_options['backups_dir'] || "backups";
Expand Down Expand Up @@ -218,10 +229,24 @@ exports.init = function (grunt) {
return cmd;
};

exports.rsync_dump_cmd = function (config) {
var cmd = grunt.template.process(tpls.rsync_dump, {
data: {
rsync_args: config.rsync_args,
from: config.from,
to: config.to,
exclusions: config.exclusions
}
});

return cmd;
};

var tpls = {
backup_path: "<%= backups_dir %>/<%= env %>/<%= date %>/<%= time %>",
mysqldump: "mysqldump -h <%= host %> -u<%= user %> -p<%= pass %> <%= database %>",
mysql: "mysql -h <%= host %> -u <%= user %> -p<%= pass %> <%= database %>",
rsync_dump: "rsync <%= rsync_args %> --delete <%= exclusions %> <%= from %> <%= to %>",
rsync_push: "rsync <%= rsync_args %> --delete -e 'ssh <%= ssh_host %>' <%= exclusions %> <%= from %> :<%= to %>",
rsync_pull: "rsync <%= rsync_args %> -e 'ssh <%= ssh_host %>' <%= exclusions %> :<%= from %> <%= to %>",
ssh: "ssh <%= host %>",
Expand Down
65 changes: 65 additions & 0 deletions tasks/wordpressdeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,71 @@ var util = require('../tasks/lib/util.js').init(grunt);

module.exports = function(grunt) {

/**
* DB DUMP
* dumps local database
*/
grunt.registerTask('dump_db', 'Dumping Database', function () {
var task_options = grunt.config.get('wordpressdeploy')['options'];

var target = grunt.option('target') || task_options['target'];

if (typeof target === "undefined" || typeof grunt.config.get('wordpressdeploy')[target] === "undefined") {
grunt.fail.warn("Invalid target specified. Did you pass the wrong argument? Please check your task configuration.", 6);
}

// Grab the options
var target_options = grunt.config.get('wordpressdeploy')[target];
var local_options = grunt.config.get('wordpressdeploy').local;

// Generate required backup directories and paths
var dump_path = {
dir: target_options.path,
file: target_options.path+'_db_dump.sql'
};

grunt.log.subhead("Dumping database from 'Local' to '" + dump_path.dir + "'");

// Dump local DB
util.db_dump(local_options, dump_path);

// Search and Replace database refs
util.db_adapt(local_options.url, target_options.url, dump_path.file);

grunt.log.subhead("Operations completed");

});

/**
* DB FILES
* dumps local files
*/
grunt.registerTask("dump_files", "Dump files with rsync.", function () {

var task_options = grunt.config.get('wordpressdeploy')['options'];
var target = grunt.option('target') || task_options['target'];

if (typeof target === "undefined" || typeof grunt.config.get('wordpressdeploy')[target] === "undefined") {
grunt.fail.warn("Invalid target provided. I cannot push files from nowhere! Please checked your configuration and provide a valid target.", 6);
}

// Grab the options
var target_options = grunt.config.get('wordpressdeploy')[target];
var local_options = grunt.config.get('wordpressdeploy').local;
var rsync_args = util.compose_rsync_options(task_options.rsync_args);
var exclusions = util.compose_rsync_exclusions(task_options.exclusions);

var config = {
rsync_args: task_options.rsync_args.join(' '),
from: local_options.path,
to: target_options.path,
exclusions: exclusions
};

util.rsync_dump(config);

grunt.log.subhead("Operations completed");
});
/**
* DB PUSH
* pushes local database to remote database
Expand Down