@forgewp/compiler 0.3.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.
Files changed (45) hide show
  1. package/README.md +24 -5
  2. package/bin/analyze.js +158 -0
  3. package/bin/cli.js +29 -4
  4. package/bin/doctor.js +125 -11
  5. package/bin/export.js +20 -0
  6. package/bin/fresh.js +32 -343
  7. package/bin/i18n-extract.js +121 -0
  8. package/bin/i18n-translate.js +112 -0
  9. package/bin/make-block.js +27 -60
  10. package/bin/make-island.js +72 -0
  11. package/bin/make-post-type.js +6 -6
  12. package/bin/make-template.js +145 -0
  13. package/bin/repair.js +2 -2
  14. package/bin/sync-routes.js +28 -158
  15. package/define-config.d.ts +1 -0
  16. package/define-config.js +1 -0
  17. package/lib/adapters/html-adapter.js +65 -0
  18. package/lib/adapters/stub-adapter.js +49 -0
  19. package/lib/add-component.js +282 -183
  20. package/lib/asset-loader.js +27 -0
  21. package/lib/block-compiler.js +552 -0
  22. package/lib/blueprints.js +1459 -501
  23. package/lib/define-config.d.ts +3 -0
  24. package/lib/define-config.js +8 -0
  25. package/lib/diagnostics.js +798 -0
  26. package/lib/export-theme.js +81 -18
  27. package/lib/framework-adapter.js +34 -0
  28. package/lib/functions-builder.js +1801 -0
  29. package/lib/generate-theme.js +1019 -1352
  30. package/lib/hydration-scanner.js +516 -21
  31. package/lib/i18n/extractor.js +60 -0
  32. package/lib/i18n/providers.js +165 -0
  33. package/lib/index.d.ts +115 -3
  34. package/lib/index.js +19 -5
  35. package/lib/load-config.js +122 -6
  36. package/lib/markup-processor.js +584 -0
  37. package/lib/php-builders.js +381 -0
  38. package/lib/react-adapter.js +1336 -0
  39. package/lib/render-static.js +9 -82
  40. package/lib/render-theme.mts +526 -232
  41. package/lib/screenshot-fallback.png +0 -0
  42. package/lib/types.js +1 -0
  43. package/lib/validate-export.js +183 -0
  44. package/package.json +14 -3
  45. package/bin/make-component.js +0 -200
package/README.md CHANGED
@@ -5,7 +5,9 @@ The core engine of the ForgeWP ecosystem. It transforms modern React application
5
5
  ## šŸ“¦ Features
6
6
 
7
7
  ### 1. Theme Export
8
+
8
9
  Compiles your React components into `header.php`, `footer.php`, and `index.php`. It automatically:
10
+
9
11
  - Resolves asset paths.
10
12
  - Injects standard WordPress PHP hooks (`wp_head()`, `wp_footer()`).
11
13
  - Replaces relative links with dynamic WordPress routing (`home_url()`).
@@ -15,6 +17,7 @@ pnpm export
15
17
  ```
16
18
 
17
19
  ### 2. Smart Component Adder
20
+
18
21
  A powerful utility that pulls components from the ForgeWP Registry or shadcn/ui and applies the signature **Sharpness Transformer**.
19
22
 
20
23
  ```bash
@@ -24,6 +27,7 @@ pnpm forgewp add --name navbar
24
27
  ```
25
28
 
26
29
  ### 3. Native Gutenberg Block Generator
30
+
27
31
  Dynamically scaffolds dynamic WordPress blocks authored in React with options for custom attributes:
28
32
 
29
33
  ```bash
@@ -31,14 +35,17 @@ pnpm forgewp make:block HeroBlock --attributes=heading,text,image,buttonText
31
35
  ```
32
36
 
33
37
  ### 4. Post-Type Loop Component Scaffolder
38
+
34
39
  Instantly scaffolds beautifully designed React loop grid components bound to custom WordPress post types (ACF-like integration):
35
40
 
36
41
  ```bash
37
42
  pnpm forgewp make:component PortfolioGrid --postType=portfolio
38
43
  ```
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!*
44
+
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!_
40
46
 
41
47
  ### 5. Resilient Framework Immunity & Diagnostics
48
+
42
49
  Keep your monorepo perfectly healthy, clean, and self-healing:
43
50
 
44
51
  ```bash
