@forgewp/compiler 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/bin/add.js +20 -14
- package/bin/cli.js +145 -70
- package/bin/doctor.js +21 -12
- package/bin/export.js +69 -20
- package/bin/fresh.js +5 -0
- package/bin/i18n-extract.js +3 -10
- package/bin/i18n-translate.js +15 -24
- package/bin/make-block.js +13 -0
- package/bin/make-editable.js +166 -0
- package/bin/make-form.js +131 -0
- package/bin/make-loop.js +40 -43
- package/bin/make-mail.js +27 -0
- package/bin/make-post-type.js +57 -29
- package/bin/make-sandbox.js +62 -11
- package/bin/make-section.js +221 -0
- package/bin/make-shell.js +375 -0
- package/bin/repair.js +14 -26
- package/bin/seed.js +119 -0
- package/bin/sync-routes.js +107 -85
- package/lib/adapters/html-adapter.js +5 -0
- package/lib/adapters/stub-adapter.js +4 -0
- package/lib/add-component.js +153 -92
- package/lib/asset-loader.js +313 -3
- package/lib/assets/asset-graph.js +432 -0
- package/lib/assets/asset-pipeline.js +125 -0
- package/lib/assets/diagnostics-report.js +345 -0
- package/lib/assets/external-fetcher.js +173 -0
- package/lib/assets/font-orchestrator.js +348 -0
- package/lib/assets/font-usage-scanner.js +242 -0
- package/lib/assets/image-optimizer.js +229 -0
- package/lib/assets/index.js +51 -0
- package/lib/assets/preload-generator.js +70 -0
- package/lib/assets/public-url.js +153 -0
- package/lib/block-authoring-help.js +11 -0
- package/lib/blocks/ast-parser.js +67 -0
- package/lib/blocks/discover-blocks.js +146 -0
- package/lib/blocks/editor-scope.js +733 -0
- package/lib/blocks/editor-transpiler.js +1229 -0
- package/lib/blocks/index.js +2838 -0
- package/lib/blocks/php-transpiler.js +4928 -0
- package/lib/blocks/scanner.js +1487 -0
- package/lib/blocks/shared-utils.js +290 -0
- package/lib/blocks/source-sanitize.js +1449 -0
- package/lib/blueprints.js +31 -91
- package/lib/build-assets.js +38 -33
- package/lib/collect-page-template-routes.js +102 -0
- package/lib/collect-static-routes.js +175 -0
- package/lib/diagnostics.js +58 -33
- package/lib/export-theme.js +84 -5
- package/lib/extract-template-content.js +90 -0
- package/lib/forms-preview.js +42 -0
- package/lib/functions/cpt-routing.js +69 -0
- package/lib/functions/forms.js +2461 -0
- package/lib/functions/hydration-enqueuer.js +400 -0
- package/lib/functions/index.js +1623 -0
- package/lib/functions/load-menus.js +112 -0
- package/lib/functions/load-translations.js +148 -0
- package/lib/functions/rest-endpoints.js +2923 -0
- package/lib/functions/routing.js +765 -0
- package/lib/functions/seed-mock-data.js +392 -0
- package/lib/functions/seed-products.js +481 -0
- package/lib/functions/settings-page.js +273 -0
- package/lib/functions/theme-setup.js +494 -0
- package/lib/generate-theme.js +1916 -339
- package/lib/hydration/editable-schemas.js +332 -0
- package/lib/hydration/enter-hidden-initial.js +65 -0
- package/lib/hydration/form-schemas.js +227 -0
- package/lib/hydration/index.js +12 -0
- package/lib/hydration/is-interactive.js +951 -0
- package/lib/hydration/island-split.js +1231 -0
- package/lib/hydration/islands-scanner.js +599 -0
- package/lib/hydration/resolve-island-chunk.js +103 -0
- package/lib/hydration/resolve-island-component.js +52 -0
- package/lib/hydration/rollup-inputs.js +81 -0
- package/lib/hydration/root-class-extractor.js +220 -0
- package/lib/hydration/scan-app-providers.js +154 -0
- package/lib/hydration/static-lint.js +382 -0
- package/lib/hydration/transform.js +257 -0
- package/lib/hydration/uses-block-area.js +49 -0
- package/lib/hydration/utils.js +119 -0
- package/lib/i18n/translation-cache.js +141 -0
- package/lib/icon-registry.js +72 -0
- package/lib/index.d.ts +287 -8
- package/lib/index.js +2 -1
- package/lib/load-config.js +338 -242
- package/lib/mail-templates.js +37 -0
- package/lib/markup-processor.js +388 -102
- package/lib/node-runtime.js +7 -0
- package/lib/page-config-plugin.js +64 -20
- package/lib/php-builders.js +383 -44
- package/lib/react-adapter.js +983 -235
- package/lib/registration-metadata.js +11 -0
- package/lib/render-theme.mts +1410 -616
- package/lib/route-layout.js +76 -0
- package/lib/template-discovery.js +58 -0
- package/lib/theme-compatibility.js +32 -0
- package/lib/validate-export.js +2 -2
- package/lib/validate.js +27 -5
- package/lib/virtual-plugin.js +319 -0
- package/lib/walkthrough.md +26 -0
- package/package.json +16 -5
- package/templates/auth/cms/email-logs.json +9 -0
- package/templates/auth/cms/menus.json +11 -0
- package/templates/auth/cms/mock-data.json +123 -0
- package/templates/auth/cms/roles.json +7 -0
- package/templates/auth/cms/sessions.json +1 -0
- package/templates/auth/cms/site-settings.json +28 -0
- package/templates/auth/cms/translations.json +4 -0
- package/templates/auth/cms/users.json +46 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +10 -2
- package/templates/auth/components/login-form-wrapper.tsx +118 -21
- package/templates/auth/components/reset-password-form-wrapper.tsx +10 -2
- package/templates/auth/components/signup-form-wrapper.tsx +2 -2
- package/templates/auth/components/verify-email-view-wrapper.tsx +5 -5
- package/templates/auth/pages/DashboardPage.tsx +1 -4
- package/templates/auth/pages/ForgotPasswordPage.tsx +1 -4
- package/templates/auth/pages/LoginPage.tsx +1 -4
- package/templates/auth/pages/ResetPasswordPage.tsx +1 -4
- package/templates/auth/pages/SignUpPage.tsx +1 -4
- package/templates/auth/pages/VerifyEmailPage.tsx +1 -4
- package/templates/auth/ui/button.tsx +57 -0
- package/templates/auth/ui/card.tsx +76 -0
- package/templates/auth/ui/field.tsx +242 -0
- package/templates/auth/ui/input.tsx +22 -0
- package/templates/auth/ui/label.tsx +24 -0
- package/templates/auth/ui/separator.tsx +31 -0
- package/templates/menus.json +12 -10
- package/templates/users.json +8 -4
- package/templates/wordpress.tsx +690 -245
- package/lib/block-compiler.js +0 -552
- package/lib/functions-builder.js +0 -2970
- package/lib/hydration-scanner.js +0 -833
package/lib/add-component.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { execSync } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import {
|
|
3
|
+
readFileSync,
|
|
4
|
+
writeFileSync,
|
|
5
|
+
readdirSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
} from 'node:fs';
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import pc from 'picocolors';
|
|
7
13
|
|
|
8
14
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
9
15
|
// CONSTANTS
|
|
@@ -15,25 +21,25 @@ import pc from "picocolors";
|
|
|
15
21
|
* It points to the standard ForgeWP project layout.
|
|
16
22
|
*/
|
|
17
23
|
const SHADCN_COMPONENTS_JSON = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
$schema: 'https://ui.shadcn.com/schema.json',
|
|
25
|
+
style: 'new-york',
|
|
26
|
+
rsc: false,
|
|
27
|
+
tsx: true,
|
|
28
|
+
tailwind: {
|
|
29
|
+
config: 'tailwind.config.js',
|
|
30
|
+
css: 'src/app/globals.css',
|
|
31
|
+
baseColor: 'zinc',
|
|
32
|
+
cssVariables: true,
|
|
33
|
+
prefix: '',
|
|
28
34
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
aliases: {
|
|
36
|
+
components: '@/components',
|
|
37
|
+
utils: '@/lib/utils',
|
|
38
|
+
ui: '@/components/ui',
|
|
39
|
+
lib: '@/lib',
|
|
40
|
+
hooks: '@/hooks',
|
|
35
41
|
},
|
|
36
|
-
|
|
42
|
+
iconLibrary: 'lucide',
|
|
37
43
|
};
|
|
38
44
|
|
|
39
45
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -56,11 +62,28 @@ const SHADCN_COMPONENTS_JSON = {
|
|
|
56
62
|
* 4. If style === "forgewp", apply the neo-brutalist sharpening transform.
|
|
57
63
|
*
|
|
58
64
|
* @param {string} component - The component name (e.g. "sheet", "navbar").
|
|
59
|
-
* @param {{ style?: "shadcn" | "forgewp" }} options
|
|
65
|
+
* @param {{ style?: "shadcn" | "forgewp", overwrite?: boolean }} options
|
|
60
66
|
*/
|
|
61
67
|
export async function addComponent(component, options) {
|
|
62
|
-
const { style =
|
|
68
|
+
const { style = 'shadcn', overwrite = false } = options || {};
|
|
63
69
|
const projectRoot = process.cwd();
|
|
70
|
+
const localRegistry = resolveLocalRegistry(component);
|
|
71
|
+
const hasLocalOverride =
|
|
72
|
+
localRegistry !== null && existsSync(localRegistry.tsxPath);
|
|
73
|
+
const targetFile = path.join(
|
|
74
|
+
projectRoot,
|
|
75
|
+
'src',
|
|
76
|
+
'components',
|
|
77
|
+
'ui',
|
|
78
|
+
`${component}.tsx`,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
if (hasLocalOverride && existsSync(targetFile) && !overwrite) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`ForgeWP component "${component}" already exists at src/components/ui/${component}.tsx. ` +
|
|
84
|
+
`Your file was left unchanged. Use --overwrite to replace it with the registry version.`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
64
87
|
|
|
65
88
|
console.log(pc.cyan(`\n ForgeWP add — ${component}\n`));
|
|
66
89
|
|
|
@@ -70,17 +93,13 @@ export async function addComponent(component, options) {
|
|
|
70
93
|
// ── Step 2: Detect package manager ────────────────────────────────────────
|
|
71
94
|
const { installCmd, shadcnCmd } = detectPackageManager(projectRoot);
|
|
72
95
|
|
|
73
|
-
// ── Step 3:
|
|
74
|
-
const localRegistry = resolveLocalRegistry(component);
|
|
75
|
-
const hasLocalOverride = localRegistry !== null && existsSync(localRegistry.tsxPath);
|
|
76
|
-
|
|
77
|
-
// ── Step 4: Run shadcn add (primary install source for everything) ─────────
|
|
96
|
+
// ── Step 3: Run shadcn add (primary install source for everything) ─────────
|
|
78
97
|
console.log(pc.dim(` Installing ${component} via shadcn...`));
|
|
79
98
|
try {
|
|
80
99
|
execSync(`${shadcnCmd} add ${component} --yes`, {
|
|
81
|
-
stdio:
|
|
100
|
+
stdio: 'inherit',
|
|
82
101
|
cwd: projectRoot,
|
|
83
|
-
shell: process.platform ===
|
|
102
|
+
shell: process.platform === 'win32',
|
|
84
103
|
});
|
|
85
104
|
} catch (err) {
|
|
86
105
|
// shadcn may fail for ForgeWP-native components not in the shadcn registry.
|
|
@@ -88,43 +107,54 @@ export async function addComponent(component, options) {
|
|
|
88
107
|
if (!hasLocalOverride) {
|
|
89
108
|
throw new Error(
|
|
90
109
|
`Failed to install "${component}" via shadcn, and no ForgeWP local override exists.\n` +
|
|
91
|
-
|
|
110
|
+
`Details: ${err.message}`,
|
|
92
111
|
);
|
|
93
112
|
}
|
|
94
|
-
console.log(
|
|
113
|
+
console.log(
|
|
114
|
+
pc.yellow(
|
|
115
|
+
` ⚠ shadcn does not know "${component}" — using ForgeWP local registry instead.`,
|
|
116
|
+
),
|
|
117
|
+
);
|
|
95
118
|
}
|
|
96
119
|
|
|
97
120
|
// ── Step 5: Install ForgeWP local override (if present) ───────────────────
|
|
98
121
|
if (hasLocalOverride) {
|
|
99
122
|
console.log(pc.dim(` Applying ForgeWP override for ${component}...`));
|
|
100
123
|
|
|
101
|
-
const targetDir = path.join(projectRoot,
|
|
124
|
+
const targetDir = path.join(projectRoot, 'src', 'components', 'ui');
|
|
102
125
|
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
|
|
103
126
|
|
|
104
127
|
const targetFile = path.join(targetDir, `${component}.tsx`);
|
|
105
|
-
const content = readFileSync(localRegistry.tsxPath,
|
|
106
|
-
writeFileSync(targetFile, content,
|
|
128
|
+
const content = readFileSync(localRegistry.tsxPath, 'utf8');
|
|
129
|
+
writeFileSync(targetFile, content, 'utf8');
|
|
107
130
|
|
|
108
131
|
// Install any extra Tailwind plugins declared in the ForgeWP registry.json
|
|
109
132
|
// that shadcn's remote registry wouldn't know about (ForgeWP-native components).
|
|
110
133
|
if (localRegistry.meta?.tailwindPlugins?.length > 0) {
|
|
111
|
-
await ensureTailwindPlugins(
|
|
134
|
+
await ensureTailwindPlugins(
|
|
135
|
+
localRegistry.meta.tailwindPlugins,
|
|
136
|
+
installCmd,
|
|
137
|
+
projectRoot,
|
|
138
|
+
);
|
|
112
139
|
}
|
|
113
140
|
|
|
114
|
-
console.log(
|
|
141
|
+
console.log(
|
|
142
|
+
pc.dim(` ↳ Override written to src/components/ui/${component}.tsx`),
|
|
143
|
+
);
|
|
115
144
|
}
|
|
116
145
|
|
|
117
146
|
// ── Step 6: Apply ForgeWP sharpening (when style === "forgewp") ────────────
|
|
118
|
-
if (style ===
|
|
119
|
-
const uiDir = path.join(projectRoot,
|
|
147
|
+
if (style === 'forgewp') {
|
|
148
|
+
const uiDir = path.join(projectRoot, 'src', 'components', 'ui');
|
|
120
149
|
if (existsSync(uiDir)) {
|
|
121
|
-
const files = readdirSync(uiDir).filter(
|
|
122
|
-
f
|
|
123
|
-
|
|
150
|
+
const files = readdirSync(uiDir).filter(
|
|
151
|
+
(f) =>
|
|
152
|
+
f.toLowerCase().includes(component.toLowerCase().replace(/-/g, '')) ||
|
|
153
|
+
f.toLowerCase().includes(component.toLowerCase()),
|
|
124
154
|
);
|
|
125
155
|
const targets = files.length > 0 ? files : readdirSync(uiDir);
|
|
126
|
-
targets.forEach(f => {
|
|
127
|
-
if (f.endsWith(
|
|
156
|
+
targets.forEach((f) => {
|
|
157
|
+
if (f.endsWith('.tsx')) sharpenFile(path.join(uiDir, f));
|
|
128
158
|
});
|
|
129
159
|
}
|
|
130
160
|
}
|
|
@@ -142,15 +172,27 @@ export async function addComponent(component, options) {
|
|
|
142
172
|
* without requiring the developer to run `shadcn init` manually.
|
|
143
173
|
*/
|
|
144
174
|
function ensureComponentsJson(projectRoot) {
|
|
145
|
-
const targetPath = path.join(projectRoot,
|
|
175
|
+
const targetPath = path.join(projectRoot, 'components.json');
|
|
146
176
|
if (existsSync(targetPath)) return;
|
|
147
177
|
|
|
148
178
|
try {
|
|
149
|
-
writeFileSync(
|
|
150
|
-
|
|
179
|
+
writeFileSync(
|
|
180
|
+
targetPath,
|
|
181
|
+
JSON.stringify(SHADCN_COMPONENTS_JSON, null, 2),
|
|
182
|
+
'utf8',
|
|
183
|
+
);
|
|
184
|
+
console.log(
|
|
185
|
+
pc.green(` ✅ Created components.json (shadcn configuration)`),
|
|
186
|
+
);
|
|
151
187
|
} catch (err) {
|
|
152
|
-
console.log(
|
|
153
|
-
|
|
188
|
+
console.log(
|
|
189
|
+
pc.yellow(` ⚠ Could not create components.json: ${err.message}`),
|
|
190
|
+
);
|
|
191
|
+
console.log(
|
|
192
|
+
pc.yellow(
|
|
193
|
+
` Run "pnpm dlx shadcn@latest init" to initialize shadcn manually.`,
|
|
194
|
+
),
|
|
195
|
+
);
|
|
154
196
|
}
|
|
155
197
|
}
|
|
156
198
|
|
|
@@ -159,24 +201,24 @@ function ensureComponentsJson(projectRoot) {
|
|
|
159
201
|
* the appropriate install and shadcn CLI commands.
|
|
160
202
|
*/
|
|
161
203
|
function detectPackageManager(projectRoot) {
|
|
162
|
-
let installCmd =
|
|
163
|
-
let shadcnCmd =
|
|
204
|
+
let installCmd = 'npm install --save-dev';
|
|
205
|
+
let shadcnCmd = 'npx shadcn@latest';
|
|
164
206
|
|
|
165
207
|
let current = projectRoot;
|
|
166
208
|
while (current) {
|
|
167
|
-
if (existsSync(path.join(current,
|
|
168
|
-
installCmd =
|
|
169
|
-
shadcnCmd =
|
|
209
|
+
if (existsSync(path.join(current, 'pnpm-lock.yaml'))) {
|
|
210
|
+
installCmd = 'pnpm add -D';
|
|
211
|
+
shadcnCmd = 'pnpm dlx shadcn@latest';
|
|
170
212
|
break;
|
|
171
213
|
}
|
|
172
|
-
if (existsSync(path.join(current,
|
|
173
|
-
installCmd =
|
|
174
|
-
shadcnCmd =
|
|
214
|
+
if (existsSync(path.join(current, 'yarn.lock'))) {
|
|
215
|
+
installCmd = 'yarn add -D';
|
|
216
|
+
shadcnCmd = 'yarn dlx shadcn@latest';
|
|
175
217
|
break;
|
|
176
218
|
}
|
|
177
|
-
if (existsSync(path.join(current,
|
|
178
|
-
installCmd =
|
|
179
|
-
shadcnCmd =
|
|
219
|
+
if (existsSync(path.join(current, 'bun.lockb'))) {
|
|
220
|
+
installCmd = 'bun add -d';
|
|
221
|
+
shadcnCmd = 'bunx --bun shadcn@latest';
|
|
180
222
|
break;
|
|
181
223
|
}
|
|
182
224
|
const parent = path.dirname(current);
|
|
@@ -199,27 +241,27 @@ function resolveLocalRegistry(component) {
|
|
|
199
241
|
try {
|
|
200
242
|
const req = createRequire(import.meta.url);
|
|
201
243
|
registryBase = path.join(
|
|
202
|
-
path.dirname(req.resolve(
|
|
203
|
-
|
|
244
|
+
path.dirname(req.resolve('@forgewp/ui/package.json')),
|
|
245
|
+
'components',
|
|
204
246
|
);
|
|
205
247
|
} catch {
|
|
206
248
|
// Fallback for local monorepo development
|
|
207
249
|
registryBase = path.resolve(
|
|
208
250
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
209
|
-
|
|
251
|
+
'../../ui/components',
|
|
210
252
|
);
|
|
211
253
|
}
|
|
212
254
|
|
|
213
255
|
const componentDir = path.join(registryBase, component);
|
|
214
|
-
const tsxPath = path.join(componentDir,
|
|
215
|
-
const registryPath = path.join(componentDir,
|
|
256
|
+
const tsxPath = path.join(componentDir, 'forgewp.tsx');
|
|
257
|
+
const registryPath = path.join(componentDir, 'registry.json');
|
|
216
258
|
|
|
217
259
|
if (!existsSync(tsxPath) && !existsSync(registryPath)) return null;
|
|
218
260
|
|
|
219
261
|
let meta = {};
|
|
220
262
|
if (existsSync(registryPath)) {
|
|
221
263
|
try {
|
|
222
|
-
meta = JSON.parse(readFileSync(registryPath,
|
|
264
|
+
meta = JSON.parse(readFileSync(registryPath, 'utf8'));
|
|
223
265
|
} catch {
|
|
224
266
|
// Malformed registry.json — proceed with empty meta
|
|
225
267
|
}
|
|
@@ -241,56 +283,71 @@ function resolveLocalRegistry(component) {
|
|
|
241
283
|
* @param {string} projectRoot
|
|
242
284
|
*/
|
|
243
285
|
async function ensureTailwindPlugins(plugins, installCmd, projectRoot) {
|
|
244
|
-
const pkgJsonPath = path.join(projectRoot,
|
|
286
|
+
const pkgJsonPath = path.join(projectRoot, 'package.json');
|
|
245
287
|
if (!existsSync(pkgJsonPath)) return;
|
|
246
288
|
|
|
247
|
-
const pkg = JSON.parse(readFileSync(pkgJsonPath,
|
|
248
|
-
const currentDeps = {
|
|
289
|
+
const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
|
|
290
|
+
const currentDeps = {
|
|
291
|
+
...(pkg.dependencies || {}),
|
|
292
|
+
...(pkg.devDependencies || {}),
|
|
293
|
+
};
|
|
249
294
|
|
|
250
295
|
for (const plugin of plugins) {
|
|
251
296
|
// Install if missing
|
|
252
297
|
if (!currentDeps[plugin]) {
|
|
253
|
-
console.log(
|
|
298
|
+
console.log(
|
|
299
|
+
pc.yellow(`\n ⚡ Requires Tailwind plugin: ${pc.bold(plugin)}`),
|
|
300
|
+
);
|
|
254
301
|
try {
|
|
255
302
|
execSync(`${installCmd} ${plugin}`, {
|
|
256
|
-
stdio:
|
|
303
|
+
stdio: 'inherit',
|
|
257
304
|
cwd: projectRoot,
|
|
258
|
-
shell: process.platform ===
|
|
305
|
+
shell: process.platform === 'win32',
|
|
259
306
|
});
|
|
260
307
|
console.log(pc.green(` ✅ Installed ${plugin}`));
|
|
261
308
|
} catch (err) {
|
|
262
309
|
console.log(pc.red(` ❌ Failed to install ${plugin}: ${err.message}`));
|
|
263
|
-
console.log(
|
|
310
|
+
console.log(
|
|
311
|
+
pc.yellow(` Please manually run: ${installCmd} ${plugin}\n`),
|
|
312
|
+
);
|
|
264
313
|
continue;
|
|
265
314
|
}
|
|
266
315
|
}
|
|
267
316
|
|
|
268
317
|
// Register @plugin in globals.css if not already present
|
|
269
318
|
const cssSearchPaths = [
|
|
270
|
-
path.join(projectRoot,
|
|
271
|
-
path.join(projectRoot,
|
|
272
|
-
path.join(projectRoot,
|
|
273
|
-
path.join(projectRoot,
|
|
319
|
+
path.join(projectRoot, 'src', 'app', 'globals.css'),
|
|
320
|
+
path.join(projectRoot, 'src', 'styles', 'globals.css'),
|
|
321
|
+
path.join(projectRoot, 'src', 'index.css'),
|
|
322
|
+
path.join(projectRoot, 'src', 'global.css'),
|
|
274
323
|
];
|
|
275
324
|
|
|
276
|
-
const globalsPath = cssSearchPaths.find(p => existsSync(p));
|
|
325
|
+
const globalsPath = cssSearchPaths.find((p) => existsSync(p));
|
|
277
326
|
if (!globalsPath) {
|
|
278
|
-
console.log(
|
|
327
|
+
console.log(
|
|
328
|
+
pc.yellow(
|
|
329
|
+
` ⚠ Could not find globals.css. Add manually: @plugin "${plugin}";`,
|
|
330
|
+
),
|
|
331
|
+
);
|
|
279
332
|
continue;
|
|
280
333
|
}
|
|
281
334
|
|
|
282
|
-
let css = readFileSync(globalsPath,
|
|
335
|
+
let css = readFileSync(globalsPath, 'utf8');
|
|
283
336
|
const directive = `@plugin "${plugin}";`;
|
|
284
337
|
if (css.includes(directive)) {
|
|
285
|
-
console.log(
|
|
338
|
+
console.log(
|
|
339
|
+
pc.dim(
|
|
340
|
+
` ↳ ${plugin} already registered in ${path.basename(globalsPath)}`,
|
|
341
|
+
),
|
|
342
|
+
);
|
|
286
343
|
continue;
|
|
287
344
|
}
|
|
288
345
|
|
|
289
346
|
// Insert after the last @import line
|
|
290
|
-
const lines = css.split(
|
|
347
|
+
const lines = css.split('\n');
|
|
291
348
|
let lastImportIdx = -1;
|
|
292
349
|
lines.forEach((line, i) => {
|
|
293
|
-
if (line.trimStart().startsWith(
|
|
350
|
+
if (line.trimStart().startsWith('@import')) lastImportIdx = i;
|
|
294
351
|
});
|
|
295
352
|
|
|
296
353
|
if (lastImportIdx !== -1) {
|
|
@@ -299,8 +356,12 @@ async function ensureTailwindPlugins(plugins, installCmd, projectRoot) {
|
|
|
299
356
|
lines.unshift(directive);
|
|
300
357
|
}
|
|
301
358
|
|
|
302
|
-
writeFileSync(globalsPath, lines.join(
|
|
303
|
-
console.log(
|
|
359
|
+
writeFileSync(globalsPath, lines.join('\n'), 'utf8');
|
|
360
|
+
console.log(
|
|
361
|
+
pc.green(
|
|
362
|
+
` ✅ Registered @plugin "${plugin}" in ${path.basename(globalsPath)}`,
|
|
363
|
+
),
|
|
364
|
+
);
|
|
304
365
|
}
|
|
305
366
|
}
|
|
306
367
|
|
|
@@ -310,21 +371,21 @@ async function ensureTailwindPlugins(plugins, installCmd, projectRoot) {
|
|
|
310
371
|
* Used only when the project's wp.config.ts sets style: "forgewp".
|
|
311
372
|
*/
|
|
312
373
|
function sharpenFile(filePath) {
|
|
313
|
-
let content = readFileSync(filePath,
|
|
374
|
+
let content = readFileSync(filePath, 'utf8');
|
|
314
375
|
|
|
315
376
|
const sharpened = content.replace(
|
|
316
377
|
/(?:\b|['"\s])([a-z0-9-:]+)?rounded(-[a-z0-9\[\]]+)?(?=["'\s])/g,
|
|
317
378
|
(match) => {
|
|
318
|
-
if (match.includes(
|
|
319
|
-
const cleanPrefix = match.split(
|
|
379
|
+
if (match.includes('rounded')) {
|
|
380
|
+
const cleanPrefix = match.split('rounded')[0];
|
|
320
381
|
return `${cleanPrefix}rounded-none`;
|
|
321
382
|
}
|
|
322
383
|
return match;
|
|
323
|
-
}
|
|
384
|
+
},
|
|
324
385
|
);
|
|
325
386
|
|
|
326
387
|
if (content !== sharpened) {
|
|
327
|
-
writeFileSync(filePath, sharpened,
|
|
388
|
+
writeFileSync(filePath, sharpened, 'utf8');
|
|
328
389
|
console.log(pc.dim(` Sharpened ${path.basename(filePath)}`));
|
|
329
390
|
}
|
|
330
391
|
}
|