@codigodoleo/wp-kit 5.3.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.
Files changed (104) hide show
  1. package/lib/commands/init.js +28 -26
  2. package/lib/config/versions.js +27 -1
  3. package/lib/core/cloud-allowlist.js +38 -0
  4. package/lib/core/generator.js +56 -50
  5. package/lib/core/infer-ci-capabilities.js +17 -5
  6. package/lib/prompts/index.js +105 -8
  7. package/lib/utils/auth-template.js +18 -0
  8. package/lib/utils/env-example.js +18 -6
  9. package/modules/blank-theme/index.js +1 -1
  10. package/modules/deploy/index.js +15 -0
  11. package/modules/deploy/scripts/check-exposure.sh +63 -0
  12. package/modules/deploy/templates/.github/workflows/ci.yml.hbs +28 -0
  13. package/modules/docs/index.js +18 -18
  14. package/modules/docs/templates/README.md.hbs +1 -1
  15. package/modules/docs/templates/docs/Arquitetura.md.hbs +2 -2
  16. package/modules/docs/templates/docs/Deploy-Pipeline.md.hbs +21 -1
  17. package/modules/docs/templates/docs/{Desenvolvimento.md.hbs → Development.md.hbs} +80 -2
  18. package/modules/docs/templates/docs/Getting-Started.md.hbs +75 -4
  19. package/modules/docs/templates/docs/Infraestrutura.md.hbs +1 -1
  20. package/modules/docs/templates/docs/Troubleshooting.md.hbs +18 -1
  21. package/modules/git/.husky/kivo-wp/commit-msg +3 -0
  22. package/modules/git/.husky/kivo-wp/pre-commit +25 -0
  23. package/modules/git/.husky/pre-commit +3 -7
  24. package/modules/git/index.js +19 -2
  25. package/modules/git/templates/.lando.yml.hbs +5 -0
  26. package/modules/git/templates/package.json.hbs +1 -1
  27. package/modules/kivo-wp/fixtures/menus.json +11 -0
  28. package/modules/kivo-wp/fixtures/options.json +10 -0
  29. package/modules/kivo-wp/fixtures/posts.json +58 -0
  30. package/modules/kivo-wp/fixtures/seed.php +152 -0
  31. package/modules/kivo-wp/fixtures/terms.json +6 -0
  32. package/modules/kivo-wp/fixtures/users.json +26 -0
  33. package/modules/kivo-wp/index.js +193 -0
  34. package/modules/kivo-wp/prompts.js +1 -0
  35. package/modules/kivo-wp/templates/.devcontainer/devcontainer.json.hbs +40 -0
  36. package/modules/kivo-wp/templates/.dockerignore.hbs +15 -0
  37. package/modules/kivo-wp/templates/Dockerfile.hbs +81 -0
  38. package/modules/kivo-wp/templates/bin/_lib.sh.hbs +116 -0
  39. package/modules/kivo-wp/templates/bin/build.hbs +13 -0
  40. package/modules/kivo-wp/templates/bin/composer.hbs +6 -0
  41. package/modules/kivo-wp/templates/bin/db-export.hbs +8 -0
  42. package/modules/kivo-wp/templates/bin/db-import.hbs +20 -0
  43. package/modules/kivo-wp/templates/bin/db.hbs +9 -0
  44. package/modules/kivo-wp/templates/bin/dev.hbs +7 -0
  45. package/modules/kivo-wp/templates/bin/down.hbs +34 -0
  46. package/modules/kivo-wp/templates/bin/e2e.hbs +20 -0
  47. package/modules/kivo-wp/templates/bin/flush.hbs +11 -0
  48. package/modules/kivo-wp/templates/bin/info.hbs +15 -0
  49. package/modules/kivo-wp/templates/bin/logs.hbs +6 -0
  50. package/modules/kivo-wp/templates/bin/mago.hbs +6 -0
  51. package/modules/kivo-wp/templates/bin/node.hbs +6 -0
  52. package/modules/kivo-wp/templates/bin/npm.hbs +6 -0
  53. package/modules/kivo-wp/templates/bin/php.hbs +6 -0
  54. package/modules/kivo-wp/templates/bin/reset-deps.hbs +11 -0
  55. package/modules/kivo-wp/templates/bin/seed.hbs +19 -0
  56. package/modules/kivo-wp/templates/bin/setup.hbs +283 -0
  57. package/modules/kivo-wp/templates/bin/shell.hbs +14 -0
  58. package/modules/kivo-wp/templates/bin/stan.hbs +6 -0
  59. package/modules/kivo-wp/templates/bin/test.hbs +6 -0
  60. package/modules/kivo-wp/templates/bin/trust-cert.hbs +21 -0
  61. package/modules/kivo-wp/templates/bin/up.hbs +6 -0
  62. package/modules/kivo-wp/templates/bin/wp.hbs +6 -0
  63. package/modules/kivo-wp/templates/bin/xdebug.hbs +22 -0
  64. package/modules/kivo-wp/templates/compose.yaml.hbs +117 -0
  65. package/modules/kivo-wp/templates/content/mu-plugins/kivo-wp-local-mail.php.hbs +29 -0
  66. package/modules/kivo-wp/templates/docs/cloud-sessions.md.hbs +34 -0
  67. package/modules/kivo-wp/templates/server/caddy/Caddyfile.hbs +44 -0
  68. package/modules/kivo-wp/templates/server/nginx/deny.conf.hbs +26 -0
  69. package/modules/lint/index.js +14 -10
  70. package/modules/lint/templates/package.json.hbs +6 -0
  71. package/modules/php/index.js +13 -1
  72. package/modules/php/kivo-wp/php-wrapper.sh +3 -0
  73. package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
  74. package/modules/sage/index.js +1 -25
  75. package/modules/sage/templates/bin/theme-lint.hbs +6 -0
  76. package/modules/sage/templates/server/cmd/setup-sage-node.sh.hbs +3 -1
  77. package/modules/sage/templates/server/cmd/setup-sage-php.sh.hbs +3 -1
  78. package/modules/sage/templates/theme/vite.config.js.hbs +20 -2
  79. package/modules/sage/templates/workspace.json.hbs +0 -57
  80. package/modules/test/index.js +12 -11
  81. package/modules/test/templates/playwright.config.js.hbs +12 -0
  82. package/modules/test/tests/e2e/smoke.spec.js +28 -0
  83. package/package.json +3 -2
  84. package/templates/.env.hbs +16 -5
  85. package/templates/.gitignore.hbs +7 -1
  86. package/templates/.lando.yml.hbs +3 -9
  87. package/templates/CLAUDE.md.hbs +19 -2
  88. package/templates/package.json.hbs +8 -1
  89. package/templates/server/cmd/install-wp.sh.hbs +1 -1
  90. package/templates/server/cmd/setup-node.sh.hbs +3 -1
  91. package/templates/server/cmd/setup-php.sh.hbs +63 -9
  92. package/templates/workspace.json.hbs +0 -56
  93. package/{wp-config.php → templates/wp-config.php.hbs} +41 -5
  94. package/modules/lint/templates/.lando.yml.hbs +0 -5
  95. package/modules/sage/templates/.devcontainer/devcontainer.json.hbs +0 -7
  96. package/modules/sage/templates/.devcontainer/docker-compose.override.yml.hbs +0 -4
  97. package/modules/sage/templates/.devcontainer/post-create.sh.hbs +0 -11
  98. package/templates/.devcontainer/Dockerfile.hbs +0 -24
  99. package/templates/.devcontainer/config/nginx.conf +0 -23
  100. package/templates/.devcontainer/config/nginx.conf.hbs +0 -23
  101. package/templates/.devcontainer/devcontainer.json.hbs +0 -29
  102. package/templates/.devcontainer/docker-compose.yml.hbs +0 -76
  103. package/templates/.devcontainer/setup.sh.hbs +0 -17
  104. package/templates/auth.json.hbs +0 -8
