@forgewp/compiler 0.2.0 → 0.4.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 +24 -5
- package/bin/analyze.js +158 -0
- package/bin/cli.js +29 -4
- package/bin/doctor.js +125 -11
- package/bin/export.js +20 -0
- package/bin/fresh.js +32 -343
- package/bin/i18n-extract.js +121 -0
- package/bin/i18n-translate.js +112 -0
- package/bin/make-block.js +27 -60
- package/bin/make-island.js +72 -0
- package/bin/make-post-type.js +6 -6
- package/bin/make-template.js +145 -0
- package/bin/repair.js +2 -2
- package/bin/sync-routes.js +28 -158
- package/define-config.d.ts +1 -0
- package/define-config.js +1 -0
- package/lib/adapters/html-adapter.js +65 -0
- package/lib/adapters/stub-adapter.js +49 -0
- package/lib/add-component.js +290 -73
- package/lib/asset-loader.js +27 -0
- package/lib/block-compiler.js +552 -0
- package/lib/blueprints.js +1459 -501
- package/lib/define-config.d.ts +3 -0
- package/lib/define-config.js +8 -0
- package/lib/diagnostics.js +798 -0
- package/lib/export-theme.js +81 -18
- package/lib/framework-adapter.js +34 -0
- package/lib/functions-builder.js +1801 -0
- package/lib/generate-theme.js +1019 -1143
- package/lib/hydration-scanner.js +674 -0
- package/lib/i18n/extractor.js +60 -0
- package/lib/i18n/providers.js +165 -0
- package/lib/index.d.ts +119 -1
- package/lib/index.js +20 -3
- package/lib/load-config.js +122 -6
- package/lib/markup-processor.js +584 -0
- package/lib/php-builders.js +381 -0
- package/lib/react-adapter.js +1336 -0
- package/lib/render-static.js +9 -82
- package/lib/render-theme.mts +526 -232
- package/lib/screenshot-fallback.png +0 -0
- package/lib/types.js +1 -0
- package/lib/validate-export.js +183 -0
- package/package.json +14 -3
- package/bin/make-component.js +0 -200
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper to build WordPress theme style.css file content.
|
|
3
|
+
*
|
|
4
|
+
* @param {import('./types.js').ForgeWPThemeConfig} config
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
7
|
+
export function buildStyleCss(config) {
|
|
8
|
+
return `/*
|
|
9
|
+
Theme Name: ${config.name}
|
|
10
|
+
Theme URI: https://forgewp.dev
|
|
11
|
+
Author: ForgeWP
|
|
12
|
+
Description: ${config.description}
|
|
13
|
+
Version: ${config.version}
|
|
14
|
+
Requires at least: 6.0
|
|
15
|
+
Tested up to: 6.7
|
|
16
|
+
Requires PHP: 7.4
|
|
17
|
+
License: GNU General Public License v2 or later
|
|
18
|
+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
19
|
+
Text Domain: ${config.textDomain}
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/* Compiled styles are enqueued from assets/ via functions.php */
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generate Advanced Custom Fields (ACF) PHP array structure for a field.
|
|
28
|
+
*/
|
|
29
|
+
export function generateAcfFieldPhp(key, field, parentKey = '') {
|
|
30
|
+
const acfKey = parentKey ? `${parentKey}_${key}` : `field_${key}`;
|
|
31
|
+
const label = field.label || key.charAt(0).toUpperCase() + key.slice(1);
|
|
32
|
+
const typeMap = {
|
|
33
|
+
text: 'text',
|
|
34
|
+
richText: 'wysiwyg',
|
|
35
|
+
boolean: 'true_false',
|
|
36
|
+
image: 'image',
|
|
37
|
+
repeater: 'repeater',
|
|
38
|
+
};
|
|
39
|
+
const acfType = field.customType || typeMap[field.type] || 'text';
|
|
40
|
+
|
|
41
|
+
let php = ` array(
|
|
42
|
+
'key' => '${acfKey}',
|
|
43
|
+
'label' => '${label.replace(/'/g, "\\'")}',
|
|
44
|
+
'name' => '${key}',
|
|
45
|
+
'type' => '${acfType}',`;
|
|
46
|
+
|
|
47
|
+
if (field.default !== undefined) {
|
|
48
|
+
if (typeof field.default === 'boolean') {
|
|
49
|
+
php += `\n 'default_value' => ${field.default ? 1 : 0},`;
|
|
50
|
+
} else if (typeof field.default === 'string') {
|
|
51
|
+
php += `\n 'default_value' => '${field.default.replace(/'/g, "\\'")}',`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (acfType === 'image') {
|
|
56
|
+
php += `\n 'return_format' => 'url',`;
|
|
57
|
+
} else if (acfType === 'relationship') {
|
|
58
|
+
const pts = field.postTypes ? field.postTypes.map(pt => `'${pt}'`).join(', ') : '';
|
|
59
|
+
const ptExpr = pts ? `array(${pts})` : `array()`;
|
|
60
|
+
php += `\n 'post_type' => ${ptExpr},\n 'filters' => array('search', 'taxonomy'),\n 'return_format' => 'id',`;
|
|
61
|
+
} else if (acfType === 'true_false') {
|
|
62
|
+
php += `\n 'ui' => 1,`;
|
|
63
|
+
} else if (acfType === 'repeater' && field.fields) {
|
|
64
|
+
const subFieldsPhp = Object.entries(field.fields)
|
|
65
|
+
.map(([subKey, subField]) => generateAcfFieldPhp(subKey, subField, acfKey))
|
|
66
|
+
.join(',\n');
|
|
67
|
+
php += `\n 'sub_fields' => array(
|
|
68
|
+
${subFieldsPhp}
|
|
69
|
+
),`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
php += `\n )`;
|
|
73
|
+
return php;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Generate dynamic ACF fallback PHP generation block.
|
|
78
|
+
*/
|
|
79
|
+
export function generateDynamicAcfFieldPhp(key, field) {
|
|
80
|
+
const acfKey = `field_${key}`;
|
|
81
|
+
const label = field.label || key.charAt(0).toUpperCase() + key.slice(1);
|
|
82
|
+
const typeMap = {
|
|
83
|
+
text: 'text',
|
|
84
|
+
richText: 'wysiwyg',
|
|
85
|
+
boolean: 'true_false',
|
|
86
|
+
image: 'image',
|
|
87
|
+
repeater: 'repeater',
|
|
88
|
+
};
|
|
89
|
+
const acfType = typeMap[field.type] || 'text';
|
|
90
|
+
|
|
91
|
+
if (acfType !== 'repeater') {
|
|
92
|
+
const fieldDef = generateAcfFieldPhp(key, field);
|
|
93
|
+
return ` $fields[] = ${fieldDef.trim()};\n`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const acfProDef = generateAcfFieldPhp(key, field);
|
|
97
|
+
const defaultRows = Array.isArray(field.default) ? field.default : [];
|
|
98
|
+
const defaultRowCount = defaultRows.length || 4;
|
|
99
|
+
|
|
100
|
+
let fallbackPhp = ` if ( function_exists('acf_is_pro') && acf_is_pro() ) {
|
|
101
|
+
$fields[] = ${acfProDef.trim()};
|
|
102
|
+
} else {
|
|
103
|
+
$post_id = isset($_GET['post']) ? intval($_GET['post']) : (isset($_POST['post_ID']) ? intval($_POST['post_ID']) : 0);
|
|
104
|
+
$count = $post_id ? intval(get_post_meta($post_id, '${key}', true)) : 0;
|
|
105
|
+
if ($count <= 0) {
|
|
106
|
+
$count = ${defaultRowCount};
|
|
107
|
+
}
|
|
108
|
+
for ($i = 0; $i < $count; $i++) {\n`;
|
|
109
|
+
|
|
110
|
+
for (const [subKey, subField] of Object.entries(field.fields)) {
|
|
111
|
+
const subLabel = subField.label || subKey.charAt(0).toUpperCase() + subKey.slice(1);
|
|
112
|
+
const subTypeMap = {
|
|
113
|
+
text: 'text',
|
|
114
|
+
richText: 'wysiwyg',
|
|
115
|
+
boolean: 'true_false',
|
|
116
|
+
image: 'image',
|
|
117
|
+
};
|
|
118
|
+
const subType = subTypeMap[subField.type] || 'text';
|
|
119
|
+
|
|
120
|
+
fallbackPhp += ` $fields[] = array(
|
|
121
|
+
'key' => "field_${key}_" . $i . "_${subKey}",
|
|
122
|
+
'label' => "${label.replace(/'/g, "\\'")}" . " " . ($i + 1) . ": ${subLabel.replace(/'/g, "\\'")}",
|
|
123
|
+
'name' => "${key}_" . $i . "_${subKey}",
|
|
124
|
+
'type' => '${subType}',`;
|
|
125
|
+
|
|
126
|
+
if (subType === 'image') {
|
|
127
|
+
fallbackPhp += `\n 'return_format' => 'url',`;
|
|
128
|
+
} else if (subType === 'true_false') {
|
|
129
|
+
fallbackPhp += `\n 'ui' => 1,`;
|
|
130
|
+
}
|
|
131
|
+
fallbackPhp += `\n );\n`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
fallbackPhp += ` }
|
|
135
|
+
}\n`;
|
|
136
|
+
|
|
137
|
+
return fallbackPhp;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function buildHeaderPhp(config) {
|
|
141
|
+
return `<?php
|
|
142
|
+
/**
|
|
143
|
+
* Theme header
|
|
144
|
+
*
|
|
145
|
+
* @package ${config.textDomain}
|
|
146
|
+
*/
|
|
147
|
+
?><!DOCTYPE html>
|
|
148
|
+
<html <?php language_attributes(); ?>>
|
|
149
|
+
<head>
|
|
150
|
+
<meta charset="<?php bloginfo('charset'); ?>">
|
|
151
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
152
|
+
<?php
|
|
153
|
+
// Yield metadata control to active SEO plugins to prevent duplication
|
|
154
|
+
$seo_plugin_active = defined('WPSEO_VERSION') ||
|
|
155
|
+
class_exists('RankMath') ||
|
|
156
|
+
class_exists('All_in_One_SEO_Pack') ||
|
|
157
|
+
defined('AIOSEO_VERSION') ||
|
|
158
|
+
class_exists('SEOPress\\\\Services\\\\Title');
|
|
159
|
+
|
|
160
|
+
if ( ! $seo_plugin_active ) {
|
|
161
|
+
$target = forgewp_resolve_head_target();
|
|
162
|
+
if (file_exists($target)) {
|
|
163
|
+
ob_start();
|
|
164
|
+
include $target;
|
|
165
|
+
$content = ob_get_clean();
|
|
166
|
+
// Strip duplicate title tag so standard wp_head title-tag support outputs it cleanly
|
|
167
|
+
echo preg_replace('/<title>.*?<\\/title>/is', '', $content);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
?>
|
|
171
|
+
<?php wp_head(); ?>
|
|
172
|
+
<style>
|
|
173
|
+
/* Reset WP link underlines to match React/Tailwind expected styling */
|
|
174
|
+
a { text-decoration: none !important; }
|
|
175
|
+
a:hover { text-decoration: none !important; }
|
|
176
|
+
</style>
|
|
177
|
+
</head>
|
|
178
|
+
<body <?php body_class(); ?>>
|
|
179
|
+
<?php wp_body_open(); ?>
|
|
180
|
+
<?php
|
|
181
|
+
$header_file = get_template_directory() . '/forgewp-static/header.html';
|
|
182
|
+
if (file_exists($header_file)) {
|
|
183
|
+
include $header_file;
|
|
184
|
+
}
|
|
185
|
+
?>
|
|
186
|
+
`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function buildFooterPhp(config) {
|
|
190
|
+
return `<?php
|
|
191
|
+
/**
|
|
192
|
+
* Theme footer
|
|
193
|
+
*
|
|
194
|
+
* @package ${config.textDomain}
|
|
195
|
+
*/
|
|
196
|
+
$footer_file = get_template_directory() . '/forgewp-static/footer.html';
|
|
197
|
+
if (file_exists($footer_file)) {
|
|
198
|
+
include $footer_file;
|
|
199
|
+
}
|
|
200
|
+
wp_footer();
|
|
201
|
+
?>
|
|
202
|
+
</body>
|
|
203
|
+
</html>
|
|
204
|
+
`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function buildIndexPhp() {
|
|
208
|
+
return `<?php
|
|
209
|
+
/**
|
|
210
|
+
* Main template — displays ForgeWP compiled static markup
|
|
211
|
+
*
|
|
212
|
+
* @package forgewp
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
get_header();
|
|
216
|
+
|
|
217
|
+
$markup_file = get_template_directory() . '/forgewp-static/content.html';
|
|
218
|
+
|
|
219
|
+
if (is_front_page() && file_exists($markup_file)) {
|
|
220
|
+
include $markup_file;
|
|
221
|
+
} elseif (have_posts()) {
|
|
222
|
+
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
223
|
+
while (have_posts()) {
|
|
224
|
+
the_post();
|
|
225
|
+
echo '<article class="mb-12">';
|
|
226
|
+
echo '<h1 class="text-3xl font-bold mb-4">' . get_the_title() . '</h1>';
|
|
227
|
+
echo '<div class="prose prose-zinc max-w-none">';
|
|
228
|
+
the_content();
|
|
229
|
+
echo '</div>';
|
|
230
|
+
echo '</article>';
|
|
231
|
+
}
|
|
232
|
+
echo '</main>';
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
get_footer();
|
|
236
|
+
`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function buildSinglePhp() {
|
|
240
|
+
return `<?php
|
|
241
|
+
/**
|
|
242
|
+
* Single post template
|
|
243
|
+
*
|
|
244
|
+
* @package forgewp
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
get_header();
|
|
248
|
+
|
|
249
|
+
$single_file = get_template_directory() . '/forgewp-static/single.html';
|
|
250
|
+
if (file_exists($single_file)) {
|
|
251
|
+
if (have_posts()) {
|
|
252
|
+
while (have_posts()) {
|
|
253
|
+
the_post();
|
|
254
|
+
include $single_file;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
if (have_posts()) {
|
|
259
|
+
while (have_posts()) {
|
|
260
|
+
the_post();
|
|
261
|
+
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
262
|
+
echo '<article>';
|
|
263
|
+
echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
|
|
264
|
+
echo '<div class="prose prose-zinc max-w-none">';
|
|
265
|
+
the_content();
|
|
266
|
+
echo '</div>';
|
|
267
|
+
echo '</article>';
|
|
268
|
+
echo '</main>';
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
get_footer();
|
|
274
|
+
`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function build404Php() {
|
|
278
|
+
return `<?php
|
|
279
|
+
/**
|
|
280
|
+
* 404 template
|
|
281
|
+
*
|
|
282
|
+
* @package forgewp
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
get_header();
|
|
286
|
+
|
|
287
|
+
$notFound_file = get_template_directory() . '/forgewp-static/404.html';
|
|
288
|
+
if (file_exists($notFound_file)) {
|
|
289
|
+
include $notFound_file;
|
|
290
|
+
} else {
|
|
291
|
+
echo '<main class="flex min-h-[60vh] flex-col items-center justify-center text-center px-6 py-24">';
|
|
292
|
+
echo '<p class="text-base font-semibold text-zinc-900">404</p>';
|
|
293
|
+
echo '<h1 class="mt-4 text-3xl font-bold tracking-tight text-zinc-900 sm:text-5xl">Page not found</h1>';
|
|
294
|
+
echo '<p class="mt-6 text-base leading-7 text-zinc-600">Sorry, we couldn’t find the page you’re looking for.</p>';
|
|
295
|
+
echo '</main>';
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
get_footer();
|
|
299
|
+
`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function buildArchivePhp() {
|
|
303
|
+
return `<?php
|
|
304
|
+
/**
|
|
305
|
+
* Archive template — category, tag, date, and author archives.
|
|
306
|
+
* Loads the ForgeWP compiled archive.html which contains the WpLoop.
|
|
307
|
+
*
|
|
308
|
+
* @package forgewp
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
get_header();
|
|
312
|
+
|
|
313
|
+
$archive_file = get_template_directory() . '/forgewp-static/archive.html';
|
|
314
|
+
|
|
315
|
+
if (file_exists($archive_file)) {
|
|
316
|
+
include $archive_file;
|
|
317
|
+
} else {
|
|
318
|
+
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
319
|
+
the_archive_title('<h1 class="text-3xl font-bold mb-8">', '</h1>');
|
|
320
|
+
if (have_posts()) {
|
|
321
|
+
echo '<div class="space-y-8">';
|
|
322
|
+
while (have_posts()) {
|
|
323
|
+
the_post();
|
|
324
|
+
echo '<article>';
|
|
325
|
+
echo '<h2 class="text-xl font-bold"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
|
|
326
|
+
echo '<div class="text-sm text-zinc-500 mt-1">' . get_the_date() . ' by ' . get_the_author() . '</div>';
|
|
327
|
+
echo '<div class="mt-3 text-zinc-600">';
|
|
328
|
+
the_excerpt();
|
|
329
|
+
echo '</div>';
|
|
330
|
+
echo '</article>';
|
|
331
|
+
}
|
|
332
|
+
echo '</div>';
|
|
333
|
+
} else {
|
|
334
|
+
echo '<p>No posts found.</p>';
|
|
335
|
+
}
|
|
336
|
+
echo '</main>';
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
get_footer();
|
|
340
|
+
`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function buildPagePhp() {
|
|
344
|
+
return `<?php
|
|
345
|
+
/**
|
|
346
|
+
* Static page template — WordPress pages (e.g. About, Contact).
|
|
347
|
+
* Reuses single.html since static pages share the same title+content structure.
|
|
348
|
+
*
|
|
349
|
+
* @package forgewp
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
get_header();
|
|
353
|
+
|
|
354
|
+
$page_file = get_template_directory() . '/forgewp-static/single.html';
|
|
355
|
+
|
|
356
|
+
if (file_exists($page_file)) {
|
|
357
|
+
if (have_posts()) {
|
|
358
|
+
while (have_posts()) {
|
|
359
|
+
the_post();
|
|
360
|
+
include $page_file;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
if (have_posts()) {
|
|
365
|
+
while (have_posts()) {
|
|
366
|
+
the_post();
|
|
367
|
+
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
368
|
+
echo '<article>';
|
|
369
|
+
echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
|
|
370
|
+
echo '<div class="prose prose-zinc max-w-none">';
|
|
371
|
+
the_content();
|
|
372
|
+
echo '</div>';
|
|
373
|
+
echo '</article>';
|
|
374
|
+
echo '</main>';
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
get_footer();
|
|
380
|
+
`;
|
|
381
|
+
}
|