Skip to content

Redirects: Add support for setting redirects in redirects.json #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2015
Merged
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"marked": "0.3.2",
"rimraf": "2.2.8",
"spawnback": "1.0.0",
"which": "1.0.5"
"which": "1.0.5",
"wordpress": "0.1.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the latest release is 1.1.0, why such an old version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same version in use in grunt-wordpress

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Yeah. That makes sense.

},
"devDependencies": {
"grunt": "0.4.5",
Expand Down
15 changes: 15 additions & 0 deletions tasks/redirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function( grunt ) {

var wp = require( "wordpress" );

grunt.registerTask( "deploy-redirects", function() {
var config = grunt.config( "wordpress" );
var redirects = grunt.file.exists( "redirects.json" ) ? grunt.file.readJSON( "redirects.json" ) : {};
var client = wp.createClient( config );

client.authenticatedCall( "jq.setRedirects", JSON.stringify( redirects ), this.async() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under the hood grunt.file.readJSON just reads a file and JSON.parse's it, so it seemed kinda strange that we're directly JSON.stringifying it again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is this just because we can catch syntax errors in the file more easily this way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, I wanted grunt to error on invalid JSON.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

} );

grunt.registerTask( "deploy", [ "wordpress-deploy", "deploy-redirects" ] );

};