@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
@@ -4,12 +4,13 @@ import { fileURLToPath } from "url";
4
4
  import { Command } from "commander";
5
5
  import fs from "fs-extra";
6
6
 
7
- import { runPrompts } from "../prompts/index.js";
7
+ import { ACF_OP_REFERENCE_PLACEHOLDER, runPrompts } from "../prompts/index.js";
8
+ import { renderAuthTemplate } from "../utils/auth-template.js";
8
9
  import { Generator } from "../core/generator.js";
9
10
  import { log, color } from "../utils/logger.js";
10
11
  import { toEnvExample } from "../utils/env-example.js";
11
- import { inferCiCapabilities } from "../core/infer-ci-capabilities.js";
12
- import { VERSION_REGISTRY, validateVersionCompatibility } from "../config/versions.js";
12
+ import { inferCiCapabilities, resolveContentDir } from "../core/infer-ci-capabilities.js";
13
+ import { validateVersionCompatibility } from "../config/versions.js";
13
14
 
14
15
  const __filename = fileURLToPath(import.meta.url);
15
16
  const __dirname = path.dirname(__filename);
@@ -31,12 +32,10 @@ export const initCommand = new Command("init")
31
32
 
32
33
  // 🔧 Ajustes automáticos para Sage 11
33
34
  if (context.useSage && context.sageVersion === "11") {
34
- context.phpVersion = VERSION_REGISTRY.php.latest;
35
35
  context.nodeVersion = "24";
36
36
  context.wpCoreVersion = "7.0";
37
37
 
38
38
  log(color.orange, "🔧 Sage 11 selected — automatically adjusting versions:");
39
- log(color.orange, ` → PHP: ${VERSION_REGISTRY.php.latest}`);
40
39
  log(color.orange, " → Node: 24");
41
40
  log(color.orange, " → WP Core: 7.0");
42
41
  }
@@ -57,6 +56,8 @@ export const initCommand = new Command("init")
57
56
  }
58
57
 
59
58
  context.cwd = target;
59
+ context.contentDir = resolveContentDir(target);
60
+ context.enabledModules = enabledModules;
60
61
 
61
62
  // 🧠 Inferência de capacidades de CI
62
63
  context.ci = inferCiCapabilities(context);
@@ -83,25 +84,24 @@ export const initCommand = new Command("init")
83
84
  // Keys-only companion that is safe to commit; the real file stays ignored.
84
85
  const envFile = ".env";
85
86
  const envContent = await fs.readFile(path.join(target, envFile), "utf8");
86
- await fs.outputFile(path.join(target, `${envFile}.example`), toEnvExample(envContent));
87
- if (context.enable_acf_pro && context.acf_license_key) {
88
- await generator.generateFile("auth.json", context);
89
- } else if (context.enable_acf_pro) {
90
- log(
91
- color.orange,
92
- "⚠️ auth.json not generated: add your ACF license key to auth.json manually.",
87
+ // kivo-wp keeps its non-secret local defaults in the example (D-028); bin/setup copies it and
88
+ // generates the secret values. Lando keeps a keys-only example.
89
+ await fs.outputFile(
90
+ path.join(target, `${envFile}.example`),
91
+ toEnvExample(envContent, { keepValue: () => context.dev_environment === "kivo-wp" }),
92
+ );
93
+ // D-014: no licence key is ever written by the generator; auth.json is rendered from these
94
+ // op:// references by bin/setup (kivo-wp) or by `op inject` (Lando), and stays gitignored.
95
+ if (context.enable_acf_pro) {
96
+ await fs.outputFile(
97
+ path.join(target, "auth.json.tpl"),
98
+ renderAuthTemplate(context.acf_op_reference || ACF_OP_REFERENCE_PLACEHOLDER),
93
99
  );
94
- log(color.orange, " See: https://www.advancedcustomfields.com/my-account/");
95
100
  }
96
101
  await generator.generateFile(".editorconfig", context);
97
102
  await generator.generateFile("server/cmd/install-wp.sh", context);
98
103
  await generator.generateFile("server/cmd/setup-php.sh", context);
99
104
  await generator.generateFile("server/cmd/setup-node.sh", context);
100
- await generator.generateFile(".devcontainer/devcontainer.json", context);
101
- await generator.generateFile(".devcontainer/docker-compose.yml", context);
102
- await generator.generateFile(".devcontainer/Dockerfile", context);
103
- await generator.generateFile(".devcontainer/setup.sh", context);
104
- await generator.generateFile(".devcontainer/config/nginx.conf", context);
105
105
 
106
106
  await generator.copyFile(".cspell.json");
107
107
 
@@ -117,14 +117,13 @@ export const initCommand = new Command("init")
117
117
  await fs.chmod(path.join(target, "server/cmd/install-wp.sh"), 0o755);
118
118
  await fs.chmod(path.join(target, "server/cmd/setup-php.sh"), 0o755);
119
119
  await fs.chmod(path.join(target, "server/cmd/setup-node.sh"), 0o755);
120
- await fs.chmod(path.join(target, ".devcontainer/setup.sh"), 0o755);
121
120
 
122
121
  await generator.generateFile("server/www/vhosts.conf", context);
123
122
  if (context.useRocket) {
124
123
  await generator.copyFile("server/www/rocket.conf");
125
124
  }
126
125
 
127
- await generator.copyFile("wp-config.php");
126
+ await generator.generateFile("wp-config.php", context);
128
127
  await generator.copyFile("index.php");
129
128
  await generator.generateFile("wp-cli.yml", context);
130
129
 
@@ -146,12 +145,15 @@ export const initCommand = new Command("init")
146
145
  mergeStrategy: "concat",
147
146
  });
