These are the base files and install script necessary to start using grunt-wordpress-deploy for your WordPress theme development workflow.
Please submit an issue if you run into installation problems.
📢 Note: The setup examples below assumes you're developing just a theme. There are some slight modifications you have to make if you want to use this for a theme + plugin deploy flow at the same time.
💡 @TODO: Add examples and instructions on developing a plugin and theme simultaneously.
You must have Node.js and npm installed. Get em.
This project also uses Grunt – which will be installed in the target folder using when npm install
is run – but you'll need to install the Grunt command line interface (grunt-cli) 'globally' so you can use the grunt
command on the command line. If none of that made sense, it's OK. Just follow the Grunt Getting Started instructions and they'll walk you through it.
If you're familiar with traditional Gruntfile.js
structures you might notice an odd-looking Gruntfile here – there are two reasons:
-
This project utilizes the load-grunt-config package to allow modularization of Grunt tasks. Each file in the
./grunt
directory represents an auto-loaded Grunt task (named like{TASK_NAME}.coffee
). The meat-and-potatoes inGruntile.coffee
is the line that initializes this package:require('load-grunt-config')(grunt, config)
For the purposes of this project, you don't really need to understand ths ins and outs of the Gruntfile. We'll almost exclusively be looking at and modifying wordpressdeploy.coffee
.
- You're looking at Coffeescript, not Javascript. I generally don't write in coffee when developing WP themes, but I always use it for creating Grunt and task files, since it makes for a much leaner and more readable file.
1. Use your command line tool of choice (I prefer iTerm2 with oh-my-zsh installed) and navigate to your theme folder:
cd /Applications/MAMP/htdocs/best-client-ev.er/wp-content/themes/client_name-theme/
git clone https://github.com/madebycaliper/grunt-wp-deploy-boilerplate.git
3. If you trust me, run the installer script (or you can manually copy the files to the parent folder, including .gitignore
):
sh ./grunt-wp-deploy-boilerplate/install.sh
4. Install the node packages using npm
(Node Package Manager) :
npm install
This is a simple two step process:
-
Configure "environments" that represent the different WordPress installs you're dealing with (
wordpressdeploy.coffee
). -
Provide connection details (filepath, database user and password) for each of those environments, stored in a file that you're not tracking in your git repository (
deployconfig.json
).
Please follow the instructions in the grunt-wordpress-deploy docs to configure your environments.
Just like the WordPress installation flow, there's a sample config file included in the repo with the suffix -sample
. Remove the -sample
from the name and add your sensitive information to get started.
🎯 Try it out: If you're just learning your way around the command line, here's a simple way to do that using the "move" command:
mv deployconfig-sample.json deployconfig.json
By default, deployconfig.json
is excluded in the .gitignore
file, so you should be covered.
{
"local": {
"db_user":"admin",
"db_pass":"admin",
"wp_content_path":"/Applications/MAMP/htdocs/best-client-ev.er/wp-content"
},
"dev": {
"db_user":"client_dev",
"db_pass":"pass_goes_here",
"wp_content_path":"/home/client/public_html/dev/wp-content"
},
"prod": {
"db_user":"client_production",
"db_pass":"pass_goes_here",
"wp_content_path":"/home/client/public_html/wp-content"
}
}
Each environment definition requires the wp_content_path
key, and each remote definition requires both the db_user
and db_pass
keys.
📢 Note : The local object must be named "local". Don't change it.
-
wp_content_path
: Establish where yourwp-content
folder lives locally and remotely. This key will be accessed every time you push or pull files using thegrunt-wordpress-deploy
package. -
db_user
: The SQL database user for WP. This is the same user that will most likely be defined in yourwp-config.php
file. -
db_pass
: The password for the above SQL database user. This password will also probably be defined in yourwp-config.php
file, unless you have a non-traditionalwp-config
setup.
The only thing you really need to change in the Gruntfile.coffee
file included here is the theme_name
property. Change this to match the folder in which you're developing your theme.
📢 Note : It must be the same on the local and all the remote servers
require('load-grunt-config')(grunt,
config:
deployconfig : deployconfig
pkg: grunt.file.readJSON('package.json')
theme_name: 'client_name-theme'
)
This is a task that's really handy for real-world WordPress theme dev/deployment. Sometimes your client may not have a server with SSH (or even FTP, in worst case scenarios) and you just have to work around it to get your job done. Or maybe you know it as ":moneybag::moneybag::moneybag:".
build
creates a .zip
file you can either upload directly through the WP backend or send to a client so they can do it themselves, while also creating a guesswork-free FTP upload flow – simply overwrite your remote theme folder with all the contents of the /build
folder and you're good to go.
Under the hood, the build
task will:
-
Create a
/build
directory at your theme folder's root. -
Copy all the files in the theme folder's root, except those specified in the
grunt/copy.coffee
file. This allows you to exclude source files and sensitive files when you push to your remote servers. -
Create a
/releases
folder and generate a.zip
of the/build
folder within it. The.zip
will be named using the theme name and version in thepackage.json
file. You can inspect these properites in thegrunt/compress.coffee
file. (e.g.:releases/client-theme-1.0.2.zip
).
This will run your build
task and then push the theme to the specified path on the remote server.
🍕 Use Caution when using this task. It does a lot and is NOT reversible.
This is a helper that's meant to create parity between local and remote servers – making sure all required plugins and uploaded assets are available when the site runs.
sync_up
will:
-
Overwrite the entire remote
/plugins
directory with the local stuff. -
Overwrite the entire
/uploads
directory with the local stuff. -
Run the
deploy
task (build and push your theme). -
Overwrite the remote DB with your local DB.
💡 @TODO: write sync_down
helper to work the opposite direction.
That's it! You should be setup to push/pull between your local install and different environs like so:
grunt push_theme --target=dev
Enjoy responsibly.
And submit an issue to this repo if you're having trouble.