@forgewp/compiler 0.4.2 → 0.4.3
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 +11 -3
- package/bin/add.js +15 -6
- package/bin/analyze.js +66 -1
- package/bin/cli.js +16 -12
- package/bin/fresh.js +1 -1
- package/bin/make-block.js +11 -0
- package/bin/make-island.js +11 -0
- package/bin/{make-template.js → make-loop.js} +24 -19
- package/bin/make-page.js +83 -0
- package/bin/make-post-type.js +11 -0
- package/bin/make-sandbox.js +558 -0
- package/lib/adapters/html-adapter.js +8 -3
- package/lib/adapters/stub-adapter.js +6 -2
- package/lib/asset-loader.js +22 -0
- package/lib/blueprints.js +133 -1
- package/lib/functions-builder.js +929 -3
- package/lib/generate-theme.js +219 -23
- package/lib/hydration-scanner.js +69 -57
- package/lib/index.d.ts +38 -1
- package/lib/index.js +1 -1
- package/lib/load-config.js +98 -0
- package/lib/markup-processor.js +105 -0
- package/lib/page-config-plugin.js +40 -0
- package/lib/php-builders.js +4 -2
- package/lib/react-adapter.js +82 -23
- package/lib/render-theme.mts +97 -24
- package/lib/validate-export.js +49 -0
- package/package.json +2 -1
- package/templates/PresetsStyle.tsx +1 -1
- package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +133 -0
- package/templates/auth/components/login-form-wrapper.tsx +203 -0
- package/templates/auth/components/reset-password-form-wrapper.tsx +182 -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 +15 -0
- package/templates/auth/pages/ForgotPasswordPage.tsx +14 -0
- package/templates/auth/pages/LoginPage.tsx +14 -0
- package/templates/auth/pages/ResetPasswordPage.tsx +14 -0
- package/templates/auth/pages/SignUpPage.tsx +14 -0
- package/templates/auth/pages/VerifyEmailPage.tsx +14 -0
- package/templates/forgewp-config.ts +70 -3
- 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 +34 -0
- package/templates/wordpress.tsx +1390 -1297
package/lib/generate-theme.js
CHANGED
|
@@ -212,17 +212,30 @@ export async function generateTheme({
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
const manifestPath = path.join(themeRoot, 'dist', '.vite', 'manifest.json');
|
|
216
|
+
let viteManifest = {};
|
|
217
|
+
if (existsSync(manifestPath)) {
|
|
218
|
+
try {
|
|
219
|
+
viteManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
220
|
+
} catch (e) {
|
|
221
|
+
console.warn('Failed to parse Vite manifest.json:', e.message);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const replaceAssetPlaceholders = (markup) => {
|
|
226
|
+
if (!markup) return '';
|
|
227
|
+
return markup.replace(/__FORGEWP_ASSET__([a-zA-Z0-9_\-\.\/]+)/g, (match, srcPath) => {
|
|
228
|
+
const manifestEntry = viteManifest[srcPath];
|
|
229
|
+
if (manifestEntry && manifestEntry.file) {
|
|
230
|
+
return `<?php echo esc_url( get_template_directory_uri() ); ?>/${manifestEntry.file}`;
|
|
231
|
+
}
|
|
232
|
+
return `<?php echo esc_url( get_template_directory_uri() ); ?>/${srcPath}`;
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
|
|
215
236
|
let hydrationManifestJson = '{}';
|
|
216
237
|
if (hasHydration) {
|
|
217
|
-
|
|
218
|
-
let viteManifest = {};
|
|
219
|
-
if (existsSync(manifestPath)) {
|
|
220
|
-
try {
|
|
221
|
-
viteManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
222
|
-
} catch (e) {
|
|
223
|
-
console.warn('Failed to parse Vite manifest.json:', e.message);
|
|
224
|
-
}
|
|
225
|
-
} else {
|
|
238
|
+
if (!existsSync(manifestPath)) {
|
|
226
239
|
console.warn(
|
|
227
240
|
'Hydration manifest not found at dist/.vite/manifest.json. Hydration asset generation may be incomplete.',
|
|
228
241
|
);
|
|
@@ -621,24 +634,24 @@ export async function generateTheme({
|
|
|
621
634
|
|
|
622
635
|
const staticDir = path.join(outDir, 'forgewp-static');
|
|
623
636
|
mkdirSync(staticDir, { recursive: true });
|
|
624
|
-
writeFileSync(path.join(staticDir, 'content.html'), contentHtml, 'utf8');
|
|
625
|
-
writeFileSync(path.join(staticDir, 'header.html'), processedHeader, 'utf8');
|
|
626
|
-
writeFileSync(path.join(staticDir, 'footer.html'), processedFooter, 'utf8');
|
|
637
|
+
writeFileSync(path.join(staticDir, 'content.html'), replaceAssetPlaceholders(contentHtml), 'utf8');
|
|
638
|
+
writeFileSync(path.join(staticDir, 'header.html'), replaceAssetPlaceholders(processedHeader), 'utf8');
|
|
639
|
+
writeFileSync(path.join(staticDir, 'footer.html'), replaceAssetPlaceholders(processedFooter), 'utf8');
|
|
627
640
|
if (headHtml) {
|
|
628
|
-
writeFileSync(path.join(staticDir, 'head.html'), headHtml, 'utf8');
|
|
641
|
+
writeFileSync(path.join(staticDir, 'head.html'), replaceAssetPlaceholders(headHtml), 'utf8');
|
|
629
642
|
}
|
|
630
643
|
if (singleHeadHtml) {
|
|
631
644
|
writeFileSync(
|
|
632
645
|
path.join(staticDir, 'single-head.html'),
|
|
633
|
-
singleHeadHtml,
|
|
646
|
+
replaceAssetPlaceholders(singleHeadHtml),
|
|
634
647
|
'utf8',
|
|
635
648
|
);
|
|
636
649
|
}
|
|
637
650
|
if (processedSingle) {
|
|
638
|
-
writeFileSync(path.join(staticDir, 'single.html'), processedSingle, 'utf8');
|
|
651
|
+
writeFileSync(path.join(staticDir, 'single.html'), replaceAssetPlaceholders(processedSingle), 'utf8');
|
|
639
652
|
}
|
|
640
653
|
if (processedNotFound) {
|
|
641
|
-
writeFileSync(path.join(staticDir, '404.html'), processedNotFound, 'utf8');
|
|
654
|
+
writeFileSync(path.join(staticDir, '404.html'), replaceAssetPlaceholders(processedNotFound), 'utf8');
|
|
642
655
|
}
|
|
643
656
|
|
|
644
657
|
// Archive page (category / tag / date archives)
|
|
@@ -656,7 +669,7 @@ export async function generateTheme({
|
|
|
656
669
|
processedArchive = processedArchive.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
657
670
|
writeFileSync(
|
|
658
671
|
path.join(staticDir, 'archive.html'),
|
|
659
|
-
processedArchive,
|
|
672
|
+
replaceAssetPlaceholders(processedArchive),
|
|
660
673
|
'utf8',
|
|
661
674
|
);
|
|
662
675
|
}
|
|
@@ -840,13 +853,13 @@ if (window.forgeWpBlocks) {
|
|
|
840
853
|
}
|
|
841
854
|
processedHtml = processedHtml.replace(/<div\b[^>]*data-forgewp-hydrate="(navbar|site-header|site-footer)"[^>]*>\s*<\/div>/g, '');
|
|
842
855
|
|
|
843
|
-
writeFileSync(path.join(staticDir, file), processedHtml, 'utf8');
|
|
856
|
+
writeFileSync(path.join(staticDir, file), replaceAssetPlaceholders(processedHtml), 'utf8');
|
|
844
857
|
|
|
845
858
|
const headFile = file.replace('.html', '-head.html');
|
|
846
859
|
if (existsSync(path.join(forgewpDir, headFile))) {
|
|
847
860
|
writeFileSync(
|
|
848
861
|
path.join(staticDir, headFile),
|
|
849
|
-
readFileSync(path.join(forgewpDir, headFile), 'utf8'),
|
|
862
|
+
replaceAssetPlaceholders(readFileSync(path.join(forgewpDir, headFile), 'utf8')),
|
|
850
863
|
'utf8',
|
|
851
864
|
);
|
|
852
865
|
}
|
|
@@ -889,6 +902,11 @@ get_footer();
|
|
|
889
902
|
}
|
|
890
903
|
}
|
|
891
904
|
|
|
905
|
+
const authManifest = {
|
|
906
|
+
protectedPages: [],
|
|
907
|
+
authGates: [],
|
|
908
|
+
};
|
|
909
|
+
|
|
892
910
|
// Dynamic Custom Page Templates Compiler
|
|
893
911
|
if (existsSync(forgewpDir)) {
|
|
894
912
|
const templateFiles = readdirSync(forgewpDir);
|
|
@@ -901,7 +919,163 @@ get_footer();
|
|
|
901
919
|
const slug = file.replace('.html', '');
|
|
902
920
|
const rawHtml = readFileSync(path.join(forgewpDir, file), 'utf8');
|
|
903
921
|
|
|
904
|
-
let
|
|
922
|
+
let isProtected = false;
|
|
923
|
+
let allowedCapability = null;
|
|
924
|
+
let redirectUrl = null;
|
|
925
|
+
|
|
926
|
+
if (rawHtml.includes('<forgewp-require-auth')) {
|
|
927
|
+
isProtected = true;
|
|
928
|
+
const match = rawHtml.match(/<forgewp-require-auth\s+([^>]*)\/?>/i);
|
|
929
|
+
if (match) {
|
|
930
|
+
const attrsStr = match[1];
|
|
931
|
+
const getAttr = (name) => {
|
|
932
|
+
const regex = new RegExp(
|
|
933
|
+
`(?:${name}|${name.toLowerCase()})=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
|
|
934
|
+
'i',
|
|
935
|
+
);
|
|
936
|
+
const m = attrsStr.match(regex);
|
|
937
|
+
return m ? m[1] || m[2] || m[3] || '' : '';
|
|
938
|
+
};
|
|
939
|
+
allowedCapability = getAttr('allowed') || null;
|
|
940
|
+
redirectUrl = getAttr('redirect') || null;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
if (isProtected) {
|
|
945
|
+
authManifest.protectedPages.push({
|
|
946
|
+
page: slug.replace('template-', ''),
|
|
947
|
+
allowed: allowedCapability,
|
|
948
|
+
redirect: redirectUrl,
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
if (rawHtml.includes('forgewp-auth-gate-start')) {
|
|
953
|
+
authManifest.authGates.push({
|
|
954
|
+
page: slug.replace('template-', ''),
|
|
955
|
+
type: 'logged_in',
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
if (rawHtml.includes('forgewp-capability-gate-start')) {
|
|
960
|
+
const match = rawHtml.match(/forgewp-capability-gate-start\s+allowed="([^"]*)"/);
|
|
961
|
+
authManifest.authGates.push({
|
|
962
|
+
page: slug.replace('template-', ''),
|
|
963
|
+
type: 'capability',
|
|
964
|
+
allowed: match ? match[1] : null,
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
let redirectPhp = '';
|
|
969
|
+
let cleanedRawHtml = rawHtml;
|
|
970
|
+
if (rawHtml.includes('<forgewp-require-auth')) {
|
|
971
|
+
const match = rawHtml.match(/<forgewp-require-auth\s+([^>]*)\/?>/i);
|
|
972
|
+
if (match) {
|
|
973
|
+
const attrsStr = match[1];
|
|
974
|
+
const getAttr = (name) => {
|
|
975
|
+
const regex = new RegExp(
|
|
976
|
+
`(?:${name}|${name.toLowerCase()})=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
|
|
977
|
+
'i',
|
|
978
|
+
);
|
|
979
|
+
const m = attrsStr.match(regex);
|
|
980
|
+
return m ? m[1] || m[2] || m[3] || '' : '';
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
const allowed = getAttr('allowed');
|
|
984
|
+
const redirect = getAttr('redirect');
|
|
985
|
+
|
|
986
|
+
let redirectUrlExpr = 'wp_login_url()';
|
|
987
|
+
let redirectSetup = '';
|
|
988
|
+
if (redirect) {
|
|
989
|
+
if (redirect.startsWith('__FORGEWP_PAGELINK_')) {
|
|
990
|
+
const match = redirect.match(/__FORGEWP_PAGELINK_([a-zA-Z0-9_-]+)_DEFAULT_(.*?)__/);
|
|
991
|
+
if (match) {
|
|
992
|
+
const name = match[1];
|
|
993
|
+
const decoded = decodeURIComponent(match[2]);
|
|
994
|
+
redirectSetup = ` $redirect_url = home_url('${decoded.replace(/'/g, "\\'")}');
|
|
995
|
+
$current_lang = function_exists('pll_current_language') ? pll_current_language() : '';
|
|
996
|
+
$get_pages_args = array('meta_key' => '_wp_page_template', 'meta_value' => 'page-${name}.php', 'number' => 1);
|
|
997
|
+
if (!empty($current_lang)) {
|
|
998
|
+
$get_pages_args['lang'] = $current_lang;
|
|
999
|
+
}
|
|
1000
|
+
$matched_pages = get_pages($get_pages_args);
|
|
1001
|
+
if (!empty($matched_pages)) {
|
|
1002
|
+
$redirect_url = get_permalink($matched_pages[0]->ID);
|
|
1003
|
+
}`;
|
|
1004
|
+
redirectUrlExpr = '$redirect_url';
|
|
1005
|
+
} else {
|
|
1006
|
+
const matchPlain = redirect.match(/__FORGEWP_PAGELINK_([a-zA-Z0-9_-]+)__/);
|
|
1007
|
+
if (matchPlain) {
|
|
1008
|
+
const name = matchPlain[1];
|
|
1009
|
+
redirectSetup = ` $redirect_url = home_url('/');
|
|
1010
|
+
$current_lang = function_exists('pll_current_language') ? pll_current_language() : '';
|
|
1011
|
+
$get_pages_args = array('meta_key' => '_wp_page_template', 'meta_value' => 'page-${name}.php', 'number' => 1);
|
|
1012
|
+
if (!empty($current_lang)) {
|
|
1013
|
+
$get_pages_args['lang'] = $current_lang;
|
|
1014
|
+
}
|
|
1015
|
+
$matched_pages = get_pages($get_pages_args);
|
|
1016
|
+
if (!empty($matched_pages)) {
|
|
1017
|
+
$redirect_url = get_permalink($matched_pages[0]->ID);
|
|
1018
|
+
}`;
|
|
1019
|
+
redirectUrlExpr = '$redirect_url';
|
|
1020
|
+
} else {
|
|
1021
|
+
redirectUrlExpr = `home_url('${redirect}')`;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
} else if (redirect.startsWith('template:')) {
|
|
1025
|
+
const name = redirect.replace('template:', '');
|
|
1026
|
+
redirectSetup = ` $redirect_url = home_url('/');
|
|
1027
|
+
$current_lang = function_exists('pll_current_language') ? pll_current_language() : '';
|
|
1028
|
+
$get_pages_args = array('meta_key' => '_wp_page_template', 'meta_value' => 'page-${name}.php', 'number' => 1);
|
|
1029
|
+
if (!empty($current_lang)) {
|
|
1030
|
+
$get_pages_args['lang'] = $current_lang;
|
|
1031
|
+
}
|
|
1032
|
+
$matched_pages = get_pages($get_pages_args);
|
|
1033
|
+
if (!empty($matched_pages)) {
|
|
1034
|
+
$redirect_url = get_permalink($matched_pages[0]->ID);
|
|
1035
|
+
}`;
|
|
1036
|
+
redirectUrlExpr = '$redirect_url';
|
|
1037
|
+
} else {
|
|
1038
|
+
redirectUrlExpr = `home_url('${redirect}')`;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
redirectPhp = `
|
|
1043
|
+
if ( ! is_user_logged_in() ) {
|
|
1044
|
+
${redirectSetup ? redirectSetup + '\n' : ''} wp_safe_redirect( ${redirectUrlExpr} );
|
|
1045
|
+
exit;
|
|
1046
|
+
} else {
|
|
1047
|
+
$email_verification_enabled = get_option( 'forgewp_auth_email_verification_enabled' ) === '1';
|
|
1048
|
+
$verified_meta = get_user_meta( get_current_user_id(), 'forgewp_email_verified', true );
|
|
1049
|
+
$email_verified = ( $verified_meta === '' ) || ( $verified_meta === '1' ) || ( $verified_meta === true );
|
|
1050
|
+
if ( $email_verification_enabled && ! $email_verified ) {
|
|
1051
|
+
$verify_url = home_url( '/verify-email' );
|
|
1052
|
+
$current_lang = function_exists('pll_current_language') ? pll_current_language() : '';
|
|
1053
|
+
$get_pages_args = array('meta_key' => '_wp_page_template', 'meta_value' => 'page-verify-email-page.php', 'number' => 1);
|
|
1054
|
+
if (!empty($current_lang)) {
|
|
1055
|
+
$get_pages_args['lang'] = $current_lang;
|
|
1056
|
+
}
|
|
1057
|
+
$matched_pages = get_pages($get_pages_args);
|
|
1058
|
+
if (!empty($matched_pages)) {
|
|
1059
|
+
$verify_url = get_permalink($matched_pages[0]->ID);
|
|
1060
|
+
}
|
|
1061
|
+
wp_safe_redirect( $verify_url );
|
|
1062
|
+
exit;
|
|
1063
|
+
}
|
|
1064
|
+
}`;
|
|
1065
|
+
|
|
1066
|
+
if (allowed) {
|
|
1067
|
+
redirectPhp += `
|
|
1068
|
+
if ( ! current_user_can( '${allowed}' ) ) {
|
|
1069
|
+
wp_safe_redirect( home_url( '/' ) );
|
|
1070
|
+
exit;
|
|
1071
|
+
}`;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
cleanedRawHtml = rawHtml.replace(/<forgewp-require-auth\s*([^>]*)\/?>/gi, '');
|
|
1075
|
+
cleanedRawHtml = cleanedRawHtml.replace(/<\/forgewp-require-auth>/gi, '');
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
let processedHtml = processMarkup(cleanedRawHtml, config.textDomain);
|
|
905
1079
|
if (processedHeader) {
|
|
906
1080
|
const replaced = processedHtml.replace(processedHeader, '');
|
|
907
1081
|
processedHtml = replaced !== processedHtml ? replaced : processedHtml.replace(/<header\b[^>]*>([\s\S]*?)<\/header>/i, '');
|
|
@@ -916,13 +1090,13 @@ get_footer();
|
|
|
916
1090
|
processedHtml = projectHooks.processTemplateMarkup(slug, processedHtml, config);
|
|
917
1091
|
}
|
|
918
1092
|
|
|
919
|
-
writeFileSync(path.join(staticDir, file), processedHtml, 'utf8');
|
|
1093
|
+
writeFileSync(path.join(staticDir, file), replaceAssetPlaceholders(processedHtml), 'utf8');
|
|
920
1094
|
|
|
921
1095
|
const headFile = file.replace('.html', '-head.html');
|
|
922
1096
|
if (existsSync(path.join(forgewpDir, headFile))) {
|
|
923
1097
|
writeFileSync(
|
|
924
1098
|
path.join(staticDir, headFile),
|
|
925
|
-
readFileSync(path.join(forgewpDir, headFile), 'utf8'),
|
|
1099
|
+
replaceAssetPlaceholders(readFileSync(path.join(forgewpDir, headFile), 'utf8')),
|
|
926
1100
|
'utf8',
|
|
927
1101
|
);
|
|
928
1102
|
}
|
|
@@ -939,7 +1113,7 @@ get_footer();
|
|
|
939
1113
|
*
|
|
940
1114
|
* @package ${config.textDomain}
|
|
941
1115
|
*/
|
|
942
|
-
|
|
1116
|
+
${redirectPhp}
|
|
943
1117
|
get_header();
|
|
944
1118
|
|
|
945
1119
|
$markup_file = get_template_directory() . '/forgewp-static/${file}';
|
|
@@ -994,6 +1168,22 @@ get_footer();
|
|
|
994
1168
|
...themeJson.settings.color,
|
|
995
1169
|
...config.settings.color,
|
|
996
1170
|
};
|
|
1171
|
+
|
|
1172
|
+
// Smartly extract background and text colors from palette to style the WP editor canvas
|
|
1173
|
+
if (config.settings.color.palette && Array.isArray(config.settings.color.palette)) {
|
|
1174
|
+
if (!themeJson.styles) themeJson.styles = {};
|
|
1175
|
+
if (!themeJson.styles.color) themeJson.styles.color = {};
|
|
1176
|
+
|
|
1177
|
+
const bgPreset = config.settings.color.palette.find(p => p && p.slug === 'background');
|
|
1178
|
+
const textPreset = config.settings.color.palette.find(p => p && (p.slug === 'text' || p.slug === 'primary'));
|
|
1179
|
+
|
|
1180
|
+
if (bgPreset && !themeJson.styles.color.background) {
|
|
1181
|
+
themeJson.styles.color.background = bgPreset.color;
|
|
1182
|
+
}
|
|
1183
|
+
if (textPreset && !themeJson.styles.color.text) {
|
|
1184
|
+
themeJson.styles.color.text = textPreset.color;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
997
1187
|
}
|
|
998
1188
|
|
|
999
1189
|
// Typography (fontSizes, fontFamilies)
|
|
@@ -1011,6 +1201,12 @@ get_footer();
|
|
|
1011
1201
|
'utf8',
|
|
1012
1202
|
);
|
|
1013
1203
|
|
|
1204
|
+
writeFileSync(
|
|
1205
|
+
path.join(outDir, 'auth-manifest.json'),
|
|
1206
|
+
JSON.stringify(authManifest, null, 2),
|
|
1207
|
+
'utf8',
|
|
1208
|
+
);
|
|
1209
|
+
|
|
1014
1210
|
const screenshot = path.join(themeRoot, 'cms', 'screenshot.png');
|
|
1015
1211
|
if (existsSync(screenshot)) {
|
|
1016
1212
|
copyFileSync(screenshot, path.join(outDir, 'screenshot.png'));
|
package/lib/hydration-scanner.js
CHANGED
|
@@ -126,10 +126,8 @@ export function scanForHydrationIslands(themeRoot) {
|
|
|
126
126
|
* @returns {string|null} The absolute path to the component file, or null if not found.
|
|
127
127
|
*/
|
|
128
128
|
export function findComponentPath(themeRoot, kebabName) {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
path.join(themeRoot, "src", "components", "ui"),
|
|
132
|
-
];
|
|
129
|
+
const compDir = path.join(themeRoot, "src", "components");
|
|
130
|
+
if (!existsSync(compDir)) return null;
|
|
133
131
|
|
|
134
132
|
// Convert kebab-case back to PascalCase and check candidates
|
|
135
133
|
const pascalName = kebabName
|
|
@@ -144,19 +142,28 @@ export function findComponentPath(themeRoot, kebabName) {
|
|
|
144
142
|
`${kebabName}.ts`,
|
|
145
143
|
];
|
|
146
144
|
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
let result = null;
|
|
146
|
+
|
|
147
|
+
function searchRecursive(dir) {
|
|
148
|
+
if (result) return;
|
|
149
149
|
try {
|
|
150
|
-
const
|
|
151
|
-
for (const
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
const items = readdirSync(dir, { withFileTypes: true });
|
|
151
|
+
for (const item of items) {
|
|
152
|
+
const fullPath = path.join(dir, item.name);
|
|
153
|
+
if (item.isDirectory()) {
|
|
154
|
+
searchRecursive(fullPath);
|
|
155
|
+
} else if (item.isFile()) {
|
|
156
|
+
if (candidates.includes(item.name)) {
|
|
157
|
+
result = fullPath;
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
162
|
} catch {}
|
|
157
163
|
}
|
|
158
164
|
|
|
159
|
-
|
|
165
|
+
searchRecursive(compDir);
|
|
166
|
+
return result;
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
/**
|
|
@@ -417,63 +424,68 @@ export function runStaticLintChecks(themeRoot) {
|
|
|
417
424
|
} catch {}
|
|
418
425
|
}
|
|
419
426
|
|
|
420
|
-
// 2. Scan CPTs, Taxonomies, and Custom Fields from cms/mock-data.json
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
427
|
+
// 2. Scan CPTs, Taxonomies, and Custom Fields from cms/mock-data.json and cms/products.json
|
|
428
|
+
const dataFiles = [
|
|
429
|
+
path.join(themeRoot, "cms", "mock-data.json"),
|
|
430
|
+
path.join(themeRoot, "cms", "products.json")
|
|
431
|
+
];
|
|
432
|
+
for (const dbPath of dataFiles) {
|
|
433
|
+
if (existsSync(dbPath)) {
|
|
434
|
+
try {
|
|
435
|
+
const mockData = JSON.parse(readFileSync(dbPath, "utf8"));
|
|
436
|
+
for (const pt of Object.keys(mockData)) {
|
|
437
|
+
if (
|
|
438
|
+
pt !== 'posts' &&
|
|
439
|
+
pt !== 'pages' &&
|
|
440
|
+
pt !== 'post' &&
|
|
441
|
+
pt !== 'page' &&
|
|
442
|
+
pt !== 'menus' &&
|
|
443
|
+
pt !== 'attachment' &&
|
|
444
|
+
!pt.startsWith('_')
|
|
445
|
+
) {
|
|
446
|
+
validPostTypes.add(pt);
|
|
447
|
+
if (!postTypeTaxonomies[pt]) {
|
|
448
|
+
postTypeTaxonomies[pt] = new Set(["category", "post_tag"]);
|
|
449
|
+
}
|
|
450
|
+
if (!postTypeCustomFields[pt]) {
|
|
451
|
+
postTypeCustomFields[pt] = new Set();
|
|
452
|
+
}
|
|
442
453
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
454
|
+
const items = mockData[pt];
|
|
455
|
+
if (Array.isArray(items)) {
|
|
456
|
+
for (const item of items) {
|
|
457
|
+
if (item._terms && typeof item._terms === 'object') {
|
|
458
|
+
for (const tax of Object.keys(item._terms)) {
|
|
459
|
+
postTypeTaxonomies[pt].add(tax);
|
|
460
|
+
}
|
|
449
461
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
462
|
+
if (item.customFields && typeof item.customFields === 'object') {
|
|
463
|
+
for (const key of Object.keys(item.customFields)) {
|
|
464
|
+
postTypeCustomFields[pt].add(key);
|
|
465
|
+
}
|
|
454
466
|
}
|
|
455
467
|
}
|
|
456
468
|
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
469
|
+
} else if (pt === 'post' || pt === 'page') {
|
|
470
|
+
const items = mockData[pt];
|
|
471
|
+
if (Array.isArray(items)) {
|
|
472
|
+
for (const item of items) {
|
|
473
|
+
if (item._terms && typeof item._terms === 'object') {
|
|
474
|
+
for (const tax of Object.keys(item._terms)) {
|
|
475
|
+
postTypeTaxonomies[pt].add(tax);
|
|
476
|
+
}
|
|
465
477
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
478
|
+
if (item.customFields && typeof item.customFields === 'object') {
|
|
479
|
+
for (const key of Object.keys(item.customFields)) {
|
|
480
|
+
postTypeCustomFields[pt].add(key);
|
|
481
|
+
}
|
|
470
482
|
}
|
|
471
483
|
}
|
|
472
484
|
}
|
|
473
485
|
}
|
|
474
486
|
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
487
|
+
} catch {}
|
|
488
|
+
}
|
|
477
489
|
}
|
|
478
490
|
|
|
479
491
|
const validSlugs = new Set(["page"]);
|
package/lib/index.d.ts
CHANGED
|
@@ -54,6 +54,8 @@ export interface ForgeWPThemeConfig {
|
|
|
54
54
|
textDomain: string;
|
|
55
55
|
configVersion?: number;
|
|
56
56
|
favicon?: string;
|
|
57
|
+
headerPath?: string;
|
|
58
|
+
footerPath?: string;
|
|
57
59
|
seo?: {
|
|
58
60
|
sitemaps?: ForgeWpSeoSitemapsConfig;
|
|
59
61
|
plugins?: {
|
|
@@ -63,6 +65,31 @@ export interface ForgeWPThemeConfig {
|
|
|
63
65
|
};
|
|
64
66
|
frameworkAdapter?: 'react' | 'html' | 'stub';
|
|
65
67
|
style?: 'forgewp' | 'shadcn';
|
|
68
|
+
headless?: {
|
|
69
|
+
apiUrl?: string;
|
|
70
|
+
jwtAuth?: boolean;
|
|
71
|
+
};
|
|
72
|
+
auth?: {
|
|
73
|
+
loginField?: 'usernameOnly' | 'emailOnly' | 'usernameAndEmail';
|
|
74
|
+
defaultRole?: string;
|
|
75
|
+
reservedUsernames?: string[];
|
|
76
|
+
features?: {
|
|
77
|
+
registration?: boolean;
|
|
78
|
+
emailVerification?: boolean;
|
|
79
|
+
blockLoginUntilVerified?: boolean;
|
|
80
|
+
autoLoginAfterSignup?: boolean;
|
|
81
|
+
};
|
|
82
|
+
emails?: {
|
|
83
|
+
verification?: {
|
|
84
|
+
subject?: string;
|
|
85
|
+
body?: string;
|
|
86
|
+
};
|
|
87
|
+
passwordReset?: {
|
|
88
|
+
subject?: string;
|
|
89
|
+
body?: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
66
93
|
postTypes?: Record<string, CustomPostTypeConfig>;
|
|
67
94
|
i18n?: ForgeWPI18nConfig;
|
|
68
95
|
settings?: {
|
|
@@ -118,7 +145,7 @@ export interface ForgeWPFrameworkAdapter {
|
|
|
118
145
|
pc: any;
|
|
119
146
|
},
|
|
120
147
|
): Promise<void> | void;
|
|
121
|
-
|
|
148
|
+
onMakeLoop?(
|
|
122
149
|
themeRoot: string,
|
|
123
150
|
options: {
|
|
124
151
|
pascalCase: string;
|
|
@@ -128,6 +155,13 @@ export interface ForgeWPFrameworkAdapter {
|
|
|
128
155
|
pc: any;
|
|
129
156
|
},
|
|
130
157
|
): Promise<void> | void;
|
|
158
|
+
onMakePage?(
|
|
159
|
+
themeRoot: string,
|
|
160
|
+
options: {
|
|
161
|
+
pascalCase: string;
|
|
162
|
+
pc: any;
|
|
163
|
+
},
|
|
164
|
+
): Promise<void> | void;
|
|
131
165
|
onSyncRoutes?(
|
|
132
166
|
themeRoot: string,
|
|
133
167
|
options: {
|
|
@@ -177,3 +211,6 @@ export function resolveFrameworkAdapter(adapterName?: string): string;
|
|
|
177
211
|
export function loadFrameworkAdapter(
|
|
178
212
|
adapterName?: string,
|
|
179
213
|
): Promise<ForgeWPFrameworkAdapterModule>;
|
|
214
|
+
|
|
215
|
+
export function forgewpPageConfigPlugin(): any;
|
|
216
|
+
|
package/lib/index.js
CHANGED
package/lib/load-config.js
CHANGED
|
@@ -56,6 +56,104 @@ export async function loadConfig(themeRoot) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// Validate headerPath
|
|
60
|
+
if (config.headerPath !== undefined) {
|
|
61
|
+
if (typeof config.headerPath !== 'string') {
|
|
62
|
+
throw new Error('headerPath must be a string pointing to a header component file');
|
|
63
|
+
}
|
|
64
|
+
const absPath = path.isAbsolute(config.headerPath) ? config.headerPath : path.join(themeRoot, config.headerPath);
|
|
65
|
+
if (!existsSync(absPath)) {
|
|
66
|
+
console.warn(
|
|
67
|
+
'\x1b[33m%s\x1b[0m',
|
|
68
|
+
`⚠️ [ForgeWP Warning]: Header component file not found at "${config.headerPath}".`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Validate footerPath
|
|
74
|
+
if (config.footerPath !== undefined) {
|
|
75
|
+
if (typeof config.footerPath !== 'string') {
|
|
76
|
+
throw new Error('footerPath must be a string pointing to a footer component file');
|
|
77
|
+
}
|
|
78
|
+
const absPath = path.isAbsolute(config.footerPath) ? config.footerPath : path.join(themeRoot, config.footerPath);
|
|
79
|
+
if (!existsSync(absPath)) {
|
|
80
|
+
console.warn(
|
|
81
|
+
'\x1b[33m%s\x1b[0m',
|
|
82
|
+
`⚠️ [ForgeWP Warning]: Footer component file not found at "${config.footerPath}".`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Validate headless
|
|
88
|
+
if (config.headless !== undefined) {
|
|
89
|
+
if (typeof config.headless !== 'object' || config.headless === null) {
|
|
90
|
+
throw new Error('headless configuration must be an object');
|
|
91
|
+
}
|
|
92
|
+
if (config.headless.apiUrl !== undefined && typeof config.headless.apiUrl !== 'string') {
|
|
93
|
+
throw new Error('headless.apiUrl must be a string');
|
|
94
|
+
}
|
|
95
|
+
if (config.headless.jwtAuth !== undefined && typeof config.headless.jwtAuth !== 'boolean') {
|
|
96
|
+
throw new Error('headless.jwtAuth must be a boolean');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Validate auth
|
|
101
|
+
if (config.auth !== undefined) {
|
|
102
|
+
if (typeof config.auth !== 'object' || config.auth === null) {
|
|
103
|
+
throw new Error('auth configuration must be an object');
|
|
104
|
+
}
|
|
105
|
+
if (
|
|
106
|
+
config.auth.loginField !== undefined &&
|
|
107
|
+
!['usernameOnly', 'emailOnly', 'usernameAndEmail'].includes(config.auth.loginField)
|
|
108
|
+
) {
|
|
109
|
+
throw new Error('auth.loginField must be "usernameOnly", "emailOnly", or "usernameAndEmail"');
|
|
110
|
+
}
|
|
111
|
+
if (config.auth.defaultRole !== undefined && typeof config.auth.defaultRole !== 'string') {
|
|
112
|
+
throw new Error('auth.defaultRole must be a string');
|
|
113
|
+
}
|
|
114
|
+
if (config.auth.reservedUsernames !== undefined) {
|
|
115
|
+
if (!Array.isArray(config.auth.reservedUsernames) || config.auth.reservedUsernames.some((u) => typeof u !== 'string')) {
|
|
116
|
+
throw new Error('auth.reservedUsernames must be an array of strings');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (config.auth.features !== undefined) {
|
|
120
|
+
if (typeof config.auth.features !== 'object' || config.auth.features === null) {
|
|
121
|
+
throw new Error('auth.features must be an object');
|
|
122
|
+
}
|
|
123
|
+
if (config.auth.features.registration !== undefined && typeof config.auth.features.registration !== 'boolean') {
|
|
124
|
+
throw new Error('auth.features.registration must be a boolean');
|
|
125
|
+
}
|
|
126
|
+
if (config.auth.features.emailVerification !== undefined && typeof config.auth.features.emailVerification !== 'boolean') {
|
|
127
|
+
throw new Error('auth.features.emailVerification must be a boolean');
|
|
128
|
+
}
|
|
129
|
+
if (config.auth.features.blockLoginUntilVerified !== undefined && typeof config.auth.features.blockLoginUntilVerified !== 'boolean') {
|
|
130
|
+
throw new Error('auth.features.blockLoginUntilVerified must be a boolean');
|
|
131
|
+
}
|
|
132
|
+
if (config.auth.features.autoLoginAfterSignup !== undefined && typeof config.auth.features.autoLoginAfterSignup !== 'boolean') {
|
|
133
|
+
throw new Error('auth.features.autoLoginAfterSignup must be a boolean');
|
|
134
|
+
}
|
|
135
|
+
if (config.auth.features.blockLoginUntilVerified === true && config.auth.features.autoLoginAfterSignup === true) {
|
|
136
|
+
console.warn('\x1b[33m%s\x1b[0m', '⚠️ Warning: Both blockLoginUntilVerified and autoLoginAfterSignup are set to true. Unverified users will be blocked from auto-logging in after signup.');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (config.auth.emails !== undefined) {
|
|
140
|
+
if (typeof config.auth.emails !== 'object' || config.auth.emails === null) {
|
|
141
|
+
throw new Error('auth.emails must be an object');
|
|
142
|
+
}
|
|
143
|
+
if (config.auth.emails.verification !== undefined) {
|
|
144
|
+
if (typeof config.auth.emails.verification !== 'object' || config.auth.emails.verification === null) {
|
|
145
|
+
throw new Error('auth.emails.verification must be an object');
|
|
146
|
+
}
|
|
147
|
+
if (config.auth.emails.verification.subject !== undefined && typeof config.auth.emails.verification.subject !== 'string') {
|
|
148
|
+
throw new Error('auth.emails.verification.subject must be a string');
|
|
149
|
+
}
|
|
150
|
+
if (config.auth.emails.verification.body !== undefined && typeof config.auth.emails.verification.body !== 'string') {
|
|
151
|
+
throw new Error('auth.emails.verification.body must be a string');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
59
157
|
// Validate seo
|
|
60
158
|
if (config.seo !== undefined) {
|
|
61
159
|
if (typeof config.seo !== 'object' || config.seo === null) {
|