Files
bunext/dist/functions/server/web-pages/grab-page-react-component-string.js
2026-10-14 12:30:41 +01:00

32 lines
1.1 KiB
JavaScript

import { log } from "../../../utils/log";
export default function grabPageReactComponentString({ file_path, root_file_path, }) {
try {
let tsx = ``;
if (root_file_path) {
tsx += `import Root from "${root_file_path}"\n`;
}
tsx += `import Page from "${file_path}"\n`;
tsx += `export default function Main({...props}) {\n\n`;
tsx += ` return (\n`;
if (root_file_path) {
tsx += ` <Root {...props}><Page {...props} /></Root>\n`;
}
else {
tsx += ` <Page {...props} />\n`;
}
tsx += ` )\n`;
tsx += `}\n`;
// Expose the page/root's own exports (meta, Head, config, ...) through
// the bundle so the server never has to import the raw source files.
tsx += `export * as __bunext_page from "${file_path}"\n`;
if (root_file_path) {
tsx += `export * as __bunext_root from "${root_file_path}"\n`;
}
return tsx;
}
catch (error) {
log.error(`grabPageReactComponentString Error: ${error.message}`);
return undefined;
}
}