@forgewp/compiler 0.1.8 ā 0.2.0
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/bin/add.js +19 -1
- package/bin/cli.js +10 -0
- package/bin/fresh.js +476 -0
- package/bin/repair.js +7 -0
- package/bin/sync-routes.js +260 -0
- package/lib/add-component.js +15 -3
- package/lib/blueprints.js +501 -497
- package/lib/generate-theme.js +359 -12
- package/lib/render-static.js +4 -0
- package/lib/render-theme.mts +32 -0
- package/package.json +2 -2
package/bin/add.js
CHANGED
|
@@ -15,7 +15,25 @@ if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
|
|
21
|
+
let projectStyle = "forgewp";
|
|
22
|
+
try {
|
|
23
|
+
// Read wp.config.ts natively by regexing the 'style' property since it's a TS file
|
|
24
|
+
const wpConfigPath = path.join(process.cwd(), "wp.config.ts");
|
|
25
|
+
if (existsSync(wpConfigPath)) {
|
|
26
|
+
const content = readFileSync(wpConfigPath, "utf8");
|
|
27
|
+
const styleMatch = content.match(/style:\s*['"](forgewp|shadcn)['"]/);
|
|
28
|
+
if (styleMatch && styleMatch[1]) {
|
|
29
|
+
projectStyle = styleMatch[1];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
} catch (e) {
|
|
33
|
+
// Silent fallback
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const style = args.find(a => a.startsWith("--style="))?.split("=")[1] || projectStyle;
|
|
19
37
|
|
|
20
38
|
if (!component) {
|
|
21
39
|
console.error("Usage: forgewp add <component> [--style=forgewp|shadcn] or forgewp add --name <component>");
|
package/bin/cli.js
CHANGED
|
@@ -12,10 +12,12 @@ const subcommands = {
|
|
|
12
12
|
"make:block": path.join(__dirname, "make-block.js"),
|
|
13
13
|
"make:post-type": path.join(__dirname, "make-post-type.js"),
|
|
14
14
|
"make:component": path.join(__dirname, "make-component.js"),
|
|
15
|
+
"sync:routes": path.join(__dirname, "sync-routes.js"),
|
|
15
16
|
export: path.join(__dirname, "export.js"),
|
|
16
17
|
doctor: path.join(__dirname, "doctor.js"),
|
|
17
18
|
repair: path.join(__dirname, "repair.js"),
|
|
18
19
|
clean: path.join(__dirname, "clean.js"),
|
|
20
|
+
fresh: path.join(__dirname, "fresh.js"),
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
const args = process.argv.slice(2);
|
|
@@ -36,6 +38,10 @@ if (!targetScript) {
|
|
|
36
38
|
targetScript = subcommands["make:post-type"];
|
|
37
39
|
} else if (command === "make-component" || command === "component" || command === "make:component") {
|
|
38
40
|
targetScript = subcommands["make:component"];
|
|
41
|
+
} else if (command === "sync-routes" || command === "sync" || command === "sync:routes") {
|
|
42
|
+
targetScript = subcommands["sync:routes"];
|
|
43
|
+
} else if (command === "reset") {
|
|
44
|
+
targetScript = subcommands["fresh"];
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
|
|
@@ -69,19 +75,23 @@ function printHelp() {
|
|
|
69
75
|
${pc.cyan("make:block <Name>")} Scaffold a React Gutenberg block (e.g. HeroBlock)
|
|
70
76
|
${pc.cyan("make:post-type <slug>")} Register a custom mock post-type (e.g. portfolio)
|
|
71
77
|
${pc.cyan("make:component <Name>")} Scaffold a post-type grid loop component
|
|
78
|
+
${pc.cyan("sync:routes")} Synchronize sitemap menus with routes and scaffold pages
|
|
72
79
|
${pc.cyan("export")} Package your theme into an installable WP zip
|
|
73
80
|
${pc.cyan("doctor")} Perform diagnostic check on project health
|
|
74
81
|
${pc.cyan("repair")} Force-repair/auto-heal system internals
|
|
75
82
|
${pc.cyan("clean")} Clear all build caches and temporary artifacts
|
|
83
|
+
${pc.cyan("fresh")} Reset workspace completely to factory-clean canvas
|
|
76
84
|
|
|
77
85
|
${pc.bold("Examples:")}
|
|
78
86
|
pnpm forgewp add navbar
|
|
79
87
|
pnpm forgewp make:block HeroBlock --attributes=title,subtitle
|
|
80
88
|
pnpm forgewp make:post-type portfolio --customFields=client_name
|
|
81
89
|
pnpm forgewp make:component PortfolioGrid --postType=portfolio
|
|
90
|
+
pnpm forgewp sync:routes
|
|
82
91
|
pnpm forgewp doctor
|
|
83
92
|
pnpm forgewp repair
|
|
84
93
|
pnpm forgewp clean
|
|
94
|
+
pnpm forgewp fresh
|
|
85
95
|
pnpm forgewp export
|
|
86
96
|
`);
|
|
87
97
|
}
|
package/bin/fresh.js
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { rmSync, existsSync, writeFileSync, mkdirSync, readdirSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import readline from "node:readline";
|
|
7
|
+
import pc from "picocolors";
|
|
8
|
+
import { SYSTEM_BLUEPRINTS } from "../lib/blueprints.js";
|
|
9
|
+
|
|
10
|
+
console.log(`\nš§¹ ${pc.bold(pc.bgRed(pc.black(" FORGEWP FACTORY RESET (FRESH CANVAS) ")))}\n`);
|
|
11
|
+
|
|
12
|
+
const projectRoot = process.cwd();
|
|
13
|
+
|
|
14
|
+
function runReset() {
|
|
15
|
+
|
|
16
|
+
// 1. Clean Build Caches & Artifacts
|
|
17
|
+
const foldersToClean = [".forgewp", "dist", ".vite"];
|
|
18
|
+
for (const folder of foldersToClean) {
|
|
19
|
+
const target = path.join(projectRoot, folder);
|
|
20
|
+
if (existsSync(target)) {
|
|
21
|
+
try {
|
|
22
|
+
rmSync(target, { recursive: true, force: true });
|
|
23
|
+
console.log(` ${pc.green("ā
Cleared cache folder")}: ${pc.cyan(folder)}`);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.log(pc.red(` ā Failed to clear ${folder}: ${err.message}`));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 2. Prune Scaffolded Directories (pages, blocks, components/ui, components)
|
|
31
|
+
const directoriesToPrune = [
|
|
32
|
+
{ dir: "src/app/pages", label: "Pages (src/app/pages/)" },
|
|
33
|
+
{ dir: "src/blocks", label: "Gutenberg Blocks (src/blocks/)" },
|
|
34
|
+
{ dir: "src/components/ui", label: "UI Components (src/components/ui/)" },
|
|
35
|
+
{ dir: "src/components", label: "Components (src/components/)" }
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
for (const targetPrune of directoriesToPrune) {
|
|
39
|
+
const fullPath = path.join(projectRoot, targetPrune.dir);
|
|
40
|
+
if (existsSync(fullPath)) {
|
|
41
|
+
try {
|
|
42
|
+
rmSync(fullPath, { recursive: true, force: true });
|
|
43
|
+
console.log(` ${pc.green("ā
Removed folder")}: ${pc.cyan(targetPrune.label)}`);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.log(pc.red(` ā Failed to remove ${targetPrune.label}: ${err.message}`));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 3. Restore Standard Database & Sitemap Menus from Core Blueprints
|
|
51
|
+
const coreFilesToReset = ["wordpress/menus.json", "wordpress/mock-data.json"];
|
|
52
|
+
for (const relPath of coreFilesToReset) {
|
|
53
|
+
const fullPath = path.join(projectRoot, relPath);
|
|
54
|
+
const blueprintContent = SYSTEM_BLUEPRINTS[relPath];
|
|
55
|
+
if (blueprintContent) {
|
|
56
|
+
try {
|
|
57
|
+
const dirPath = path.dirname(fullPath);
|
|
58
|
+
if (!existsSync(dirPath)) {
|
|
59
|
+
mkdirSync(dirPath, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
writeFileSync(fullPath, blueprintContent, "utf8");
|
|
62
|
+
console.log(` ${pc.green("ā
Reset database schema")}: ${pc.cyan(relPath)}`);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.log(pc.red(` ā Failed to reset ${relPath}: ${err.message}`));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 4. Restore Pristine App Routes (src/app/routes.tsx)
|
|
70
|
+
const routesPath = path.join(projectRoot, "src/app/routes.tsx");
|
|
71
|
+
const routesContent = `import { Route, Switch } from "wouter";
|
|
72
|
+
import HomePage from "./page";
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Local Developer Routes ā ForgeWP.
|
|
76
|
+
*
|
|
77
|
+
* Edit this file to add new routes/components for your local Vite preview server.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* // 1. Create a component in src/app/about.tsx
|
|
81
|
+
* // 2. Import it here: import AboutPage from "./about";
|
|
82
|
+
* // 3. Add the Route: <Route path="/about" component={AboutPage} />
|
|
83
|
+
*/
|
|
84
|
+
export default function AppRoutes() {
|
|
85
|
+
return (
|
|
86
|
+
<Switch>
|
|
87
|
+
{/* Home preview */}
|
|
88
|
+
<Route path="/" component={HomePage} />
|
|
89
|
+
|
|
90
|
+
{/* Fallback route */}
|
|
91
|
+
<Route>
|
|
92
|
+
<div className="flex min-h-[60vh] flex-col items-center justify-center text-center p-6">
|
|
93
|
+
<h1 className="text-4xl font-bold font-serif text-zinc-950">404</h1>
|
|
94
|
+
<p className="mt-2 text-zinc-600">Page not found locally.</p>
|
|
95
|
+
<a href="/" className="mt-4 text-brand font-semibold hover:underline">
|
|
96
|
+
Go back home
|
|
97
|
+
</a>
|
|
98
|
+
</div>
|
|
99
|
+
</Route>
|
|
100
|
+
</Switch>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
writeFileSync(routesPath, routesContent, "utf8");
|
|
107
|
+
console.log(` ${pc.green("ā
Reset routes definition")}: src/app/routes.tsx`);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
console.log(pc.red(` ā Failed to reset src/app/routes.tsx: ${err.message}`));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 5. Restore Pristine Home Page (src/app/page.tsx)
|
|
113
|
+
const pagePath = path.join(projectRoot, "src/app/page.tsx");
|
|
114
|
+
const pageContent = `import { SEO } from "../.forgewp/SEO";
|
|
115
|
+
import wpConfig from "../../wp.config";
|
|
116
|
+
import { useWpCustomField, WpMenu, WpQueryLoop } from "../.forgewp/wordpress";
|
|
117
|
+
|
|
118
|
+
export default function HomePage() {
|
|
119
|
+
const colors = wpConfig.settings?.color?.palette || [];
|
|
120
|
+
const fontFamilies = wpConfig.settings?.typography?.fontFamilies || [];
|
|
121
|
+
const googleFonts = wpConfig.settings?.typography?.googleFonts || [];
|
|
122
|
+
const layout = wpConfig.settings?.layout || {};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div className="min-h-screen bg-bg-light p-6 md:p-12 font-sans selection:bg-brand selection:text-white">
|
|
126
|
+
<SEO
|
|
127
|
+
title="ForgeWP Starter ā React & Tailwind CSS for WordPress"
|
|
128
|
+
description="A premium, sharp-edge developer framework for creating modern block-themes using React."
|
|
129
|
+
/>
|
|
130
|
+
|
|
131
|
+
{/* Main Container ā Sharp brutalist outer grid */}
|
|
132
|
+
<main className="mx-auto max-w-6xl border-4 border-zinc-950 bg-white shadow-[8px_8px_0px_0px_rgba(0,0,0,1)]">
|
|
133
|
+
{/* Header Grid Bar */}
|
|
134
|
+
<header className="flex flex-col sm:flex-row items-stretch border-b-4 border-zinc-950">
|
|
135
|
+
<div className="bg-brand text-white px-6 py-6 flex items-center border-b-4 sm:border-b-0 sm:border-r-4 border-zinc-950 font-black tracking-wider text-xl uppercase select-none">
|
|
136
|
+
ā” FORGEWP
|
|
137
|
+
</div>
|
|
138
|
+
<div className="flex-1 px-6 py-4 flex items-center text-xs md:text-sm font-semibold text-zinc-600 font-mono tracking-tight bg-zinc-50">
|
|
139
|
+
theme-compiler://v{wpConfig.version} // status: online
|
|
140
|
+
</div>
|
|
141
|
+
<div className="px-6 py-4 border-t-4 sm:border-t-0 sm:border-l-4 border-zinc-950 flex items-center bg-accent font-black text-sm uppercase tracking-wide text-zinc-950 select-none">
|
|
142
|
+
Developer Console
|
|
143
|
+
</div>
|
|
144
|
+
</header>
|
|
145
|
+
|
|
146
|
+
{/* Hero Section */}
|
|
147
|
+
<section className="grid md:grid-cols-12 border-b-4 border-zinc-950">
|
|
148
|
+
<div className="md:col-span-8 p-8 md:p-12 flex flex-col justify-center border-b-4 md:border-b-0 md:border-r-4 border-zinc-950">
|
|
149
|
+
<span className="inline-block bg-zinc-950 text-white text-xs font-bold font-mono tracking-widest px-3 py-1 uppercase max-w-fit mb-6 select-none">
|
|
150
|
+
v{wpConfig.version} Active
|
|
151
|
+
</span>
|
|
152
|
+
<h1 className="text-4xl md:text-6xl font-serif font-black tracking-tight leading-none text-zinc-950">
|
|
153
|
+
React structure.<br />
|
|
154
|
+
Tailwind speed.<br />
|
|
155
|
+
WordPress power.
|
|
156
|
+
</h1>
|
|
157
|
+
<p className="mt-6 text-base md:text-lg text-zinc-700 leading-relaxed font-sans font-medium max-w-xl">
|
|
158
|
+
Welcome to the next generation of WordPress theme development. Build your layout dynamically using standard React components, mock hooks, and modern utilities.
|
|
159
|
+
</p>
|
|
160
|
+
<div className="mt-8 flex flex-wrap gap-4">
|
|
161
|
+
<a
|
|
162
|
+
href="https://forgewp.dev/docs"
|
|
163
|
+
target="_blank"
|
|
164
|
+
rel="noreferrer"
|
|
165
|
+
className="group relative inline-flex items-center justify-center border-2 border-zinc-950 bg-zinc-950 text-white font-bold text-sm tracking-wider uppercase px-6 py-3 transition-colors hover:bg-brand hover:text-white"
|
|
166
|
+
>
|
|
167
|
+
Read Framework Docs
|
|
168
|
+
</a>
|
|
169
|
+
<a
|
|
170
|
+
href="#tokens"
|
|
171
|
+
className="group relative inline-flex items-center justify-center border-2 border-zinc-950 bg-white text-zinc-950 font-bold text-sm tracking-wider uppercase px-6 py-3 transition-all hover:bg-zinc-100"
|
|
172
|
+
>
|
|
173
|
+
Inspect Config Settings
|
|
174
|
+
</a>
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
{/* Quick Stats sidebar */}
|
|
179
|
+
<div className="md:col-span-4 bg-zinc-50 p-8 flex flex-col justify-between font-mono text-xs">
|
|
180
|
+
<div className="space-y-6">
|
|
181
|
+
<div className="border-b-2 border-zinc-200 pb-4">
|
|
182
|
+
<span className="block text-zinc-400 font-bold uppercase tracking-wider mb-1">Theme Name</span>
|
|
183
|
+
<span className="text-sm font-black text-zinc-900">{wpConfig.name}</span>
|
|
184
|
+
</div>
|
|
185
|
+
<div className="border-b-2 border-zinc-200 pb-4">
|
|
186
|
+
<span className="block text-zinc-400 font-bold uppercase tracking-wider mb-1">Theme Slug</span>
|
|
187
|
+
<span className="text-sm font-black text-zinc-900">{wpConfig.slug}</span>
|
|
188
|
+
</div>
|
|
189
|
+
<div className="border-b-2 border-zinc-200 pb-4">
|
|
190
|
+
<span className="block text-zinc-400 font-bold uppercase tracking-wider mb-1">Text Domain</span>
|
|
191
|
+
<span className="text-sm font-black text-zinc-900">{wpConfig.textDomain}</span>
|
|
192
|
+
</div>
|
|
193
|
+
<div>
|
|
194
|
+
<span className="block text-zinc-400 font-bold uppercase tracking-wider mb-1">PHP Engine Target</span>
|
|
195
|
+
<span className="text-sm font-black text-zinc-900">PHP 7.4+ // WP 6.0+</span>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
<div className="mt-8 border-t-2 border-zinc-950 pt-4 text-[10px] text-zinc-500 font-bold uppercase">
|
|
200
|
+
ā” Generated via @forgewp/compiler
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
</section>
|
|
204
|
+
|
|
205
|
+
{/* Dynamic Tokens Section */}
|
|
206
|
+
<section id="tokens" className="p-8 md:p-12">
|
|
207
|
+
<div className="border-2 border-zinc-950 p-6 md:p-8 bg-zinc-50">
|
|
208
|
+
<div className="flex items-center gap-3 border-b-2 border-zinc-950 pb-4 mb-8">
|
|
209
|
+
<div className="w-4 h-4 bg-secondary"></div>
|
|
210
|
+
<h2 className="text-lg md:text-xl font-bold uppercase tracking-wider text-zinc-950">
|
|
211
|
+
Design Tokens Synchronization Check
|
|
212
|
+
</h2>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<div className="grid gap-8 md:grid-cols-2 lg:grid-cols-3">
|
|
216
|
+
{/* Color Presets */}
|
|
217
|
+
<div className="border border-zinc-300 bg-white p-6 shadow-[4px_4px_0px_0px_rgba(0,0,0,1)]">
|
|
218
|
+
<h3 className="font-serif font-black text-lg text-zinc-900 mb-4 border-b border-zinc-200 pb-2 uppercase tracking-wide">
|
|
219
|
+
Color Palette
|
|
220
|
+
</h3>
|
|
221
|
+
<div className="space-y-3 font-mono text-xs">
|
|
222
|
+
{colors.map((c) => (
|
|
223
|
+
<div key={c.slug} className="flex items-center gap-3">
|
|
224
|
+
<div
|
|
225
|
+
className="w-6 h-6 border border-zinc-950"
|
|
226
|
+
style={{ backgroundColor: c.color }}
|
|
227
|
+
></div>
|
|
228
|
+
<div className="flex-1">
|
|
229
|
+
<span className="block font-black text-zinc-800">{c.name}</span>
|
|
230
|
+
<span className="text-zinc-500">{c.color} // {c.slug}</span>
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
))}
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
{/* Typography Presets */}
|
|
238
|
+
<div className="border border-zinc-300 bg-white p-6 shadow-[4px_4px_0px_0px_rgba(0,0,0,1)]">
|
|
239
|
+
<h3 className="font-serif font-black text-lg text-zinc-900 mb-4 border-b border-zinc-200 pb-2 uppercase tracking-wide">
|
|
240
|
+
Font Families
|
|
241
|
+
</h3>
|
|
242
|
+
<div className="space-y-4">
|
|
243
|
+
{fontFamilies.map((f) => (
|
|
244
|
+
<div key={f.slug} className="font-mono text-xs">
|
|
245
|
+
<span className="block font-black text-zinc-800 uppercase">{f.name}</span>
|
|
246
|
+
<span className="text-zinc-500 block mb-2">{f.fontFamily}</span>
|
|
247
|
+
<span
|
|
248
|
+
className="text-lg block font-semibold text-zinc-950 border border-zinc-200 p-2 bg-zinc-50"
|
|
249
|
+
style={{ fontFamily: f.fontFamily }}
|
|
250
|
+
>
|
|
251
|
+
The quick brown fox
|
|
252
|
+
</span>
|
|
253
|
+
</div>
|
|
254
|
+
))}
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
{/* Layout Presets */}
|
|
259
|
+
<div className="border border-zinc-300 bg-white p-6 shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] flex flex-col justify-between">
|
|
260
|
+
<div>
|
|
261
|
+
<h3 className="font-serif font-black text-lg text-zinc-900 mb-4 border-b border-zinc-200 pb-2 uppercase tracking-wide">
|
|
262
|
+
Layout Bounds
|
|
263
|
+
</h3>
|
|
264
|
+
<div className="space-y-4 font-mono text-xs">
|
|
265
|
+
<div>
|
|
266
|
+
<span className="block font-black text-zinc-800">CONTENT SIZE</span>
|
|
267
|
+
<span className="text-zinc-500 text-lg font-black">{layout.contentSize || "N/A"}</span>
|
|
268
|
+
</div>
|
|
269
|
+
<div>
|
|
270
|
+
<span className="block font-black text-zinc-800">WIDE SIZE</span>
|
|
271
|
+
<span className="text-zinc-500 text-lg font-black">{layout.wideSize || "N/A"}</span>
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
|
|
276
|
+
<div className="mt-8 border-t border-zinc-200 pt-4">
|
|
277
|
+
<span className="block font-mono text-[10px] text-zinc-400 font-bold uppercase tracking-wider mb-2">
|
|
278
|
+
Synced Google Fonts
|
|
279
|
+
</span>
|
|
280
|
+
<div className="flex flex-wrap gap-2">
|
|
281
|
+
{googleFonts.map((font) => (
|
|
282
|
+
<span
|
|
283
|
+
key={font}
|
|
284
|
+
className="inline-block bg-zinc-900 text-white text-[10px] font-mono px-2 py-1 uppercase"
|
|
285
|
+
>
|
|
286
|
+
{font.split(":")[0]}
|
|
287
|
+
</span>
|
|
288
|
+
))}
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
</div>
|
|
292
|
+
</div>
|
|
293
|
+
</div>
|
|
294
|
+
</section>
|
|
295
|
+
|
|
296
|
+
{/* WordPress Dynamic Data Layer Console Section */}
|
|
297
|
+
<section id="data-layer" className="p-8 md:p-12 border-t-4 border-zinc-950 bg-zinc-50">
|
|
298
|
+
<div className="border-2 border-zinc-950 p-6 md:p-8 bg-white shadow-[4px_4px_0px_0px_rgba(0,0,0,1)]">
|
|
299
|
+
<div className="flex items-center gap-3 border-b-2 border-zinc-950 pb-4 mb-8">
|
|
300
|
+
<div className="w-4 h-4 bg-brand"></div>
|
|
301
|
+
<h2 className="text-lg md:text-xl font-bold uppercase tracking-wider text-zinc-950">
|
|
302
|
+
WordPress Data Layer & Compiler Sandbox
|
|
303
|
+
</h2>
|
|
304
|
+
</div>
|
|
305
|
+
|
|
306
|
+
<div className="grid gap-8 lg:grid-cols-3">
|
|
307
|
+
{/* Dynamic Menus Console */}
|
|
308
|
+
<div className="border border-zinc-200 bg-zinc-50 p-6">
|
|
309
|
+
<span className="inline-block bg-zinc-950 text-white text-[9px] font-mono font-black uppercase tracking-widest px-2 py-0.5 mb-4">
|
|
310
|
+
Hook: <WpMenu>
|
|
311
|
+
</span>
|
|
312
|
+
<h3 className="font-serif font-black text-base text-zinc-900 mb-2">
|
|
313
|
+
Navigation Menu
|
|
314
|
+
</h3>
|
|
315
|
+
<p className="text-zinc-500 text-xs mb-4">
|
|
316
|
+
Compiles into dynamic WP site menus (\`wp_nav_menu\`) managed in the WP Dashboard.
|
|
317
|
+
</p>
|
|
318
|
+
<div className="border border-zinc-300 p-4 bg-white">
|
|
319
|
+
<span className="block font-mono text-[9px] text-zinc-400 font-bold uppercase tracking-wider mb-2">
|
|
320
|
+
Rendered Header Navigation:
|
|
321
|
+
</span>
|
|
322
|
+
<WpMenu
|
|
323
|
+
location="primary"
|
|
324
|
+
className="flex flex-col gap-2"
|
|
325
|
+
linkClassName="font-mono text-xs font-bold uppercase tracking-wide text-zinc-700 hover:text-brand transition-colors"
|
|
326
|
+
/>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
{/* Custom Meta Fields */}
|
|
331
|
+
<div className="border border-zinc-200 bg-zinc-50 p-6">
|
|
332
|
+
<span className="inline-block bg-zinc-950 text-white text-[9px] font-mono font-black uppercase tracking-widest px-2 py-0.5 mb-4">
|
|
333
|
+
Hook: useWpCustomField()
|
|
334
|
+
</span>
|
|
335
|
+
<h3 className="font-serif font-black text-base text-zinc-900 mb-2">
|
|
336
|
+
Metadata & Custom Fields
|
|
337
|
+
</h3>
|
|
338
|
+
<p className="text-zinc-500 text-xs mb-4">
|
|
339
|
+
Bridges WordPress metadata and ACF (Advanced Custom Fields) directly to your React markup.
|
|
340
|
+
</p>
|
|
341
|
+
<div className="border border-zinc-300 p-4 bg-white font-mono text-xs">
|
|
342
|
+
<div className="mb-3">
|
|
343
|
+
<span className="block text-[9px] text-zinc-400 font-bold uppercase">Field: "author_bio"</span>
|
|
344
|
+
<span className="text-zinc-800 font-bold">{useWpCustomField("author_bio", "React Developer & WP theme engineer")}</span>
|
|
345
|
+
</div>
|
|
346
|
+
<div>
|
|
347
|
+
<span className="block text-[9px] text-zinc-400 font-bold uppercase">Field: "article_rating"</span>
|
|
348
|
+
<span className="text-zinc-800 font-bold">{useWpCustomField("article_rating", "āļøāļøāļøāļøāļø")}</span>
|
|
349
|
+
</div>
|
|
350
|
+
</div>
|
|
351
|
+
</div>
|
|
352
|
+
|
|
353
|
+
{/* Custom Query Loop */}
|
|
354
|
+
<div className="border border-zinc-200 bg-zinc-50 p-6">
|
|
355
|
+
<span className="inline-block bg-zinc-950 text-white text-[9px] font-mono font-black uppercase tracking-widest px-2 py-0.5 mb-4">
|
|
356
|
+
Hook: <WpQueryLoop>
|
|
357
|
+
</span>
|
|
358
|
+
<h3 className="font-serif font-black text-base text-zinc-900 mb-2">
|
|
359
|
+
Custom WP_Query Loop
|
|
360
|
+
</h3>
|
|
361
|
+
<p className="text-zinc-500 text-xs mb-4">
|
|
362
|
+
Fetches specialized collections of posts (like category grids or sidebars).
|
|
363
|
+
</p>
|
|
364
|
+
<div className="border border-zinc-300 p-3 bg-white space-y-2.5 max-h-[140px] overflow-y-auto">
|
|
365
|
+
<WpQueryLoop postType="post" postsPerPage={3}>
|
|
366
|
+
<div className="border border-zinc-100 p-2 hover:bg-zinc-50 transition-colors">
|
|
367
|
+
<h4 className="font-mono text-xs font-black text-zinc-950 uppercase tracking-tight truncate">
|
|
368
|
+
ā” Recent Block Post
|
|
369
|
+
</h4>
|
|
370
|
+
<span className="text-[9px] text-zinc-400 font-mono">Date: {new Date().toLocaleDateString()}</span>
|
|
371
|
+
</div>
|
|
372
|
+
</WpQueryLoop>
|
|
373
|
+
</div>
|
|
374
|
+
</div>
|
|
375
|
+
</div>
|
|
376
|
+
</div>
|
|
377
|
+
</section>
|
|
378
|
+
|
|
379
|
+
{/* Footer info console bar */}
|
|
380
|
+
<footer className="border-t-4 border-zinc-950 bg-zinc-950 text-white p-6 font-mono text-xs flex flex-col sm:flex-row justify-between items-center gap-4">
|
|
381
|
+
<div className="flex items-center gap-2">
|
|
382
|
+
<span className="inline-block w-2.5 h-2.5 bg-green-500 animate-pulse"></span>
|
|
383
|
+
<span>Vite Dev Environment active on port 5173</span>
|
|
384
|
+
</div>
|
|
385
|
+
<div>
|
|
386
|
+
<span>Press <kbd className="bg-zinc-800 px-1 py-0.5 border border-zinc-700">Ctrl + C</kbd> to exit console</span>
|
|
387
|
+
</div>
|
|
388
|
+
</footer>
|
|
389
|
+
</main>
|
|
390
|
+
</div>
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
`;
|
|
394
|
+
|
|
395
|
+
try {
|
|
396
|
+
writeFileSync(pagePath, pageContent, "utf8");
|
|
397
|
+
console.log(` ${pc.green("ā
Reset core template")}: src/app/page.tsx`);
|
|
398
|
+
} catch (err) {
|
|
399
|
+
console.log(pc.red(` ā Failed to reset src/app/page.tsx: err.message`));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// 6. Automatically Trigger Monorepo CLI Template Synchronization
|
|
403
|
+
// If running inside the monorepo starter, sync the template as well!
|
|
404
|
+
const monorepoSyncScript = path.join(projectRoot, "..", "..", "scripts", "sync-cli-template.mjs");
|
|
405
|
+
if (existsSync(monorepoSyncScript)) {
|
|
406
|
+
console.log(`\nš¦ ${pc.bold("MONOREPO CONTEXT DETECTED")} ā Syncing CLI Template...`);
|
|
407
|
+
try {
|
|
408
|
+
const result = spawnSync("node", [monorepoSyncScript], {
|
|
409
|
+
stdio: "inherit",
|
|
410
|
+
shell: process.platform === "win32"
|
|
411
|
+
});
|
|
412
|
+
if (result.status === 0) {
|
|
413
|
+
console.log(`\nš ${pc.green("Successfully synced factory-fresh canvas directly to create-forgewp CLI template!")}`);
|
|
414
|
+
} else {
|
|
415
|
+
console.log(`\nā ļø CLI sync template script returned non-zero status code: ${result.status}`);
|
|
416
|
+
}
|
|
417
|
+
} catch (err) {
|
|
418
|
+
console.log(pc.red(`\nā Failed to sync CLI template: ${err.message}`));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
console.log("\n" + "ā".repeat(60));
|
|
423
|
+
console.log(pc.green(`\nš ${pc.bold("CANVAS RESET COMPLETE:")} Reverted workspace back to standard empty blueprints.`));
|
|
424
|
+
console.log(pc.cyan(" Your ForgeWP canvas is now factory-fresh, clean, and perfectly synced!\n"));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function hasWorkBeenDone() {
|
|
428
|
+
const dirsToCheck = [
|
|
429
|
+
"src/app/pages",
|
|
430
|
+
"src/blocks",
|
|
431
|
+
"src/components"
|
|
432
|
+
];
|
|
433
|
+
for (const dir of dirsToCheck) {
|
|
434
|
+
const fullPath = path.join(projectRoot, dir);
|
|
435
|
+
if (existsSync(fullPath)) {
|
|
436
|
+
try {
|
|
437
|
+
const files = readdirSync(fullPath);
|
|
438
|
+
if (files.length > 0) {
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
} catch (e) {
|
|
442
|
+
// Directory exists but failed to read or is empty
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const isForce = process.argv.includes("--force") || process.argv.includes("-f") || process.argv.includes("-y");
|
|
450
|
+
|
|
451
|
+
if (hasWorkBeenDone() && !isForce) {
|
|
452
|
+
if (!process.stdin.isTTY) {
|
|
453
|
+
console.log(pc.red(`ā Non-interactive environment detected. Please use the --force flag to reset active work.`));
|
|
454
|
+
process.exit(1);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const rl = readline.createInterface({
|
|
458
|
+
input: process.stdin,
|
|
459
|
+
output: process.stdout
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
console.log(pc.yellow(`ā ļø ${pc.bold("WARNING:")} Existing custom pages, blocks, or components detected in your canvas!`));
|
|
463
|
+
console.log(pc.yellow(` Continuing will permanently delete all custom work and reset back to factory default.`));
|
|
464
|
+
|
|
465
|
+
rl.question(`\n Are you sure you want to proceed? (y/N): `, (answer) => {
|
|
466
|
+
rl.close();
|
|
467
|
+
const confirmed = answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes";
|
|
468
|
+
if (!confirmed) {
|
|
469
|
+
console.log(pc.blue(`\nā Reset aborted. No changes were made.\n`));
|
|
470
|
+
process.exit(0);
|
|
471
|
+
}
|
|
472
|
+
runReset();
|
|
473
|
+
});
|
|
474
|
+
} else {
|
|
475
|
+
runReset();
|
|
476
|
+
}
|
package/bin/repair.js
CHANGED
|
@@ -31,6 +31,13 @@ try {
|
|
|
31
31
|
const mockDataPath = path.join(projectRoot, "wordpress", "mock-data.json");
|
|
32
32
|
if (!existsSync(mockDataPath)) {
|
|
33
33
|
const defaultJson = {
|
|
34
|
+
menu: {
|
|
35
|
+
primary: [
|
|
36
|
+
{ title: "Home", url: "/" },
|
|
37
|
+
{ title: "Blog", url: "/post" },
|
|
38
|
+
{ title: "Archive", url: "/archive" }
|
|
39
|
+
]
|
|
40
|
+
},
|
|
34
41
|
post: [
|
|
35
42
|
{
|
|
36
43
|
id: 1,
|