@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/lib/render-static.js
CHANGED
|
@@ -1,90 +1,17 @@
|
|
|
1
|
-
import {
|
|
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
|
-
* @
|
|
6
|
+
* @param {string} [adapterName]
|
|
14
7
|
*/
|
|
15
|
-
export async function renderStaticMarkup(themeRoot) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
}
|