@forgewp/compiler 0.4.1 → 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 +20 -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/bin/sync-hooks.js +221 -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 +122 -1434
- package/lib/functions-builder.js +1172 -3
- package/lib/generate-theme.js +340 -23
- package/lib/hydration-scanner.js +170 -11
- 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 +110 -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 +115 -25
- package/lib/validate-export.js +49 -0
- package/package.json +4 -2
- package/templates/PresetsStyle.tsx +74 -0
- package/templates/SEO.tsx +109 -0
- 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 +110 -0
- package/templates/menus.json +11 -0
- package/templates/mock-data.json +123 -0
- 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 -0
package/README.md
CHANGED
|
@@ -34,17 +34,25 @@ Dynamically scaffolds dynamic WordPress blocks authored in React with options fo
|
|
|
34
34
|
pnpm forgewp make:block HeroBlock --attributes=heading,text,image,buttonText
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
### 4. Post-Type Loop
|
|
37
|
+
### 4. Post-Type Loop Scaffolder
|
|
38
38
|
|
|
39
39
|
Instantly scaffolds beautifully designed React loop grid components bound to custom WordPress post types (ACF-like integration):
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
pnpm forgewp make:
|
|
42
|
+
pnpm forgewp make:loop PortfolioGrid --postType=portfolio
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
_Note: If the requested post type does not exist in `cms/mock-data.json`, the compiler will automatically register and seed it for you!_
|
|
46
46
|
|
|
47
|
-
### 5.
|
|
47
|
+
### 5. Custom Page Template Scaffolder
|
|
48
|
+
|
|
49
|
+
Scaffold custom standalone WordPress Page Templates written in React:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pnpm forgewp make:page AboutUs
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 6. Resilient Framework Immunity & Diagnostics
|
|
48
56
|
|
|
49
57
|
Keep your monorepo perfectly healthy, clean, and self-healing:
|
|
50
58
|
|
package/bin/add.js
CHANGED
|
@@ -2,19 +2,22 @@
|
|
|
2
2
|
import { addComponent } from "../lib/add-component.js";
|
|
3
3
|
|
|
4
4
|
const args = process.argv.slice(2);
|
|
5
|
-
let
|
|
5
|
+
let components = args.filter(a => !a.startsWith("-"));
|
|
6
6
|
|
|
7
7
|
// Support --name navbar or --name=navbar
|
|
8
8
|
const nameIndex = args.indexOf("--name");
|
|
9
9
|
if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
10
|
-
|
|
10
|
+
components.push(args[nameIndex + 1]);
|
|
11
11
|
} else {
|
|
12
12
|
const nameEqual = args.find(a => a.startsWith("--name="));
|
|
13
13
|
if (nameEqual) {
|
|
14
|
-
|
|
14
|
+
components.push(nameEqual.split("=")[1]);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// Clean and deduplicate the component list
|
|
19
|
+
components = Array.from(new Set(components.map(c => c.trim()).filter(Boolean)));
|
|
20
|
+
|
|
18
21
|
import { readFileSync, existsSync } from "node:fs";
|
|
19
22
|
import path from "node:path";
|
|
20
23
|
|
|
@@ -35,12 +38,18 @@ try {
|
|
|
35
38
|
|
|
36
39
|
const style = args.find(a => a.startsWith("--style="))?.split("=")[1] || projectStyle;
|
|
37
40
|
|
|
38
|
-
if (
|
|
39
|
-
console.error("Usage: forgewp add <
|
|
41
|
+
if (components.length === 0) {
|
|
42
|
+
console.error("Usage: forgewp add <component1> [component2] ... [--style=forgewp|shadcn]");
|
|
40
43
|
process.exit(1);
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
async function run() {
|
|
47
|
+
for (const component of components) {
|
|
48
|
+
await addComponent(component, { style });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
run().catch((err) => {
|
|
44
53
|
console.error(err.message);
|
|
45
54
|
process.exit(1);
|
|
46
55
|
});
|
package/bin/analyze.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import pc from "picocolors";
|
|
6
6
|
import { exec } from "node:child_process";
|
|
@@ -98,6 +98,56 @@ async function main() {
|
|
|
98
98
|
const violations = runStaticLintChecks(projectRoot);
|
|
99
99
|
analysis.violations = violations;
|
|
100
100
|
|
|
101
|
+
// 6.5. Run Auth Security checks & parse manifest
|
|
102
|
+
const authManifestPath = path.join(projectRoot, ".forgewp", "out", config.slug, "auth-manifest.json");
|
|
103
|
+
let authManifest = { protectedPages: [], authGates: [] };
|
|
104
|
+
if (existsSync(authManifestPath)) {
|
|
105
|
+
try {
|
|
106
|
+
authManifest = JSON.parse(readFileSync(authManifestPath, "utf8"));
|
|
107
|
+
} catch {}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const authWarnings = [];
|
|
111
|
+
const pagesDir = path.join(projectRoot, "src", "app", "pages");
|
|
112
|
+
if (existsSync(pagesDir)) {
|
|
113
|
+
const collectPagesRecursive = (dir, list = []) => {
|
|
114
|
+
const items = readdirSync(dir, { withFileTypes: true });
|
|
115
|
+
for (const item of items) {
|
|
116
|
+
const fullPath = path.join(dir, item.name);
|
|
117
|
+
if (item.isDirectory()) {
|
|
118
|
+
collectPagesRecursive(fullPath, list);
|
|
119
|
+
} else if (item.isFile() && (item.name.endsWith(".tsx") || item.name.endsWith(".ts"))) {
|
|
120
|
+
list.push(fullPath);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return list;
|
|
124
|
+
};
|
|
125
|
+
try {
|
|
126
|
+
const pageFiles = collectPagesRecursive(pagesDir);
|
|
127
|
+
for (const file of pageFiles) {
|
|
128
|
+
const content = readFileSync(file, "utf8");
|
|
129
|
+
const hasAuthHooks = content.includes("useWpAuth") || content.includes("useWpUser");
|
|
130
|
+
if (hasAuthHooks) {
|
|
131
|
+
const fileBasename = path.basename(file, path.extname(file));
|
|
132
|
+
const slug = fileBasename
|
|
133
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
134
|
+
.toLowerCase();
|
|
135
|
+
|
|
136
|
+
const isPageProtected = authManifest.protectedPages.some(
|
|
137
|
+
p => p.page === slug || p.page === slug.replace(/-page$/, "")
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if (!isPageProtected) {
|
|
141
|
+
authWarnings.push({
|
|
142
|
+
file: path.relative(projectRoot, file),
|
|
143
|
+
message: `Page utilizes authentication hooks (useWpAuth/useWpUser) but is not protected by server-side page guards.`
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch {}
|
|
149
|
+
}
|
|
150
|
+
|
|
101
151
|
// 7. Generate HTML report
|
|
102
152
|
let reportPath;
|
|
103
153
|
try {
|
|
@@ -115,6 +165,21 @@ async function main() {
|
|
|
115
165
|
const totalJsKb = analysis.results.reduce((acc, curr) => acc + curr.sizeKb, 0);
|
|
116
166
|
console.log(` Total Client JS Weight: ${totalJsKb > 200 ? pc.red(totalJsKb.toFixed(1) + " kB") : pc.green(totalJsKb.toFixed(1) + " kB")}`);
|
|
117
167
|
|
|
168
|
+
console.log(`\n🔍 ${pc.bold("ForgeWP Auth Analysis")}`);
|
|
169
|
+
console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
|
|
170
|
+
console.log(` Protected Pages: ${pc.cyan(authManifest.protectedPages.length)}`);
|
|
171
|
+
console.log(` Auth Gates: ${pc.cyan(authManifest.authGates.filter(g => g.type === 'logged_in').length)}`);
|
|
172
|
+
console.log(` Capability Gates: ${pc.cyan(authManifest.authGates.filter(g => g.type === 'capability').length)}`);
|
|
173
|
+
|
|
174
|
+
if (authWarnings.length > 0) {
|
|
175
|
+
console.log(`\n⚠️ ${pc.bold(pc.yellow("SECURITY WARNINGS"))}`);
|
|
176
|
+
for (const w of authWarnings) {
|
|
177
|
+
console.log(` ${pc.yellow("⚠️ WARN")} ${pc.bold(w.file)}: ${w.message}`);
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
console.log(`\n✅ ${pc.green(pc.bold("Security Audit Passed:"))} No unprotected page auth hook usages detected.`);
|
|
181
|
+
}
|
|
182
|
+
|
|
118
183
|
if (violations.length > 0) {
|
|
119
184
|
console.log(`\n⚠️ ${pc.bold(pc.yellow("THEME LINT WARNINGS & SEO RECOMMENDATIONS"))}`);
|
|
120
185
|
for (const v of violations) {
|
package/bin/cli.js
CHANGED
|
@@ -11,10 +11,12 @@ const subcommands = {
|
|
|
11
11
|
add: path.join(__dirname, "add.js"),
|
|
12
12
|
"make:block": path.join(__dirname, "make-block.js"),
|
|
13
13
|
"make:post-type": path.join(__dirname, "make-post-type.js"),
|
|
14
|
-
"make:
|
|
15
|
-
"make:
|
|
14
|
+
"make:loop": path.join(__dirname, "make-loop.js"),
|
|
15
|
+
"make:page": path.join(__dirname, "make-page.js"),
|
|
16
16
|
"make:island": path.join(__dirname, "make-island.js"),
|
|
17
|
+
"make:sandbox": path.join(__dirname, "make-sandbox.js"),
|
|
17
18
|
"sync:routes": path.join(__dirname, "sync-routes.js"),
|
|
19
|
+
"sync:hooks": path.join(__dirname, "sync-hooks.js"),
|
|
18
20
|
"i18n:extract": path.join(__dirname, "i18n-extract.js"),
|
|
19
21
|
"i18n:translate": path.join(__dirname, "i18n-translate.js"),
|
|
20
22
|
export: path.join(__dirname, "export.js"),
|
|
@@ -41,14 +43,18 @@ if (!targetScript) {
|
|
|
41
43
|
targetScript = subcommands["make:block"];
|
|
42
44
|
} else if (command === "make-post-type" || command === "post-type" || command === "make:post-type") {
|
|
43
45
|
targetScript = subcommands["make:post-type"];
|
|
44
|
-
} else if (command === "make-
|
|
45
|
-
targetScript = subcommands["make:
|
|
46
|
-
} else if (command === "make-
|
|
47
|
-
targetScript = subcommands["make:
|
|
46
|
+
} else if (command === "make-loop" || command === "loop" || command === "make:loop") {
|
|
47
|
+
targetScript = subcommands["make:loop"];
|
|
48
|
+
} else if (command === "make-page" || command === "page" || command === "make:page") {
|
|
49
|
+
targetScript = subcommands["make:page"];
|
|
48
50
|
} else if (command === "make-island" || command === "island" || command === "make:island") {
|
|
49
51
|
targetScript = subcommands["make:island"];
|
|
52
|
+
} else if (command === "make-sandbox" || command === "sandbox" || command === "make:sandbox") {
|
|
53
|
+
targetScript = subcommands["make:sandbox"];
|
|
50
54
|
} else if (command === "sync-routes" || command === "sync" || command === "sync:routes") {
|
|
51
55
|
targetScript = subcommands["sync:routes"];
|
|
56
|
+
} else if (command === "sync-hooks" || command === "sync:hooks") {
|
|
57
|
+
targetScript = subcommands["sync:hooks"];
|
|
52
58
|
} else if (command === "i18n-extract" || command === "i18n:extract") {
|
|
53
59
|
targetScript = subcommands["i18n:extract"];
|
|
54
60
|
} else if (command === "i18n-translate" || command === "i18n:translate") {
|
|
@@ -72,10 +78,6 @@ const commandArgs = args.slice(1);
|
|
|
72
78
|
// Run the subcommand using spawn, inheriting stdio for rich interactivity
|
|
73
79
|
const child = spawn(process.execPath, [targetScript, ...commandArgs], {
|
|
74
80
|
stdio: "inherit",
|
|
75
|
-
env: {
|
|
76
|
-
...process.env,
|
|
77
|
-
FORGEWP_LEGACY_ALIAS: (command === "make:component" || command === "make-component" || command === "component") ? "1" : "0",
|
|
78
|
-
},
|
|
79
81
|
});
|
|
80
82
|
|
|
81
83
|
child.on("close", (code) => {
|
|
@@ -93,9 +95,12 @@ function printHelp() {
|
|
|
93
95
|
${pc.cyan("add <component>")} Add registry components (e.g. navbar)
|
|
94
96
|
${pc.cyan("make:block <Name>")} Scaffold a type-safe Gutenberg Block via defineBlock()
|
|
95
97
|
${pc.cyan("make:post-type <slug>")} Register a custom mock post-type (e.g. portfolio)
|
|
96
|
-
${pc.cyan("make:
|
|
98
|
+
${pc.cyan("make:loop <Name>")} Scaffold a custom post-type loop feed component
|
|
99
|
+
${pc.cyan("make:page <Name>")} Scaffold a custom WordPress Page Template
|
|
97
100
|
${pc.cyan("make:island <Name>")} Scaffold an interactive selective hydration island
|
|
101
|
+
${pc.cyan("make:sandbox <type>")} Scaffold sandbox mock databases (e.g. ecommerce, auth)
|
|
98
102
|
${pc.cyan("sync:routes")} Synchronize sitemap menus with routes and scaffold pages
|
|
103
|
+
${pc.cyan("sync:hooks")} Propagate wordpress.tsx hooks to all workspace projects
|
|
99
104
|
${pc.cyan("i18n:extract")} Extract translation strings to translations.json
|
|
100
105
|
${pc.cyan("i18n:translate")} Translate missing strings via the configured engine
|
|
101
106
|
${pc.cyan("export")} Package your theme into an installable WP zip
|
|
@@ -109,7 +114,10 @@ function printHelp() {
|
|
|
109
114
|
pnpm forgewp add navbar
|
|
110
115
|
pnpm forgewp make:block HeroBlock --attributes=title,subtitle
|
|
111
116
|
pnpm forgewp make:post-type portfolio --customFields=client_name
|
|
112
|
-
pnpm forgewp make:
|
|
117
|
+
pnpm forgewp make:sandbox ecommerce
|
|
118
|
+
pnpm forgewp make:sandbox auth
|
|
119
|
+
pnpm forgewp make:loop PortfolioGrid --postType=portfolio
|
|
120
|
+
pnpm forgewp make:page AboutUs
|
|
113
121
|
pnpm forgewp make:island CounterIsland
|
|
114
122
|
pnpm forgewp sync:routes
|
|
115
123
|
pnpm forgewp doctor
|
package/bin/fresh.js
CHANGED
|
@@ -58,7 +58,7 @@ for (const targetPrune of directoriesToPrune) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// 3. Restore Standard Database & Sitemap Menus from Core Blueprints
|
|
61
|
-
const coreFilesToReset = ["cms/menus.json", "cms/mock-data.json"];
|
|
61
|
+
const coreFilesToReset = ["cms/menus.json", "cms/mock-data.json", "cms/products.json"];
|
|
62
62
|
for (const relPath of coreFilesToReset) {
|
|
63
63
|
const fullPath = path.join(projectRoot, relPath);
|
|
64
64
|
const blueprintContent = SYSTEM_BLUEPRINTS[relPath];
|
package/bin/make-block.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
5
7
|
import pc from "picocolors";
|
|
6
8
|
import { loadConfig } from "../lib/load-config.js";
|
|
7
9
|
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
@@ -20,6 +22,15 @@ if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
if (!rawBlockName) {
|
|
26
|
+
const rl = readline.createInterface({ input, output });
|
|
27
|
+
try {
|
|
28
|
+
const answer = await rl.question(pc.cyan("? Enter a block name: "));
|
|
29
|
+
rawBlockName = answer.trim();
|
|
30
|
+
} catch (err) {}
|
|
31
|
+
rl.close();
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
if (!rawBlockName) {
|
|
24
35
|
console.error(pc.red("\n❌ Error: Please specify a block name."));
|
|
25
36
|
console.log(pc.cyan(" Example: pnpm forgewp make:block TestimonialBlock"));
|
package/bin/make-island.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
5
7
|
import pc from "picocolors";
|
|
6
8
|
import { loadConfig } from "../lib/load-config.js";
|
|
7
9
|
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
@@ -20,6 +22,15 @@ if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
if (!rawIslandName) {
|
|
26
|
+
const rl = readline.createInterface({ input, output });
|
|
27
|
+
try {
|
|
28
|
+
const answer = await rl.question(pc.cyan("? Enter an island name: "));
|
|
29
|
+
rawIslandName = answer.trim();
|
|
30
|
+
} catch (err) {}
|
|
31
|
+
rl.close();
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
if (!rawIslandName) {
|
|
24
35
|
console.error(pc.red("\n❌ Error: Please specify an island name."));
|
|
25
36
|
console.log(pc.cyan(" Example: pnpm forgewp make:island CounterIsland"));
|
|
@@ -2,45 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
5
7
|
import pc from "picocolors";
|
|
6
8
|
import { loadConfig } from "../lib/load-config.js";
|
|
7
9
|
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
8
10
|
|
|
9
11
|
const args = process.argv.slice(2);
|
|
10
|
-
let
|
|
12
|
+
let rawLoopName = args.find(a => !a.startsWith("-"));
|
|
11
13
|
|
|
12
|
-
// Support --name
|
|
14
|
+
// Support --name PortfolioGrid or --name=PortfolioGrid
|
|
13
15
|
const nameIndex = args.indexOf("--name");
|
|
14
16
|
if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
15
|
-
|
|
17
|
+
rawLoopName = args[nameIndex + 1];
|
|
16
18
|
} else {
|
|
17
19
|
const nameEqual = args.find(a => a.startsWith("--name="));
|
|
18
20
|
if (nameEqual) {
|
|
19
|
-
|
|
21
|
+
rawLoopName = nameEqual.split("=")[1];
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (!rawLoopName) {
|
|
26
|
+
const rl = readline.createInterface({ input, output });
|
|
27
|
+
try {
|
|
28
|
+
const answer = await rl.question(pc.cyan("? Enter a loop name: "));
|
|
29
|
+
rawLoopName = answer.trim();
|
|
30
|
+
} catch (err) {}
|
|
31
|
+
rl.close();
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
if (!
|
|
30
|
-
console.error(pc.red("\n❌ Error: Please specify a
|
|
31
|
-
console.log(pc.cyan(" Example: pnpm forgewp make:
|
|
32
|
-
console.log(pc.cyan(" Or: pnpm forgewp make:
|
|
34
|
+
if (!rawLoopName) {
|
|
35
|
+
console.error(pc.red("\n❌ Error: Please specify a loop name."));
|
|
36
|
+
console.log(pc.cyan(" Example: pnpm forgewp make:loop PortfolioGrid --postType=portfolio"));
|
|
37
|
+
console.log(pc.cyan(" Or: pnpm forgewp make:loop --name PortfolioGrid --postType=portfolio\n"));
|
|
33
38
|
process.exit(1);
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
// PascalCase formatting
|
|
37
|
-
const cleanName =
|
|
42
|
+
const cleanName = rawLoopName.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
38
43
|
const pascalCase = cleanName
|
|
39
44
|
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => word.toUpperCase())
|
|
40
45
|
.replace(/[^a-zA-Z0-9]/g, "");
|
|
41
46
|
|
|
42
47
|
if (!pascalCase) {
|
|
43
|
-
console.error(pc.red("\n❌ Error: Invalid
|
|
48
|
+
console.error(pc.red("\n❌ Error: Invalid loop name.\n"));
|
|
44
49
|
process.exit(1);
|
|
45
50
|
}
|
|
46
51
|
|
|
@@ -78,7 +83,7 @@ if (existsSync(mockDataPath)) {
|
|
|
78
83
|
id: 1,
|
|
79
84
|
title: `Sample ${postType.charAt(0).toUpperCase() + postType.slice(1)} Item 1`,
|
|
80
85
|
excerpt: `This is a custom ${postType} post seeded dynamically via ForgeWP CLI.`,
|
|
81
|
-
content: `<p>Welcome to your new custom <strong>${postType}</strong> post
|
|
86
|
+
content: `<p>Welcome to your new custom <strong>${postType}</strong> post loop! Edit this in cms/mock-data.json.</p>`,
|
|
82
87
|
date: new Date().toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }),
|
|
83
88
|
author: "ForgeWP CLI",
|
|
84
89
|
featuredImage: `https://picsum.photos/seed/${postType}1/1200/630`,
|
|
@@ -127,8 +132,8 @@ try {
|
|
|
127
132
|
try {
|
|
128
133
|
const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
|
|
129
134
|
const adapter = adapterModule.default || adapterModule;
|
|
130
|
-
if (typeof adapter.
|
|
131
|
-
await adapter.
|
|
135
|
+
if (typeof adapter.onMakeLoop === "function") {
|
|
136
|
+
await adapter.onMakeLoop(projectRoot, {
|
|
132
137
|
pascalCase,
|
|
133
138
|
postType,
|
|
134
139
|
customFields,
|
|
@@ -136,10 +141,10 @@ try {
|
|
|
136
141
|
pc
|
|
137
142
|
});
|
|
138
143
|
} else {
|
|
139
|
-
console.error(pc.red(`\n❌ Error: Framework adapter "${frameworkAdapter}" does not support making custom
|
|
144
|
+
console.error(pc.red(`\n❌ Error: Framework adapter "${frameworkAdapter}" does not support making custom loops.`));
|
|
140
145
|
process.exit(1);
|
|
141
146
|
}
|
|
142
147
|
} catch (err) {
|
|
143
|
-
console.error(pc.red(`\n❌ Failed to execute make:
|
|
148
|
+
console.error(pc.red(`\n❌ Failed to execute make:loop: ${err.message}`));
|
|
144
149
|
process.exit(1);
|
|
145
150
|
}
|
package/bin/make-page.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
7
|
+
import pc from "picocolors";
|
|
8
|
+
import { loadConfig } from "../lib/load-config.js";
|
|
9
|
+
import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
let rawPageName = args.find(a => !a.startsWith("-"));
|
|
13
|
+
|
|
14
|
+
// Support --name AboutUs or --name=AboutUs
|
|
15
|
+
const nameIndex = args.indexOf("--name");
|
|
16
|
+
if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
17
|
+
rawPageName = args[nameIndex + 1];
|
|
18
|
+
} else {
|
|
19
|
+
const nameEqual = args.find(a => a.startsWith("--name="));
|
|
20
|
+
if (nameEqual) {
|
|
21
|
+
rawPageName = nameEqual.split("=")[1];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!rawPageName) {
|
|
26
|
+
const rl = readline.createInterface({ input, output });
|
|
27
|
+
try {
|
|
28
|
+
const answer = await rl.question(pc.cyan("? Enter a page name: "));
|
|
29
|
+
rawPageName = answer.trim();
|
|
30
|
+
} catch (err) {}
|
|
31
|
+
rl.close();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!rawPageName) {
|
|
35
|
+
console.error(pc.red("\n❌ Error: Please specify a page name."));
|
|
36
|
+
console.log(pc.cyan(" Example: pnpm forgewp make:page AboutUs"));
|
|
37
|
+
console.log(pc.cyan(" Or: pnpm forgewp make:page --name AboutUs\n"));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// PascalCase formatting
|
|
42
|
+
const cleanName = rawPageName.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
43
|
+
const pascalCase = cleanName
|
|
44
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => word.toUpperCase())
|
|
45
|
+
.replace(/[^a-zA-Z0-9]/g, "");
|
|
46
|
+
|
|
47
|
+
if (!pascalCase) {
|
|
48
|
+
console.error(pc.red("\n❌ Error: Invalid page name.\n"));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const projectRoot = process.cwd();
|
|
53
|
+
|
|
54
|
+
if (!existsSync(path.join(projectRoot, "src"))) {
|
|
55
|
+
console.error(pc.red(`\n❌ Error: "src" folder not found. Are you in your theme's root directory?\n`));
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Load configuration and invoke adapter
|
|
60
|
+
let frameworkAdapter = "react";
|
|
61
|
+
try {
|
|
62
|
+
const config = await loadConfig(projectRoot);
|
|
63
|
+
frameworkAdapter = config.frameworkAdapter || "react";
|
|
64
|
+
} catch (err) {
|
|
65
|
+
// Use default
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
|
|
70
|
+
const adapter = adapterModule.default || adapterModule;
|
|
71
|
+
if (typeof adapter.onMakePage === "function") {
|
|
72
|
+
await adapter.onMakePage(projectRoot, {
|
|
73
|
+
pascalCase,
|
|
74
|
+
pc
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
console.error(pc.red(`\n❌ Error: Framework adapter "${frameworkAdapter}" does not support making custom page templates.`));
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.error(pc.red(`\n❌ Failed to execute make:page: ${err.message}`));
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
package/bin/make-post-type.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync, mkdirSync, writeFileSync, readFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
5
7
|
import pc from "picocolors";
|
|
6
8
|
|
|
7
9
|
const args = process.argv.slice(2);
|
|
@@ -18,6 +20,15 @@ if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
if (!rawName) {
|
|
24
|
+
const rl = readline.createInterface({ input, output });
|
|
25
|
+
try {
|
|
26
|
+
const answer = await rl.question(pc.cyan("? Enter a post type name: "));
|
|
27
|
+
rawName = answer.trim();
|
|
28
|
+
} catch (err) {}
|
|
29
|
+
rl.close();
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
if (!rawName) {
|
|
22
33
|
console.error(pc.red("\n❌ Error: Please specify a post type name."));
|
|
23
34
|
console.log(pc.cyan(" Example: pnpm forgewp make:post-type portfolio"));
|