Merge mailpoet-dev-env into the plugin repository
[MAILPOET-3919]
This commit is contained in:
5
.dockerignore
Normal file
5
.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.idea
|
||||||
|
fake_mail_output
|
||||||
|
mailpoet
|
||||||
|
mailpoet-premium
|
||||||
|
wordpress
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,6 +1,9 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
.env
|
||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
|
docker-compose.override.yml
|
||||||
|
fake_mail_output
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
mailpoet-premium
|
mailpoet-premium
|
||||||
|
94
do
Executable file
94
do
Executable file
@@ -0,0 +1,94 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function syntax {
|
||||||
|
cat << EOF
|
||||||
|
./do setup Setup the dev environment.
|
||||||
|
./do start Start the docker containers (docker-compose up -d).
|
||||||
|
./do stop Stop the docker containers (docker-compose stop).
|
||||||
|
./do ssh [--test] Run an interactive bash shell inside the plugin directory.
|
||||||
|
./do run [--test] <command> Run a custom bash command in the wordpress container.
|
||||||
|
./do acceptance [--premium] Run acceptance tests.
|
||||||
|
./do build [--premium] Builds a .zip for the plugin.
|
||||||
|
./do templates Generates templates classes and assets.
|
||||||
|
./do [--test] [--premium] <command> Run './do <command>' inside the plugin directory.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--test Run the command using the 'test_wordpress' service.
|
||||||
|
--premium Run the command inside the premium plugin.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function ssh_and_run {
|
||||||
|
params=("$@")
|
||||||
|
params=("${params[@]:1}")
|
||||||
|
docker-compose exec $1 bash -c "${params[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" = "" -o "$1" = "--help" ]; then
|
||||||
|
syntax
|
||||||
|
|
||||||
|
elif [ "$1" = "setup" ]; then
|
||||||
|
./initial-setup.sh
|
||||||
|
|
||||||
|
elif [ "$1" = "start" ]; then
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
elif [ "$1" = "stop" ]; then
|
||||||
|
docker-compose stop
|
||||||
|
|
||||||
|
elif [ "$1" = "run" ]; then
|
||||||
|
params=("$@")
|
||||||
|
params=("${params[@]:1}")
|
||||||
|
if [ "$2" = "--test" ]; then
|
||||||
|
params=("${params[@]:1}")
|
||||||
|
ssh_and_run test_wordpress "${params[@]}"
|
||||||
|
else
|
||||||
|
ssh_and_run wordpress "${params[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "$1" = "ssh" ]; then
|
||||||
|
if [ "$2" = "--premium" ] || [ "$3" = "--premium" ]; then
|
||||||
|
dir=/var/www/html/wp-content/plugins/mailpoet-premium
|
||||||
|
else
|
||||||
|
dir=/var/www/html/wp-content/plugins/mailpoet
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$2" = "--test" ] || [ "$3" = "--test" ]; then
|
||||||
|
docker-compose exec --workdir $dir test_wordpress bash
|
||||||
|
else
|
||||||
|
docker-compose exec --workdir $dir wordpress bash
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "$1" = "acceptance" ]; then
|
||||||
|
if [ "$2" = "--premium" ]; then
|
||||||
|
cd mailpoet-premium
|
||||||
|
else
|
||||||
|
cd mailpoet
|
||||||
|
fi
|
||||||
|
COMPOSE_HTTP_TIMEOUT=200 docker-compose run codeception -e KEEP_DEPS=1 --steps --debug -vvv
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
elif [ "$1" = "build" ]; then
|
||||||
|
if [ "$2" = "--premium" ]; then
|
||||||
|
ssh_and_run wordpress "cd wp-content/plugins/mailpoet-premium && ./build.sh"
|
||||||
|
else
|
||||||
|
ssh_and_run wordpress "cd wp-content/plugins/mailpoet && ./build.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "$1" = "templates" ]; then
|
||||||
|
ssh_and_run wordpress "cd ../templates && php generate.php"
|
||||||
|
|
||||||
|
else
|
||||||
|
docker_service="wordpress"
|
||||||
|
plugin_directory="mailpoet"
|
||||||
|
params=("$@")
|
||||||
|
if [ "$1" = "--test" -o "$2" = "--test" ]; then
|
||||||
|
docker_service="test_wordpress"
|
||||||
|
params=("${params[@]:1}")
|
||||||
|
fi
|
||||||
|
if [ "$1" = "--premium" -o "$2" = "--premium" ]; then
|
||||||
|
plugin_directory="mailpoet-premium"
|
||||||
|
params=("${params[@]:1}")
|
||||||
|
fi
|
||||||
|
ssh_and_run $docker_service "cd wp-content/plugins/$plugin_directory && ./do ${params[@]}"
|
||||||
|
fi
|
33
docker-compose.override.macos-sample.yml
Normal file
33
docker-compose.override.macos-sample.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
version: '3.7'
|
||||||
|
|
||||||
|
services:
|
||||||
|
wordpress:
|
||||||
|
volumes:
|
||||||
|
- nfs-wordpress:/var/www/html
|
||||||
|
- nfs-mailpoet:/var/www/html/wp-content/plugins/mailpoet
|
||||||
|
- nfs-mailpoet-premium:/var/www/html/wp-content/plugins/mailpoet-premium
|
||||||
|
|
||||||
|
test_wordpress:
|
||||||
|
volumes:
|
||||||
|
- nfs-mailpoet:/var/www/html/wp-content/plugins/mailpoet
|
||||||
|
- nfs-mailpoet-premium:/var/www/html/wp-content/plugins/mailpoet-premium
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
nfs-wordpress:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: nfs
|
||||||
|
o: addr=host.docker.internal,nolock
|
||||||
|
device: ":/System/Volumes/Data${PWD}/wordpress"
|
||||||
|
nfs-mailpoet:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: nfs
|
||||||
|
o: addr=host.docker.internal,nolock
|
||||||
|
device: ":/System/Volumes/Data${PWD}/mailpoet"
|
||||||
|
nfs-mailpoet-premium:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: nfs
|
||||||
|
o: addr=host.docker.internal,nolock
|
||||||
|
device: ":/System/Volumes/Data${PWD}/mailpoet-premium"
|
102
docker-compose.yml
Normal file
102
docker-compose.yml
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
version: '3.7'
|
||||||
|
|
||||||
|
services:
|
||||||
|
dashboard:
|
||||||
|
container_name: mp-dashboard
|
||||||
|
image: nginx:1.21-alpine
|
||||||
|
ports:
|
||||||
|
- 8888:80
|
||||||
|
volumes:
|
||||||
|
- ./docker/dashboard:/usr/share/nginx/html:ro
|
||||||
|
|
||||||
|
db:
|
||||||
|
container_name: mp-db
|
||||||
|
image: mysql:5.7
|
||||||
|
volumes:
|
||||||
|
- my-datavolume:/var/lib/mysql
|
||||||
|
- ./docker/create_test_db.sh:/docker-entrypoint-initdb.d/10-create_test_db.sh
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: somewordpress
|
||||||
|
MYSQL_DATABASE: wordpress
|
||||||
|
MYSQL_TEST_DATABASE: test_wordpress
|
||||||
|
MYSQL_USER: wordpress
|
||||||
|
MYSQL_PASSWORD: wordpress
|
||||||
|
|
||||||
|
wordpress:
|
||||||
|
container_name: mp-wp
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: docker/php80/Dockerfile
|
||||||
|
args:
|
||||||
|
UID: ${UID:-1000}
|
||||||
|
GID: ${GID:-1000}
|
||||||
|
ports:
|
||||||
|
- "8002:80"
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- smtp
|
||||||
|
user: ${UID:-1000}:${GID:-1000}
|
||||||
|
environment:
|
||||||
|
WORDPRESS_DEBUG: 1
|
||||||
|
WORDPRESS_DB_NAME: wordpress
|
||||||
|
WORDPRESS_DB_HOST: db:3306
|
||||||
|
WORDPRESS_DB_USER: wordpress
|
||||||
|
WORDPRESS_DB_PASSWORD: wordpress
|
||||||
|
PHP_IDE_CONFIG: "serverName=Mailpoet"
|
||||||
|
COMPOSER_HOME: "/tmp/.composer"
|
||||||
|
NPM_CONFIG_CACHE: "/tmp/.npm"
|
||||||
|
MAILPOET_DEV_SITE: 1
|
||||||
|
volumes:
|
||||||
|
- "./wordpress:/var/www/html"
|
||||||
|
- "./mailpoet:/var/www/html/wp-content/plugins/mailpoet"
|
||||||
|
- "./mailpoet-premium:/var/www/html/wp-content/plugins/mailpoet-premium"
|
||||||
|
- "./templates:/var/www/templates"
|
||||||
|
|
||||||
|
test_wordpress:
|
||||||
|
container_name: mp-test-wp
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: docker/php80/Dockerfile
|
||||||
|
args:
|
||||||
|
UID: ${UID:-1000}
|
||||||
|
GID: ${GID:-1000}
|
||||||
|
ports:
|
||||||
|
- "8003:80"
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- smtp
|
||||||
|
user: ${UID:-1000}:${GID:-1000}
|
||||||
|
environment:
|
||||||
|
WORDPRESS_DB_NAME: test_wordpress
|
||||||
|
WORDPRESS_DB_HOST: db:3306
|
||||||
|
WORDPRESS_DB_USER: wordpress
|
||||||
|
WORDPRESS_DB_PASSWORD: wordpress
|
||||||
|
PHP_IDE_CONFIG: "serverName=Mailpoet"
|
||||||
|
volumes:
|
||||||
|
- "./mailpoet:/var/www/html/wp-content/plugins/mailpoet"
|
||||||
|
- "./mailpoet-premium:/var/www/html/wp-content/plugins/mailpoet-premium"
|
||||||
|
|
||||||
|
smtp:
|
||||||
|
container_name: mp-mailhog
|
||||||
|
image: mailhog/mailhog:v1.0.0
|
||||||
|
user: ${UID:-1000}:${GID:-1000}
|
||||||
|
environment:
|
||||||
|
MH_STORAGE: maildir
|
||||||
|
MH_MAILDIR_PATH: /output
|
||||||
|
volumes:
|
||||||
|
- "./fake_mail_output:/output"
|
||||||
|
ports:
|
||||||
|
- "8082:8025"
|
||||||
|
|
||||||
|
adminer:
|
||||||
|
container_name: mp-adminer
|
||||||
|
image: adminer:latest
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "8081:8080"
|
||||||
|
volumes:
|
||||||
|
- "./docker/php.ini:/usr/local/etc/php/conf.d/custom.ini"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
my-datavolume:
|
10
docker/create_test_db.sh
Executable file
10
docker/create_test_db.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
RUNMYSQL="mysql --user=root --password=${MYSQL_ROOT_PASSWORD}"
|
||||||
|
|
||||||
|
$RUNMYSQL <<EOSQL
|
||||||
|
CREATE DATABASE ${MYSQL_TEST_DATABASE};
|
||||||
|
GRANT ALL PRIVILEGES ON ${MYSQL_TEST_DATABASE}.* TO '${MYSQL_USER}'@'%';
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
EOSQL
|
BIN
docker/dashboard/favicon.png
Normal file
BIN
docker/dashboard/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
85
docker/dashboard/index.html
Normal file
85
docker/dashboard/index.html
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>MailPoet dev environment</title>
|
||||||
|
<link rel="icon" href="favicon.png" />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: #ffe0d0;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
color: #071c6d;
|
||||||
|
font-weight: 600;
|
||||||
|
text-align: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: #fe5301;
|
||||||
|
transition: all 0.25s ease-in-out;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #cb4201;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
margin: 2em auto;
|
||||||
|
}
|
||||||
|
table tr td {
|
||||||
|
color: #071c6d;
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
table tr td:nth-child(2) {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
margin: 3em auto 0;
|
||||||
|
width: 250px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<a href="/"><img src="logo.svg" /></a>
|
||||||
|
<p>Dev environment</p>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>🖥</td>
|
||||||
|
<td>
|
||||||
|
<a href="http://localhost:8002">WordPress</a>
|
||||||
|
[<a href="http://localhost:8002/wp-admin/">wp-admin</a>]
|
||||||
|
</td>
|
||||||
|
<td>App for development</td>
|
||||||
|
<td><a href="http://localhost:8002">http://localhost:8002</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>🚥</td>
|
||||||
|
<td>
|
||||||
|
<a href="http://localhost:8003">WordPress Tests</a>
|
||||||
|
[<a href="http://localhost:8003/wp-admin/">wp-admin</a>]
|
||||||
|
</td>
|
||||||
|
<td>App for E2E tests</td>
|
||||||
|
<td><a href="http://localhost:8003">http://localhost:8003</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>💾</td>
|
||||||
|
<td>
|
||||||
|
<a href="http://localhost:8081?server=db&mysql=wordpress&username=wordpress">Adminer</a>
|
||||||
|
</td>
|
||||||
|
<td>DB management</td>
|
||||||
|
<td>
|
||||||
|
<a href="http://localhost:8081?server=db&mysql=wordpress&username=wordpress">http://localhost:8081</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>📪</td>
|
||||||
|
<td><a href="http://localhost:8082">MailHog</a></td>
|
||||||
|
<td>Email catcher</td>
|
||||||
|
<td><a href="http://localhost:8082">http://localhost:8082</a></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
12
docker/dashboard/logo.svg
Normal file
12
docker/dashboard/logo.svg
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 526.22 159.7" fill="#fe5301">
|
||||||
|
<path d="M37.81,92.5c3.5,0,5.9-.8,7.2-2.3a8,8,0,0,0,2-5.4V39.1L64,84.2a12.68,12.68,0,0,0,3.7,5.4c1.6,1.3,4,2,7.2,2a12.54,12.54,0,0,0,5.9-1.4,8.41,8.41,0,0,0,3.9-5l18.1-50V84.4a8.53,8.53,0,0,0,2.1,6.1c1.4,1.4,3.7,2.2,6.9,2.2,3.5,0,5.9-.8,7.2-2.3a8,8,0,0,0,2-5.4V12.1a7.48,7.48,0,0,0-3.3-6.6c-2.1-1.4-5-2.1-8.6-2.1a19.3,19.3,0,0,0-9.4,2,11.63,11.63,0,0,0-5.1,6.8L74.91,70.5,54.41,11.8a12.4,12.4,0,0,0-4.5-6.2c-2.1-1.5-5-2.2-8.8-2.2a16.51,16.51,0,0,0-8.9,2.1c-2.3,1.5-3.5,3.9-3.5,7.2V84.2c0,2.8.7,4.8,2,6.2C32.21,91.8,34.51,92.5,37.81,92.5Z"/>
|
||||||
|
<path d="M150.11,93.1a30.15,30.15,0,0,0,7.7-.9,26,26,0,0,0,5.8-2.3,17.85,17.85,0,0,0,4.3-3.2c.6-.6,1.2-1.2,1.7-1.8V85c0,2.7.8,4.7,2.5,5.9a11,11,0,0,0,6.4,1.7c3.1,0,5.3-.6,6.7-1.8s2.1-3.2,2.1-5.8V48c0-8.1-2.2-14.1-6.5-18s-11.4-5.8-21.1-5.8a49.58,49.58,0,0,0-12.3,1.4,35.14,35.14,0,0,0-8.9,3.5,17.41,17.41,0,0,0-5.5,4.7,8.26,8.26,0,0,0-1.9,5,7.58,7.58,0,0,0,2.5,5.8,7.73,7.73,0,0,0,5.6,2.4,9.35,9.35,0,0,0,3.9-.8c1-.5,2-1.2,3.1-1.9A42.86,42.86,0,0,1,150,42a29,29,0,0,1,3.1-1.5,15.67,15.67,0,0,1,3.1-.8,20,20,0,0,1,3.5-.2,13.55,13.55,0,0,1,4.9.8,6.76,6.76,0,0,1,3,2.1,8.47,8.47,0,0,1,1.5,3,13.45,13.45,0,0,1,.5,3.5v1.6c-3.4.2-6.6.5-9.7.8s-6.4.8-9.6,1.4a57.32,57.32,0,0,0-8.4,2.1,21.25,21.25,0,0,0-7.1,3.9,18.08,18.08,0,0,0-4.8,6.1,19.73,19.73,0,0,0-1.8,8.8c0,5.9,2,10.7,5.9,14.3C138,91.3,143.41,93.1,150.11,93.1Zm-2.4-25.3c1.1-1.4,3.5-2.5,7.3-3.3,1.4-.3,3.5-.7,6.3-1.1,2.6-.4,5.3-.7,8.1-1v3.7a10.58,10.58,0,0,1-3.9,8.5c-2.7,2.2-6.5,3.4-11.4,3.4-3,0-5.1-.5-6.3-1.6a5.52,5.52,0,0,1-1.7-4.4A5.86,5.86,0,0,1,147.71,67.8Z"/>
|
||||||
|
<path d="M212.91,27.2a10.17,10.17,0,0,0-6.6-1.9c-3.3,0-5.8.8-7.4,2.3a8.45,8.45,0,0,0-2.3,6.3v51c0,3.4,1.7,7.5,9.6,7.5a11.31,11.31,0,0,0,6.7-1.8c1.7-1.2,2.6-3.2,2.6-6V33.1A7.61,7.61,0,0,0,212.91,27.2Z"/>
|
||||||
|
<path d="M198.61,17.3a10.71,10.71,0,0,0,7.6,2.7,10.87,10.87,0,0,0,7.6-2.7,9.71,9.71,0,0,0,2.9-7.3c0-3.4-1.1-5.9-3.4-7.6a11.7,11.7,0,0,0-7.1-2.4,10.94,10.94,0,0,0-7.6,2.8h0a9.73,9.73,0,0,0-2.9,7.1A9.79,9.79,0,0,0,198.61,17.3Z"/>
|
||||||
|
<path d="M234.41,92.5a11.31,11.31,0,0,0,6.7-1.8c1.7-1.2,2.6-3.2,2.6-6V10.4a6.34,6.34,0,0,0-2.9-5.8,11.77,11.77,0,0,0-6.2-1.7c-8,0-9.7,4.3-9.7,8v74C224.81,88.4,226.51,92.5,234.41,92.5Z"/>
|
||||||
|
<path d="M264.71,92.5c3.6,0,6-.8,7.3-2.4a8.66,8.66,0,0,0,1.8-5.5V60.3h14q9.45,0,15.6-2.7a26.51,26.51,0,0,0,9.7-6.9,24.5,24.5,0,0,0,4.9-9.1,35.05,35.05,0,0,0,1.3-9.5c0-9-2.6-16-7.7-20.9s-13.3-7.4-24.4-7.4h-24.5a8.5,8.5,0,0,0-5.4,1.7,5.86,5.86,0,0,0-2.2,4.9V84.3C255.11,88.1,256.81,92.5,264.71,92.5Zm9.1-72.8h11.9a19.17,19.17,0,0,1,6.9,1.1,11.09,11.09,0,0,1,4.3,2.8,10.72,10.72,0,0,1,2.3,4,15.07,15.07,0,0,1,.7,4.8,15.7,15.7,0,0,1-.7,4.9,10,10,0,0,1-2.3,3.8,10.64,10.64,0,0,1-4.3,2.5,21.91,21.91,0,0,1-6.9,1h-11.9Z"/>
|
||||||
|
<path d="M329.21,84.2a30.83,30.83,0,0,0,10.7,7.1A39.33,39.33,0,0,0,354,93.8a38.08,38.08,0,0,0,13.8-2.5,32.81,32.81,0,0,0,10.7-7.1,30.7,30.7,0,0,0,6.9-11.1,41,41,0,0,0,2.4-14.4,39.74,39.74,0,0,0-2.4-14.1,29.88,29.88,0,0,0-6.9-10.9,30.4,30.4,0,0,0-10.6-6.9,37.69,37.69,0,0,0-13.8-2.5,36.07,36.07,0,0,0-13.8,2.5,31.47,31.47,0,0,0-10.8,7,30.5,30.5,0,0,0-7,11A40.45,40.45,0,0,0,320,59.1a43.32,43.32,0,0,0,2.3,14.3A36.88,36.88,0,0,0,329.21,84.2ZM343.31,45c2.6-3.3,6.2-4.9,10.8-4.9,4.8,0,8.5,1.6,11.1,4.9s3.9,8,3.9,13.9-1.3,10.7-4,13.9-6.2,4.8-11,4.8a13.28,13.28,0,0,1-10.8-4.8c-2.6-3.2-4-7.9-4-13.9S340.61,48.3,343.31,45Z"/>
|
||||||
|
<path d="M403.41,85.4a28.7,28.7,0,0,0,10.9,6.3,48.23,48.23,0,0,0,14.2,2,46.52,46.52,0,0,0,11-1.3,31.74,31.74,0,0,0,9.7-3.9,16.38,16.38,0,0,0,4.5-3.7,6.9,6.9,0,0,0,1.5-4.4,9.46,9.46,0,0,0-2.3-6.1c-1.6-1.8-3.3-2.8-5.2-2.8a8.58,8.58,0,0,0-4.3,1.1c-1.1.7-2.2,1.3-3.4,2s-2.9,1.4-4.7,2.3a15.23,15.23,0,0,1-6.4,1.2c-9.5,0-14.6-4.5-15.7-13.7h35.1a12.41,12.41,0,0,0,6.6-1.5c1.7-1.1,2.5-3,2.5-5.6,0-10.6-2.8-18.9-8.2-24.6s-12.9-8.6-22.1-8.6a33.05,33.05,0,0,0-14.9,3.1,29.85,29.85,0,0,0-10.4,8,32.77,32.77,0,0,0-6,11.4,44.18,44.18,0,0,0-1.9,13.1,42.72,42.72,0,0,0,2.4,15.1A34,34,0,0,0,403.41,85.4ZM418.21,42a13.6,13.6,0,0,1,8.8-3,14.45,14.45,0,0,1,5.4,1,9.22,9.22,0,0,1,3.6,2.8,13.39,13.39,0,0,1,2.2,3.8,13.72,13.72,0,0,1,.7,3.4h-24.8A12.65,12.65,0,0,1,418.21,42Z"/>
|
||||||
|
<path d="M482.61,93.7a36,36,0,0,0,9.2-1h0a20.51,20.51,0,0,0,6.5-2.6,6.45,6.45,0,0,0,2.7-3,9.37,9.37,0,0,0,.7-3.9,11.29,11.29,0,0,0-1.5-5.7,5.63,5.63,0,0,0-5.3-2.9,5.83,5.83,0,0,0-2.6.6l-1.9.9a18,18,0,0,0-2.1.8,5.27,5.27,0,0,1-2.3.4,3.37,3.37,0,0,1-2.7-.9c-.6-.6-.9-1.8-.9-3.5V40.5h9.3c2.5,0,5.4-1.3,5.4-7.4a10.18,10.18,0,0,0-1.1-4.7,4.32,4.32,0,0,0-4.2-2.2h-9.4V12.6a6.52,6.52,0,0,0-1.5-4.4c-1-1.2-2.8-1.8-5.1-1.8a19,19,0,0,0-4,.5A15.65,15.65,0,0,0,468,8.3a9.72,9.72,0,0,0-3,2.7,7.39,7.39,0,0,0-1.2,4.2V74.8c0,6.4,1.7,11.2,5.1,14.3S477,93.7,482.61,93.7Z"/>
|
||||||
|
<path d="M523.31,120l-2.4-1.9a7.39,7.39,0,0,0-9.4.3,19.59,19.59,0,0,1-12.4,4.6H292.61a37.08,37.08,0,0,0-26.3,10.9l-1.1,1.1-1.1-1.1a37.25,37.25,0,0,0-26.3-10.9H27a19.59,19.59,0,0,1-12.4-4.6,7.28,7.28,0,0,0-9.4-.3L2.81,120A7.43,7.43,0,0,0,0,125.5a7.14,7.14,0,0,0,2.4,5.7A37.28,37.28,0,0,0,27,140.7h210.7a19.59,19.59,0,0,1,18.9,14.4v.2c.1.7,1.1,4.4,8.5,4.4s8.4-3.7,8.5-4.4v-.2a19.59,19.59,0,0,1,18.9-14.4h206.7a37.28,37.28,0,0,0,24.6-9.5,7.42,7.42,0,0,0,2.4-5.7A8.1,8.1,0,0,0,523.31,120Z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 5.1 KiB |
5
docker/php.ini
Normal file
5
docker/php.ini
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
upload_max_filesize = 500M
|
||||||
|
memory_limit = 1024M
|
||||||
|
post_max_size = 500M
|
||||||
|
sendmail_path = /usr/bin/msmtp -C /etc/msmtprc -t
|
||||||
|
sendmail_from = 'wordpress@mp3.localhost'
|
44
docker/php74/Dockerfile
Normal file
44
docker/php74/Dockerfile
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
FROM wordpress:php7.4
|
||||||
|
|
||||||
|
ARG UID=1000
|
||||||
|
ARG GID=1000
|
||||||
|
|
||||||
|
# additinal extensions
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y git zlib1g-dev wget gnupg msmtp \
|
||||||
|
&& docker-php-ext-install pdo_mysql \
|
||||||
|
&& pecl install xdebug-2.9.8 && \
|
||||||
|
\
|
||||||
|
# Install NodeJS + NPM
|
||||||
|
curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
|
||||||
|
apt-get install -y nodejs build-essential && \
|
||||||
|
\
|
||||||
|
# Install WP-CLI
|
||||||
|
curl -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
|
||||||
|
chmod +x /usr/local/bin/wp && \
|
||||||
|
\
|
||||||
|
# Installing Transifex Client
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y python3-pip gettext zip subversion && \
|
||||||
|
pip install transifex-client && \
|
||||||
|
\
|
||||||
|
# Clean up
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
COPY docker/php.ini /usr/local/etc/php/conf.d/php_user.ini
|
||||||
|
|
||||||
|
# msmtp config
|
||||||
|
RUN printf "account default\nhost smtp\nport 1025" > /etc/msmtprc
|
||||||
|
|
||||||
|
# xdebug config
|
||||||
|
ENV XDEBUGINI_PATH=/usr/local/etc/php/conf.d/xdebug.ini
|
||||||
|
RUN echo "zend_extension="`find /usr/local/lib/php/extensions/ -iname 'xdebug.so'` > $XDEBUGINI_PATH
|
||||||
|
COPY docker/php74/xdebug.ini /tmp/xdebug.ini
|
||||||
|
RUN cat /tmp/xdebug.ini >> $XDEBUGINI_PATH
|
||||||
|
|
||||||
|
# allow .htaccess files (between <Directory /var/www/> and </Directory>, which is WordPress installation)
|
||||||
|
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
||||||
|
|
||||||
|
# ensure existing content in /var/www/html respects UID and GID
|
||||||
|
RUN chown -R ${UID}:${GID} /var/www/html
|
9
docker/php74/xdebug.ini
Normal file
9
docker/php74/xdebug.ini
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
xdebug.remote_enable=on
|
||||||
|
xdebug.remote_autostart=on
|
||||||
|
xdebug.remote_connect_back=off
|
||||||
|
xdebug.remote_handler=dbgp
|
||||||
|
xdebug.profiler_enable=0
|
||||||
|
xdebug.profiler_output_dir="/var/www/html"
|
||||||
|
xdebug.remote_host=host.docker.internal
|
||||||
|
xdebug.remote_port=9000
|
||||||
|
# xdebug.remote_log="/var/www/html/xdebug_remote.log"
|
48
docker/php80/Dockerfile
Normal file
48
docker/php80/Dockerfile
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
FROM wordpress:php8.0
|
||||||
|
|
||||||
|
ARG UID=1000
|
||||||
|
ARG GID=1000
|
||||||
|
|
||||||
|
# additinal extensions
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y git zlib1g-dev libzip-dev zip wget gnupg msmtp libpng-dev \
|
||||||
|
&& \
|
||||||
|
# Install NodeJS + NPM
|
||||||
|
curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
|
||||||
|
apt-get install -y nodejs build-essential && \
|
||||||
|
\
|
||||||
|
# Install WP-CLI
|
||||||
|
curl -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
|
||||||
|
chmod +x /usr/local/bin/wp && \
|
||||||
|
\
|
||||||
|
# Installing Transifex Client
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y python3-pip gettext subversion && \
|
||||||
|
pip3 install transifex-client && \
|
||||||
|
\
|
||||||
|
# Clean up
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
COPY docker/php.ini /usr/local/etc/php/conf.d/php_user.ini
|
||||||
|
|
||||||
|
# msmtp config
|
||||||
|
RUN printf "account default\nhost smtp\nport 1025" > /etc/msmtprc
|
||||||
|
|
||||||
|
# xdebug build an config
|
||||||
|
ENV XDEBUGINI_PATH=/usr/local/etc/php/conf.d/xdebug.ini
|
||||||
|
RUN git clone -b "3.0.2" --depth 1 https://github.com/xdebug/xdebug.git /usr/src/php/ext/xdebug \
|
||||||
|
&& docker-php-ext-configure xdebug --enable-xdebug-dev \
|
||||||
|
&& docker-php-ext-install xdebug \
|
||||||
|
&& mkdir /tmp/debug
|
||||||
|
COPY docker/xdebug.ini /tmp/xdebug.ini
|
||||||
|
RUN cat /tmp/xdebug.ini >> $XDEBUGINI_PATH
|
||||||
|
|
||||||
|
# php extensions
|
||||||
|
RUN docker-php-ext-install pdo_mysql
|
||||||
|
|
||||||
|
# allow .htaccess files (between <Directory /var/www/> and </Directory>, which is WordPress installation)
|
||||||
|
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
||||||
|
|
||||||
|
# ensure existing content in /var/www/html respects UID and GID
|
||||||
|
RUN chown -R ${UID}:${GID} /var/www/html
|
48
docker/php81/Dockerfile
Normal file
48
docker/php81/Dockerfile
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
FROM wordpress:php8.1-apache
|
||||||
|
|
||||||
|
ARG UID=1000
|
||||||
|
ARG GID=1000
|
||||||
|
|
||||||
|
# additinal extensions
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y git zlib1g-dev libzip-dev zip wget gnupg msmtp libpng-dev \
|
||||||
|
&& \
|
||||||
|
# Install NodeJS + NPM
|
||||||
|
curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
|
||||||
|
apt-get install -y nodejs build-essential && \
|
||||||
|
\
|
||||||
|
# Install WP-CLI
|
||||||
|
curl -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
|
||||||
|
chmod +x /usr/local/bin/wp && \
|
||||||
|
\
|
||||||
|
# Installing Transifex Client
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y python3-pip gettext subversion && \
|
||||||
|
pip3 install transifex-client && \
|
||||||
|
\
|
||||||
|
# Clean up
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
COPY docker/php.ini /usr/local/etc/php/conf.d/php_user.ini
|
||||||
|
|
||||||
|
# msmtp config
|
||||||
|
RUN printf "account default\nhost smtp\nport 1025" > /etc/msmtprc
|
||||||
|
|
||||||
|
# xdebug build an config
|
||||||
|
ENV XDEBUGINI_PATH=/usr/local/etc/php/conf.d/xdebug.ini
|
||||||
|
RUN git clone -b "3.1.1" --depth 1 https://github.com/xdebug/xdebug.git /usr/src/php/ext/xdebug \
|
||||||
|
&& docker-php-ext-configure xdebug --enable-xdebug-dev \
|
||||||
|
&& docker-php-ext-install xdebug \
|
||||||
|
&& mkdir /tmp/debug
|
||||||
|
COPY docker/xdebug.ini /tmp/xdebug.ini
|
||||||
|
RUN cat /tmp/xdebug.ini >> $XDEBUGINI_PATH
|
||||||
|
|
||||||
|
# php extensions
|
||||||
|
RUN docker-php-ext-install pdo_mysql
|
||||||
|
|
||||||
|
# allow .htaccess files (between <Directory /var/www/> and </Directory>, which is WordPress installation)
|
||||||
|
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
||||||
|
|
||||||
|
# ensure existing content in /var/www/html respects UID and GID
|
||||||
|
RUN chown -R ${UID}:${GID} /var/www/html
|
6
docker/xdebug.ini
Normal file
6
docker/xdebug.ini
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
xdebug.mode=debug
|
||||||
|
xdebug.output_dir="/var/www/html"
|
||||||
|
xdebug.client_host=host.docker.internal
|
||||||
|
xdebug.client_port=9000
|
||||||
|
xdebug.discover_client_host=On
|
||||||
|
# xdebug.log="/var/www/html/xdebug.log"
|
68
initial-setup.sh
Executable file
68
initial-setup.sh
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
git clone git@github.com:mailpoet/mailpoet.git
|
||||||
|
git clone git@github.com:mailpoet/mailpoet-premium.git
|
||||||
|
|
||||||
|
# Save current UID and GID to .env so we can run images with current user
|
||||||
|
# to avoid any potential problems with file permissions (mainly on Linux).
|
||||||
|
cat <<EOT > .env
|
||||||
|
UID=$(id -u)
|
||||||
|
UID=$(id -g)
|
||||||
|
EOT
|
||||||
|
|
||||||
|
cat <<EOT > mailpoet/.env
|
||||||
|
|
||||||
|
WP_ROOT="/var/www/html"
|
||||||
|
WP_TEST_CACHE_PATH="/tmp"
|
||||||
|
WP_TEST_MAILER_ENABLE_SENDING="true"
|
||||||
|
WP_TEST_ENABLE_NETWORK_TESTS="true"
|
||||||
|
|
||||||
|
# get following secrets from the Secret Store. Look for "MailPoet plugin .env"
|
||||||
|
WP_TRANSIFEX_API_TOKEN=
|
||||||
|
WP_TEST_IMPORT_MAILCHIMP_API=
|
||||||
|
WP_TEST_IMPORT_MAILCHIMP_LISTS=
|
||||||
|
WP_TEST_MAILER_AMAZON_ACCESS=
|
||||||
|
WP_TEST_MAILER_AMAZON_SECRET=
|
||||||
|
WP_TEST_MAILER_AMAZON_REGION=
|
||||||
|
WP_TEST_MAILER_MAILPOET_API=
|
||||||
|
WP_TEST_MAILER_SENDGRID_API=
|
||||||
|
WP_TEST_MAILER_SMTP_HOST=
|
||||||
|
WP_TEST_MAILER_SMTP_LOGIN=
|
||||||
|
WP_TEST_MAILER_SMTP_PASSWORD=
|
||||||
|
WP_SVN_USERNAME=
|
||||||
|
WP_SVN_PASSWORD=
|
||||||
|
WP_SLACK_WEBHOOK_URL=
|
||||||
|
WP_CIRCLECI_USERNAME=
|
||||||
|
WP_CIRCLECI_TOKEN=
|
||||||
|
|
||||||
|
# get GitHub token from https://github.com/settings/tokens with repo access
|
||||||
|
WP_GITHUB_USERNAME=
|
||||||
|
WP_GITHUB_TOKEN=
|
||||||
|
|
||||||
|
# get Jira token from https://id.atlassian.com/manage/api-tokens
|
||||||
|
WP_JIRA_USER=
|
||||||
|
WP_JIRA_TOKEN=
|
||||||
|
|
||||||
|
EOT
|
||||||
|
cp mailpoet/.env mailpoet-premium
|
||||||
|
echo "MAILPOET_FREE_PATH=/var/www/html/wp-content/plugins/mailpoet" >> mailpoet-premium/.env
|
||||||
|
|
||||||
|
# create Docker mount endpoints beforehand with current user (Docker would create them as root)
|
||||||
|
mkdir -p wordpress/wp-content/plugins/mailpoet
|
||||||
|
mkdir -p wordpress/wp-content/plugins/mailpoet-premium
|
||||||
|
mkdir -p fake_mail_output
|
||||||
|
|
||||||
|
for plugin in "mailpoet" "mailpoet-premium"; do
|
||||||
|
docker-compose run --rm wordpress /bin/sh -c "
|
||||||
|
cd /var/www/html/wp-content/plugins/$plugin &&
|
||||||
|
./do install &&
|
||||||
|
./do compile:all
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
|
docker-compose run --rm wordpress /bin/sh -c "
|
||||||
|
cd /var/www/templates &&
|
||||||
|
mkdir assets classes exported
|
||||||
|
"
|
||||||
|
echo 'Don‘t forget to configure environment variables in .env files in ./mailpoet and ./mailpoet-premium'
|
||||||
|
echo 'You can run the environment by executing "./do start" and visiting http://localhost:8002'
|
34
mac-nfs-setup.sh
Executable file
34
mac-nfs-setup.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# ensure this is run on MacOS
|
||||||
|
if [ "$(uname -s)" != "Darwin" ]; then
|
||||||
|
(>&2 echo "This script can only be run on MacOS.")
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ensure root privileges
|
||||||
|
if [ $EUID -ne 0 ]; then
|
||||||
|
(>&2 echo "This script must be run with sudo.")
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# add shared file settings for current user to /etc/exports (if not set yet)
|
||||||
|
LINE="/System/Volumes/Data/Users -alldirs -mapall="$SUDO_USER":$(id -gn "$SUDO_USER") localhost"
|
||||||
|
FILE=/etc/exports
|
||||||
|
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
|
||||||
|
|
||||||
|
# add NFS settings to /etc/nfs.conf (if not set yet)
|
||||||
|
LINE="nfs.server.mount.require_resv_port = 0"
|
||||||
|
FILE=/etc/nfs.conf
|
||||||
|
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
|
||||||
|
|
||||||
|
# restart NFS server
|
||||||
|
nfsd restart
|
||||||
|
|
||||||
|
cat <<EOT
|
||||||
|
NFS volume sharing is set up. Recreate your containers and volumes using:
|
||||||
|
cp docker-compose.override.macos-sample.yml docker-compose.override.yml
|
||||||
|
|
||||||
|
docker-compose down -v --remove-orphans
|
||||||
|
docker-compose up -d
|
||||||
|
EOT
|
82
readme.md
Normal file
82
readme.md
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
# MailPoet
|
||||||
|
The **MailPoet** development environment.
|
||||||
|
|
||||||
|
## 🔌 Initial setup
|
||||||
|
1) Run `./do setup` to pull everything and install necessary dependencies.
|
||||||
|
2) Add secrets to `.env` files in `mailpoet-dev-env/mailpoet` and `mailpoet-dev-env/mailpoet-premium`. Go to the Secret Store and look for "MailPoet: plugin .env"
|
||||||
|
3) Run `./do start` to start the stack.
|
||||||
|
4) Go to http://localhost:8888 to see the dashboard of the dev environment.
|
||||||
|
|
||||||
|
|
||||||
|
## 🔍 PHPStorm setup for XDebug
|
||||||
|
In `Languages & Preferences > PHP > Servers` set path mappings:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mailpoet-dev-env/wordpress -> /var/www/html
|
||||||
|
mailpoet-dev-env/mailpoet -> /var/www/html/wp-content/plugins/mailpoet
|
||||||
|
mailpoet-dev-env/mailpoet-premium -> /var/www/html/wp-content/plugins/mailpoet-premium
|
||||||
|
```
|
||||||
|
|
||||||
|
For PHP 8 and XDebug 3 we support **browser debugging extension**.
|
||||||
|
You can choose extension by your browser in [JetBrains documentation](https://www.jetbrains.com/help/phpstorm/browser-debugging-extensions.html).
|
||||||
|
|
||||||
|
To use XDebug inside the **cron**, you need to pass a URL argument `&XDEBUG_TRIGGER=yes`
|
||||||
|
[in the cron request](https://github.com/mailpoet/mailpoet/blob/bf7bd6d2d9090ed6ec7b8b575bb7d6b08e663a52/lib/Cron/CronHelper.php#L155-L166).
|
||||||
|
Alternatively, you can add `XDEBUG_TRIGGER: yes` to the `wordpress` service in `docker-compose.yml` and restart it (which will run XDebug also for all other requests).
|
||||||
|
|
||||||
|
## 💾 NFS volume sharing for Mac
|
||||||
|
NFS volumes can bring more stability and performance on Docker for Mac. To setup NFS volume sharing run:
|
||||||
|
```shell
|
||||||
|
sudo sh mac-nfs-setup.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Then create a Docker Compose override file with NFS settings and restart containers:
|
||||||
|
```shell
|
||||||
|
cp docker-compose.override.macos-sample.yml docker-compose.override.yml
|
||||||
|
|
||||||
|
docker-compose down -v --remove-orphans
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🕹 Commands
|
||||||
|
The `./do` script define aliases for most of the commands you will need while working on plugins:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./do setup Setup the environment.
|
||||||
|
./do start Start the docker containers.
|
||||||
|
./do stop Stop the docker containers.
|
||||||
|
./do ssh [--test] Run an interactive bash shell inside the plugin directory.
|
||||||
|
./do run [--test] <command> Run a custom bash command in the wordpress container.
|
||||||
|
./do acceptance [--premium] Run acceptance tests.
|
||||||
|
./do build [--premium] Builds a .zip for the plugin.
|
||||||
|
./do templates Generates templates classes and assets.
|
||||||
|
./do [--test] [--premium] <command> Run './do <command>' inside the plugin directory.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--test Run the command using the 'test_wordpress' service.
|
||||||
|
--premium Run the command inside the premium plugin.
|
||||||
|
```
|
||||||
|
|
||||||
|
You can access this help in your command line running `./do` without parameters.
|
||||||
|
|
||||||
|
## ✉️ Adding new templates to the plugin
|
||||||
|
[Read the article.](https://mailpoet.atlassian.net/wiki/spaces/MAILPOET/pages/629374977/Adding+new+templates+to+the+plugin)
|
||||||
|
|
||||||
|
## 🚥 Testing with PHP 7.4 or PHP 8.1
|
||||||
|
To switch the environment to PHP 7.4/8.1:
|
||||||
|
1) Configure the `wordpress` service in `docker-compose.override.yml` to build from the php74 Dockerfile:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
wordpress:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: docker/php74/Dockerfile # OR docker/php81/Dockerfile
|
||||||
|
```
|
||||||
|
3) Run `docker-compose build wordpress`.
|
||||||
|
4) Start the stack with `./do start`.
|
||||||
|
|
||||||
|
To switch back to PHP 8 remove what was added in 1) and, run `docker-compose build wordpress` for application container and `docker-compose build test_wordpress` for tests container,
|
||||||
|
and start the stack using `./do start`.
|
||||||
|
|
||||||
|
## ✅ TODO
|
||||||
|
- install woo commerce, members and other useful plugins by default
|
5
templates/.gitignore
vendored
Normal file
5
templates/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
vendor
|
||||||
|
assets
|
||||||
|
classes
|
||||||
|
exported
|
||||||
|
composer.phar
|
33
templates/Class.php.tpl
Normal file
33
templates/Class.php.tpl
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Config\PopulatorData\Templates;
|
||||||
|
|
||||||
|
class {{class_name}} {
|
||||||
|
|
||||||
|
private $template_image_url;
|
||||||
|
private $social_icon_url;
|
||||||
|
|
||||||
|
function __construct($assets_url) {
|
||||||
|
$this->template_image_url = 'https://ps.w.org/mailpoet/assets/newsletter-templates/{{dir_name}}';
|
||||||
|
$this->social_icon_url = $assets_url . '/img/newsletter_editor/social-icons';
|
||||||
|
}
|
||||||
|
|
||||||
|
function get() {
|
||||||
|
return array(
|
||||||
|
'name' => __("{{template_name}}", 'mailpoet'),
|
||||||
|
'categories' => json_encode(array('{{category}}', 'all')),
|
||||||
|
'readonly' => 1,
|
||||||
|
'thumbnail' => $this->getThumbnail(),
|
||||||
|
'body' => json_encode($this->getBody()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getThumbnail() {
|
||||||
|
return $this->template_image_url . '/thumbnail.jpg';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBody() {
|
||||||
|
return {{body}};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
templates/composer.json
Normal file
6
templates/composer.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "mailpoet/templates",
|
||||||
|
"require": {
|
||||||
|
"tarsana/functional": "^2.2"
|
||||||
|
}
|
||||||
|
}
|
66
templates/composer.lock
generated
Normal file
66
templates/composer.lock
generated
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"content-hash": "a607345ee7a66b12b9ee1d37141baa67",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "tarsana/functional",
|
||||||
|
"version": "2.2.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/tarsana/functional.git",
|
||||||
|
"reference": "77ab9cbe8e44865edb686c07cc0848d8a950ed19"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/tarsana/functional/zipball/77ab9cbe8e44865edb686c07cc0848d8a950ed19",
|
||||||
|
"reference": "77ab9cbe8e44865edb686c07cc0848d8a950ed19",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "~4.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Tarsana\\Functional\\": "src/Classes/",
|
||||||
|
"Tarsana\\UnitTests\\Functional\\": "tests/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/Internal/_functions.php",
|
||||||
|
"src/Internal/_stream.php",
|
||||||
|
"src/functions.php",
|
||||||
|
"src/operators.php",
|
||||||
|
"src/common.php",
|
||||||
|
"src/object.php",
|
||||||
|
"src/string.php",
|
||||||
|
"src/list.php",
|
||||||
|
"src/math.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Amine Ben hammou",
|
||||||
|
"email": "webneat@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "functional programming library for PHP",
|
||||||
|
"time": "2018-07-21T01:02:03+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": [],
|
||||||
|
"platform-dev": []
|
||||||
|
}
|
7
templates/config.php
Normal file
7
templates/config.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
return (object) [
|
||||||
|
'templatesDir' => __DIR__ . '/exported',
|
||||||
|
'assetsDir' => __DIR__ . '/assets',
|
||||||
|
'classesDir' => __DIR__ . '/classes',
|
||||||
|
'classTemplatePath' => __DIR__ . '/Class.php.tpl',
|
||||||
|
];
|
197
templates/generate.php
Normal file
197
templates/generate.php
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
<?php
|
||||||
|
require __DIR__.'/vendor/autoload.php';
|
||||||
|
|
||||||
|
use Tarsana\Functional as F;
|
||||||
|
|
||||||
|
function main(object $config) : void {
|
||||||
|
$generate = F\curry('generate');
|
||||||
|
F\each(
|
||||||
|
$generate($config),
|
||||||
|
loadTemplates($config->templatesDir)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadTemplates(string $templatesDir) : array {
|
||||||
|
return F\s(glob("{$templatesDir}/*.json"))
|
||||||
|
->map(F\pipe('file_get_contents', function($content) {
|
||||||
|
return json_decode($content, true);
|
||||||
|
}))
|
||||||
|
->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
function generate(object $config, array $template) : void {
|
||||||
|
$templateDir = makeTemplateDirectory($config->assetsDir, $template);
|
||||||
|
$classTemplate = file_get_contents($config->classTemplatePath);
|
||||||
|
F\s($template)
|
||||||
|
->saveThumbnail($templateDir)
|
||||||
|
->normalizeBody($templateDir)
|
||||||
|
->renderBody()
|
||||||
|
->renderTemplate($classTemplate)
|
||||||
|
->saveTemplate($config->classesDir)
|
||||||
|
->result();
|
||||||
|
echo $template['name'], ' generated!', PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeTemplateDirectory(string $assetsDir, array $template) : string {
|
||||||
|
$path = $assetsDir. '/' . getDirectoryName($template);
|
||||||
|
if (!is_dir($path) && !mkdir($path))
|
||||||
|
throw new \Exception("Unable to create directory '{$path}'!");
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveThumbnail(string $templateDir, array $template) : array {
|
||||||
|
$thumbnail = substr($template['thumbnail'], 23); // 'data:image/jpeg;base64,' is 23 chars
|
||||||
|
file_put_contents($templateDir.'/thumbnail.jpg', base64_decode($thumbnail));
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
F\Stream::operation('saveThumbnail', 'String -> Array -> Array');
|
||||||
|
|
||||||
|
function normalizeBody(string $templateDir, array $template) : array {
|
||||||
|
$template['body'] = F\s($template['body'])
|
||||||
|
->removeContainerDefaults()
|
||||||
|
->downloadAndReplaceImages($templateDir)
|
||||||
|
->replaceSocialIconURLs()
|
||||||
|
->result();
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
F\Stream::operation('normalizeBody', 'String -> Array -> Array');
|
||||||
|
|
||||||
|
function renderBody(array $template) : array {
|
||||||
|
$template['body'] = F\s($template['body'])
|
||||||
|
->then('export')
|
||||||
|
->render([
|
||||||
|
'image_url' => '\' . $this->template_image_url . \'',
|
||||||
|
'icon_url' => '\' . $this->social_icon_url . \''
|
||||||
|
])
|
||||||
|
->replace("'' . ", '')
|
||||||
|
->split("\n")
|
||||||
|
->map(F\prepend(" "))
|
||||||
|
->join("\n")
|
||||||
|
->then('trim')
|
||||||
|
->result();
|
||||||
|
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
F\Stream::operation('renderBody', 'Array -> Array');
|
||||||
|
|
||||||
|
function renderTemplate(string $classTemplate, array $template) : array {
|
||||||
|
$template['body'] = render([
|
||||||
|
'class_name' => getClassName($template),
|
||||||
|
'dir_name' => getDirectoryName($template),
|
||||||
|
'template_name' => $template['name'],
|
||||||
|
'category' => getCategory($template),
|
||||||
|
'body' => $template['body']
|
||||||
|
], $classTemplate);
|
||||||
|
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
F\Stream::operation('renderTemplate', 'String -> Array -> Array');
|
||||||
|
|
||||||
|
function saveTemplate(string $classesDir, array $template) : void {
|
||||||
|
file_put_contents($classesDir . '/' . getClassName($template) . '.php', $template['body']);
|
||||||
|
}
|
||||||
|
F\Stream::operation('saveTemplate', 'String -> Array -> Null');
|
||||||
|
|
||||||
|
function removeContainerDefaults(array $body) : array {
|
||||||
|
unset($body['blockDefaults']['container']);
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
F\Stream::operation('removeContainerDefaults', 'Array -> Array');
|
||||||
|
|
||||||
|
function downloadAndReplaceImages(string $templateDir, array $block) : array {
|
||||||
|
if (!empty($block['content'])) {
|
||||||
|
$block['content'] = downloadAndReplaceImages($templateDir, $block['content']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($block['type'] == 'image' && !empty($block['src'])) {
|
||||||
|
$block['src'] = downloadImage($templateDir, $block['src']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($block['image']) && !empty($block['image']['src'])) {
|
||||||
|
$block['image']['src'] = downloadImage($templateDir, $block['image']['src']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($block['blocks'])) {
|
||||||
|
foreach ($block['blocks'] as $i => $innerBlock) {
|
||||||
|
$block['blocks'][$i] = downloadAndReplaceImages($templateDir, $innerBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $block;
|
||||||
|
}
|
||||||
|
F\Stream::operation('downloadAndReplaceImages', 'String -> Array -> Array');
|
||||||
|
|
||||||
|
function replaceSocialIconURLs(array $block) : array {
|
||||||
|
if (!empty($block['content'])) {
|
||||||
|
$block['content'] = replaceSocialIconURLs($block['content']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($block['blockDefaults']) && !empty($block['blockDefaults']['social'])) {
|
||||||
|
$block['blockDefaults']['social'] = replaceSocialIconURLs($block['blockDefaults']['social']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($block['type'] == 'socialIcon' && !empty($block['image'])) {
|
||||||
|
$block['image'] = F\s($block['image'])
|
||||||
|
->split('?')
|
||||||
|
->head()
|
||||||
|
->split('/')
|
||||||
|
->take(-2)
|
||||||
|
->prepend('{{icon_url}}')
|
||||||
|
->join('/')
|
||||||
|
->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($block['icons'])) {
|
||||||
|
foreach ($block['icons'] as $i => $icon) {
|
||||||
|
$block['icons'][$i] = replaceSocialIconURLs($icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($block['blocks'])) {
|
||||||
|
foreach ($block['blocks'] as $i => $innerBlock) {
|
||||||
|
$block['blocks'][$i] = replaceSocialIconURLs($innerBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $block;
|
||||||
|
}
|
||||||
|
F\Stream::operation('replaceSocialIconURLs', 'Array -> Array');
|
||||||
|
|
||||||
|
function render(array $data, string $text) : string {
|
||||||
|
foreach ($data as $name => $value) {
|
||||||
|
$text = str_replace('{{'.$name.'}}', $value, $text);
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
F\Stream::operation('render', 'Array -> String -> String');
|
||||||
|
|
||||||
|
|
||||||
|
function getDirectoryName(array $template) : string {
|
||||||
|
return F\snakeCase('-', $template['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getClassName(array $template) : string {
|
||||||
|
return ucfirst(F\camelCase($template['name']));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCategory(array $template) : string {
|
||||||
|
$categories = json_decode($template['categories']);
|
||||||
|
return $categories[0] == 'saved' ? $categories[1] : $categories[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadImage($templateDir, $src) {
|
||||||
|
$name = F\s($src)
|
||||||
|
->split('/')
|
||||||
|
->last()
|
||||||
|
->split('?')
|
||||||
|
->head()
|
||||||
|
->result();
|
||||||
|
file_put_contents($templateDir . '/' . $name, file_get_contents($src));
|
||||||
|
return '{{image_url}}/' . $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function export($variable) : string {
|
||||||
|
return var_export($variable, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
main(require __DIR__.'/config.php');
|
Reference in New Issue
Block a user