@forgewp/compiler 0.4.2 → 0.4.4

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 (144) hide show
  1. package/README.md +70 -3
  2. package/bin/add.js +30 -15
  3. package/bin/analyze.js +66 -1
  4. package/bin/cli.js +149 -70
  5. package/bin/doctor.js +21 -12
  6. package/bin/export.js +69 -20
  7. package/bin/fresh.js +6 -1
  8. package/bin/i18n-extract.js +3 -10
  9. package/bin/i18n-translate.js +15 -24
  10. package/bin/make-block.js +24 -0
  11. package/bin/make-editable.js +166 -0
  12. package/bin/make-form.js +131 -0
  13. package/bin/make-island.js +11 -0
  14. package/bin/make-loop.js +147 -0
  15. package/bin/make-mail.js +27 -0
  16. package/bin/make-page.js +83 -0
  17. package/bin/make-post-type.js +68 -29
  18. package/bin/make-sandbox.js +609 -0
  19. package/bin/make-section.js +221 -0
  20. package/bin/make-shell.js +375 -0
  21. package/bin/repair.js +14 -26
  22. package/bin/seed.js +119 -0
  23. package/bin/sync-routes.js +107 -85
  24. package/lib/adapters/html-adapter.js +13 -3
  25. package/lib/adapters/stub-adapter.js +10 -2
  26. package/lib/add-component.js +153 -92
  27. package/lib/asset-loader.js +333 -1
  28. package/lib/assets/asset-graph.js +432 -0
  29. package/lib/assets/asset-pipeline.js +125 -0
  30. package/lib/assets/diagnostics-report.js +345 -0
  31. package/lib/assets/external-fetcher.js +173 -0
  32. package/lib/assets/font-orchestrator.js +348 -0
  33. package/lib/assets/font-usage-scanner.js +242 -0
  34. package/lib/assets/image-optimizer.js +229 -0
  35. package/lib/assets/index.js +51 -0
  36. package/lib/assets/preload-generator.js +70 -0
  37. package/lib/assets/public-url.js +153 -0
  38. package/lib/block-authoring-help.js +11 -0
  39. package/lib/blocks/ast-parser.js +67 -0
  40. package/lib/blocks/discover-blocks.js +146 -0
  41. package/lib/blocks/editor-scope.js +733 -0
  42. package/lib/blocks/editor-transpiler.js +1229 -0
  43. package/lib/blocks/index.js +2838 -0
  44. package/lib/blocks/php-transpiler.js +4928 -0
  45. package/lib/blocks/scanner.js +1487 -0
  46. package/lib/blocks/shared-utils.js +290 -0
  47. package/lib/blocks/source-sanitize.js +1449 -0
  48. package/lib/blueprints.js +77 -5
  49. package/lib/build-assets.js +38 -33
  50. package/lib/collect-page-template-routes.js +102 -0
  51. package/lib/collect-static-routes.js +175 -0
  52. package/lib/diagnostics.js +58 -33
  53. package/lib/export-theme.js +84 -5
  54. package/lib/extract-template-content.js +90 -0
  55. package/lib/forms-preview.js +42 -0
  56. package/lib/functions/cpt-routing.js +69 -0
  57. package/lib/functions/forms.js +2461 -0
  58. package/lib/functions/hydration-enqueuer.js +400 -0
  59. package/lib/functions/index.js +1623 -0
  60. package/lib/functions/load-menus.js +112 -0
  61. package/lib/functions/load-translations.js +148 -0
  62. package/lib/functions/rest-endpoints.js +2923 -0
  63. package/lib/functions/routing.js +765 -0
  64. package/lib/functions/seed-mock-data.js +392 -0
  65. package/lib/functions/seed-products.js +481 -0
  66. package/lib/functions/settings-page.js +273 -0
  67. package/lib/functions/theme-setup.js +494 -0
  68. package/lib/generate-theme.js +2076 -303
  69. package/lib/hydration/editable-schemas.js +332 -0
  70. package/lib/hydration/enter-hidden-initial.js +65 -0
  71. package/lib/hydration/form-schemas.js +227 -0
  72. package/lib/hydration/index.js +12 -0
  73. package/lib/hydration/is-interactive.js +951 -0
  74. package/lib/hydration/island-split.js +1231 -0
  75. package/lib/hydration/islands-scanner.js +599 -0
  76. package/lib/hydration/resolve-island-chunk.js +103 -0
  77. package/lib/hydration/resolve-island-component.js +52 -0
  78. package/lib/hydration/rollup-inputs.js +81 -0
  79. package/lib/hydration/root-class-extractor.js +220 -0
  80. package/lib/hydration/scan-app-providers.js +154 -0
  81. package/lib/hydration/static-lint.js +382 -0
  82. package/lib/hydration/transform.js +257 -0
  83. package/lib/hydration/uses-block-area.js +49 -0
  84. package/lib/hydration/utils.js +119 -0
  85. package/lib/i18n/translation-cache.js +141 -0
  86. package/lib/icon-registry.js +72 -0
  87. package/lib/index.d.ts +324 -8
  88. package/lib/index.js +3 -2
  89. package/lib/load-config.js +338 -144
  90. package/lib/mail-templates.js +37 -0
  91. package/lib/markup-processor.js +483 -92
  92. package/lib/node-runtime.js +7 -0
  93. package/lib/page-config-plugin.js +84 -0
  94. package/lib/php-builders.js +383 -42
  95. package/lib/react-adapter.js +1053 -246
  96. package/lib/registration-metadata.js +11 -0
  97. package/lib/render-theme.mts +1410 -543
  98. package/lib/route-layout.js +76 -0
  99. package/lib/template-discovery.js +58 -0
  100. package/lib/theme-compatibility.js +32 -0
  101. package/lib/validate-export.js +51 -2
  102. package/lib/validate.js +27 -5
  103. package/lib/virtual-plugin.js +319 -0
  104. package/lib/walkthrough.md +26 -0
  105. package/package.json +17 -5
  106. package/templates/PresetsStyle.tsx +1 -1
  107. package/templates/auth/cms/email-logs.json +9 -0
  108. package/templates/auth/cms/menus.json +11 -0
  109. package/templates/auth/cms/mock-data.json +123 -0
  110. package/templates/auth/cms/roles.json +7 -0
  111. package/templates/auth/cms/sessions.json +1 -0
  112. package/templates/auth/cms/site-settings.json +28 -0
  113. package/templates/auth/cms/translations.json +4 -0
  114. package/templates/auth/cms/users.json +46 -0
  115. package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
  116. package/templates/auth/components/forgot-password-form-wrapper.tsx +141 -0
  117. package/templates/auth/components/login-form-wrapper.tsx +300 -0
  118. package/templates/auth/components/reset-password-form-wrapper.tsx +190 -0
  119. package/templates/auth/components/signup-form-wrapper.tsx +257 -0
  120. package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
  121. package/templates/auth/pages/DashboardPage.tsx +12 -0
  122. package/templates/auth/pages/ForgotPasswordPage.tsx +11 -0
  123. package/templates/auth/pages/LoginPage.tsx +11 -0
  124. package/templates/auth/pages/ResetPasswordPage.tsx +11 -0
  125. package/templates/auth/pages/SignUpPage.tsx +11 -0
  126. package/templates/auth/pages/VerifyEmailPage.tsx +11 -0
  127. package/templates/auth/ui/button.tsx +57 -0
  128. package/templates/auth/ui/card.tsx +76 -0
  129. package/templates/auth/ui/field.tsx +242 -0
  130. package/templates/auth/ui/input.tsx +22 -0
  131. package/templates/auth/ui/label.tsx +24 -0
  132. package/templates/auth/ui/separator.tsx +31 -0
  133. package/templates/forgewp-config.ts +70 -3
  134. package/templates/menus.json +12 -10
  135. package/templates/mock-data.json +122 -433
  136. package/templates/products.json +5 -0
  137. package/templates/roles.json +7 -0
  138. package/templates/sessions.json +1 -0
  139. package/templates/users.json +38 -0
  140. package/templates/wordpress.tsx +1835 -1297
  141. package/bin/make-template.js +0 -145
  142. package/lib/block-compiler.js +0 -552
  143. package/lib/functions-builder.js +0 -2044
  144. package/lib/hydration-scanner.js +0 -821
