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