@@ -53,13 +60,25 @@ ForgeWP is controlled via `wp.config.ts` in your project root:
53
60
 
54
61
  ```typescript
55
62
  export default {
56
- themeName: "My Sharp Theme",
57
- slug: "my-sharp-theme",
58
- style: "forgewp" // or "shadcn"
63
+ themeName: 'My Sharp Theme',
64
+ slug: 'my-sharp-theme',
65
+ style: 'forgewp', // or "shadcn"
59
66
  };
60
67
  ```
61
68
 
69
+ ## 🧩 Framework Adapters
70
+
71
+ The compiler is adapter-driven. React is the default adapter today, but the adapter boundary is designed to support other renderers in the future.
72
+
73
+ Read more in [ADAPTERS.md](./ADAPTERS.md).
74
+
75
+ ### Adapter test coverage
76
+
77
+ The compiler package now includes dedicated adapter validation scripts:
78
+
79
+ - `pnpm --filter @forgewp/compiler run test:adapter-runtime`
80
+ - `pnpm --filter @forgewp/compiler run test:adapter-types`
81
+
62
82
  ---
63
83
 
64
84
  Maintainable, Resilient, WordPress-native.
65
-
package/bin/analyze.js ADDED
@@ -0,0 +1,158 @@
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 { exec } from "node:child_process";
7
+ import { loadConfig } from "../lib/load-config.js";
8
+ import { scanForHydrationIslandsWithProps, runStaticLintChecks } from "../lib/hydration-scanner.js";
9
+ import { analyzeHydrationIslands, generateVisualReport } from "../lib/diagnostics.js";
10
+
11
+ console.log(`\nšŸ“Š ${pc.bold(pc.bgCyan(pc.black(" FORGEWP HYDRATION ANALYZER ")))}\n`);
12
+
13
+ const projectRoot = process.cwd();
14
+
15
+ async function main() {
16
+ // 1. Load config
17
+ let config = { name: "Starter Theme", slug: "starter", version: "1.0.0" };
18
+ try {
19
+ const loaded = await loadConfig(projectRoot);
20
+ if (loaded) {
21
+ config = {
22
+ name: loaded.name || config.name,
23
+ slug: loaded.slug || config.slug,
24
+ version: loaded.version || config.version,
25
+ };
26
+ }
27
+ } catch (err) {
28
+ console.warn(pc.yellow(`āš ļø Could not load wp.config.ts, using fallback values.`));
29
+ }
30
+
31
+ // 2. Scan islands
32
+ const islands = scanForHydrationIslandsWithProps(projectRoot);
33
+ if (islands.length === 0) {
34
+ console.log(pc.yellow("āš ļø No hydration islands detected in src/app page files."));
35
+ console.log(` Wrap components in ${pc.bold("<Hydrate>")} to scan them.\n`);
36
+ process.exit(0);
37
+ }
38
+
39
+ // 3. Resolve manifest
40
+ const manifestPath = path.join(projectRoot, "dist", ".vite", "manifest.json");
41
+ const manifestPathAlt = path.join(projectRoot, "dist", "manifest.json");
42
+ const targetManifest = existsSync(manifestPath)
43
+ ? manifestPath
44
+ : existsSync(manifestPathAlt)
45
+ ? manifestPathAlt
46
+ : null;
47
+
48
+ if (!targetManifest) {
49
+ console.log(pc.red(`āŒ ${pc.bold("Vite Manifest Not Found")}`));
50
+ console.log(pc.yellow(` Could not locate "dist/.vite/manifest.json" or "dist/manifest.json".`));
51
+ console.log(pc.cyan(` šŸ’” Fix: Run "pnpm forgewp export" first to compile assets.\n`));
52
+ process.exit(1);
53
+ }
54
+
55
+ let viteManifest = {};
56
+ try {
57
+ viteManifest = JSON.parse(readFileSync(targetManifest, "utf8"));
58
+ } catch (e) {
59
+ console.error(pc.red(`āŒ Failed to parse Vite manifest: ${e.message}`));
60
+ process.exit(1);
61
+ }
62
+
63
+ // 4. Map island kebab-case name to manifest chunk path
64
+ const mapping = {};
65
+ for (const island of islands) {
66
+ const name = island.name;
67
+ const pascalName = name
68
+ .split("-")
69
+ .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
70
+ .join("");
71
+
72
+ let resolvedChunk = null;
73
+ for (const [key, value] of Object.entries(viteManifest)) {
74
+ const fileBasename = path.basename(value.file || '');
75
+ const cleanName = fileBasename.replace(/-[A-Za-z0-9_-]+\.js$/, '');
76
+ if (
77
+ key.endsWith(`/${pascalName}.tsx`) ||
78
+ key.endsWith(`/${pascalName}.ts`) ||
79
+ key.endsWith(`/${name}.tsx`) ||
80
+ key.endsWith(`/${name}.ts`) ||
81
+ cleanName === name ||
82
+ cleanName === pascalName.toLowerCase()
83
+ ) {
84
+ resolvedChunk = value.file;
85
+ break;
86
+ }
87
+ }
88
+
89
+ if (resolvedChunk) {
90
+ mapping[name] = resolvedChunk;
91
+ }
92
+ }
93
+
94
+ // 5. Compute diagnostics
95
+ const analysis = analyzeHydrationIslands(projectRoot, mapping);
96
+
97
+ // 6. Run Static Lint Checks
98
+ const violations = runStaticLintChecks(projectRoot);
99
+ analysis.violations = violations;
100
+
101
+ // 7. Generate HTML report
102
+ let reportPath;
103
+ try {
104
+ reportPath = generateVisualReport(projectRoot, analysis, islands, config);
105
+ } catch (err) {
106
+ console.error(pc.red(`āŒ Failed to generate HTML report: ${err.message}`));
107
+ process.exit(1);
108
+ }
109
+
110
+ // 8. Output terminal summary
111
+ console.log(` Project: ${pc.cyan(config.name)} (${pc.dim(config.slug)})`);
112
+ console.log(` Total Islands Scanned: ${pc.cyan(islands.length)}`);
113
+ console.log(` Heavy Islands (>100 kB): ${analysis.heavyCount > 0 ? pc.red(analysis.heavyCount) : pc.green(0)}`);
114
+
115
+ const totalJsKb = analysis.results.reduce((acc, curr) => acc + curr.sizeKb, 0);
116
+ console.log(` Total Client JS Weight: ${totalJsKb > 200 ? pc.red(totalJsKb.toFixed(1) + " kB") : pc.green(totalJsKb.toFixed(1) + " kB")}`);
117
+
118
+ if (violations.length > 0) {
119
+ console.log(`\nāš ļø ${pc.bold(pc.yellow("THEME LINT WARNINGS & SEO RECOMMENDATIONS"))}`);
120
+ for (const v of violations) {
121
+ const icon = v.severity === "error" ? pc.red("āŒ ERROR") : pc.yellow("āš ļø WARN");
122
+ console.log(` ${icon} ${pc.bold(v.file)}: ${v.message}`);
123
+ if (v.lineContent) {
124
+ console.log(` ${pc.dim("šŸ‘‰ Code:")} ${pc.italic(v.lineContent)}`);
125
+ }
126
+ }
127
+ } else {
128
+ console.log(`\nāœ… ${pc.green(pc.bold("Best Practices Audit Passed:"))} 0 lint or SEO violations detected!`);
129
+ }
130
+
131
+ console.log(`\nšŸŽ‰ ${pc.green(pc.bold("HTML Diagnostic Report generated successfully!"))}`);
132
+ console.log(` Report path: ${pc.dim(reportPath)}`);
133
+
134
+ // 8. Auto-open report in the browser
135
+ const startCommand =
136
+ process.platform === "win32"
137
+ ? "start"
138
+ : process.platform === "darwin"
139
+ ? "open"
140
+ : "xdg-open";
141
+
142
+ const command =
143
+ process.platform === "win32"
144
+ ? `start "" "${reportPath}"`
145
+ : `${startCommand} "${reportPath}"`;
146
+
147
+ console.log(` Opening report in your browser...\n`);
148
+ exec(command, (err) => {
149
+ if (err) {
150
+ console.warn(pc.yellow(`āš ļø Failed to open browser automatically: ${err.message}`));
151
+ }
152
+ });
153
+ }
154
+
155
+ main().catch((err) => {
156
+ console.error(pc.red(`āŒ Unexpected analyzer error: ${err.message}`));
157
+ process.exit(1);
158
+ });
package/bin/cli.js CHANGED
@@ -11,10 +11,15 @@ 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:component": path.join(__dirname, "make-component.js"),
14
+ "make:template": path.join(__dirname, "make-template.js"),
15
+ "make:component": path.join(__dirname, "make-template.js"), // Backward compatible alias mapping
16
+ "make:island": path.join(__dirname, "make-island.js"),
15
17
  "sync:routes": path.join(__dirname, "sync-routes.js"),