148
147
 
149
- await generator.generateModularFile({
150
- baseTemplate: ".lando.yml",
151
- modules: enabledModules,
152
- context,
153
- mergeStrategy: "concat",
154
- });
148
+ // The Landofile belongs to the deprecated Lando choice only (D-008); kivo-wp renders compose.yaml.
149
+ if (context.dev_environment === "lando") {
150
+ await generator.generateModularFile({
151
+ baseTemplate: ".lando.yml",
152
+ modules: enabledModules,
153
+ context,
154
+ mergeStrategy: "concat",
155
+ });
156
+ }
155
157
 
156
158
  await generator.generateModularFile({
157
159
  baseTemplate: "workspace.json",
@@ -30,7 +30,8 @@ export const VERSION_REGISTRY = {
30
30
  sage: {
31
31
  11: {
32
32
  tag: "v11.0.1",
33
- minPhp: "8.2",
33
+ // Q-032: the theme requires roots/acorn-ai, which needs PHP 8.4+.
34
+ minPhp: "8.4",
34
35
  acornVersion: "6.1.0",
35
36
  nodeMin: "20",
36
37
  status: "active",
@@ -83,8 +84,33 @@ export const VERSION_REGISTRY = {
83
84
  18: { start: "2022-10-25", end: "2025-04-30" },
84
85
  },
85
86
  },
87
+
88
+ /**
89
+ * kivo-wp images (Docker Compose environment). Pinned so every project builds the same
90
+ * stack; the scheduled tag check in wp-kit CI catches a removed tag.
91
+ */
92
+ kivoWp: {
93
+ // serversideup/php release suffix: serversideup/php:<php>-fpm-nginx-<release>
94
+ serversidePhpRelease: "v5.2.1",
95
+ images: {
96
+ db: "mysql:8.4",
97
+ cache: "valkey/valkey:8.1.12-alpine",
98
+ proxy: "caddy:2.11.9-alpine",
99
+ mail: "axllent/mailpit:v1.34.0",
100
+ },
101
+ wpCli: {
102
+ version: "2.12.0",
103
+ sha512:
104
+ "be928f6b8ca1e8dfb9d2f4b75a13aa4aee0896f8a9a0a1c45cd5d2c98605e6172e6d014dda2e27f88c98befc16c040cbb2bd1bfa121510ea5cdf5f6a30fe8832",
105
+ },
106
+ },
86
107
  };
87
108
 
109
+ /** Base image of the kivo-wp app service for a PHP version. */
110
+ export function serversidePhpImage(phpVersion) {
111
+ return `serversideup/php:${phpVersion}-fpm-nginx-${VERSION_REGISTRY.kivoWp.serversidePhpRelease}`;
112
+ }
113
+
88
114
  /**
89
115
  * Helper functions for version management
90
116
  */
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Hosts a Claude Code cloud session needs in Limited network mode for a kivo-wp project
3
+ * (spec section 4, kivo-wise spec S-6). Generated from the enabled modules; rendered into
4
+ * docs/cloud-sessions.md.
5
+ */
6
+ const BASE_HOSTS = [
7
+ // Docker Hub
8
+ "registry-1.docker.io",
9
+ "auth.docker.io",
10
+ "production.cloudflare.docker.com",
11
+ // GitHub container registry and its layer storage
12
+ "ghcr.io",
13
+ "pkg-containers.githubusercontent.com",
14
+ // Composer
15
+ "repo.packagist.org",
16
+ "packagist.org",
17
+ "wpackagist.org",
18
+ // npm
19
+ "registry.npmjs.org",
20
+ // WordPress.org API and downloads (core, translations)
21
+ "api.wordpress.org",
22
+ "downloads.wordpress.org",
23
+ // Documentation hosts used by the kivo-wise skills when no local corpus exists
24
+ "developer.wordpress.org",
25
+ "roots.io",
26
+ "docs.docker.com",
27
+ "containers.dev",
28
+ ];
29
+
30
+ /**
31
+ * @param {{ enable_acf_pro?: boolean }} context - generator context
32
+ * @returns {string[]} sorted, unique host names
33
+ */
34
+ export function buildCloudAllowlist(context) {
35
+ const hosts = new Set(BASE_HOSTS);
36
+ if (context.enable_acf_pro) hosts.add("connect.advancedcustomfields.com");
37
+ return [...hosts].sort();
38
+ }
@@ -1,13 +1,13 @@
1
1
  // lib/core/generator.js
2
- import path from 'path';
3
- import crypto from 'crypto';
2
+ import path from "path";
3
+ import crypto from "crypto";
4
4
 
5
- import fs from 'fs-extra';
6
- import handlebars from 'handlebars';
7
- import mergeWith from 'lodash.mergewith';
8
- import yaml from 'js-yaml';
5
+ import fs from "fs-extra";
6
+ import handlebars from "handlebars";
7
+ import mergeWith from "lodash.mergewith";
8
+ import yaml from "js-yaml";
9
9
 
10
- import { log, color } from '../utils/logger.js';
10
+ import { log, color } from "../utils/logger.js";
11
11
  import {
12
12
  PACKAGE_ROOT,
13
13
  MODULES_PATH,
@@ -15,9 +15,9 @@ import {
15
15
  getModulePath,
16
16
  getModuleTemplatePath,
17
17
  getBaseTemplatePath,
18
- } from '../utils/paths.js';
18
+ } from "../utils/paths.js";
19
19
 
20
- import { HookManager } from './hook-manager.js';
20
+ import { HookManager } from "./hook-manager.js";
21
21
 
22
22
  export class Generator {
23
23
  constructor(baseDir = process.cwd()) {
@@ -25,7 +25,7 @@ export class Generator {
25
25
  this.hooks = new HookManager();
26
26
  }
27
27
 
28
- async copyFile(sourcePathRelative, moduleName = null, outputName = '') {
28
+ async copyFile(sourcePathRelative, moduleName = null, outputName = "") {
29
29
  const baseDir = moduleName ? getModulePath(moduleName) : PACKAGE_ROOT;
30
30
 
31
31
  outputName = outputName ? outputName : sourcePathRelative;
@@ -44,7 +44,7 @@ export class Generator {
44
44
  * @param {string} outputName - Nome da pasta de destino (opcional)
45
45
  * @param {boolean} overwrite - Se deve sobrescrever arquivos existentes (padrão: true)
46
46
  */
47
- async copyDirectory(sourcePathRelative, moduleName = null, outputName = '', overwrite = true) {
47
+ async copyDirectory(sourcePathRelative, moduleName = null, outputName = "", overwrite = true) {
48
48
  const baseDir = moduleName ? getModulePath(moduleName) : PACKAGE_ROOT;
49
49
 
50
50
  outputName = outputName ? outputName : sourcePathRelative;
@@ -107,15 +107,15 @@ export class Generator {
107
107
  }
108
108
  }
109
109
 
110
- async generateFile(templatePathRelative, context, moduleName = null, outputName = '') {
111
- const baseDir = moduleName ? getModuleTemplatePath(moduleName, '') : TEMPLATES_PATH;
110
+ async generateFile(templatePathRelative, context, moduleName = null, outputName = "") {
111
+ const baseDir = moduleName ? getModuleTemplatePath(moduleName, "") : TEMPLATES_PATH;
112
112
 
113
113
  outputName = outputName ? outputName : templatePathRelative;
114
114
 
115
- const templatePath = path.resolve(baseDir, templatePathRelative + '.hbs');
115
+ const templatePath = path.resolve(baseDir, templatePathRelative + ".hbs");
116
116
  const outputPath = path.join(this.cwd, outputName);
117
117
 
118
- const content = await fs.readFile(templatePath, 'utf8');
118
+ const content = await fs.readFile(templatePath, "utf8");
119
119
  const template = handlebars.compile(content);
120
120
  const result = template(context);
121
121
 
@@ -132,27 +132,33 @@ export class Generator {
132
132
  * @param {Object} [options.context={}] - Contexto para handlebars
133
133
  * @param {'json'|'yaml'} [options.format='yaml'] - Formato do arquivo
134
134
  * @param {'concat'|'replace'} [options.mergeStrategy='concat'] - Estratégia de merge de arrays
135
+ * @param {string} [options.baseModule] - Module that owns the base template (default: templates/)
136
+ * @param {string} [options.header] - Comment block written before YAML output (YAML drops comments)
135
137
  */
136
138
  async generateModularFile({
137
139
  baseTemplate,
138
- outputFile = '',
140
+ baseModule = null,
141
+ header = "",
142
+ outputFile = "",
139
143
  modules = [],
140
144
  context = {},
141
- format = 'yaml',
142
- mergeStrategy = 'replace',
145
+ format = "yaml",
146
+ mergeStrategy = "replace",
143
147
  debug = false,
144
148
  }) {
145
- const baseTemplatePath = getBaseTemplatePath(baseTemplate + '.hbs');
146
- const baseRaw = await fs.readFile(baseTemplatePath, 'utf8');
149
+ const baseTemplatePath = baseModule
150
+ ? getModuleTemplatePath(baseModule, baseTemplate + ".hbs")
151
+ : getBaseTemplatePath(baseTemplate + ".hbs");
152
+ const baseRaw = await fs.readFile(baseTemplatePath, "utf8");
147
153
  const compiledBase = handlebars.compile(baseRaw);
148
154
  outputFile = outputFile ? outputFile : baseTemplate;
149
155
  let mergedOutput;
150
156
  try {
151
157
  mergedOutput =
152
- format === 'json' ? JSON.parse(compiledBase(context)) : yaml.load(compiledBase(context));
158
+ format === "json" ? JSON.parse(compiledBase(context)) : yaml.load(compiledBase(context));
153
159
  } catch (err) {
154
160
  if (debug) {
155
- log(color.red, '[DEBUG] Erro ao fazer parse do template base:');
161
+ log(color.red, "[DEBUG] Erro ao fazer parse do template base:");
156
162
  log(color.red, compiledBase(context));
157
163
  log(color.red, err);
158
164
  }
@@ -161,20 +167,20 @@ export class Generator {
161
167
 
162
168
  function customizer(objValue, srcValue) {
163
169
  if (Array.isArray(objValue) && Array.isArray(srcValue)) {
164
- return mergeStrategy === 'concat' ? objValue.concat(srcValue) : srcValue;
170
+ return mergeStrategy === "concat" ? objValue.concat(srcValue) : srcValue;
165
171
  }
166
172
  }
167
173
 
168
- for (const mod of modules) {
169
- const modPath = getModuleTemplatePath(mod, path.basename(baseTemplate) + '.hbs');
174
+ for (const mod of modules.filter((name) => name !== baseModule)) {
175
+ const modPath = getModuleTemplatePath(mod, path.basename(baseTemplate) + ".hbs");
170
176
 
171
177
  if (await fs.pathExists(modPath)) {
172
- const modRaw = await fs.readFile(modPath, 'utf8');
178
+ const modRaw = await fs.readFile(modPath, "utf8");
173
179
  const compiledMod = handlebars.compile(modRaw);
174
180
  let modParsed;
175
181
  try {
176
182
  modParsed =
177
- format === 'json' ? JSON.parse(compiledMod(context)) : yaml.load(compiledMod(context));
183
+ format === "json" ? JSON.parse(compiledMod(context)) : yaml.load(compiledMod(context));
178
184
  } catch (err) {
179
185
  if (debug) {
180
186
  log(color.red, `[DEBUG] Erro ao fazer parse do template do módulo ${mod}:`);
@@ -188,9 +194,9 @@ export class Generator {
188
194
  }
189
195
 
190
196
  const finalOutput =
191
- format === 'json'
197
+ format === "json"
192
198
  ? JSON.stringify(mergedOutput, null, 2)
193
- : yaml.dump(mergedOutput, { lineWidth: 120 });
199
+ : (header ? `${header}\n` : "") + yaml.dump(mergedOutput, { lineWidth: 120, noRefs: true });
194
200
 
195
201
  const outputPath = path.join(this.cwd, outputFile);
196
202
  await fs.outputFile(outputPath, finalOutput);
@@ -201,9 +207,9 @@ export class Generator {
201
207
  existingFile,
202
208
  moduleTemplatePath,
203
209
  context,
204
- format = 'json',
210
+ format = "json",
205
211
  moduleName = null,
206
- mergeStrategy = 'replace',
212
+ mergeStrategy = "replace",
207
213
  debug = false,
208
214
  }) {
209
215
  const existingPath = path.isAbsolute(existingFile)
@@ -215,31 +221,31 @@ export class Generator {
215
221
  throw new Error(`File to merge not found: ${existingPath}`);
216
222
  }
217
223
 
218
- const existingRaw = await fs.readFile(existingPath, 'utf8');
224
+ const existingRaw = await fs.readFile(existingPath, "utf8");
219
225
  let existingParsed;
220
226
  try {
221
- existingParsed = format === 'json' ? JSON.parse(existingRaw) : yaml.load(existingRaw);
227
+ existingParsed = format === "json" ? JSON.parse(existingRaw) : yaml.load(existingRaw);
222
228
  } catch (err) {
223
229
  if (debug) {
224
- log(color.red, '[DEBUG] Erro ao fazer parse do arquivo existente:');
230
+ log(color.red, "[DEBUG] Erro ao fazer parse do arquivo existente:");
225
231
  log(color.red, existingRaw);
226
232
  log(color.red, err);
227
233
  }
228
234
  throw err;
229
235
  }
230
236
 
231
- const moduleBase = moduleName ? getModuleTemplatePath(moduleName, '') : TEMPLATES_PATH;
232
- const templatePath = path.resolve(moduleBase, moduleTemplatePath + '.hbs');
237
+ const moduleBase = moduleName ? getModuleTemplatePath(moduleName, "") : TEMPLATES_PATH;
238
+ const templatePath = path.resolve(moduleBase, moduleTemplatePath + ".hbs");
233
239
 
234
- const modRaw = await fs.readFile(templatePath, 'utf8');
240
+ const modRaw = await fs.readFile(templatePath, "utf8");
235
241
  const compiledMod = handlebars.compile(modRaw);
236
242
  let modParsed;
237
243
  try {
238
244
  modParsed =
239
- format === 'json' ? JSON.parse(compiledMod(context)) : yaml.load(compiledMod(context));
245
+ format === "json" ? JSON.parse(compiledMod(context)) : yaml.load(compiledMod(context));
240
246
  } catch (err) {
241
247
  if (debug) {
242
- log(color.red, '[DEBUG] Erro ao fazer parse do template do módulo:');
248
+ log(color.red, "[DEBUG] Erro ao fazer parse do template do módulo:");
243
249
  log(color.red, compiledMod(context));
244
250
  log(color.red, err);
245
251
  }
@@ -248,14 +254,14 @@ export class Generator {
248
254
 
249
255
  function customizer(objValue, srcValue) {
250
256
  if (Array.isArray(objValue) && Array.isArray(srcValue)) {
251
- return mergeStrategy === 'concat' ? objValue.concat(srcValue) : srcValue;
257
+ return mergeStrategy === "concat" ? objValue.concat(srcValue) : srcValue;
252
258
  }
253
259
  }
254
260
 
255
261
  const merged = mergeWith({}, existingParsed, modParsed, customizer);
256
262
 
257
263
  const output =
258
- format === 'json' ? JSON.stringify(merged, null, 2) : yaml.dump(merged, { lineWidth: 120 });
264
+ format === "json" ? JSON.stringify(merged, null, 2) : yaml.dump(merged, { lineWidth: 120 });
259
265
 
260
266
  await fs.outputFile(existingPath, output);
261
267
  log(color.blue, `🔀 Merged into: ${existingPath}`);
@@ -263,16 +269,16 @@ export class Generator {
263
269
 
264
270
  static generateSalts() {
265
271
  return [
266
- 'AUTH_KEY',
267
- 'SECURE_AUTH_KEY',
268
- 'LOGGED_IN_KEY',
269
- 'NONCE_KEY',
270
- 'AUTH_SALT',
271
- 'SECURE_AUTH_SALT',
272
- 'LOGGED_IN_SALT',
273
- 'NONCE_SALT',
272
+ "AUTH_KEY",
273
+ "SECURE_AUTH_KEY",
274
+ "LOGGED_IN_KEY",
275
+ "NONCE_KEY",
276
+ "AUTH_SALT",
277
+ "SECURE_AUTH_SALT",
278
+ "LOGGED_IN_SALT",
279
+ "NONCE_SALT",
274
280
  ].reduce((acc, key) => {
275
- acc[key] = crypto.randomBytes(64).toString('base64');
281
+ acc[key] = crypto.randomBytes(64).toString("base64");
276
282
  return acc;
277
283
  }, {});
278
284
  }
@@ -10,13 +10,25 @@ function fileExists(filePath) {
10
10
  }
11
11
  }
12
12
 
13
+ /**
14
+ * Content directories a WordPress project may use, in detection order. wp-kit generates
15
+ * `content/`; the others cover Bedrock-style and stock layouts.
16
+ */
17
+ export const CONTENT_PATH_CANDIDATES = Object.freeze(["content", "web/app", "wp-content"]);
18
+
19
+ /** First candidate that exists under cwd, else the generated default (`content`). */
20
+ export function resolveContentDir(cwd) {
21
+ return (
22
+ CONTENT_PATH_CANDIDATES.find((dir) => cwd && fileExists(path.join(cwd, dir))) ??
23
+ CONTENT_PATH_CANDIDATES[0]
24
+ );
25
+ }
26
+
13
27
  function detectThemePaths(context, hasSage) {
14
28
  const projectName = context.projectName;
15
- const candidates = [
16
- path.join(context.cwd, "content", "themes", projectName),
17
- path.join(context.cwd, "web", "app", "themes", projectName),
18
- path.join(context.cwd, "wp-content", "themes", projectName),
19
- ];
29
+ const candidates = CONTENT_PATH_CANDIDATES.map((dir) =>
30
+ path.join(context.cwd, dir, "themes", projectName),
31
+ );
20
32
 
21
33
  for (const abs of candidates) {
22
34
  if (fileExists(abs)) {
@@ -7,6 +7,60 @@ import { VERSION_REGISTRY } from "../config/versions.js";
7
7
 
8
8
  import { loadModulePrompts } from "./loadModulePrompts.js";
9
9
 
10
+ // D-014: licensed Composer credentials are 1Password references, never typed into the generator.
11
+ export const ACF_OP_REFERENCE_PLACEHOLDER = "op://<vault>/<item>";
12
+
13
+ // D-010: 8.4 is the default for every scaffold, Sage 11 included.
14
+ export const DEFAULT_PHP_VERSION = "8.4";
15
+
16
+ export function resolvePhpVersion(value) {
17
+ const version = String(value).trim();
18
+ const { supported } = VERSION_REGISTRY.php;
19
+ if (!supported.includes(version)) {
20
+ throw new Error(
21
+ `Unsupported PHP version "${version}". Supported versions: ${supported.join(", ")}.`,
22
+ );
23
+ }
24
+ return version;
25
+ }
26
+
27
+ // Q-032: Sage 11 requires PHP 8.4+ (roots/acorn-ai); older versions are not offered with Sage.
28
+ export function phpVersionsFor(contentModules = []) {
29
+ const { supported } = VERSION_REGISTRY.php;
30
+ if (!contentModules.includes("sage")) return supported;
31
+ const minPhp = parseFloat(VERSION_REGISTRY.sage[11].minPhp);
32
+ return supported.filter((v) => parseFloat(v) >= minPhp);
33
+ }
34
+
35
+ export function assertPhpForModules(version, contentModules = []) {
36
+ if (!phpVersionsFor(contentModules).includes(version)) {
37
+ throw new Error(
38
+ `Sage requires PHP ${VERSION_REGISTRY.sage[11].minPhp}+ (got ${version}). ` +
39
+ `Choose one of: ${phpVersionsFor(contentModules).join(", ")}, or a scaffold without Sage.`,
40
+ );
41
+ }
42
+ return version;
43
+ }
44
+
45
+ // D-008: kivo-wp is the default environment; Lando stays for 6.x as a deprecated choice.
46
+ export const DEV_ENVIRONMENTS = ["kivo-wp", "lando"];
47
+ export const DEFAULT_DEV_ENVIRONMENT = "kivo-wp";
48
+
49
+ export function resolveDevEnvironment(value) {
50
+ const environment = String(value).trim();
51
+ if (!DEV_ENVIRONMENTS.includes(environment)) {
52
+ throw new Error(
53
+ `Unknown dev environment "${environment}". Supported environments: ${DEV_ENVIRONMENTS.join(", ")}.`,
54
+ );
55
+ }
56
+ return environment;
57
+ }
58
+
59
+ // Hostname of the local site for the chosen environment.
60
+ export function localDomain(projectName, devEnvironment) {
61
+ return devEnvironment === "lando" ? `${projectName}.lndo.site` : `${projectName}.localhost`;
62
+ }
63
+
10
64
  function parseBooleanEnv(value) {
11
65
  if (typeof value !== "string") return null;
12
66
  const normalized = value.trim().toLowerCase();
@@ -150,7 +204,16 @@ export async function runPrompts({ defaults = false } = {}) {
150
204
  message: "Repository URL:",
151
205
  default: defaultsGit.gitRepository,
152
206
  },
153
- // phpVersion (VERSION_REGISTRY.php.latest) and nodeVersion ('24') are injected into context, not prompted
207
+ {
208
+ type: "list",
209
+ name: "dev_environment",
210
+ message: "Local development environment:",
211
+ choices: [
212
+ { name: "kivo-wp (Docker Compose)", value: "kivo-wp" },
213
+ { name: "Lando (deprecated, removed in 7.0.0)", value: "lando" },
214
+ ],
215
+ default: DEFAULT_DEV_ENVIRONMENT,
216
+ },
154
217
  {
155
218
  type: "list",
156
219
  name: "wpCoreVersion",
@@ -182,6 +245,15 @@ export async function runPrompts({ defaults = false } = {}) {
182
245
  ],
183
246
  default: ["sage"],
184
247
  },
248
+ // php_version feeds context.phpVersion for every environment (D-010); nodeVersion ('24') is injected.
249
+ // It follows the content modules so Sage only offers the versions it installs on (Q-032).
250
+ {
251
+ type: "list",
252
+ name: "php_version",
253
+ message: "PHP version:",
254
+ choices: (answers) => phpVersionsFor(answers.selectedContentModules),
255
+ default: DEFAULT_PHP_VERSION,
256
+ },
185
257
  {
186
258
  type: "confirm",
187
259
  name: "enable_acf_pro",
@@ -190,10 +262,10 @@ export async function runPrompts({ defaults = false } = {}) {
190
262
  },
191
263
  {
192
264
  type: "input",
193
- name: "acf_license_key",
265
+ name: "acf_op_reference",
194
266
  message:
195
- "ACF Pro license key (from connect.advancedcustomfields.com — leave blank to configure later):",
196
- default: "",
267
+ "1Password item for the ACF Pro credentials (op://<vault>/<item>; fields license-key and site-url):",
268
+ default: ACF_OP_REFERENCE_PLACEHOLDER,
197
269
  when: (answers) => answers.enable_acf_pro,
198
270
  },
199
271
  {
@@ -268,11 +340,34 @@ export async function runPrompts({ defaults = false } = {}) {
268
340
  defaultAnswers.gitProvider = envGitProvider;
269
341
  }
270
342
 
343
+ // WP_KIT_DEV_ENVIRONMENT: overrides dev_environment (kivo-wp or lando).
344
+ if (process.env.WP_KIT_DEV_ENVIRONMENT) {
345
+ defaultAnswers.dev_environment = resolveDevEnvironment(process.env.WP_KIT_DEV_ENVIRONMENT);
346
+ }
347
+
348
+ // WP_KIT_ACF_PRO: overrides enable_acf_pro (the e2e and image tests run without a licence).
349
+ const envAcfPro = parseBooleanEnv(process.env.WP_KIT_ACF_PRO);
350
+ if (envAcfPro !== null) {
351
+ defaultAnswers.enable_acf_pro = envAcfPro;
352
+ if (!envAcfPro) {
353
+ delete defaultAnswers.acf_op_reference;
354
+ delete defaultAnswers.acf_site_url;
355
+ }
356
+ }
357
+
358
+ // WP_KIT_PHP_VERSION: overrides php_version; only supported versions are accepted.
359
+ if (process.env.WP_KIT_PHP_VERSION) {
360
+ defaultAnswers.php_version = resolvePhpVersion(process.env.WP_KIT_PHP_VERSION);
361
+ }
362
+ assertPhpForModules(defaultAnswers.php_version, defaultAnswers.selectedContentModules);
363
+
271
364
  // WP_KIT_SSH_TRANSPORT: overrides ssh_transport (used for non-interactive E2E generation).
272
365
  if (process.env.WP_KIT_SSH_TRANSPORT) {
273
366
  defaultAnswers.ssh_transport = process.env.WP_KIT_SSH_TRANSPORT;
274
367
  }
275
368
 
369
+ defaultAnswers.enable_kivo_wp = defaultAnswers.dev_environment === "kivo-wp";
370
+
276
371
  const enabledModules = Object.keys(modulePromptDefs).filter(
277
372
  (mod) => defaultAnswers[`enable_${mod.replace(/-/g, "_")}`] === true,
278
373
  );
@@ -284,10 +379,10 @@ export async function runPrompts({ defaults = false } = {}) {
284
379
  return {
285
380
  ...defaultAnswers,
286
381
  ...derived,
287
- phpVersion: VERSION_REGISTRY.php.latest,
382
+ phpVersion: defaultAnswers.php_version,
288
383
  nodeVersion: "24",
289
384
  enabledModules,
290
- projectDomain: `${defaultAnswers.projectName}.lndo.site`,
385
+ projectDomain: localDomain(defaultAnswers.projectName, defaultAnswers.dev_environment),
291
386
  salts: Generator.generateSalts(),
292
387
  };
293
388
  }
@@ -301,6 +396,8 @@ export async function runPrompts({ defaults = false } = {}) {
301
396
  answers.enable_mu_plugin = sel.includes("mu-plugin");
302
397
  answers.enable_plugin = sel.includes("plugin");
303
398
 
399
+ answers.enable_kivo_wp = answers.dev_environment === "kivo-wp";
400
+
304
401
  const enabledModules = Object.keys(modulePromptDefs).filter(
305
402
  (mod) => answers[`enable_${mod.replace(/-/g, "_")}`] === true,
306
403
  );
@@ -312,10 +409,10 @@ export async function runPrompts({ defaults = false } = {}) {
312
409
  return {
313
410
  ...answers,
314
411
  ...derived,
315
- phpVersion: VERSION_REGISTRY.php.latest,
412
+ phpVersion: answers.php_version,
316
413
  nodeVersion: "24",
317
414
  enabledModules,
318
- projectDomain: `${answers.projectName}.lndo.site`,
415
+ projectDomain: localDomain(answers.projectName, answers.dev_environment),
319
416
  salts: Generator.generateSalts(),
320
417
  };
321
418
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Composer auth.json template for `op inject` (D-014): only 1Password secret references, never
3
+ * values. `op inject -i auth.json.tpl -o auth.json` replaces each {{ op://... }} with its value.
4
+ * @param {string} reference - op://<vault>/<item> holding the fields license-key and site-url
5
+ * @returns {string} JSON template text
6
+ */
7
+ export function renderAuthTemplate(reference) {
8
+ const base = reference.replace(/\/+$/, "");
9
+ const template = {
10
+ "http-basic": {
11
+ "connect.advancedcustomfields.com": {
12
+ username: `{{ ${base}/license-key }}`,
13
+ password: `{{ ${base}/site-url }}`,
14
+ },
15
+ },
16
+ };
17
+ return `${JSON.stringify(template, null, 2)}\n`;
18
+ }