@@ -1,16 +1,28 @@
1
1
  // Matches active and commented-out assignments (`KEY=v`, `export KEY=v`, `# KEY=v`).
2
- const ASSIGNMENT = /^(\s*(?:#\s*)?(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*)=.*$/;
2
+ const ASSIGNMENT = /^(\s*(?:#\s*)?(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*))=.*$/;
3
+
4
+ // Keys whose values are never kept, whatever the caller allows (salts, keys, tokens, passwords).
5
+ export const SECRET_KEY_PATTERN = /(KEY|SALT|SECRET|TOKEN|PASSWORD)/;
3
6
 
4
7
  /**
5
- * Turns dotenv content into a keys-only example: every assignment, including
6
- * commented-out ones, keeps its key and loses its value; other comments and
7
- * blank lines are preserved as-is.
8
+ * Turns dotenv content into an example that is safe to commit. Every assignment, including
9
+ * commented-out ones, keeps its key and loses its value, except active assignments for which
10
+ * `keepValue(key)` returns true and whose key is not secret-like (D-028: non-secret kivo-wp
11
+ * defaults). Other comments and blank lines are preserved as-is.
8
12
  * @param {string} content - Rendered dotenv content
13
+ * @param {{ keepValue?: (key: string) => boolean }} [options]
9
14
  * @returns {string} Content safe to commit
10
15
  */
11
- export function toEnvExample(content) {
16
+ export function toEnvExample(content, { keepValue = () => false } = {}) {
12
17
  return content
13
18
  .split("\n")
14
- .map((line) => line.replace(ASSIGNMENT, "$1="))
19
+ .map((line) => {
20
+ const match = line.match(ASSIGNMENT);
21
+ if (!match) return line;
22
+ const [, prefix, key] = match;
23
+ const commented = /^\s*#/.test(line);
24
+ if (!commented && !SECRET_KEY_PATTERN.test(key) && keepValue(key)) return line;
25
+ return `${prefix}=`;
26
+ })
15
27
  .join("\n");
16
28
  }
@@ -12,7 +12,7 @@ import { log, color } from "../../lib/utils/logger.js";
12
12
  *
13
13
  * acme-theme -> ACME_THEME
14
14
  * my-site-theme -> MY_SITE_THEME
15
- * wp-futrading-theme -> WP_FUTRADING_THEME
15
+ * wp-myproject-theme -> WP_MYPROJECT_THEME
16
16
  */
17
17
  function toConstantPrefix(slug) {
18
18
  return slug
@@ -1,3 +1,7 @@
1
+ import path from "path";
2
+
3
+ import fs from "fs-extra";
4
+
1
5
  import { log, color } from "../../lib/utils/logger.js";
2
6
 
3
7
  export async function setupModule(context, generator) {
@@ -8,6 +12,17 @@ export async function setupModule(context, generator) {
8
12
 
9
13
  log(color.blue, "[deploy] Gerando pipeline de CI baseado em context.ci");
10
14
 
15
+ // Verificador de exposição: serve ao CI (ci.yml) e a quem faz deploy por conta própria. Confere de fora
16
+ // que .env, CLAUDE.md, composer.lock etc. não respondem 200; ver docs/Deploy-Pipeline.md.
17
+ await generator.copyFile("scripts/check-exposure.sh", "deploy", "scripts/check-exposure.sh");
18
+ if (context.enable_kivo_wp) {
19
+ // The local environment file to probe is compose.yaml instead of the Landofile.
20
+ const script = path.join(generator.cwd, "scripts/check-exposure.sh");
21
+ const text = await fs.readFile(script, "utf8");
22
+ await fs.outputFile(script, text.replace(" .lando.yml ", " compose.yaml "));
23
+ }
24
+ log(color.green, "[deploy] scripts/check-exposure.sh copiado.");
25
+
11
26
  try {
12
27
  await generator.generateFile("renovate.json", context, "deploy", "renovate.json");
13
28
  log(color.green, "[deploy] renovate.json gerado (frota Hekivo).");
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env bash
2
+ # Checks from the outside that no secret or development file is public.
3
+ # Usage: check-exposure.sh <base-url> [theme-slug]
4
+ # Exits 1 if a CRITICAL path answers 200 with a body; WARN paths are only listed. Each request carries a
5
+ # unique query: Cloudflare caches static files by URL, and a stale cached copy would hide (or invent) an
6
+ # exposure. Prints status and size only, never content.
7
+ #
8
+ # Where it runs matters. From an IP the WAF lets through (a "Bypass IP" rule, a CI runner on an allow list)
9
+ # the result is the ORIGIN's: the WAF does not act, so it is the strictest reading. To see what the PUBLIC
10
+ # sees, run it from an IP outside any bypass (for example from the server itself over ssh).
11
+ set -uo pipefail
12
+
13
+ BASE="${1:?Usage: $0 <base-url> [theme-slug]}"
14
+ BASE="${BASE%/}"
15
+ THEME="${2:-}"
16
+
17
+ CRITICAL=(
18
+ .env .env.local .env.production .env.staging .env.backup .env.save .env.example '.env~'
19
+ .git/config .git/HEAD .gitignore .htpasswd .npmrc auth.json
20
+ composer.json composer.lock package.json package-lock.json
21
+ CLAUDE.md AGENTS.md README.md DESIGN.md PRODUCT.md
22
+ .mcp.json .claude/settings.json .claude/settings.local.json .cursor/mcp.json .vscode/settings.json
23
+ .devcontainer/devcontainer.json .github/workflows/ci.yml .github/workflows/deploy.yml .lando.yml docker-compose.yml
24
+ wp-config.php.bak 'wp-config.php~' wp-config.old wp-config.txt
25
+ backup.sql dump.sql db.sql backup.zip debug.log content/debug.log error_log phpinfo.php
26
+ )
27
+ WARN=(
28
+ wp-cli.yml vendor/composer/installed.json wp/readme.html wp/license.txt wp/wp-config-sample.php
29
+ wp-json/ wp-json/wp/v2/users
30
+ )
31
+ if [ -n "$THEME" ]; then
32
+ CRITICAL+=("content/themes/$THEME/package.json" "content/themes/$THEME/vite.config.js" "content/themes/$THEME/.env")
33
+ WARN+=("content/themes/$THEME/composer.json" "content/themes/$THEME/resources/views/layouts/app.blade.php")
34
+ fi
35
+
36
+ nonce="$(date +%s)$RANDOM"
37
+ critical=0
38
+
39
+ probe() { # path -> "status size"
40
+ curl -s -o /dev/null -m 20 -w '%{http_code} %{size_download}' "$BASE/$1?_x=$nonce"
41
+ }
42
+
43
+ for path in "${CRITICAL[@]}"; do
44
+ read -r status size < <(probe "$path")
45
+ if [ "$status" = "200" ] && [ "${size:-0}" -gt 0 ]; then
46
+ echo "::error title=Public file::/$path answers 200 (${size}B) on $BASE"
47
+ critical=$((critical + 1))
48
+ fi
49
+ done
50
+
51
+ for path in "${WARN[@]}"; do
52
+ read -r status size < <(probe "$path")
53
+ if [ "$status" = "200" ] && [ "${size:-0}" -gt 0 ]; then
54
+ echo "::warning title=Information disclosure::/$path answers 200 (${size}B) on $BASE"
55
+ fi
56
+ done
57
+
58
+ if [ "$critical" -gt 0 ]; then
59
+ echo "$critical critical path(s) public on $BASE. Block them in nginx/WAF and keep them out of the deploy." >&2
60
+ exit 1
61
+ fi
62
+
63
+ echo "Exposure: no critical path is public on $BASE."
@@ -247,6 +247,9 @@ jobs:
247
247
  with:
248
248
  ssh-target: $\{{ env.SSH_HOST }}
249
249
  remote-root: $\{{ env.SSH_REMOTE_PATH }}
250
+ # .env goes ABOVE the web root (wp-config.php reads it from there): the deploy path is the
251
+ # document root, and anything inside it is public unless a WAF/vhost rule happens to block it.
252
+ env-location: parent
250
253
  {{#if enable_acf_pro}}
251
254
  plugin-slug: advanced-custom-fields-pro
252
255
  {{/if}}
@@ -260,6 +263,17 @@ jobs:
260
263
  zone-id: $\{{ env.CLOUDFLARE_PURGE_ZONE_ID }}
261
264
  api-token: $\{{ env.CLOUDFLARE_PURGE_TOKEN }}
262
265
 
266
+ - name: Check public exposure
267
+ # Fails the deploy if .env, CLAUDE.md, composer.lock... answer 200. Set the STAGING_URL variable
268
+ # (Settings > Environments > staging) to the site's public URL; without it the check is skipped.
269
+ if: vars.STAGING_URL != ''
270
+ uses: hekivo/gha-workflows/actions/check-exposure@v1
271
+ with:
272
+ site-url: $\{{ vars.STAGING_URL }}
273
+ {{#if ci.build.sage}}
274
+ theme-slug: {{projectName}}
275
+ {{/if}}
276
+
263
277
  # ── Deploy Production ─────────────────────────────────────────────────────────
264
278
  deploy-production:
265
279
  needs: quality
@@ -362,6 +376,9 @@ jobs:
362
376
  ssh-target: $\{{ env.SSH_USER }}@$\{{ env.SSH_HOST }}
363
377
  ssh-cmd: ssh -p $\{{ env.SSH_PORT || '22' }}
364
378
  remote-root: $\{{ env.SSH_REMOTE_PATH }}
379
+ # .env goes ABOVE the web root (wp-config.php reads it from there): the deploy path is the
380
+ # document root, and anything inside it is public unless a WAF/vhost rule happens to block it.
381
+ env-location: parent
365
382
  {{#if enable_acf_pro}}
366
383
  plugin-slug: advanced-custom-fields-pro
367
384
  {{/if}}
@@ -374,4 +391,15 @@ jobs:
374
391
  with:
375
392
  zone-id: $\{{ env.CLOUDFLARE_PURGE_ZONE_ID }}
376
393
  api-token: $\{{ env.CLOUDFLARE_PURGE_TOKEN }}
394
+
395
+ - name: Check public exposure
396
+ # Fails the deploy if .env, CLAUDE.md, composer.lock... answer 200. Set the PRODUCTION_URL variable
397
+ # (Settings > Environments > production) to the site's public URL; without it the check is skipped.
398
+ if: vars.PRODUCTION_URL != ''
399
+ uses: hekivo/gha-workflows/actions/check-exposure@v1
400
+ with:
401
+ site-url: $\{{ vars.PRODUCTION_URL }}
402
+ {{#if ci.build.sage}}
403
+ theme-slug: {{projectName}}
404
+ {{/if}}
377
405
  {{/if}}
@@ -5,19 +5,19 @@
5
5
  * placeholders inside the generated docs for the team to fill in.
6
6
  */
7
7
  function deriveDocContext(context) {
8
- const isGitHub = context.gitProvider === 'github';
9
- const isGitLab = context.gitProvider === 'gitlab';
10
- const isBitbucket = context.gitProvider === 'bitbucket';
8
+ const isGitHub = context.gitProvider === "github";
9
+ const isGitLab = context.gitProvider === "gitlab";
10
+ const isBitbucket = context.gitProvider === "bitbucket";
11
11
 
12
12
  // Pull request terminology varies by provider; the docs reference it
13
13
  // dozens of times so a single derived string keeps the templates clean.
14
- const prTerm = isGitLab ? 'Merge Request (MR)' : 'Pull Request (PR)';
15
- const prTermShort = isGitLab ? 'MR' : 'PR';
14
+ const prTerm = isGitLab ? "Merge Request (MR)" : "Pull Request (PR)";
15
+ const prTermShort = isGitLab ? "MR" : "PR";
16
16
  const ciSystem = isGitLab
17
- ? 'GitLab CI/CD'
17
+ ? "GitLab CI/CD"
18
18
  : isBitbucket
19
- ? 'Bitbucket Pipelines'
20
- : 'GitHub Actions';
19
+ ? "Bitbucket Pipelines"
20
+ : "GitHub Actions";
21
21
 
22
22
  return {
23
23
  ...context,
@@ -35,17 +35,17 @@ export async function setupModule(context, generator) {
35
35
 
36
36
  // README.md lands at the docs/ entry point (not the project root README,
37
37
  // which is generated by the kit core).
38
- await generator.generateFile('README.md', docContext, 'docs', 'docs/README.md');
38
+ await generator.generateFile("README.md", docContext, "docs", "docs/README.md");
39
39
 
40
40
  const docFiles = [
41
- 'Arquitetura.md',
42
- 'Deploy-Pipeline.md',
43
- 'Desenvolvimento.md',
44
- 'Getting-Started.md',
45
- 'Infraestrutura.md',
46
- 'Monitoramento.md',
47
- 'Sync-the-Production-DB-with-the-Staging-DB.md',
48
- 'Troubleshooting.md',
41
+ "Arquitetura.md",
42
+ "Deploy-Pipeline.md",
43
+ "Development.md",
44
+ "Getting-Started.md",
45
+ "Infraestrutura.md",
46
+ "Monitoramento.md",
47
+ "Sync-the-Production-DB-with-the-Staging-DB.md",
48
+ "Troubleshooting.md",
49
49
  ];
50
50
 
51
51
  // Bug fix: the previous implementation passed `file` as the 4th arg
@@ -53,6 +53,6 @@ export async function setupModule(context, generator) {
53
53
  // inside docs/. Removing that arg restores the template path as the
54
54
  // output path (docs/${file}).
55
55
  for (const file of docFiles) {
56
- await generator.generateFile(`docs/${file}`, docContext, 'docs');
56
+ await generator.generateFile(`docs/${file}`, docContext, "docs");
57
57
  }
58
58
  }
@@ -9,7 +9,7 @@ monitoring tools) as your infrastructure decisions get made.
9
9
  | Document | Purpose |
10
10
  | --- | --- |
11
11
  | [Getting-Started](./Getting-Started.md) | Local environment setup |
12
- | [Desenvolvimento](./Desenvolvimento.md) | Workflow, branching, commit hygiene |
12
+ | [Development](./Development.md) | Workflow, branching, commit hygiene |
13
13
  | [Arquitetura](./Arquitetura.md) | High-level technical architecture |
14
14
  | [Infraestrutura](./Infraestrutura.md) | Cloud / network / runtime topology |
15
15
  | [Deploy-Pipeline](./Deploy-Pipeline.md) | CI/CD flow and environments |
@@ -13,7 +13,7 @@ High-level technical architecture of **{{projectTitle}}**.
13
13
  graph TB
14
14
  subgraph "Developer"
15
15
  DEV[Engineers]
16
- LOCAL[{{projectDomain}}<br/>Lando + Docker]
16
+ LOCAL[{{projectDomain}}<br/>{{#if enable_kivo_wp}}kivo-wp Docker Compose{{else}}Lando + Docker{{/if}}]
17
17
  end
18
18
 
19
19
  subgraph "CI / CD"
@@ -54,7 +54,7 @@ graph TB
54
54
 
55
55
  | Component | Technology | Notes |
56
56
  | --- | --- | --- |
57
- | Database | `{{ "{{TODO: MySQL / MariaDB / managed service}}" }}` | Local dev uses MariaDB via Lando |
57
+ | Database | `{{ "{{TODO: MySQL / MariaDB / managed service}}" }}` | Local dev uses {{#if enable_kivo_wp}}MySQL 8.4 in the kivo-wp `db` service{{else}}MariaDB via Lando{{/if}} |
58
58
  | Object storage | `{{ "{{TODO: S3 / GCS / Azure Blob / NFS}}" }}` | For uploads, backups |
59
59
  | Cache | `{{ "{{TODO: Redis / Memcached / none}}" }}` | Object cache, sessions |
60
60
 
@@ -59,7 +59,27 @@ graph LR
59
59
  - *Docker push + remote pull*: build, push to `{{ "{{TODO: registry}}" }}`, SSH to remote, `docker compose pull && docker compose up -d`.
60
60
  - *Kubernetes*: `kubectl apply -f k8s/<env>/` (or `helm upgrade --install`).
61
61
  - *Cloud-managed (ECS / Cloud Run / App Runner)*: trigger service update with new image tag.
62
- - *SSH rsync*: `rsync -av --delete ./ user@host:/var/www/{{projectName}}/`.
62
+ - *SSH rsync*: sync an **allow list** (`index.php`, `wp-config.php`, `wp-cli.yml`, `vendor/`, `wp/`, `content/`), never `./`. See [Keep files out of the web root](#keep-files-out-of-the-web-root).
63
+
64
+ ## Keep files out of the web root
65
+
66
+ On a VPS/CloudPanel layout the deploy path **is** the document root: nginx serves whatever sits in it. Two
67
+ projects leaked this way (`.env` publicly readable on a production host; `CLAUDE.md`, `AGENTS.md`, `composer.lock`
68
+ and `vendor/composer/installed.json` on a staging host). The rules below are built into the generated project:
69
+
70
+ 1. **`.env` lives one level above the web root** (`<remote-root>/../.env`, mode 600). `wp-config.php` reads it
71
+ from there and falls back to the root when there is no file in the parent ({{#if enable_kivo_wp}}the local kivo-wp environment{{else}}Lando{{/if}}). The generated `ci.yml` passes
72
+ `env-location: parent` to `wp-post-deploy`.
73
+ 2. **Sync an allow list, not the repository.** `deploy-rsync` sends only `wp/`, `vendor/`, `content/*`, `index.php`,
74
+ `wp-config.php`. Anything else at the root (`CLAUDE.md`, `.mcp.json`, `.claude/`, `composer.*`, lint configs,
75
+ `docs/`, `tests/`) is development material. An exclude list fails silently on the first new file; an allow list does not.
76
+ 3. **Check from the outside.** `scripts/check-exposure.sh <url> [theme]` (and the `check-exposure` step in `ci.yml`,
77
+ which needs the `STAGING_URL` / `PRODUCTION_URL` environment variable) fails the deploy if a secret or
78
+ development file answers 200. Run it from an IP **outside** any WAF bypass to see what the public sees; from a
79
+ bypassed IP (your own, a CI runner on an allow list) it shows the origin, the stricter reading.
80
+ 4. **Defence in depth** (a file that slips through still cannot leave the server): deny dotfiles and `vendor/`,
81
+ `composer.*`, `package*.json`, `*.blade.php` in the vhost, and block them with a WAF rule. After deleting a file
82
+ from the origin, purge its URL on the CDN: a cached copy keeps being served.
63
83
 
64
84
  ## Secrets
65
85
 
@@ -1,7 +1,76 @@
1
- # Desenvolvimento
1
+ # Development
2
2
 
3
3
  Workflow and conventions for working on **{{projectTitle}}**.
4
4
 
5
+ {{#if enable_kivo_wp}}
6
+ ## Local environment (kivo-wp)
7
+
8
+ The project runs in a Docker Compose stack named `kivo-wp-{{projectName}}` (services `app`, `db`,
9
+ `cache`, `proxy`, `node`, `mail`). Every tool runs inside it through the scripts in `bin/`; nothing
10
+ needs PHP, Composer or Node.js on your machine.
11
+
12
+ ```bash
13
+ bin/setup # first run and any time after: build, start, install, seed (idempotent)
14
+ bin/up # start the stack
15
+ bin/down # stop it (bin/down --volumes also deletes the database; it asks first)
16
+ bin/info # URLs and service state
17
+ bin/logs # follow the logs
18
+ bin/wp <command> # WP-CLI (bin/wp acorn <command> for Acorn)
19
+ bin/composer <args> # Composer
20
+ bin/npm <args> # npm (bin/node for Node.js)
21
+ bin/build # build the theme assets
22
+ bin/dev # Vite dev server with HMR
23
+ bin/flush # flush WordPress, Acorn and object caches
24
+ bin/test # PHP tests
25
+ bin/e2e # Playwright tests
26
+ bin/xdebug on|off # toggle Xdebug without a rebuild
27
+ bin/shell [service] # shell in a service
28
+ ```
29
+
30
+ ### Ports and certificates
31
+
32
+ The site is served by Caddy at **https://{{projectName}}.localhost** with a local certificate
33
+ authority. `HTTPS_PORT` (default 443) and `HTTP_PORT` (default 80) in `.env` set the host ports;
34
+ when one is busy, `bin/setup` picks a free port and writes it to `.env` together with
35
+ `WORDPRESS_SITE_URL` (for example `https://{{projectName}}.localhost:8443`), then rewrites stored URLs
36
+ with `bin/wp search-replace`. Run `bin/trust-cert` once to export the CA and print the command that
37
+ trusts it on Linux, macOS or Windows (WSL).
38
+
39
+ ### Licensed packages
40
+
41
+ {{#if enable_acf_pro}}
42
+ ACF Pro is installed from `connect.advancedcustomfields.com`. Credentials never live in the
43
+ repository: `auth.json.tpl` holds 1Password references and `bin/setup` renders `auth.json` (mode 600,
44
+ gitignored) with `op inject -i auth.json.tpl -o auth.json`. Install the 1Password CLI (`op`) and sign
45
+ in before the first `bin/setup`.
46
+ {{else}}
47
+ No licensed Composer packages are configured. If one is added, keep its credentials as 1Password
48
+ references in `auth.json.tpl` and let `bin/setup` render `auth.json` with `op inject`.
49
+ {{/if}}
50
+
51
+ ### Data
52
+
53
+ `bin/setup` seeds an empty database with synthetic fixtures from `fixtures/` (users, posts, pages,
54
+ terms, a menu and options; every email is on `example.test`). `bin/seed` reseeds them and
55
+ `bin/seed --reset` empties the database first. Fixtures are the only data allowed in CI, Codespaces
56
+ and cloud agent sessions.
57
+
58
+ `bin/db-import <dump.sql[.gz]>` loads a sanitized snapshot. It is a **human-only, local** command: it
59
+ refuses to run when `CI`, `CODESPACES` or `CLAUDE_CODE_REMOTE` is set, and agents must never run it.
60
+ Sanitizing the snapshot (for example `wp db export` without sensitive tables, then an anonymizing
61
+ `wp search-replace`) is the responsibility of whoever produces it.
62
+ {{else}}
63
+ ## Local environment (Lando, deprecated)
64
+
65
+ Lando remains available for the 6.x line of wp-kit and is removed in 7.0.0. Common commands:
66
+ `lando start`, `lando wp <command>`, `lando composer <args>`, `lando npm <args>`, `lando flush`.
67
+ {{#if enable_acf_pro}}
68
+
69
+ ACF Pro credentials come from 1Password: render `auth.json` once with
70
+ `op inject -i auth.json.tpl -o auth.json` and keep it out of version control.
71
+ {{/if}}
72
+ {{/if}}
73
+
5
74
  ## Git workflow
6
75
 
7
76
  This project follows a **GitFlow-derived workflow** with three long-lived
@@ -96,6 +165,14 @@ chore(deps): bump roots/acorn to 6.2
96
165
 
97
166
  ## Lint and formatting
98
167
 
168
+ {{#if enable_kivo_wp}}
169
+ ```bash
170
+ bin/npm exec -- oxlint . # JavaScript lint
171
+ bin/npm exec -- oxfmt --write . # Format JS, JSON, YAML and Markdown
172
+ bin/mago lint # PHP lint
173
+ bin/mago format # PHP format
174
+ ```
175
+ {{else}}
99
176
  ```bash
100
177
  npm run lint # ESLint + Stylelint
101
178
  npm run lint:fix # Auto-fix where possible
@@ -103,6 +180,7 @@ npm run format # Prettier
103
180
  {{#if useSage}}composer lint --working-dir=content/themes/{{projectName}} # Pint
104
181
  composer lint:fix --working-dir=content/themes/{{projectName}}{{/if}}
105
182
  ```
183
+ {{/if}}
106
184
 
107
185
  Husky runs lint-staged on every commit so only changed files are
108
186
  checked; CI re-runs the full sweep.
@@ -111,7 +189,7 @@ checked; CI re-runs the full sweep.
111
189
 
112
190
  - **PHP**: `{{ "{{TODO: Pest suite location and how to invoke it}}" }}`
113
191
  - **E2E**: Playwright specs under `tests/e2e/`. Run locally with
114
- `npm run test:e2e`.
192
+ {{#if enable_kivo_wp}}`bin/e2e`{{else}}`npm run test:e2e`{{/if}}.
115
193
  - **Visual regression**: `{{ "{{TODO: define if/how visual regression is captured}}" }}`
116
194
 
117
195
  ## Releases
@@ -2,11 +2,79 @@
2
2
 
3
3
  Local development setup for **{{projectTitle}}**.
4
4
 
5
+ {{#if enable_kivo_wp}}
5
6
  ## Prerequisites
6
7
 
7
8
  | Tool | Version | Purpose |
8
9
  | --- | --- | --- |
9
- | [Lando](https://lando.dev/) | 3.0+ | Local environment orchestration |
10
+ | [Docker](https://docs.docker.com/get-started/get-docker/) | Engine 24+ with Compose v2 | Runs the kivo-wp stack |
11
+ | [Git](https://git-scm.com/) | any | Version control |
12
+ {{#if enable_acf_pro}}
13
+ | [1Password CLI](https://developer.1password.com/docs/cli/get-started/) | 2.x | Renders `auth.json` for ACF Pro |
14
+ {{/if}}
15
+
16
+ PHP, Composer and Node.js run inside the containers; you do not need them on your machine.
17
+
18
+ ## Clone and bootstrap
19
+
20
+ ```bash
21
+ git clone {{repositoryHttpsUrl}}
22
+ cd {{projectName}}
23
+ bin/setup
24
+ ```
25
+
26
+ `bin/setup` is idempotent and is the only command you need: it creates `.env` from `.env.example`
27
+ when missing, picks free ports, {{#if enable_acf_pro}}renders `auth.json` from 1Password with
28
+ `op inject` (sign in with `op signin` first), {{/if}}builds and starts the stack, installs Composer
29
+ and npm dependencies, builds the theme, installs WordPress ({{wpCoreVersion}}), seeds synthetic
30
+ fixtures into an empty database and prints the URLs and the local admin login. Flags: `--ci`,
31
+ `--quick`, `--fresh` (`bin/setup --help`).
32
+
33
+ Once it finishes, the site is at **https://{{projectName}}.localhost** (with the port from
34
+ `HTTPS_PORT` when it is not 443). Run `bin/trust-cert` once and follow the printed command so your
35
+ browser trusts the local certificate.
36
+
37
+ ## Database
38
+
39
+ The database starts with synthetic fixtures (`bin/seed`, `bin/seed --reset`). To work against a
40
+ sanitized snapshot on your own machine:
41
+
42
+ ```bash
43
+ bin/db-import path/to/sanitized-dump.sql.gz
44
+ bin/wp search-replace 'https://{{projectStagingDomain}}' "$(bin/wp option get home)" --all-tables
45
+ ```
46
+
47
+ `bin/db-import` is a human-only, local command: it refuses to run when `CI`, `CODESPACES` or
48
+ `CLAUDE_CODE_REMOTE` is set, and snapshots never go to CI, Codespaces or cloud agent sessions.
49
+
50
+ {{#if useSage}}
51
+ ## Theme build
52
+
53
+ The Sage theme lives under `content/themes/{{projectName}}`. Vite drives the asset pipeline:
54
+
55
+ ```bash
56
+ bin/dev # HMR dev server through https://vite.{{projectName}}.localhost
57
+ bin/build # Production build
58
+ ```
59
+ {{/if}}
60
+
61
+ ## Common commands
62
+
63
+ ```bash
64
+ bin/up # Start the stack
65
+ bin/down # Stop it
66
+ bin/info # URLs and service state
67
+ bin/logs # Follow container logs
68
+ bin/wp <command> # WP-CLI
69
+ bin/shell # Shell in the app service
70
+ bin/down --volumes # Delete the stack's data (asks first)
71
+ ```
72
+ {{else}}
73
+ ## Prerequisites
74
+
75
+ | Tool | Version | Purpose |
76
+ | --- | --- | --- |
77
+ | [Lando](https://lando.dev/) | 3.0+ | Local environment orchestration (deprecated; removed in wp-kit 7.0.0) |
10
78
  | [Docker](https://docker.com/) | 20.0+ | Container runtime backing Lando |
11
79
  | [Git](https://git-scm.com/) | any | Version control |
12
80
  | [Node.js](https://nodejs.org/) | {{nodeVersion}}+ | Build pipeline (Vite, lint) |
@@ -17,6 +85,9 @@ Local development setup for **{{projectTitle}}**.
17
85
  ```bash
18
86
  git clone {{repositoryHttpsUrl}}
19
87
  cd {{projectName}}
88
+ {{#if enable_acf_pro}}
89
+ op inject -i auth.json.tpl -o auth.json # ACF Pro credentials from 1Password
90
+ {{/if}}
20
91
  lando start
21
92
  ```
22
93
 
@@ -63,6 +134,7 @@ lando wp <command> # Run WP-CLI against the Lando WordPress
63
134
  lando ssh # Shell into the appserver
64
135
  lando destroy # Wipe containers (data is preserved on disk)
65
136
  ```
137
+ {{/if}}
66
138
 
67
139
  ## Editor setup
68
140
 
@@ -73,11 +145,10 @@ open.
73
145
 
74
146
  ## What to read next
75
147
 
76
- - [Desenvolvimento](./Desenvolvimento.md) — git workflow and {{prTermShort}} hygiene
148
+ - [Development](./Development.md) — local environment, git workflow and {{prTermShort}} hygiene
77
149
  - [Arquitetura](./Arquitetura.md) — how the pieces fit together
78
150
 
79
151
  ## Troubleshooting
80
152
 
81
153
  If anything goes wrong during the first boot, check
82
- [Troubleshooting](./Troubleshooting.md) — common Lando/Docker issues
83
- are listed there.
154
+ [Troubleshooting](./Troubleshooting.md).
@@ -62,7 +62,7 @@ In production behind edge auth, provision **both** parts:
62
62
  prefix, so this defines `DISABLE_WP_CRON`. It must be `WORDPRESS_DISABLE_WP_CRON` — not
63
63
  `WORDPRESS_DISABLE_CRON`, which would define `DISABLE_CRON` and be ignored by WordPress.
64
64
 
65
- Do not enable this in the local `.env`: under Lando the loopback works and is convenient.
65
+ Do not enable this in the local `.env`: under {{#if enable_kivo_wp}}kivo-wp{{else}}Lando{{/if}} the loopback works and is convenient{{#if enable_kivo_wp}} (bin/setup sets it only in Codespaces){{/if}}.
66
66
  See [Troubleshooting](./Troubleshooting.md) for the symptom and diagnosis.
67
67
 
68
68
  ## Secrets and IAM
@@ -18,6 +18,22 @@ Each entry follows the same shape:
18
18
 
19
19
  ---
20
20
 
21
+ {{#if enable_kivo_wp}}
22
+ ### `bin/setup` reports "ports are not available"
23
+
24
+ **Symptom**: the stack does not start and Docker reports that a host port is not available.
25
+ **Likely cause**: another local stack, a system service or (on WSL) a Windows service holds the port
26
+ set by `HTTPS_PORT` or `HTTP_PORT` in `.env`.
27
+ **Fix**:
28
+
29
+ 1. Run `bin/setup` again: it moves busy ports to free ones and updates `WORDPRESS_SITE_URL`.
30
+ 2. To choose the ports yourself, set `HTTPS_PORT` and `HTTP_PORT` in `.env` and run `bin/setup`.
31
+ 3. `sudo lsof -i :443` identifies a process holding a port on Linux and macOS.
32
+
33
+ **Why this is the fix**: Caddy publishes the host ports from `.env`; `bin/setup` keeps the site URL in
34
+ step with them and rewrites stored URLs.
35
+
36
+ {{else}}
21
37
  ### `lando start` fails with "port already in use"
22
38
 
23
39
  **Symptom**: Lando fails to start with `Error starting the network: ports are not available`.
@@ -31,6 +47,7 @@ Each entry follows the same shape:
31
47
 
32
48
  **Why this is the fix**: Lando binds host ports; conflicts surface as start failures, not run failures.
33
49
 
50
+ {{/if}}
34
51
  ---
35
52
 
36
53
  ### Composer install hangs or 404s on a wpackagist plugin
@@ -64,7 +81,7 @@ Each entry follows the same shape:
64
81
 
65
82
  ### Scheduled tasks never run / a plugin screen stays empty (behind edge auth)
66
83
 
67
- **Symptom**: A plugin admin screen that loads data via a background refresh never populates (e.g. an items list spins or returns empty forever). More generally: any `wp_schedule_event` / WP-Cron job silently never fires in production, while the same code works under Lando.
84
+ **Symptom**: A plugin admin screen that loads data via a background refresh never populates (e.g. an items list spins or returns empty forever). More generally: any `wp_schedule_event` / WP-Cron job silently never fires in production, while the same code works under {{#if enable_kivo_wp}}kivo-wp{{else}}Lando{{/if}}.
68
85
  **Likely cause**: The site is behind **Cloudflare Access** (or any edge auth fronting the whole domain). Default WP-Cron fires via a loopback HTTP request to `/wp/wp-cron.php`, which the edge `302`-redirects to its login — so `wp-cron.php` never executes and no scheduled event runs. The browser's `admin-ajax` still works (it carries the auth cookie), so the page loads but the background job never completes.
69
86
  **Fix**:
70
87
 
@@ -0,0 +1,3 @@
1
+ # kivo-wp: commitlint runs in the node service through bin/npm.
2
+ echo "🔍 Validating commit message..."
3
+ bin/npm exec -- commitlint --edit "$1"
@@ -0,0 +1,25 @@
1
+ # kivo-wp: every tool runs in the Compose stack through bin/* (start it with bin/up).
2
+ echo "🔍 Running pre-commit checks..."
3
+
4
+ if [ -z "$(git diff --cached --name-only)" ]; then
5
+ echo "ℹ️ No staged files, skipping pre-commit checks"
6
+ exit 0
7
+ fi
8
+
9
+ if [ -f ".lintstagedrc.json" ]; then
10
+ echo "📝 Running lint-staged..."
11
+ bin/npm exec -- lint-staged
12
+ fi
13
+
14
+ # PHP formatting: the node service has no PHP, so staged PHP files are formatted with
15
+ # bin/mago in the app service and staged again.
16
+ php_files="$(git diff --cached --name-only --diff-filter=ACMR -- '*.php')"
17
+ if [ -n "$php_files" ] && [ -f vendor/bin/mago ]; then
18
+ echo "🐘 Formatting staged PHP files with Mago..."
19
+ echo "$php_files" | while IFS= read -r file; do
20
+ bin/mago format --no-progress "$file"
21
+ git add -- "$file"
22
+ done
23
+ fi
24
+
25
+ echo "✅ Pre-commit checks completed!"
@@ -12,13 +12,9 @@ if [ -z "$(git diff --cached --name-only)" ]; then
12
12
  exit 0
13
13
  fi
14
14
 
15
+ # lint-staged runs where git runs (the host); its PHP entries reach the
16
+ # environment through their own commands.
15
17
  echo "📝 Running lint-staged..."
16
- if command -v lando >/dev/null 2>&1 && lando info >/dev/null 2>&1; then
17
- echo "🐳 Using Lando environment..."
18
- lando lint-staged
19
- else
20
- echo "🏠 Using local environment..."
21
- npx lint-staged
22
- fi
18
+ npx --no lint-staged
23
19
 
24
20
  echo "✅ Pre-commit checks completed!"