Skip to content

Commit

Permalink
Implement a target task to specify deployment targets. Update wordpre…
Browse files Browse the repository at this point in the history
…ss-client helper accordingly. Fixes #4 - CLI flag for config file
  • Loading branch information
jzaefferer authored and scottgonzalez committed Jul 18, 2012
1 parent e06e6d6 commit 3a10ccc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Expand Up @@ -31,13 +31,41 @@ 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.
If the protocol is `https`, then a secure connection will be used.
* `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

Expand Down
15 changes: 14 additions & 1 deletion tasks/wordpress.js
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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" );
Expand Down

0 comments on commit 3a10ccc

Please sign in to comment.