-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-wp-project.sh
executable file
·83 lines (63 loc) · 2.47 KB
/
create-wp-project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -euo pipefail
echo "Let's create a new WordPress project"
echo
# Check for dependencies
declare -a DEPENDENCIES=("composer" "jq")
for DEPENDENCY in "${DEPENDENCIES[@]}"; do
if ! command -v $DEPENDENCY &> /dev/null; then
echo "$DEPENDENCY could not be found, please install it and try again."
exit 1
fi
done
git config --global --add safe.directory '*'
# # Install the Bedrock WordPress boilerplate
composer create-project roots/bedrock temp
# Give temporary directory permissions
chmod 777 temp
# Move into the temporary directory
cd temp
# Patch application.php
patch -p1 -N < ../resources/application.php.patch.1
patch -p1 -N < ../resources/application.php.patch.2
# Define a function to append a value to composer.json scripts array of a given key (or create it if it doesn't exist)
function composer_scripts_add {
local KEY="$1"
local VALUE="$2"
# Check if the key already exists
local SCRIPT_EXISTS=$(jq -r ".scripts | has(\"$KEY\")" composer.json)
# If the key exists, append the new value to the array
if [ "$SCRIPT_EXISTS" == "true" ]; then
jq --arg key "$KEY" --arg value "$VALUE" '.scripts[$key] += [$value]' composer.json > composer.json.tmp
# If not, create it as a new array
else
jq --arg key "$KEY" --arg value "$VALUE" '.scripts[$key] = [$value]' composer.json > composer.json.tmp
fi
# Rename the temporary file back to composer.json
mv composer.json.tmp composer.json
}
# Set Composer scripts
composer_scripts_add "setup-drop-ins" "cp web/app/plugins/redis-cache/includes/object-cache.php web/app/object-cache.php"
composer_scripts_add "setup-drop-ins" "ln -fs \$(pwd)/web/app/plugins/query-monitor/wp-content/db.php web/app/db.php"
composer_scripts_add "post-install-cmd" "@setup-drop-ins"
composer_scripts_add "post-update-cmd" "@setup-drop-ins"
# Merge our composer.json with the Bedrock composer.json
jq -s ".[0] * .[1]" "composer.json" "../resources/composer.json" > composer.json.tmp
mv composer.json.tmp composer.json
composer config --no-plugins allow-plugins.koodimonni/composer-dropin-installer true
# Install some packages
composer require -n \
php ">=8.1" \
wp-cli/wp-cli-bundle \
wpackagist-plugin/redis-cache \
wpackagist-plugin/query-monitor \
koodimonni-language/core-fi \
koodimonni/composer-dropin-installer \
10up/elasticpress
# Move all to root directory
cp -r * ../
cd ../
rm -rf temp
# Remove this script
rm create-wp-project.sh
echo "Done!"