@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.
- 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 +282 -183
- 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 -1352
- package/lib/hydration-scanner.js +516 -21
- package/lib/i18n/extractor.js +60 -0
- package/lib/i18n/providers.js +165 -0
- package/lib/index.d.ts +115 -3
- package/lib/index.js +19 -5
- 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/export-theme.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import pc from
|
|
3
|
-
import { buildAssets } from
|
|
4
|
-
import { generateTheme } from
|
|
5
|
-
import { loadConfig } from
|
|
6
|
-
import { renderStaticMarkup } from
|
|
7
|
-
import { assertZipCreated, zipTheme } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import pc from 'picocolors';
|
|
3
|
+
import { buildAssets } from './build-assets.js';
|
|
4
|
+
import { generateTheme } from './generate-theme.js';
|
|
5
|
+
import { loadConfig } from './load-config.js';
|
|
6
|
+
import { renderStaticMarkup } from './render-static.js';
|
|
7
|
+
import { assertZipCreated, zipTheme } from './zip-theme.js';
|
|
8
8
|
|
|
9
|
-
import { validateCriticalFiles } from
|
|
9
|
+
import { validateCriticalFiles } from './validate.js';
|
|
10
|
+
import { validateExport } from './validate-export.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @param {Object} options
|
|
@@ -17,26 +18,53 @@ import { validateCriticalFiles } from "./validate.js";
|
|
|
17
18
|
*/
|
|
18
19
|
export async function exportTheme(options) {
|
|
19
20
|
const themeRoot = path.resolve(options.themeRoot);
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
// Run Preflight Safeguards and Self-Healing checks
|
|
22
23
|
validateCriticalFiles(themeRoot);
|
|
23
24
|
|
|
24
25
|
const config = await loadConfig(themeRoot);
|
|
25
26
|
|
|
27
|
+
function report(stage, message, level = 'dim') {
|
|
28
|
+
if (options.onProgress && typeof options.onProgress === 'function') {
|
|
29
|
+
try {
|
|
30
|
+
options.onProgress({ stage, message });
|
|
31
|
+
} catch (e) {
|
|
32
|
+
// swallow errors from callbacks
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const fn =
|
|
36
|
+
level === 'dim'
|
|
37
|
+
? pc.dim
|
|
38
|
+
: level === 'yellow'
|
|
39
|
+
? pc.yellow
|
|
40
|
+
: level === 'red'
|
|
41
|
+
? pc.red
|
|
42
|
+
: level === 'green'
|
|
43
|
+
? pc.green
|
|
44
|
+
: pc.white;
|
|
45
|
+
console.log(fn(` ${message}`));
|
|
46
|
+
}
|
|
47
|
+
|
|
26
48
|
console.log(pc.cyan(`\n ForgeWP export — ${config.name}\n`));
|
|
27
49
|
|
|
50
|
+
report(
|
|
51
|
+
'build',
|
|
52
|
+
options.skipBuild
|
|
53
|
+
? 'Using existing build (skipBuild)'
|
|
54
|
+
: 'Building assets with Vite…',
|
|
55
|
+
);
|
|
28
56
|
const assets = options.skipBuild
|
|
29
|
-
? (await import(
|
|
57
|
+
? (await import('./build-assets.js')).readBuildManifest(themeRoot)
|
|
30
58
|
: buildAssets(themeRoot, { packageManager: options.packageManager });
|
|
31
59
|
|
|
32
|
-
|
|
33
|
-
const markup = await renderStaticMarkup(themeRoot);
|
|
60
|
+
report('render', `Rendering ${config.frameworkAdapter || 'React'} app to static HTML…`);
|
|
61
|
+
const markup = await renderStaticMarkup(themeRoot, config.frameworkAdapter);
|
|
34
62
|
|
|
35
|
-
const outDir = path.join(themeRoot,
|
|
36
|
-
const zipPath = path.join(themeRoot,
|
|
63
|
+
const outDir = path.join(themeRoot, '.forgewp', 'out', config.slug);
|
|
64
|
+
const zipPath = path.join(themeRoot, '.forgewp', `${config.slug}.zip`);
|
|
37
65
|
|
|
38
|
-
|
|
39
|
-
generateTheme({
|
|
66
|
+
report('generate', 'Generating WordPress theme files…');
|
|
67
|
+
await generateTheme({
|
|
40
68
|
themeRoot,
|
|
41
69
|
outDir,
|
|
42
70
|
config,
|
|
@@ -51,11 +79,46 @@ export async function exportTheme(options) {
|
|
|
51
79
|
assets,
|
|
52
80
|
});
|
|
53
81
|
|
|
82
|
+
// Optional export validation
|
|
83
|
+
if (options.validate) {
|
|
84
|
+
report('validate', 'Validating exported theme package…');
|
|
85
|
+
const validation = await validateExport({
|
|
86
|
+
themeRoot,
|
|
87
|
+
outDir,
|
|
88
|
+
assets,
|
|
89
|
+
config,
|
|
90
|
+
strict: !!options.strict,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (validation.warnings && validation.warnings.length > 0) {
|
|
94
|
+
report('validate-warnings', 'Validation warnings:', 'yellow');
|
|
95
|
+
for (const w of validation.warnings)
|
|
96
|
+
report('validate-warnings-item', ' - ' + w, 'dim');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (validation.missing && validation.missing.length > 0) {
|
|
100
|
+
report('validate-failed', 'Validation failed — missing files:', 'red');
|
|
101
|
+
for (const m of validation.missing)
|
|
102
|
+
report('validate-failed-item', ' - ' + m, 'dim');
|
|
103
|
+
throw new Error(
|
|
104
|
+
'Export validation failed — missing required files or assets',
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
report('validate-passed', 'Validation passed', 'green');
|
|
109
|
+
}
|
|
110
|
+
|
|
54
111
|
if (options.zip !== false) {
|
|
55
|
-
|
|
112
|
+
report('zip', 'Creating ZIP…');
|
|
56
113
|
await zipTheme(outDir, zipPath);
|
|
57
114
|
assertZipCreated(zipPath);
|
|
115
|
+
report('zip-done', 'ZIP created', 'green');
|
|
58
116
|
}
|
|
59
117
|
|
|
60
|
-
return {
|
|
118
|
+
return {
|
|
119
|
+
config,
|
|
120
|
+
outDir,
|
|
121
|
+
zipPath: options.zip !== false ? zipPath : null,
|
|
122
|
+
assets,
|
|
123
|
+
};
|
|
61
124
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
const SUPPORTED_ADAPTERS = ['react', 'html', 'stub'];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the adapter module path for a known framework adapter.
|
|
7
|
+
* @param {string} adapterName
|
|
8
|
+
*/
|
|
9
|
+
export function resolveFrameworkAdapter(adapterName = 'react') {
|
|
10
|
+
if (adapterName === 'react') {
|
|
11
|
+
return './react-adapter.js';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (adapterName === 'html') {
|
|
15
|
+
return './adapters/html-adapter.js';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (adapterName === 'stub') {
|
|
19
|
+
return './adapters/stub-adapter.js';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Unsupported framework adapter "${adapterName}". Supported adapters: ${SUPPORTED_ADAPTERS.join(', ')}`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Load the selected framework adapter module.
|
|
29
|
+
* @param {string} adapterName
|
|
30
|
+
*/
|
|
31
|
+
export async function loadFrameworkAdapter(adapterName = 'react') {
|
|
32
|
+
const modulePath = resolveFrameworkAdapter(adapterName);
|
|
33
|
+
return import(modulePath);
|
|
34
|
+
}
|