@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.
- package/lib/commands/init.js +28 -26
- package/lib/config/versions.js +27 -1
- package/lib/core/cloud-allowlist.js +38 -0
- package/lib/core/generator.js +56 -50
- package/lib/core/infer-ci-capabilities.js +17 -5
- package/lib/prompts/index.js +105 -8
- package/lib/utils/auth-template.js +18 -0
- package/lib/utils/env-example.js +18 -6
- package/modules/blank-theme/index.js +1 -1
- package/modules/deploy/index.js +15 -0
- package/modules/deploy/scripts/check-exposure.sh +63 -0
- package/modules/deploy/templates/.github/workflows/ci.yml.hbs +28 -0
- package/modules/docs/index.js +18 -18
- package/modules/docs/templates/README.md.hbs +1 -1
- package/modules/docs/templates/docs/Arquitetura.md.hbs +2 -2
- package/modules/docs/templates/docs/Deploy-Pipeline.md.hbs +21 -1
- package/modules/docs/templates/docs/{Desenvolvimento.md.hbs → Development.md.hbs} +80 -2
- package/modules/docs/templates/docs/Getting-Started.md.hbs +75 -4
- package/modules/docs/templates/docs/Infraestrutura.md.hbs +1 -1
- package/modules/docs/templates/docs/Troubleshooting.md.hbs +18 -1
- package/modules/git/.husky/kivo-wp/commit-msg +3 -0
- package/modules/git/.husky/kivo-wp/pre-commit +25 -0
- package/modules/git/.husky/pre-commit +3 -7
- package/modules/git/index.js +19 -2
- package/modules/git/templates/.lando.yml.hbs +5 -0
- package/modules/git/templates/package.json.hbs +1 -1
- package/modules/kivo-wp/fixtures/menus.json +11 -0
- package/modules/kivo-wp/fixtures/options.json +10 -0
- package/modules/kivo-wp/fixtures/posts.json +58 -0
- package/modules/kivo-wp/fixtures/seed.php +152 -0
- package/modules/kivo-wp/fixtures/terms.json +6 -0
- package/modules/kivo-wp/fixtures/users.json +26 -0
- package/modules/kivo-wp/index.js +193 -0
- package/modules/kivo-wp/prompts.js +1 -0
- package/modules/kivo-wp/templates/.devcontainer/devcontainer.json.hbs +40 -0
- package/modules/kivo-wp/templates/.dockerignore.hbs +15 -0
- package/modules/kivo-wp/templates/Dockerfile.hbs +81 -0
- package/modules/kivo-wp/templates/bin/_lib.sh.hbs +116 -0
- package/modules/kivo-wp/templates/bin/build.hbs +13 -0
- package/modules/kivo-wp/templates/bin/composer.hbs +6 -0
- package/modules/kivo-wp/templates/bin/db-export.hbs +8 -0
- package/modules/kivo-wp/templates/bin/db-import.hbs +20 -0
- package/modules/kivo-wp/templates/bin/db.hbs +9 -0
- package/modules/kivo-wp/templates/bin/dev.hbs +7 -0
- package/modules/kivo-wp/templates/bin/down.hbs +34 -0
- package/modules/kivo-wp/templates/bin/e2e.hbs +20 -0
- package/modules/kivo-wp/templates/bin/flush.hbs +11 -0
- package/modules/kivo-wp/templates/bin/info.hbs +15 -0
- package/modules/kivo-wp/templates/bin/logs.hbs +6 -0
- package/modules/kivo-wp/templates/bin/mago.hbs +6 -0
- package/modules/kivo-wp/templates/bin/node.hbs +6 -0
- package/modules/kivo-wp/templates/bin/npm.hbs +6 -0
- package/modules/kivo-wp/templates/bin/php.hbs +6 -0
- package/modules/kivo-wp/templates/bin/reset-deps.hbs +11 -0
- package/modules/kivo-wp/templates/bin/seed.hbs +19 -0
- package/modules/kivo-wp/templates/bin/setup.hbs +283 -0
- package/modules/kivo-wp/templates/bin/shell.hbs +14 -0
- package/modules/kivo-wp/templates/bin/stan.hbs +6 -0
- package/modules/kivo-wp/templates/bin/test.hbs +6 -0
- package/modules/kivo-wp/templates/bin/trust-cert.hbs +21 -0
- package/modules/kivo-wp/templates/bin/up.hbs +6 -0
- package/modules/kivo-wp/templates/bin/wp.hbs +6 -0
- package/modules/kivo-wp/templates/bin/xdebug.hbs +22 -0
- package/modules/kivo-wp/templates/compose.yaml.hbs +117 -0
- package/modules/kivo-wp/templates/content/mu-plugins/kivo-wp-local-mail.php.hbs +29 -0
- package/modules/kivo-wp/templates/docs/cloud-sessions.md.hbs +34 -0
- package/modules/kivo-wp/templates/server/caddy/Caddyfile.hbs +44 -0
- package/modules/kivo-wp/templates/server/nginx/deny.conf.hbs +26 -0
- package/modules/lint/index.js +14 -10
- package/modules/lint/templates/package.json.hbs +6 -0
- package/modules/php/index.js +13 -1
- package/modules/php/kivo-wp/php-wrapper.sh +3 -0
- package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
- package/modules/sage/index.js +1 -25
- package/modules/sage/templates/bin/theme-lint.hbs +6 -0
- package/modules/sage/templates/server/cmd/setup-sage-node.sh.hbs +3 -1
- package/modules/sage/templates/server/cmd/setup-sage-php.sh.hbs +3 -1
- package/modules/sage/templates/theme/vite.config.js.hbs +20 -2
- package/modules/sage/templates/workspace.json.hbs +0 -57
- package/modules/test/index.js +12 -11
- package/modules/test/templates/playwright.config.js.hbs +12 -0
- package/modules/test/tests/e2e/smoke.spec.js +28 -0
- package/package.json +3 -2
- package/templates/.env.hbs +16 -5
- package/templates/.gitignore.hbs +7 -1
- package/templates/.lando.yml.hbs +3 -9
- package/templates/CLAUDE.md.hbs +19 -2
- package/templates/package.json.hbs +8 -1
- package/templates/server/cmd/install-wp.sh.hbs +1 -1
- package/templates/server/cmd/setup-node.sh.hbs +3 -1
- package/templates/server/cmd/setup-php.sh.hbs +63 -9
- package/templates/workspace.json.hbs +0 -56
- package/{wp-config.php → templates/wp-config.php.hbs} +41 -5
- package/modules/lint/templates/.lando.yml.hbs +0 -5
- package/modules/sage/templates/.devcontainer/devcontainer.json.hbs +0 -7
- package/modules/sage/templates/.devcontainer/docker-compose.override.yml.hbs +0 -4
- package/modules/sage/templates/.devcontainer/post-create.sh.hbs +0 -11
- package/templates/.devcontainer/Dockerfile.hbs +0 -24
- package/templates/.devcontainer/config/nginx.conf +0 -23
- package/templates/.devcontainer/config/nginx.conf.hbs +0 -23
- package/templates/.devcontainer/devcontainer.json.hbs +0 -29
- package/templates/.devcontainer/docker-compose.yml.hbs +0 -76
- package/templates/.devcontainer/setup.sh.hbs +0 -17
- package/templates/auth.json.hbs +0 -8
package/lib/commands/init.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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.
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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",
|
package/lib/config/versions.js
CHANGED
|
@@ -30,7 +30,8 @@ export const VERSION_REGISTRY = {
|
|
|
30
30
|
sage: {
|
|
31
31
|
11: {
|
|
32
32
|
tag: "v11.0.1",
|
|
33
|
-
|
|
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
|
+
}
|
package/lib/core/generator.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// lib/core/generator.js
|
|
2
|
-
import path from
|
|
3
|
-
import crypto from
|
|
2
|
+
import path from "path";
|
|
3
|
+
import crypto from "crypto";
|
|
4
4
|
|
|
5
|
-
import fs from
|
|
6
|
-
import handlebars from
|
|
7
|
-
import mergeWith from
|
|
8
|
-
import yaml from
|
|
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
|
|
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
|
|
18
|
+
} from "../utils/paths.js";
|
|
19
19
|
|
|
20
|
-
import { HookManager } from
|
|
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 =
|
|
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,
|
|
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 +
|
|
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,
|
|
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
|
-
|
|
140
|
+
baseModule = null,
|
|
141
|
+
header = "",
|
|
142
|
+
outputFile = "",
|
|
139
143
|
modules = [],
|
|
140
144
|
context = {},
|
|
141
|
-
format =
|
|
142
|
-
mergeStrategy =
|
|
145
|
+
format = "yaml",
|
|
146
|
+
mergeStrategy = "replace",
|
|
143
147
|
debug = false,
|
|
144
148
|
}) {
|
|
145
|
-
const baseTemplatePath =
|
|
146
|
-
|
|
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 ===
|
|
158
|
+
format === "json" ? JSON.parse(compiledBase(context)) : yaml.load(compiledBase(context));
|
|
153
159
|
} catch (err) {
|
|
154
160
|
if (debug) {
|
|
155
|
-
log(color.red,
|
|
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 ===
|
|
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) +
|
|
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,
|
|
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 ===
|
|
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 ===
|
|
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 =
|
|
210
|
+
format = "json",
|
|
205
211
|
moduleName = null,
|
|
206
|
-
mergeStrategy =
|
|
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,
|
|
224
|
+
const existingRaw = await fs.readFile(existingPath, "utf8");
|
|
219
225
|
let existingParsed;
|
|
220
226
|
try {
|
|
221
|
-
existingParsed = format ===
|
|
227
|
+
existingParsed = format === "json" ? JSON.parse(existingRaw) : yaml.load(existingRaw);
|
|
222
228
|
} catch (err) {
|
|
223
229
|
if (debug) {
|
|
224
|
-
log(color.red,
|
|
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,
|
|
232
|
-
const templatePath = path.resolve(moduleBase, moduleTemplatePath +
|
|
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,
|
|
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 ===
|
|
245
|
+
format === "json" ? JSON.parse(compiledMod(context)) : yaml.load(compiledMod(context));
|
|
240
246
|
} catch (err) {
|
|
241
247
|
if (debug) {
|
|
242
|
-
log(color.red,
|
|
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 ===
|
|
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 ===
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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(
|
|
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,
|
|
17
|
-
|
|
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)) {
|
package/lib/prompts/index.js
CHANGED
|
@@ -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
|
-
|
|
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: "
|
|
265
|
+
name: "acf_op_reference",
|
|
194
266
|
message:
|
|
195
|
-
"
|
|
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:
|
|
382
|
+
phpVersion: defaultAnswers.php_version,
|
|
288
383
|
nodeVersion: "24",
|
|
289
384
|
enabledModules,
|
|
290
|
-
projectDomain:
|
|
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:
|
|
412
|
+
phpVersion: answers.php_version,
|
|
316
413
|
nodeVersion: "24",
|
|
317
414
|
enabledModules,
|
|
318
|
-
projectDomain:
|
|
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
|
+
}
|