@@ -0,0 +1,609 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from "node:fs";
4
+ import path from "node:path";
5
+ import pc from "picocolors";
6
+ import { spawnSync } from "node:child_process";
7
+ import readline from "node:readline";
8
+ import { fileURLToPath } from "node:url";
9
+ import { addComponent } from "../lib/add-component.js";
10
+
11
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
+
13
+ const args = process.argv.slice(2);
14
+ const type = args[0];
15
+
16
+ if (!type || (type !== "ecommerce" && type !== "auth")) {
17
+ console.error(pc.red(`\nāŒ Error: Please specify sandbox type: "ecommerce" or "auth"`));
18
+ console.log(` Usage: pnpm forgewp make:sandbox <ecommerce|auth>\n`);
19
+ process.exit(1);
20
+ }
21
+
22
+ const projectRoot = process.cwd();
23
+ const wpDir = path.join(projectRoot, "cms");
24
+
25
+ // Ensure cms directory exists
26
+ if (!wpDir) {
27
+ // satisfied compiler check
28
+ }
29
+ if (!existsSync(wpDir)) {
30
+ mkdirSync(wpDir, { recursive: true });
31
+ }
32
+
33
+ if (type === "ecommerce") {
34
+ const packageJsonPath = path.join(projectRoot, "package.json");
35
+ let packageJson = {};
36
+ if (existsSync(packageJsonPath)) {
37
+ try {
38
+ packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
39
+ } catch (e) {}
40
+ }
41
+
42
+ const dependencies = packageJson.dependencies || {};
43
+ const devDependencies = packageJson.devDependencies || {};
44
+ const hasWooDependency = dependencies["@forgewp/woocommerce"] || devDependencies["@forgewp/woocommerce"];
45
+
46
+ if (!hasWooDependency) {
47
+ console.log(pc.yellow(`\nā„¹ļø To seed an e-commerce sandbox, the "@forgewp/woocommerce" package is required.`));
48
+
49
+ const rl = readline.createInterface({
50
+ input: process.stdin,
51
+ output: process.stdout
52
+ });
53
+
54
+ rl.question(`\n Would you like to install "@forgewp/woocommerce" and configure e-commerce support? (y/N): `, (answer) => {
55
+ rl.close();
56
+ const confirmed = answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes";
57
+ if (!confirmed) {
58
+ console.log(pc.red(`\nāŒ Aborted: E-commerce sandbox requires "@forgewp/woocommerce" dependency.\n`));
59
+ process.exit(1);
60
+ }
61
+
62
+ // 1. Add dependency to package.json
63
+ const isWorkspace = existsSync(path.join(projectRoot, "..", "..", "pnpm-workspace.yaml")) || existsSync(path.join(projectRoot, "..", "pnpm-workspace.yaml"));
64
+ const versionToUse = isWorkspace ? "workspace:*" : "^0.1.1";
65
+
66
+ if (!packageJson.dependencies) {
67
+ packageJson.dependencies = {};
68
+ }
69
+ packageJson.dependencies["@forgewp/woocommerce"] = versionToUse;
70
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf8");
71
+ console.log(pc.green(` āœ… Added "@forgewp/woocommerce": "${versionToUse}" to package.json`));
72
+
73
+ // 2. Detect package manager and install
74
+ let packageManager = "npm";
75
+ if (existsSync(path.join(projectRoot, "pnpm-lock.yaml")) || existsSync(path.join(projectRoot, "..", "pnpm-lock.yaml"))) {
76
+ packageManager = "pnpm";
77
+ } else if (existsSync(path.join(projectRoot, "yarn.lock"))) {
78
+ packageManager = "yarn";
79
+ } else if (existsSync(path.join(projectRoot, "bun.lockb"))) {
80
+ packageManager = "bun";
81
+ }
82
+
83
+ console.log(pc.cyan(` šŸ“¦ Installing dependencies using ${packageManager}...`));
84
+
85
+ const spawnResult = spawnSync(packageManager, ["install"], {
86
+ stdio: "inherit",
87
+ shell: process.platform === "win32"
88
+ });
89
+
90
+ if (spawnResult.status !== 0) {
91
+ console.error(pc.red(`\nāŒ Error: Failed to run "${packageManager} install". Please run it manually.`));
92
+ process.exit(1);
93
+ }
94
+
95
+ console.log(pc.green(` āœ… Package installation complete.`));
96
+
97
+ // 3. Run repair / blueprint healing silently to make sure wordpress.tsx and products.json are written
98
+ console.log(pc.cyan(` šŸ”§ Configuring system blueprints and updating wordpress.tsx...`));
99
+
100
+ const repairScript = path.join(__dirname, "repair.js");
101
+ const repairResult = spawnSync("node", [repairScript], {
102
+ stdio: "ignore",
103
+ shell: process.platform === "win32"
104
+ });
105
+
106
+ if (repairResult.status !== 0) {
107
+ console.error(pc.red(`\nāŒ Error: Failed to repair system blueprints.`));
108
+ process.exit(1);
109
+ }
110
+
111
+ console.log(pc.green(` āœ… Blueprints healed successfully.`));
112
+
113
+ // Proceed to seed
114
+ seedEcommerceData();
115
+ });
116
+ } else {
117
+ // Proceed to seed directly
118
+ seedEcommerceData();
119
+ }
120
+ }
121
+
122
+ function seedEcommerceData() {
123
+ const productsTsPath = path.join(wpDir, "products.ts");
124
+ if (existsSync(productsTsPath)) {
125
+ console.warn(pc.yellow(`\nāš ļø E-Commerce mock data already exists in cms/products.ts.`));
126
+ console.log(` You can open the file directly to view or edit existing mock products.\n`);
127
+ return;
128
+ }
129
+
130
+ const productsPath = path.join(wpDir, "products.json");
131
+ let productsData = {
132
+ "product": [],
133
+ "_taxonomy_product_cat": [],
134
+ "_taxonomy_product_tag": []
135
+ };
136
+
137
+ if (existsSync(productsPath)) {
138
+ try {
139
+ productsData = JSON.parse(readFileSync(productsPath, "utf8"));
140
+ } catch (err) {
141
+ console.error(pc.red(`\nāŒ Error: Failed to parse cms/products.json. Overwriting with clean structure.`));
142
+ productsData = {
143
+ "product": [],
144
+ "_taxonomy_product_cat": [],
145
+ "_taxonomy_product_tag": []
146
+ };
147
+ }
148
+ }
149
+
150
+ if (productsData["product"] && productsData["product"].length > 0) {
151
+ console.warn(pc.yellow(`\nāš ļø E-Commerce mock data already exists in cms/products.json.`));
152
+ console.log(` You can open the file directly to view or edit existing mock products.\n`);
153
+ return;
154
+ }
155
+
156
+ // Seed Taxonomy Categories
157
+ const seededCategories = [
158
+ { "id": 1, "name": "Apparel", "slug": "apparel", "description": "High-contrast streetwear and caps", "count": 2, "meta": {} },
159
+ { "id": 2, "name": "Brutalist Design", "slug": "brutalist", "description": "Raw concrete design prints and books", "count": 2, "meta": {} },
160
+ { "id": 3, "name": "Digital Art", "slug": "digital", "description": "Digital downloadable prints", "count": 1, "meta": {} }
161
+ ];
162
+
163
+ // Seed Taxonomy Tags
164
+ const seededTags = [
165
+ { "id": 10, "name": "Hoodie", "slug": "hoodie", "count": 1, "meta": {} },
166
+ { "id": 11, "name": "T-Shirt", "slug": "t-shirt", "count": 1, "meta": {} },
167
+ { "id": 12, "name": "Print", "slug": "print", "count": 1, "meta": {} }
168
+ ];
169
+
170
+ productsData["_taxonomy_product_cat"] = seededCategories;
171
+ productsData["_taxonomy_product_tag"] = seededTags;
172
+
173
+ productsData["product"] = [
174
+ {
175
+ "id": 101,
176
+ "type": "simple",
177
+ "title": "Minimalist Brutalist Hoodie",
178
+ "excerpt": "A heavy-weight, raw-seam hoodie featuring high-contrast brutalist typesetting.",
179
+ "content": "<p>Crafted from 450gsm organic cotton, this hoodie features zero border-radius drawcord tabs and structural double-stitch seams. Built for longevity and stark visual presence.</p>",
180
+ "price": "49.99",
181
+ "regular_price": "59.99",
182
+ "on_sale": true,
183
+ "sku": "FWP-BRUT-01",
184
+ "stock_status": "instock",
185
+ "featuredImage": "https://picsum.photos/seed/hoodie/1200/630",
186
+ "images": [
187
+ { "id": 201, "url": "https://picsum.photos/seed/hoodie-front/600/600" },
188
+ { "id": 202, "url": "https://picsum.photos/seed/hoodie-back/600/600" }
189
+ ],
190
+ "average_rating": "4.6",
191
+ "rating_count": 8,
192
+ "reviews": [
193
+ { "id": 1, "author": "Alex Reed", "content": "Heavy, stiff, perfect sharp edges. Love the brutalist look.", "rating": 5, "date": "2026-06-18" },
194
+ { "id": 2, "author": "Morgan Vance", "content": "Excellent construct. Size up for an oversized fit.", "rating": 4, "date": "2026-06-19" }
195
+ ],
196
+ "_terms": {
197
+ "product_cat": [
198
+ { "id": 1, "slug": "apparel", "name": "Apparel" }
199
+ ],
200
+ "product_tag": [
201
+ { "id": 10, "slug": "hoodie", "name": "Hoodie" }
202
+ ]
203
+ }
204
+ },
205
+ {
206
+ "id": 102,
207
+ "type": "variable",
208
+ "title": "Raw Edge Heavy Tee",
209
+ "excerpt": "A premium boxy-fit tee featuring concrete-dye coloring and flat double-hem details.",
210
+ "content": "<p>Designed as the foundational base-layer, this tee features dropped shoulders and raw-cut hem lines. dyed in industrial concrete tones.</p>",
211
+ "sku": "FWP-TEE-02",
212
+ "stock_status": "instock",
213
+ "featuredImage": "https://picsum.photos/seed/tee/1200/630",
214
+ "images": [
215
+ { "id": 203, "url": "https://picsum.photos/seed/concrete-tee/600/600" },
216
+ { "id": 204, "url": "https://picsum.photos/seed/coal-tee/600/600" }
217
+ ],
218
+ "attributes": [
219
+ { "name": "Size", "options": ["S", "M", "L"] },
220
+ { "name": "Color", "options": ["Concrete", "Coal"] }
221
+ ],
222
+ "variations": [
223
+ {
224
+ "id": 1021,
225
+ "attributes": { "Size": "S", "Color": "Concrete" },
226
+ "price": "29.99",
227
+ "regular_price": "29.99",
228
+ "stock_status": "instock",
229
+ "image": { "id": 203, "url": "https://picsum.photos/seed/concrete-tee/600/600" }
230
+ },
231
+ {
232
+ "id": 1022,
233
+ "attributes": { "Size": "M", "Color": "Concrete" },
234
+ "price": "29.99",
235
+ "regular_price": "29.99",
236
+ "stock_status": "instock",
237
+ "image": { "id": 203, "url": "https://picsum.photos/seed/concrete-tee/600/600" }
238
+ },
239
+ {
240
+ "id": 1023,
241
+ "attributes": { "Size": "L", "Color": "Concrete" },
242
+ "price": "32.99",
243
+ "regular_price": "32.99",
244
+ "stock_status": "instock",
245
+ "image": { "id": 203, "url": "https://picsum.photos/seed/concrete-tee/600/600" }
246
+ },
247
+ {
248
+ "id": 1024,
249
+ "attributes": { "Size": "S", "Color": "Coal" },
250
+ "price": "34.99",
251
+ "regular_price": "39.99",
252
+ "stock_status": "instock",
253
+ "image": { "id": 204, "url": "https://picsum.photos/seed/coal-tee/600/600" }
254
+ },
255
+ {
256
+ "id": 1025,
257
+ "attributes": { "Size": "M", "Color": "Coal" },
258
+ "price": "34.99",
259
+ "regular_price": "39.99",
260
+ "stock_status": "instock",
261
+ "image": { "id": 204, "url": "https://picsum.photos/seed/coal-tee/600/600" }
262
+ },
263
+ {
264
+ "id": 1026,
265
+ "attributes": { "Size": "L", "Color": "Coal" },
266
+ "price": "37.99",
267
+ "regular_price": "39.99",
268
+ "stock_status": "outofstock",
269
+ "image": { "id": 204, "url": "https://picsum.photos/seed/coal-tee/600/600" }
270
+ }
271
+ ],
272
+ "average_rating": "4.8",
273
+ "rating_count": 5,
274
+ "reviews": [
275
+ { "id": 3, "author": "Sam Miller", "content": "Coal color is incredibly deep. Boxy fit is perfect.", "rating": 5, "date": "2026-06-17" }
276
+ ],
277
+ "_terms": {
278
+ "product_cat": [
279
+ { "id": 1, "slug": "apparel", "name": "Apparel" }
280
+ ],
281
+ "product_tag": [
282
+ { "id": 11, "slug": "t-shirt", "name": "T-Shirt" }
283
+ ]
284
+ }
285
+ },
286
+ {
287
+ "id": 103,
288
+ "type": "grouped",
289
+ "title": "Studio Concrete Capsule Pack",
290
+ "excerpt": "A curated selection containing the Minimalist Brutalist Hoodie and the Raw Edge Heavy Tee in Concrete.",
291
+ "content": "<p>Simplify your capsule wardrobe. This pack includes both our raw-seam hoodie and dye-finished boxy tee, bundled for offline design styling.</p>",
292
+ "price": "",
293
+ "regular_price": "",
294
+ "sku": "FWP-PACK-03",
295
+ "stock_status": "instock",
296
+ "featuredImage": "https://picsum.photos/seed/pack/1200/630",
297
+ "grouped_products": [101, 102],
298
+ "average_rating": "5.0",
299
+ "rating_count": 2,
300
+ "reviews": [],
301
+ "_terms": {
302
+ "product_cat": [
303
+ { "id": 2, "slug": "brutalist", "name": "Brutalist Design" }
304
+ ]
305
+ }
306
+ },
307
+ {
308
+ "id": 104,
309
+ "type": "external",
310
+ "title": "Brutalist Typography & Layouts Book",
311
+ "excerpt": "A printed guide detailing brutalist composition, stark grids, and web typography systems.",
312
+ "content": "<p>Written by the creators of ForgeWP, this physical publication explores the visual history of high-contrast flat layout systems.</p>",
313
+ "price": "19.99",
314
+ "regular_price": "19.99",
315
+ "sku": "FWP-BOOK-04",
316
+ "stock_status": "instock",
317
+ "featuredImage": "https://picsum.photos/seed/book/1200/630",
318
+ "external_url": "https://external-publisher.com/book",
319
+ "button_text": "Purchase from Publisher",
320
+ "average_rating": "4.2",
321
+ "rating_count": 3,
322
+ "reviews": [],
323
+ "_terms": {
324
+ "product_cat": [
325
+ { "id": 2, "slug": "brutalist", "name": "Brutalist Design" }
326
+ ]
327
+ }
328
+ },
329
+ {
330
+ "id": 105,
331
+ "type": "simple",
332
+ "virtual": true,
333
+ "downloadable": true,
334
+ "title": "Brutalist Poster Art Print",
335
+ "excerpt": "High-resolution digital vector graphic poster featuring geometric layout composition.",
336
+ "content": "<p>A high-fidelity digital artwork print ready for architectural framing. Instantly delivered in vector formats.</p>",
337
+ "price": "9.99",
338
+ "regular_price": "9.99",
339
+ "sku": "FWP-POST-05",
340
+ "stock_status": "instock",
341
+ "featuredImage": "https://picsum.photos/seed/poster/1200/630",
342
+ "average_rating": "4.9",
343
+ "rating_count": 12,
344
+ "downloads": [
345
+ { "name": "High-Res PDF Vector", "url": "https://example.com/downloads/brutalist-poster.pdf" }
346
+ ],
347
+ "reviews": [],
348
+ "_terms": {
349
+ "product_cat": [
350
+ { "id": 3, "slug": "digital", "name": "Digital Art" }
351
+ ],
352
+ "product_tag": [
353
+ { "id": 12, "slug": "print", "name": "Print" }
354
+ ]
355
+ }
356
+ }
357
+ ];
358
+
359
+ writeFileSync(productsPath, JSON.stringify(productsData, null, 2), "utf8");
360
+
361
+ console.log(pc.green(`\n⚔ E-Commerce Mock Sandbox successfully created!`));
362
+ console.log(` Local DB: ${pc.cyan(`cms/products.json`)}`);
363
+ console.log(`\nšŸŽ‰ Seeded 5 standard products of different WooCommerce types:`);
364
+ console.log(` 1. ${pc.yellow("Simple Product")} (Minimalist Brutalist Hoodie)`);
365
+ console.log(` 2. ${pc.yellow("Variable Product")} (Raw Edge Heavy Tee with attributes/variations)`);
366
+ console.log(` 3. ${pc.yellow("Grouped Product")} (Studio Concrete Capsule Pack)`);
367
+ console.log(` 4. ${pc.yellow("External/Affiliate Product")} (Brutalist Typography Book)`);
368
+ console.log(` 5. ${pc.yellow("Virtual & Downloadable Product")} (Brutalist Poster Art Print)`);
369
+ }
370
+
371
+ if (type === "auth") {
372
+ const usersPath = path.join(wpDir, "users.json");
373
+ const rolesPath = path.join(wpDir, "roles.json");
374
+ const sessionsPath = path.join(wpDir, "sessions.json");
375
+ const usersTsPath = path.join(wpDir, "users.ts");
376
+ const rolesTsPath = path.join(wpDir, "roles.ts");
377
+ const hasUsers = existsSync(usersPath) || existsSync(usersTsPath);
378
+ const hasRoles = existsSync(rolesPath) || existsSync(rolesTsPath);
379
+
380
+ // 1. Seed JSON files (skip when the typed .ts source already exists)
381
+ if (!hasUsers || !hasRoles || !existsSync(sessionsPath)) {
382
+ const seededUsers = [
383
+ {
384
+ "id": 1,
385
+ "username": "admin",
386
+ "email": "admin@forgewp.local",
387
+ "displayName": "Concrete Designer",
388
+ "roles": ["administrator"],
389
+ "avatarUrl": "https://picsum.photos/seed/avatar1/150/150",
390
+ "emailVerified": true
391
+ },
392
+ {
393
+ "id": 2,
394
+ "username": "subscriber",
395
+ "email": "user@forgewp.local",
396
+ "displayName": "Sub Concrete",
397
+ "roles": ["subscriber"],
398
+ "avatarUrl": "https://picsum.photos/seed/avatar2/150/150",
399
+ "emailVerified": true
400
+ },
401
+ {
402
+ "id": 3,
403
+ "username": "editor",
404
+ "email": "editor@forgewp.local",
405
+ "displayName": "Concrete Editor",
406
+ "roles": ["editor"],
407
+ "avatarUrl": "https://picsum.photos/seed/avatar3/150/150",
408
+ "emailVerified": true
409
+ },
410
+ {
411
+ "id": 4,
412
+ "username": "customer",
413
+ "email": "customer@forgewp.local",
414
+ "displayName": "Concrete Customer",
415
+ "roles": ["customer"],
416
+ "avatarUrl": "https://picsum.photos/seed/avatar4/150/150",
417
+ "emailVerified": true
418
+ }
419
+ ];
420
+
421
+ const seededRoles = {
422
+ "administrator": ["manage_options", "edit_theme_options", "edit_posts", "edit_others_posts", "publish_posts", "read"],
423
+ "editor": ["edit_posts", "edit_others_posts", "publish_posts", "read"],
424
+ "author": ["edit_posts", "publish_posts", "read"],
425
+ "subscriber": ["read"],
426
+ "customer": ["read"]
427
+ };
428
+
429
+ const seededSessions = [];
430
+
431
+ if (!hasUsers) writeFileSync(usersPath, JSON.stringify(seededUsers, null, 2), "utf8");
432
+ if (!hasRoles) writeFileSync(rolesPath, JSON.stringify(seededRoles, null, 2), "utf8");
433
+ if (!existsSync(sessionsPath)) writeFileSync(sessionsPath, JSON.stringify(seededSessions, null, 2), "utf8");
434
+
435
+ console.log(pc.green(` āœ… Seeded authentication mock data files in cms/`));
436
+ }
437
+
438
+ // 2. Copy Pages & Components (without overwriting)
439
+ const templatesDir = path.join(__dirname, "..", "templates", "auth");
440
+ const copyIfNotExist = (src, dest) => {
441
+ if (existsSync(dest)) {
442
+ console.log(pc.yellow(` ā„¹ļø Skipping existing file: ${path.relative(projectRoot, dest)}`));
443
+ return;
444
+ }
445
+ const dir = path.dirname(dest);
446
+ if (!existsSync(dir)) {
447
+ mkdirSync(dir, { recursive: true });
448
+ }
449
+ writeFileSync(dest, readFileSync(src, 'utf8'), 'utf8');
450
+ console.log(pc.green(` āœ… Created file: ${path.relative(projectRoot, dest)}`));
451
+ };
452
+
453
+ // 2. Provision UI primitives from canonical auth templates
454
+ const uiSrcDir = path.join(templatesDir, 'ui');
455
+ const uiDestDir = path.join(projectRoot, 'src', 'components', 'ui');
456
+ if (existsSync(uiSrcDir)) {
457
+ const uiFiles = ['button.tsx', 'card.tsx', 'field.tsx', 'input.tsx', 'label.tsx', 'separator.tsx'];
458
+ for (const uiFile of uiFiles) {
459
+ const srcFile = path.join(uiSrcDir, uiFile);
460
+ if (existsSync(srcFile)) {
461
+ copyIfNotExist(srcFile, path.join(uiDestDir, uiFile));
462
+ }
463
+ }
464
+ }
465
+
466
+ // Fallback: If any required UI component is missing, pull via shadcn add
467
+ let projectStyle = "shadcn";
468
+ try {
469
+ const wpConfigPath = path.join(projectRoot, "wp.config.ts");
470
+ if (existsSync(wpConfigPath)) {
471
+ const content = readFileSync(wpConfigPath, "utf8");
472
+ const styleMatch = content.match(/style:\s*['"](forgewp|shadcn)['"]/);
473
+ if (styleMatch && styleMatch[1]) {
474
+ projectStyle = styleMatch[1];
475
+ }
476
+ }
477
+ } catch (e) {}
478
+
479
+ const requiredUi = ["card", "input", "button", "field"];
480
+ for (const uiComp of requiredUi) {
481
+ const compFile = path.join(uiDestDir, `${uiComp}.tsx`);
482
+ if (!existsSync(compFile)) {
483
+ try {
484
+ console.log(pc.cyan(` šŸ“¦ Pulling required "${uiComp}" UI component via shadcn...`));
485
+ await addComponent(uiComp, { style: projectStyle });
486
+ } catch (err) {
487
+ console.warn(pc.yellow(` ⚠ Could not auto-add "${uiComp}": ${err.message}`));
488
+ }
489
+ }
490
+ }
491
+
492
+ const componentsSrcDir = path.join(templatesDir, 'components');
493
+ const componentsDestDir = path.join(projectRoot, 'src', 'components');
494
+ if (existsSync(componentsSrcDir)) {
495
+ copyIfNotExist(path.join(componentsSrcDir, 'login-form-wrapper.tsx'), path.join(componentsDestDir, 'login-form-wrapper.tsx'));
496
+ copyIfNotExist(path.join(componentsSrcDir, 'signup-form-wrapper.tsx'), path.join(componentsDestDir, 'signup-form-wrapper.tsx'));
497
+ copyIfNotExist(path.join(componentsSrcDir, 'forgot-password-form-wrapper.tsx'), path.join(componentsDestDir, 'forgot-password-form-wrapper.tsx'));
498
+ copyIfNotExist(path.join(componentsSrcDir, 'reset-password-form-wrapper.tsx'), path.join(componentsDestDir, 'reset-password-form-wrapper.tsx'));
499
+ copyIfNotExist(path.join(componentsSrcDir, 'verify-email-view-wrapper.tsx'), path.join(componentsDestDir, 'verify-email-view-wrapper.tsx'));
500
+ copyIfNotExist(path.join(componentsSrcDir, 'dashboard-view-wrapper.tsx'), path.join(componentsDestDir, 'dashboard-view-wrapper.tsx'));
501
+ }
502
+
503
+ const pagesSrcDir = path.join(templatesDir, 'pages');
504
+ const pagesDestDir = path.join(projectRoot, 'src', 'app', 'pages');
505
+ if (existsSync(pagesSrcDir)) {
506
+ const pages = ['LoginPage.tsx', 'SignUpPage.tsx', 'VerifyEmailPage.tsx', 'ForgotPasswordPage.tsx', 'ResetPasswordPage.tsx', 'DashboardPage.tsx'];
507
+ for (const page of pages) {
508
+ copyIfNotExist(path.join(pagesSrcDir, page), path.join(pagesDestDir, page));
509
+ }
510
+ }
511
+
512
+ // 3. Inject WpAuthProvider in src/app/layout.tsx
513
+ const layoutPath = path.join(projectRoot, 'src', 'app', 'layout.tsx');
514
+ if (existsSync(layoutPath)) {
515
+ let layoutContent = readFileSync(layoutPath, 'utf8');
516
+ if (!layoutContent.includes('WpAuthProvider')) {
517
+ layoutContent = 'import { WpAuthProvider } from "@forgewp/auth";\n' + layoutContent;
518
+ // Robustly wrap JSX children with WpAuthProvider
519
+ layoutContent = layoutContent.replace(/(>\s*)\{\s*children\s*\}(\s*<)/, '$1<WpAuthProvider>{children}</WpAuthProvider>$2');
520
+ writeFileSync(layoutPath, layoutContent, 'utf8');
521
+ console.log(pc.green(` āœ… Wrapped root layout in <WpAuthProvider>`));
522
+ }
523
+ }
524
+
525
+ // 4. Register Routes in src/app/routes.tsx
526
+ const routesPath = path.join(projectRoot, 'src', 'app', 'routes.tsx');
527
+ if (existsSync(routesPath)) {
528
+ let routesContent = readFileSync(routesPath, 'utf8');
529
+ if (!routesContent.includes('/forgot-password')) {
530
+ const importBlock = `import * as LoginPage from "./pages/LoginPage";\nimport * as SignUpPage from "./pages/SignUpPage";\nimport * as VerifyEmailPage from "./pages/VerifyEmailPage";\nimport * as ForgotPasswordPage from "./pages/ForgotPasswordPage";\nimport * as ResetPasswordPage from "./pages/ResetPasswordPage";\n`;
531
+ routesContent = importBlock + routesContent;
532
+
533
+ const routesBlock = ` <Route path="/login" component={withLayout(LoginPage)} />\n <Route path="/signup" component={withLayout(SignUpPage)} />\n <Route path="/verify-email" component={withLayout(VerifyEmailPage)} />\n <Route path="/forgot-password" component={withLayout(ForgotPasswordPage)} />\n <Route path="/reset-password" component={withLayout(ResetPasswordPage)} />\n`;
534
+ if (routesContent.includes('<Route path="/query-sandbox"')) {
535
+ routesContent = routesContent.replace('<Route path="/query-sandbox"', routesBlock + ' <Route path="/query-sandbox"');
536
+ } else if (routesContent.includes('<Route path="/" component={withLayout(HomePage)} />') || routesContent.includes('<Route path="/" component={HomePage} />')) {
537
+ routesContent = routesContent.replace(/<Route path="\/" component=\{.*?\} \/>/, (match) => `${match}\n${routesBlock}`);
538
+ } else {
539
+ routesContent = routesContent.replace(/<Switch>/i, `<Switch>\n${routesBlock}`);
540
+ }
541
+ writeFileSync(routesPath, routesContent, 'utf8');
542
+ console.log(pc.green(` āœ… Registered auth routes in src/app/routes.tsx`));
543
+ }
544
+ }
545
+
546
+ // 5. Update wp.config.ts to include auth configuration block if missing
547
+ const wpConfigPath = path.join(projectRoot, 'wp.config.ts');
548
+ if (existsSync(wpConfigPath)) {
549
+ let configContent = readFileSync(wpConfigPath, 'utf8');
550
+ if (!configContent.includes('auth:')) {
551
+ const authConfigBlock = ` auth: {
552
+ loginField: 'usernameAndEmail',
553
+ defaultRole: 'subscriber',
554
+ reservedUsernames: ['admin', 'system', 'root', 'administrator'],
555
+ features: {
556
+ registration: true,
557
+ emailVerification: true,
558
+ blockLoginUntilVerified: true,
559
+ autoLoginAfterSignup: false,
560
+ },
561
+ emails: {
562
+ verification: {
563
+ subject: 'Verify your ForgeWP Account',
564
+ body: 'Welcome to ForgeWP! Click this link to verify your email address:\\n\\n{verification_url}',
565
+ },
566
+ passwordReset: {
567
+ subject: 'Password Reset Request',
568
+ body: 'Click the link below to reset your password:\\n\\n{reset_url}',
569
+ },
570
+ },
571
+ },`;
572
+
573
+ if (configContent.includes('defineConfig({')) {
574
+ configContent = configContent.replace(/(defineConfig\(\{)/, `$1\n${authConfigBlock}`);
575
+ } else if (configContent.includes('const config: ForgeWPThemeConfig = {')) {
576
+ configContent = configContent.replace(/(const config:\s*ForgeWPThemeConfig\s*=\s*\{)/, `$1\n${authConfigBlock}`);
577
+ } else {
578
+ configContent = configContent.replace(/(export default \{)/, `$1\n${authConfigBlock}`);
579
+ }
580
+ writeFileSync(wpConfigPath, configContent, 'utf8');
581
+ console.log(pc.green(` āœ… Added auth settings block to wp.config.ts`));
582
+ } else if (!configContent.includes('passwordReset:')) {
583
+ if (configContent.includes('emails: {') && configContent.includes('verification: {')) {
584
+ const passwordResetBlock = ` passwordReset: {
585
+ subject: 'Password Reset Request',
586
+ body: 'Click the link below to reset your password:\\n\\n{reset_url}',
587
+ },`;
588
+ configContent = configContent.replace(/(verification:\s*\{[^}]*\},)/, `$1\n${passwordResetBlock}`);
589
+ writeFileSync(wpConfigPath, configContent, 'utf8');
590
+ console.log(pc.green(` āœ… Added passwordReset template block to wp.config.ts`));
591
+ }
592
+ }
593
+ }
594
+
595
+ // 6. Ensure package.json has @forgewp/auth dependency and paths are set
596
+ const packageJsonPath = path.join(projectRoot, 'package.json');
597
+ if (existsSync(packageJsonPath)) {
598
+ let packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
599
+ if (!packageJson.dependencies) packageJson.dependencies = {};
600
+ if (!packageJson.dependencies['@forgewp/auth']) {
601
+ const isWorkspace = existsSync(path.join(projectRoot, '..', 'pnpm-workspace.yaml'));
602
+ packageJson.dependencies['@forgewp/auth'] = isWorkspace ? 'workspace:*' : '^0.1.2';
603
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8');
604
+ console.log(pc.green(` āœ… Added @forgewp/auth to package.json dependencies`));
605
+ }
606
+ }
607
+
608
+ console.log(pc.green(`\n⚔ Authentication Mock Sandbox successfully created!`));
609
+ }