@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.
Files changed (106) hide show
  1. package/lib/commands/init.js +35 -27
  2. package/lib/config/versions.js +32 -5
  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 +106 -8
  7. package/lib/utils/auth-template.js +18 -0
  8. package/lib/utils/env-example.js +28 -0
  9. package/modules/blank-theme/index.js +1 -1
  10. package/modules/deploy/index.js +18 -0
  11. package/modules/deploy/scripts/check-exposure.sh +63 -0
  12. package/modules/deploy/templates/.github/workflows/ci.yml.hbs +37 -2
  13. package/modules/deploy/templates/renovate.json.hbs +4 -0
  14. package/modules/docs/index.js +18 -18
  15. package/modules/docs/templates/README.md.hbs +1 -1
  16. package/modules/docs/templates/docs/Arquitetura.md.hbs +2 -2
  17. package/modules/docs/templates/docs/Deploy-Pipeline.md.hbs +21 -1
  18. package/modules/docs/templates/docs/{Desenvolvimento.md.hbs → Development.md.hbs} +80 -2
  19. package/modules/docs/templates/docs/Getting-Started.md.hbs +75 -4
  20. package/modules/docs/templates/docs/Infraestrutura.md.hbs +1 -1
  21. package/modules/docs/templates/docs/Troubleshooting.md.hbs +18 -1
  22. package/modules/git/.husky/kivo-wp/commit-msg +3 -0
  23. package/modules/git/.husky/kivo-wp/pre-commit +25 -0
  24. package/modules/git/.husky/pre-commit +3 -7
  25. package/modules/git/index.js +75 -57
  26. package/modules/git/templates/.lando.yml.hbs +5 -0
  27. package/modules/git/templates/package.json.hbs +1 -1
  28. package/modules/kivo-wp/fixtures/menus.json +11 -0
  29. package/modules/kivo-wp/fixtures/options.json +10 -0
  30. package/modules/kivo-wp/fixtures/posts.json +58 -0
  31. package/modules/kivo-wp/fixtures/seed.php +152 -0
  32. package/modules/kivo-wp/fixtures/terms.json +6 -0
  33. package/modules/kivo-wp/fixtures/users.json +26 -0
  34. package/modules/kivo-wp/index.js +193 -0
  35. package/modules/kivo-wp/prompts.js +1 -0
  36. package/modules/kivo-wp/templates/.devcontainer/devcontainer.json.hbs +40 -0
  37. package/modules/kivo-wp/templates/.dockerignore.hbs +15 -0
  38. package/modules/kivo-wp/templates/Dockerfile.hbs +81 -0
  39. package/modules/kivo-wp/templates/bin/_lib.sh.hbs +116 -0
  40. package/modules/kivo-wp/templates/bin/build.hbs +13 -0
  41. package/modules/kivo-wp/templates/bin/composer.hbs +6 -0
  42. package/modules/kivo-wp/templates/bin/db-export.hbs +8 -0
  43. package/modules/kivo-wp/templates/bin/db-import.hbs +20 -0
  44. package/modules/kivo-wp/templates/bin/db.hbs +9 -0
  45. package/modules/kivo-wp/templates/bin/dev.hbs +7 -0
  46. package/modules/kivo-wp/templates/bin/down.hbs +34 -0
  47. package/modules/kivo-wp/templates/bin/e2e.hbs +20 -0
  48. package/modules/kivo-wp/templates/bin/flush.hbs +11 -0
  49. package/modules/kivo-wp/templates/bin/info.hbs +15 -0
  50. package/modules/kivo-wp/templates/bin/logs.hbs +6 -0
  51. package/modules/kivo-wp/templates/bin/mago.hbs +6 -0
  52. package/modules/kivo-wp/templates/bin/node.hbs +6 -0
  53. package/modules/kivo-wp/templates/bin/npm.hbs +6 -0
  54. package/modules/kivo-wp/templates/bin/php.hbs +6 -0
  55. package/modules/kivo-wp/templates/bin/reset-deps.hbs +11 -0
  56. package/modules/kivo-wp/templates/bin/seed.hbs +19 -0
  57. package/modules/kivo-wp/templates/bin/setup.hbs +283 -0
  58. package/modules/kivo-wp/templates/bin/shell.hbs +14 -0
  59. package/modules/kivo-wp/templates/bin/stan.hbs +6 -0
  60. package/modules/kivo-wp/templates/bin/test.hbs +6 -0
  61. package/modules/kivo-wp/templates/bin/trust-cert.hbs +21 -0
  62. package/modules/kivo-wp/templates/bin/up.hbs +6 -0
  63. package/modules/kivo-wp/templates/bin/wp.hbs +6 -0
  64. package/modules/kivo-wp/templates/bin/xdebug.hbs +22 -0
  65. package/modules/kivo-wp/templates/compose.yaml.hbs +117 -0
  66. package/modules/kivo-wp/templates/content/mu-plugins/kivo-wp-local-mail.php.hbs +29 -0
  67. package/modules/kivo-wp/templates/docs/cloud-sessions.md.hbs +34 -0
  68. package/modules/kivo-wp/templates/server/caddy/Caddyfile.hbs +44 -0
  69. package/modules/kivo-wp/templates/server/nginx/deny.conf.hbs +26 -0
  70. package/modules/lint/.prettierignore +3 -4
  71. package/modules/lint/index.js +14 -10
  72. package/modules/lint/templates/package.json.hbs +6 -0
  73. package/modules/php/index.js +13 -1
  74. package/modules/php/kivo-wp/php-wrapper.sh +3 -0
  75. package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
  76. package/modules/sage/index.js +7 -24
  77. package/modules/sage/templates/bin/theme-lint.hbs +6 -0
  78. package/modules/sage/templates/server/cmd/setup-sage-node.sh.hbs +3 -1
  79. package/modules/sage/templates/server/cmd/setup-sage-php.sh.hbs +3 -1
  80. package/modules/sage/templates/theme/vite.config.js.hbs +25 -4
  81. package/modules/sage/templates/workspace.json.hbs +0 -57
  82. package/modules/test/index.js +12 -11
  83. package/modules/test/templates/playwright.config.js.hbs +12 -0
  84. package/modules/test/tests/e2e/smoke.spec.js +28 -0
  85. package/package.json +3 -2
  86. package/templates/.env.hbs +16 -5
  87. package/templates/.gitignore.hbs +12 -1
  88. package/templates/.lando.yml.hbs +5 -11
  89. package/templates/CLAUDE.md.hbs +19 -2
  90. package/templates/package.json.hbs +8 -1
  91. package/templates/server/cmd/install-wp.sh.hbs +1 -1
  92. package/templates/server/cmd/setup-node.sh.hbs +3 -1
  93. package/templates/server/cmd/setup-php.sh.hbs +63 -9
  94. package/templates/workspace.json.hbs +0 -56
  95. package/{wp-config.php → templates/wp-config.php.hbs} +41 -5
  96. package/modules/lint/templates/.lando.yml.hbs +0 -5
  97. package/modules/sage/templates/.devcontainer/devcontainer.json.hbs +0 -7
  98. package/modules/sage/templates/.devcontainer/docker-compose.override.yml.hbs +0 -4
  99. package/modules/sage/templates/.devcontainer/post-create.sh.hbs +0 -11
  100. package/templates/.devcontainer/Dockerfile.hbs +0 -24
  101. package/templates/.devcontainer/config/nginx.conf +0 -23
  102. package/templates/.devcontainer/config/nginx.conf.hbs +0 -23
  103. package/templates/.devcontainer/devcontainer.json.hbs +0 -29
  104. package/templates/.devcontainer/docker-compose.yml.hbs +0 -76
  105. package/templates/.devcontainer/setup.sh.hbs +0 -17
  106. package/templates/auth.json.hbs +0 -8