18
+ "i18n:extract": path.join(__dirname, "i18n-extract.js"),
19
+ "i18n:translate": path.join(__dirname, "i18n-translate.js"),
16
20
  export: path.join(__dirname, "export.js"),
17
21
  doctor: path.join(__dirname, "doctor.js"),
22
+ analyze: path.join(__dirname, "analyze.js"),
18
23
  repair: path.join(__dirname, "repair.js"),
19
24
  clean: path.join(__dirname, "clean.js"),
20
25
  fresh: path.join(__dirname, "fresh.js"),
@@ -36,12 +41,22 @@ if (!targetScript) {
36
41
  targetScript = subcommands["make:block"];
37
42
  } else if (command === "make-post-type" || command === "post-type" || command === "make:post-type") {
38
43
  targetScript = subcommands["make:post-type"];
44
+ } else if (command === "make-template" || command === "template" || command === "make:template") {
45
+ targetScript = subcommands["make:template"];
39
46
  } else if (command === "make-component" || command === "component" || command === "make:component") {
40
47
  targetScript = subcommands["make:component"];
48
+ } else if (command === "make-island" || command === "island" || command === "make:island") {
49
+ targetScript = subcommands["make:island"];
41
50
  } else if (command === "sync-routes" || command === "sync" || command === "sync:routes") {
42
51
  targetScript = subcommands["sync:routes"];
52
+ } else if (command === "i18n-extract" || command === "i18n:extract") {
53
+ targetScript = subcommands["i18n:extract"];
54
+ } else if (command === "i18n-translate" || command === "i18n:translate") {
55
+ targetScript = subcommands["i18n:translate"];
43
56
  } else if (command === "reset") {
44
57
  targetScript = subcommands["fresh"];
58
+ } else if (command === "inspect" || command === "analyze") {
59
+ targetScript = subcommands["analyze"];
45
60
  }
