@codigodoleo/wp-kit 5.2.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/init.js +35 -27
- package/lib/config/versions.js +32 -5
- package/lib/core/cloud-allowlist.js +38 -0
- package/lib/core/generator.js +56 -50
- package/lib/core/infer-ci-capabilities.js +17 -5
- package/lib/prompts/index.js +106 -8
- package/lib/utils/auth-template.js +18 -0
- package/lib/utils/env-example.js +28 -0
- package/modules/blank-theme/index.js +1 -1
- package/modules/deploy/index.js +18 -0
- package/modules/deploy/scripts/check-exposure.sh +63 -0
- package/modules/deploy/templates/.github/workflows/ci.yml.hbs +37 -2
- package/modules/deploy/templates/renovate.json.hbs +4 -0
- package/modules/docs/index.js +18 -18
- package/modules/docs/templates/README.md.hbs +1 -1
- package/modules/docs/templates/docs/Arquitetura.md.hbs +2 -2
- package/modules/docs/templates/docs/Deploy-Pipeline.md.hbs +21 -1
- package/modules/docs/templates/docs/{Desenvolvimento.md.hbs → Development.md.hbs} +80 -2
- package/modules/docs/templates/docs/Getting-Started.md.hbs +75 -4
- package/modules/docs/templates/docs/Infraestrutura.md.hbs +1 -1
- package/modules/docs/templates/docs/Troubleshooting.md.hbs +18 -1
- package/modules/git/.husky/kivo-wp/commit-msg +3 -0
- package/modules/git/.husky/kivo-wp/pre-commit +25 -0
- package/modules/git/.husky/pre-commit +3 -7
- package/modules/git/index.js +75 -57
- package/modules/git/templates/.lando.yml.hbs +5 -0
- package/modules/git/templates/package.json.hbs +1 -1
- package/modules/kivo-wp/fixtures/menus.json +11 -0
- package/modules/kivo-wp/fixtures/options.json +10 -0
- package/modules/kivo-wp/fixtures/posts.json +58 -0
- package/modules/kivo-wp/fixtures/seed.php +152 -0
- package/modules/kivo-wp/fixtures/terms.json +6 -0
- package/modules/kivo-wp/fixtures/users.json +26 -0
- package/modules/kivo-wp/index.js +193 -0
- package/modules/kivo-wp/prompts.js +1 -0
- package/modules/kivo-wp/templates/.devcontainer/devcontainer.json.hbs +40 -0
- package/modules/kivo-wp/templates/.dockerignore.hbs +15 -0
- package/modules/kivo-wp/templates/Dockerfile.hbs +81 -0
- package/modules/kivo-wp/templates/bin/_lib.sh.hbs +116 -0
- package/modules/kivo-wp/templates/bin/build.hbs +13 -0
- package/modules/kivo-wp/templates/bin/composer.hbs +6 -0
- package/modules/kivo-wp/templates/bin/db-export.hbs +8 -0
- package/modules/kivo-wp/templates/bin/db-import.hbs +20 -0
- package/modules/kivo-wp/templates/bin/db.hbs +9 -0
- package/modules/kivo-wp/templates/bin/dev.hbs +7 -0
- package/modules/kivo-wp/templates/bin/down.hbs +34 -0
- package/modules/kivo-wp/templates/bin/e2e.hbs +20 -0
- package/modules/kivo-wp/templates/bin/flush.hbs +11 -0
- package/modules/kivo-wp/templates/bin/info.hbs +15 -0
- package/modules/kivo-wp/templates/bin/logs.hbs +6 -0
- package/modules/kivo-wp/templates/bin/mago.hbs +6 -0
- package/modules/kivo-wp/templates/bin/node.hbs +6 -0
- package/modules/kivo-wp/templates/bin/npm.hbs +6 -0
- package/modules/kivo-wp/templates/bin/php.hbs +6 -0
- package/modules/kivo-wp/templates/bin/reset-deps.hbs +11 -0
- package/modules/kivo-wp/templates/bin/seed.hbs +19 -0
- package/modules/kivo-wp/templates/bin/setup.hbs +283 -0
- package/modules/kivo-wp/templates/bin/shell.hbs +14 -0
- package/modules/kivo-wp/templates/bin/stan.hbs +6 -0
- package/modules/kivo-wp/templates/bin/test.hbs +6 -0
- package/modules/kivo-wp/templates/bin/trust-cert.hbs +21 -0
- package/modules/kivo-wp/templates/bin/up.hbs +6 -0
- package/modules/kivo-wp/templates/bin/wp.hbs +6 -0
- package/modules/kivo-wp/templates/bin/xdebug.hbs +22 -0
- package/modules/kivo-wp/templates/compose.yaml.hbs +117 -0
- package/modules/kivo-wp/templates/content/mu-plugins/kivo-wp-local-mail.php.hbs +29 -0
- package/modules/kivo-wp/templates/docs/cloud-sessions.md.hbs +34 -0
- package/modules/kivo-wp/templates/server/caddy/Caddyfile.hbs +44 -0
- package/modules/kivo-wp/templates/server/nginx/deny.conf.hbs +26 -0
- package/modules/lint/.prettierignore +3 -4
- package/modules/lint/index.js +14 -10
- package/modules/lint/templates/package.json.hbs +6 -0
- package/modules/php/index.js +13 -1
- package/modules/php/kivo-wp/php-wrapper.sh +3 -0
- package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
- package/modules/sage/index.js +7 -24
- package/modules/sage/templates/bin/theme-lint.hbs +6 -0
- package/modules/sage/templates/server/cmd/setup-sage-node.sh.hbs +3 -1
- package/modules/sage/templates/server/cmd/setup-sage-php.sh.hbs +3 -1
- package/modules/sage/templates/theme/vite.config.js.hbs +25 -4
- package/modules/sage/templates/workspace.json.hbs +0 -57
- package/modules/test/index.js +12 -11
- package/modules/test/templates/playwright.config.js.hbs +12 -0
- package/modules/test/tests/e2e/smoke.spec.js +28 -0
- package/package.json +3 -2
- package/templates/.env.hbs +16 -5
- package/templates/.gitignore.hbs +12 -1
- package/templates/.lando.yml.hbs +5 -11
- package/templates/CLAUDE.md.hbs +19 -2
- package/templates/package.json.hbs +8 -1
- package/templates/server/cmd/install-wp.sh.hbs +1 -1
- package/templates/server/cmd/setup-node.sh.hbs +3 -1
- package/templates/server/cmd/setup-php.sh.hbs +63 -9
- package/templates/workspace.json.hbs +0 -56
- package/{wp-config.php → templates/wp-config.php.hbs} +41 -5
- package/modules/lint/templates/.lando.yml.hbs +0 -5
- package/modules/sage/templates/.devcontainer/devcontainer.json.hbs +0 -7
- package/modules/sage/templates/.devcontainer/docker-compose.override.yml.hbs +0 -4
- package/modules/sage/templates/.devcontainer/post-create.sh.hbs +0 -11
- package/templates/.devcontainer/Dockerfile.hbs +0 -24
- package/templates/.devcontainer/config/nginx.conf +0 -23
- package/templates/.devcontainer/config/nginx.conf.hbs +0 -23
- package/templates/.devcontainer/devcontainer.json.hbs +0 -29
- package/templates/.devcontainer/docker-compose.yml.hbs +0 -76
- package/templates/.devcontainer/setup.sh.hbs +0 -17
- package/templates/auth.json.hbs +0 -8
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Import a SQL dump (.sql or .sql.gz) into the local database. Human-only, local only (D-002).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
# Snapshots never reach CI, Codespaces or cloud agent sessions (D-002, D-007).
|
|
7
|
+
for marker in CI CODESPACES CLAUDE_CODE_REMOTE; do
|
|
8
|
+
if [ -n "${!marker:-}" ]; then
|
|
9
|
+
kivo_wp_die "bin/db-import is disabled when ${marker} is set: production data stays on a developer machine; use bin/seed"
|
|
10
|
+
fi
|
|
11
|
+
done
|
|
12
|
+
|
|
13
|
+
file="${1:-}"
|
|
14
|
+
[ -n "${file}" ] || kivo_wp_die "usage: bin/db-import <dump.sql|dump.sql.gz>"
|
|
15
|
+
[ -f "${file}" ] || kivo_wp_die "file not found: ${file}"
|
|
16
|
+
|
|
17
|
+
case "${file}" in
|
|
18
|
+
*.gz) gzip -dc "${file}" | kivo_wp_exec app wp db import - ;;
|
|
19
|
+
*) kivo_wp_exec app wp db import - <"${file}" ;;
|
|
20
|
+
esac
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# MySQL client in the db service (local, non-secret credentials).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
name="$(kivo_wp_env_get WORDPRESS_DB_NAME)"
|
|
7
|
+
user="$(kivo_wp_env_get WORDPRESS_DB_USER)"
|
|
8
|
+
password="$(kivo_wp_env_get WORDPRESS_DB_PASSWORD)"
|
|
9
|
+
kivo_wp_exec db env MYSQL_PWD="${password:-wordpress}" mysql -u"${user:-wordpress}" "${name:-wordpress}" "$@"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Run the theme Vite dev server in the node service (served at https://vite.<project>.localhost).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
[ "${#KIVO_WP_THEME_DIRS[@]}" -gt 0 ] || kivo_wp_die "this project has no theme with a Vite dev server"
|
|
7
|
+
kivo_wp_exec_in node "${KIVO_WP_THEME_DIRS[0]}" npm run dev -- "$@"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Stop the kivo-wp stack. --volumes also deletes its data (asks first; --yes confirms).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
volumes=false
|
|
7
|
+
confirmed=false
|
|
8
|
+
args=()
|
|
9
|
+
for arg in "$@"; do
|
|
10
|
+
case "${arg}" in
|
|
11
|
+
-v | --volumes)
|
|
12
|
+
volumes=true
|
|
13
|
+
args+=(--volumes)
|
|
14
|
+
;;
|
|
15
|
+
-y | --yes) confirmed=true ;;
|
|
16
|
+
*) args+=("${arg}") ;;
|
|
17
|
+
esac
|
|
18
|
+
done
|
|
19
|
+
|
|
20
|
+
if [ "${volumes}" = true ]; then
|
|
21
|
+
kivo_wp_err "--volumes deletes the named volumes of this project:"
|
|
22
|
+
kivo_wp_err " db-data the local database: content, users and settings (export first with bin/db-export)"
|
|
23
|
+
kivo_wp_err " caddy-data Caddy's local CA and certificates (browsers must trust the new CA again: bin/trust-cert)"
|
|
24
|
+
if [ "${confirmed}" != true ]; then
|
|
25
|
+
[ -t 0 ] || kivo_wp_die "refusing to delete volumes without confirmation; pass --yes to confirm"
|
|
26
|
+
read -r -p "Delete these volumes? [y/N] " answer
|
|
27
|
+
case "${answer}" in
|
|
28
|
+
y | Y | yes | YES) ;;
|
|
29
|
+
*) kivo_wp_die "aborted; nothing was deleted" ;;
|
|
30
|
+
esac
|
|
31
|
+
fi
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
kivo_wp_compose down ${args[@]+"${args[@]}"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Playwright end-to-end tests in the node service (bin/e2e --project=smoke for the HTTP smoke checks).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
kivo_wp_require_running node
|
|
7
|
+
kivo_wp_require_running proxy
|
|
8
|
+
|
|
9
|
+
# Trust Caddy's local CA inside the node service, never by ignoring TLS errors.
|
|
10
|
+
ca_tmp="$(mktemp)"
|
|
11
|
+
KIVO_WP_CERT_OUT="${ca_tmp}" "${KIVO_WP_ROOT}/bin/trust-cert" >/dev/null
|
|
12
|
+
chmod 0644 "${ca_tmp}"
|
|
13
|
+
kivo_wp_compose cp "${ca_tmp}" node:/tmp/kivo-wp-root.crt >/dev/null
|
|
14
|
+
rm -f "${ca_tmp}"
|
|
15
|
+
|
|
16
|
+
# The proxy answers the project host names on the same port inside the Compose network.
|
|
17
|
+
site_url="$(kivo_wp_env_get WORDPRESS_SITE_URL)"
|
|
18
|
+
|
|
19
|
+
kivo_wp_exec node env NODE_EXTRA_CA_CERTS=/tmp/kivo-wp-root.crt WP_HOME="${site_url}" \
|
|
20
|
+
npx playwright test "$@"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Flush the WordPress, Acorn and object caches.
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
kivo_wp_exec app wp rewrite flush
|
|
7
|
+
kivo_wp_exec app wp cache flush
|
|
8
|
+
{{#if enable_sage}}
|
|
9
|
+
kivo_wp_exec app wp acorn optimize:clear
|
|
10
|
+
{{/if}}
|
|
11
|
+
kivo_wp_exec cache valkey-cli FLUSHDB
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Print the local URLs and the state of the services.
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
site_url="$(kivo_wp_env_get WORDPRESS_SITE_URL)"
|
|
7
|
+
host="${site_url#https://}"
|
|
8
|
+
host="${host#http://}"
|
|
9
|
+
|
|
10
|
+
printf 'Site: %s\n' "${site_url}"
|
|
11
|
+
printf 'Admin: %s/wp/wp-admin/\n' "${site_url}"
|
|
12
|
+
printf 'Vite: https://vite.%s\n' "${host}"
|
|
13
|
+
printf 'Mailpit: https://mail.%s\n' "${host}"
|
|
14
|
+
printf '\n'
|
|
15
|
+
kivo_wp_compose ps
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Delete and reinstall the Composer and npm dependencies.
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
kivo_wp_exec_in app . bash -c 'rm -rf vendor && bash server/cmd/setup-php.sh'
|
|
7
|
+
kivo_wp_exec_in node . bash -c 'rm -rf node_modules && bash server/cmd/setup-node.sh'
|
|
8
|
+
{{#if enable_sage}}
|
|
9
|
+
kivo_wp_exec_in app . bash server/cmd/setup-sage-php.sh
|
|
10
|
+
kivo_wp_exec_in node . bash server/cmd/setup-sage-node.sh
|
|
11
|
+
{{/if}}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Seed deterministic synthetic fixtures (D-002); --reset empties the database first.
|
|
3
|
+
# Records carry the _kivo_wp_fixture meta, so running it again replaces them.
|
|
4
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
5
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
6
|
+
|
|
7
|
+
case "${1:-}" in
|
|
8
|
+
--reset)
|
|
9
|
+
kivo_wp_exec app wp db reset --yes --path=wp
|
|
10
|
+
kivo_wp_exec_in app . bash server/cmd/install-wp.sh
|
|
11
|
+
{{#if enable_sage}}
|
|
12
|
+
kivo_wp_exec app wp theme activate "{{projectName}}" --path=wp
|
|
13
|
+
{{/if}}
|
|
14
|
+
;;
|
|
15
|
+
"") ;;
|
|
16
|
+
*) kivo_wp_die "usage: bin/seed [--reset]" ;;
|
|
17
|
+
esac
|
|
18
|
+
|
|
19
|
+
kivo_wp_exec_in app . wp eval-file fixtures/seed.php --path=wp
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# One-command, idempotent onboarding of the kivo-wp environment (local, CI, Codespaces, cloud).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
PROJECT_NAME="{{projectName}}"
|
|
7
|
+
ACF_PLACEHOLDER="op://<vault>/<item>"
|
|
8
|
+
|
|
9
|
+
usage() {
|
|
10
|
+
cat <<'USAGE'
|
|
11
|
+
Usage: bin/setup [--ci] [--cloud] [--quick] [--fresh]
|
|
12
|
+
|
|
13
|
+
Builds and starts the kivo-wp stack, installs dependencies, installs WordPress, seeds synthetic
|
|
14
|
+
fixtures into an empty database and prints the URLs. Safe to run again.
|
|
15
|
+
|
|
16
|
+
--ci non-interactive: never prompts, skips the certificate trust step, stops at the first error
|
|
17
|
+
--cloud cloud agent session: no auth.json is created (licensed packages come from the session proxy)
|
|
18
|
+
--quick only start the stack and verify a previous setup
|
|
19
|
+
--fresh reset the database and reseed the fixtures
|
|
20
|
+
--help show this help
|
|
21
|
+
USAGE
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
ci=false
|
|
25
|
+
cloud=false
|
|
26
|
+
quick=false
|
|
27
|
+
fresh=false
|
|
28
|
+
for arg in "$@"; do
|
|
29
|
+
case "${arg}" in
|
|
30
|
+
--ci) ci=true ;;
|
|
31
|
+
--cloud) cloud=true ;;
|
|
32
|
+
--quick) quick=true ;;
|
|
33
|
+
--fresh) fresh=true ;;
|
|
34
|
+
-h | --help)
|
|
35
|
+
usage
|
|
36
|
+
exit 0
|
|
37
|
+
;;
|
|
38
|
+
*)
|
|
39
|
+
usage >&2
|
|
40
|
+
exit 2
|
|
41
|
+
;;
|
|
42
|
+
esac
|
|
43
|
+
done
|
|
44
|
+
[ "${CLAUDE_CODE_REMOTE:-}" = "true" ] && cloud=true
|
|
45
|
+
[ "${CI:-}" = "true" ] && ci=true
|
|
46
|
+
|
|
47
|
+
step() {
|
|
48
|
+
printf '\n==> %s\n' "$*" >&2
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
port_in_use() {
|
|
52
|
+
(exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Port published by this project's proxy for a container port, empty when not running.
|
|
56
|
+
published_port() {
|
|
57
|
+
local mapping
|
|
58
|
+
mapping="$(kivo_wp_compose port proxy "$1" 2>/dev/null | head -n 1 || true)"
|
|
59
|
+
printf '%s\n' "${mapping##*:}"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# Where the search for a replacement starts: 8443/8080 for the standard ports (the ports right
|
|
63
|
+
# above them are often reserved, for example 445 by SMB), otherwise the next port.
|
|
64
|
+
first_alternative() {
|
|
65
|
+
case "$1" in
|
|
66
|
+
443) echo 8443 ;;
|
|
67
|
+
80) echo 8080 ;;
|
|
68
|
+
*) echo $(($1 + 1)) ;;
|
|
69
|
+
esac
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# First port from $1 that no local listener holds, within 100 ports.
|
|
73
|
+
next_free_port() {
|
|
74
|
+
local candidate
|
|
75
|
+
for candidate in $(seq "$1" $(($1 + 100))); do
|
|
76
|
+
if ! port_in_use "${candidate}"; then
|
|
77
|
+
printf '%s\n' "${candidate}"
|
|
78
|
+
return
|
|
79
|
+
fi
|
|
80
|
+
done
|
|
81
|
+
kivo_wp_die "no free port found between $1 and $(($1 + 100))"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Keep the configured port when it is free or already ours; otherwise pick the next free one.
|
|
85
|
+
choose_port() {
|
|
86
|
+
local key="$1" container_port="$2" fallback="$3" current ours
|
|
87
|
+
current="$(kivo_wp_env_get "${key}")"
|
|
88
|
+
current="${current:-${fallback}}"
|
|
89
|
+
ours="$(published_port "${container_port}")"
|
|
90
|
+
if [ "${ours}" = "${current}" ] || ! port_in_use "${current}"; then
|
|
91
|
+
printf '%s\n' "${current}"
|
|
92
|
+
return
|
|
93
|
+
fi
|
|
94
|
+
local candidate
|
|
95
|
+
candidate="$(next_free_port "$(first_alternative "${current}")")"
|
|
96
|
+
kivo_wp_err "port ${current} is busy; using ${candidate} for ${key}"
|
|
97
|
+
printf '%s\n' "${candidate}"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
site_url_for() {
|
|
101
|
+
local https_port="$1" http_port="$2"
|
|
102
|
+
if [ "${CODESPACES:-}" = "true" ]; then
|
|
103
|
+
# The forwarder terminates TLS and reaches Caddy on the HTTP port (see the Caddyfile).
|
|
104
|
+
printf 'https://%s-%s.%s\n' "${CODESPACE_NAME:?}" "${http_port}" "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:?}"
|
|
105
|
+
elif [ "${https_port}" = "443" ]; then
|
|
106
|
+
printf 'https://%s.localhost\n' "${PROJECT_NAME}"
|
|
107
|
+
else
|
|
108
|
+
printf 'https://%s.localhost:%s\n' "${PROJECT_NAME}" "${https_port}"
|
|
109
|
+
fi
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# 1. Tooling and .env ----------------------------------------------------------------------
|
|
113
|
+
step "Checking Docker"
|
|
114
|
+
command -v docker >/dev/null 2>&1 || kivo_wp_die "docker not found; install Docker Engine or Docker Desktop"
|
|
115
|
+
docker compose version >/dev/null 2>&1 || kivo_wp_die "docker compose v2 not found"
|
|
116
|
+
|
|
117
|
+
env_file="${KIVO_WP_ROOT}/.env"
|
|
118
|
+
if [ ! -f "${env_file}" ]; then
|
|
119
|
+
[ -f "${KIVO_WP_ROOT}/.env.example" ] || kivo_wp_die ".env.example not found"
|
|
120
|
+
(umask 077 && cp "${KIVO_WP_ROOT}/.env.example" "${env_file}")
|
|
121
|
+
kivo_wp_err "created .env from .env.example"
|
|
122
|
+
fi
|
|
123
|
+
# Local, per-environment values (D-006): not secrets.
|
|
124
|
+
[ -n "$(kivo_wp_env_get WORDPRESS_DB_PASSWORD)" ] || kivo_wp_env_set WORDPRESS_DB_PASSWORD '"wordpress"'
|
|
125
|
+
[ -n "$(kivo_wp_env_get USER_ID)" ] || kivo_wp_env_set USER_ID "$(id -u)"
|
|
126
|
+
[ -n "$(kivo_wp_env_get GROUP_ID)" ] || kivo_wp_env_set GROUP_ID "$(id -g)"
|
|
127
|
+
|
|
128
|
+
if [ "${quick}" = true ]; then
|
|
129
|
+
step "Starting the stack"
|
|
130
|
+
kivo_wp_compose up -d --wait
|
|
131
|
+
kivo_wp_exec app wp core is-installed --path=wp >/dev/null 2>&1 ||
|
|
132
|
+
kivo_wp_die "WordPress is not installed; run bin/setup without --quick"
|
|
133
|
+
"${KIVO_WP_ROOT}/bin/info"
|
|
134
|
+
exit 0
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
# 2. Ports and site URL (D-013) ---------------------------------------------------------------
|
|
138
|
+
step "Choosing ports"
|
|
139
|
+
https_port="$(choose_port HTTPS_PORT 443 443)"
|
|
140
|
+
http_port="$(choose_port HTTP_PORT 80 80)"
|
|
141
|
+
[ "$(kivo_wp_env_get HTTPS_PORT)" = "${https_port}" ] || kivo_wp_env_set HTTPS_PORT "${https_port}"
|
|
142
|
+
[ "$(kivo_wp_env_get HTTP_PORT)" = "${http_port}" ] || kivo_wp_env_set HTTP_PORT "${http_port}"
|
|
143
|
+
site_url="$(site_url_for "${https_port}" "${http_port}")"
|
|
144
|
+
[ "$(kivo_wp_env_get WORDPRESS_SITE_URL)" = "${site_url}" ] || kivo_wp_env_set WORDPRESS_SITE_URL "\"${site_url}\""
|
|
145
|
+
|
|
146
|
+
# Codespaces: requests to the private forwarded URL fail GitHub's authentication, so WP-Cron
|
|
147
|
+
# leaves the request path; the devcontainer postStartCommand runs due events every minute.
|
|
148
|
+
if [ "${CODESPACES:-}" = "true" ]; then
|
|
149
|
+
[ "$(kivo_wp_env_get WORDPRESS_DISABLE_WP_CRON)" = "true" ] || kivo_wp_env_set WORDPRESS_DISABLE_WP_CRON true
|
|
150
|
+
else
|
|
151
|
+
kivo_wp_env_unset WORDPRESS_DISABLE_WP_CRON
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
# 3. Licensed Composer credentials (D-014) ----------------------------------------------------
|
|
155
|
+
template="${KIVO_WP_ROOT}/auth.json.tpl"
|
|
156
|
+
auth="${KIVO_WP_ROOT}/auth.json"
|
|
157
|
+
if [ -f "${template}" ] && [ "${cloud}" = false ]; then
|
|
158
|
+
if [ ! -f "${auth}" ] || [ "${template}" -nt "${auth}" ]; then
|
|
159
|
+
step "Rendering auth.json from 1Password references"
|
|
160
|
+
grep -qF "${ACF_PLACEHOLDER}" "${template}" &&
|
|
161
|
+
kivo_wp_die "auth.json.tpl still has the placeholder ${ACF_PLACEHOLDER}; set the acf_op_reference prompt value (op://<vault>/<item>) in auth.json.tpl"
|
|
162
|
+
command -v op >/dev/null 2>&1 ||
|
|
163
|
+
kivo_wp_die "1Password CLI (op) not found; install it (https://developer.1password.com/docs/cli/get-started/) and sign in"
|
|
164
|
+
op whoami >/dev/null 2>&1 || kivo_wp_die "1Password CLI is not signed in; run: eval \"\$(op signin)\""
|
|
165
|
+
(umask 077 && op inject --force -i "${template}" -o "${auth}" >/dev/null)
|
|
166
|
+
chmod 600 "${auth}"
|
|
167
|
+
fi
|
|
168
|
+
fi
|
|
169
|
+
|
|
170
|
+
# 4. Build and start --------------------------------------------------------------------------
|
|
171
|
+
step "Building the images"
|
|
172
|
+
kivo_wp_compose build
|
|
173
|
+
|
|
174
|
+
if ! grep -qE '^WORDPRESS_AUTH_KEY=.+' "${env_file}"; then
|
|
175
|
+
step "Generating WordPress salts"
|
|
176
|
+
for key in AUTH_KEY SECURE_AUTH_KEY LOGGED_IN_KEY NONCE_KEY AUTH_SALT SECURE_AUTH_SALT LOGGED_IN_SALT NONCE_SALT; do
|
|
177
|
+
salt="$(kivo_wp_compose run --rm --no-deps -T app php -r 'echo base64_encode(random_bytes(48));')"
|
|
178
|
+
kivo_wp_env_set "WORDPRESS_${key}" "${salt}"
|
|
179
|
+
done
|
|
180
|
+
fi
|
|
181
|
+
|
|
182
|
+
step "Starting the stack"
|
|
183
|
+
# A port can be free for this shell and still refused by Docker (for example a port held on the
|
|
184
|
+
# Windows side of WSL); then both ports move up and the start is retried.
|
|
185
|
+
for attempt in 1 2 3; do
|
|
186
|
+
if up_output="$(kivo_wp_compose up -d --wait 2>&1)"; then
|
|
187
|
+
printf '%s\n' "${up_output}" >&2
|
|
188
|
+
break
|
|
189
|
+
fi
|
|
190
|
+
printf '%s\n' "${up_output}" >&2
|
|
191
|
+
if [ "${attempt}" -lt 3 ] && grep -qiE 'ports are not available|address already in use|port is already allocated' <<<"${up_output}"; then
|
|
192
|
+
https_port="$(next_free_port $((https_port + 1)))"
|
|
193
|
+
http_port="$(next_free_port $((http_port + 1)))"
|
|
194
|
+
kivo_wp_err "Docker refused the host ports; retrying with ${https_port} and ${http_port}"
|
|
195
|
+
kivo_wp_env_set HTTPS_PORT "${https_port}"
|
|
196
|
+
kivo_wp_env_set HTTP_PORT "${http_port}"
|
|
197
|
+
site_url="$(site_url_for "${https_port}" "${http_port}")"
|
|
198
|
+
kivo_wp_env_set WORDPRESS_SITE_URL "\"${site_url}\""
|
|
199
|
+
continue
|
|
200
|
+
fi
|
|
201
|
+
kivo_wp_die "the stack did not start"
|
|
202
|
+
done
|
|
203
|
+
|
|
204
|
+
# Cloud sessions: trust Caddy's root CA in the VM so curl, PHP and Playwright accept the site.
|
|
205
|
+
if [ "${cloud}" = true ]; then
|
|
206
|
+
step "Trusting Caddy's local CA in the VM"
|
|
207
|
+
ca_tmp="$(mktemp)"
|
|
208
|
+
KIVO_WP_CERT_OUT="${ca_tmp}" "${KIVO_WP_ROOT}/bin/trust-cert" >/dev/null
|
|
209
|
+
ca_target="${KIVO_WP_CA_DIR:-/usr/local/share/ca-certificates}/kivo-wp-${PROJECT_NAME}.crt"
|
|
210
|
+
if ! cmp -s "${ca_tmp}" "${ca_target}"; then
|
|
211
|
+
sudo install -m 0644 "${ca_tmp}" "${ca_target}"
|
|
212
|
+
sudo update-ca-certificates >/dev/null
|
|
213
|
+
fi
|
|
214
|
+
rm -f "${ca_tmp}"
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
# 5. Dependencies -----------------------------------------------------------------------------
|
|
218
|
+
npm_install() {
|
|
219
|
+
local dir="$1"
|
|
220
|
+
if [ -f "${KIVO_WP_ROOT}/${dir}/package-lock.json" ]; then
|
|
221
|
+
kivo_wp_exec_in node "${dir}" npm ci --no-audit --no-fund
|
|
222
|
+
else
|
|
223
|
+
kivo_wp_exec_in node "${dir}" npm install --no-audit --no-fund
|
|
224
|
+
fi
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
step "Installing dependencies"
|
|
228
|
+
kivo_wp_exec_in app . composer install --no-interaction --no-progress
|
|
229
|
+
{{#if enable_sage}}
|
|
230
|
+
kivo_wp_exec_in app . bash server/cmd/setup-sage-php.sh
|
|
231
|
+
{{/if}}
|
|
232
|
+
npm_install .
|
|
233
|
+
for dir in ${KIVO_WP_THEME_DIRS[@]+"${KIVO_WP_THEME_DIRS[@]}"}; do
|
|
234
|
+
npm_install "${dir}"
|
|
235
|
+
done
|
|
236
|
+
"${KIVO_WP_ROOT}/bin/build"
|
|
237
|
+
|
|
238
|
+
# 6. WordPress --------------------------------------------------------------------------------
|
|
239
|
+
step "Installing WordPress"
|
|
240
|
+
installed=false
|
|
241
|
+
kivo_wp_exec app wp core is-installed --path=wp >/dev/null 2>&1 && installed=true
|
|
242
|
+
if [ "${installed}" = true ]; then
|
|
243
|
+
old_url="$(kivo_wp_exec app wp option get home --path=wp)"
|
|
244
|
+
if [ -n "${old_url}" ] && [ "${old_url}" != "${site_url}" ]; then
|
|
245
|
+
kivo_wp_err "site URL changed: ${old_url} -> ${site_url}"
|
|
246
|
+
kivo_wp_exec app wp search-replace "${old_url}" "${site_url}" --all-tables --path=wp
|
|
247
|
+
fi
|
|
248
|
+
else
|
|
249
|
+
kivo_wp_exec_in app . bash server/cmd/install-wp.sh
|
|
250
|
+
fi
|
|
251
|
+
{{#if enable_sage}}
|
|
252
|
+
kivo_wp_exec app wp theme activate "${PROJECT_NAME}" --path=wp
|
|
253
|
+
kivo_wp_exec app wp acorn optimize:clear --path=wp
|
|
254
|
+
{{/if}}
|
|
255
|
+
|
|
256
|
+
# 7. Fixtures (D-002) -------------------------------------------------------------------------
|
|
257
|
+
if [ "${fresh}" = true ]; then
|
|
258
|
+
step "Resetting the database and reseeding"
|
|
259
|
+
"${KIVO_WP_ROOT}/bin/seed" --reset
|
|
260
|
+
else
|
|
261
|
+
fixtures="$(kivo_wp_exec app wp post list --post_type=any --post_status=any --meta_key=_kivo_wp_fixture --format=count --path=wp)"
|
|
262
|
+
posts="$(kivo_wp_exec app wp post list --post_type=post,page --post_status=any --format=count --path=wp)"
|
|
263
|
+
# A fresh install has at most WordPress's own sample post, sample page and privacy page.
|
|
264
|
+
if [ "${fixtures}" = "0" ] && [ "${posts}" -le 3 ]; then
|
|
265
|
+
step "Seeding synthetic fixtures"
|
|
266
|
+
"${KIVO_WP_ROOT}/bin/seed"
|
|
267
|
+
fi
|
|
268
|
+
fi
|
|
269
|
+
|
|
270
|
+
# 8. Certificate trust and summary ------------------------------------------------------------
|
|
271
|
+
if [ "${ci}" = false ] && [ "${cloud}" = false ]; then
|
|
272
|
+
step "Certificate trust (run the command printed for your system once)"
|
|
273
|
+
"${KIVO_WP_ROOT}/bin/trust-cert"
|
|
274
|
+
fi
|
|
275
|
+
|
|
276
|
+
step "Ready"
|
|
277
|
+
"${KIVO_WP_ROOT}/bin/info"
|
|
278
|
+
admin_user="$(kivo_wp_env_get WORDPRESS_ADMIN_USER)"
|
|
279
|
+
if [ -n "$(kivo_wp_env_get WORDPRESS_ADMIN_PASSWORD)" ]; then
|
|
280
|
+
printf '\nAdmin login: %s (password from WORDPRESS_ADMIN_PASSWORD in .env)\n' "${admin_user:-admin}"
|
|
281
|
+
else
|
|
282
|
+
printf '\nAdmin login: %s / admin (synthetic local user)\n' "${admin_user:-admin}"
|
|
283
|
+
fi
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Open a shell in a service (default app), or run a command there: bin/shell cache valkey-cli
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
service="${1:-app}"
|
|
7
|
+
[ "$#" -gt 0 ] && shift
|
|
8
|
+
if [ "$#" -eq 0 ]; then
|
|
9
|
+
case "${service}" in
|
|
10
|
+
app | node) set -- bash ;;
|
|
11
|
+
*) set -- sh ;;
|
|
12
|
+
esac
|
|
13
|
+
fi
|
|
14
|
+
kivo_wp_exec "${service}" "$@"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Export Caddy's local root CA and print the command that trusts it on this OS (never runs it).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
kivo_wp_require_running proxy
|
|
7
|
+
out="${KIVO_WP_CERT_OUT:-${TMPDIR:-/tmp}/kivo-wp-{{projectName}}-root.crt}"
|
|
8
|
+
kivo_wp_compose cp proxy:/data/caddy/pki/authorities/local/root.crt "${out}" >/dev/null
|
|
9
|
+
printf "Caddy root CA exported to %s\n\n" "${out}"
|
|
10
|
+
|
|
11
|
+
printf 'Linux (Debian/Ubuntu):\n'
|
|
12
|
+
printf ' sudo cp "%s" /usr/local/share/ca-certificates/kivo-wp-{{projectName}}.crt && sudo update-ca-certificates\n\n' "${out}"
|
|
13
|
+
printf 'macOS:\n'
|
|
14
|
+
printf ' sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s"\n\n' "${out}"
|
|
15
|
+
|
|
16
|
+
if [ -n "${WSL_DISTRO_NAME:-}" ]; then
|
|
17
|
+
windows_path="\\\\wsl.localhost\\${WSL_DISTRO_NAME}${out//\//\\}"
|
|
18
|
+
printf 'Windows (browsers on the Windows side), from an elevated Command Prompt:\n'
|
|
19
|
+
printf ' certutil.exe -addstore -f ROOT "%s"\n' "${windows_path}"
|
|
20
|
+
printf ' Firefox also needs security.enterprise_roots.enabled = true in about:config.\n'
|
|
21
|
+
fi
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Toggle Xdebug without a rebuild: bin/xdebug on [mode] | off | status
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
case "${1:-status}" in
|
|
7
|
+
on)
|
|
8
|
+
mode="${2:-debug,develop}"
|
|
9
|
+
kivo_wp_env_set XDEBUG_MODE "${mode}"
|
|
10
|
+
kivo_wp_compose up -d --no-build app
|
|
11
|
+
kivo_wp_err "Xdebug on (XDEBUG_MODE=${mode})"
|
|
12
|
+
;;
|
|
13
|
+
off)
|
|
14
|
+
kivo_wp_env_set XDEBUG_MODE off
|
|
15
|
+
kivo_wp_compose up -d --no-build app
|
|
16
|
+
kivo_wp_err "Xdebug off"
|
|
17
|
+
;;
|
|
18
|
+
status)
|
|
19
|
+
printf 'XDEBUG_MODE=%s\n' "$(kivo_wp_env_get XDEBUG_MODE)"
|
|
20
|
+
;;
|
|
21
|
+
*) kivo_wp_die "usage: bin/xdebug on [mode] | off | status" ;;
|
|
22
|
+
esac
|