diff --git a/README.md b/README.md index bca3be1..5869fe5 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,33 @@ grunt.initConfig({ }); ``` +This works for a single deployment target. If you have multiple targets, you +can specify url, username and password for each: + +```javascript +grunt.initConfig({ + wordpress: { + dev: { + url: "wordpress.dev", + username: "admin", + password: "admin", + }, + live: { + url: "wordpress.com", + username: "admin", + password: "admin", + }, + _default: "dev", + dir: "dist" + } +}); +``` + +If nothing is specified, the `_default` target is used. Override using the +target task: + + grunt target:live deploy + * `url`: The URL for the WordPress install. Can be a full URL, e.g., `http://wordpress.dev:123/some/path` or as short as just the host name. @@ -38,6 +65,7 @@ grunt.initConfig({ * `username`: WordPress username. * `password`: WordPress password. * `dir`: Directory containing posts, taxonomies, and resources (see [Directory Structure](#directory-structure)). +* `_default`: The default deployment target, optional. ### Directory Structure diff --git a/tasks/wordpress.js b/tasks/wordpress.js index 72d6ddd..9d47e72 100644 --- a/tasks/wordpress.js +++ b/tasks/wordpress.js @@ -32,9 +32,18 @@ grunt.registerHelper( "wordpress-recurse", function recurse( rootdir, fn, comple }); }); +function config() { + var target = grunt.config( "target" ) || grunt.config( "wordpress._default" ), + base = grunt.config( "wordpress" ); + if ( target ) { + return base[ target ]; + } + return base; +} + grunt.registerHelper( "wordpress-client", function() { if ( !_client ) { - _client = wordpress.createClient( grunt.config( "wordpress" ) ); + _client = wordpress.createClient( config() ); } return _client; }); @@ -124,6 +133,10 @@ grunt.registerTask( "wordpress-validate", "Validate HTML files for synchronizing }); }); +grunt.registerTask( "target", "Runtime configuration to choose deployment target", function( target ) { + grunt.config.set( "target", target ); +}); + grunt.registerTask( "wordpress-publish", "wordpress-validate wordpress-sync" ); grunt.registerTask( "wordpress-deploy", "build-wordpress wordpress-publish" ); grunt.registerTask( "deploy", "wordpress-deploy" );