Skip to content
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

WIP: VIP Local Development Environment Integration #5

Open
wants to merge 20 commits into
base: default
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Local Development
.local/site
.local/db_dumps/*
!.local/db_dumps/.gitkeep
debug.log

# Build files.
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
50 changes: 0 additions & 50 deletions .lando.yml

This file was deleted.

125 changes: 125 additions & 0 deletions .local/bin/dev-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env bash

# Exit if any command fails.
set -e

print_style () {
if [[ "$2" == "info" ]] ; then
COLOR="96m"
elif [[ "$2" == "success" ]] ; then
COLOR="92m"
elif [[ "$2" == "warning" ]] ; then
COLOR="93m"
elif [[ "$2" == "danger" ]] ; then
COLOR="91m"
else #default color
COLOR="0m"
fi

START_COLOR="\e[$COLOR"
END_COLOR="\e[0m"

printf "$START_COLOR%b$END_COLOR" "$1"
}

usage() {
echo "usage: $0 command"
echo " init [-m] Init the dev environment. The '-m' option is for setting up a multisite"
echo " destroy Destroy the dev environment"
echo " start Start the dev environment"
echo " stop Stop the dev environment"
echo " exec Execute an operation on a dev environment"
echo " info Provides basic info about the dev environments"
echo " db-import <file.sql> Import a SQL file into the dev environment"
echo ' db-search-replace <file.sql> [options] Perform a search and replace on a SQL file. The required options are: -s="from,to" -o="<output.sql>"'
echo " -h | usage Output this message"
exit 1
}

REPO_DIR=$(basename "$(pwd)")
ENV_CONFIG_DIR="$(pwd)/.local/site"
VENDOR_DIR="$(pwd)/client-mu-plugins/vendor"

init_env() {
MULTISITE='--multisite=false'
if [[ "$1" == "-m" ]]; then
MULTISITE='--multisite'
fi;
echo ${MULTISITE}
print_style "Installing composer dependencies...\n" "success"
composer install
print_style "Installing npm dependencies...\n" "success"
npm install
print_style "Initializing the '${REPO_DIR}' VIP local environment...\n" "success"
vip --slug="${REPO_DIR}" dev-env create --title="${REPO_DIR} Dev Env " --phpmyadmin --mu-plugins="./client-mu-plugins/vendor/automattic/vip-go-mu-plugins" --client-code="./" --wordpress="5.8" ${MULTISITE}
ENV_DIR=$(vip --slug="${REPO_DIR}" dev-env info | awk '/LOCATION/ {print $2}')
print_style "Creating a symlink from ${ENV_DIR} to ${ENV_CONFIG_DIR}\n" "success"
ln -s ${ENV_DIR} ${ENV_CONFIG_DIR}
}

destroy_env() {
print_style "Removing ${VENDOR_DIR}...\n" "success"
rm -rf "${VENDOR_DIR}"
print_style "Removing the node_modules folder...\n" "success"
rm -rf node_modules
ENV_DIR=$(vip --slug="${REPO_DIR}" dev-env info | awk '/LOCATION/ {print $2}')
print_style "Destroying the '${REPO_DIR}' VIP local environment...\n" "success"
vip --slug="${REPO_DIR}" dev-env destroy
print_style "Removing the ${ENV_CONFIG_DIR} symlink...\n" "success"
rm -rf "${ENV_CONFIG_DIR}"
print_style "Removing ${ENV_DIR}...\n" "success"
rm -rf "${ENV_DIR}"
}

start_env() {
print_style "Starting the ${REPO_DIR} VIP local environment...\n" "success"
vip --slug="${REPO_DIR}" dev-env start
print_style "WordPress Credentials: Username: vipgo \t Password: password\n" "success"
}

stop_env() {
print_style "Stopping the ${REPO_DIR} VIP local environment...\n" "success"
vip --slug="${REPO_DIR}" dev-env stop
}

exec_env() {
vip --slug="${REPO_DIR}" dev-env exec -- "${@:1}"
}

exec_wp_env() {
vip --slug="${REPO_DIR}" dev-env exec -- wp "${@:1}"
}

info_env() {
vip --slug="${REPO_DIR}" dev-env info
}

db_import_env() {
vip --slug="${REPO_DIR}" dev-env import sql "${@:1}"
}

db_search_replace_env() {
vip search-replace "${@:1}"
}

if [ "${1}" == "init" ]; then
init_env "${@:2}"
elif [ "${1}" == "destroy" ]; then
destroy_env
elif [ "${1}" == "start" ]; then
start_env
elif [ "${1}" == "stop" ]; then
stop_env
elif [ "${1}" == "exec" ]; then
exec_env "${@:2}"
elif [ "${1}" == "wp" ]; then
exec_wp_env "${@:2}"
elif [ "${1}" == "info" ]; then
info_env
elif [ "${1}" == "db-import" ]; then
db_import_env "${@:2}"
elif [ "${1}" == "db-search-replace" ]; then
db_search_replace_env "${@:2}"
else
usage
fi
Empty file added .local/db_dumps/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
14.18
104 changes: 90 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,106 @@
[5]: https://npmjs.com
[6]: https://github.com/features/actions
[8]: https://lando.dev
[9]: https://www.docker.com/products/docker-desktop
[10]: https://docs.wpvip.com/technical-references/vip-cli/
[11]: https://docs.wpvip.com/how-tos/local-development/use-the-vip-local-development-environment/

A starter template, built and maintained by [Rareview][1], to jumpstart development for the [WPVIP Platform][2]. This template brings together some of the most modern forms for engineering and continuous intergrations, leveraging tools like [Composer][3], [Node][4] + [NPM][5], and [Github Actions][6].
A starter template, built and maintained by [Rareview][1], to jumpstart development for the [WP VIP Platform][2].
This template brings together some of the most modern forms for engineering and continuous integration, leveraging tools like [Composer][3], [Node][4] + [NPM][5], and [Github Actions][6].

## Configuration
## Prerequisites

The following configurations are required in order to build using this project template.
- PHP 7.4 or higher
- [VIP CLI][10] Latest version recommended
- [Docker Desktop][9] Latest version recommended
- [Composer][3] Latest version recommended
- [Node][4] Latest version recommended
- [NPM][5] Latest version recommended
- [Lando][8] Latest version recommended

### Programming Tools
## Local Development

- [Lando][8] 3.4+
- [Composer][3] 2.0+
- [Node][4] 14.0+ LTS
- [NPM][5] 6.0+
This project local development is powered by the [VIP Local Development Environment][11].

### Local Development
_Note: All the commands described below should be executed from the root of the repo._

This project contains default configuration for local development using [Lando][8] (learn more and download [here](https://lando.dev/download/)), a versitile and modern development tool, which works seemlessly with WordPress development.
### Environment setup

### VSCode Config
The first step which should be done only once per repository is to initialize the environment using the following command:

While development with a particular IDE is not required, this particular project does include configuration for VSCode, which consisits of recommended extensions and devault XDebug configuration for PHP.
```shell
npm run env:init # or for a multiste: npm run env:init -- -m
```

## License
This command will run the following steps:

[MIT](https://en.wikipedia.org/wiki/MIT_License) &copy; [Rareview][1] 2021-present
- Run the `composer install` command to install PHP dependencies.
- Run the `npm install` command to install the Node dependencies.
- Run the VIP command to setup a local WordPress development environment.
- Create a symlink of the new VIP WordPress development environment setup folder to the `.local/site` folder local to the repo.

**Note**: Please ignore the message in the output of the command above mentioned the following:

```
To start it please run:

vip dev-env start --slug SLUG_OF_THE_SITE
```

As the next command to progress will be `npm run env:start`. See below for more details.

### Environment usage

Once you have initialized the environment wih the command above you can:

```shell
- npm run env:start # Start the environment.
- npm run env:stop # Stop the environment.
- npm run env:wp # Run a WP CLI command .
- npm run env:exec # Execute a command on the environment (any bash command).
- npm run env:info # Get some info about the environment.
- npm run env:db:import # Import a SQL file into the environment.
- npm run env:db:search-replace # Perform a search and replace on a SQL file.
```

**Note - The default WordPress credentials are:**

```shell
Username: vipgo
Passoword: password
```
#### importing a remote environment database.

To import a remote environment database, the usual workflow would be :
- Place the database sql dump into the ./local/db-dump directory, so it will be ignored from git.
- Run the DB search and replace command which will look like:
```shell
npm run env:db:search-replace -- ./.local/db_dumps/file.sql -s="REMOTE_ENV_DOMAIN_NAME,LOCAL_DEV_ENV_DOMAIN_NAME" -o="./.local/db_dumps/updated-file.sql"
```
- Run the DB import command which will look like:
```shell
npm run env:db:import ./.local/db_dumps/updated-file.sql
```

### Environment termination

If you want to destroy the environment and start from scratch again, run the following command:

```shell
npm run env:destroy
```

This command will run the following steps:

- Remove the `./client-mu-plugins/vendor/` Composer dependencies folder in .
- Remove the `node_modules` Node dependencies folder.
- Run the VIP command to destroy the local WordPress development environment.
- Remove the symlink of the VIP WordPress development environment setup folder to the `.local/site` folder local to the repo.

## VSCode Config

While development with a particular IDE is not required, this particular project does include configuration for VSCode, which consists of recommended extensions and default XDebug configuration for PHP.

## License

[MIT](https://en.wikipedia.org/wiki/MIT_License) &copy; [Rareview][1] 2021-present
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"platform-check": false,
"platform": {
"php": "7.4"
},
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"autoload": {
Expand All @@ -27,13 +31,14 @@
}
},
"require": {
"composer/installers": "~1.0"
"composer/installers": "^2.1"
},
"require-dev": {
"automattic/vip-go-mu-plugins": "dev-master",
"automattic/vipwpcs": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"wpackagist-theme/twentytwentyone": "^1.4"
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
"roave/security-advisories": "dev-latest",
"wpackagist-theme/twentytwentytwo": "^1.2"
},
"scripts": {
"lint": "phpcs",
Expand Down
Loading