@forgewp/compiler 0.3.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 +282 -183
- 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 -1352
- package/lib/hydration-scanner.js +516 -21
- package/lib/i18n/extractor.js +60 -0
- package/lib/i18n/providers.js +165 -0
- package/lib/index.d.ts +115 -3
- package/lib/index.js +19 -5
- 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
package/lib/generate-theme.js
CHANGED
|
@@ -1,1352 +1,1019 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
)
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
);
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
)
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
)
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
''
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
/<
|
|
589
|
-
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
'
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
)
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
if (
|
|
1012
|
-
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
a { text-decoration: none !important; }
|
|
1021
|
-
a:hover { text-decoration: none !important; }
|
|
1022
|
-
</style>
|
|
1023
|
-
</head>
|
|
1024
|
-
<body <?php body_class(); ?>>
|
|
1025
|
-
<?php wp_body_open(); ?>
|
|
1026
|
-
<?php
|
|
1027
|
-
$header_file = get_template_directory() . '/forgewp-static/header.html';
|
|
1028
|
-
if (file_exists($header_file)) {
|
|
1029
|
-
include $header_file;
|
|
1030
|
-
}
|
|
1031
|
-
?>
|
|
1032
|
-
`;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
function buildFooterPhp(config) {
|
|
1036
|
-
return `<?php
|
|
1037
|
-
/**
|
|
1038
|
-
* Theme footer
|
|
1039
|
-
*
|
|
1040
|
-
* @package ${config.textDomain}
|
|
1041
|
-
*/
|
|
1042
|
-
$footer_file = get_template_directory() . '/forgewp-static/footer.html';
|
|
1043
|
-
if (file_exists($footer_file)) {
|
|
1044
|
-
include $footer_file;
|
|
1045
|
-
}
|
|
1046
|
-
wp_footer();
|
|
1047
|
-
?>
|
|
1048
|
-
</body>
|
|
1049
|
-
</html>
|
|
1050
|
-
`;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
function buildIndexPhp() {
|
|
1054
|
-
return `<?php
|
|
1055
|
-
/**
|
|
1056
|
-
* Main template — displays ForgeWP compiled static markup
|
|
1057
|
-
*
|
|
1058
|
-
* @package forgewp
|
|
1059
|
-
*/
|
|
1060
|
-
|
|
1061
|
-
get_header();
|
|
1062
|
-
|
|
1063
|
-
$markup_file = get_template_directory() . '/forgewp-static/content.html';
|
|
1064
|
-
|
|
1065
|
-
if (is_front_page() && file_exists($markup_file)) {
|
|
1066
|
-
include $markup_file;
|
|
1067
|
-
} elseif (have_posts()) {
|
|
1068
|
-
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
1069
|
-
while (have_posts()) {
|
|
1070
|
-
the_post();
|
|
1071
|
-
echo '<article class="mb-12">';
|
|
1072
|
-
echo '<h1 class="text-3xl font-bold mb-4">' . get_the_title() . '</h1>';
|
|
1073
|
-
echo '<div class="prose prose-zinc max-w-none">';
|
|
1074
|
-
the_content();
|
|
1075
|
-
echo '</div>';
|
|
1076
|
-
echo '</article>';
|
|
1077
|
-
}
|
|
1078
|
-
echo '</main>';
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
get_footer();
|
|
1082
|
-
`;
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
function buildSinglePhp() {
|
|
1086
|
-
return `<?php
|
|
1087
|
-
/**
|
|
1088
|
-
* Single post template
|
|
1089
|
-
*
|
|
1090
|
-
* @package forgewp
|
|
1091
|
-
*/
|
|
1092
|
-
|
|
1093
|
-
get_header();
|
|
1094
|
-
|
|
1095
|
-
$single_file = get_template_directory() . '/forgewp-static/single.html';
|
|
1096
|
-
if (file_exists($single_file)) {
|
|
1097
|
-
if (have_posts()) {
|
|
1098
|
-
while (have_posts()) {
|
|
1099
|
-
the_post();
|
|
1100
|
-
include $single_file;
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
} else {
|
|
1104
|
-
if (have_posts()) {
|
|
1105
|
-
while (have_posts()) {
|
|
1106
|
-
the_post();
|
|
1107
|
-
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
1108
|
-
echo '<article>';
|
|
1109
|
-
echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
|
|
1110
|
-
echo '<div class="prose prose-zinc max-w-none">';
|
|
1111
|
-
the_content();
|
|
1112
|
-
echo '</div>';
|
|
1113
|
-
echo '</article>';
|
|
1114
|
-
echo '</main>';
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
get_footer();
|
|
1120
|
-
`;
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
function build404Php() {
|
|
1124
|
-
return `<?php
|
|
1125
|
-
/**
|
|
1126
|
-
* 404 template
|
|
1127
|
-
*
|
|
1128
|
-
* @package forgewp
|
|
1129
|
-
*/
|
|
1130
|
-
|
|
1131
|
-
get_header();
|
|
1132
|
-
|
|
1133
|
-
$notFound_file = get_template_directory() . '/forgewp-static/404.html';
|
|
1134
|
-
if (file_exists($notFound_file)) {
|
|
1135
|
-
include $notFound_file;
|
|
1136
|
-
} else {
|
|
1137
|
-
echo '<main class="flex min-h-[60vh] flex-col items-center justify-center text-center px-6 py-24">';
|
|
1138
|
-
echo '<p class="text-base font-semibold text-zinc-900">404</p>';
|
|
1139
|
-
echo '<h1 class="mt-4 text-3xl font-bold tracking-tight text-zinc-900 sm:text-5xl">Page not found</h1>';
|
|
1140
|
-
echo '<p class="mt-6 text-base leading-7 text-zinc-600">Sorry, we couldn’t find the page you’re looking for.</p>';
|
|
1141
|
-
echo '</main>';
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
get_footer();
|
|
1145
|
-
`;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
function buildArchivePhp() {
|
|
1149
|
-
return `<?php
|
|
1150
|
-
/**
|
|
1151
|
-
* Archive template — category, tag, date, and author archives.
|
|
1152
|
-
* Loads the ForgeWP compiled archive.html which contains the WpLoop.
|
|
1153
|
-
*
|
|
1154
|
-
* @package forgewp
|
|
1155
|
-
*/
|
|
1156
|
-
|
|
1157
|
-
get_header();
|
|
1158
|
-
|
|
1159
|
-
$archive_file = get_template_directory() . '/forgewp-static/archive.html';
|
|
1160
|
-
|
|
1161
|
-
if (file_exists($archive_file)) {
|
|
1162
|
-
include $archive_file;
|
|
1163
|
-
} else {
|
|
1164
|
-
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
1165
|
-
the_archive_title('<h1 class="text-3xl font-bold mb-8">', '</h1>');
|
|
1166
|
-
if (have_posts()) {
|
|
1167
|
-
echo '<div class="space-y-8">';
|
|
1168
|
-
while (have_posts()) {
|
|
1169
|
-
the_post();
|
|
1170
|
-
echo '<article>';
|
|
1171
|
-
echo '<h2 class="text-xl font-bold"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
|
|
1172
|
-
echo '<div class="text-sm text-zinc-500 mt-1">' . get_the_date() . ' by ' . get_the_author() . '</div>';
|
|
1173
|
-
echo '<div class="mt-3 text-zinc-600">';
|
|
1174
|
-
the_excerpt();
|
|
1175
|
-
echo '</div>';
|
|
1176
|
-
echo '</article>';
|
|
1177
|
-
}
|
|
1178
|
-
echo '</div>';
|
|
1179
|
-
} else {
|
|
1180
|
-
echo '<p>No posts found.</p>';
|
|
1181
|
-
}
|
|
1182
|
-
echo '</main>';
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
get_footer();
|
|
1186
|
-
`;
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
function buildPagePhp() {
|
|
1190
|
-
return `<?php
|
|
1191
|
-
/**
|
|
1192
|
-
* Static page template — WordPress pages (e.g. About, Contact).
|
|
1193
|
-
* Reuses single.html since static pages share the same title+content structure.
|
|
1194
|
-
*
|
|
1195
|
-
* @package forgewp
|
|
1196
|
-
*/
|
|
1197
|
-
|
|
1198
|
-
get_header();
|
|
1199
|
-
|
|
1200
|
-
$page_file = get_template_directory() . '/forgewp-static/single.html';
|
|
1201
|
-
|
|
1202
|
-
if (file_exists($page_file)) {
|
|
1203
|
-
if (have_posts()) {
|
|
1204
|
-
while (have_posts()) {
|
|
1205
|
-
the_post();
|
|
1206
|
-
include $page_file;
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
} else {
|
|
1210
|
-
if (have_posts()) {
|
|
1211
|
-
while (have_posts()) {
|
|
1212
|
-
the_post();
|
|
1213
|
-
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
1214
|
-
echo '<article>';
|
|
1215
|
-
echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
|
|
1216
|
-
echo '<div class="prose prose-zinc max-w-none">';
|
|
1217
|
-
the_content();
|
|
1218
|
-
echo '</div>';
|
|
1219
|
-
echo '</article>';
|
|
1220
|
-
echo '</main>';
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
get_footer();
|
|
1226
|
-
`;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
/**
|
|
1230
|
-
* Scans the \`src/blocks/\` folder, parses block settings and JSX content,
|
|
1231
|
-
* and compiles them into official, dynamic WordPress blocks.
|
|
1232
|
-
*
|
|
1233
|
-
* @param {string} themeRoot
|
|
1234
|
-
* @param {string} outDir
|
|
1235
|
-
* @returns {string[]} Compiled block slugs
|
|
1236
|
-
*/
|
|
1237
|
-
function compileBlocks(themeRoot, outDir) {
|
|
1238
|
-
const blocksDir = path.join(themeRoot, "src", "blocks");
|
|
1239
|
-
const blockSlugs = [];
|
|
1240
|
-
|
|
1241
|
-
if (!existsSync(blocksDir)) {
|
|
1242
|
-
return blockSlugs;
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
const entries = readdirSync(blocksDir);
|
|
1246
|
-
for (const entry of entries) {
|
|
1247
|
-
const entryPath = path.join(blocksDir, entry);
|
|
1248
|
-
let blockFile = "";
|
|
1249
|
-
let blockSlug = "";
|
|
1250
|
-
|
|
1251
|
-
if (statSync(entryPath).isDirectory()) {
|
|
1252
|
-
const indexPath = path.join(entryPath, "index.tsx");
|
|
1253
|
-
if (existsSync(indexPath)) {
|
|
1254
|
-
blockFile = indexPath;
|
|
1255
|
-
blockSlug = entry.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
1256
|
-
}
|
|
1257
|
-
} else if (entry.endsWith(".tsx") || entry.endsWith(".jsx")) {
|
|
1258
|
-
blockFile = entryPath;
|
|
1259
|
-
blockSlug = entry.replace(/\.(tsx|jsx)$/, "").replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
if (blockFile) {
|
|
1263
|
-
try {
|
|
1264
|
-
const code = readFileSync(blockFile, "utf8");
|
|
1265
|
-
|
|
1266
|
-
// Parse human-readable title and metadata from setting exports
|
|
1267
|
-
const settingsMatch = code.match(/export\s+const\s+settings\s*=\s*(\{[\s\S]*?\});/);
|
|
1268
|
-
let settings = {
|
|
1269
|
-
apiVersion: 3,
|
|
1270
|
-
name: `forgewp/${blockSlug}`,
|
|
1271
|
-
title: blockSlug.split("-").map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(" "),
|
|
1272
|
-
category: "design",
|
|
1273
|
-
icon: "admin-generic",
|
|
1274
|
-
attributes: {},
|
|
1275
|
-
render: "file:./render.php"
|
|
1276
|
-
};
|
|
1277
|
-
|
|
1278
|
-
if (settingsMatch) {
|
|
1279
|
-
try {
|
|
1280
|
-
// Evaluates settings safely without external libraries
|
|
1281
|
-
const evalFn = new Function(`return ${settingsMatch[1]};`);
|
|
1282
|
-
settings = { ...settings, ...evalFn() };
|
|
1283
|
-
// Ensure schema, apiVersion, name and render path are strictly aligned
|
|
1284
|
-
settings.name = `forgewp/${blockSlug}`;
|
|
1285
|
-
settings.apiVersion = 3;
|
|
1286
|
-
settings.render = "file:./render.php";
|
|
1287
|
-
} catch (e) {
|
|
1288
|
-
console.warn(`[Gutenberg Block Compiler] Error parsing settings for ${blockSlug}:`, e.message);
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
// Parse JSX block content
|
|
1293
|
-
let jsx = "";
|
|
1294
|
-
const returnMatch = code.match(/return\s*\(\s*(<[\s\S]*?>)\s*\)/);
|
|
1295
|
-
if (returnMatch) {
|
|
1296
|
-
jsx = returnMatch[1];
|
|
1297
|
-
} else {
|
|
1298
|
-
const returnMatchSingle = code.match(/return\s+(<[\s\S]*?>);/);
|
|
1299
|
-
if (returnMatchSingle) {
|
|
1300
|
-
jsx = returnMatchSingle[1];
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
if (!jsx) {
|
|
1305
|
-
console.warn(`[Gutenberg Block Compiler] Skipping block ${blockSlug}: No returning JSX element found.`);
|
|
1306
|
-
continue;
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
// Translate dynamic attributes inside returning JSX into dynamic PHP echoes
|
|
1310
|
-
let phpMarkup = jsx;
|
|
1311
|
-
|
|
1312
|
-
// className="..." -> class="..."
|
|
1313
|
-
phpMarkup = phpMarkup.replace(/className=/g, "class=");
|
|
1314
|
-
|
|
1315
|
-
// src={image} or src={attributes.image}
|
|
1316
|
-
phpMarkup = phpMarkup.replace(/(src|href|alt|title)=\{\s*(?:attributes\.|props\.)?([a-zA-Z0-9_-]+)\s*\}/gi, (match, attr, varName) => {
|
|
1317
|
-
const escFunc = attr === "href" || attr === "src" ? "esc_url" : "esc_attr";
|
|
1318
|
-
return `${attr}="<?php echo ${escFunc}( $attributes['${varName}'] ?? '' ); ?>"`;
|
|
1319
|
-
});
|
|
1320
|
-
|
|
1321
|
-
// {title} or {props.title}
|
|
1322
|
-
phpMarkup = phpMarkup.replace(/\{\s*(?:attributes\.|props\.)?([a-zA-Z0-9_-]+)\s*\}/g, (match, varName) => {
|
|
1323
|
-
return `<?php echo esc_html( $attributes['${varName}'] ?? '' ); ?>`;
|
|
1324
|
-
});
|
|
1325
|
-
|
|
1326
|
-
// Wrap the final PHP template markup in a clean block wrapper
|
|
1327
|
-
const renderPhpContent = `<?php
|
|
1328
|
-
/**
|
|
1329
|
-
* Gutenberg dynamic block template — ${settings.title}
|
|
1330
|
-
* Autogenerated by ForgeWP Theme Compiler. Do not modify manually.
|
|
1331
|
-
*/
|
|
1332
|
-
?>
|
|
1333
|
-
${phpMarkup}
|
|
1334
|
-
`;
|
|
1335
|
-
|
|
1336
|
-
const blockOutDir = path.join(outDir, "blocks", blockSlug);
|
|
1337
|
-
mkdirSync(blockOutDir, { recursive: true });
|
|
1338
|
-
|
|
1339
|
-
// Write block.json and render.php
|
|
1340
|
-
writeFileSync(path.join(blockOutDir, "block.json"), JSON.stringify(settings, null, 2), "utf8");
|
|
1341
|
-
writeFileSync(path.join(blockOutDir, "render.php"), renderPhpContent, "utf8");
|
|
1342
|
-
|
|
1343
|
-
blockSlugs.push(settings);
|
|
1344
|
-
} catch (e) {
|
|
1345
|
-
console.error(`[Gutenberg Block Compiler] Failed to compile block ${blockSlug}:`, e.message);
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
return blockSlugs;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1
|
+
import fs, {
|
|
2
|
+
copyFileSync,
|
|
3
|
+
cpSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
statSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
} from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
14
|
+
import { scanForEditableSchemas } from './hydration-scanner.js';
|
|
15
|
+
import { loadFrameworkAdapter } from './framework-adapter.js';
|
|
16
|
+
import {
|
|
17
|
+
analyzeHydrationIslands,
|
|
18
|
+
printDiagnosticsReport,
|
|
19
|
+
} from './diagnostics.js';
|
|
20
|
+
|
|
21
|
+
// Import newly refactored modular helpers
|
|
22
|
+
import { processMarkup } from './markup-processor.js';
|
|
23
|
+
import {
|
|
24
|
+
buildStyleCss,
|
|
25
|
+
buildHeaderPhp,
|
|
26
|
+
buildFooterPhp,
|
|
27
|
+
buildIndexPhp,
|
|
28
|
+
buildSinglePhp,
|
|
29
|
+
build404Php,
|
|
30
|
+
buildArchivePhp,
|
|
31
|
+
buildPagePhp,
|
|
32
|
+
} from './php-builders.js';
|
|
33
|
+
import { buildFunctionsPhp } from './functions-builder.js';
|
|
34
|
+
import { compileBlocks } from './block-compiler.js';
|
|
35
|
+
|
|
36
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Orchestrates the theme generation pipeline.
|
|
40
|
+
* Transpiles isomorphic React components into native WordPress theme assets.
|
|
41
|
+
*
|
|
42
|
+
* @param {Object} options
|
|
43
|
+
* @param {string} options.themeRoot
|
|
44
|
+
* @param {string} options.outDir
|
|
45
|
+
* @param {import('./types.js').ForgeWPThemeConfig} options.config
|
|
46
|
+
* @param {string} options.appHtml
|
|
47
|
+
* @param {string} [options.headerHtml]
|
|
48
|
+
* @param {string} [options.footerHtml]
|
|
49
|
+
* @param {import('./types.js').ForgeWPBuildAssets} options.assets
|
|
50
|
+
*/
|
|
51
|
+
export async function generateTheme({
|
|
52
|
+
themeRoot,
|
|
53
|
+
outDir,
|
|
54
|
+
config,
|
|
55
|
+
appHtml,
|
|
56
|
+
headerHtml = '',
|
|
57
|
+
footerHtml = '',
|
|
58
|
+
headHtml = '',
|
|
59
|
+
singleHeadHtml = '',
|
|
60
|
+
singleHtml = '',
|
|
61
|
+
notFoundHtml = '',
|
|
62
|
+
archiveHtml = '',
|
|
63
|
+
assets,
|
|
64
|
+
}) {
|
|
65
|
+
if (existsSync(outDir)) {
|
|
66
|
+
rmSync(outDir, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
mkdirSync(outDir, { recursive: true });
|
|
70
|
+
|
|
71
|
+
const schemas = scanForEditableSchemas(themeRoot);
|
|
72
|
+
console.log(`[ForgeWP Compiler] Discovered colocated editable schemas for templates: ${Object.keys(schemas).join(', ') || '<none>'}`);
|
|
73
|
+
|
|
74
|
+
// Load project-specific compiler hooks if they exist in theme src
|
|
75
|
+
let projectHooks = null;
|
|
76
|
+
const hooksPath = path.join(themeRoot, 'src', 'compiler-hooks.js');
|
|
77
|
+
if (existsSync(hooksPath)) {
|
|
78
|
+
console.warn(
|
|
79
|
+
'\x1b[33m%s\x1b[0m',
|
|
80
|
+
'⚠️ [ForgeWP Deprecation Warning]: "compiler-hooks.js" is deprecated. Please migrate custom PHP logic to "src/server/*.php" files.'
|
|
81
|
+
);
|
|
82
|
+
try {
|
|
83
|
+
const fileUrl = pathToFileURL(hooksPath).href;
|
|
84
|
+
projectHooks = await import(fileUrl);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.warn('[ForgeWP Compiler] Failed to import project compiler hooks:', e.message);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Load menus configuration for auto-registration and setup
|
|
91
|
+
let menus = {};
|
|
92
|
+
const menusJsonSrc = path.join(themeRoot, 'cms', 'menus.json');
|
|
93
|
+
if (existsSync(menusJsonSrc)) {
|
|
94
|
+
try {
|
|
95
|
+
menus = JSON.parse(readFileSync(menusJsonSrc, 'utf8'));
|
|
96
|
+
} catch (e) {
|
|
97
|
+
console.warn('Failed to parse menus.json:', e.message);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Merge static menu definitions from defineTheme/wp.config.ts config.menus
|
|
102
|
+
if (config.menus) {
|
|
103
|
+
for (const [key, label] of Object.entries(config.menus)) {
|
|
104
|
+
if (!menus[key]) {
|
|
105
|
+
menus[key] = []; // Initialize menu locations for auto-registration
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Gather compiled custom page templates for auto-creation with smart slug mapping
|
|
111
|
+
const pagesToAutoCreate = [];
|
|
112
|
+
const pageTemplateSlugs = [];
|
|
113
|
+
const forgewpDir = path.join(themeRoot, '.forgewp');
|
|
114
|
+
if (existsSync(forgewpDir)) {
|
|
115
|
+
const templateFiles = readdirSync(forgewpDir);
|
|
116
|
+
for (const file of templateFiles) {
|
|
117
|
+
if (
|
|
118
|
+
file.startsWith('template-') &&
|
|
119
|
+
file.endsWith('.html') &&
|
|
120
|
+
!file.includes('-head')
|
|
121
|
+
) {
|
|
122
|
+
const slug = file.replace('.html', '');
|
|
123
|
+
const pageTemplateSlug = slug.replace('template-', '');
|
|
124
|
+
pageTemplateSlugs.push(pageTemplateSlug);
|
|
125
|
+
|
|
126
|
+
let matchedSlug = null;
|
|
127
|
+
let matchedTitle = null;
|
|
128
|
+
|
|
129
|
+
const toKebabTemplateSlug = (str) => {
|
|
130
|
+
const compName =
|
|
131
|
+
str
|
|
132
|
+
.replace(/[^a-zA-Z0-9]/g, ' ')
|
|
133
|
+
.trim()
|
|
134
|
+
.split(/\s+/)
|
|
135
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
|
136
|
+
.join('') + 'Page';
|
|
137
|
+
return compName.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const targetKebab = pageTemplateSlug;
|
|
141
|
+
|
|
142
|
+
// Search in menus to find matching target URL slugs defined by the developer
|
|
143
|
+
for (const [location, items] of Object.entries(menus)) {
|
|
144
|
+
if (!Array.isArray(items)) continue;
|
|
145
|
+
for (const item of items) {
|
|
146
|
+
if (!item.url || !item.url.startsWith('/')) continue;
|
|
147
|
+
const menuUrlSlug = item.url.replace(/^\//, '');
|
|
148
|
+
|
|
149
|
+
if (
|
|
150
|
+
toKebabTemplateSlug(item.title) === targetKebab ||
|
|
151
|
+
toKebabTemplateSlug(menuUrlSlug) === targetKebab
|
|
152
|
+
) {
|
|
153
|
+
matchedSlug = menuUrlSlug;
|
|
154
|
+
matchedTitle = item.title;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (matchedSlug) break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Fallback 1: Strip trailing "-page" from template slug
|
|
162
|
+
if (!matchedSlug) {
|
|
163
|
+
matchedSlug = pageTemplateSlug.endsWith('-page')
|
|
164
|
+
? pageTemplateSlug.slice(0, -5)
|
|
165
|
+
: pageTemplateSlug;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Fallback 2: Generate clean human-readable title
|
|
169
|
+
if (!matchedTitle) {
|
|
170
|
+
const cleanName = pageTemplateSlug.endsWith('-page')
|
|
171
|
+
? pageTemplateSlug.slice(0, -5)
|
|
172
|
+
: pageTemplateSlug;
|
|
173
|
+
matchedTitle = cleanName
|
|
174
|
+
.split('-')
|
|
175
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
176
|
+
.join(' ');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
pagesToAutoCreate.push({
|
|
180
|
+
title: matchedTitle,
|
|
181
|
+
slug: matchedSlug,
|
|
182
|
+
template: `page-${pageTemplateSlug}.php`,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const adapter = await loadFrameworkAdapter(config.frameworkAdapter);
|
|
189
|
+
const scanForHydrationIslands =
|
|
190
|
+
adapter.scanForHydrationIslands || adapter.default?.scanForHydrationIslands;
|
|
191
|
+
|
|
192
|
+
const hydrationIslands = scanForHydrationIslands
|
|
193
|
+
? scanForHydrationIslands(themeRoot)
|
|
194
|
+
: [];
|
|
195
|
+
const hasHydration = hydrationIslands.length > 0;
|
|
196
|
+
|
|
197
|
+
const assetsOut = path.join(outDir, 'assets');
|
|
198
|
+
const distAssets = path.join(themeRoot, 'dist', 'assets');
|
|
199
|
+
mkdirSync(assetsOut, { recursive: true });
|
|
200
|
+
cpSync(distAssets, assetsOut, { recursive: true });
|
|
201
|
+
|
|
202
|
+
// Copy all other files/folders from dist to outDir (excluding .vite, index.html, and assets)
|
|
203
|
+
const distDir = path.join(themeRoot, 'dist');
|
|
204
|
+
if (existsSync(distDir)) {
|
|
205
|
+
const items = readdirSync(distDir);
|
|
206
|
+
for (const item of items) {
|
|
207
|
+
if (item !== '.vite' && item !== 'index.html' && item !== 'assets') {
|
|
208
|
+
const srcPath = path.join(distDir, item);
|
|
209
|
+
const destPath = path.join(outDir, item);
|
|
210
|
+
cpSync(srcPath, destPath, { recursive: true });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let hydrationManifestJson = '{}';
|
|
216
|
+
if (hasHydration) {
|
|
217
|
+
const manifestPath = path.join(themeRoot, 'dist', '.vite', 'manifest.json');
|
|
218
|
+
let viteManifest = {};
|
|
219
|
+
if (existsSync(manifestPath)) {
|
|
220
|
+
try {
|
|
221
|
+
viteManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
222
|
+
} catch (e) {
|
|
223
|
+
console.warn('Failed to parse Vite manifest.json:', e.message);
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
console.warn(
|
|
227
|
+
'Hydration manifest not found at dist/.vite/manifest.json. Hydration asset generation may be incomplete.',
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const mapping = {};
|
|
232
|
+
let mainJsFile = '';
|
|
233
|
+
const entryChunk =
|
|
234
|
+
viteManifest['index.html'] ||
|
|
235
|
+
Object.values(viteManifest).find((c) => c.isEntry);
|
|
236
|
+
if (entryChunk) {
|
|
237
|
+
mainJsFile = entryChunk.file;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
for (const island of hydrationIslands) {
|
|
241
|
+
const pascalName = island
|
|
242
|
+
.split('-')
|
|
243
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
244
|
+
.join('');
|
|
245
|
+
|
|
246
|
+
let resolvedChunk = null;
|
|
247
|
+
for (const [key, value] of Object.entries(viteManifest)) {
|
|
248
|
+
const fileBasename = path.basename(value.file || '');
|
|
249
|
+
const cleanName = fileBasename.replace(/-[A-Za-z0-9_-]+\.js$/, '');
|
|
250
|
+
if (
|
|
251
|
+
key.endsWith(`/${pascalName}.tsx`) ||
|
|
252
|
+
key.endsWith(`/${pascalName}.ts`) ||
|
|
253
|
+
key.endsWith(`/${island}.tsx`) ||
|
|
254
|
+
key.endsWith(`/${island}.ts`) ||
|
|
255
|
+
cleanName === island ||
|
|
256
|
+
cleanName === pascalName.toLowerCase()
|
|
257
|
+
) {
|
|
258
|
+
resolvedChunk = value.file;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (resolvedChunk) {
|
|
264
|
+
mapping[island] = resolvedChunk;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (!mainJsFile) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
'Hydration generation failed: could not resolve the React runtime entry chunk. Ensure Vite emitted a valid manifest and the theme entry is present.',
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const missingIslands = hydrationIslands.filter(
|
|
275
|
+
(island) => !(island in mapping),
|
|
276
|
+
);
|
|
277
|
+
if (missingIslands.length > 0) {
|
|
278
|
+
throw new Error(
|
|
279
|
+
`Hydration generation failed: missing compiled chunk for island(s): ${missingIslands.join(', ')}. ` +
|
|
280
|
+
'Verify the Hydrate component children and the corresponding Vite input files.',
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const hydratorScript = `(function () {
|
|
285
|
+
const config = window.forgeWpHydration || { themeUri: "", manifest: {} };
|
|
286
|
+
const islands = document.querySelectorAll("[data-forgewp-hydrate]");
|
|
287
|
+
|
|
288
|
+
const observer = new IntersectionObserver((entries) => {
|
|
289
|
+
entries.forEach((entry) => {
|
|
290
|
+
if (entry.isIntersecting) {
|
|
291
|
+
const hydrate = entry.target.__forgewpHydrate;
|
|
292
|
+
if (typeof hydrate === "function") hydrate();
|
|
293
|
+
observer.unobserve(entry.target);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}, { rootMargin: "200px" });
|
|
297
|
+
|
|
298
|
+
// Predictive preloading observer with larger viewport margin (600px)
|
|
299
|
+
const preloadObserver = new IntersectionObserver((entries) => {
|
|
300
|
+
entries.forEach((entry) => {
|
|
301
|
+
if (entry.isIntersecting) {
|
|
302
|
+
const el = entry.target;
|
|
303
|
+
preloadElement(el);
|
|
304
|
+
preloadObserver.unobserve(el);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}, { rootMargin: "600px" });
|
|
308
|
+
|
|
309
|
+
const StrategyRegistry = {
|
|
310
|
+
load: (el, hydrate) => {
|
|
311
|
+
if (document.readyState === "complete") {
|
|
312
|
+
hydrate();
|
|
313
|
+
} else {
|
|
314
|
+
window.addEventListener("load", hydrate);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
visible: (el, hydrate) => {
|
|
318
|
+
el.__forgewpHydrate = hydrate;
|
|
319
|
+
observer.observe(el);
|
|
320
|
+
},
|
|
321
|
+
interaction: (el, hydrate) => {
|
|
322
|
+
const run = () => {
|
|
323
|
+
hydrate();
|
|
324
|
+
el.removeEventListener("click", run);
|
|
325
|
+
el.removeEventListener("mouseenter", run);
|
|
326
|
+
el.removeEventListener("focusin", run);
|
|
327
|
+
};
|
|
328
|
+
el.addEventListener("click", run);
|
|
329
|
+
el.addEventListener("mouseenter", run);
|
|
330
|
+
el.addEventListener("focusin", run);
|
|
331
|
+
},
|
|
332
|
+
click: (el, hydrate) => {
|
|
333
|
+
const run = () => {
|
|
334
|
+
hydrate();
|
|
335
|
+
el.removeEventListener("click", run);
|
|
336
|
+
};
|
|
337
|
+
el.addEventListener("click", run);
|
|
338
|
+
},
|
|
339
|
+
hover: (el, hydrate) => {
|
|
340
|
+
const run = () => {
|
|
341
|
+
hydrate();
|
|
342
|
+
el.removeEventListener("mouseenter", run);
|
|
343
|
+
};
|
|
344
|
+
el.addEventListener("mouseenter", run);
|
|
345
|
+
},
|
|
346
|
+
idle: (el, hydrate) => {
|
|
347
|
+
if ("requestIdleCallback" in window) {
|
|
348
|
+
window.requestIdleCallback(hydrate);
|
|
349
|
+
} else {
|
|
350
|
+
setTimeout(hydrate, 200);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
islands.forEach((el) => {
|
|
356
|
+
const islandName = el.getAttribute("data-forgewp-hydrate");
|
|
357
|
+
|
|
358
|
+
// 1. Network-Aware Check: Restrict/skip hydration on slow 2G/3G connections if requested
|
|
359
|
+
const connection = el.getAttribute("data-forgewp-connection");
|
|
360
|
+
if (connection === "fast") {
|
|
361
|
+
const conn = navigator.connection;
|
|
362
|
+
if (conn && (conn.saveData || /2g|3g/.test(conn.effectiveType))) {
|
|
363
|
+
console.warn("[ForgeWP Hydrator] Deferring hydration of island '" + islandName + "' due to slow 2G/3G network conditions.");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// 2. Predictive Preloading Setup
|
|
369
|
+
const preload = el.getAttribute("data-forgewp-preload");
|
|
370
|
+
if (preload === "near-visible") {
|
|
371
|
+
preloadObserver.observe(el);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const runHydration = () => hydrateElement(el);
|
|
375
|
+
|
|
376
|
+
// 3. Media-Query Check: Gated by target device dimensions
|
|
377
|
+
const media = el.getAttribute("data-forgewp-media");
|
|
378
|
+
if (media) {
|
|
379
|
+
const mql = window.matchMedia(media);
|
|
380
|
+
const setupMediaHydration = () => {
|
|
381
|
+
const trigger = el.getAttribute("data-forgewp-trigger") || "visible";
|
|
382
|
+
const strategy = StrategyRegistry[trigger];
|
|
383
|
+
if (strategy) {
|
|
384
|
+
strategy(el, runHydration);
|
|
385
|
+
} else {
|
|
386
|
+
StrategyRegistry.visible(el, runHydration);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
if (mql.matches) {
|
|
391
|
+
setupMediaHydration();
|
|
392
|
+
} else {
|
|
393
|
+
const listener = (e) => {
|
|
394
|
+
if (e.matches) {
|
|
395
|
+
setupMediaHydration();
|
|
396
|
+
mql.removeEventListener("change", listener);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
mql.addEventListener("change", listener);
|
|
400
|
+
}
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Standard trigger registration
|
|
405
|
+
const trigger = el.getAttribute("data-forgewp-trigger") || "visible";
|
|
406
|
+
const strategy = StrategyRegistry[trigger];
|
|
407
|
+
if (strategy) {
|
|
408
|
+
strategy(el, runHydration);
|
|
409
|
+
} else {
|
|
410
|
+
StrategyRegistry.visible(el, runHydration);
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
function preloadElement(el) {
|
|
415
|
+
const islandName = el.getAttribute("data-forgewp-hydrate");
|
|
416
|
+
const chunkPath = config.manifest?.[islandName];
|
|
417
|
+
if (!chunkPath) return;
|
|
418
|
+
const scriptUrl = config.themeUri + "/assets/" + chunkPath.replace("assets/", "").replace("assets\\\\", "");
|
|
419
|
+
|
|
420
|
+
// Inject link[rel=modulepreload]
|
|
421
|
+
if (document.querySelector("link[href='" + scriptUrl + "']")) return;
|
|
422
|
+
const link = document.createElement("link");
|
|
423
|
+
link.rel = "modulepreload";
|
|
424
|
+
link.href = scriptUrl;
|
|
425
|
+
document.head.appendChild(link);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function hydrateElement(el) {
|
|
429
|
+
const islandName = el.getAttribute("data-forgewp-hydrate");
|
|
430
|
+
if (!islandName) {
|
|
431
|
+
console.error("[ForgeWP Hydrator] Missing data-forgewp-hydrate attribute on hydration boundary.");
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const rawProps = el.getAttribute("data-forgewp-props") || "{}";
|
|
436
|
+
let props = {};
|
|
437
|
+
try {
|
|
438
|
+
props = JSON.parse(rawProps);
|
|
439
|
+
} catch (err) {
|
|
440
|
+
console.error("[ForgeWP Hydrator] Failed to parse props for island " + islandName + ":", err);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const chunkPath = config.manifest?.[islandName];
|
|
444
|
+
if (!chunkPath) {
|
|
445
|
+
const available = config.manifest ? Object.keys(config.manifest).join(", ") : "<none>";
|
|
446
|
+
console.error(
|
|
447
|
+
"[ForgeWP Hydrator] Could not find compiled chunk for island " + islandName + ". " +
|
|
448
|
+
"Available manifest keys: " + available
|
|
449
|
+
);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const scriptUrl = config.themeUri + "/assets/" + chunkPath.replace("assets/", "").replace("assets\\\\", "");
|
|
454
|
+
|
|
455
|
+
import(scriptUrl)
|
|
456
|
+
.then((module) => {
|
|
457
|
+
let Component = module.default;
|
|
458
|
+
if (!Component) {
|
|
459
|
+
Component = Object.values(module).find((val) => typeof val === "function");
|
|
460
|
+
if (!Component) {
|
|
461
|
+
Component = Object.values(module)[0];
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (typeof Component !== "function") {
|
|
465
|
+
const exportsList = Object.keys(module).join(", ");
|
|
466
|
+
console.error(
|
|
467
|
+
"[ForgeWP Hydrator] Chunk for " + islandName + " does not export a valid React component. " +
|
|
468
|
+
"Available exports: " + exportsList
|
|
469
|
+
);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Resolve ReactDOM/React — prefer window globals set by main.tsx.
|
|
474
|
+
// Always use createRoot (not hydrateRoot): island chunks bundle their
|
|
475
|
+
// own React via Vite code-splitting, so hydrateRoot from window.ReactDOM
|
|
476
|
+
// (a different instance) causes a silent Fiber reconciler failure.
|
|
477
|
+
// createRoot takes full ownership of the container, bypassing this issue.
|
|
478
|
+
const ReactDOM = window.ReactDOM;
|
|
479
|
+
const React = window.React;
|
|
480
|
+
|
|
481
|
+
if (ReactDOM && React) {
|
|
482
|
+
const root = ReactDOM.createRoot(el);
|
|
483
|
+
root.render(React.createElement(Component, props));
|
|
484
|
+
} else {
|
|
485
|
+
console.error("[ForgeWP Hydration Error] React or ReactDOM not found on window. Ensure main.tsx exposes window.React and window.ReactDOM.");
|
|
486
|
+
}
|
|
487
|
+
})
|
|
488
|
+
.catch((err) => {
|
|
489
|
+
console.error("[ForgeWP Hydrator] Failed to load chunk for " + islandName + ":", err);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
})();`;
|
|
493
|
+
|
|
494
|
+
writeFileSync(
|
|
495
|
+
path.join(assetsOut, 'forgewp-hydrator.js'),
|
|
496
|
+
hydratorScript,
|
|
497
|
+
'utf8',
|
|
498
|
+
);
|
|
499
|
+
hydrationManifestJson = JSON.stringify({
|
|
500
|
+
mainJsFile,
|
|
501
|
+
mapping,
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// Run compiler diagnostics & output detailed metrics
|
|
505
|
+
const analysis = analyzeHydrationIslands(themeRoot, mapping);
|
|
506
|
+
printDiagnosticsReport(analysis);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// Drop unused JS from the theme ZIP
|
|
510
|
+
const files = readdirSync(assetsOut);
|
|
511
|
+
for (const file of files) {
|
|
512
|
+
if (
|
|
513
|
+
(file.endsWith('.js') || file.endsWith('.js.map')) &&
|
|
514
|
+
file !== 'forgewp-editor.js' &&
|
|
515
|
+
file !== 'forgewp-hydrator.js'
|
|
516
|
+
) {
|
|
517
|
+
if (!hasHydration) {
|
|
518
|
+
rmSync(path.join(assetsOut, file), { force: true });
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Scan all page templates for translations before processMarkup replaces them
|
|
524
|
+
const i18nKeys = new Set();
|
|
525
|
+
const scanForI18nKeys = (content) => {
|
|
526
|
+
if (!content) return;
|
|
527
|
+
const regex = /__FORGEWP_I18N_([^_](?:[^_]|_(?!_))*?)__/g;
|
|
528
|
+
let match;
|
|
529
|
+
while ((match = regex.exec(content)) !== null) {
|
|
530
|
+
const clean = match[1]
|
|
531
|
+
.replace(/&/g, '&')
|
|
532
|
+
.replace(/"/g, '"')
|
|
533
|
+
.replace(/'/g, "'")
|
|
534
|
+
.replace(/'/g, "'")
|
|
535
|
+
.replace(/</g, '<')
|
|
536
|
+
.replace(/>/g, '>');
|
|
537
|
+
i18nKeys.add(clean);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
scanForI18nKeys(appHtml);
|
|
542
|
+
scanForI18nKeys(headerHtml);
|
|
543
|
+
scanForI18nKeys(footerHtml);
|
|
544
|
+
scanForI18nKeys(singleHtml);
|
|
545
|
+
scanForI18nKeys(notFoundHtml);
|
|
546
|
+
scanForI18nKeys(archiveHtml);
|
|
547
|
+
|
|
548
|
+
if (existsSync(forgewpDir)) {
|
|
549
|
+
const templateFiles = readdirSync(forgewpDir);
|
|
550
|
+
for (const file of templateFiles) {
|
|
551
|
+
if (file.endsWith('.html')) {
|
|
552
|
+
const rawHtml = readFileSync(path.join(forgewpDir, file), 'utf8');
|
|
553
|
+
scanForI18nKeys(rawHtml);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// Load and merge keys from cms/translations.json
|
|
559
|
+
const translationsFileSrc = path.join(themeRoot, 'cms', 'translations.json');
|
|
560
|
+
if (existsSync(translationsFileSrc)) {
|
|
561
|
+
try {
|
|
562
|
+
const transData = JSON.parse(readFileSync(translationsFileSrc, 'utf8'));
|
|
563
|
+
for (const locale of Object.keys(transData)) {
|
|
564
|
+
if (transData[locale] && typeof transData[locale] === 'object') {
|
|
565
|
+
for (const key of Object.keys(transData[locale])) {
|
|
566
|
+
i18nKeys.add(key);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
} catch (e) {
|
|
571
|
+
// Ignore parse/read errors during build time
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Fix nav links and split markup
|
|
576
|
+
const processedApp = processMarkup(appHtml, config.textDomain);
|
|
577
|
+
const processedHeader = processMarkup(headerHtml, config.textDomain);
|
|
578
|
+
const processedFooter = processMarkup(footerHtml, config.textDomain);
|
|
579
|
+
|
|
580
|
+
// Extract content (App markup minus Header/Footer)
|
|
581
|
+
let contentHtml = processedApp;
|
|
582
|
+
if (processedHeader) {
|
|
583
|
+
const replaced = contentHtml.replace(processedHeader, '');
|
|
584
|
+
contentHtml = replaced !== contentHtml ? replaced : contentHtml.replace(/<header\b[^>]*>([\s\S]*?)<\/header>/i, '');
|
|
585
|
+
}
|
|
586
|
+
if (processedFooter) {
|
|
587
|
+
const replaced = contentHtml.replace(processedFooter, '');
|
|
588
|
+
contentHtml = replaced !== contentHtml ? replaced : contentHtml.replace(/<footer\b[^>]*>([\s\S]*?)<\/footer>/i, '');
|
|
589
|
+
}
|
|
590
|
+
contentHtml = contentHtml.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
591
|
+
|
|
592
|
+
// Process single post template if exists
|
|
593
|
+
let processedSingle = '';
|
|
594
|
+
if (singleHtml) {
|
|
595
|
+
processedSingle = processMarkup(singleHtml, config.textDomain);
|
|
596
|
+
if (processedHeader) {
|
|
597
|
+
const replaced = processedSingle.replace(processedHeader, '');
|
|
598
|
+
processedSingle = replaced !== processedSingle ? replaced : processedSingle.replace(/<header\b[^>]*>([\s\S]*?)<\/header>/i, '');
|
|
599
|
+
}
|
|
600
|
+
if (processedFooter) {
|
|
601
|
+
const replaced = processedSingle.replace(processedFooter, '');
|
|
602
|
+
processedSingle = replaced !== processedSingle ? replaced : processedSingle.replace(/<footer\b[^>]*>([\s\S]*?)<\/footer>/i, '');
|
|
603
|
+
}
|
|
604
|
+
processedSingle = processedSingle.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Process 404 template if exists
|
|
608
|
+
let processedNotFound = '';
|
|
609
|
+
if (notFoundHtml) {
|
|
610
|
+
processedNotFound = processMarkup(notFoundHtml, config.textDomain);
|
|
611
|
+
if (processedHeader) {
|
|
612
|
+
const replaced = processedNotFound.replace(processedHeader, '');
|
|
613
|
+
processedNotFound = replaced !== processedNotFound ? replaced : processedNotFound.replace(/<header\b[^>]*>([\s\S]*?)<\/header>/i, '');
|
|
614
|
+
}
|
|
615
|
+
if (processedFooter) {
|
|
616
|
+
const replaced = processedNotFound.replace(processedFooter, '');
|
|
617
|
+
processedNotFound = replaced !== processedNotFound ? replaced : processedNotFound.replace(/<footer\b[^>]*>([\s\S]*?)<\/footer>/i, '');
|
|
618
|
+
}
|
|
619
|
+
processedNotFound = processedNotFound.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const staticDir = path.join(outDir, 'forgewp-static');
|
|
623
|
+
mkdirSync(staticDir, { recursive: true });
|
|
624
|
+
writeFileSync(path.join(staticDir, 'content.html'), contentHtml, 'utf8');
|
|
625
|
+
writeFileSync(path.join(staticDir, 'header.html'), processedHeader, 'utf8');
|
|
626
|
+
writeFileSync(path.join(staticDir, 'footer.html'), processedFooter, 'utf8');
|
|
627
|
+
if (headHtml) {
|
|
628
|
+
writeFileSync(path.join(staticDir, 'head.html'), headHtml, 'utf8');
|
|
629
|
+
}
|
|
630
|
+
if (singleHeadHtml) {
|
|
631
|
+
writeFileSync(
|
|
632
|
+
path.join(staticDir, 'single-head.html'),
|
|
633
|
+
singleHeadHtml,
|
|
634
|
+
'utf8',
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
if (processedSingle) {
|
|
638
|
+
writeFileSync(path.join(staticDir, 'single.html'), processedSingle, 'utf8');
|
|
639
|
+
}
|
|
640
|
+
if (processedNotFound) {
|
|
641
|
+
writeFileSync(path.join(staticDir, '404.html'), processedNotFound, 'utf8');
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Archive page (category / tag / date archives)
|
|
645
|
+
let processedArchive = '';
|
|
646
|
+
if (archiveHtml) {
|
|
647
|
+
processedArchive = processMarkup(archiveHtml, config.textDomain);
|
|
648
|
+
if (processedHeader) {
|
|
649
|
+
const replaced = processedArchive.replace(processedHeader, '');
|
|
650
|
+
processedArchive = replaced !== processedArchive ? replaced : processedArchive.replace(/<header\b[^>]*>([\s\S]*?)<\/header>/i, '');
|
|
651
|
+
}
|
|
652
|
+
if (processedFooter) {
|
|
653
|
+
const replaced = processedArchive.replace(processedFooter, '');
|
|
654
|
+
processedArchive = replaced !== processedArchive ? replaced : processedArchive.replace(/<footer\b[^>]*>([\s\S]*?)<\/footer>/i, '');
|
|
655
|
+
}
|
|
656
|
+
processedArchive = processedArchive.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
657
|
+
writeFileSync(
|
|
658
|
+
path.join(staticDir, 'archive.html'),
|
|
659
|
+
processedArchive,
|
|
660
|
+
'utf8',
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// Dynamic Gutenberg blocks compilation (Phase 5)
|
|
665
|
+
const compiledBlocks = compileBlocks(themeRoot, outDir);
|
|
666
|
+
|
|
667
|
+
const editorScriptContent = `
|
|
668
|
+
const { registerBlockType } = wp.blocks;
|
|
669
|
+
const { createElement } = wp.element;
|
|
670
|
+
const { InspectorControls, useBlockProps } = wp.blockEditor;
|
|
671
|
+
const { PanelBody, TextControl } = wp.components;
|
|
672
|
+
const ServerSideRender = wp.serverSideRender;
|
|
673
|
+
|
|
674
|
+
if (window.forgeWpBlocks) {
|
|
675
|
+
window.forgeWpBlocks.forEach(block => {
|
|
676
|
+
registerBlockType(block.name, {
|
|
677
|
+
title: block.title,
|
|
678
|
+
icon: block.icon,
|
|
679
|
+
category: block.category,
|
|
680
|
+
attributes: block.attributes,
|
|
681
|
+
edit: function(props) {
|
|
682
|
+
const { attributes, setAttributes } = props;
|
|
683
|
+
const blockProps = useBlockProps();
|
|
684
|
+
|
|
685
|
+
if (block.customEditJsx) {
|
|
686
|
+
try {
|
|
687
|
+
const renderFn = new Function('props', 'createElement', 'useBlockProps', 'attributes', 'setAttributes', 'blockProps',
|
|
688
|
+
'return ' + block.customEditJsx
|
|
689
|
+
);
|
|
690
|
+
return renderFn(props, createElement, useBlockProps, attributes, setAttributes, blockProps);
|
|
691
|
+
} catch (e) {
|
|
692
|
+
console.error("[ForgeWP Editor] Custom edit render failed for block " + block.name + ":", e);
|
|
693
|
+
return createElement('div', blockProps, 'Render Error: ' + e.message);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// Build inspector controls dynamically from attributes
|
|
698
|
+
const controls = Object.keys(block.attributes).map(key => {
|
|
699
|
+
return createElement(TextControl, {
|
|
700
|
+
label: key.charAt(0).toUpperCase() + key.slice(1),
|
|
701
|
+
value: attributes[key],
|
|
702
|
+
onChange: (val) => setAttributes({ [key]: val })
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
return createElement('div', blockProps,
|
|
707
|
+
createElement(InspectorControls, null,
|
|
708
|
+
createElement(PanelBody, { title: 'Block Settings', initialOpen: true }, controls)
|
|
709
|
+
),
|
|
710
|
+
createElement(ServerSideRender, {
|
|
711
|
+
block: block.name,
|
|
712
|
+
attributes: attributes
|
|
713
|
+
})
|
|
714
|
+
);
|
|
715
|
+
},
|
|
716
|
+
save: function() {
|
|
717
|
+
return null; // Dynamic blocks return null in save
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
`;
|
|
723
|
+
writeFileSync(
|
|
724
|
+
path.join(outDir, 'assets', 'forgewp-editor.js'),
|
|
725
|
+
editorScriptContent,
|
|
726
|
+
'utf8',
|
|
727
|
+
);
|
|
728
|
+
|
|
729
|
+
writeFileSync(path.join(outDir, 'style.css'), buildStyleCss(config), 'utf8');
|
|
730
|
+
|
|
731
|
+
let hydrationData = null;
|
|
732
|
+
if (hasHydration) {
|
|
733
|
+
try {
|
|
734
|
+
hydrationData = JSON.parse(hydrationManifestJson);
|
|
735
|
+
} catch {}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
let functionsPhpContent = buildFunctionsPhp(
|
|
739
|
+
config,
|
|
740
|
+
assets,
|
|
741
|
+
compiledBlocks,
|
|
742
|
+
themeRoot,
|
|
743
|
+
pagesToAutoCreate,
|
|
744
|
+
menus,
|
|
745
|
+
hydrationData,
|
|
746
|
+
Array.from(i18nKeys),
|
|
747
|
+
schemas,
|
|
748
|
+
);
|
|
749
|
+
|
|
750
|
+
if (projectHooks && typeof projectHooks.processFunctionsPhp === 'function') {
|
|
751
|
+
functionsPhpContent = projectHooks.processFunctionsPhp(functionsPhpContent, config);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// Execute plugin functions.php transformation hooks
|
|
755
|
+
if (config.plugins && Array.isArray(config.plugins)) {
|
|
756
|
+
for (const plugin of config.plugins) {
|
|
757
|
+
if (typeof plugin.transformFunctionsPhp === 'function') {
|
|
758
|
+
functionsPhpContent = plugin.transformFunctionsPhp(functionsPhpContent, config, themeRoot, { fs, path });
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// Append custom PHP server escape hatch files from src/server/*.php
|
|
764
|
+
const serverDir = path.join(themeRoot, 'src', 'server');
|
|
765
|
+
if (existsSync(serverDir)) {
|
|
766
|
+
const phpFiles = readdirSync(serverDir)
|
|
767
|
+
.filter((file) => file.endsWith('.php'))
|
|
768
|
+
.sort();
|
|
769
|
+
if (phpFiles.length > 0) {
|
|
770
|
+
let serverPhpContent = '\n\n/**\n * ── PHP Server Escape Hatch (src/server/) ──\n */';
|
|
771
|
+
for (const file of phpFiles) {
|
|
772
|
+
const filePath = path.join(serverDir, file);
|
|
773
|
+
let content = readFileSync(filePath, 'utf8');
|
|
774
|
+
// Clean leading and trailing php tags safely
|
|
775
|
+
content = content
|
|
776
|
+
.replace(/^<\?php\s*/i, '')
|
|
777
|
+
.replace(/^<\?\s*/i, '')
|
|
778
|
+
.replace(/\s*\?>\s*$/i, '');
|
|
779
|
+
serverPhpContent += `\n\n/**\n * Source: src/server/${file}\n */\n${content.trim()}`;
|
|
780
|
+
}
|
|
781
|
+
functionsPhpContent += serverPhpContent + '\n';
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
writeFileSync(
|
|
786
|
+
path.join(outDir, 'functions.php'),
|
|
787
|
+
functionsPhpContent,
|
|
788
|
+
'utf8',
|
|
789
|
+
);
|
|
790
|
+
|
|
791
|
+
// Copy translations.json directly if it exists in the project cms/ folder
|
|
792
|
+
const translationsSrc = path.join(themeRoot, 'cms', 'translations.json');
|
|
793
|
+
if (existsSync(translationsSrc)) {
|
|
794
|
+
copyFileSync(translationsSrc, path.join(outDir, 'translations.json'));
|
|
795
|
+
}
|
|
796
|
+
writeFileSync(
|
|
797
|
+
path.join(outDir, 'header.php'),
|
|
798
|
+
buildHeaderPhp(config),
|
|
799
|
+
'utf8',
|
|
800
|
+
);
|
|
801
|
+
writeFileSync(
|
|
802
|
+
path.join(outDir, 'footer.php'),
|
|
803
|
+
buildFooterPhp(config),
|
|
804
|
+
'utf8',
|
|
805
|
+
);
|
|
806
|
+
writeFileSync(path.join(outDir, 'index.php'), buildIndexPhp(), 'utf8');
|
|
807
|
+
writeFileSync(path.join(outDir, 'single.php'), buildSinglePhp(), 'utf8');
|
|
808
|
+
writeFileSync(path.join(outDir, '404.php'), build404Php(), 'utf8');
|
|
809
|
+
writeFileSync(path.join(outDir, 'front-page.php'), buildIndexPhp(), 'utf8');
|
|
810
|
+
writeFileSync(path.join(outDir, 'archive.php'), buildArchivePhp(), 'utf8');
|
|
811
|
+
writeFileSync(path.join(outDir, 'page.php'), buildPagePhp(), 'utf8');
|
|
812
|
+
|
|
813
|
+
// Dynamic Custom WP hierarchy templates compiler (single-*, taxonomy-*, archive-*, etc.)
|
|
814
|
+
if (existsSync(forgewpDir)) {
|
|
815
|
+
const templateFiles = readdirSync(forgewpDir);
|
|
816
|
+
for (const file of templateFiles) {
|
|
817
|
+
const name = file.replace('.html', '');
|
|
818
|
+
const isHierarchyTemplate =
|
|
819
|
+
(name.startsWith('single-') ||
|
|
820
|
+
name.startsWith('archive-') ||
|
|
821
|
+
name.startsWith('taxonomy-') ||
|
|
822
|
+
name === 'taxonomy') &&
|
|
823
|
+
file.endsWith('.html') &&
|
|
824
|
+
!file.includes('-head');
|
|
825
|
+
|
|
826
|
+
if (isHierarchyTemplate) {
|
|
827
|
+
const rawHtml = readFileSync(path.join(forgewpDir, file), 'utf8');
|
|
828
|
+
let processedHtml = processMarkup(rawHtml, config.textDomain);
|
|
829
|
+
if (processedHeader) {
|
|
830
|
+
const replaced = processedHtml.replace(processedHeader, '');
|
|
831
|
+
processedHtml = replaced !== processedHtml ? replaced : processedHtml.replace(/<header\b[^>]*>([\s\S]*?)<\/header>/i, '');
|
|
832
|
+
}
|
|
833
|
+
if (processedFooter) {
|
|
834
|
+
const replaced = processedHtml.replace(processedFooter, '');
|
|
835
|
+
processedHtml = replaced !== processedHtml ? replaced : processedHtml.replace(/<footer\b[^>]*>([\s\S]*?)<\/footer>/i, '');
|
|
836
|
+
}
|
|
837
|
+
processedHtml = processedHtml.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
838
|
+
|
|
839
|
+
writeFileSync(path.join(staticDir, file), processedHtml, 'utf8');
|
|
840
|
+
|
|
841
|
+
const headFile = file.replace('.html', '-head.html');
|
|
842
|
+
if (existsSync(path.join(forgewpDir, headFile))) {
|
|
843
|
+
writeFileSync(
|
|
844
|
+
path.join(staticDir, headFile),
|
|
845
|
+
readFileSync(path.join(forgewpDir, headFile), 'utf8'),
|
|
846
|
+
'utf8',
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
const phpLoop = name.startsWith('single-')
|
|
851
|
+
? ` if (have_posts()) {
|
|
852
|
+
the_post();
|
|
853
|
+
include $markup_file;
|
|
854
|
+
} else {
|
|
855
|
+
include $markup_file;
|
|
856
|
+
}`
|
|
857
|
+
: ` if (have_posts()) {
|
|
858
|
+
while (have_posts()) {
|
|
859
|
+
the_post();
|
|
860
|
+
include $markup_file;
|
|
861
|
+
}
|
|
862
|
+
} else {
|
|
863
|
+
include $markup_file;
|
|
864
|
+
}`;
|
|
865
|
+
|
|
866
|
+
const phpContent = `<?php
|
|
867
|
+
/**
|
|
868
|
+
* Dynamic ${name} template
|
|
869
|
+
*
|
|
870
|
+
* @package ${config.textDomain}
|
|
871
|
+
*/
|
|
872
|
+
|
|
873
|
+
get_header();
|
|
874
|
+
|
|
875
|
+
$markup_file = get_template_directory() . '/forgewp-static/${file}';
|
|
876
|
+
if (file_exists($markup_file)) {
|
|
877
|
+
${phpLoop}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
get_footer();
|
|
881
|
+
`;
|
|
882
|
+
writeFileSync(path.join(outDir, `${name}.php`), phpContent, 'utf8');
|
|
883
|
+
console.warn(`[ForgeWP Compiler] Wrote dynamic WP template ${name}.php`);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// Dynamic Custom Page Templates Compiler
|
|
889
|
+
if (existsSync(forgewpDir)) {
|
|
890
|
+
const templateFiles = readdirSync(forgewpDir);
|
|
891
|
+
for (const file of templateFiles) {
|
|
892
|
+
if (
|
|
893
|
+
file.startsWith('template-') &&
|
|
894
|
+
file.endsWith('.html') &&
|
|
895
|
+
!file.includes('-head')
|
|
896
|
+
) {
|
|
897
|
+
const slug = file.replace('.html', '');
|
|
898
|
+
const rawHtml = readFileSync(path.join(forgewpDir, file), 'utf8');
|
|
899
|
+
|
|
900
|
+
let processedHtml = processMarkup(rawHtml, config.textDomain);
|
|
901
|
+
if (processedHeader) {
|
|
902
|
+
const replaced = processedHtml.replace(processedHeader, '');
|
|
903
|
+
processedHtml = replaced !== processedHtml ? replaced : processedHtml.replace(/<header\b[^>]*>([\s\S]*?)<\/header>/i, '');
|
|
904
|
+
}
|
|
905
|
+
if (processedFooter) {
|
|
906
|
+
const replaced = processedHtml.replace(processedFooter, '');
|
|
907
|
+
processedHtml = replaced !== processedHtml ? replaced : processedHtml.replace(/<footer\b[^>]*>([\s\S]*?)<\/footer>/i, '');
|
|
908
|
+
}
|
|
909
|
+
processedHtml = processedHtml.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
910
|
+
|
|
911
|
+
if (projectHooks && typeof projectHooks.processTemplateMarkup === 'function') {
|
|
912
|
+
processedHtml = projectHooks.processTemplateMarkup(slug, processedHtml, config);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
writeFileSync(path.join(staticDir, file), processedHtml, 'utf8');
|
|
916
|
+
|
|
917
|
+
const headFile = file.replace('.html', '-head.html');
|
|
918
|
+
if (existsSync(path.join(forgewpDir, headFile))) {
|
|
919
|
+
writeFileSync(
|
|
920
|
+
path.join(staticDir, headFile),
|
|
921
|
+
readFileSync(path.join(forgewpDir, headFile), 'utf8'),
|
|
922
|
+
'utf8',
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// Generate the native WordPress PHP Custom Page Template
|
|
927
|
+
const templateName = slug
|
|
928
|
+
.replace('template-', '')
|
|
929
|
+
.split('-')
|
|
930
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
931
|
+
.join(' ');
|
|
932
|
+
const phpContent = `<?php
|
|
933
|
+
/**
|
|
934
|
+
* Template Name: ${templateName}
|
|
935
|
+
*
|
|
936
|
+
* @package ${config.textDomain}
|
|
937
|
+
*/
|
|
938
|
+
|
|
939
|
+
get_header();
|
|
940
|
+
|
|
941
|
+
$markup_file = get_template_directory() . '/forgewp-static/${file}';
|
|
942
|
+
if (file_exists($markup_file)) {
|
|
943
|
+
include $markup_file;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
get_footer();
|
|
947
|
+
`;
|
|
948
|
+
writeFileSync(
|
|
949
|
+
path.join(outDir, `page-${slug.replace('template-', '')}.php`),
|
|
950
|
+
phpContent,
|
|
951
|
+
'utf8',
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// Dynamic theme.json compiler (Phase 5)
|
|
958
|
+
const themeJsonSrc = path.join(themeRoot, 'cms', 'theme.json');
|
|
959
|
+
let themeJson = {
|
|
960
|
+
$schema: 'https://schemas.wp.org/trunk/theme.json',
|
|
961
|
+
version: 3,
|
|
962
|
+
settings: {
|
|
963
|
+
appearanceTools: true,
|
|
964
|
+
},
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
if (existsSync(themeJsonSrc)) {
|
|
968
|
+
try {
|
|
969
|
+
themeJson = JSON.parse(readFileSync(themeJsonSrc, 'utf8'));
|
|
970
|
+
} catch (e) {
|
|
971
|
+
console.warn('Failed to parse theme.json template:', e.message);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// Merge tokens from wp.config.ts
|
|
976
|
+
if (config.settings) {
|
|
977
|
+
if (!themeJson.settings) themeJson.settings = {};
|
|
978
|
+
|
|
979
|
+
// Layout (contentSize, wideSize)
|
|
980
|
+
if (config.settings.layout) {
|
|
981
|
+
themeJson.settings.layout = {
|
|
982
|
+
...themeJson.settings.layout,
|
|
983
|
+
...config.settings.layout,
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// Colors (custom, palette)
|
|
988
|
+
if (config.settings.color) {
|
|
989
|
+
themeJson.settings.color = {
|
|
990
|
+
...themeJson.settings.color,
|
|
991
|
+
...config.settings.color,
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// Typography (fontSizes, fontFamilies)
|
|
996
|
+
if (config.settings.typography) {
|
|
997
|
+
themeJson.settings.typography = {
|
|
998
|
+
...themeJson.settings.typography,
|
|
999
|
+
...config.settings.typography,
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
writeFileSync(
|
|
1005
|
+
path.join(outDir, 'theme.json'),
|
|
1006
|
+
JSON.stringify(themeJson, null, 2),
|
|
1007
|
+
'utf8',
|
|
1008
|
+
);
|
|
1009
|
+
|
|
1010
|
+
const screenshot = path.join(themeRoot, 'cms', 'screenshot.png');
|
|
1011
|
+
if (existsSync(screenshot)) {
|
|
1012
|
+
copyFileSync(screenshot, path.join(outDir, 'screenshot.png'));
|
|
1013
|
+
} else {
|
|
1014
|
+
const fallbackScreenshot = path.join(__dirname, 'screenshot-fallback.png');
|
|
1015
|
+
if (existsSync(fallbackScreenshot)) {
|
|
1016
|
+
copyFileSync(fallbackScreenshot, path.join(outDir, 'screenshot.png'));
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|