46
61
  }
47
62
 
@@ -57,6 +72,10 @@ const commandArgs = args.slice(1);
57
72
  // Run the subcommand using spawn, inheriting stdio for rich interactivity
58
73
  const child = spawn(process.execPath, [targetScript, ...commandArgs], {
59
74
  stdio: "inherit",
75
+ env: {
76
+ ...process.env,
77
+ FORGEWP_LEGACY_ALIAS: (command === "make:component" || command === "make-component" || command === "component") ? "1" : "0",
78
+ },
60
79
  });
61
80
 
62
81
  child.on("close", (code) => {
@@ -72,12 +91,16 @@ function printHelp() {
72
91
 
73
92
  ${pc.bold("Commands:")}
74
93
  ${pc.cyan("add <component>")} Add registry components (e.g. navbar)
75
- ${pc.cyan("make:block <Name>")} Scaffold a React Gutenberg block (e.g. HeroBlock)
94
+ ${pc.cyan("make:block <Name>")} Scaffold a type-safe Gutenberg Block via defineBlock()
76
95
  ${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
96
+ ${pc.cyan("make:template <Name>")} Scaffold a custom post-type loop template
97
+ ${pc.cyan("make:island <Name>")} Scaffold an interactive selective hydration island
78
98
  ${pc.cyan("sync:routes")} Synchronize sitemap menus with routes and scaffold pages
99
+ ${pc.cyan("i18n:extract")} Extract translation strings to translations.json
100
+ ${pc.cyan("i18n:translate")} Translate missing strings via the configured engine
79
101
  ${pc.cyan("export")} Package your theme into an installable WP zip
80
102
  ${pc.cyan("doctor")} Perform diagnostic check on project health
103
+ ${pc.cyan("analyze")} Generate visual hydration island & size report
81
104
  ${pc.cyan("repair")} Force-repair/auto-heal system internals
82
105
  ${pc.cyan("clean")} Clear all build caches and temporary artifacts
83
106
  ${pc.cyan("fresh")} Reset workspace completely to factory-clean canvas
@@ -86,9 +109,11 @@ function printHelp() {
86
109
  pnpm forgewp add navbar
87
110
  pnpm forgewp make:block HeroBlock --attributes=title,subtitle
88
111
  pnpm forgewp make:post-type portfolio --customFields=client_name
89
- pnpm forgewp make:component PortfolioGrid --postType=portfolio
112
+ pnpm forgewp make:template PortfolioGrid --postType=portfolio
113
+ pnpm forgewp make:island CounterIsland
90
114
  pnpm forgewp sync:routes
91
115
  pnpm forgewp doctor
116
+ pnpm forgewp analyze
92
117
  pnpm forgewp repair
93
118
  pnpm forgewp clean
94
119
  pnpm forgewp fresh
package/bin/doctor.js CHANGED
@@ -4,11 +4,29 @@ import { existsSync, readFileSync } from "node:fs";
4
4
  import path from "node:path";
5
5
  import pc from "picocolors";
6
6
  import { SYSTEM_BLUEPRINTS } from "../lib/blueprints.js";
7
+ import { loadConfig } from "../lib/load-config.js";
8
+ import { loadFrameworkAdapter } from "../lib/framework-adapter.js";
9
+ import { scanForHydrationIslands, runStaticLintChecks } from "../lib/hydration-scanner.js";
10
+ import { analyzeHydrationIslands, printDiagnosticsReport } from "../lib/diagnostics.js";
7
11
 
8
12
  console.log(`\n🩺 ${pc.bold(pc.bgCyan(pc.black(" FORGEWP SYSTEM DOCTOR ")))}\n`);
9
13
 
10
14
  const projectRoot = process.cwd();
11
- let issuesFound = 0;
15
+ let failuresFound = 0;
16
+ let warningsFound = 0;
17
+
18
+ // Load configuration and framework adapter
19
+ let frameworkAdapter = "react";
20
+ let adapter = null;
21
+ let configLoadError = null;
22
+ try {
23
+ const config = await loadConfig(projectRoot);
24
+ frameworkAdapter = config.frameworkAdapter || "react";
25
+ const adapterModule = await loadFrameworkAdapter(frameworkAdapter);
26
+ adapter = adapterModule.default || adapterModule;
27
+ } catch (err) {
28
+ configLoadError = err;
29
+ }
12
30
 
13
31
  function runCheck(name, fn) {
14
32
  process.stdout.write(` Checking ${name.padEnd(45, ".")} `);
@@ -17,14 +35,14 @@ function runCheck(name, fn) {
17
35
  if (warning) {
18
36
  console.log(pc.yellow("āš ļø WARNING"));
19
37
  console.log(pc.yellow(` šŸ‘‰ ${warning}`));
20
- issuesFound++;
38
+ warningsFound++;
21
39
  } else {
22
40
  console.log(pc.green("āœ… OK"));
23
41
  }
24
42
  } catch (err) {
25
43
  console.log(pc.red("āŒ FAILED"));
26
44
  console.log(pc.red(` šŸ‘‰ Error: ${err.message}`));
27
- issuesFound++;
45
+ failuresFound++;
28
46
  }
29
47
  }
30
48
 
@@ -39,25 +57,34 @@ runCheck("Node.js Runtime Environment", () => {
39
57
 
40
58
  // 2. User Editable Files
41
59
  runCheck("User Configuration & HTML Layout", () => {
42
- const critical = ["wp.config.ts", "package.json", "index.html", "src/main.tsx"];
60
+ const critical = ["wp.config.ts", "package.json", "index.html"];
61
+ if (adapter && typeof adapter.getCriticalFiles === "function") {
62
+ const adapterFiles = adapter.getCriticalFiles(projectRoot);
63
+ if (Array.isArray(adapterFiles)) {
64
+ critical.push(...adapterFiles);
65
+ }
66
+ }
43
67
  for (const f of critical) {
44
68
  if (!existsSync(path.join(projectRoot, f))) {
45
69
  throw new Error(`Critical file "${f}" is missing from project root!`);
46
70
  }
47
71
  }
72
+ if (configLoadError) {
73
+ throw new Error(`Failed to load wp.config.ts configuration:\n šŸ‘‰ ${configLoadError.message}`);
74
+ }
48
75
  return null;
49
76
  });
50
77
 
51
78
  // 3. Database Check
52
79
  runCheck("Mock Database Schema Integration", () => {
53
- const dbPath = path.join(projectRoot, "wordpress", "mock-data.json");
80
+ const dbPath = path.join(projectRoot, "cms", "mock-data.json");
54
81
  if (!existsSync(dbPath)) {
55
- throw new Error(`Database "wordpress/mock-data.json" was not found!`);
82
+ throw new Error(`Database "cms/mock-data.json" was not found!`);
56
83
  }
57
84
  try {
58
85
  JSON.parse(readFileSync(dbPath, "utf8"));
59
86
  } catch (err) {
60
- throw new Error(`Database "wordpress/mock-data.json" contains invalid JSON syntax!\n Message: ${err.message}`);
87
+ throw new Error(`Database "cms/mock-data.json" contains invalid JSON syntax!\n Message: ${err.message}`);
61
88
  }
62
89
  return null;
63
90
  });
@@ -87,13 +114,100 @@ runCheck("Tailwind Styling Architecture", () => {
87
114
  return null;
88
115
  });
89
116
 
117
+ // 6. Active Hydration Islands Diagnostics
118
+ runCheck("Selective Hydration Islands Diagnostics", () => {
119
+ const islands = scanForHydrationIslands(projectRoot);
120
+ if (islands.length === 0) {
121
+ return null;
122
+ }
123
+
124
+ const manifestPath = path.join(projectRoot, 'dist', '.vite', 'manifest.json');
125
+ const manifestPathAlt = path.join(projectRoot, 'dist', 'manifest.json');
126
+ const targetManifest = existsSync(manifestPath) ? manifestPath : (existsSync(manifestPathAlt) ? manifestPathAlt : null);
127
+
128
+ if (!targetManifest) {
129
+ return `Found ${islands.length} active island(s) in source files, but no compiled build dist folder. Run "pnpm forgewp export" first to analyze bundle sizes.`;
130
+ }
131
+
132
+ let viteManifest = {};
133
+ try {
134
+ viteManifest = JSON.parse(readFileSync(targetManifest, "utf8"));
135
+ } catch (e) {
136
+ throw new Error(`Failed to parse Vite manifest: ${e.message}`);
137
+ }
138
+
139
+ const mapping = {};
140
+ for (const island of islands) {
141
+ const pascalName = island
142
+ .split('-')
143
+ .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
144
+ .join('');
145
+
146
+ let resolvedChunk = null;
147
+ for (const [key, value] of Object.entries(viteManifest)) {
148
+ const fileBasename = path.basename(value.file || '');
149
+ const cleanName = fileBasename.replace(/-[A-Za-z0-9_-]+\.js$/, '');
150
+ if (
151
+ key.endsWith(`/${pascalName}.tsx`) ||
152
+ key.endsWith(`/${pascalName}.ts`) ||
153
+ key.endsWith(`/${island}.tsx`) ||
154
+ key.endsWith(`/${island}.ts`) ||
155
+ cleanName === island ||
156
+ cleanName === pascalName.toLowerCase()
157
+ ) {
158
+ resolvedChunk = value.file;
159
+ break;
160
+ }
161
+ }
162
+
163
+ if (resolvedChunk) {
164
+ mapping[island] = resolvedChunk;
165
+ }
166
+ }
167
+
168
+ const analysis = analyzeHydrationIslands(projectRoot, mapping);
169
+ console.log("");
170
+ printDiagnosticsReport(analysis);
171
+
172
+ if (analysis.heavyCount > 0) {
173
+ return `Detected ${analysis.heavyCount} heavy interactive island(s) exceeding 100 kB threshold. Audit recommends optimizing dynamic imports or changing strategies.`;
174
+ }
175
+
176
+ return null;
177
+ });
178
+
179
+ // 7. Static Code Lint & SEO Best Practices
180
+ runCheck("Static Code Lint & SEO Best Practices", () => {
181
+ const violations = runStaticLintChecks(projectRoot);
182
+ if (violations.length === 0) {
183
+ return null;
184
+ }
185
+
186
+ const errors = violations.filter(v => v.severity === "error").length;
187
+ const warnings = violations.filter(v => v.severity === "warning").length;
188
+
189
+ console.log("");
190
+ for (const v of violations) {
191
+ const prefix = v.severity === "error" ? pc.red(" [ERROR]") : pc.yellow(" [WARN] ");
192
+ console.log(`${prefix} ${pc.bold(v.file)}: ${v.message}`);
193
+ }
194
+
195
+ return `Detected ${errors} error(s) and ${warnings} warning(s) in template source files. Run "pnpm forgewp analyze" to review detailed remedies inside the visual report.`;
196
+ });
197
+
90
198
  // Final Diagnostic
91
199
  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"));
200
+ if (failuresFound === 0) {
201
+ if (warningsFound > 0) {
202
+ console.log(pc.yellow(`\nāš ļø ${pc.bold("SYSTEM READY WITH WARNINGS:")} Found ${warningsFound} warning-level suggestion(s).`));
203
+ console.log(pc.cyan(" Your theme environment is healthy, but review recommendations above for best practices.\n"));
204
+ } else {
205
+ console.log(pc.green(`\nšŸŽ‰ ${pc.bold("SYSTEM HEALTHY:")} Your ForgeWP monorepo is in perfect condition!`));
206
+ console.log(pc.cyan(" You are ready to compile, scaffold, and upload themes safely.\n"));
207
+ }
208
+ process.exit(0);
95
209
  } else {
96
- console.log(pc.red(`\nāŒ ${pc.bold("DIAGNOSTIC COMPLETED:")} Found ${issuesFound} active system issue(s).`));
210
+ console.log(pc.red(`\nāŒ ${pc.bold("DIAGNOSTIC COMPLETED:")} Found ${failuresFound} critical system issue(s) and ${warningsFound} warning(s).`));
97
211
  console.log(pc.yellow(` šŸ’” Tip: Follow the instructions above or run "pnpm forgewp repair" to auto-heal framework internals.\n`));
98
212
  process.exit(1);
99
213
  }
package/bin/export.js CHANGED
@@ -12,6 +12,8 @@ Usage: forgewp-export [options] [theme-directory]
12
12
  Options:
13
13
  --skip-build Use existing dist/ (skip Vite build)
14
14
  --no-zip Output folder only, no ZIP file
15
+ --validate Run export validation checks after generation
16
+ --strict Treat validation warnings as failures
15
17
  -h, --help Show help
16
18
 
17
19
  Examples:
@@ -26,6 +28,8 @@ function parseArgs(argv) {
26
28
  themeRoot: cwd(),
27
29
  skipBuild: false,
28
30
  zip: true,
31
+ validate: false,
32
+ strict: false,
29
33
  help: false,
30
34
  };
31
35
 
@@ -47,6 +51,16 @@ function parseArgs(argv) {
47
51
  continue;
48
52
  }
49
53
 
54
+ if (arg === "--validate") {
55
+ options.validate = true;
56
+ continue;
57
+ }
58
+
59
+ if (arg === "--strict") {
60
+ options.strict = true;
61
+ continue;
62
+ }
63
+
50
64
  if (arg.startsWith("-")) {
51
65
  console.error(pc.red(`Unknown option: ${arg}`));
52
66
  process.exit(1);
@@ -71,6 +85,12 @@ async function main() {
71
85
  themeRoot: options.themeRoot,
72
86
  skipBuild: options.skipBuild,
73
87
  zip: options.zip,
88
+ validate: options.validate,
89
+ strict: options.strict,
90
+ onProgress: (evt) => {
91
+ // Minimal CLI progress line (stage label)
92
+ console.log(pc.dim(` [${evt.stage}] ${evt.message}`));
93
+ },
74
94
  });
75
95
 
76
96
  console.log(pc.green("\n Export complete\n"));