@forgewp/compiler 0.2.0 → 0.4.1
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 +29 -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-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 +290 -73
- package/lib/asset-loader.js +27 -0
- package/lib/block-compiler.js +552 -0
- package/lib/blueprints.js +1459 -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 +1801 -0
- package/lib/generate-theme.js +1019 -1143
- package/lib/hydration-scanner.js +674 -0
- package/lib/i18n/extractor.js +60 -0
- package/lib/i18n/providers.js +165 -0
- package/lib/index.d.ts +119 -1
- package/lib/index.js +20 -3
- package/lib/load-config.js +122 -6
- package/lib/markup-processor.js +584 -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 +526 -232
- package/lib/screenshot-fallback.png +0 -0
- package/lib/types.js +1 -0
- package/lib/validate-export.js +183 -0
- package/package.json +14 -3
- package/bin/make-component.js +0 -200
package/bin/make-block.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { existsSync
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import pc from "picocolors";
|
|
6
|
+
import { loadConfig } from "../lib/load-config.js";
|
|
7
|
+
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
6
8
|
|
|
7
9
|
const args = process.argv.slice(2);
|
|
8
10
|
let rawBlockName = args.find(a => !a.startsWith("-"));
|
|
@@ -44,25 +46,12 @@ const readableTitle = pascalCase
|
|
|
44
46
|
|
|
45
47
|
// Ensure we are inside a ForgeWP theme workspace
|
|
46
48
|
const projectRoot = process.cwd();
|
|
47
|
-
const blocksDir = path.join(projectRoot, "src", "blocks");
|
|
48
49
|
|
|
49
50
|
if (!existsSync(path.join(projectRoot, "src"))) {
|
|
50
51
|
console.error(pc.red(`\n❌ Error: "src" folder not found. Are you in your theme's root directory?\n`));
|
|
51
52
|
process.exit(1);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
// Ensure src/blocks directory exists
|
|
55
|
-
if (!existsSync(blocksDir)) {
|
|
56
|
-
mkdirSync(blocksDir, { recursive: true });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const targetFile = path.join(blocksDir, `${pascalCase}.tsx`);
|
|
60
|
-
|
|
61
|
-
if (existsSync(targetFile)) {
|
|
62
|
-
console.error(pc.red(`\n❌ Error: Block "${pascalCase}.tsx" already exists at src/blocks/\n`));
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
55
|
// 2. Parse custom attributes if provided via --attributes or --attrs
|
|
67
56
|
let attributesList = ["title", "description"];
|
|
68
57
|
const attrsArg = args.find(a => /^-+attributes=/.test(a) || /^-+attrs=/.test(a));
|
|
@@ -78,53 +67,31 @@ if (attrsArg) {
|
|
|
78
67
|
}
|
|
79
68
|
}
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</h3>`;
|
|
89
|
-
}
|
|
90
|
-
if (attr.toLowerCase().includes("image") || attr.toLowerCase().includes("pic") || attr.toLowerCase().includes("img")) {
|
|
91
|
-
return `<img src={${attr}} alt="Block Media" className="w-full border-2 border-zinc-950 mb-3" />`;
|
|
92
|
-
}
|
|
93
|
-
return `<p className="text-sm text-zinc-600 font-medium font-sans leading-relaxed mb-3">
|
|
94
|
-
{${attr}}
|
|
95
|
-
</p>`;
|
|
96
|
-
}).join("\n ");
|
|
97
|
-
|
|
98
|
-
const attributesRegistry = attributesList.map(a => {
|
|
99
|
-
return ` ${a}: { type: "string", default: "Customize ${a} here" }`;
|
|
100
|
-
}).join(",\n");
|
|
101
|
-
|
|
102
|
-
// 3. Generate the beautiful Neo-Brutalist React block template
|
|
103
|
-
const blockTemplate = `export default function ${pascalCase}({ ${propDestructuring} }: { ${propSignature} }) {
|
|
104
|
-
return (
|
|
105
|
-
<div className="p-8 bg-white border-4 border-zinc-950 shadow-[6px_6px_0px_0px_rgba(0,0,0,1)] rounded-none my-6 selection:bg-brand selection:text-white">
|
|
106
|
-
<span className="inline-block bg-brand text-white text-xs font-mono font-bold uppercase tracking-wider px-2 py-0.5 mb-3 border-2 border-zinc-950">
|
|
107
|
-
Gutenberg Custom Block
|
|
108
|
-
</span>
|
|
109
|
-
${layoutMarkup}
|
|
110
|
-
</div>
|
|
111
|
-
);
|
|
70
|
+
// Load configuration and invoke adapter
|
|
71
|
+
let frameworkAdapter = "react";
|
|
72
|
+
try {
|
|
73
|
+
const config = await loadConfig(projectRoot);
|
|
74
|
+
frameworkAdapter = config.frameworkAdapter || "react";
|
|
75
|
+
} catch (err) {
|
|
76
|
+
// Use default
|
|
112
77
|
}
|
|
113
78
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
79
|
+
try {
|
|
80
|
+
const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
|
|
81
|
+
const adapter = adapterModule.default || adapterModule;
|
|
82
|
+
if (typeof adapter.onMakeBlock === "function") {
|
|
83
|
+
await adapter.onMakeBlock(projectRoot, {
|
|
84
|
+
pascalCase,
|
|
85
|
+
readableTitle,
|
|
86
|
+
attributesList,
|
|
87
|
+
pc
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
console.error(pc.red(`\n❌ Error: Framework adapter "${frameworkAdapter}" does not support making Gutenberg blocks.`));
|
|
91
|
+
process.exit(1);
|
|
120
92
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
writeFileSync(targetFile, blockTemplate, "utf8");
|
|
93
|
+
} catch (err) {
|
|
94
|
+
console.error(pc.red(`\n❌ Failed to execute make:block: ${err.message}`));
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
126
97
|
|
|
127
|
-
console.log(pc.green(`\n⚡ Block "${pascalCase}" successfully created!`));
|
|
128
|
-
console.log(` Location: ${pc.cyan(`src/blocks/${pascalCase}.tsx`)}`);
|
|
129
|
-
console.log(` Gutenberg Title: ${pc.yellow(`Sharp ${readableTitle}`)}`);
|
|
130
|
-
console.log(`\n🎉 Run ${pc.cyan("pnpm export")} to automatically register it inside your WordPress theme!\n`);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import { loadConfig } from "../lib/load-config.js";
|
|
7
|
+
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
let rawIslandName = args.find(a => !a.startsWith("-"));
|
|
11
|
+
|
|
12
|
+
// Support --name CounterIsland or --name=CounterIsland
|
|
13
|
+
const nameIndex = args.indexOf("--name");
|
|
14
|
+
if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
15
|
+
rawIslandName = args[nameIndex + 1];
|
|
16
|
+
} else {
|
|
17
|
+
const nameEqual = args.find(a => a.startsWith("--name="));
|
|
18
|
+
if (nameEqual) {
|
|
19
|
+
rawIslandName = nameEqual.split("=")[1];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!rawIslandName) {
|
|
24
|
+
console.error(pc.red("\n❌ Error: Please specify an island name."));
|
|
25
|
+
console.log(pc.cyan(" Example: pnpm forgewp make:island CounterIsland"));
|
|
26
|
+
console.log(pc.cyan(" Or: pnpm forgewp make:island --name CounterIsland\n"));
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// PascalCase formatting
|
|
31
|
+
const cleanName = rawIslandName.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
32
|
+
const pascalCase = cleanName
|
|
33
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => word.toUpperCase())
|
|
34
|
+
.replace(/[^a-zA-Z0-9]/g, "");
|
|
35
|
+
|
|
36
|
+
if (!pascalCase) {
|
|
37
|
+
console.error(pc.red("\n❌ Error: Invalid island name.\n"));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const projectRoot = process.cwd();
|
|
42
|
+
|
|
43
|
+
if (!existsSync(path.join(projectRoot, "src"))) {
|
|
44
|
+
console.error(pc.red(`\n❌ Error: "src" folder not found. Are you in your theme's root directory?\n`));
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Load configuration and invoke adapter
|
|
49
|
+
let frameworkAdapter = "react";
|
|
50
|
+
try {
|
|
51
|
+
const config = await loadConfig(projectRoot);
|
|
52
|
+
frameworkAdapter = config.frameworkAdapter || "react";
|
|
53
|
+
} catch (err) {
|
|
54
|
+
// Use default
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
|
|
59
|
+
const adapter = adapterModule.default || adapterModule;
|
|
60
|
+
if (typeof adapter.onMakeIsland === "function") {
|
|
61
|
+
await adapter.onMakeIsland(projectRoot, {
|
|
62
|
+
pascalCase,
|
|
63
|
+
pc
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
console.error(pc.red(`\n❌ Error: Framework adapter "${frameworkAdapter}" does not support making interactive hydration islands.`));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
console.error(pc.red(`\n❌ Failed to execute make:island: ${err.message}`));
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
package/bin/make-post-type.js
CHANGED
|
@@ -33,10 +33,10 @@ if (!cleanName) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const projectRoot = process.cwd();
|
|
36
|
-
const wpDir = path.join(projectRoot, "
|
|
36
|
+
const wpDir = path.join(projectRoot, "cms");
|
|
37
37
|
const mockDataPath = path.join(wpDir, "mock-data.json");
|
|
38
38
|
|
|
39
|
-
// Ensure
|
|
39
|
+
// Ensure cms directory exists
|
|
40
40
|
if (!existsSync(wpDir)) {
|
|
41
41
|
mkdirSync(wpDir, { recursive: true });
|
|
42
42
|
}
|
|
@@ -47,13 +47,13 @@ if (existsSync(mockDataPath)) {
|
|
|
47
47
|
try {
|
|
48
48
|
mockData = JSON.parse(readFileSync(mockDataPath, "utf8"));
|
|
49
49
|
} catch (err) {
|
|
50
|
-
console.error(pc.red(`\n❌ Error: Failed to parse
|
|
50
|
+
console.error(pc.red(`\n❌ Error: Failed to parse cms/mock-data.json. Enforcing clean file.`));
|
|
51
51
|
mockData = {};
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (mockData[cleanName]) {
|
|
56
|
-
console.warn(pc.yellow(`\n⚠️ Post type "${cleanName}" already exists in
|
|
56
|
+
console.warn(pc.yellow(`\n⚠️ Post type "${cleanName}" already exists in cms/mock-data.json.`));
|
|
57
57
|
console.log(` You can open the file directly to view or edit existing fields.\n`);
|
|
58
58
|
process.exit(0);
|
|
59
59
|
}
|
|
@@ -97,7 +97,7 @@ mockData[cleanName] = [
|
|
|
97
97
|
id: 1,
|
|
98
98
|
title: `Sample ${cleanName.charAt(0).toUpperCase() + cleanName.slice(1)} Item 1`,
|
|
99
99
|
excerpt: `This is a custom ${cleanName} post seeded dynamically via ForgeWP CLI.`,
|
|
100
|
-
content: `<p>Welcome to your new custom <strong>${cleanName}</strong> post template! Edit this in
|
|
100
|
+
content: `<p>Welcome to your new custom <strong>${cleanName}</strong> post template! Edit this in cms/mock-data.json.</p>`,
|
|
101
101
|
date: new Date().toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }),
|
|
102
102
|
author: "ForgeWP CLI",
|
|
103
103
|
featuredImage: `https://picsum.photos/seed/${cleanName}1/1200/630`,
|
|
@@ -121,7 +121,7 @@ writeFileSync(mockDataPath, JSON.stringify(mockData, null, 2), "utf8");
|
|
|
121
121
|
const suggestedField = customFieldsList.length > 0 ? customFieldsList[0] : "client_name";
|
|
122
122
|
|
|
123
123
|
console.log(pc.green(`\n⚡ Post Type "${cleanName}" successfully registered!`));
|
|
124
|
-
console.log(` Local DB: ${pc.cyan(`
|
|
124
|
+
console.log(` Local DB: ${pc.cyan(`cms/mock-data.json`)}`);
|
|
125
125
|
console.log(`\n🎉 Query your seeded fields in React inside:`);
|
|
126
126
|
console.log(` ${pc.yellow(`<WpQueryLoop postType="${cleanName}" postsPerPage={2}>`)}`);
|
|
127
127
|
console.log(` ${pc.yellow(`<h3>{useWpTitle()}</h3>`)}`);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import { loadConfig } from "../lib/load-config.js";
|
|
7
|
+
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
let rawTemplateName = args.find(a => !a.startsWith("-"));
|
|
11
|
+
|
|
12
|
+
// Support --name PortfolioTemplate or --name=PortfolioTemplate
|
|
13
|
+
const nameIndex = args.indexOf("--name");
|
|
14
|
+
if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
15
|
+
rawTemplateName = args[nameIndex + 1];
|
|
16
|
+
} else {
|
|
17
|
+
const nameEqual = args.find(a => a.startsWith("--name="));
|
|
18
|
+
if (nameEqual) {
|
|
19
|
+
rawTemplateName = nameEqual.split("=")[1];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Check for legacy alias warning
|
|
24
|
+
if (process.env.FORGEWP_LEGACY_ALIAS === "1") {
|
|
25
|
+
console.log(pc.yellow(`\n⚠️ Legacy Command Warning: "make:component" is deprecated.`));
|
|
26
|
+
console.log(` Please use the new modern naming: ${pc.cyan("pnpm forgewp make:template <Name>")}\n`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!rawTemplateName) {
|
|
30
|
+
console.error(pc.red("\n❌ Error: Please specify a template name."));
|
|
31
|
+
console.log(pc.cyan(" Example: pnpm forgewp make:template PortfolioTemplate --postType=portfolio"));
|
|
32
|
+
console.log(pc.cyan(" Or: pnpm forgewp make:template --name PortfolioTemplate --postType=portfolio\n"));
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// PascalCase formatting
|
|
37
|
+
const cleanName = rawTemplateName.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
38
|
+
const pascalCase = cleanName
|
|
39
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => word.toUpperCase())
|
|
40
|
+
.replace(/[^a-zA-Z0-9]/g, "");
|
|
41
|
+
|
|
42
|
+
if (!pascalCase) {
|
|
43
|
+
console.error(pc.red("\n❌ Error: Invalid template name.\n"));
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Parse postType
|
|
48
|
+
let postType = "post";
|
|
49
|
+
const postTypeArg = args.find(a => a.startsWith("--postType=") || a.startsWith("--post-type="));
|
|
50
|
+
if (postTypeArg) {
|
|
51
|
+
postType = postTypeArg.split("=")[1];
|
|
52
|
+
} else {
|
|
53
|
+
const postTypeIndex = args.findIndex(a => a === "--postType" || a === "--post-type");
|
|
54
|
+
if (postTypeIndex !== -1 && args[postTypeIndex + 1]) {
|
|
55
|
+
postType = args[postTypeIndex + 1];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const projectRoot = process.cwd();
|
|
60
|
+
const mockDataPath = path.join(projectRoot, "cms", "mock-data.json");
|
|
61
|
+
|
|
62
|
+
if (!existsSync(path.join(projectRoot, "src"))) {
|
|
63
|
+
console.error(pc.red(`\n❌ Error: "src" folder not found. Are you in your theme's root directory?\n`));
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Try to load custom fields from mock-data.json for this post type
|
|
68
|
+
let customFields = [];
|
|
69
|
+
let automaticallySeeded = false;
|
|
70
|
+
|
|
71
|
+
if (existsSync(mockDataPath)) {
|
|
72
|
+
try {
|
|
73
|
+
const mockData = JSON.parse(readFileSync(mockDataPath, "utf8"));
|
|
74
|
+
if (!mockData[postType]) {
|
|
75
|
+
// SMART ACTION: Automatically register and seed postType records in the JSON database
|
|
76
|
+
mockData[postType] = [
|
|
77
|
+
{
|
|
78
|
+
id: 1,
|
|
79
|
+
title: `Sample ${postType.charAt(0).toUpperCase() + postType.slice(1)} Item 1`,
|
|
80
|
+
excerpt: `This is a custom ${postType} post seeded dynamically via ForgeWP CLI.`,
|
|
81
|
+
content: `<p>Welcome to your new custom <strong>${postType}</strong> post template! Edit this in cms/mock-data.json.</p>`,
|
|
82
|
+
date: new Date().toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }),
|
|
83
|
+
author: "ForgeWP CLI",
|
|
84
|
+
featuredImage: `https://picsum.photos/seed/${postType}1/1200/630`,
|
|
85
|
+
customFields: {
|
|
86
|
+
client_name: "Mock Enterprise",
|
|
87
|
+
project_budget: "$30,000",
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: 2,
|
|
92
|
+
title: `Sample ${postType.charAt(0).toUpperCase() + postType.slice(1)} Item 2`,
|
|
93
|
+
excerpt: `This is another custom ${postType} post seeded dynamically via ForgeWP CLI.`,
|
|
94
|
+
content: `<p>This is the second custom post for the ${postType} post type.</p>`,
|
|
95
|
+
date: new Date().toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }),
|
|
96
|
+
author: "ForgeWP CLI",
|
|
97
|
+
featuredImage: `https://picsum.photos/seed/${postType}2/1200/630`,
|
|
98
|
+
customFields: {
|
|
99
|
+
client_name: "Mock Organization",
|
|
100
|
+
project_budget: "$55,000",
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
// Save updated JSON
|
|
105
|
+
writeFileSync(mockDataPath, JSON.stringify(mockData, null, 2), "utf8");
|
|
106
|
+
automaticallySeeded = true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const records = mockData[postType] || [];
|
|
110
|
+
if (records.length > 0 && records[0].customFields) {
|
|
111
|
+
customFields = Object.keys(records[0].customFields);
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
// Ignore and fallback
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Load configuration and invoke adapter
|
|
119
|
+
let frameworkAdapter = "react";
|
|
120
|
+
try {
|
|
121
|
+
const config = await loadConfig(projectRoot);
|
|
122
|
+
frameworkAdapter = config.frameworkAdapter || "react";
|
|
123
|
+
} catch (err) {
|
|
124
|
+
// Use default
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
|
|
129
|
+
const adapter = adapterModule.default || adapterModule;
|
|
130
|
+
if (typeof adapter.onMakeTemplate === "function") {
|
|
131
|
+
await adapter.onMakeTemplate(projectRoot, {
|
|
132
|
+
pascalCase,
|
|
133
|
+
postType,
|
|
134
|
+
customFields,
|
|
135
|
+
automaticallySeeded,
|
|
136
|
+
pc
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
console.error(pc.red(`\n❌ Error: Framework adapter "${frameworkAdapter}" does not support making custom templates.`));
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.error(pc.red(`\n❌ Failed to execute make:template: ${err.message}`));
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
package/bin/repair.js
CHANGED
|
@@ -28,7 +28,7 @@ try {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Ensure default mock data table is recreated if deleted
|
|
31
|
-
const mockDataPath = path.join(projectRoot, "
|
|
31
|
+
const mockDataPath = path.join(projectRoot, "cms", "mock-data.json");
|
|
32
32
|
if (!existsSync(mockDataPath)) {
|
|
33
33
|
const defaultJson = {
|
|
34
34
|
menu: {
|
|
@@ -56,7 +56,7 @@ try {
|
|
|
56
56
|
mkdirSync(dirPath, { recursive: true });
|
|
57
57
|
}
|
|
58
58
|
writeFileSync(mockDataPath, JSON.stringify(defaultJson, null, 2), "utf8");
|
|
59
|
-
console.log(` ${pc.green("✅ Seeded Default Database")}:
|
|
59
|
+
console.log(` ${pc.green("✅ Seeded Default Database")}: cms/mock-data.json`);
|
|
60
60
|
repairedCount++;
|
|
61
61
|
}
|
|
62
62
|
|
package/bin/sync-routes.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import pc from "picocolors";
|
|
6
|
+
import { loadConfig } from "../lib/load-config.js";
|
|
7
|
+
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
6
8
|
|
|
7
9
|
console.log(`\n⚡ ${pc.bold(pc.bgCyan(pc.black(" FORGEWP SITEMAP COMPILER (SYNC:ROUTES) ")))}\n`);
|
|
8
10
|
|
|
@@ -11,18 +13,18 @@ const args = process.argv.slice(2);
|
|
|
11
13
|
const isForce = args.includes("--force") || args.includes("--override");
|
|
12
14
|
|
|
13
15
|
// 1. Locate menus configuration file
|
|
14
|
-
let menusPath = path.join(projectRoot, "
|
|
16
|
+
let menusPath = path.join(projectRoot, "cms", "menus.json");
|
|
15
17
|
let menus = null;
|
|
16
18
|
|
|
17
19
|
if (!existsSync(menusPath)) {
|
|
18
20
|
// Try fallback in mock-data.json
|
|
19
|
-
const mockDataPath = path.join(projectRoot, "
|
|
21
|
+
const mockDataPath = path.join(projectRoot, "cms", "mock-data.json");
|
|
20
22
|
if (existsSync(mockDataPath)) {
|
|
21
23
|
try {
|
|
22
24
|
const mockData = JSON.parse(readFileSync(mockDataPath, "utf8"));
|
|
23
25
|
if (mockData.menu) {
|
|
24
26
|
menus = mockData.menu;
|
|
25
|
-
console.log(` ℹ️ Using legacy menus block inside:
|
|
27
|
+
console.log(` ℹ️ Using legacy menus block inside: cms/mock-data.json`);
|
|
26
28
|
}
|
|
27
29
|
} catch (e) {
|
|
28
30
|
// Ignored
|
|
@@ -48,14 +50,14 @@ if (!existsSync(menusPath)) {
|
|
|
48
50
|
mkdirSync(dir, { recursive: true });
|
|
49
51
|
}
|
|
50
52
|
writeFileSync(menusPath, JSON.stringify(menus, null, 2), "utf8");
|
|
51
|
-
console.log(` 🎉 ${pc.green("Created dedicated sitemap source")}:
|
|
53
|
+
console.log(` 🎉 ${pc.green("Created dedicated sitemap source")}: cms/menus.json`);
|
|
52
54
|
}
|
|
53
55
|
} else {
|
|
54
56
|
try {
|
|
55
57
|
menus = JSON.parse(readFileSync(menusPath, "utf8"));
|
|
56
|
-
console.log(` 📖 ${pc.green("Loaded sitemap source")}:
|
|
58
|
+
console.log(` 📖 ${pc.green("Loaded sitemap source")}: cms/menus.json`);
|
|
57
59
|
} catch (err) {
|
|
58
|
-
console.error(pc.red(`\n❌ Error: Failed to parse
|
|
60
|
+
console.error(pc.red(`\n❌ Error: Failed to parse cms/menus.json.\nReason: ${err.message}`));
|
|
59
61
|
process.exit(1);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -101,160 +103,28 @@ if (routesToScaffold.length === 0) {
|
|
|
101
103
|
process.exit(0);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.join("") + "Page";
|
|
106
|
+
// Load configuration and invoke adapter
|
|
107
|
+
let frameworkAdapter = "react";
|
|
108
|
+
try {
|
|
109
|
+
const config = await loadConfig(projectRoot);
|
|
110
|
+
frameworkAdapter = config.frameworkAdapter || "react";
|
|
111
|
+
} catch (err) {
|
|
112
|
+
// Use default
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
for (const route of routesToScaffold) {
|
|
125
|
-
const componentName = toPascalCase(route.title);
|
|
126
|
-
const componentPath = path.join(pagesDir, `${componentName}.tsx`);
|
|
127
|
-
|
|
128
|
-
const componentContent = `/**
|
|
129
|
-
* ⚡ Auto-Generated Page Component by ForgeWP
|
|
130
|
-
*
|
|
131
|
-
* This file was generated automatically from your sitemap configuration (wordpress/menus.json).
|
|
132
|
-
* You can safely edit this file to customize the visual layout, styles, and logic.
|
|
133
|
-
* Subsequent runs of 'pnpm forgewp sync:routes' will NOT overwrite your changes.
|
|
134
|
-
*
|
|
135
|
-
* To force reset this page back to boilerplate defaults, run:
|
|
136
|
-
* 'pnpm forgewp sync:routes --force'
|
|
137
|
-
*/
|
|
138
|
-
import { SEO } from "../../.forgewp/SEO";
|
|
139
|
-
import { WpQueryLoop, useWpTitle, useWpExcerpt, useWpFeaturedImage } from "../../.forgewp/wordpress";
|
|
140
|
-
|
|
141
|
-
export function ${componentName}() {
|
|
142
|
-
return (
|
|
143
|
-
<main className="container mx-auto px-6 py-12">
|
|
144
|
-
{/* Dynamic SEO Injector */}
|
|
145
|
-
<SEO
|
|
146
|
-
title="${route.title}"
|
|
147
|
-
description="Explore our exclusive ${route.title} section, dynamically loaded in Headless React."
|
|
148
|
-
/>
|
|
149
|
-
|
|
150
|
-
{/* Hero Header Area */}
|
|
151
|
-
<header className="border-b-4 border-black pb-6 mb-12">
|
|
152
|
-
<h1 className="text-5xl font-black tracking-tight uppercase">${route.title}</h1>
|
|
153
|
-
<p className="text-zinc-500 mt-2 text-lg">
|
|
154
|
-
Auto-generated template. Edit <code className="bg-zinc-100 px-1 py-0.5 rounded text-sm text-red-600 font-mono">src/app/pages/${componentName}.tsx</code> to customize this page.
|
|
155
|
-
</p>
|
|
156
|
-
</header>
|
|
157
|
-
|
|
158
|
-
{/* Grid Starter - WordPress Mock Loop */}
|
|
159
|
-
<section className="grid grid-cols-1 md:grid-cols-3 gap-8">
|
|
160
|
-
<WpQueryLoop postType="post" postsPerPage={3}>
|
|
161
|
-
<article className="border-2 border-black p-6 bg-white shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:translate-y-[-2px] hover:shadow-[6px_6px_0px_0px_rgba(0,0,0,1)] transition-all">
|
|
162
|
-
<div className="w-full h-48 bg-zinc-100 mb-4 border border-zinc-200 overflow-hidden">
|
|
163
|
-
<img
|
|
164
|
-
src={useWpFeaturedImage()}
|
|
165
|
-
alt={useWpTitle()}
|
|
166
|
-
className="w-full h-full object-cover"
|
|
167
|
-
/>
|
|
168
|
-
</div>
|
|
169
|
-
<h2 className="text-xl font-bold uppercase tracking-tight mb-2">
|
|
170
|
-
{useWpTitle()}
|
|
171
|
-
</h2>
|
|
172
|
-
<p className="text-zinc-600 text-sm mb-4">
|
|
173
|
-
{useWpExcerpt()}
|
|
174
|
-
</p>
|
|
175
|
-
<a
|
|
176
|
-
href="#"
|
|
177
|
-
className="inline-block px-4 py-2 border-2 border-black bg-zinc-100 font-bold uppercase text-xs hover:bg-black hover:text-white transition-colors"
|
|
178
|
-
>
|
|
179
|
-
Read More
|
|
180
|
-
</a>
|
|
181
|
-
</article>
|
|
182
|
-
</WpQueryLoop>
|
|
183
|
-
</section>
|
|
184
|
-
</main>
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
`;
|
|
188
|
-
|
|
189
|
-
if (existsSync(componentPath) && !isForce) {
|
|
190
|
-
console.log(` ${pc.gray("ℹ️ [Skip] Component already exists:")} src/app/pages/${componentName}.tsx`);
|
|
191
|
-
skippedCount++;
|
|
192
|
-
} else {
|
|
193
|
-
writeFileSync(componentPath, componentContent, "utf8");
|
|
194
|
-
console.log(` ${pc.green("✅ Scaffolded component")}: src/app/pages/${componentName}.tsx`);
|
|
195
|
-
scaffoldedCount++;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// 5. Inject pages into src/app/routes.tsx
|
|
200
|
-
const routesFilePath = path.join(projectRoot, "src/app/routes.tsx");
|
|
201
|
-
if (existsSync(routesFilePath)) {
|
|
202
|
-
let routesContent = readFileSync(routesFilePath, "utf8");
|
|
203
|
-
let modified = false;
|
|
204
|
-
|
|
205
|
-
for (const route of routesToScaffold) {
|
|
206
|
-
const componentName = toPascalCase(route.title);
|
|
207
|
-
|
|
208
|
-
// Check if the component is imported
|
|
209
|
-
const importRegex = new RegExp(`import\\s+\\{\\s*${componentName}\\s*\\}\\s+from\\s+["']\\./pages/${componentName}["']`);
|
|
210
|
-
if (!importRegex.test(routesContent)) {
|
|
211
|
-
// Find a clean place to inject imports
|
|
212
|
-
// Right above "export default function" or under other imports
|
|
213
|
-
const defaultExportIndex = routesContent.indexOf("export default function");
|
|
214
|
-
if (defaultExportIndex !== -1) {
|
|
215
|
-
routesContent =
|
|
216
|
-
routesContent.slice(0, defaultExportIndex) +
|
|
217
|
-
`import { ${componentName} } from "./pages/${componentName}";\n` +
|
|
218
|
-
routesContent.slice(defaultExportIndex);
|
|
219
|
-
modified = true;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Check if the Route path is registered
|
|
224
|
-
const routeRegex = new RegExp(`path\\s*=\\s*["']${route.path}["']`);
|
|
225
|
-
if (!routeRegex.test(routesContent)) {
|
|
226
|
-
// Find the fallback route or closing Switch tag to inject
|
|
227
|
-
const fallbackMarker = "{/* Fallback route */}";
|
|
228
|
-
const fallbackIndex = routesContent.indexOf(fallbackMarker);
|
|
229
|
-
if (fallbackIndex !== -1) {
|
|
230
|
-
routesContent =
|
|
231
|
-
routesContent.slice(0, fallbackIndex) +
|
|
232
|
-
`<Route path="${route.path}" component={${componentName}} />\n\n ` +
|
|
233
|
-
routesContent.slice(fallbackIndex);
|
|
234
|
-
modified = true;
|
|
235
|
-
} else {
|
|
236
|
-
// Fallback to closing Switch tag
|
|
237
|
-
const switchCloseIndex = routesContent.indexOf("</Switch>");
|
|
238
|
-
if (switchCloseIndex !== -1) {
|
|
239
|
-
routesContent =
|
|
240
|
-
routesContent.slice(0, switchCloseIndex) +
|
|
241
|
-
` <Route path="${route.path}" component={${componentName}} />\n ` +
|
|
242
|
-
routesContent.slice(switchCloseIndex);
|
|
243
|
-
modified = true;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (modified) {
|
|
250
|
-
writeFileSync(routesFilePath, routesContent, "utf8");
|
|
251
|
-
console.log(` ${pc.green("✅ Synced routing paths in")}: src/app/routes.tsx`);
|
|
115
|
+
try {
|
|
116
|
+
const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
|
|
117
|
+
const adapter = adapterModule.default || adapterModule;
|
|
118
|
+
if (typeof adapter.onSyncRoutes === "function") {
|
|
119
|
+
await adapter.onSyncRoutes(projectRoot, {
|
|
120
|
+
routesToScaffold,
|
|
121
|
+
isForce,
|
|
122
|
+
pc
|
|
123
|
+
});
|
|
252
124
|
} else {
|
|
253
|
-
console.log(
|
|
125
|
+
console.log(pc.yellow(` ⚠️ No sync:routes hook implemented for framework adapter: ${frameworkAdapter}`));
|
|
254
126
|
}
|
|
255
|
-
}
|
|
256
|
-
console.
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.error(pc.red(`\n❌ Failed to execute sync:routes: ${err.message}`));
|
|
129
|
+
process.exit(1);
|
|
257
130
|
}
|
|
258
|
-
|
|
259
|
-
console.log("\n" + "─".repeat(60));
|
|
260
|
-
console.log(pc.green(`\n🎉 ${pc.bold("SITEMAP SYNC COMPLETE:")} Generated ${scaffoldedCount} new pages (skipped ${skippedCount}).\n`));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig } from './lib/define-config.js';
|
package/define-config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig } from './lib/define-config.js';
|