@forgewp/compiler 0.4.2 → 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 +70 -3
- package/bin/add.js +30 -15
- package/bin/analyze.js +66 -1
- package/bin/cli.js +149 -70
- package/bin/doctor.js +21 -12
- package/bin/export.js +69 -20
- package/bin/fresh.js +6 -1
- package/bin/i18n-extract.js +3 -10
- package/bin/i18n-translate.js +15 -24
- package/bin/make-block.js +24 -0
- package/bin/make-editable.js +166 -0
- package/bin/make-form.js +131 -0
- package/bin/make-island.js +11 -0
- package/bin/make-loop.js +147 -0
- package/bin/make-mail.js +27 -0
- package/bin/make-page.js +83 -0
- package/bin/make-post-type.js +68 -29
- package/bin/make-sandbox.js +609 -0
- 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 +13 -3
- package/lib/adapters/stub-adapter.js +10 -2
- package/lib/add-component.js +153 -92
- package/lib/asset-loader.js +333 -1
- 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 +77 -5
- 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 +2076 -303
- 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 +324 -8
- package/lib/index.js +3 -2
- package/lib/load-config.js +338 -144
- package/lib/mail-templates.js +37 -0
- package/lib/markup-processor.js +483 -92
- package/lib/node-runtime.js +7 -0
- package/lib/page-config-plugin.js +84 -0
- package/lib/php-builders.js +383 -42
- package/lib/react-adapter.js +1053 -246
- package/lib/registration-metadata.js +11 -0
- package/lib/render-theme.mts +1410 -543
- 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 +51 -2
- package/lib/validate.js +27 -5
- package/lib/virtual-plugin.js +319 -0
- package/lib/walkthrough.md +26 -0
- package/package.json +17 -5
- package/templates/PresetsStyle.tsx +1 -1
- 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/dashboard-view-wrapper.tsx +168 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +141 -0
- package/templates/auth/components/login-form-wrapper.tsx +300 -0
- package/templates/auth/components/reset-password-form-wrapper.tsx +190 -0
- package/templates/auth/components/signup-form-wrapper.tsx +257 -0
- package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
- package/templates/auth/pages/DashboardPage.tsx +12 -0
- package/templates/auth/pages/ForgotPasswordPage.tsx +11 -0
- package/templates/auth/pages/LoginPage.tsx +11 -0
- package/templates/auth/pages/ResetPasswordPage.tsx +11 -0
- package/templates/auth/pages/SignUpPage.tsx +11 -0
- package/templates/auth/pages/VerifyEmailPage.tsx +11 -0
- 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/forgewp-config.ts +70 -3
- package/templates/menus.json +12 -10
- package/templates/mock-data.json +122 -433
- package/templates/products.json +5 -0
- package/templates/roles.json +7 -0
- package/templates/sessions.json +1 -0
- package/templates/users.json +38 -0
- package/templates/wordpress.tsx +1835 -1297
- package/bin/make-template.js +0 -145
- package/lib/block-compiler.js +0 -552
- package/lib/functions-builder.js +0 -2044
- package/lib/hydration-scanner.js +0 -821
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover Gutenberg blocks already defined in a theme (defineBlock + @forgewp-block).
|
|
3
|
+
* Used by make:shell to offer child block multi-select.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { parseDefineBlock, parseJsdocMetaLine } from "./scanner.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {{ name: string, title: string, category: string, isShell: boolean, source: string, file: string }} DiscoveredBlock
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} themeRoot
|
|
15
|
+
* @param {{ includeShells?: boolean }} [options]
|
|
16
|
+
* @returns {DiscoveredBlock[]}
|
|
17
|
+
*/
|
|
18
|
+
export function discoverProjectBlocks(themeRoot, options = {}) {
|
|
19
|
+
const { includeShells = false } = options;
|
|
20
|
+
const srcDir = path.join(themeRoot, "src");
|
|
21
|
+
if (!existsSync(srcDir)) return [];
|
|
22
|
+
|
|
23
|
+
const files = [];
|
|
24
|
+
function collect(dir) {
|
|
25
|
+
if (!existsSync(dir)) return;
|
|
26
|
+
for (const item of readdirSync(dir, { withFileTypes: true })) {
|
|
27
|
+
const full = path.join(dir, item.name);
|
|
28
|
+
if (item.isDirectory()) {
|
|
29
|
+
if (
|
|
30
|
+
["node_modules", ".forgewp", "dist", ".git", "out"].includes(item.name)
|
|
31
|
+
) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
// Still walk generated/ — those are real blocks
|
|
35
|
+
collect(full);
|
|
36
|
+
} else if (
|
|
37
|
+
item.isFile() &&
|
|
38
|
+
(item.name.endsWith(".tsx") || item.name.endsWith(".jsx"))
|
|
39
|
+
) {
|
|
40
|
+
files.push(full);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
collect(srcDir);
|
|
45
|
+
|
|
46
|
+
/** @type {Map<string, DiscoveredBlock>} */
|
|
47
|
+
const byName = new Map();
|
|
48
|
+
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
let content;
|
|
51
|
+
try {
|
|
52
|
+
content = readFileSync(file, "utf8");
|
|
53
|
+
} catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// defineBlock({ ... })
|
|
58
|
+
if (content.includes("defineBlock(")) {
|
|
59
|
+
const rel = path.relative(themeRoot, file);
|
|
60
|
+
const slugGuess = path.basename(file, path.extname(file))
|
|
61
|
+
.replace(/Block$/i, "")
|
|
62
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
63
|
+
.toLowerCase()
|
|
64
|
+
.replace(/[^a-z0-9]+/g, "-");
|
|
65
|
+
const parsed = parseDefineBlock(content, slugGuess);
|
|
66
|
+
if (parsed && parsed.name) {
|
|
67
|
+
const name = stripNs(String(parsed.name));
|
|
68
|
+
const isShell = !!(parsed.innerBlocks && typeof parsed.innerBlocks === "object");
|
|
69
|
+
if (!includeShells && isShell) {
|
|
70
|
+
// still record shells when includeShells; skip leaf filter later
|
|
71
|
+
}
|
|
72
|
+
byName.set(name, {
|
|
73
|
+
name,
|
|
74
|
+
title: String(parsed.title || name),
|
|
75
|
+
category: String(parsed.category || "design"),
|
|
76
|
+
isShell,
|
|
77
|
+
source: "defineBlock",
|
|
78
|
+
file: rel,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// @forgewp-block annotated components (generated into blocks/generated)
|
|
84
|
+
if (content.includes("@forgewp-block")) {
|
|
85
|
+
const blockRegex =
|
|
86
|
+
/\/\*\*((?:(?!\*\/)[\s\S])*?@forgewp-block(?:(?!\*\/)[\s\S])*?)\*\/[\s\r\n]*(?:export\s+(?:interface|type)\s+[A-Za-z0-9_$-]+\s*=?\s*\{[\s\S]*?\}[\s\r\n]*)?export\s+(?:default\s+)?(?:function|const)\s+([A-Za-z0-9_$-]+)/g;
|
|
87
|
+
let match;
|
|
88
|
+
while ((match = blockRegex.exec(content)) !== null) {
|
|
89
|
+
const jsdoc = match[1];
|
|
90
|
+
const compName = match[2];
|
|
91
|
+
if (!jsdoc.includes("@forgewp-block")) continue;
|
|
92
|
+
const name = compName
|
|
93
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
94
|
+
.toLowerCase()
|
|
95
|
+
.replace(/[^a-z0-9]+/g, "-");
|
|
96
|
+
// Prefer explicit defineBlock entries if both exist
|
|
97
|
+
if (byName.has(name)) continue;
|
|
98
|
+
byName.set(name, {
|
|
99
|
+
name,
|
|
100
|
+
title: parseJsdocMetaLine(jsdoc, "title") || compName,
|
|
101
|
+
category: parseJsdocMetaLine(jsdoc, "category") || "design",
|
|
102
|
+
isShell: false,
|
|
103
|
+
source: "@forgewp-block",
|
|
104
|
+
file: path.relative(themeRoot, file),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let list = Array.from(byName.values());
|
|
111
|
+
if (!includeShells) {
|
|
112
|
+
list = list.filter((b) => !b.isShell);
|
|
113
|
+
}
|
|
114
|
+
list.sort((a, b) => a.name.localeCompare(b.name));
|
|
115
|
+
return list;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function stripNs(name) {
|
|
119
|
+
if (!name) return name;
|
|
120
|
+
return name.includes("/") ? name.split("/").pop() : name;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Layout presets for shell.gridClassName
|
|
125
|
+
*/
|
|
126
|
+
export const SHELL_LAYOUT_PRESETS = {
|
|
127
|
+
"2-col": {
|
|
128
|
+
label: "Two columns (responsive)",
|
|
129
|
+
gridClassName:
|
|
130
|
+
"grid grid-cols-1 lg:grid-cols-2 gap-12 items-center",
|
|
131
|
+
orientation: "horizontal",
|
|
132
|
+
},
|
|
133
|
+
"3-col": {
|
|
134
|
+
label: "Three columns (responsive)",
|
|
135
|
+
gridClassName: "grid grid-cols-1 md:grid-cols-3 gap-8",
|
|
136
|
+
orientation: "horizontal",
|
|
137
|
+
},
|
|
138
|
+
stack: {
|
|
139
|
+
label: "Vertical stack",
|
|
140
|
+
gridClassName: "flex flex-col gap-8",
|
|
141
|
+
orientation: "vertical",
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const DEFAULT_SHELL_CLASSNAME =
|
|
146
|
+
"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-16";
|