@@ -4,10 +4,12 @@ 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
- import { inferCiCapabilities } from "../core/infer-ci-capabilities.js";
11
+ import { toEnvExample } from "../utils/env-example.js";
12
+ import { inferCiCapabilities, resolveContentDir } from "../core/infer-ci-capabilities.js";
11
13
  import { validateVersionCompatibility } from "../config/versions.js";
12
14
 
13
15
  const __filename = fileURLToPath(import.meta.url);
@@ -30,12 +32,10 @@ export const initCommand = new Command("init")
30
32
 
31
33
  // 🔧 Ajustes automáticos para Sage 11
32
34
  if (context.useSage && context.sageVersion === "11") {
33
- context.phpVersion = "8.4";
34
35
  context.nodeVersion = "24";
35
36
  context.wpCoreVersion = "7.0";
36
37
 
37
38
  log(color.orange, "🔧 Sage 11 selected — automatically adjusting versions:");
38
- log(color.orange, " → PHP: 8.4");
39
39
  log(color.orange, " → Node: 24");
40
40
  log(color.orange, " → WP Core: 7.0");
41
41
  }
@@ -56,6 +56,8 @@ export const initCommand = new Command("init")
56
56
  }
57
57
 
58
58
  context.cwd = target;
59
+ context.contentDir = resolveContentDir(target);
60
+ context.enabledModules = enabledModules;
59
61
 
60
62
  // 🧠 Inferência de capacidades de CI
61
63
  context.ci = inferCiCapabilities(context);
@@ -79,24 +81,27 @@ export const initCommand = new Command("init")
79
81
  await generator.generateFile(".gitignore", context);
80
82
  await generator.generateFile("README.md", context);
81
83
  await generator.generateFile(".env", context);
