webrain / grunt-wordpress-deploy

A Grunt plugin to quickly deploy Wordpress websites.
MIT License
104 stars 37 forks source link

Adds support for custom DB dump filter functions #38

Open benjaminbojko opened 9 years ago

benjaminbojko commented 9 years ago

Allows for a custom filter function to run string operations on the DB dump before importing it to each environment.

For example, this allows for custom fixes regarding MySQL warnings as discussed in #6, #37 and #34 by adding the following filter:

local: {
  'title': 'local',
  //...
  'filter': function(mysql_dump) {
    return mysql_dump.replace(/^Warning.*\n?/gm, ''); // filter MySQL warnings
  }
}

I've also used it to switch between wordpress themes when pushing/pulling from/to local:

local: {
  'title': 'local',
  //...
  'filter': function(mysql_dump) {
    return mysql_dump
      .replace(/^Warning.*\n?/gm, '') // filter MySQL warnings
      .replace(/'(current_theme)','My Production Theme'/g, '\'$1\',\'My Development Theme\'')
      .replace(/'(stylesheet|template)','my-production-theme-folder'/g, '\'$1\',\'my-dev-theme-folder\'');
  }
}
//...
staging: {
  'title': 'staging',
  //...
  'filter': function(mysql_dump) {
    return mysql_dump
      .replace(/^Warning.*\n?/gm, '') // filter MySQL warnings
      .replace(/'(current_theme)','My Development Theme'/g, '\'$1\',\'My Production Theme\'')
      .replace(/'(stylesheet|template)','my-dev-theme-folder'/g, '\'$1\',\'my-production-theme-folder\'');
  }
}