@forgewp/compiler 0.3.0 → 0.4.2
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 +33 -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-hooks.js +221 -0
- 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 +282 -183
- package/lib/asset-loader.js +27 -0
- package/lib/block-compiler.js +552 -0
- package/lib/blueprints.js +15 -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 +2044 -0
- package/lib/generate-theme.js +1140 -1352
- package/lib/hydration-scanner.js +663 -21
- package/lib/i18n/extractor.js +60 -0
- package/lib/i18n/providers.js +165 -0
- package/lib/index.d.ts +115 -3
- package/lib/index.js +19 -5
- package/lib/load-config.js +122 -6
- package/lib/markup-processor.js +589 -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 +543 -232
- package/lib/screenshot-fallback.png +0 -0
- package/lib/types.js +1 -0
- package/lib/validate-export.js +183 -0
- package/package.json +15 -3
- package/templates/PresetsStyle.tsx +74 -0
- package/templates/SEO.tsx +109 -0
- package/templates/forgewp-config.ts +43 -0
- package/templates/menus.json +11 -0
- package/templates/mock-data.json +434 -0
- package/templates/wordpress.tsx +1297 -0
- package/bin/make-component.js +0 -200
package/lib/add-component.js
CHANGED
|
@@ -1,231 +1,330 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
2
|
import { readFileSync, writeFileSync, readdirSync, existsSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
3
5
|
import path from "node:path";
|
|
4
|
-
import readline from "node:readline";
|
|
5
6
|
import pc from "picocolors";
|
|
6
7
|
|
|
8
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
9
|
+
// CONSTANTS
|
|
10
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The canonical shadcn components.json file expected at the project root.
|
|
14
|
+
* ForgeWP ensures this exists before delegating to the shadcn CLI.
|
|
15
|
+
* It points to the standard ForgeWP project layout.
|
|
16
|
+
*/
|
|
17
|
+
const SHADCN_COMPONENTS_JSON = {
|
|
18
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
19
|
+
"style": "new-york",
|
|
20
|
+
"rsc": false,
|
|
21
|
+
"tsx": true,
|
|
22
|
+
"tailwind": {
|
|
23
|
+
"config": "tailwind.config.js",
|
|
24
|
+
"css": "src/app/globals.css",
|
|
25
|
+
"baseColor": "zinc",
|
|
26
|
+
"cssVariables": true,
|
|
27
|
+
"prefix": ""
|
|
28
|
+
},
|
|
29
|
+
"aliases": {
|
|
30
|
+
"components": "@/components",
|
|
31
|
+
"utils": "@/lib/utils",
|
|
32
|
+
"ui": "@/components/ui",
|
|
33
|
+
"lib": "@/lib",
|
|
34
|
+
"hooks": "@/hooks"
|
|
35
|
+
},
|
|
36
|
+
"iconLibrary": "lucide"
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
40
|
+
// MAIN EXPORT
|
|
41
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Adds a UI component to the ForgeWP project.
|
|
45
|
+
*
|
|
46
|
+
* Flow:
|
|
47
|
+
* 1. Ensure shadcn's components.json is present (create if missing).
|
|
48
|
+
* 2. Run `shadcn add <component>` — shadcn handles all npm deps, Tailwind
|
|
49
|
+
* plugins, CSS vars, and globals.css registration automatically via its
|
|
50
|
+
* own remote registry.json for every component it knows about.
|
|
51
|
+
* 3. If ForgeWP has a local override (`@forgewp/ui/components/<name>/forgewp.tsx`),
|
|
52
|
+
* overwrite shadcn's freshly installed copy with the ForgeWP version.
|
|
53
|
+
* Read the component's registry.json for any additional plugin requirements
|
|
54
|
+
* not covered by shadcn (e.g. ForgeWP-native components that aren't in
|
|
55
|
+
* the shadcn remote registry).
|
|
56
|
+
* 4. If style === "forgewp", apply the neo-brutalist sharpening transform.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} component - The component name (e.g. "sheet", "navbar").
|
|
59
|
+
* @param {{ style?: "shadcn" | "forgewp" }} options
|
|
60
|
+
*/
|
|
7
61
|
export async function addComponent(component, options) {
|
|
8
|
-
const { style = "
|
|
62
|
+
const { style = "shadcn" } = options;
|
|
9
63
|
const projectRoot = process.cwd();
|
|
10
64
|
|
|
11
|
-
console.log(pc.cyan(`\n ForgeWP add — ${component}
|
|
65
|
+
console.log(pc.cyan(`\n ForgeWP add — ${component}\n`));
|
|
66
|
+
|
|
67
|
+
// ── Step 1: Guarantee components.json exists ───────────────────────────────
|
|
68
|
+
ensureComponentsJson(projectRoot);
|
|
69
|
+
|
|
70
|
+
// ── Step 2: Detect package manager ────────────────────────────────────────
|
|
71
|
+
const { installCmd, shadcnCmd } = detectPackageManager(projectRoot);
|
|
72
|
+
|
|
73
|
+
// ── Step 3: Check for a ForgeWP local override ────────────────────────────
|
|
74
|
+
const localRegistry = resolveLocalRegistry(component);
|
|
75
|
+
const hasLocalOverride = localRegistry !== null && existsSync(localRegistry.tsxPath);
|
|
12
76
|
|
|
13
|
-
//
|
|
14
|
-
|
|
77
|
+
// ── Step 4: Run shadcn add (primary install source for everything) ─────────
|
|
78
|
+
console.log(pc.dim(` Installing ${component} via shadcn...`));
|
|
15
79
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
80
|
+
execSync(`${shadcnCmd} add ${component} --yes`, {
|
|
81
|
+
stdio: "inherit",
|
|
82
|
+
cwd: projectRoot,
|
|
83
|
+
shell: process.platform === "win32",
|
|
84
|
+
});
|
|
85
|
+
} catch (err) {
|
|
86
|
+
// shadcn may fail for ForgeWP-native components not in the shadcn registry.
|
|
87
|
+
// If we have a local override, that's fine — we'll install it ourselves below.
|
|
88
|
+
if (!hasLocalOverride) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Failed to install "${component}" via shadcn, and no ForgeWP local override exists.\n` +
|
|
91
|
+
`Details: ${err.message}`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
console.log(pc.yellow(` ⚠ shadcn does not know "${component}" — using ForgeWP local registry instead.`));
|
|
27
95
|
}
|
|
28
96
|
|
|
29
|
-
if
|
|
30
|
-
|
|
97
|
+
// ── Step 5: Install ForgeWP local override (if present) ───────────────────
|
|
98
|
+
if (hasLocalOverride) {
|
|
99
|
+
console.log(pc.dim(` Applying ForgeWP override for ${component}...`));
|
|
100
|
+
|
|
31
101
|
const targetDir = path.join(projectRoot, "src", "components", "ui");
|
|
32
102
|
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
|
|
33
|
-
|
|
103
|
+
|
|
34
104
|
const targetFile = path.join(targetDir, `${component}.tsx`);
|
|
35
|
-
const content = readFileSync(
|
|
105
|
+
const content = readFileSync(localRegistry.tsxPath, "utf8");
|
|
36
106
|
writeFileSync(targetFile, content, "utf8");
|
|
37
|
-
|
|
38
|
-
// Auto-detect and install missing third-party dependencies from imported component files
|
|
39
|
-
await autoInstallMissingDependencies(targetFile, projectRoot);
|
|
40
107
|
|
|
41
|
-
|
|
42
|
-
|
|
108
|
+
// Install any extra Tailwind plugins declared in the ForgeWP registry.json
|
|
109
|
+
// that shadcn's remote registry wouldn't know about (ForgeWP-native components).
|
|
110
|
+
if (localRegistry.meta?.tailwindPlugins?.length > 0) {
|
|
111
|
+
await ensureTailwindPlugins(localRegistry.meta.tailwindPlugins, installCmd, projectRoot);
|
|
43
112
|
}
|
|
44
113
|
|
|
45
|
-
console.log(pc.
|
|
46
|
-
return;
|
|
114
|
+
console.log(pc.dim(` ↳ Override written to src/components/ui/${component}.tsx`));
|
|
47
115
|
}
|
|
48
116
|
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
shadcnCmd = "yarn dlx shadcn@latest";
|
|
117
|
+
// ── Step 6: Apply ForgeWP sharpening (when style === "forgewp") ────────────
|
|
118
|
+
if (style === "forgewp") {
|
|
119
|
+
const uiDir = path.join(projectRoot, "src", "components", "ui");
|
|
120
|
+
if (existsSync(uiDir)) {
|
|
121
|
+
const files = readdirSync(uiDir).filter(f =>
|
|
122
|
+
f.toLowerCase().includes(component.toLowerCase().replace(/-/g, "")) ||
|
|
123
|
+
f.toLowerCase().includes(component.toLowerCase())
|
|
124
|
+
);
|
|
125
|
+
const targets = files.length > 0 ? files : readdirSync(uiDir);
|
|
126
|
+
targets.forEach(f => {
|
|
127
|
+
if (f.endsWith(".tsx")) sharpenFile(path.join(uiDir, f));
|
|
128
|
+
});
|
|
62
129
|
}
|
|
130
|
+
}
|
|
63
131
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
132
|
+
console.log(pc.green(`\n ✅ ${component} ready in src/components/ui/\n`));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
136
|
+
// HELPERS
|
|
137
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Ensures shadcn's components.json exists at the project root.
|
|
141
|
+
* If missing, writes the standard ForgeWP default so `shadcn add` works
|
|
142
|
+
* without requiring the developer to run `shadcn init` manually.
|
|
143
|
+
*/
|
|
144
|
+
function ensureComponentsJson(projectRoot) {
|
|
145
|
+
const targetPath = path.join(projectRoot, "components.json");
|
|
146
|
+
if (existsSync(targetPath)) return;
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
writeFileSync(targetPath, JSON.stringify(SHADCN_COMPONENTS_JSON, null, 2), "utf8");
|
|
150
|
+
console.log(pc.green(` ✅ Created components.json (shadcn configuration)`));
|
|
70
151
|
} catch (err) {
|
|
71
|
-
|
|
152
|
+
console.log(pc.yellow(` ⚠ Could not create components.json: ${err.message}`));
|
|
153
|
+
console.log(pc.yellow(` Run "pnpm dlx shadcn@latest init" to initialize shadcn manually.`));
|
|
72
154
|
}
|
|
155
|
+
}
|
|
73
156
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const files = readdirSync(uiDir);
|
|
82
|
-
// Find files related to the component
|
|
83
|
-
const relevantFiles = files.filter(f =>
|
|
84
|
-
f.toLowerCase().includes(component.toLowerCase().replace(/-/g, "")) ||
|
|
85
|
-
f.toLowerCase().includes(component.toLowerCase())
|
|
86
|
-
);
|
|
157
|
+
/**
|
|
158
|
+
* Detects the project's package manager from lockfiles and returns
|
|
159
|
+
* the appropriate install and shadcn CLI commands.
|
|
160
|
+
*/
|
|
161
|
+
function detectPackageManager(projectRoot) {
|
|
162
|
+
let installCmd = "npm install --save-dev";
|
|
163
|
+
let shadcnCmd = "npx shadcn@latest";
|
|
87
164
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
files.forEach(f => {
|
|
95
|
-
if (f.endsWith(".tsx")) sharpenFile(path.join(uiDir, f));
|
|
96
|
-
});
|
|
165
|
+
let current = projectRoot;
|
|
166
|
+
while (current) {
|
|
167
|
+
if (existsSync(path.join(current, "pnpm-lock.yaml"))) {
|
|
168
|
+
installCmd = "pnpm add -D";
|
|
169
|
+
shadcnCmd = "pnpm dlx shadcn@latest";
|
|
170
|
+
break;
|
|
97
171
|
}
|
|
172
|
+
if (existsSync(path.join(current, "yarn.lock"))) {
|
|
173
|
+
installCmd = "yarn add -D";
|
|
174
|
+
shadcnCmd = "yarn dlx shadcn@latest";
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (existsSync(path.join(current, "bun.lockb"))) {
|
|
178
|
+
installCmd = "bun add -d";
|
|
179
|
+
shadcnCmd = "bunx --bun shadcn@latest";
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
const parent = path.dirname(current);
|
|
183
|
+
if (parent === current) break;
|
|
184
|
+
current = parent;
|
|
98
185
|
}
|
|
99
186
|
|
|
100
|
-
|
|
187
|
+
return { installCmd, shadcnCmd };
|
|
101
188
|
}
|
|
102
189
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Checks the `@forgewp/ui` local registry for a component override.
|
|
192
|
+
* Returns an object with the tsx path and parsed registry.json metadata,
|
|
193
|
+
* or null if no override exists for this component.
|
|
194
|
+
*
|
|
195
|
+
* @returns {{ tsxPath: string, meta: object } | null}
|
|
196
|
+
*/
|
|
197
|
+
function resolveLocalRegistry(component) {
|
|
198
|
+
let registryBase;
|
|
199
|
+
try {
|
|
200
|
+
const req = createRequire(import.meta.url);
|
|
201
|
+
registryBase = path.join(
|
|
202
|
+
path.dirname(req.resolve("@forgewp/ui/package.json")),
|
|
203
|
+
"components"
|
|
204
|
+
);
|
|
205
|
+
} catch {
|
|
206
|
+
// Fallback for local monorepo development
|
|
207
|
+
registryBase = path.resolve(
|
|
208
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
209
|
+
"../../ui/components"
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const componentDir = path.join(registryBase, component);
|
|
214
|
+
const tsxPath = path.join(componentDir, "forgewp.tsx");
|
|
215
|
+
const registryPath = path.join(componentDir, "registry.json");
|
|
216
|
+
|
|
217
|
+
if (!existsSync(tsxPath) && !existsSync(registryPath)) return null;
|
|
218
|
+
|
|
219
|
+
let meta = {};
|
|
220
|
+
if (existsSync(registryPath)) {
|
|
221
|
+
try {
|
|
222
|
+
meta = JSON.parse(readFileSync(registryPath, "utf8"));
|
|
223
|
+
} catch {
|
|
224
|
+
// Malformed registry.json — proceed with empty meta
|
|
113
225
|
}
|
|
114
|
-
return match;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
if (content !== sharpened) {
|
|
118
|
-
writeFileSync(filePath, sharpened, "utf8");
|
|
119
|
-
console.log(pc.dim(` Sharpened ${path.basename(filePath)}`));
|
|
120
226
|
}
|
|
227
|
+
|
|
228
|
+
return { tsxPath, meta };
|
|
121
229
|
}
|
|
122
230
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Ensures the given Tailwind CSS plugins are installed and registered
|
|
233
|
+
* via `@plugin` in the project's globals.css file.
|
|
234
|
+
*
|
|
235
|
+
* This is used only for ForgeWP-native components whose Tailwind plugin
|
|
236
|
+
* requirements are declared in their local registry.json — since shadcn's
|
|
237
|
+
* remote registry handles this automatically for shadcn-sourced components.
|
|
238
|
+
*
|
|
239
|
+
* @param {string[]} plugins - Plugin package names (e.g. ["tailwindcss-animate"])
|
|
240
|
+
* @param {string} installCmd - The detected package manager install command
|
|
241
|
+
* @param {string} projectRoot
|
|
242
|
+
*/
|
|
243
|
+
async function ensureTailwindPlugins(plugins, installCmd, projectRoot) {
|
|
244
|
+
const pkgJsonPath = path.join(projectRoot, "package.json");
|
|
245
|
+
if (!existsSync(pkgJsonPath)) return;
|
|
246
|
+
|
|
247
|
+
const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
|
|
248
|
+
const currentDeps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
|
|
249
|
+
|
|
250
|
+
for (const plugin of plugins) {
|
|
251
|
+
// Install if missing
|
|
252
|
+
if (!currentDeps[plugin]) {
|
|
253
|
+
console.log(pc.yellow(`\n ⚡ Requires Tailwind plugin: ${pc.bold(plugin)}`));
|
|
254
|
+
try {
|
|
255
|
+
execSync(`${installCmd} ${plugin}`, {
|
|
256
|
+
stdio: "inherit",
|
|
257
|
+
cwd: projectRoot,
|
|
258
|
+
shell: process.platform === "win32",
|
|
259
|
+
});
|
|
260
|
+
console.log(pc.green(` ✅ Installed ${plugin}`));
|
|
261
|
+
} catch (err) {
|
|
262
|
+
console.log(pc.red(` ❌ Failed to install ${plugin}: ${err.message}`));
|
|
263
|
+
console.log(pc.yellow(` Please manually run: ${installCmd} ${plugin}\n`));
|
|
264
|
+
continue;
|
|
151
265
|
}
|
|
152
266
|
}
|
|
153
267
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
268
|
+
// Register @plugin in globals.css if not already present
|
|
269
|
+
const cssSearchPaths = [
|
|
270
|
+
path.join(projectRoot, "src", "app", "globals.css"),
|
|
271
|
+
path.join(projectRoot, "src", "styles", "globals.css"),
|
|
272
|
+
path.join(projectRoot, "src", "index.css"),
|
|
273
|
+
path.join(projectRoot, "src", "global.css"),
|
|
274
|
+
];
|
|
158
275
|
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
161
|
-
|
|
162
|
-
|
|
276
|
+
const globalsPath = cssSearchPaths.find(p => existsSync(p));
|
|
277
|
+
if (!globalsPath) {
|
|
278
|
+
console.log(pc.yellow(` ⚠ Could not find globals.css. Add manually: @plugin "${plugin}";`));
|
|
279
|
+
continue;
|
|
163
280
|
}
|
|
164
281
|
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const missingDeps = Array.from(foundImports).filter(dep => !currentDeps[dep]);
|
|
172
|
-
|
|
173
|
-
if (missingDeps.length > 0) {
|
|
174
|
-
console.log(pc.yellow(`\n ⚡ Detected missing dependencies: ${missingDeps.join(", ")}`));
|
|
175
|
-
|
|
176
|
-
// Detect Package Manager
|
|
177
|
-
let installCmd = "npm install --save";
|
|
178
|
-
let managerName = "npm";
|
|
179
|
-
if (existsSync(path.join(projectRoot, "pnpm-lock.yaml"))) {
|
|
180
|
-
installCmd = "pnpm add";
|
|
181
|
-
managerName = "pnpm";
|
|
182
|
-
} else if (existsSync(path.join(projectRoot, "yarn.lock"))) {
|
|
183
|
-
installCmd = "yarn add";
|
|
184
|
-
managerName = "yarn";
|
|
185
|
-
} else if (existsSync(path.join(projectRoot, "bun.lockb"))) {
|
|
186
|
-
installCmd = "bun add";
|
|
187
|
-
managerName = "bun";
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Check if environment is interactive
|
|
191
|
-
if (!process.stdin.isTTY) {
|
|
192
|
-
console.log(pc.dim(` Non-interactive environment detected. Skipping auto-install.`));
|
|
193
|
-
console.log(pc.yellow(` Please manually install: ${installCmd} ${missingDeps.join(" ")}\n`));
|
|
194
|
-
resolve();
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
282
|
+
let css = readFileSync(globalsPath, "utf8");
|
|
283
|
+
const directive = `@plugin "${plugin}";`;
|
|
284
|
+
if (css.includes(directive)) {
|
|
285
|
+
console.log(pc.dim(` ↳ ${plugin} already registered in ${path.basename(globalsPath)}`));
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
197
288
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
289
|
+
// Insert after the last @import line
|
|
290
|
+
const lines = css.split("\n");
|
|
291
|
+
let lastImportIdx = -1;
|
|
292
|
+
lines.forEach((line, i) => {
|
|
293
|
+
if (line.trimStart().startsWith("@import")) lastImportIdx = i;
|
|
294
|
+
});
|
|
202
295
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const confirmed = answer.trim().toLowerCase() !== "n";
|
|
206
|
-
|
|
207
|
-
if (confirmed) {
|
|
208
|
-
console.log(pc.dim(" Automatically installing dependencies..."));
|
|
209
|
-
try {
|
|
210
|
-
execSync(`${installCmd} ${missingDeps.join(" ")}`, {
|
|
211
|
-
stdio: "inherit",
|
|
212
|
-
cwd: projectRoot,
|
|
213
|
-
shell: process.platform === "win32"
|
|
214
|
-
});
|
|
215
|
-
console.log(pc.green(` ✅ Successfully installed: ${missingDeps.join(", ")}\n`));
|
|
216
|
-
} catch (err) {
|
|
217
|
-
console.log(pc.red(` ❌ Auto-installation failed: ${err.message}`));
|
|
218
|
-
console.log(pc.yellow(` Please manually install: ${installCmd} ${missingDeps.join(" ")}\n`));
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
console.log(pc.blue(" Skipped installation."));
|
|
222
|
-
console.log(pc.yellow(` Please manually install: ${installCmd} ${missingDeps.join(" ")}\n`));
|
|
223
|
-
}
|
|
224
|
-
resolve();
|
|
225
|
-
});
|
|
296
|
+
if (lastImportIdx !== -1) {
|
|
297
|
+
lines.splice(lastImportIdx + 1, 0, directive);
|
|
226
298
|
} else {
|
|
227
|
-
|
|
299
|
+
lines.unshift(directive);
|
|
228
300
|
}
|
|
229
|
-
|
|
301
|
+
|
|
302
|
+
writeFileSync(globalsPath, lines.join("\n"), "utf8");
|
|
303
|
+
console.log(pc.green(` ✅ Registered @plugin "${plugin}" in ${path.basename(globalsPath)}`));
|
|
304
|
+
}
|
|
230
305
|
}
|
|
231
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Applies the ForgeWP "sharp" neo-brutalist aesthetic transform to a component file.
|
|
309
|
+
* Replaces all Tailwind rounding utilities with `rounded-none`.
|
|
310
|
+
* Used only when the project's wp.config.ts sets style: "forgewp".
|
|
311
|
+
*/
|
|
312
|
+
function sharpenFile(filePath) {
|
|
313
|
+
let content = readFileSync(filePath, "utf8");
|
|
314
|
+
|
|
315
|
+
const sharpened = content.replace(
|
|
316
|
+
/(?:\b|['"\s])([a-z0-9-:]+)?rounded(-[a-z0-9\[\]]+)?(?=["'\s])/g,
|
|
317
|
+
(match) => {
|
|
318
|
+
if (match.includes("rounded")) {
|
|
319
|
+
const cleanPrefix = match.split("rounded")[0];
|
|
320
|
+
return `${cleanPrefix}rounded-none`;
|
|
321
|
+
}
|
|
322
|
+
return match;
|
|
323
|
+
}
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
if (content !== sharpened) {
|
|
327
|
+
writeFileSync(filePath, sharpened, "utf8");
|
|
328
|
+
console.log(pc.dim(` Sharpened ${path.basename(filePath)}`));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js ESM Loader hook to intercept and mock static asset imports (images, styles, fonts)
|
|
3
|
+
* during server-side theme compilation.
|
|
4
|
+
*/
|
|
5
|
+
export async function load(url, context, defaultLoad) {
|
|
6
|
+
const cleanUrl = url.split('?')[0].split('#')[0];
|
|
7
|
+
if (
|
|
8
|
+
cleanUrl.endsWith('.css') ||
|
|
9
|
+
cleanUrl.endsWith('.png') ||
|
|
10
|
+
cleanUrl.endsWith('.jpg') ||
|
|
11
|
+
cleanUrl.endsWith('.jpeg') ||
|
|
12
|
+
cleanUrl.endsWith('.webp') ||
|
|
13
|
+
cleanUrl.endsWith('.svg') ||
|
|
14
|
+
cleanUrl.endsWith('.gif') ||
|
|
15
|
+
cleanUrl.endsWith('.woff') ||
|
|
16
|
+
cleanUrl.endsWith('.woff2') ||
|
|
17
|
+
cleanUrl.endsWith('.ttf') ||
|
|
18
|
+
cleanUrl.endsWith('.eot')
|
|
19
|
+
) {
|
|
20
|
+
return {
|
|
21
|
+
format: 'module',
|
|
22
|
+
source: 'export default "";',
|
|
23
|
+
shortCircuit: true,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return defaultLoad(url, context, defaultLoad);
|
|
27
|
+
}
|