@forgewp/compiler 0.1.7 โ 0.1.9
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 +29 -2
- package/bin/add.js +33 -3
- package/bin/clean.js +37 -0
- package/bin/cli.js +97 -0
- package/bin/doctor.js +99 -0
- package/bin/export.js +0 -0
- package/bin/fresh.js +421 -0
- package/bin/make-block.js +130 -0
- package/bin/make-component.js +200 -0
- package/bin/make-post-type.js +129 -0
- package/bin/repair.js +69 -0
- package/bin/sync-routes.js +260 -0
- package/lib/add-component.js +19 -4
- package/lib/blueprints.js +501 -316
- package/lib/generate-theme.js +341 -11
- package/lib/index.d.ts +1 -0
- package/lib/render-static.js +4 -0
- package/lib/render-theme.mts +32 -0
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -18,7 +18,33 @@ pnpm export
|
|
|
18
18
|
A powerful utility that pulls components from the ForgeWP Registry or shadcn/ui and applies the signature **Sharpness Transformer**.
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
pnpm forgewp
|
|
21
|
+
pnpm forgewp add navbar
|
|
22
|
+
# Or
|
|
23
|
+
pnpm forgewp add --name navbar
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 3. Native Gutenberg Block Generator
|
|
27
|
+
Dynamically scaffolds dynamic WordPress blocks authored in React with options for custom attributes:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm forgewp make:block HeroBlock --attributes=heading,text,image,buttonText
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 4. Post-Type Loop Component Scaffolder
|
|
34
|
+
Instantly scaffolds beautifully designed React loop grid components bound to custom WordPress post types (ACF-like integration):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm forgewp make:component PortfolioGrid --postType=portfolio
|
|
38
|
+
```
|
|
39
|
+
*Note: If the requested post type does not exist in `wordpress/mock-data.json`, the compiler will automatically register and seed it for you!*
|
|
40
|
+
|
|
41
|
+
### 5. Resilient Framework Immunity & Diagnostics
|
|
42
|
+
Keep your monorepo perfectly healthy, clean, and self-healing:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pnpm forgewp doctor # Run diagnostic health & dependency checks
|
|
46
|
+
pnpm forgewp repair # Force restore framework utility blueprints
|
|
47
|
+
pnpm forgewp clean # Prune build artifacts and clear caches
|
|
22
48
|
```
|
|
23
49
|
|
|
24
50
|
## ๐ Configuration
|
|
@@ -35,4 +61,5 @@ export default {
|
|
|
35
61
|
|
|
36
62
|
---
|
|
37
63
|
|
|
38
|
-
Maintainable,
|
|
64
|
+
Maintainable, Resilient, WordPress-native.
|
|
65
|
+
|
package/bin/add.js
CHANGED
|
@@ -2,11 +2,41 @@
|
|
|
2
2
|
import { addComponent } from "../lib/add-component.js";
|
|
3
3
|
|
|
4
4
|
const args = process.argv.slice(2);
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
let component = args.find(a => !a.startsWith("-"));
|
|
6
|
+
|
|
7
|
+
// Support --name navbar or --name=navbar
|
|
8
|
+
const nameIndex = args.indexOf("--name");
|
|
9
|
+
if (nameIndex !== -1 && args[nameIndex + 1]) {
|
|
10
|
+
component = args[nameIndex + 1];
|
|
11
|
+
} else {
|
|
12
|
+
const nameEqual = args.find(a => a.startsWith("--name="));
|
|
13
|
+
if (nameEqual) {
|
|
14
|
+
component = nameEqual.split("=")[1];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
|
|
21
|
+
let projectStyle = "forgewp";
|
|
22
|
+
try {
|
|
23
|
+
// Read wp.config.ts natively by regexing the 'style' property since it's a TS file
|
|
24
|
+
const wpConfigPath = path.join(process.cwd(), "wp.config.ts");
|
|
25
|
+
if (existsSync(wpConfigPath)) {
|
|
26
|
+
const content = readFileSync(wpConfigPath, "utf8");
|
|
27
|
+
const styleMatch = content.match(/style:\s*['"](forgewp|shadcn)['"]/);
|
|
28
|
+
if (styleMatch && styleMatch[1]) {
|
|
29
|
+
projectStyle = styleMatch[1];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
} catch (e) {
|
|
33
|
+
// Silent fallback
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const style = args.find(a => a.startsWith("--style="))?.split("=")[1] || projectStyle;
|
|
7
37
|
|
|
8
38
|
if (!component) {
|
|
9
|
-
console.error("Usage: forgewp
|
|
39
|
+
console.error("Usage: forgewp add <component> [--style=forgewp|shadcn] or forgewp add --name <component>");
|
|
10
40
|
process.exit(1);
|
|
11
41
|
}
|
|
12
42
|
|
package/bin/clean.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { rmSync, existsSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
|
|
7
|
+
console.log(`\n๐งน ${pc.bold(pc.bgMagenta(pc.black(" FORGEWP CACHE CLEANER ")))}\n`);
|
|
8
|
+
|
|
9
|
+
const projectRoot = process.cwd();
|
|
10
|
+
const foldersToClean = [
|
|
11
|
+
".forgewp",
|
|
12
|
+
"dist",
|
|
13
|
+
".vite"
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
let cleanedCount = 0;
|
|
17
|
+
|
|
18
|
+
for (const folder of foldersToClean) {
|
|
19
|
+
const target = path.join(projectRoot, folder);
|
|
20
|
+
if (existsSync(target)) {
|
|
21
|
+
try {
|
|
22
|
+
rmSync(target, { recursive: true, force: true });
|
|
23
|
+
console.log(` ${pc.green("โ
Cleared folder")}: ${pc.cyan(folder)}`);
|
|
24
|
+
cleanedCount++;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.log(pc.red(` โ Failed to clear ${folder}: ${err.message}`));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log("\n" + "โ".repeat(60));
|
|
32
|
+
if (cleanedCount > 0) {
|
|
33
|
+
console.log(pc.green(`\n๐ ${pc.bold("CLEAN COMPLETE:")} Pruned ${cleanedCount} build artifact/cache folders.`));
|
|
34
|
+
console.log(pc.cyan(" Your development workspace is now 100% clean and fresh.\n"));
|
|
35
|
+
} else {
|
|
36
|
+
console.log(pc.yellow(`\nโ ๏ธ ${pc.bold("NO ACTION NEEDED:")} No cached build folders or artifacts found. Workspace is already clean!\n`));
|
|
37
|
+
}
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
const subcommands = {
|
|
11
|
+
add: path.join(__dirname, "add.js"),
|
|
12
|
+
"make:block": path.join(__dirname, "make-block.js"),
|
|
13
|
+
"make:post-type": path.join(__dirname, "make-post-type.js"),
|
|
14
|
+
"make:component": path.join(__dirname, "make-component.js"),
|
|
15
|
+
"sync:routes": path.join(__dirname, "sync-routes.js"),
|
|
16
|
+
export: path.join(__dirname, "export.js"),
|
|
17
|
+
doctor: path.join(__dirname, "doctor.js"),
|
|
18
|
+
repair: path.join(__dirname, "repair.js"),
|
|
19
|
+
clean: path.join(__dirname, "clean.js"),
|
|
20
|
+
fresh: path.join(__dirname, "fresh.js"),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
const command = args[0];
|
|
25
|
+
|
|
26
|
+
if (!command || command === "-h" || command === "--help") {
|
|
27
|
+
printHelp();
|
|
28
|
+
process.exit(0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let targetScript = subcommands[command];
|
|
32
|
+
|
|
33
|
+
// Helper fallback routes
|
|
34
|
+
if (!targetScript) {
|
|
35
|
+
if (command === "make-block" || command === "make") {
|
|
36
|
+
targetScript = subcommands["make:block"];
|
|
37
|
+
} else if (command === "make-post-type" || command === "post-type" || command === "make:post-type") {
|
|
38
|
+
targetScript = subcommands["make:post-type"];
|
|
39
|
+
} else if (command === "make-component" || command === "component" || command === "make:component") {
|
|
40
|
+
targetScript = subcommands["make:component"];
|
|
41
|
+
} else if (command === "sync-routes" || command === "sync" || command === "sync:routes") {
|
|
42
|
+
targetScript = subcommands["sync:routes"];
|
|
43
|
+
} else if (command === "reset") {
|
|
44
|
+
targetScript = subcommands["fresh"];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!targetScript) {
|
|
49
|
+
console.error(pc.red(`\nโ Error: Unknown command "${command}"`));
|
|
50
|
+
printHelp();
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Forward other parameters
|
|
55
|
+
const commandArgs = args.slice(1);
|
|
56
|
+
|
|
57
|
+
// Run the subcommand using spawn, inheriting stdio for rich interactivity
|
|
58
|
+
const child = spawn(process.execPath, [targetScript, ...commandArgs], {
|
|
59
|
+
stdio: "inherit",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
child.on("close", (code) => {
|
|
63
|
+
process.exit(code ?? 0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
function printHelp() {
|
|
67
|
+
console.log(`
|
|
68
|
+
${pc.bold(pc.bgCyan(pc.black(" โก FORGEWP CLI ")))} ${pc.cyan("โ Fast visual frameworks for WordPress")}
|
|
69
|
+
|
|
70
|
+
${pc.bold("Usage:")}
|
|
71
|
+
pnpm forgewp <command> [options]
|
|
72
|
+
|
|
73
|
+
${pc.bold("Commands:")}
|
|
74
|
+
${pc.cyan("add <component>")} Add registry components (e.g. navbar)
|
|
75
|
+
${pc.cyan("make:block <Name>")} Scaffold a React Gutenberg block (e.g. HeroBlock)
|
|
76
|
+
${pc.cyan("make:post-type <slug>")} Register a custom mock post-type (e.g. portfolio)
|
|
77
|
+
${pc.cyan("make:component <Name>")} Scaffold a post-type grid loop component
|
|
78
|
+
${pc.cyan("sync:routes")} Synchronize sitemap menus with routes and scaffold pages
|
|
79
|
+
${pc.cyan("export")} Package your theme into an installable WP zip
|
|
80
|
+
${pc.cyan("doctor")} Perform diagnostic check on project health
|
|
81
|
+
${pc.cyan("repair")} Force-repair/auto-heal system internals
|
|
82
|
+
${pc.cyan("clean")} Clear all build caches and temporary artifacts
|
|
83
|
+
${pc.cyan("fresh")} Reset workspace completely to factory-clean canvas
|
|
84
|
+
|
|
85
|
+
${pc.bold("Examples:")}
|
|
86
|
+
pnpm forgewp add navbar
|
|
87
|
+
pnpm forgewp make:block HeroBlock --attributes=title,subtitle
|
|
88
|
+
pnpm forgewp make:post-type portfolio --customFields=client_name
|
|
89
|
+
pnpm forgewp make:component PortfolioGrid --postType=portfolio
|
|
90
|
+
pnpm forgewp sync:routes
|
|
91
|
+
pnpm forgewp doctor
|
|
92
|
+
pnpm forgewp repair
|
|
93
|
+
pnpm forgewp clean
|
|
94
|
+
pnpm forgewp fresh
|
|
95
|
+
pnpm forgewp export
|
|
96
|
+
`);
|
|
97
|
+
}
|
package/bin/doctor.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import { SYSTEM_BLUEPRINTS } from "../lib/blueprints.js";
|
|
7
|
+
|
|
8
|
+
console.log(`\n๐ฉบ ${pc.bold(pc.bgCyan(pc.black(" FORGEWP SYSTEM DOCTOR ")))}\n`);
|
|
9
|
+
|
|
10
|
+
const projectRoot = process.cwd();
|
|
11
|
+
let issuesFound = 0;
|
|
12
|
+
|
|
13
|
+
function runCheck(name, fn) {
|
|
14
|
+
process.stdout.write(` Checking ${name.padEnd(45, ".")} `);
|
|
15
|
+
try {
|
|
16
|
+
const warning = fn();
|
|
17
|
+
if (warning) {
|
|
18
|
+
console.log(pc.yellow("โ ๏ธ WARNING"));
|
|
19
|
+
console.log(pc.yellow(` ๐ ${warning}`));
|
|
20
|
+
issuesFound++;
|
|
21
|
+
} else {
|
|
22
|
+
console.log(pc.green("โ
OK"));
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.log(pc.red("โ FAILED"));
|
|
26
|
+
console.log(pc.red(` ๐ Error: ${err.message}`));
|
|
27
|
+
issuesFound++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 1. Node Version Check
|
|
32
|
+
runCheck("Node.js Runtime Environment", () => {
|
|
33
|
+
const major = parseInt(process.versions.node.split(".")[0], 10);
|
|
34
|
+
if (major < 18) {
|
|
35
|
+
return `Your Node version is v${process.version}. ForgeWP recommends Node v18+ for compiling React themes.`;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// 2. User Editable Files
|
|
41
|
+
runCheck("User Configuration & HTML Layout", () => {
|
|
42
|
+
const critical = ["wp.config.ts", "package.json", "index.html", "src/main.tsx"];
|
|
43
|
+
for (const f of critical) {
|
|
44
|
+
if (!existsSync(path.join(projectRoot, f))) {
|
|
45
|
+
throw new Error(`Critical file "${f}" is missing from project root!`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// 3. Database Check
|
|
52
|
+
runCheck("Mock Database Schema Integration", () => {
|
|
53
|
+
const dbPath = path.join(projectRoot, "wordpress", "mock-data.json");
|
|
54
|
+
if (!existsSync(dbPath)) {
|
|
55
|
+
throw new Error(`Database "wordpress/mock-data.json" was not found!`);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
JSON.parse(readFileSync(dbPath, "utf8"));
|
|
59
|
+
} catch (err) {
|
|
60
|
+
throw new Error(`Database "wordpress/mock-data.json" contains invalid JSON syntax!\n Message: ${err.message}`);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 4. System Files Integrity Check
|
|
66
|
+
runCheck("System Internal Framework Libraries", () => {
|
|
67
|
+
const systemFiles = Object.keys(SYSTEM_BLUEPRINTS);
|
|
68
|
+
const missing = [];
|
|
69
|
+
for (const sf of systemFiles) {
|
|
70
|
+
if (!existsSync(path.join(projectRoot, sf))) {
|
|
71
|
+
missing.push(sf);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (missing.length > 0) {
|
|
75
|
+
throw new Error(`Framework internal files are missing: ${missing.join(", ")}\n ๐ก Fix: Run "pnpm forgewp repair" to auto-heal system boundaries!`);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// 5. Tailwind Integration Check
|
|
81
|
+
runCheck("Tailwind Styling Architecture", () => {
|
|
82
|
+
const cssFile1 = path.join(projectRoot, "src", "index.css");
|
|
83
|
+
const cssFile2 = path.join(projectRoot, "src", "app", "globals.css");
|
|
84
|
+
if (!existsSync(cssFile1) && !existsSync(cssFile2)) {
|
|
85
|
+
return `Style sheet (src/index.css or src/app/globals.css) is missing. Please ensure your Tailwind styles are loaded.`;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Final Diagnostic
|
|
91
|
+
console.log("\n" + "โ".repeat(60));
|
|
92
|
+
if (issuesFound === 0) {
|
|
93
|
+
console.log(pc.green(`\n๐ ${pc.bold("SYSTEM HEALTHY:")} Your ForgeWP monorepo is in perfect condition!`));
|
|
94
|
+
console.log(pc.cyan(" You are ready to compile, scaffold, and upload themes safely.\n"));
|
|
95
|
+
} else {
|
|
96
|
+
console.log(pc.red(`\nโ ${pc.bold("DIAGNOSTIC COMPLETED:")} Found ${issuesFound} active system issue(s).`));
|
|
97
|
+
console.log(pc.yellow(` ๐ก Tip: Follow the instructions above or run "pnpm forgewp repair" to auto-heal framework internals.\n`));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
package/bin/export.js
CHANGED
|
File without changes
|