@codigodoleo/wp-kit 5.2.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/init.js +35 -27
- package/lib/config/versions.js +32 -5
- package/lib/core/cloud-allowlist.js +38 -0
- package/lib/core/generator.js +56 -50
- package/lib/core/infer-ci-capabilities.js +17 -5
- package/lib/prompts/index.js +106 -8
- package/lib/utils/auth-template.js +18 -0
- package/lib/utils/env-example.js +28 -0
- package/modules/blank-theme/index.js +1 -1
- package/modules/deploy/index.js +18 -0
- package/modules/deploy/scripts/check-exposure.sh +63 -0
- package/modules/deploy/templates/.github/workflows/ci.yml.hbs +37 -2
- package/modules/deploy/templates/renovate.json.hbs +4 -0
- package/modules/docs/index.js +18 -18
- package/modules/docs/templates/README.md.hbs +1 -1
- package/modules/docs/templates/docs/Arquitetura.md.hbs +2 -2
- package/modules/docs/templates/docs/Deploy-Pipeline.md.hbs +21 -1
- package/modules/docs/templates/docs/{Desenvolvimento.md.hbs → Development.md.hbs} +80 -2
- package/modules/docs/templates/docs/Getting-Started.md.hbs +75 -4
- package/modules/docs/templates/docs/Infraestrutura.md.hbs +1 -1
- package/modules/docs/templates/docs/Troubleshooting.md.hbs +18 -1
- package/modules/git/.husky/kivo-wp/commit-msg +3 -0
- package/modules/git/.husky/kivo-wp/pre-commit +25 -0
- package/modules/git/.husky/pre-commit +3 -7
- package/modules/git/index.js +75 -57
- package/modules/git/templates/.lando.yml.hbs +5 -0
- package/modules/git/templates/package.json.hbs +1 -1
- package/modules/kivo-wp/fixtures/menus.json +11 -0
- package/modules/kivo-wp/fixtures/options.json +10 -0
- package/modules/kivo-wp/fixtures/posts.json +58 -0
- package/modules/kivo-wp/fixtures/seed.php +152 -0
- package/modules/kivo-wp/fixtures/terms.json +6 -0
- package/modules/kivo-wp/fixtures/users.json +26 -0
- package/modules/kivo-wp/index.js +193 -0
- package/modules/kivo-wp/prompts.js +1 -0
- package/modules/kivo-wp/templates/.devcontainer/devcontainer.json.hbs +40 -0
- package/modules/kivo-wp/templates/.dockerignore.hbs +15 -0
- package/modules/kivo-wp/templates/Dockerfile.hbs +81 -0
- package/modules/kivo-wp/templates/bin/_lib.sh.hbs +116 -0
- package/modules/kivo-wp/templates/bin/build.hbs +13 -0
- package/modules/kivo-wp/templates/bin/composer.hbs +6 -0
- package/modules/kivo-wp/templates/bin/db-export.hbs +8 -0
- package/modules/kivo-wp/templates/bin/db-import.hbs +20 -0
- package/modules/kivo-wp/templates/bin/db.hbs +9 -0
- package/modules/kivo-wp/templates/bin/dev.hbs +7 -0
- package/modules/kivo-wp/templates/bin/down.hbs +34 -0
- package/modules/kivo-wp/templates/bin/e2e.hbs +20 -0
- package/modules/kivo-wp/templates/bin/flush.hbs +11 -0
- package/modules/kivo-wp/templates/bin/info.hbs +15 -0
- package/modules/kivo-wp/templates/bin/logs.hbs +6 -0
- package/modules/kivo-wp/templates/bin/mago.hbs +6 -0
- package/modules/kivo-wp/templates/bin/node.hbs +6 -0
- package/modules/kivo-wp/templates/bin/npm.hbs +6 -0
- package/modules/kivo-wp/templates/bin/php.hbs +6 -0
- package/modules/kivo-wp/templates/bin/reset-deps.hbs +11 -0
- package/modules/kivo-wp/templates/bin/seed.hbs +19 -0
- package/modules/kivo-wp/templates/bin/setup.hbs +283 -0
- package/modules/kivo-wp/templates/bin/shell.hbs +14 -0
- package/modules/kivo-wp/templates/bin/stan.hbs +6 -0
- package/modules/kivo-wp/templates/bin/test.hbs +6 -0
- package/modules/kivo-wp/templates/bin/trust-cert.hbs +21 -0
- package/modules/kivo-wp/templates/bin/up.hbs +6 -0
- package/modules/kivo-wp/templates/bin/wp.hbs +6 -0
- package/modules/kivo-wp/templates/bin/xdebug.hbs +22 -0
- package/modules/kivo-wp/templates/compose.yaml.hbs +117 -0
- package/modules/kivo-wp/templates/content/mu-plugins/kivo-wp-local-mail.php.hbs +29 -0
- package/modules/kivo-wp/templates/docs/cloud-sessions.md.hbs +34 -0
- package/modules/kivo-wp/templates/server/caddy/Caddyfile.hbs +44 -0
- package/modules/kivo-wp/templates/server/nginx/deny.conf.hbs +26 -0
- package/modules/lint/.prettierignore +3 -4
- package/modules/lint/index.js +14 -10
- package/modules/lint/templates/package.json.hbs +6 -0
- package/modules/php/index.js +13 -1
- package/modules/php/kivo-wp/php-wrapper.sh +3 -0
- package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
- package/modules/sage/index.js +7 -24
- package/modules/sage/templates/bin/theme-lint.hbs +6 -0
- package/modules/sage/templates/server/cmd/setup-sage-node.sh.hbs +3 -1
- package/modules/sage/templates/server/cmd/setup-sage-php.sh.hbs +3 -1
- package/modules/sage/templates/theme/vite.config.js.hbs +25 -4
- package/modules/sage/templates/workspace.json.hbs +0 -57
- package/modules/test/index.js +12 -11
- package/modules/test/templates/playwright.config.js.hbs +12 -0
- package/modules/test/tests/e2e/smoke.spec.js +28 -0
- package/package.json +3 -2
- package/templates/.env.hbs +16 -5
- package/templates/.gitignore.hbs +12 -1
- package/templates/.lando.yml.hbs +5 -11
- package/templates/CLAUDE.md.hbs +19 -2
- package/templates/package.json.hbs +8 -1
- package/templates/server/cmd/install-wp.sh.hbs +1 -1
- package/templates/server/cmd/setup-node.sh.hbs +3 -1
- package/templates/server/cmd/setup-php.sh.hbs +63 -9
- package/templates/workspace.json.hbs +0 -56
- package/{wp-config.php → templates/wp-config.php.hbs} +41 -5
- package/modules/lint/templates/.lando.yml.hbs +0 -5
- package/modules/sage/templates/.devcontainer/devcontainer.json.hbs +0 -7
- package/modules/sage/templates/.devcontainer/docker-compose.override.yml.hbs +0 -4
- package/modules/sage/templates/.devcontainer/post-create.sh.hbs +0 -11
- package/templates/.devcontainer/Dockerfile.hbs +0 -24
- package/templates/.devcontainer/config/nginx.conf +0 -23
- package/templates/.devcontainer/config/nginx.conf.hbs +0 -23
- package/templates/.devcontainer/devcontainer.json.hbs +0 -29
- package/templates/.devcontainer/docker-compose.yml.hbs +0 -76
- package/templates/.devcontainer/setup.sh.hbs +0 -17
- package/templates/auth.json.hbs +0 -8
package/lib/commands/init.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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.
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
});
|
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",
|
|
@@ -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.
|
|
57
|
-
supported: ["8.
|
|
58
|
-
eol: ["8.0", "7.4", "7.3", "7.2"], // Deprecated - do not use
|
|
59
|
-
description:
|
|
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
|
+
}
|
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)) {
|