@forgewp/compiler 0.4.1 → 0.4.3

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 (51) hide show
  1. package/README.md +11 -3
  2. package/bin/add.js +15 -6
  3. package/bin/analyze.js +66 -1
  4. package/bin/cli.js +20 -12
  5. package/bin/fresh.js +1 -1
  6. package/bin/make-block.js +11 -0
  7. package/bin/make-island.js +11 -0
  8. package/bin/{make-template.js → make-loop.js} +24 -19
  9. package/bin/make-page.js +83 -0
  10. package/bin/make-post-type.js +11 -0
  11. package/bin/make-sandbox.js +558 -0
  12. package/bin/sync-hooks.js +221 -0
  13. package/lib/adapters/html-adapter.js +8 -3
  14. package/lib/adapters/stub-adapter.js +6 -2
  15. package/lib/asset-loader.js +22 -0
  16. package/lib/blueprints.js +122 -1434
  17. package/lib/functions-builder.js +1172 -3
  18. package/lib/generate-theme.js +340 -23
  19. package/lib/hydration-scanner.js +170 -11
  20. package/lib/index.d.ts +38 -1
  21. package/lib/index.js +1 -1
  22. package/lib/load-config.js +98 -0
  23. package/lib/markup-processor.js +110 -0
  24. package/lib/page-config-plugin.js +40 -0
  25. package/lib/php-builders.js +4 -2
  26. package/lib/react-adapter.js +82 -23
  27. package/lib/render-theme.mts +115 -25
  28. package/lib/validate-export.js +49 -0
  29. package/package.json +4 -2
  30. package/templates/PresetsStyle.tsx +74 -0
  31. package/templates/SEO.tsx +109 -0
  32. package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
  33. package/templates/auth/components/forgot-password-form-wrapper.tsx +133 -0
  34. package/templates/auth/components/login-form-wrapper.tsx +203 -0
  35. package/templates/auth/components/reset-password-form-wrapper.tsx +182 -0
  36. package/templates/auth/components/signup-form-wrapper.tsx +257 -0
  37. package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
  38. package/templates/auth/pages/DashboardPage.tsx +15 -0
  39. package/templates/auth/pages/ForgotPasswordPage.tsx +14 -0
  40. package/templates/auth/pages/LoginPage.tsx +14 -0
  41. package/templates/auth/pages/ResetPasswordPage.tsx +14 -0
  42. package/templates/auth/pages/SignUpPage.tsx +14 -0
  43. package/templates/auth/pages/VerifyEmailPage.tsx +14 -0
  44. package/templates/forgewp-config.ts +110 -0
  45. package/templates/menus.json +11 -0
  46. package/templates/mock-data.json +123 -0
  47. package/templates/products.json +5 -0
  48. package/templates/roles.json +7 -0
  49. package/templates/sessions.json +1 -0
  50. package/templates/users.json +34 -0
  51. package/templates/wordpress.tsx +1390 -0