82
- if (context.enable_acf_pro && context.acf_license_key) {
83
- await generator.generateFile("auth.json", context);
84
- } else if (context.enable_acf_pro) {
85
- log(
86
- color.orange,
87
- "⚠️ auth.json not generated: add your ACF license key to auth.json manually.",
84
+ // Keys-only companion that is safe to commit; the real file stays ignored.
85
+ const envFile = ".env";
86
+ const envContent = await fs.readFile(path.join(target, envFile), "utf8");
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),
88
99
  );
89
- log(color.orange, " See: https://www.advancedcustomfields.com/my-account/");
90
100
  }
91
101
  await generator.generateFile(".editorconfig", context);
92
102
  await generator.generateFile("server/cmd/install-wp.sh", context);
93
103
  await generator.generateFile("server/cmd/setup-php.sh", context);
94
104
  await generator.generateFile("server/cmd/setup-node.sh", context);
95
- await generator.generateFile(".devcontainer/devcontainer.json", context);
96
- await generator.generateFile(".devcontainer/docker-compose.yml", context);
97
- await generator.generateFile(".devcontainer/Dockerfile", context);
98
- await generator.generateFile(".devcontainer/setup.sh", context);
99
- await generator.generateFile(".devcontainer/config/nginx.conf", context);
100
105
 
101
106
  await generator.copyFile(".cspell.json");
102
107
 
@@ -112,14 +117,13 @@ export const initCommand = new Command("init")
112
117
  await fs.chmod(path.join(target, "server/cmd/install-wp.sh"), 0o755);
113
118
  await fs.chmod(path.join(target, "server/cmd/setup-php.sh"), 0o755);
114
119
  await fs.chmod(path.join(target, "server/cmd/setup-node.sh"), 0o755);
115
- await fs.chmod(path.join(target, ".devcontainer/setup.sh"), 0o755);
116
120
 
117
121
  await generator.generateFile("server/www/vhosts.conf", context);
118
122
  if (context.useRocket) {
119
123
  await generator.copyFile("server/www/rocket.conf");
120
124
  }
121
125
 
122
- await generator.copyFile("wp-config.php");
126
+ await generator.generateFile("wp-config.php", context);
123
127
  await generator.copyFile("index.php");
124
128
  await generator.generateFile("wp-cli.yml", context);
125
129
 
@@ -141,12 +145,15 @@ export const initCommand = new Command("init")
141
145
  mergeStrategy: "concat",
142
146
  });
143
147
 
144
- await generator.generateModularFile({
145
- baseTemplate: ".lando.yml",
146
- modules: enabledModules,
147
- context,
148
- mergeStrategy: "concat",
149
- });
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
+ }
150
157
 
151
158
  await generator.generateModularFile({
152
159
  baseTemplate: "workspace.json",
@@ -168,12 +175,13 @@ export const initCommand = new Command("init")
168
175
  }
169
176
  }
170
177
 
178
+ // CLAUDE.md must exist before the post-setup hooks run, so the initial
179
+ // commit made by the git module includes it.
180
+ await generator.generateFile("CLAUDE.md", context);
181
+
171
182
  // Executa hooks após todo o setup dos módulos
172
183
  log(color.blue, "🔗 Executing post-setup hooks...");
173
184
  generator.hooks.doAction("after_setup_complete", context, generator);
174
185
 
175
- // Gera CLAUDE.md com overview do projeto e referência ao AI Co-Pilot
176
- await generator.generateFile("CLAUDE.md", context);
177
-
178
186
  log(color.green, "✅ Project initialized with templates.");
179
187
  });
@@ -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",
@@ -53,10 +54,11 @@ export const VERSION_REGISTRY = {
53
54
  * Only actively supported versions per php.net
54
55
  */
55
56
  php: {
56
- latest: "8.4",
57
- supported: ["8.4", "8.3", "8.2"],
58
- eol: ["8.0", "7.4", "7.3", "7.2"], // Deprecated - do not use
59
- description: "Supported PHP versions. PHP 7.4+ reached EOL on 2022-11-28",
57
+ latest: "8.5",
58
+ supported: ["8.5", "8.4", "8.3"],
59
+ eol: ["8.2", "8.1", "8.0", "7.4", "7.3", "7.2"], // Deprecated - do not use
60
+ description:
61
+ "Supported PHP versions (active support per php.net). 8.2 left active support on 2024-12-31.",
60
62
  // PHP version dates: https://www.php.net/supported-versions.php
61
63
  eolDates: {
62
64
  8.1: "2025-11-25",
@@ -82,8 +84,33 @@ export const VERSION_REGISTRY = {
82
84
  18: { start: "2022-10-25", end: "2025-04-30" },
83
85
  },
84
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
+ },
85
107
  };
86
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
+
87
114
  /**
88
115
  * Helper functions for version management
89
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)) {