@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,112 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseSource, traverse } from '../blocks/ast-parser.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a Babel AST literal/object/array node to a JS value.
|
|
7
|
+
* Unwraps defineWpMenus({...}) (and other) call wrappers.
|
|
8
|
+
*/
|
|
9
|
+
function astToValue(node) {
|
|
10
|
+
if (!node) return null;
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'StringLiteral':
|
|
13
|
+
return node.value;
|
|
14
|
+
case 'NumericLiteral':
|
|
15
|
+
return node.value;
|
|
16
|
+
case 'BooleanLiteral':
|
|
17
|
+
return node.value;
|
|
18
|
+
case 'NullLiteral':
|
|
19
|
+
return null;
|
|
20
|
+
case 'ArrayExpression':
|
|
21
|
+
return node.elements.map((el) => astToValue(el));
|
|
22
|
+
case 'ObjectExpression': {
|
|
23
|
+
const obj = {};
|
|
24
|
+
for (const prop of node.properties) {
|
|
25
|
+
if (prop.type === 'ObjectProperty') {
|
|
26
|
+
const key = prop.key.name || prop.key.value;
|
|
27
|
+
obj[key] = astToValue(prop.value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
case 'UnaryExpression': {
|
|
33
|
+
if (node.operator === '-' && node.argument?.type === 'NumericLiteral') {
|
|
34
|
+
return -node.argument.value;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
case 'CallExpression': {
|
|
39
|
+
// Handles defineWpMenus({...}) wrapper
|
|
40
|
+
if (node.arguments && node.arguments[0]) {
|
|
41
|
+
return astToValue(node.arguments[0]);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
case 'TSAsExpression':
|
|
46
|
+
case 'TSSatisfiesExpression':
|
|
47
|
+
case 'TSTypeAssertion':
|
|
48
|
+
case 'TSNonNullExpression':
|
|
49
|
+
return astToValue(node.expression);
|
|
50
|
+
default:
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isMenuMap(value) {
|
|
56
|
+
return value && typeof value === 'object' && !Array.isArray(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Loads navigation menus from cms/menus.ts (preferred) or cms/menus.json.
|
|
61
|
+
* Matches the dual-resolution used for products/mock-data.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} themeRoot
|
|
64
|
+
* @returns {Record<string, Array<any>>}
|
|
65
|
+
*/
|
|
66
|
+
export function loadMenusData(themeRoot) {
|
|
67
|
+
const tsPath = path.join(themeRoot, 'cms', 'menus.ts');
|
|
68
|
+
const jsonPath = path.join(themeRoot, 'cms', 'menus.json');
|
|
69
|
+
|
|
70
|
+
if (fs.existsSync(tsPath)) {
|
|
71
|
+
try {
|
|
72
|
+
const code = fs.readFileSync(tsPath, 'utf8');
|
|
73
|
+
const ast = parseSource(code);
|
|
74
|
+
let extracted = null;
|
|
75
|
+
|
|
76
|
+
traverse(ast, {
|
|
77
|
+
ExportNamedDeclaration(astPath) {
|
|
78
|
+
const decl = astPath.node.declaration;
|
|
79
|
+
if (decl && decl.declarations) {
|
|
80
|
+
for (const d of decl.declarations) {
|
|
81
|
+
if (d.id?.name === 'menus' && d.init) {
|
|
82
|
+
extracted = astToValue(d.init);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
ExportDefaultDeclaration(astPath) {
|
|
88
|
+
if (!extracted && astPath.node.declaration) {
|
|
89
|
+
extracted = astToValue(astPath.node.declaration);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (isMenuMap(extracted)) return extracted;
|
|
95
|
+
if (extracted && isMenuMap(extracted.menus)) return extracted.menus;
|
|
96
|
+
} catch (e) {
|
|
97
|
+
console.warn(`⚠️ [ForgeWP Menus] Could not load ${tsPath}: ${e.message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (fs.existsSync(jsonPath)) {
|
|
102
|
+
try {
|
|
103
|
+
const raw = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
|
104
|
+
if (isMenuMap(raw)) return raw;
|
|
105
|
+
if (raw && isMenuMap(raw.menus)) return raw.menus;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.warn(`⚠️ [ForgeWP Menus] Could not parse ${jsonPath}: ${e.message}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseSource, traverse } from '../blocks/ast-parser.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a Babel AST literal/object/array node to a JS value.
|
|
7
|
+
* Unwraps defineTranslations({...}) (and other) call wrappers.
|
|
8
|
+
*/
|
|
9
|
+
function astToValue(node) {
|
|
10
|
+
if (!node) return null;
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'StringLiteral':
|
|
13
|
+
return node.value;
|
|
14
|
+
case 'NumericLiteral':
|
|
15
|
+
return node.value;
|
|
16
|
+
case 'BooleanLiteral':
|
|
17
|
+
return node.value;
|
|
18
|
+
case 'NullLiteral':
|
|
19
|
+
return null;
|
|
20
|
+
case 'ArrayExpression':
|
|
21
|
+
return node.elements.map((el) => astToValue(el));
|
|
22
|
+
case 'ObjectExpression': {
|
|
23
|
+
const obj = {};
|
|
24
|
+
for (const prop of node.properties) {
|
|
25
|
+
if (prop.type === 'ObjectProperty') {
|
|
26
|
+
const key = prop.key.name || prop.key.value;
|
|
27
|
+
obj[key] = astToValue(prop.value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
case 'UnaryExpression': {
|
|
33
|
+
if (node.operator === '-' && node.argument?.type === 'NumericLiteral') {
|
|
34
|
+
return -node.argument.value;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
case 'CallExpression': {
|
|
39
|
+
if (node.arguments && node.arguments[0]) {
|
|
40
|
+
return astToValue(node.arguments[0]);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
case 'TSAsExpression':
|
|
45
|
+
case 'TSSatisfiesExpression':
|
|
46
|
+
case 'TSTypeAssertion':
|
|
47
|
+
case 'TSNonNullExpression':
|
|
48
|
+
return astToValue(node.expression);
|
|
49
|
+
default:
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isLocaleMap(value) {
|
|
55
|
+
return value && typeof value === 'object' && !Array.isArray(value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function translationsSourcePath(themeRoot) {
|
|
59
|
+
const tsPath = path.join(themeRoot, 'cms', 'translations.ts');
|
|
60
|
+
const jsonPath = path.join(themeRoot, 'cms', 'translations.json');
|
|
61
|
+
if (fs.existsSync(tsPath)) return tsPath;
|
|
62
|
+
if (fs.existsSync(jsonPath)) return jsonPath;
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Loads i18n dictionaries from cms/translations.ts (preferred) or cms/translations.json.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} themeRoot
|
|
70
|
+
* @returns {Record<string, Record<string, string>>}
|
|
71
|
+
*/
|
|
72
|
+
export function loadTranslationsData(themeRoot) {
|
|
73
|
+
const tsPath = path.join(themeRoot, 'cms', 'translations.ts');
|
|
74
|
+
const jsonPath = path.join(themeRoot, 'cms', 'translations.json');
|
|
75
|
+
|
|
76
|
+
if (fs.existsSync(tsPath)) {
|
|
77
|
+
try {
|
|
78
|
+
const code = fs.readFileSync(tsPath, 'utf8');
|
|
79
|
+
const ast = parseSource(code);
|
|
80
|
+
let extracted = null;
|
|
81
|
+
|
|
82
|
+
traverse(ast, {
|
|
83
|
+
ExportNamedDeclaration(astPath) {
|
|
84
|
+
const decl = astPath.node.declaration;
|
|
85
|
+
if (decl && decl.declarations) {
|
|
86
|
+
for (const d of decl.declarations) {
|
|
87
|
+
if (d.id?.name === 'translations' && d.init) {
|
|
88
|
+
extracted = astToValue(d.init);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
ExportDefaultDeclaration(astPath) {
|
|
94
|
+
if (!extracted && astPath.node.declaration) {
|
|
95
|
+
extracted = astToValue(astPath.node.declaration);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (isLocaleMap(extracted)) return extracted;
|
|
101
|
+
if (extracted && isLocaleMap(extracted.translations)) return extracted.translations;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.warn(`⚠️ [ForgeWP i18n] Could not load ${tsPath}: ${e.message}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (fs.existsSync(jsonPath)) {
|
|
108
|
+
try {
|
|
109
|
+
const raw = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
|
110
|
+
if (isLocaleMap(raw)) return raw;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.warn(`⚠️ [ForgeWP i18n] Could not parse ${jsonPath}: ${e.message}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Writes translations back to cms/translations.ts when that file exists,
|
|
121
|
+
* otherwise to cms/translations.json. Creates translations.ts when neither exists.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} themeRoot
|
|
124
|
+
* @param {Record<string, Record<string, string>>} translations
|
|
125
|
+
* @returns {string} absolute path written
|
|
126
|
+
*/
|
|
127
|
+
export function writeTranslationsData(themeRoot, translations) {
|
|
128
|
+
const cmsDir = path.join(themeRoot, 'cms');
|
|
129
|
+
if (!fs.existsSync(cmsDir)) {
|
|
130
|
+
fs.mkdirSync(cmsDir, { recursive: true });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const tsPath = path.join(cmsDir, 'translations.ts');
|
|
134
|
+
const jsonPath = path.join(cmsDir, 'translations.json');
|
|
135
|
+
const body = JSON.stringify(translations, null, 2);
|
|
136
|
+
|
|
137
|
+
if (fs.existsSync(tsPath) || !fs.existsSync(jsonPath)) {
|
|
138
|
+
const content =
|
|
139
|
+
`import { defineTranslations } from '@forgewp/react';\n\n` +
|
|
140
|
+
`export const translations = defineTranslations(${body});\n\n` +
|
|
141
|
+
`export default translations;\n`;
|
|
142
|
+
fs.writeFileSync(tsPath, content, 'utf8');
|
|
143
|
+
return tsPath;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
fs.writeFileSync(jsonPath, body, 'utf8');
|
|
147
|
+
return jsonPath;
|
|
148
|
+
}
|