diff --git a/README.md b/README.md index ec77f34..8840aae 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ A collection of [Deployer](https://deployer.org) Tasks/Recipes to deploy WordPre - [Plugin Tasks (`tasks/plugins.php`)](#plugin-tasks-taskspluginsphp) - [MU Plugin Tasks (`tasks/mu-plugins.php`)](#mu-plugin-tasks-tasksmu-pluginsphp) - [WordPress Tasks (`tasks/wp.php`)](#wordpress-tasks-taskswpphp) + - [WP-CLI](#wp-cli) - [Simple Tasks (`tasks/simple.php`)](#simple-tasks-taskssimplephp) - [Recipes](#recipes) - [Default aka Vanilla - `deploy.php`](#default-aka-vanilla---deployphp) @@ -163,12 +164,15 @@ You can also run `dep --list` to see all available tasks and their description. #### WordPress Tasks (`tasks/wp.php`) -- `wp:install-cli`: Installs WP CLI on remote machine -- `wp:install`: Installs WordPress core via WP CLI +- `wp:download-core`: Installs WordPress core via WP CLI - `wp:push`: Pushes WordPress core files via rsync - `wp:pull`: Pulls WordPress core files via rsync - `wp:info`: Runs the --info command via WP CLI - just a helper/test task +##### WP-CLI + +You can set the `bin/wp` variable to the existing path of your WP-CLI binary or let the default `bin/wp` function download it to `{{deploy_path}}/.dep/wp-cli.phar`. So without setting the variable the binary will be downloaded on the first usage of WP-CLI. There's a task for downloading core and `--info`. You can generate your own tasks to handle other WP-CLI commands, there's a util function `Gaambo\DeployerWordpress\Utils\WPCLI\runCommand` (`src/utils/wp-cli.php`); + #### Simple Tasks (`tasks/simple.php`) - Contains some overwrites of Deployer default `deploy:*` tasks to be used in a "simple" recipe without release paths. See [Simple Recipe](#simple) diff --git a/src/set.php b/src/set.php index 1c1c4ab..c60153b 100644 --- a/src/set.php +++ b/src/set.php @@ -6,16 +6,33 @@ namespace Deployer; +use function \Gaambo\DeployerWordpress\Utils\WPCLI\installWPCLI; + require_once 'utils/localhost.php'; +require_once 'utils/wp-cli.php'; // BINARIES set('bin/npm', function () { return locateBinaryPath('npm'); }); +// can be overwritten if you eg. use wpcli in a docker container set('bin/wp', function () { - // can be overwritten if you eg. use wpcli in a docker container - return locateBinaryPath('wp'); + if (commandExist('wp')) { + return locateBinaryPath('wp'); + } + + $installPath = '{{deploy_path}}/.dep'; + $binaryFile = 'wp-cli.phar'; + + if (test("[ -f $installPath/$binaryFile ]")) { + return "{{bin/php}} $installPath/$binaryFile"; + } + + + writeln("WP-CLI binary wasn't found. Installing latest wp-cli to \"$installPath/$binaryFile\"."); + installWPCLI($installPath, $binaryFile); + return "$installPath/$binaryFile"; }); set('composer_options', 'install --no-dev'); diff --git a/src/tasks/wp.php b/src/tasks/wp.php index 2222308..f289e75 100644 --- a/src/tasks/wp.php +++ b/src/tasks/wp.php @@ -5,30 +5,23 @@ namespace Deployer; +use function Gaambo\DeployerWordpress\Utils\WPCLI\runCommand; + require_once 'utils/files.php'; require_once 'utils/localhost.php'; require_once 'utils/rsync.php'; +require_once 'utils/wp-cli.php'; /** - * Install WP Cli - */ -task('wp:install-cli', function () { - $remotePath = Gaambo\DeployerWordpress\Utils\Files\getRemotePath(); - run("cd $remotePath && curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar"); - run("chmod +x wp-cli.phar"); - run("{{sudo_cmd}} mv wp-cli.phar /usr/local/bin/wp", ['tty' => true] ); -})->desc('Installs WP Cli on remote server'); - -/** - * Installs WordPress core via WP CLI + * Downloads WordPress core via WP CLI * Needs the following variables: * - deploy_path or release_path: to build remote path * - bin/wp: WP CLI binary/command to use (has a default) * - wp/version: WordPress verstion to install */ -task('wp:install', function () { - $remotePath = Gaambo\DeployerWordpress\Utils\Files\getRemotePath(); - run("cd $remotePath && {{bin/wp}} core download --version={{wp/version}}"); +task('wp:download-core', function () { + $wpVersion = get('wp/version', 'latest'); + runCommand("core download --version=$wpVersion"); })->desc('Installs a WordPress version via WP CLI'); /** @@ -69,6 +62,5 @@ * - bin/wp: WP CLI binary/command to use (has a default) */ task('wp:info', function () { - $remotePath = Gaambo\DeployerWordpress\Utils\Files\getRemotePath(); - run("cd $remotePath && {{bin/wp}} --info"); + runCommand("--info"); }); diff --git a/src/utils/wp-cli.php b/src/utils/wp-cli.php new file mode 100644 index 0000000..76623bc --- /dev/null +++ b/src/utils/wp-cli.php @@ -0,0 +1,31 @@ +