package/lib/index.d.ts CHANGED
@@ -54,6 +54,8 @@ export interface ForgeWPThemeConfig {
54
54
  textDomain: string;
55
55
  configVersion?: number;
56
56
  favicon?: string;
57
+ headerPath?: string;
58
+ footerPath?: string;
57
59
  seo?: {
58
60
  sitemaps?: ForgeWpSeoSitemapsConfig;
59
61
  plugins?: {
@@ -63,6 +65,31 @@ export interface ForgeWPThemeConfig {
63
65
  };
64
66
  frameworkAdapter?: 'react' | 'html' | 'stub';
65
67
  style?: 'forgewp' | 'shadcn';
68
+ headless?: {
69
+ apiUrl?: string;
70
+ jwtAuth?: boolean;
71
+ };
72
+ auth?: {
73
+ loginField?: 'usernameOnly' | 'emailOnly' | 'usernameAndEmail';
74
+ defaultRole?: string;
75
+ reservedUsernames?: string[];
76
+ features?: {
77
+ registration?: boolean;
78
+ emailVerification?: boolean;
79
+ blockLoginUntilVerified?: boolean;
80
+ autoLoginAfterSignup?: boolean;
81
+ };
82
+ emails?: {
83
+ verification?: {
84
+ subject?: string;
85
+ body?: string;
86
+ };
87
+ passwordReset?: {
88
+ subject?: string;
89
+ body?: string;
90
+ };
91
+ };
92
+ };
66
93
  postTypes?: Record<string, CustomPostTypeConfig>;
67
94
  i18n?: ForgeWPI18nConfig;
68
95
  settings?: {
@@ -118,7 +145,7 @@ export interface ForgeWPFrameworkAdapter {
118
145
  pc: any;
119
146
  },
120
147
  ): Promise<void> | void;
121
- onMakeComponent?(
148
+ onMakeLoop?(
122
149
  themeRoot: string,
123
150
  options: {
124
151
  pascalCase: string;
@@ -128,6 +155,13 @@ export interface ForgeWPFrameworkAdapter {
128
155
  pc: any;
129
156
  },
130
157
  ): Promise<void> | void;
158
+ onMakePage?(
159
+ themeRoot: string,
160
+ options: {
161
+ pascalCase: string;
162
+ pc: any;
163
+ },
164
+ ): Promise<void> | void;
131
165
  onSyncRoutes?(
132
166
  themeRoot: string,
133
167
  options: {
@@ -177,3 +211,6 @@ export function resolveFrameworkAdapter(adapterName?: string): string;
177
211
  export function loadFrameworkAdapter(
178
212
  adapterName?: string,
179
213
  ): Promise<ForgeWPFrameworkAdapterModule>;
214
+
215
+ export function forgewpPageConfigPlugin(): any;
216
+
package/lib/index.js CHANGED
@@ -17,4 +17,4 @@ export {
17
17
  analyzeHydrationIslands,
18
18
  generateVisualReport,
19
19
  } from './diagnostics.js';
20
-
20
+ export { forgewpPageConfigPlugin } from './page-config-plugin.js';
@@ -56,6 +56,104 @@ export async function loadConfig(themeRoot) {
56
56
  }
57
57
  }
58
58
 
59
+ // Validate headerPath
60
+ if (config.headerPath !== undefined) {
61
+ if (typeof config.headerPath !== 'string') {
62
+ throw new Error('headerPath must be a string pointing to a header component file');
63
+ }
64
+ const absPath = path.isAbsolute(config.headerPath) ? config.headerPath : path.join(themeRoot, config.headerPath);
65
+ if (!existsSync(absPath)) {
66
+ console.warn(
67
+ '\x1b[33m%s\x1b[0m',
68
+ `⚠️ [ForgeWP Warning]: Header component file not found at "${config.headerPath}".`
69
+ );
70
+ }
71
+ }
72
+
73
+ // Validate footerPath
74
+ if (config.footerPath !== undefined) {
75
+ if (typeof config.footerPath !== 'string') {
76
+ throw new Error('footerPath must be a string pointing to a footer component file');
77
+ }
78
+ const absPath = path.isAbsolute(config.footerPath) ? config.footerPath : path.join(themeRoot, config.footerPath);
79
+ if (!existsSync(absPath)) {
80
+ console.warn(
81
+ '\x1b[33m%s\x1b[0m',
82
+ `⚠️ [ForgeWP Warning]: Footer component file not found at "${config.footerPath}".`
83
+ );
84
+ }
85
+ }
86
+
87
+ // Validate headless
88
+ if (config.headless !== undefined) {
89
+ if (typeof config.headless !== 'object' || config.headless === null) {
90
+ throw new Error('headless configuration must be an object');
91
+ }
92
+ if (config.headless.apiUrl !== undefined && typeof config.headless.apiUrl !== 'string') {
93
+ throw new Error('headless.apiUrl must be a string');
94
+ }
95
+ if (config.headless.jwtAuth !== undefined && typeof config.headless.jwtAuth !== 'boolean') {
96
+ throw new Error('headless.jwtAuth must be a boolean');
97
+ }
98
+ }
99
+
100
+ // Validate auth
101
+ if (config.auth !== undefined) {
102
+ if (typeof config.auth !== 'object' || config.auth === null) {
103
+ throw new Error('auth configuration must be an object');
104
+ }
105
+ if (
106
+ config.auth.loginField !== undefined &&
107
+ !['usernameOnly', 'emailOnly', 'usernameAndEmail'].includes(config.auth.loginField)
108
+ ) {
109
+ throw new Error('auth.loginField must be "usernameOnly", "emailOnly", or "usernameAndEmail"');
110
+ }
111
+ if (config.auth.defaultRole !== undefined && typeof config.auth.defaultRole !== 'string') {
112
+ throw new Error('auth.defaultRole must be a string');
113
+ }
114
+ if (config.auth.reservedUsernames !== undefined) {
115
+ if (!Array.isArray(config.auth.reservedUsernames) || config.auth.reservedUsernames.some((u) => typeof u !== 'string')) {
116
+ throw new Error('auth.reservedUsernames must be an array of strings');
117
+ }
118
+ }
119
+ if (config.auth.features !== undefined) {
120
+ if (typeof config.auth.features !== 'object' || config.auth.features === null) {
121
+ throw new Error('auth.features must be an object');
122
+ }
123
+ if (config.auth.features.registration !== undefined && typeof config.auth.features.registration !== 'boolean') {
124
+ throw new Error('auth.features.registration must be a boolean');
125
+ }
126
+ if (config.auth.features.emailVerification !== undefined && typeof config.auth.features.emailVerification !== 'boolean') {
127
+ throw new Error('auth.features.emailVerification must be a boolean');
128
+ }
129
+ if (config.auth.features.blockLoginUntilVerified !== undefined && typeof config.auth.features.blockLoginUntilVerified !== 'boolean') {
130
+ throw new Error('auth.features.blockLoginUntilVerified must be a boolean');
131
+ }
132
+ if (config.auth.features.autoLoginAfterSignup !== undefined && typeof config.auth.features.autoLoginAfterSignup !== 'boolean') {
133
+ throw new Error('auth.features.autoLoginAfterSignup must be a boolean');
134
+ }
135
+ if (config.auth.features.blockLoginUntilVerified === true && config.auth.features.autoLoginAfterSignup === true) {
136
+ console.warn('\x1b[33m%s\x1b[0m', '⚠️ Warning: Both blockLoginUntilVerified and autoLoginAfterSignup are set to true. Unverified users will be blocked from auto-logging in after signup.');
137
+ }
138
+ }
139
+ if (config.auth.emails !== undefined) {
140
+ if (typeof config.auth.emails !== 'object' || config.auth.emails === null) {
141
+ throw new Error('auth.emails must be an object');
142
+ }
143
+ if (config.auth.emails.verification !== undefined) {
144
+ if (typeof config.auth.emails.verification !== 'object' || config.auth.emails.verification === null) {
145
+ throw new Error('auth.emails.verification must be an object');
146
+ }
147
+ if (config.auth.emails.verification.subject !== undefined && typeof config.auth.emails.verification.subject !== 'string') {
148
+ throw new Error('auth.emails.verification.subject must be a string');
149
+ }
150
+ if (config.auth.emails.verification.body !== undefined && typeof config.auth.emails.verification.body !== 'string') {
151
+ throw new Error('auth.emails.verification.body must be a string');
152
+ }
153
+ }
154
+ }
155
+ }
156
+
59
157
  // Validate seo
60
158
  if (config.seo !== undefined) {
61
159
  if (typeof config.seo !== 'object' || config.seo === null) {
@@ -46,6 +46,11 @@ export function processMarkup(html, textDomain = 'theme') {
46
46
  '<?php echo esc_html( get_the_date() ); ?>',
47
47
  );
48
48
 
49
+ processed = processed.replace(
50
+ /__FORGEWP_THE_MODIFIED_DATE__/g,
51
+ '<?php echo esc_html( get_the_modified_date() ); ?>',
52
+ );
53
+
49
54
  processed = processed.replace(
50
55
  /__FORGEWP_THE_AUTHOR__/g,
51
56
  '<?php echo esc_html( get_the_author() ); ?>',
@@ -251,6 +256,8 @@ if (function_exists('pll_the_languages')) {
251
256
  getAttr('postsPerPage') || getAttr('postsperpage') || '10';
252
257
  const categoryName =
253
258
  getAttr('categoryName') || getAttr('categoryname') || '';
259
+ const orderby = getAttr('orderby') || '';
260
+ const order = getAttr('order') || '';
254
261
  const metaKey = getAttr('metaKey') || getAttr('metakey') || '';
255
262
  const metaValue = getAttr('metaValue') || getAttr('metavalue') || '';
256
263
  const metaCompare = getAttr('metaCompare') || getAttr('metacompare') || '=';
@@ -278,6 +285,12 @@ if (function_exists('pll_the_languages')) {
278
285
 
279
286
  let phpArgs = ` 'post_type' => '${postType}',\n 'posts_per_page' => ${postsPerPage},`;
280
287
 
288
+ if (orderby !== '') {
289
+ phpArgs += `\n 'orderby' => '${orderby}',`;
290
+ }
291
+ if (order !== '') {
292
+ phpArgs += `\n 'order' => '${order}',`;
293
+ }
281
294
  if (categoryName !== '') {
282
295
  phpArgs += `\n 'category_name' => '${categoryName}',`;
283
296
  }
@@ -419,6 +432,44 @@ ${phpArgs}
419
432
  );
420
433
  processed = processed.replace(/<\/forgewp-icon-placeholder>/g, '');
421
434
 
435
+ // ── Authentication & Capability Gates ──
436
+ processed = processed.replace(
437
+ /<forgewp-auth-gate-start\s*\/?>/g,
438
+ '<?php if ( is_user_logged_in() ) : ?>',
439
+ );
440
+ processed = processed.replace(/<\/forgewp-auth-gate-start>/g, '');
441
+
442
+ processed = processed.replace(
443
+ /<forgewp-auth-gate-fallback\s*\/?>/g,
444
+ '<?php else : ?>',
445
+ );
446
+ processed = processed.replace(/<\/forgewp-auth-gate-fallback>/g, '');
447
+
448
+ processed = processed.replace(
449
+ /<forgewp-auth-gate-end\s*\/?>/g,
450
+ '<?php endif; ?>',
451
+ );
452
+ processed = processed.replace(/<\/forgewp-auth-gate-end>/g, '');
453
+
454
+ processed = processed.replace(
455
+ /<forgewp-capability-gate-start\s+[^>]*allowed="([^"]+)"\s*\/?>/g,
456
+ "<?php if ( current_user_can( '$1' ) ) : ?>",
457
+ );
458
+ processed = processed.replace(/<\/forgewp-capability-gate-start>/g, '');
459
+
460
+ processed = processed.replace(
461
+ /<forgewp-capability-gate-fallback\s*\/?>/g,
462
+ '<?php else : ?>',
463
+ );
464
+ processed = processed.replace(/<\/forgewp-capability-gate-fallback>/g, '');
465
+
466
+ processed = processed.replace(
467
+ /<forgewp-capability-gate-end\s*\/?>/g,
468
+ '<?php endif; ?>',
469
+ );
470
+ processed = processed.replace(/<\/forgewp-capability-gate-end>/g, '');
471
+
472
+
422
473
  processed = processed.replace(
423
474
  /__FORGEWP_REPEATER_FIELD_([a-zA-Z0-9_-]+)__/g,
424
475
  (match, fieldName) => `<?php echo esc_html($row['${fieldName}']); ?>`
@@ -560,6 +611,65 @@ ${phpArgs}
560
611
  "<?php echo esc_url( get_template_directory_uri() ); ?>",
561
612
  );
562
613
 
614
+ // ── WooCommerce Product Loop Blocks ──
615
+ processed = processed.replace(
616
+ /<forgewp-product-loop-start\s+([^>]*)\/?>/g,
617
+ (match, attrsStr) => {
618
+ const getAttr = (name) => {
619
+ const regex = new RegExp(
620
+ `(?:${name}|${name.toLowerCase()})=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
621
+ 'i',
622
+ );
623
+ const m = attrsStr.match(regex);
624
+ return m ? m[1] || m[2] || m[3] || '' : '';
625
+ };
626
+
627
+ const category = getAttr('category') || '';
628
+ const limit = getAttr('limit') || '10';
629
+ const orderBy = getAttr('orderBy') || getAttr('orderby') || 'date';
630
+ const order = getAttr('order') || 'desc';
631
+ const status = getAttr('status') || 'publish';
632
+
633
+ let catQuery = '';
634
+ if (category !== '') {
635
+ catQuery = `\n 'category' => array('${category}'),`;
636
+ }
637
+
638
+ return `<?php
639
+ $query_args = array(
640
+ 'limit' => ${limit},
641
+ 'orderby' => '${orderBy}',
642
+ 'order' => '${order}',
643
+ 'status' => '${status}',${catQuery}
644
+ );
645
+ $products = wc_get_products($query_args);
646
+ foreach ($products as $product) {
647
+ global $product;
648
+ setup_postdata(get_the_ID());
649
+ ?>`;
650
+ },
651
+ );
652
+ processed = processed.replace(/<\/forgewp-product-loop-start>/g, '');
653
+ processed = processed.replace(
654
+ /<forgewp-product-loop-end\s*\/?>/g,
655
+ '<?php\n }\n wp_reset_postdata();\n ?>',
656
+ );
657
+ processed = processed.replace(/<\/forgewp-product-loop-end>/g, '');
658
+
659
+ // ── WooCommerce Dynamic Hook Replacements ──
660
+ processed = processed.replace(
661
+ /__FORGEWP_PRODUCT_PRICE__/g,
662
+ '<?php global $product; echo wp_kses_post( $product->get_price_html() ); ?>'
663
+ );
664
+ processed = processed.replace(
665
+ /__FORGEWP_PRODUCT_SKU__/g,
666
+ '<?php global $product; echo esc_html( $product->get_sku() ); ?>'
667
+ );
668
+ processed = processed.replace(
669
+ /__FORGEWP_PRODUCT_RATING__/g,
670
+ '<?php global $product; echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>'
671
+ );
672
+
563
673
  return processed;
564
674
  }
565
675
 
@@ -0,0 +1,40 @@
1
+ import path from 'node:path';
2
+
3
+ /**
4
+ * Custom Vite Plugin to statically parse "export const page = { ... }" configs in pages,
5
+ * and dynamically inject useWpPageProtect(page) hook call at component startup.
6
+ */
7
+ export function forgewpPageConfigPlugin() {
8
+ return {
9
+ name: 'forgewp-page-config',
10
+ transform(code, id) {
11
+ // Check if it's a page component inside src/app/pages/
12
+ const normalizedPath = id.replace(/\\/g, '/');
13
+ if (!normalizedPath.includes('/src/app/pages/') || !normalizedPath.endsWith('.tsx')) {
14
+ return null;
15
+ }
16
+ if (!code.includes('export const pageConfig')) {
17
+ return null;
18
+ }
19
+
20
+ // Prepend hook import
21
+ let transformed = `import { useWpPageProtect as _useWpPageProtect } from '@forgewp/auth';\n` + code;
22
+
23
+ // Match functional components
24
+ const funcRegex = /export\s+(default\s+)?function\s+([a-zA-Z0-9_$]+)\s*\(([\s\S]*?)\)\s*\{/g;
25
+ if (funcRegex.test(transformed)) {
26
+ transformed = transformed.replace(funcRegex, `export $1function $2($3) {\n _useWpPageProtect(pageConfig);`);
27
+ return { code: transformed, map: null };
28
+ }
29
+
30
+ // Match arrow function component exports
31
+ const arrowRegex = /export\s+(const|let|var)\s+([a-zA-Z0-9_$]+)(\s*:\s*[a-zA-Z0-9_$.<>]+)?\s*=\s*\(([\s\S]*?)\)\s*=>\s*\{/g;
32
+ if (arrowRegex.test(transformed)) {
33
+ transformed = transformed.replace(arrowRegex, `export $1 $2$3 = ($4) => {\n _useWpPageProtect(pageConfig);`);
34
+ return { code: transformed, map: null };
35
+ }
36
+
37
+ return null;
38
+ }
39
+ };
40
+ }
@@ -171,8 +171,10 @@ export function buildHeaderPhp(config) {
171
171
  <?php wp_head(); ?>
172
172
  <style>
173
173
  /* Reset WP link underlines to match React/Tailwind expected styling */
174
- a { text-decoration: none !important; }
175
- a:hover { text-decoration: none !important; }
174
+ a { text-decoration: none; }
175
+ a:hover { text-decoration: none; }
176
+ .underline { text-decoration: underline !important; }
177
+ .hover\\:underline:hover { text-decoration: underline !important; }
176
178
  </style>
177
179
  </head>
178
180
  <body <?php body_class(); ?>>
@@ -799,15 +799,15 @@ ${attributesRegistry}
799
799
  console.log(`\n🎉 Run ${pc.cyan('pnpm export')} to automatically register it inside your WordPress theme!\n`);
800
800
  }
801
801
 
802
- export function onMakeTemplate(themeRoot, { pascalCase, postType, customFields, automaticallySeeded, pc }) {
803
- const templatesDir = path.join(themeRoot, 'src', 'templates');
804
- if (!existsSync(templatesDir)) {
805
- mkdirSync(templatesDir, { recursive: true });
802
+ export function onMakeLoop(themeRoot, { pascalCase, postType, customFields, automaticallySeeded, pc }) {
803
+ const loopsDir = path.join(themeRoot, 'src', 'loops');
804
+ if (!existsSync(loopsDir)) {
805
+ mkdirSync(loopsDir, { recursive: true });
806
806
  }
807
807
 
808
- const targetFile = path.join(templatesDir, `${pascalCase}.tsx`);
808
+ const targetFile = path.join(loopsDir, `${pascalCase}.tsx`);
809
809
  if (existsSync(targetFile)) {
810
- console.error(pc.red(`\n❌ Error: Template "${pascalCase}.tsx" already exists at src/templates/\n`));
810
+ console.error(pc.red(`\n❌ Error: Loop "${pascalCase}.tsx" already exists at src/loops/\n`));
811
811
  process.exit(1);
812
812
  }
813
813
 
@@ -828,12 +828,12 @@ export function onMakeTemplate(themeRoot, { pascalCase, postType, customFields,
828
828
  customFieldsMarkup = `{/* No custom fields registered in mock-data.json. Add fields by running forgewp make:post-type */}\n <p className="text-xs text-zinc-500 font-mono italic">No custom fields configured for post type: ${postType}</p>`;
829
829
  }
830
830
 
831
- const templateTemplate = `import { WpQueryLoop, useWpTitle, useWpFeaturedImage, useWpExcerpt, useWpPermalink, useWpCustomField } from "@/.forgewp/wordpress";
831
+ const loopTemplate = `import { WpQueryLoop, useWpTitle, useWpFeaturedImage, useWpExcerpt, useWpPermalink, useWpCustomField } from "@/.forgewp/wordpress";
832
832
 
833
833
  /**
834
- * ⚡ ForgeWP Custom Post Type Template — "${pascalCase}"
834
+ * ⚡ ForgeWP Custom Post Type Loop — "${pascalCase}"
835
835
  *
836
- * This loop template dynamically queries and renders records of the "${postType}" post type.
836
+ * This loop dynamically queries and renders records of the "${postType}" post type.
837
837
  * In local development, the post data and custom fields are fetched dynamically from
838
838
  * your local JSON database file at: \`cms/mock-data.json\`.
839
839
  */
@@ -844,13 +844,13 @@ export default function ${pascalCase}() {
844
844
  {/* Header Banner */}
845
845
  <div className="mb-12 border border-slate-100 bg-white p-8 shadow-xl shadow-slate-100/50">
846
846
  <span className="inline-block bg-primary/5 text-primary border border-primary/10 text-xs font-mono font-bold uppercase tracking-wider px-3 py-1 mb-4">
847
- Loop Template
847
+ Post Loop
848
848
  </span>
849
849
  <h1 className="text-4xl md:text-5xl font-black uppercase tracking-tight text-slate-900">
850
850
  Latest ${postType.charAt(0).toUpperCase() + postType.slice(1)} Feed
851
851
  </h1>
852
852
  <p className="text-sm font-mono font-medium text-slate-500 mt-2">
853
- Dynamic Post-Type Template &bull; Querying: "${postType}"
853
+ Dynamic Post-Type Loop &bull; Querying: "${postType}"
854
854
  </p>
855
855
  </div>
856
856
 
@@ -886,26 +886,21 @@ export default function ${pascalCase}() {
886
886
  }
887
887
  `;
888
888
 
889
- writeFileSync(targetFile, templateTemplate, 'utf8');
889
+ writeFileSync(targetFile, loopTemplate, 'utf8');
890
890
 
891
891
  if (automaticallySeeded) {
892
892
  console.log(pc.yellow(`\n⚠️ Post type "${postType}" was missing from local database (mock-data.json).`));
893
893
  console.log(` We have automatically registered it and seeded default custom fields for you!`);
894
894
  }
895
895
 
896
- console.log(pc.green(`\n⚡ Loop Template "${pascalCase}" successfully created!`));
897
- console.log(` Location: ${pc.cyan(`src/templates/${pascalCase}.tsx`)}`);
896
+ console.log(pc.green(`\n⚡ Post Loop "${pascalCase}" successfully created!`));
897
+ console.log(` Location: ${pc.cyan(`src/loops/${pascalCase}.tsx`)}`);
898
898
  console.log(` Target Post Type: ${pc.yellow(postType)}`);
899
899
  if (customFields.length > 0) {
900
900
  console.log(` Seeded Custom Fields: ${pc.yellow(customFields.join(', '))}`);
901
901
  }
902
902
  console.log(`\n🎉 You can now import it directly inside your pages:`);
903
- console.log(` ${pc.cyan(`import ${pascalCase} from "@/templates/${pascalCase}";`)}\n`);
904
- }
905
-
906
- // Backward compatible proxy forwarding make:component parameters straight to onMakeTemplate
907
- export function onMakeComponent(themeRoot, options) {
908
- return onMakeTemplate(themeRoot, options);
903
+ console.log(` ${pc.cyan(`import ${pascalCase} from "@/loops/${pascalCase}";`)}\n`);
909
904
  }
910
905
 
911
906
  export function onMakeIsland(themeRoot, { pascalCase, pc }) {
@@ -990,6 +985,67 @@ export default function ${pascalCase}({ label = "React State Island (${pascalCas
990
985
  console.log(` ${pc.cyan(`<Hydrate trigger="visible" preload="near-visible">\n <${pascalCase} />\n </Hydrate>`)}\n`);
991
986
  }
992
987
 
988
+ export function onMakePage(themeRoot, { pascalCase, pc }) {
989
+ const pagesDir = path.join(themeRoot, 'src', 'app', 'pages');
990
+ if (!existsSync(pagesDir)) {
991
+ mkdirSync(pagesDir, { recursive: true });
992
+ }
993
+
994
+ const targetFile = path.join(pagesDir, `${pascalCase}.tsx`);
995
+ if (existsSync(targetFile)) {
996
+ console.error(pc.red(`\n❌ Error: Page Template "${pascalCase}.tsx" already exists at src/app/pages/\n`));
997
+ process.exit(1);
998
+ }
999
+
1000
+ const pageTemplate = `import { WpHead, useWpTitle, useWpExcerpt } from "../../.forgewp/wordpress";
1001
+
1002
+ /**
1003
+ * ⚡ ForgeWP Custom Page Template — "${pascalCase}"
1004
+ *
1005
+ * This file compiles into a standalone WordPress Custom Page Template.
1006
+ * You can select it in the WordPress page editor dropdown as "Template: ${pascalCase}".
1007
+ */
1008
+ export function ${pascalCase}() {
1009
+ return (
1010
+ <main className="container mx-auto px-6 py-12 font-sans text-slate-900">
1011
+ <WpHead
1012
+ title="${pascalCase}"
1013
+ description="Dynamic WordPress Custom Page Template ${pascalCase} compiled with ForgeWP."
1014
+ />
1015
+
1016
+ {/* Hero Header Area */}
1017
+ <header className="border-b border-slate-100 pb-6 mb-12">
1018
+ <span className="inline-block bg-primary/5 text-primary border border-primary/10 text-xs font-mono font-bold uppercase tracking-wider px-3 py-1 mb-4">
1019
+ Page Template
1020
+ </span>
1021
+ <h1 className="text-5xl font-black tracking-tight uppercase text-slate-900">
1022
+ {useWpTitle() || "${pascalCase}"}
1023
+ </h1>
1024
+ <p className="text-slate-500 mt-2 text-sm leading-relaxed">
1025
+ {useWpExcerpt() || "Custom page layout designed dynamically."}
1026
+ </p>
1027
+ </header>
1028
+
1029
+ {/* Page Content layout */}
1030
+ <div className="bg-white border border-slate-100 p-8 shadow-lg max-w-none prose prose-slate">
1031
+ <p className="text-slate-600 leading-relaxed">
1032
+ Welcome to your new custom page template! You can design anything here in React, using standard HTML/JSX tags and Tailwind classes.
1033
+ </p>
1034
+ </div>
1035
+ </main>
1036
+ );
1037
+ }
1038
+ `;
1039
+
1040
+ writeFileSync(targetFile, pageTemplate, 'utf8');
1041
+
1042
+ console.log(pc.green(`\n⚡ Custom Page Template "${pascalCase}" successfully created!`));
1043
+ console.log(` Location: ${pc.cyan(`src/app/pages/${pascalCase}.tsx`)}`);
1044
+ console.log(` WordPress Template Name: ${pc.yellow(pascalCase)}`);
1045
+ console.log(`\n🎉 To link it in your application routing:`);
1046
+ console.log(` Add it inside your ${pc.cyan('src/app/routes.tsx')} file.\n`);
1047
+ }
1048
+
993
1049
  export function onSyncRoutes(themeRoot, { routesToScaffold, isForce, pc }) {
994
1050
  function toPascalCase(str) {
995
1051
  return str
@@ -1021,6 +1077,9 @@ export function onSyncRoutes(themeRoot, { routesToScaffold, isForce, pc }) {
1021
1077
  *
1022
1078
  * To force reset this page back to boilerplate defaults, run:
1023
1079
  * 'pnpm forgewp sync:routes --force'
1080
+ *
1081
+ * This file compiles into a standalone WordPress Custom Page Template.
1082
+ * You can select it in the WordPress page editor dropdown as "Template: ${componentName}".
1024
1083
  */
1025
1084
  import { WpHead } from "../../.forgewp/wordpress";
1026
1085
  import { WpQueryLoop, useWpTitle, useWpExcerpt, useWpFeaturedImage } from "../../.forgewp/wordpress";
@@ -1154,7 +1213,7 @@ export function Single${pascalCpt}Page() {
1154
1213
  // In production, forgeWpHydration.post.id holds the real WP numeric ID
1155
1214
  const hydrationId =
1156
1215
  typeof window !== 'undefined'
1157
- ? (window as any).forgeWpHydration?.post?.id || 0
1216
+ ? window.forgeWpHydration?.post?.id || 0
1158
1217
  : 0;
1159
1218
  const id = hydrationId || routeParam;
1160
1219
 
@@ -1174,8 +1233,8 @@ export function Single${pascalCpt}Page() {
1174
1233
  useWpContent() || devPost?.content || "<p>Loading details...</p>";
1175
1234
  const rawImage = useWpFeaturedImage();
1176
1235
  const hydrationImage =
1177
- typeof window !== 'undefined' && !(window as any)._forgeWpCompileTime
1178
- ? (window as any).forgeWpHydration?.currentFeaturedImage || ""
1236
+ typeof window !== 'undefined' && !window._forgeWpCompileTime
1237
+ ? window.forgeWpHydration?.currentFeaturedImage || ""
1179
1238
  : "";
1180
1239
  const restImage =
1181
1240
  typeof devPost?.featuredImage === "object" && devPost?.featuredImage !== null