Now that WordPress 3.8 is in development, now is a good time to look into contributing a patch.
But seriously, if you’re looking into contributing to the codebase, then it’s important to be familiar with two things:
- Where to grab the source code for the current release
- How to use Grunt on your local machine to kick off the build process
Once you’ve gotten those two things setup, you can actually setup customized Grunt tasks (via your own options) that will help test the work that you’re doing without kicking off the entire process, a part of the process, or testing individual files.
Custom Grunt Task For WordPress
When you checkout the latest codebase of WordPress, it includes a `Gruntfile` so that when you execute Grunt, you can run the entire process – or part of the process – that is used to build the actual release of the product.
Pretty convenient, isn’t it?
The thing is, if you’re working on a patch, then you may not need to actually run the entire, or even part of, the process. To that end, you may just want to execute, say, JSHint against a certain file.
To do that, you can enter the following command:
grunt jshint:core --file=filename.js
For example, in the upcoming release of WordPress, I had a handful of JavaScript files for which I responsible for getting to satisfy a set of JSHint rules. There are two ways in which you can execute JSHint against those files.
1. Append Multiple Commands To The Command Line
This is a tip provided by @KAdamWhite which may be more useful if you’re working with a small set of files:
grunt jshint:core --file=dashboard.js; grunt jshint:core --file=shortcode.js;
You can read more information about this in this comment thread.
2. Define a Custom Grunt Task
Another option is to define a custom task that includes the array of files that you want to run:
You can then modify the array of files to contain what you’re working on for the given patch.
That’s Not All
Obviously, this particular example is used to show how to work with JavaScript and JSHint. There’s clearly much more you can do with Grunt and the tasks that go into working on WordPress.
However, this may be a good place to start if you’re planning to begin working on JavaScript in WordPress.
Leave a Reply
You must be logged in to post a comment.