Astro
Astro is a JavaScript api wrapper for wp-cli.
var wp =
Installation
$ npm install wp-astro
Prerequisite
Requires WP-cli to be installed correctly and coincidently access to mysql
Features
- Call wp cli commands from JavaScript
- Write your own automated WordPress scripting
- Async makes for faster automation
- Simple api
API
The api can be called a number of different ways for example:
// Standalone command // Flags as array // command with config // Config object
Config options
Command
Define the wp cli command to call. The initial wp
is not required here as this is done behind the scenes.
Custom working directory
Set the current working directory for the command by default this uses the current working directory process.cwd()
.
This example will download the WordPress core to a folder called example
the folder must exist.
Flags
Any flags needed for the command are added here. Flags can be passed as an array or object.
// OR // OR
Async
By default astro is synchronous by enabling async, commands can be run in parallel making for faster scripts.
Note: Running async on commands which require a previous command will not work as the previous command may not have completed!
Astro returns back the child process object meaning we have access to the events that triggers
var plugin = plugin plugin
For commands where data is piped into the command like wp config create this would be more appropriate:
var config = configstdin config
Verbose
Enable verbose mode to log wp cli's output to the console useful for debugging.
Other Options
Behind the scenes we are just calling the wp-cli command with node's child_process module.
Depending on if async is enabled or disabled depends on which method we use, by default (async set to false) we use execSync otherwise if async is enabled we use exec
fortunatly that means we can pass any of it's config values in like so:
Coming soon!
- Promise API support
- Predefined scripts
- Entire install procedure
- Install multiple plugins & themes
- Tests :(