@codigodoleo/wp-kit 5.2.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/lib/commands/init.js +35 -27
  2. package/lib/config/versions.js +32 -5
  3. package/lib/core/cloud-allowlist.js +38 -0
  4. package/lib/core/generator.js +56 -50
  5. package/lib/core/infer-ci-capabilities.js +17 -5
  6. package/lib/prompts/index.js +106 -8
  7. package/lib/utils/auth-template.js +18 -0
  8. package/lib/utils/env-example.js +28 -0
  9. package/modules/blank-theme/index.js +1 -1
  10. package/modules/deploy/index.js +18 -0
  11. package/modules/deploy/scripts/check-exposure.sh +63 -0
  12. package/modules/deploy/templates/.github/workflows/ci.yml.hbs +37 -2
  13. package/modules/deploy/templates/renovate.json.hbs +4 -0
  14. package/modules/docs/index.js +18 -18
  15. package/modules/docs/templates/README.md.hbs +1 -1
  16. package/modules/docs/templates/docs/Arquitetura.md.hbs +2 -2
  17. package/modules/docs/templates/docs/Deploy-Pipeline.md.hbs +21 -1
  18. package/modules/docs/templates/docs/{Desenvolvimento.md.hbs → Development.md.hbs} +80 -2
  19. package/modules/docs/templates/docs/Getting-Started.md.hbs +75 -4
  20. package/modules/docs/templates/docs/Infraestrutura.md.hbs +1 -1
  21. package/modules/docs/templates/docs/Troubleshooting.md.hbs +18 -1
  22. package/modules/git/.husky/kivo-wp/commit-msg +3 -0
  23. package/modules/git/.husky/kivo-wp/pre-commit +25 -0
  24. package/modules/git/.husky/pre-commit +3 -7
  25. package/modules/git/index.js +75 -57
  26. package/modules/git/templates/.lando.yml.hbs +5 -0
  27. package/modules/git/templates/package.json.hbs +1 -1
  28. package/modules/kivo-wp/fixtures/menus.json +11 -0
  29. package/modules/kivo-wp/fixtures/options.json +10 -0
  30. package/modules/kivo-wp/fixtures/posts.json +58 -0
  31. package/modules/kivo-wp/fixtures/seed.php +152 -0
  32. package/modules/kivo-wp/fixtures/terms.json +6 -0
  33. package/modules/kivo-wp/fixtures/users.json +26 -0
  34. package/modules/kivo-wp/index.js +193 -0
  35. package/modules/kivo-wp/prompts.js +1 -0
  36. package/modules/kivo-wp/templates/.devcontainer/devcontainer.json.hbs +40 -0
  37. package/modules/kivo-wp/templates/.dockerignore.hbs +15 -0
  38. package/modules/kivo-wp/templates/Dockerfile.hbs +81 -0
  39. package/modules/kivo-wp/templates/bin/_lib.sh.hbs +116 -0
  40. package/modules/kivo-wp/templates/bin/build.hbs +13 -0
  41. package/modules/kivo-wp/templates/bin/composer.hbs +6 -0
  42. package/modules/kivo-wp/templates/bin/db-export.hbs +8 -0
  43. package/modules/kivo-wp/templates/bin/db-import.hbs +20 -0
  44. package/modules/kivo-wp/templates/bin/db.hbs +9 -0
  45. package/modules/kivo-wp/templates/bin/dev.hbs +7 -0
  46. package/modules/kivo-wp/templates/bin/down.hbs +34 -0
  47. package/modules/kivo-wp/templates/bin/e2e.hbs +20 -0
  48. package/modules/kivo-wp/templates/bin/flush.hbs +11 -0
  49. package/modules/kivo-wp/templates/bin/info.hbs +15 -0
  50. package/modules/kivo-wp/templates/bin/logs.hbs +6 -0
  51. package/modules/kivo-wp/templates/bin/mago.hbs +6 -0
  52. package/modules/kivo-wp/templates/bin/node.hbs +6 -0
  53. package/modules/kivo-wp/templates/bin/npm.hbs +6 -0
  54. package/modules/kivo-wp/templates/bin/php.hbs +6 -0
  55. package/modules/kivo-wp/templates/bin/reset-deps.hbs +11 -0
  56. package/modules/kivo-wp/templates/bin/seed.hbs +19 -0
  57. package/modules/kivo-wp/templates/bin/setup.hbs +283 -0
  58. package/modules/kivo-wp/templates/bin/shell.hbs +14 -0
  59. package/modules/kivo-wp/templates/bin/stan.hbs +6 -0
  60. package/modules/kivo-wp/templates/bin/test.hbs +6 -0
  61. package/modules/kivo-wp/templates/bin/trust-cert.hbs +21 -0
  62. package/modules/kivo-wp/templates/bin/up.hbs +6 -0
  63. package/modules/kivo-wp/templates/bin/wp.hbs +6 -0
  64. package/modules/kivo-wp/templates/bin/xdebug.hbs +22 -0
  65. package/modules/kivo-wp/templates/compose.yaml.hbs +117 -0
  66. package/modules/kivo-wp/templates/content/mu-plugins/kivo-wp-local-mail.php.hbs +29 -0
  67. package/modules/kivo-wp/templates/docs/cloud-sessions.md.hbs +34 -0
  68. package/modules/kivo-wp/templates/server/caddy/Caddyfile.hbs +44 -0
  69. package/modules/kivo-wp/templates/server/nginx/deny.conf.hbs +26 -0
  70. package/modules/lint/.prettierignore +3 -4
  71. package/modules/lint/index.js +14 -10
  72. package/modules/lint/templates/package.json.hbs +6 -0
  73. package/modules/php/index.js +13 -1
  74. package/modules/php/kivo-wp/php-wrapper.sh +3 -0
  75. package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
  76. package/modules/sage/index.js +7 -24
  77. package/modules/sage/templates/bin/theme-lint.hbs +6 -0
  78. package/modules/sage/templates/server/cmd/setup-sage-node.sh.hbs +3 -1
  79. package/modules/sage/templates/server/cmd/setup-sage-php.sh.hbs +3 -1
  80. package/modules/sage/templates/theme/vite.config.js.hbs +25 -4
  81. package/modules/sage/templates/workspace.json.hbs +0 -57
  82. package/modules/test/index.js +12 -11
  83. package/modules/test/templates/playwright.config.js.hbs +12 -0
  84. package/modules/test/tests/e2e/smoke.spec.js +28 -0
  85. package/package.json +3 -2
  86. package/templates/.env.hbs +16 -5
  87. package/templates/.gitignore.hbs +12 -1
  88. package/templates/.lando.yml.hbs +5 -11
  89. package/templates/CLAUDE.md.hbs +19 -2
  90. package/templates/package.json.hbs +8 -1
  91. package/templates/server/cmd/install-wp.sh.hbs +1 -1
  92. package/templates/server/cmd/setup-node.sh.hbs +3 -1
  93. package/templates/server/cmd/setup-php.sh.hbs +63 -9
  94. package/templates/workspace.json.hbs +0 -56
  95. package/{wp-config.php → templates/wp-config.php.hbs} +41 -5
  96. package/modules/lint/templates/.lando.yml.hbs +0 -5
  97. package/modules/sage/templates/.devcontainer/devcontainer.json.hbs +0 -7
  98. package/modules/sage/templates/.devcontainer/docker-compose.override.yml.hbs +0 -4
  99. package/modules/sage/templates/.devcontainer/post-create.sh.hbs +0 -11
  100. package/templates/.devcontainer/Dockerfile.hbs +0 -24
  101. package/templates/.devcontainer/config/nginx.conf +0 -23
  102. package/templates/.devcontainer/config/nginx.conf.hbs +0 -23
  103. package/templates/.devcontainer/devcontainer.json.hbs +0 -29
  104. package/templates/.devcontainer/docker-compose.yml.hbs +0 -76
  105. package/templates/.devcontainer/setup.sh.hbs +0 -17
  106. package/templates/auth.json.hbs +0 -8
