@forgewp/compiler 0.2.0 โ 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -5
- package/bin/analyze.js +158 -0
- package/bin/cli.js +29 -4
- package/bin/doctor.js +125 -11
- package/bin/export.js +20 -0
- package/bin/fresh.js +32 -343
- package/bin/i18n-extract.js +121 -0
- package/bin/i18n-translate.js +112 -0
- package/bin/make-block.js +27 -60
- package/bin/make-island.js +72 -0
- package/bin/make-post-type.js +6 -6
- package/bin/make-template.js +145 -0
- package/bin/repair.js +2 -2
- package/bin/sync-routes.js +28 -158
- package/define-config.d.ts +1 -0
- package/define-config.js +1 -0
- package/lib/adapters/html-adapter.js +65 -0
- package/lib/adapters/stub-adapter.js +49 -0
- package/lib/add-component.js +290 -73
- package/lib/asset-loader.js +27 -0
- package/lib/block-compiler.js +552 -0
- package/lib/blueprints.js +1459 -501
- package/lib/define-config.d.ts +3 -0
- package/lib/define-config.js +8 -0
- package/lib/diagnostics.js +798 -0
- package/lib/export-theme.js +81 -18
- package/lib/framework-adapter.js +34 -0
- package/lib/functions-builder.js +1801 -0
- package/lib/generate-theme.js +1019 -1143
- package/lib/hydration-scanner.js +674 -0
- package/lib/i18n/extractor.js +60 -0
- package/lib/i18n/providers.js +165 -0
- package/lib/index.d.ts +119 -1
- package/lib/index.js +20 -3
- package/lib/load-config.js +122 -6
- package/lib/markup-processor.js +584 -0
- package/lib/php-builders.js +381 -0
- package/lib/react-adapter.js +1336 -0
- package/lib/render-static.js +9 -82
- package/lib/render-theme.mts +526 -232
- package/lib/screenshot-fallback.png +0 -0
- package/lib/types.js +1 -0
- package/lib/validate-export.js +183 -0
- package/package.json +14 -3
- package/bin/make-component.js +0 -200
package/bin/fresh.js
CHANGED
|
@@ -6,12 +6,22 @@ import { spawnSync } from "node:child_process";
|
|
|
6
6
|
import readline from "node:readline";
|
|
7
7
|
import pc from "picocolors";
|
|
8
8
|
import { SYSTEM_BLUEPRINTS } from "../lib/blueprints.js";
|
|
9
|
+
import { loadConfig } from "../lib/load-config.js";
|
|
10
|
+
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
9
11
|
|
|
10
12
|
console.log(`\n๐งน ${pc.bold(pc.bgRed(pc.black(" FORGEWP FACTORY RESET (FRESH CANVAS) ")))}\n`);
|
|
11
13
|
|
|
12
14
|
const projectRoot = process.cwd();
|
|
13
15
|
|
|
14
|
-
function runReset() {
|
|
16
|
+
async function runReset() {
|
|
17
|
+
// Load the project config to determine the framework adapter
|
|
18
|
+
let frameworkAdapter = 'react';
|
|
19
|
+
try {
|
|
20
|
+
const config = await loadConfig(projectRoot);
|
|
21
|
+
frameworkAdapter = config.frameworkAdapter || 'react';
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.log(pc.yellow(` โ ๏ธ Could not load wp.config.ts. Using default adapter: react`));
|
|
24
|
+
}
|
|
15
25
|
|
|
16
26
|
// 1. Clean Build Caches & Artifacts
|
|
17
27
|
const foldersToClean = [".forgewp", "dist", ".vite"];
|
|
@@ -48,7 +58,7 @@ for (const targetPrune of directoriesToPrune) {
|
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
// 3. Restore Standard Database & Sitemap Menus from Core Blueprints
|
|
51
|
-
const coreFilesToReset = ["
|
|
61
|
+
const coreFilesToReset = ["cms/menus.json", "cms/mock-data.json"];
|
|
52
62
|
for (const relPath of coreFilesToReset) {
|
|
53
63
|
const fullPath = path.join(projectRoot, relPath);
|
|
54
64
|
const blueprintContent = SYSTEM_BLUEPRINTS[relPath];
|
|
@@ -66,362 +76,41 @@ for (const relPath of coreFilesToReset) {
|
|
|
66
76
|
}
|
|
67
77
|
}
|
|
68
78
|
|
|
69
|
-
// 4. Restore
|
|
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
|
-
|
|
79
|
+
// 4. Restore Framework-Specific Canvas Blueprints via Adapter
|
|
105
80
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
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`);
|
|
81
|
+
const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
|
|
82
|
+
const adapter = adapterModule.default || adapterModule;
|
|
83
|
+
if (typeof adapter.onFresh === "function") {
|
|
84
|
+
await adapter.onFresh(projectRoot);
|
|
85
|
+
} else {
|
|
86
|
+
console.log(` ${pc.yellow("โ ๏ธ No fresh canvas hook implemented for framework adapter:")} ${pc.cyan(frameworkAdapter)}`);
|
|
87
|
+
}
|
|
398
88
|
} catch (err) {
|
|
399
|
-
console.log(pc.red(` โ Failed to
|
|
89
|
+
console.log(pc.red(` โ Failed to load framework adapter "${frameworkAdapter}": ${err.message}`));
|
|
400
90
|
}
|
|
401
91
|
|
|
402
|
-
// 6. Automatically Trigger Monorepo CLI Template Synchronization
|
|
403
|
-
// If running inside the monorepo starter, sync the template as well!
|
|
92
|
+
// 6. Automatically Trigger Monorepo CLI Template Synchronization Silently
|
|
93
|
+
// If running inside the monorepo starter, sync the template as well in the background!
|
|
404
94
|
const monorepoSyncScript = path.join(projectRoot, "..", "..", "scripts", "sync-cli-template.mjs");
|
|
405
95
|
if (existsSync(monorepoSyncScript)) {
|
|
406
|
-
console.log(`\n๐ฆ ${pc.bold("MONOREPO CONTEXT DETECTED")} โ Syncing CLI Template...`);
|
|
407
96
|
try {
|
|
408
|
-
|
|
409
|
-
stdio: "
|
|
97
|
+
spawnSync("node", [monorepoSyncScript], {
|
|
98
|
+
stdio: "ignore",
|
|
410
99
|
shell: process.platform === "win32"
|
|
411
100
|
});
|
|
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
101
|
} catch (err) {
|
|
418
|
-
|
|
102
|
+
// Fail silently in development background sync
|
|
419
103
|
}
|
|
420
104
|
}
|
|
421
105
|
|
|
422
106
|
console.log("\n" + "โ".repeat(60));
|
|
423
107
|
console.log(pc.green(`\n๐ ${pc.bold("CANVAS RESET COMPLETE:")} Reverted workspace back to standard empty blueprints.`));
|
|
424
|
-
console.log(pc.cyan(
|
|
108
|
+
console.log(pc.cyan(` Your ForgeWP canvas is now factory-fresh, clean, and perfectly synced.`));
|
|
109
|
+
console.log(`\n๐ ${pc.bold("NEXT STEPS:")}`);
|
|
110
|
+
console.log(` 1. Start the Vite Dev Server: ${pc.cyan("pnpm dev")} or ${pc.cyan("npm run dev")}`);
|
|
111
|
+
console.log(` 2. Add dynamic UI components: ${pc.cyan("pnpm forgewp add fade-reveal")}`);
|
|
112
|
+
console.log(` 3. Customize your entry page: ${pc.cyan("src/app/page.tsx")}`);
|
|
113
|
+
console.log(` 4. Compile to WordPress theme: ${pc.cyan("pnpm export")} or ${pc.cyan("npm run export")}\n`);
|
|
425
114
|
}
|
|
426
115
|
|
|
427
116
|
function hasWorkBeenDone() {
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
import { loadConfig } from '../lib/load-config.js';
|
|
7
|
+
import { extractKeysFromDirectory } from '../lib/i18n/extractor.js';
|
|
8
|
+
|
|
9
|
+
console.log(`\n๐ฃ๏ธ ${pc.bold(pc.bgCyan(pc.black(" FORGEWP I18N EXTRACTOR ")))}\n`);
|
|
10
|
+
|
|
11
|
+
const themeRoot = process.cwd();
|
|
12
|
+
|
|
13
|
+
async function run() {
|
|
14
|
+
try {
|
|
15
|
+
let config = {};
|
|
16
|
+
const configPath = path.join(themeRoot, 'wp.config.ts');
|
|
17
|
+
if (fs.existsSync(configPath)) {
|
|
18
|
+
config = await loadConfig(themeRoot);
|
|
19
|
+
} else {
|
|
20
|
+
console.warn(pc.yellow(`โ ๏ธ Could not load wp.config.ts, using fallback defaults.`));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const i18n = config.i18n || {
|
|
24
|
+
locales: ['en', 'de'],
|
|
25
|
+
defaultLocale: 'en',
|
|
26
|
+
provider: 'local'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const defaultLocale = i18n.defaultLocale || 'en';
|
|
30
|
+
const locales = i18n.locales || ['en', 'de'];
|
|
31
|
+
|
|
32
|
+
const srcDir = path.join(themeRoot, 'src');
|
|
33
|
+
if (!fs.existsSync(srcDir)) {
|
|
34
|
+
throw new Error(`Source directory not found at ${srcDir}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log(` ๐ Scanning files in: ${pc.cyan('src/')}`);
|
|
38
|
+
const extractedKeys = extractKeysFromDirectory(srcDir);
|
|
39
|
+
console.log(` โ
Extracted ${pc.green(extractedKeys.length)} unique translation keys.`);
|
|
40
|
+
|
|
41
|
+
const cmsDir = path.join(themeRoot, 'cms');
|
|
42
|
+
if (!fs.existsSync(cmsDir)) {
|
|
43
|
+
fs.mkdirSync(cmsDir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const translationsPath = path.join(cmsDir, 'translations.json');
|
|
47
|
+
let translations = {};
|
|
48
|
+
if (fs.existsSync(translationsPath)) {
|
|
49
|
+
try {
|
|
50
|
+
translations = JSON.parse(fs.readFileSync(translationsPath, 'utf8'));
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.warn(pc.yellow(`โ ๏ธ Could not parse existing translations.json, starting fresh.`));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Initialize missing locales
|
|
57
|
+
for (const locale of locales) {
|
|
58
|
+
if (!translations[locale] || typeof translations[locale] !== 'object') {
|
|
59
|
+
translations[locale] = {};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let addedCount = 0;
|
|
64
|
+
let unusedCount = 0;
|
|
65
|
+
|
|
66
|
+
// Merge extracted keys
|
|
67
|
+
for (const locale of locales) {
|
|
68
|
+
const isDefault = locale === defaultLocale;
|
|
69
|
+
const localeMap = translations[locale];
|
|
70
|
+
|
|
71
|
+
// Add new keys
|
|
72
|
+
for (const key of extractedKeys) {
|
|
73
|
+
if (typeof localeMap[key] === 'undefined') {
|
|
74
|
+
localeMap[key] = isDefault ? key : '';
|
|
75
|
+
addedCount++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Check for unused keys (defined in JSON but not found in source code)
|
|
80
|
+
for (const key of Object.keys(localeMap)) {
|
|
81
|
+
if (!extractedKeys.includes(key)) {
|
|
82
|
+
unusedCount++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Write back sorted translations
|
|
88
|
+
const sortedTranslations = {};
|
|
89
|
+
for (const locale of locales) {
|
|
90
|
+
const localeMap = translations[locale];
|
|
91
|
+
const sortedMap = {};
|
|
92
|
+
|
|
93
|
+
// Sort keys alphabetically for clean diffs
|
|
94
|
+
const allKeys = Array.from(new Set([...extractedKeys, ...Object.keys(localeMap)])).sort();
|
|
95
|
+
for (const key of allKeys) {
|
|
96
|
+
if (typeof localeMap[key] !== 'undefined') {
|
|
97
|
+
sortedMap[key] = localeMap[key];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
sortedTranslations[locale] = sortedMap;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fs.writeFileSync(translationsPath, JSON.stringify(sortedTranslations, null, 2), 'utf8');
|
|
104
|
+
|
|
105
|
+
console.log(`\n${pc.bold("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")}`);
|
|
106
|
+
console.log(` โจ ${pc.green("Extraction completed successfully!")}`);
|
|
107
|
+
console.log(` ๐ File: ${pc.cyan(path.relative(themeRoot, translationsPath))}`);
|
|
108
|
+
console.log(` ๐ Locales: ${pc.yellow(locales.join(', '))}`);
|
|
109
|
+
console.log(` โ New keys discovered: ${pc.green(addedCount / locales.length)}`);
|
|
110
|
+
if (unusedCount > 0) {
|
|
111
|
+
console.log(` โน๏ธ Unused keys remaining in catalog: ${pc.yellow(unusedCount / locales.length)} (retained to prevent work loss)`);
|
|
112
|
+
}
|
|
113
|
+
console.log(`\n`);
|
|
114
|
+
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error(pc.red(`\nโ Extraction failed: ${error.message}\n`));
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
run();
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
import { loadConfig } from '../lib/load-config.js';
|
|
7
|
+
import { getProvider } from '../lib/i18n/providers.js';
|
|
8
|
+
|
|
9
|
+
console.log(`\n๐ค ${pc.bold(pc.bgCyan(pc.black(" FORGEWP I18N AUTO-TRANSLATOR ")))}\n`);
|
|
10
|
+
|
|
11
|
+
const themeRoot = process.cwd();
|
|
12
|
+
|
|
13
|
+
async function run() {
|
|
14
|
+
try {
|
|
15
|
+
let config = {};
|
|
16
|
+
const configPath = path.join(themeRoot, 'wp.config.ts');
|
|
17
|
+
if (fs.existsSync(configPath)) {
|
|
18
|
+
config = await loadConfig(themeRoot);
|
|
19
|
+
} else {
|
|
20
|
+
console.warn(pc.yellow(`โ ๏ธ Could not load wp.config.ts, using fallback defaults.`));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const i18n = config.i18n || {
|
|
24
|
+
locales: ['en', 'de'],
|
|
25
|
+
defaultLocale: 'en',
|
|
26
|
+
provider: 'local'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const defaultLocale = i18n.defaultLocale || 'en';
|
|
30
|
+
const locales = i18n.locales || ['en', 'de'];
|
|
31
|
+
const providerName = i18n.provider || 'local';
|
|
32
|
+
|
|
33
|
+
const translationsPath = path.join(themeRoot, 'cms', 'translations.json');
|
|
34
|
+
if (!fs.existsSync(translationsPath)) {
|
|
35
|
+
throw new Error(`Translations catalog not found at ${translationsPath}. Please run "pnpm forgewp i18n:extract" first.`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let translations = {};
|
|
39
|
+
try {
|
|
40
|
+
translations = JSON.parse(fs.readFileSync(translationsPath, 'utf8'));
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw new Error(`Failed to parse translations.json: ${err.message}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(` ๐ Active provider: ${pc.cyan(providerName)}`);
|
|
46
|
+
console.log(` ๐ Default locale: ${pc.yellow(defaultLocale)}`);
|
|
47
|
+
|
|
48
|
+
const provider = getProvider(providerName, i18n.providerConfig || {});
|
|
49
|
+
|
|
50
|
+
let totalTranslated = 0;
|
|
51
|
+
|
|
52
|
+
for (const locale of locales) {
|
|
53
|
+
if (locale === defaultLocale) continue;
|
|
54
|
+
|
|
55
|
+
if (!translations[locale]) {
|
|
56
|
+
translations[locale] = {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const localeMap = translations[locale];
|
|
60
|
+
const untranslatedKeys = Object.keys(localeMap).filter(key => !localeMap[key]);
|
|
61
|
+
|
|
62
|
+
if (untranslatedKeys.length === 0) {
|
|
63
|
+
console.log(` โ
Locale ${pc.yellow(locale.toUpperCase())} is fully translated.`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(` โณ Translating ${pc.yellow(untranslatedKeys.length)} keys to ${pc.green(locale.toUpperCase())}...`);
|
|
68
|
+
|
|
69
|
+
if (providerName === 'local' || providerName === 'manual') {
|
|
70
|
+
console.log(` โ ๏ธ Manual/local mode: Initializing keys in ${pc.yellow(locale.toUpperCase())} as empty placeholders.`);
|
|
71
|
+
for (const key of untranslatedKeys) {
|
|
72
|
+
localeMap[key] = "";
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Execute auto-translation
|
|
78
|
+
const translatedMap = await provider.translate(untranslatedKeys, defaultLocale, locale);
|
|
79
|
+
|
|
80
|
+
let successCount = 0;
|
|
81
|
+
for (const key of untranslatedKeys) {
|
|
82
|
+
if (translatedMap[key]) {
|
|
83
|
+
localeMap[key] = translatedMap[key];
|
|
84
|
+
successCount++;
|
|
85
|
+
totalTranslated++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
console.log(` โ
Translated ${pc.green(successCount)}/${pc.yellow(untranslatedKeys.length)} keys successfully.`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Save changes
|
|
92
|
+
fs.writeFileSync(translationsPath, JSON.stringify(translations, null, 2), 'utf8');
|
|
93
|
+
|
|
94
|
+
console.log(`\n${pc.bold("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")}`);
|
|
95
|
+
console.log(` โจ ${pc.green("Translation execution completed successfully!")}`);
|
|
96
|
+
if (totalTranslated > 0) {
|
|
97
|
+
console.log(` ๐ Total keys automated: ${pc.green(totalTranslated)}`);
|
|
98
|
+
} else if (providerName === 'local' || providerName === 'manual') {
|
|
99
|
+
console.log(` ๐ก Setup complete. Open ${pc.cyan("cms/translations.json")} to write translations manually.`);
|
|
100
|
+
console.log(` Or configure 'deepl' to auto-translate using environment variables.`);
|
|
101
|
+
} else {
|
|
102
|
+
console.log(` โ
All locales are 100% up-to-date. No API calls were made.`);
|
|
103
|
+
}
|
|
104
|
+
console.log(`\n`);
|
|
105
|
+
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(pc.red(`\nโ Translation failed: ${error.message}\n`));
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
run();
|