@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
@@ -1,90 +1,17 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { spawnSync } from "node:child_process";
5
- import { createRequire } from "node:module";
6
-
7
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
- const require = createRequire(import.meta.url);
1
+ import { loadFrameworkAdapter } from './framework-adapter.js';
9
2
 
10
3
  /**
11
4
  * Server-render the theme App to static HTML (no client JS in WordPress for v1).
12
5
  * @param {string} themeRoot
13
- * @returns {Promise<string>}
6
+ * @param {string} [adapterName]
14
7
  */
15
- export async function renderStaticMarkup(themeRoot) {
16
- const renderScript = path.join(__dirname, "render-theme.mts");
17
- const tsconfig = path.join(themeRoot, "tsconfig.json");
18
-
19
- let tsxCli = "tsx";
20
- try {
21
- tsxCli = require.resolve("tsx/cli");
22
- } catch {
23
- // fallback to PATH
24
- }
25
-
26
- const args = [tsxCli];
27
- if (existsSync(tsconfig)) {
28
- args.push("--tsconfig", tsconfig);
29
- }
30
- args.push(renderScript, themeRoot);
31
-
32
- const result = spawnSync(process.execPath, args, {
33
- cwd: themeRoot,
34
- env: {
35
- ...process.env,
36
- INIT_CWD: themeRoot,
37
- },
38
- encoding: "utf8",
39
- shell: false,
40
- });
41
-
42
- if (result.status !== 0) {
43
- const detail = result.stderr?.trim() || result.stdout?.trim() || "Unknown error";
44
- throw new Error(`Static render failed:\n${detail}`);
45
- }
46
-
47
- if (result.stderr) {
48
- console.warn(result.stderr);
49
- }
50
-
51
- const outDir = result.stdout?.trim() || path.join(themeRoot, ".forgewp");
52
- const appHtmlPath = path.join(outDir, "app.html");
53
-
54
- if (!existsSync(appHtmlPath)) {
55
- throw new Error(`Render output not found: ${appHtmlPath}`);
8
+ export async function renderStaticMarkup(themeRoot, adapterName) {
9
+ const adapter = await loadFrameworkAdapter(adapterName);
10
+ if (typeof adapter.renderStaticMarkup !== 'function') {
11
+ throw new Error(
12
+ `Framework adapter must expose renderStaticMarkup() - adapter=${adapterName}`,
13
+ );
56
14
  }
57
15
 
58
- const headerHtmlPath = path.join(outDir, "header.html");
59
- const footerHtmlPath = path.join(outDir, "footer.html");
60
- const headHtmlPath = path.join(outDir, "head.html");
61
- const singleHtmlPath = path.join(outDir, "single.html");
62
- const singleHeadHtmlPath = path.join(outDir, "single-head.html");
63
- const notFoundHtmlPath = path.join(outDir, "404.html");
64
- const archiveHtmlPath = path.join(outDir, "archive.html");
65
-
66
- return {
67
- appHtml: readFileSync(appHtmlPath, "utf8"),
68
- headerHtml: existsSync(headerHtmlPath)
69
- ? readFileSync(headerHtmlPath, "utf8")
70
- : "",
71
- footerHtml: existsSync(footerHtmlPath)
72
- ? readFileSync(footerHtmlPath, "utf8")
73
- : "",
74
- headHtml: existsSync(headHtmlPath)
75
- ? readFileSync(headHtmlPath, "utf8")
76
- : "",
77
- singleHtml: existsSync(singleHtmlPath)
78
- ? readFileSync(singleHtmlPath, "utf8")
79
- : "",
80
- singleHeadHtml: existsSync(singleHeadHtmlPath)
81
- ? readFileSync(singleHeadHtmlPath, "utf8")
82
- : "",
83
- notFoundHtml: existsSync(notFoundHtmlPath)
84
- ? readFileSync(notFoundHtmlPath, "utf8")
85
- : "",
86
- archiveHtml: existsSync(archiveHtmlPath)
87
- ? readFileSync(archiveHtmlPath, "utf8")
88
- : "",
89
- };
16
+ return adapter.renderStaticMarkup(themeRoot);
90
17
  }