@@ -0,0 +1,152 @@
1
+ <?php
2
+
3
+ /**
4
+ * Synthetic fixtures for the kivo-wp environment (D-002): no real personal data, emails on
5
+ * example.test, fixed dates. Run with `bin/seed` (wp eval-file). Every user, term, post and menu
6
+ * item carries the _kivo_wp_fixture meta, so a second run deletes the previous fixtures first
7
+ * and the result is the same. Fixture user passwords are random and never printed.
8
+ */
9
+
10
+ if (! defined('ABSPATH') || ! class_exists('WP_CLI')) {
11
+ exit(1);
12
+ }
13
+
14
+ require_once ABSPATH . 'wp-admin/includes/user.php';
15
+
16
+ const KIVO_WP_FIXTURE_META = '_kivo_wp_fixture';
17
+
18
+ $kivoWpFixturesDir = __DIR__;
19
+
20
+ $kivoWpLoad = static function (string $name) use ($kivoWpFixturesDir): array {
21
+ $raw = file_get_contents($kivoWpFixturesDir . '/' . $name . '.json');
22
+
23
+ return json_decode((string) $raw, true, 512, JSON_THROW_ON_ERROR);
24
+ };
25
+
26
+ $kivoWpCheck = static function ($result, string $what) {
27
+ if (is_wp_error($result)) {
28
+ WP_CLI::error($what . ': ' . $result->get_error_message());
29
+ }
30
+
31
+ return $result;
32
+ };
33
+
34
+ // 1. Remove the previous fixtures (menu items are posts too).
35
+ $tagged = get_posts([
36
+ 'post_type' => 'any',
37
+ 'post_status' => 'any',
38
+ 'numberposts' => -1,
39
+ 'fields' => 'ids',
40
+ 'meta_key' => KIVO_WP_FIXTURE_META,
41
+ ]);
42
+ $taggedItems = get_posts([
43
+ 'post_type' => 'nav_menu_item',
44
+ 'post_status' => 'any',
45
+ 'numberposts' => -1,
46
+ 'fields' => 'ids',
47
+ 'meta_key' => KIVO_WP_FIXTURE_META,
48
+ ]);
49
+ foreach (array_unique(array_merge($tagged, $taggedItems)) as $postId) {
50
+ wp_delete_post($postId, true);
51
+ }
52
+ foreach (['category', 'post_tag', 'nav_menu'] as $taxonomy) {
53
+ $terms = get_terms([
54
+ 'taxonomy' => $taxonomy,
55
+ 'hide_empty' => false,
56
+ 'fields' => 'ids',
57
+ 'meta_key' => KIVO_WP_FIXTURE_META,
58
+ ]);
59
+ foreach (is_array($terms) ? $terms : [] as $termId) {
60
+ wp_delete_term($termId, $taxonomy);
61
+ }
62
+ }
63
+ foreach (get_users(['meta_key' => KIVO_WP_FIXTURE_META, 'fields' => 'ID']) as $userId) {
64
+ wp_delete_user((int) $userId);
65
+ }
66
+
67
+ // 2. Users.
68
+ $users = [];
69
+ foreach ($kivoWpLoad('users') as $user) {
70
+ $userId = $kivoWpCheck(wp_insert_user([
71
+ 'user_login' => $user['login'],
72
+ 'user_email' => $user['email'],
73
+ 'user_pass' => wp_generate_password(32),
74
+ 'display_name' => $user['display_name'],
75
+ 'first_name' => $user['first_name'],
76
+ 'last_name' => $user['last_name'],
77
+ 'role' => $user['role'],
78
+ ]), 'user ' . $user['login']);
79
+ update_user_meta($userId, KIVO_WP_FIXTURE_META, 1);
80
+ $users[$user['login']] = $userId;
81
+ }
82
+
83
+ // 3. Terms.
84
+ foreach ($kivoWpLoad('terms') as $term) {
85
+ $created = $kivoWpCheck(wp_insert_term($term['name'], $term['taxonomy'], [
86
+ 'slug' => $term['slug'],
87
+ 'description' => $term['description'] ?? '',
88
+ ]), 'term ' . $term['slug']);
89
+ update_term_meta($created['term_id'], KIVO_WP_FIXTURE_META, 1);
90
+ }
91
+
92
+ // 4. Posts and pages.
93
+ $pages = [];
94
+ foreach ($kivoWpLoad('posts') as $post) {
95
+ $categoryIds = array_map(
96
+ static fn (string $slug): int => (int) get_term_by('slug', $slug, 'category')->term_id,
97
+ $post['categories'] ?? []
98
+ );
99
+ $postId = $kivoWpCheck(wp_insert_post([
100
+ 'post_type' => $post['type'],
101
+ 'post_name' => $post['slug'],
102
+ 'post_title' => $post['title'],
103
+ 'post_content' => $post['content'],
104
+ 'post_excerpt' => $post['excerpt'] ?? '',
105
+ 'post_status' => $post['status'] ?? 'publish',
106
+ 'post_author' => $users[$post['author']] ?? 1,
107
+ 'post_date' => $post['date'],
108
+ 'post_category' => $categoryIds,
109
+ 'tags_input' => $post['tags'] ?? [],
110
+ 'meta_input' => [KIVO_WP_FIXTURE_META => 1],
111
+ ], true), 'post ' . $post['slug']);
112
+ if ($post['type'] === 'page') {
113
+ $pages[$post['slug']] = $postId;
114
+ }
115
+ }
116
+
117
+ // 5. Menus.
118
+ foreach ($kivoWpLoad('menus') as $menu) {
119
+ $menuId = $kivoWpCheck(wp_create_nav_menu($menu['name']), 'menu ' . $menu['name']);
120
+ update_term_meta($menuId, KIVO_WP_FIXTURE_META, 1);
121
+ foreach ($menu['items'] as $position => $item) {
122
+ $itemId = $kivoWpCheck(wp_update_nav_menu_item($menuId, 0, [
123
+ 'menu-item-title' => $item['title'],
124
+ 'menu-item-object' => 'page',
125
+ 'menu-item-object-id' => $pages[$item['page']],
126
+ 'menu-item-type' => 'post_type',
127
+ 'menu-item-status' => 'publish',
128
+ 'menu-item-position' => $position + 1,
129
+ ]), 'menu item ' . $item['title']);
130
+ update_post_meta($itemId, KIVO_WP_FIXTURE_META, 1);
131
+ }
132
+ if (array_key_exists($menu['location'], get_registered_nav_menus())) {
133
+ $locations = get_theme_mod('nav_menu_locations', []);
134
+ $locations[$menu['location']] = $menuId;
135
+ set_theme_mod('nav_menu_locations', $locations);
136
+ }
137
+ }
138
+
139
+ // 6. Options, written by key. {"page": "<slug>"} resolves to that fixture page's id.
140
+ foreach ($kivoWpLoad('options') as $key => $value) {
141
+ if (is_array($value) && isset($value['page'])) {
142
+ $value = $pages[$value['page']];
143
+ }
144
+ update_option($key, $value);
145
+ }
146
+
147
+ WP_CLI::success(sprintf(
148
+ 'Seeded %d users, %d pages and %d posts of synthetic fixtures.',
149
+ count($users),
150
+ count($pages),
151
+ count($kivoWpLoad('posts')) - count($pages)
152
+ ));
@@ -0,0 +1,6 @@
1
+ [
2
+ { "taxonomy": "category", "name": "News", "slug": "news", "description": "Project updates." },
3
+ { "taxonomy": "category", "name": "Guides", "slug": "guides", "description": "How-to articles." },
4
+ { "taxonomy": "post_tag", "name": "Sample", "slug": "sample" },
5
+ { "taxonomy": "post_tag", "name": "Fixture", "slug": "fixture" }
6
+ ]
@@ -0,0 +1,26 @@
1
+ [
2
+ {
3
+ "login": "editor",
4
+ "email": "editor@example.test",
5
+ "display_name": "Erin Editor",
6
+ "first_name": "Erin",
7
+ "last_name": "Editor",
8
+ "role": "editor"
9
+ },
10
+ {
11
+ "login": "author",
12
+ "email": "author@example.test",
13
+ "display_name": "Alex Author",
14
+ "first_name": "Alex",
15
+ "last_name": "Author",
16
+ "role": "author"
17
+ },
18
+ {
19
+ "login": "subscriber",
20
+ "email": "subscriber@example.test",
21
+ "display_name": "Sam Subscriber",
22
+ "first_name": "Sam",
23
+ "last_name": "Subscriber",
24
+ "role": "subscriber"
25
+ }
26
+ ]
@@ -0,0 +1,193 @@
1
+ import path from "path";
2
+
3
+ import fs from "fs-extra";
4
+
5
+ import { VERSION_REGISTRY, serversidePhpImage } from "../../lib/config/versions.js";
6
+ import { buildCloudAllowlist } from "../../lib/core/cloud-allowlist.js";
7
+ import { log, color } from "../../lib/utils/logger.js";
8
+
9
+ /**
10
+ * Themes built into the production image: each has its own Composer and npm dependencies.
11
+ */
12
+ function themeDirs(context) {
13
+ const contentDir = context.contentDir || "content";
14
+ const dirs = [];
15
+ if (context.enable_sage) dirs.push(`${contentDir}/themes/${context.projectName}`);
16
+ if (context.enable_blank_theme) {
17
+ dirs.push(`${contentDir}/themes/${context.blank_theme_name || `${context.projectName}-theme`}`);
18
+ }
19
+ return dirs;
20
+ }
21
+
22
+ /**
23
+ * bin/ runner (D-023): script names are the contract kivo-wise reads; renaming one is a
24
+ * contract change. Every script sources bin/_lib.sh within its first 4 KB.
25
+ */
26
+ export const BIN_SCRIPTS = Object.freeze([
27
+ "up",
28
+ "down",
29
+ "info",
30
+ "logs",
31
+ "shell",
32
+ "wp",
33
+ "php",
34
+ "composer",
35
+ "npm",
36
+ "node",
37
+ "dev",
38
+ "build",
39
+ "flush",
40
+ "reset-deps",
41
+ "db",
42
+ "db-export",
43
+ "db-import",
44
+ "test",
45
+ "stan",
46
+ "mago",
47
+ "e2e",
48
+ "xdebug",
49
+ "trust-cert",
50
+ "setup",
51
+ "seed",
52
+ ]);
53
+
54
+ // Lando tooling in editor workspace tasks, mapped to the kivo-wp bin/ scripts (D-030).
55
+ const LANDO_TASKS = {
56
+ start: ["bin/up"],
57
+ stop: ["bin/down"],
58
+ info: ["bin/info"],
59
+ yarn: ["bin/npm"],
60
+ composer: ["bin/composer"],
61
+ "redis-cli": ["bin/shell", "cache", "valkey-cli"],
62
+ "git-cz": ["bin/npm", "exec", "--", "git-cz"],
63
+ "commitlint-check": [
64
+ "bin/npm",
65
+ "exec",
66
+ "--",
67
+ "commitlint",
68
+ "--from",
69
+ "HEAD~1",
70
+ "--to",
71
+ "HEAD",
72
+ "--verbose",
73
+ ],
74
+ "conventional-changelog": [
75
+ "bin/npm",
76
+ "exec",
77
+ "--",
78
+ "conventional-changelog",
79
+ "-p",
80
+ "angular",
81
+ "-i",
82
+ "CHANGELOG.md",
83
+ "-s",
84
+ ],
85
+ mago: ["bin/mago", "format"],
86
+ "mago-check": ["bin/mago", "format", "--check"],
87
+ "mago-lint": ["bin/mago", "lint"],
88
+ "theme-bootstrap": ["bin/reset-deps"],
89
+ "theme-build": ["bin/build"],
90
+ "theme-dev": ["bin/dev"],
91
+ "theme-lint": ["bin/theme-lint"],
92
+ acorn: ["bin/wp", "acorn"],
93
+ };
94
+
95
+ /** Rewrite Lando references in the generated editor workspace for kivo-wp. */
96
+ export function toKivoWpWorkspace(workspace) {
97
+ const tasks = workspace.tasks?.tasks ?? [];
98
+ workspace.tasks &&
99
+ (workspace.tasks.tasks = tasks.flatMap((task) => {
100
+ if (task.command !== "lando") return [task];
101
+ const [tool, ...rest] = task.args ?? [];
102
+ const mapped = LANDO_TASKS[tool];
103
+ if (!mapped) return [];
104
+ const [command, ...args] = mapped;
105
+ return [
106
+ {
107
+ ...task,
108
+ label: task.label.replace(/Lando/g, "kivo-wp"),
109
+ command,
110
+ args: [...args, ...rest],
111
+ },
112
+ ];
113
+ }));
114
+
115
+ const json = JSON.stringify(workspace)
116
+ .replace(/,?"\*\*\/\.lando(\/\*\*)?":true/g, "")
117
+ .replace(/,?"\*\*\/\.lando\/\*\*"/g, "")
118
+ .replace(/"lando"/g, '"kivo-wp"');
119
+ return JSON.parse(json.replace(/\{,/g, "{").replace(/\[,/g, "["));
120
+ }
121
+
122
+ /**
123
+ * kivo-wp: the Docker Compose development environment (D-004, D-009, D-011, D-012).
124
+ * Renders compose.yaml (other modules may add compose.yaml.hbs fragments), the root
125
+ * Dockerfile, the nginx deny include, the Caddy config and the local mail MU plugin.
126
+ */
127
+ export async function setupModule(context, generator) {
128
+ if (!context.enable_kivo_wp) return;
129
+
130
+ const contentDir = context.contentDir || "content";
131
+ const kivoWp = {
132
+ ...VERSION_REGISTRY.kivoWp,
133
+ appImage: serversidePhpImage(context.phpVersion),
134
+ themeDirs: themeDirs(context),
135
+ };
136
+ const ctx = { ...context, contentDir, kivoWp, cloudAllowlist: buildCloudAllowlist(context) };
137
+
138
+ log(color.blue, "[kivo-wp] Rendering the Docker Compose environment");
139
+
140
+ await generator.generateModularFile({
141
+ baseTemplate: "compose.yaml",
142
+ baseModule: "kivo-wp",
143
+ modules: context.enabledModules || [],
144
+ context: ctx,
145
+ mergeStrategy: "concat",
146
+ header: [
147
+ "# kivo-wp: Docker Compose development environment generated by wp-kit.",
148
+ "# Use the bin/ scripts instead of calling docker compose directly.",
149
+ "# x-kivo-wp.contract is read by agent tooling: service and bin/ names are fixed for that version.",
150
+ "# Keep x-kivo-wp, service names and image keys free of YAML anchors and aliases.",
151
+ ].join("\n"),
152
+ });
153
+ await generator.generateFile("Dockerfile", ctx, "kivo-wp");
154
+ await generator.generateFile(".dockerignore", ctx, "kivo-wp");
155
+ await generator.generateFile("server/nginx/deny.conf", ctx, "kivo-wp");
156
+ await generator.generateFile("server/caddy/Caddyfile", ctx, "kivo-wp");
157
+ for (const name of ["_lib.sh", ...BIN_SCRIPTS]) {
158
+ await generator.generateFile(`bin/${name}`, ctx, "kivo-wp");
159
+ await fs.chmod(path.join(generator.cwd, "bin", name), name === "_lib.sh" ? 0o644 : 0o755);
160
+ }
161
+ if (context.enable_sage && context.enable_lint) {
162
+ await generator.generateFile("bin/theme-lint", ctx, "sage");
163
+ await fs.chmod(path.join(generator.cwd, "bin", "theme-lint"), 0o755);
164
+ }
165
+
166
+ // One workspace container running the root compose.yaml (D-009, D-022); cloud session guide.
167
+ await generator.generateFile(".devcontainer/devcontainer.json", ctx, "kivo-wp");
168
+ await generator.generateFile("docs/cloud-sessions.md", ctx, "kivo-wp");
169
+
170
+ // Synthetic fixtures (D-002) read by bin/seed.
171
+ await generator.copyDirectory("fixtures", "kivo-wp", "fixtures");
172
+
173
+ // The spell-check dictionary of the Lando era lists "lando"; kivo-wp projects do not need it.
174
+ const cspellFile = path.join(generator.cwd, ".cspell.json");
175
+ if (await fs.pathExists(cspellFile)) {
176
+ const cspell = await fs.readJson(cspellFile);
177
+ if (Array.isArray(cspell.words)) cspell.words = cspell.words.filter((word) => word !== "lando");
178
+ await fs.writeJson(cspellFile, cspell, { spaces: 2 });
179
+ }
180
+
181
+ const workspaceFile = path.join(generator.cwd, `${context.projectName}.code-workspace`);
182
+ if (await fs.pathExists(workspaceFile)) {
183
+ const workspace = await fs.readJson(workspaceFile);
184
+ await fs.writeJson(workspaceFile, toKivoWpWorkspace(workspace), { spaces: 2 });
185
+ }
186
+
187
+ await generator.generateFile(
188
+ "content/mu-plugins/kivo-wp-local-mail.php",
189
+ ctx,
190
+ "kivo-wp",
191
+ `${contentDir}/mu-plugins/kivo-wp-local-mail.php`,
192
+ );
193
+ }
@@ -0,0 +1 @@
1
+ export default [];
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "{{projectName}} (kivo-wp)",
3
+ "image": "mcr.microsoft.com/devcontainers/base:3.0.14-noble",
4
+ "features": {
5
+ "ghcr.io/devcontainers/features/docker-in-docker:4": {},
6
+ "ghcr.io/devcontainers/features/node:2": {
7
+ "version": "lts"
8
+ }
9
+ },
10
+ "containerEnv": {
11
+ "KIVO_WP_CONTEXT": "devcontainer"
12
+ },
13
+ "postCreateCommand": "bin/setup",
14
+ "postStartCommand": "bin/up && if [ \"${CODESPACES:-}\" = \"true\" ]; then nohup bash -c 'while sleep 60; do bin/wp cron event run --due-now >/dev/null 2>&1; done' >/dev/null 2>&1 & fi",
15
+ "forwardPorts": [443, 80],
16
+ "portsAttributes": {
17
+ "443": {
18
+ "label": "Site (Caddy, HTTPS)",
19
+ "protocol": "https"
20
+ },
21
+ "80": {
22
+ "label": "Site (Caddy, HTTP; used by Codespaces forwarding)",
23
+ "protocol": "http"
24
+ }
25
+ },
26
+ "customizations": {
27
+ "vscode": {
28
+ "extensions": [
29
+ "bmewburn.vscode-intelephense-client",
30
+ "carthage-software.mago",
31
+ "oxc.oxc-vscode",
32
+ "ms-azuretools.vscode-docker"
33
+ ],
34
+ "settings": {
35
+ "editor.formatOnSave": false,
36
+ "terminal.integrated.defaultProfile.linux": "bash"
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,15 @@
1
+ # Never sent to the build: secrets, local state and dependencies rebuilt inside the image.
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+ auth.json
6
+ auth.json.tpl
7
+ .git
8
+ .github
9
+ .gitlab
10
+ **/node_modules
11
+ **/vendor
12
+ wp
13
+ {{contentDir}}/uploads
14
+ compose.override.yaml
15
+ .kivo-wise
@@ -0,0 +1,81 @@
1
+ # syntax=docker/dockerfile:1
2
+ # kivo-wp image (D-011). Targets:
3
+ # base serversideup/php fpm-nginx with the extensions, WP-CLI and nginx rules WordPress needs
4
+ # development used by compose.yaml: Xdebug (off by default), host UID/GID, OPcache revalidation
5
+ # production project code with production dependencies and built theme assets
6
+ ARG PHP_VERSION={{phpVersion}}
7
+
8
+ FROM serversideup/php:${PHP_VERSION}-fpm-nginx-{{kivoWp.serversidePhpRelease}} AS base
9
+
10
+ USER root
11
+
12
+ ARG WP_CLI_VERSION={{kivoWp.wpCli.version}}
13
+ ARG WP_CLI_SHA512={{kivoWp.wpCli.sha512}}
14
+
15
+ RUN install-php-extensions mysqli gd intl exif bcmath imagick \
16
+ && curl -fsSL -o /usr/local/bin/wp \
17
+ "https://github.com/wp-cli/wp-cli/releases/download/v${WP_CLI_VERSION}/wp-cli-${WP_CLI_VERSION}.phar" \
18
+ && echo "${WP_CLI_SHA512} /usr/local/bin/wp" | sha512sum -c - \
19
+ && chmod 0755 /usr/local/bin/wp
20
+
21
+ # The project root is the web root (WordPress core lives in wp/).
22
+ ENV NGINX_WEBROOT=/var/www/html
23
+
24
+ # Sorted before the image's own server options so its 404 rules win (see the file).
25
+ COPY server/nginx/deny.conf /etc/nginx/server-opts.d/00-kivo-wp-deny.conf
26
+ {{#if useRocket}}
27
+ COPY server/www/rocket.conf /etc/nginx/server-opts.d/50-rocket.conf
28
+ {{/if}}
29
+ COPY server/php/php.ini /usr/local/etc/php/conf.d/zz-project.ini
30
+
31
+ USER www-data
32
+
33
+ FROM base AS development
34
+
35
+ USER root
36
+
37
+ ARG USER_ID=1000
38
+ ARG GROUP_ID=1000
39
+
40
+ # Bind-mounted files keep the developer's ownership; bin/xdebug toggles XDEBUG_MODE.
41
+ RUN install-php-extensions xdebug \
42
+ && docker-php-serversideup-set-id www-data "${USER_ID}:${GROUP_ID}" \
43
+ && docker-php-serversideup-set-file-permissions --owner "${USER_ID}:${GROUP_ID}" --service fpm-nginx
44
+
45
+ ENV XDEBUG_MODE=off \
46
+ PHP_OPCACHE_ENABLE=1 \
47
+ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \
48
+ PHP_OPCACHE_REVALIDATE_FREQ=0
49
+
50
+ USER www-data
51
+ {{#if kivoWp.themeDirs.length}}
52
+
53
+ FROM node:{{nodeVersion}}-bookworm AS assets
54
+
55
+ WORKDIR /app
56
+ {{#each kivoWp.themeDirs}}
57
+ COPY {{this}}/ {{this}}/
58
+ RUN cd {{this}} \
59
+ && if [ -f package-lock.json ]; then npm ci; else npm install; fi \
60
+ && npm run build \
61
+ && rm -rf node_modules
62
+ {{/each}}
63
+ {{/if}}
64
+
65
+ FROM base AS production
66
+
67
+ COPY --chown=www-data:www-data . /var/www/html
68
+ {{#each kivoWp.themeDirs}}
69
+ COPY --from=assets --chown=www-data:www-data /app/{{this}}/ /var/www/html/{{this}}/
70
+ {{/each}}
71
+
72
+ # Licensed packages: pass auth.json as a BuildKit secret (--secret id=composer_auth,src=auth.json);
73
+ # it is never written to a layer.
74
+ RUN --mount=type=secret,id=composer_auth,required=false,uid=33 \
75
+ set -eu; \
76
+ if [ -f /run/secrets/composer_auth ]; then COMPOSER_AUTH="$(cat /run/secrets/composer_auth)"; export COMPOSER_AUTH; fi; \
77
+ for dir in /var/www/html{{#each kivoWp.themeDirs}} /var/www/html/{{this}}{{/each}}; do \
78
+ if [ -f "${dir}/composer.json" ]; then \
79
+ composer install --working-dir="${dir}" --no-dev --no-interaction --no-progress --prefer-dist --optimize-autoloader; \
80
+ fi; \
81
+ done
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env bash
2
+ # kivo-wp bin/ library: sourced by every bin/ script, never executed on its own.
3
+ # Every tool runs inside the Compose stack; nothing runs on the host.
4
+ # shellcheck shell=bash
5
+
6
+ set -euo pipefail
7
+
8
+ KIVO_WP_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
9
+ # Project path inside the app and node containers (bind mount in compose.yaml).
10
+ KIVO_WP_CONTAINER_ROOT="/var/www/html"
11
+ # Theme directories relative to the root (used by bin/build, bin/dev and bin/flush).
12
+ # shellcheck disable=SC2034
13
+ KIVO_WP_THEME_DIRS=({{#each kivoWp.themeDirs}}"{{this}}"{{#unless @last}} {{/unless}}{{/each}})
14
+ export KIVO_WP_ROOT KIVO_WP_CONTAINER_ROOT
15
+
16
+ kivo_wp_err() {
17
+ printf 'kivo-wp: %s\n' "$*" >&2
18
+ }
19
+
20
+ kivo_wp_die() {
21
+ kivo_wp_err "$@"
22
+ exit 1
23
+ }
24
+
25
+ # docker compose for this project. No -f: compose.override.yaml still merges.
26
+ kivo_wp_compose() {
27
+ command -v docker >/dev/null 2>&1 || kivo_wp_die "docker not found; open the project on a host or workspace container with Docker"
28
+ docker compose --project-directory "${KIVO_WP_ROOT}" "$@"
29
+ }
30
+
31
+ kivo_wp_is_running() {
32
+ local service="$1" running
33
+ running="$(kivo_wp_compose ps --status running --services 2>/dev/null || true)"
34
+ grep -qx "${service}" <<<"${running}"
35
+ }
36
+
37
+ kivo_wp_require_running() {
38
+ local service="${1:-app}"
39
+ kivo_wp_is_running "${service}" || kivo_wp_die "kivo-wp stack is not running (service ${service}); start it with bin/up"
40
+ }
41
+
42
+ # Container working directory: the caller's directory when it is inside the project.
43
+ kivo_wp_workdir() {
44
+ local here
45
+ here="$(pwd -P)"
46
+ case "${here}/" in
47
+ "${KIVO_WP_ROOT}/"*)
48
+ local rel="${here#"${KIVO_WP_ROOT}"}"
49
+ printf '%s%s\n' "${KIVO_WP_CONTAINER_ROOT}" "${rel}"
50
+ ;;
51
+ *) printf '%s\n' "${KIVO_WP_CONTAINER_ROOT}" ;;
52
+ esac
53
+ }
54
+
55
+ # Run a command in a service. -T when stdin or stdout is not a terminal, so piped input
56
+ # (agents, MCP stdio, CI) and captured output stay byte-clean.
57
+ kivo_wp_exec() {
58
+ local service="$1"
59
+ shift
60
+ kivo_wp_require_running "${service}"
61
+ local flags=()
62
+ if [ ! -t 0 ] || [ ! -t 1 ]; then
63
+ flags+=(-T)
64
+ fi
65
+ kivo_wp_compose exec ${flags[@]+"${flags[@]}"} --workdir "$(kivo_wp_workdir)" "${service}" "$@"
66
+ }
67
+
68
+ # Same as kivo_wp_exec, from a fixed container directory relative to the project root.
69
+ kivo_wp_exec_in() {
70
+ local service="$1" dir="$2"
71
+ shift 2
72
+ kivo_wp_require_running "${service}"
73
+ local flags=()
74
+ if [ ! -t 0 ] || [ ! -t 1 ]; then
75
+ flags+=(-T)
76
+ fi
77
+ kivo_wp_compose exec ${flags[@]+"${flags[@]}"} --workdir "${KIVO_WP_CONTAINER_ROOT}/${dir}" "${service}" "$@"
78
+ }
79
+
80
+ # Value of a key in .env without exporting the file (it holds salts; only named keys are read).
81
+ kivo_wp_env_get() {
82
+ local key="$1" file="${KIVO_WP_ROOT}/.env" line
83
+ [ -f "${file}" ] || return 0
84
+ line="$(grep -E "^${key}=" "${file}" | tail -n 1 || true)"
85
+ line="${line#*=}"
86
+ line="${line%\"}"
87
+ line="${line#\"}"
88
+ printf '%s\n' "${line}"
89
+ }
90
+
91
+ # Set KEY=value in .env, adding the line when missing.
92
+ kivo_wp_env_set() {
93
+ local key="$1" value="$2" file="${KIVO_WP_ROOT}/.env" tmp
94
+ [ -f "${file}" ] || kivo_wp_die ".env not found; run bin/setup"
95
+ tmp="$(mktemp)"
96
+ if grep -qE "^${key}=" "${file}"; then
97
+ awk -v k="${key}" -v v="${value}" 'BEGIN { FS = OFS = "=" } $1 == k { print k "=" v; next } { print }' "${file}" >"${tmp}"
98
+ else
99
+ cat "${file}" >"${tmp}"
100
+ # Keep the new line on its own even when the file lacks a final newline.
101
+ [ -z "$(tail -c 1 "${file}")" ] || printf '\n' >>"${tmp}"
102
+ printf '%s=%s\n' "${key}" "${value}" >>"${tmp}"
103
+ fi
104
+ cat "${tmp}" >"${file}"
105
+ rm -f "${tmp}"
106
+ }
107
+
108
+ # Remove KEY from .env when present.
109
+ kivo_wp_env_unset() {
110
+ local key="$1" file="${KIVO_WP_ROOT}/.env" tmp
111
+ [ -f "${file}" ] && grep -qE "^${key}=" "${file}" || return 0
112
+ tmp="$(mktemp)"
113
+ grep -vE "^${key}=" "${file}" >"${tmp}" || true
114
+ cat "${tmp}" >"${file}"
115
+ rm -f "${tmp}"
116
+ }
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bash
2
+ # Build the theme assets in the node service.
3
+ # shellcheck source=_lib.sh source-path=SCRIPTDIR
4
+ source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
5
+
6
+ if [ "${#KIVO_WP_THEME_DIRS[@]}" -eq 0 ]; then
7
+ kivo_wp_err "this project has no theme to build"
8
+ exit 0
9
+ fi
10
+ for dir in "${KIVO_WP_THEME_DIRS[@]}"; do
11
+ kivo_wp_err "building ${dir}"
12
+ kivo_wp_exec_in node "${dir}" npm run build
13
+ done
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ # Composer in the app service.
3
+ # shellcheck source=_lib.sh source-path=SCRIPTDIR
4
+ source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
5
+
6
+ kivo_wp_exec app composer "$@"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ # Export the local database to a SQL file (default: db-export-<timestamp>.sql).
3
+ # shellcheck source=_lib.sh source-path=SCRIPTDIR
4
+ source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
5
+
6
+ file="${1:-db-export-$(date +%Y%m%d-%H%M%S).sql}"
7
+ kivo_wp_exec app wp db export - >"${file}"
8
+ kivo_wp_err "database exported to ${file}"