@codigodoleo/wp-kit 5.3.0 → 6.0.1
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/README.md +83 -96
- 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/lib/utils/git.js +5 -188
- 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/Development.md.hbs +236 -0
- 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 +34 -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/.lintstagedrc.json +5 -2
- 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 +83 -0
- package/modules/kivo-wp/templates/bin/_lib.sh.hbs +137 -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 +18 -0
- package/modules/kivo-wp/templates/bin/db-import.hbs +26 -0
- package/modules/kivo-wp/templates/bin/db.hbs +6 -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 +48 -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 +8 -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 +21 -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 +8 -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 +22 -14
- package/modules/lint/templates/package.json.hbs +6 -0
- package/modules/php/index.js +18 -1
- package/modules/php/kivo-wp/php-wrapper.sh +3 -0
- package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
- package/modules/php/templates/phpstan.neon.dist.hbs +27 -0
- package/modules/sage/index.js +4 -26
- 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/skills/index.js +56 -11
- package/modules/skills/prompts.js +3 -16
- package/modules/test/index.js +13 -11
- package/modules/test/phpunit.xml +18 -0
- package/modules/test/templates/playwright.config.js.hbs +23 -0
- package/modules/test/tests/SmokeTest.php +8 -9
- 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 +8 -1
- package/templates/.lando.yml.hbs +3 -9
- package/templates/CLAUDE.md.hbs +33 -15
- package/templates/README.md.hbs +38 -12
- package/templates/composer.json.hbs +1 -1
- 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} +56 -14
- package/modules/docs/templates/docs/Desenvolvimento.md.hbs +0 -127
- 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
|
@@ -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
|
+
}
|
package/lib/utils/env-example.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
// Matches active and commented-out assignments (`KEY=v`, `export KEY=v`, `# KEY=v`).
|
|
2
|
-
const ASSIGNMENT = /^(\s*(?:#\s*)?(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*)=.*$/;
|
|
2
|
+
const ASSIGNMENT = /^(\s*(?:#\s*)?(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*))=.*$/;
|
|
3
|
+
|
|
4
|
+
// Keys whose values are never kept, whatever the caller allows (salts, keys, tokens, passwords).
|
|
5
|
+
export const SECRET_KEY_PATTERN = /(KEY|SALT|SECRET|TOKEN|PASSWORD)/;
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
|
-
* Turns dotenv content into
|
|
6
|
-
* commented-out ones, keeps its key and loses its value
|
|
7
|
-
*
|
|
8
|
+
* Turns dotenv content into an example that is safe to commit. Every assignment, including
|
|
9
|
+
* commented-out ones, keeps its key and loses its value, except active assignments for which
|
|
10
|
+
* `keepValue(key)` returns true and whose key is not secret-like (D-028: non-secret kivo-wp
|
|
11
|
+
* defaults). Other comments and blank lines are preserved as-is.
|
|
8
12
|
* @param {string} content - Rendered dotenv content
|
|
13
|
+
* @param {{ keepValue?: (key: string) => boolean }} [options]
|
|
9
14
|
* @returns {string} Content safe to commit
|
|
10
15
|
*/
|
|
11
|
-
export function toEnvExample(content) {
|
|
16
|
+
export function toEnvExample(content, { keepValue = () => false } = {}) {
|
|
12
17
|
return content
|
|
13
18
|
.split("\n")
|
|
14
|
-
.map((line) =>
|
|
19
|
+
.map((line) => {
|
|
20
|
+
const match = line.match(ASSIGNMENT);
|
|
21
|
+
if (!match) return line;
|
|
22
|
+
const [, prefix, key] = match;
|
|
23
|
+
const commented = /^\s*#/.test(line);
|
|
24
|
+
if (!commented && !SECRET_KEY_PATTERN.test(key) && keepValue(key)) return line;
|
|
25
|
+
return `${prefix}=`;
|
|
26
|
+
})
|
|
15
27
|
.join("\n");
|
|
16
28
|
}
|
package/lib/utils/git.js
CHANGED
|
@@ -1,200 +1,17 @@
|
|
|
1
|
-
import { execSync
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
|
-
|
|
7
|
-
import { log, color } from './logger.js';
|
|
8
|
-
|
|
9
|
-
const CLAUDE_PLUGIN_SUPERPOWERS_SAGE = '.claude/plugins/superpowers-sage';
|
|
10
|
-
const CLAUDE_PLUGIN_SUPERPOWERS = '.claude/plugins/superpowers';
|
|
1
|
+
import { execSync } from "child_process";
|
|
11
2
|
|
|
12
3
|
export function getGitUserDefaults() {
|
|
13
4
|
const exec = (cmd) => {
|
|
14
5
|
try {
|
|
15
6
|
return execSync(cmd).toString().trim();
|
|
16
7
|
} catch {
|
|
17
|
-
return
|
|
8
|
+
return "";
|
|
18
9
|
}
|
|
19
10
|
};
|
|
20
11
|
|
|
21
12
|
return {
|
|
22
|
-
author: exec(
|
|
23
|
-
authorEmail: exec(
|
|
24
|
-
gitRepository: exec(
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Dirs que cada destino copia do repositório superpowers-sage.
|
|
30
|
-
* A subpasta de destino dentro do projeto é TARGET_CONFIG[key].dest.
|
|
31
|
-
*/
|
|
32
|
-
const TARGET_CONFIG = {
|
|
33
|
-
claude: {
|
|
34
|
-
dest: CLAUDE_PLUGIN_SUPERPOWERS_SAGE,
|
|
35
|
-
dirs: ['.claude-plugin', 'skills', 'agents', 'hooks'],
|
|
36
|
-
label: 'Claude Code (.claude/)',
|
|
37
|
-
},
|
|
38
|
-
cursor: {
|
|
39
|
-
dest: '.cursor/plugins/local/superpowers-sage',
|
|
40
|
-
dirs: ['.cursor-plugin', 'skills', 'agents', 'hooks', 'rules'],
|
|
41
|
-
label: 'Cursor (.cursor/)',
|
|
42
|
-
},
|
|
43
|
-
ai: {
|
|
44
|
-
dest: '.ai/superpowers-sage',
|
|
45
|
-
dirs: ['skills', 'agents', 'hooks'],
|
|
46
|
-
label: 'Agnóstico (.ai/)',
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const CLAUDE_SETTINGS_BASELINE = {
|
|
51
|
-
$schema: 'https://json.schemastore.org/claude-code-settings.json',
|
|
52
|
-
permissions: {
|
|
53
|
-
deny: [
|
|
54
|
-
'Read(./.env)',
|
|
55
|
-
'Read(./.env.*)',
|
|
56
|
-
'Read(./secrets/**)',
|
|
57
|
-
'Read(./config/credentials.json)',
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
function mergeUnique(base = [], extra = []) {
|
|
63
|
-
return [...new Set([...(Array.isArray(base) ? base : []), ...extra])];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function mergeClaudeSettings(existing = {}, incoming = {}) {
|
|
67
|
-
const merged = { ...existing, ...incoming };
|
|
68
|
-
|
|
69
|
-
const existingPermissions = existing.permissions ?? {};
|
|
70
|
-
const incomingPermissions = incoming.permissions ?? {};
|
|
71
|
-
|
|
72
|
-
merged.permissions = {
|
|
73
|
-
...existingPermissions,
|
|
74
|
-
...incomingPermissions,
|
|
75
|
-
deny: mergeUnique(existingPermissions.deny, incomingPermissions.deny),
|
|
13
|
+
author: exec("git config --get user.name") || "Developer",
|
|
14
|
+
authorEmail: exec("git config --get user.email") || "developer@example.com",
|
|
15
|
+
gitRepository: exec("git config --get remote.origin.url") || "",
|
|
76
16
|
};
|
|
77
|
-
|
|
78
|
-
merged.enabledPlugins = {
|
|
79
|
-
...(existing.enabledPlugins ?? {}),
|
|
80
|
-
...(incoming.enabledPlugins ?? {}),
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
return merged;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function updateClaudeProjectSettings(targetDir, enabledPlugins = {}) {
|
|
87
|
-
const claudeDir = path.join(targetDir, '.claude');
|
|
88
|
-
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
89
|
-
|
|
90
|
-
await fs.ensureDir(claudeDir);
|
|
91
|
-
|
|
92
|
-
let existing = {};
|
|
93
|
-
if (await fs.pathExists(settingsPath)) {
|
|
94
|
-
try {
|
|
95
|
-
existing = await fs.readJson(settingsPath);
|
|
96
|
-
} catch {
|
|
97
|
-
log(
|
|
98
|
-
color.orange,
|
|
99
|
-
'[skills] .claude/settings.json invalido. Recriando com baseline seguro + plugins instalados.'
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const nextSettings = mergeClaudeSettings(existing, {
|
|
105
|
-
...CLAUDE_SETTINGS_BASELINE,
|
|
106
|
-
enabledPlugins,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
await fs.writeJson(settingsPath, nextSettings, { spaces: 2 });
|
|
110
|
-
log(
|
|
111
|
-
color.green,
|
|
112
|
-
'✅ .claude/settings.json atualizado com plugins locais e baseline de seguranca.'
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function cloneRepo(repo, tmpDir) {
|
|
117
|
-
return spawnSync('git', ['clone', '--depth=1', repo, tmpDir], {
|
|
118
|
-
stdio: 'inherit',
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Clona codigodoleo/superpowers-sage e copia o conteúdo para os destinos selecionados.
|
|
124
|
-
* Requer git instalado no host.
|
|
125
|
-
*
|
|
126
|
-
* @param {string} targetDir - Caminho absoluto do projeto gerado
|
|
127
|
-
* @param {string[]} targets - Lista de destinos: 'claude' | 'cursor' | 'ai'
|
|
128
|
-
*/
|
|
129
|
-
export async function installSuperpowersSage(targetDir, targets = ['claude']) {
|
|
130
|
-
const sageRepo = 'https://github.com/codigodoleo/superpowers-sage.git';
|
|
131
|
-
const baseRepo = 'https://github.com/obra/superpowers.git';
|
|
132
|
-
const tmpDir = path.join(os.tmpdir(), `superpowers-sage-${Date.now()}`);
|
|
133
|
-
const tmpBaseDir = path.join(os.tmpdir(), `superpowers-base-${Date.now()}`);
|
|
134
|
-
|
|
135
|
-
const validTargets = targets.filter((t) => TARGET_CONFIG[t]);
|
|
136
|
-
if (validTargets.length === 0) {
|
|
137
|
-
log(color.orange, '[skills] Nenhum destino válido informado. Pulando.');
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
log(color.blue, `🔌 Clonando superpowers-sage para: ${validTargets.join(', ')}...`);
|
|
142
|
-
|
|
143
|
-
const result = cloneRepo(sageRepo, tmpDir);
|
|
144
|
-
|
|
145
|
-
if (result.status !== 0) {
|
|
146
|
-
log(
|
|
147
|
-
color.orange,
|
|
148
|
-
'⚠️ Não foi possível clonar superpowers-sage (sem rede ou git indisponível). Pulando.'
|
|
149
|
-
);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
for (const key of validTargets) {
|
|
154
|
-
const cfg = TARGET_CONFIG[key];
|
|
155
|
-
const destBase = path.join(targetDir, cfg.dest);
|
|
156
|
-
|
|
157
|
-
await fs.ensureDir(destBase);
|
|
158
|
-
|
|
159
|
-
for (const dir of cfg.dirs) {
|
|
160
|
-
const srcDir = path.join(tmpDir, dir);
|
|
161
|
-
if (!(await fs.pathExists(srcDir))) continue;
|
|
162
|
-
|
|
163
|
-
const destDir = path.join(destBase, dir);
|
|
164
|
-
await fs.copy(srcDir, destDir, { overwrite: true });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
log(color.green, `✅ superpowers-sage instalado em ${cfg.dest}`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const claudeEnabledPlugins = {
|
|
171
|
-
'superpowers-sage@superpowers-sage-marketplace': true,
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
if (validTargets.includes('claude')) {
|
|
175
|
-
log(color.blue, '🔌 Clonando superpowers (base) para Claude Code...');
|
|
176
|
-
|
|
177
|
-
const baseResult = cloneRepo(baseRepo, tmpBaseDir);
|
|
178
|
-
if (baseResult.status !== 0) {
|
|
179
|
-
log(
|
|
180
|
-
color.orange,
|
|
181
|
-
'⚠️ Nao foi possivel clonar obra/superpowers. O plugin base nao foi instalado localmente.'
|
|
182
|
-
);
|
|
183
|
-
} else {
|
|
184
|
-
const baseDest = path.join(targetDir, CLAUDE_PLUGIN_SUPERPOWERS);
|
|
185
|
-
await fs.ensureDir(baseDest);
|
|
186
|
-
await fs.copy(tmpBaseDir, baseDest, {
|
|
187
|
-
overwrite: true,
|
|
188
|
-
filter: (src) =>
|
|
189
|
-
!src.includes(`${path.sep}.git${path.sep}`) && !src.endsWith(`${path.sep}.git`),
|
|
190
|
-
});
|
|
191
|
-
claudeEnabledPlugins['superpowers@superpowers-dev'] = true;
|
|
192
|
-
log(color.green, `✅ superpowers instalado em ${CLAUDE_PLUGIN_SUPERPOWERS}`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
await updateClaudeProjectSettings(targetDir, claudeEnabledPlugins);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
await fs.remove(tmpDir);
|
|
199
|
-
await fs.remove(tmpBaseDir);
|
|
200
17
|
}
|
|
@@ -12,7 +12,7 @@ import { log, color } from "../../lib/utils/logger.js";
|
|
|
12
12
|
*
|
|
13
13
|
* acme-theme -> ACME_THEME
|
|
14
14
|
* my-site-theme -> MY_SITE_THEME
|
|
15
|
-
* wp-
|
|
15
|
+
* wp-myproject-theme -> WP_MYPROJECT_THEME
|
|
16
16
|
*/
|
|
17
17
|
function toConstantPrefix(slug) {
|
|
18
18
|
return slug
|
package/modules/deploy/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
|
|
1
5
|
import { log, color } from "../../lib/utils/logger.js";
|
|
2
6
|
|
|
3
7
|
export async function setupModule(context, generator) {
|
|
@@ -8,6 +12,17 @@ export async function setupModule(context, generator) {
|
|
|
8
12
|
|
|
9
13
|
log(color.blue, "[deploy] Gerando pipeline de CI baseado em context.ci");
|
|
10
14
|
|
|
15
|
+
// Verificador de exposição: serve ao CI (ci.yml) e a quem faz deploy por conta própria. Confere de fora
|
|
16
|
+
// que .env, CLAUDE.md, composer.lock etc. não respondem 200; ver docs/Deploy-Pipeline.md.
|
|
17
|
+
await generator.copyFile("scripts/check-exposure.sh", "deploy", "scripts/check-exposure.sh");
|
|
18
|
+
if (context.enable_kivo_wp) {
|
|
19
|
+
// The local environment file to probe is compose.yaml instead of the Landofile.
|
|
20
|
+
const script = path.join(generator.cwd, "scripts/check-exposure.sh");
|
|
21
|
+
const text = await fs.readFile(script, "utf8");
|
|
22
|
+
await fs.outputFile(script, text.replace(" .lando.yml ", " compose.yaml "));
|
|
23
|
+
}
|
|
24
|
+
log(color.green, "[deploy] scripts/check-exposure.sh copiado.");
|
|
25
|
+
|
|
11
26
|
try {
|
|
12
27
|
await generator.generateFile("renovate.json", context, "deploy", "renovate.json");
|
|
13
28
|
log(color.green, "[deploy] renovate.json gerado (frota Hekivo).");
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Checks from the outside that no secret or development file is public.
|
|
3
|
+
# Usage: check-exposure.sh <base-url> [theme-slug]
|
|
4
|
+
# Exits 1 if a CRITICAL path answers 200 with a body; WARN paths are only listed. Each request carries a
|
|
5
|
+
# unique query: Cloudflare caches static files by URL, and a stale cached copy would hide (or invent) an
|
|
6
|
+
# exposure. Prints status and size only, never content.
|
|
7
|
+
#
|
|
8
|
+
# Where it runs matters. From an IP the WAF lets through (a "Bypass IP" rule, a CI runner on an allow list)
|
|
9
|
+
# the result is the ORIGIN's: the WAF does not act, so it is the strictest reading. To see what the PUBLIC
|
|
10
|
+
# sees, run it from an IP outside any bypass (for example from the server itself over ssh).
|
|
11
|
+
set -uo pipefail
|
|
12
|
+
|
|
13
|
+
BASE="${1:?Usage: $0 <base-url> [theme-slug]}"
|
|
14
|
+
BASE="${BASE%/}"
|
|
15
|
+
THEME="${2:-}"
|
|
16
|
+
|
|
17
|
+
CRITICAL=(
|
|
18
|
+
.env .env.local .env.production .env.staging .env.backup .env.save .env.example '.env~'
|
|
19
|
+
.git/config .git/HEAD .gitignore .htpasswd .npmrc auth.json
|
|
20
|
+
composer.json composer.lock package.json package-lock.json
|
|
21
|
+
CLAUDE.md AGENTS.md README.md DESIGN.md PRODUCT.md
|
|
22
|
+
.mcp.json .claude/settings.json .claude/settings.local.json .cursor/mcp.json .vscode/settings.json
|
|
23
|
+
.devcontainer/devcontainer.json .github/workflows/ci.yml .github/workflows/deploy.yml .lando.yml docker-compose.yml
|
|
24
|
+
wp-config.php.bak 'wp-config.php~' wp-config.old wp-config.txt
|
|
25
|
+
backup.sql dump.sql db.sql backup.zip debug.log content/debug.log error_log phpinfo.php
|
|
26
|
+
)
|
|
27
|
+
WARN=(
|
|
28
|
+
wp-cli.yml vendor/composer/installed.json wp/readme.html wp/license.txt wp/wp-config-sample.php
|
|
29
|
+
wp-json/ wp-json/wp/v2/users
|
|
30
|
+
)
|
|
31
|
+
if [ -n "$THEME" ]; then
|
|
32
|
+
CRITICAL+=("content/themes/$THEME/package.json" "content/themes/$THEME/vite.config.js" "content/themes/$THEME/.env")
|
|
33
|
+
WARN+=("content/themes/$THEME/composer.json" "content/themes/$THEME/resources/views/layouts/app.blade.php")
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
nonce="$(date +%s)$RANDOM"
|
|
37
|
+
critical=0
|
|
38
|
+
|
|
39
|
+
probe() { # path -> "status size"
|
|
40
|
+
curl -s -o /dev/null -m 20 -w '%{http_code} %{size_download}' "$BASE/$1?_x=$nonce"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for path in "${CRITICAL[@]}"; do
|
|
44
|
+
read -r status size < <(probe "$path")
|
|
45
|
+
if [ "$status" = "200" ] && [ "${size:-0}" -gt 0 ]; then
|
|
46
|
+
echo "::error title=Public file::/$path answers 200 (${size}B) on $BASE"
|
|
47
|
+
critical=$((critical + 1))
|
|
48
|
+
fi
|
|
49
|
+
done
|
|
50
|
+
|
|
51
|
+
for path in "${WARN[@]}"; do
|
|
52
|
+
read -r status size < <(probe "$path")
|
|
53
|
+
if [ "$status" = "200" ] && [ "${size:-0}" -gt 0 ]; then
|
|
54
|
+
echo "::warning title=Information disclosure::/$path answers 200 (${size}B) on $BASE"
|
|
55
|
+
fi
|
|
56
|
+
done
|
|
57
|
+
|
|
58
|
+
if [ "$critical" -gt 0 ]; then
|
|
59
|
+
echo "$critical critical path(s) public on $BASE. Block them in nginx/WAF and keep them out of the deploy." >&2
|
|
60
|
+
exit 1
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
echo "Exposure: no critical path is public on $BASE."
|
|
@@ -247,6 +247,9 @@ jobs:
|
|
|
247
247
|
with:
|
|
248
248
|
ssh-target: $\{{ env.SSH_HOST }}
|
|
249
249
|
remote-root: $\{{ env.SSH_REMOTE_PATH }}
|
|
250
|
+
# .env goes ABOVE the web root (wp-config.php reads it from there): the deploy path is the
|
|
251
|
+
# document root, and anything inside it is public unless a WAF/vhost rule happens to block it.
|
|
252
|
+
env-location: parent
|
|
250
253
|
{{#if enable_acf_pro}}
|
|
251
254
|
plugin-slug: advanced-custom-fields-pro
|
|
252
255
|
{{/if}}
|
|
@@ -260,6 +263,17 @@ jobs:
|
|
|
260
263
|
zone-id: $\{{ env.CLOUDFLARE_PURGE_ZONE_ID }}
|
|
261
264
|
api-token: $\{{ env.CLOUDFLARE_PURGE_TOKEN }}
|
|
262
265
|
|
|
266
|
+
- name: Check public exposure
|
|
267
|
+
# Fails the deploy if .env, CLAUDE.md, composer.lock... answer 200. Set the STAGING_URL variable
|
|
268
|
+
# (Settings > Environments > staging) to the site's public URL; without it the check is skipped.
|
|
269
|
+
if: vars.STAGING_URL != ''
|
|
270
|
+
uses: hekivo/gha-workflows/actions/check-exposure@v1
|
|
271
|
+
with:
|
|
272
|
+
site-url: $\{{ vars.STAGING_URL }}
|
|
273
|
+
{{#if ci.build.sage}}
|
|
274
|
+
theme-slug: {{projectName}}
|
|
275
|
+
{{/if}}
|
|
276
|
+
|
|
263
277
|
# ── Deploy Production ─────────────────────────────────────────────────────────
|
|
264
278
|
deploy-production:
|
|
265
279
|
needs: quality
|
|
@@ -362,6 +376,9 @@ jobs:
|
|
|
362
376
|
ssh-target: $\{{ env.SSH_USER }}@$\{{ env.SSH_HOST }}
|
|
363
377
|
ssh-cmd: ssh -p $\{{ env.SSH_PORT || '22' }}
|
|
364
378
|
remote-root: $\{{ env.SSH_REMOTE_PATH }}
|
|
379
|
+
# .env goes ABOVE the web root (wp-config.php reads it from there): the deploy path is the
|
|
380
|
+
# document root, and anything inside it is public unless a WAF/vhost rule happens to block it.
|
|
381
|
+
env-location: parent
|
|
365
382
|
{{#if enable_acf_pro}}
|
|
366
383
|
plugin-slug: advanced-custom-fields-pro
|
|
367
384
|
{{/if}}
|
|
@@ -374,4 +391,15 @@ jobs:
|
|
|
374
391
|
with:
|
|
375
392
|
zone-id: $\{{ env.CLOUDFLARE_PURGE_ZONE_ID }}
|
|
376
393
|
api-token: $\{{ env.CLOUDFLARE_PURGE_TOKEN }}
|
|
394
|
+
|
|
395
|
+
- name: Check public exposure
|
|
396
|
+
# Fails the deploy if .env, CLAUDE.md, composer.lock... answer 200. Set the PRODUCTION_URL variable
|
|
397
|
+
# (Settings > Environments > production) to the site's public URL; without it the check is skipped.
|
|
398
|
+
if: vars.PRODUCTION_URL != ''
|
|
399
|
+
uses: hekivo/gha-workflows/actions/check-exposure@v1
|
|
400
|
+
with:
|
|
401
|
+
site-url: $\{{ vars.PRODUCTION_URL }}
|
|
402
|
+
{{#if ci.build.sage}}
|
|
403
|
+
theme-slug: {{projectName}}
|
|
404
|
+
{{/if}}
|
|
377
405
|
{{/if}}
|