Refactor Server Paradigm.

This commit is contained in:
2026-03-24 07:18:57 +01:00
parent 342f56f3f5
commit 60ee353bf0
34 changed files with 425 additions and 279 deletions
+5 -1
View File
@@ -20,8 +20,9 @@ function grabPageDirRecursively({ page_dir }) {
}
for (let i = 0; i < pages.length; i++) {
const page = pages[i];
const page_name = page.split("/").pop();
const full_page_path = path.join(page_dir, page);
if (!existsSync(full_page_path)) {
if (!existsSync(full_page_path) || !page_name) {
continue;
}
if (page.match(new RegExp(`${AppNames["RootPagesComponentName"]}`))) {
@@ -30,6 +31,9 @@ function grabPageDirRecursively({ page_dir }) {
if (page.match(/\(|\)|--|\/api\//)) {
continue;
}
if (page_name.split(".").length > 2) {
continue;
}
const page_stat = statSync(full_page_path);
if (page_stat.isDirectory()) {
if (page.match(/\(|\)/))
+1 -1
View File
@@ -2,7 +2,7 @@ export declare const log: {
info: (msg: string, log?: any) => void;
success: (msg: string, log?: any) => void;
error: (msg: string | Error, log?: any) => void;
warn: (msg: string) => void;
warn: (msg: string, log?: any) => void;
build: (msg: string) => void;
watch: (msg: string) => void;
server: (url: string) => void;
+2 -1
View File
@@ -3,6 +3,7 @@ import AppNames from "./grab-app-names";
const prefix = {
info: chalk.bgCyan.bold(" nfo "),
success: chalk.green.bold("✓"),
zap: chalk.green.bold("⚡"),
error: chalk.red.bold("✗"),
warn: chalk.yellow.bold("⚠"),
build: chalk.magenta.bold("⚙"),
@@ -16,7 +17,7 @@ export const log = {
console.log(`${prefix.success} ${chalk.green(msg)}`, log || "");
},
error: (msg, log) => console.error(`${prefix.error} ${chalk.red(String(msg))}`, log || ""),
warn: (msg) => console.warn(`${prefix.warn} ${chalk.yellow(msg)}`),
warn: (msg, log) => console.warn(`${prefix.warn} ${chalk.yellow(msg)}`, log || ""),
build: (msg) => console.log(`${prefix.build} ${chalk.magenta(msg)}`),
watch: (msg) => console.log(`${prefix.watch} ${chalk.blue(msg)}`),
server: (url) => console.log(`${prefix.success} ${chalk.white("Server running on")} ${chalk.cyan.underline(url)}`),
+18 -12
View File
@@ -1,6 +1,8 @@
import grabAllPages from "./grab-all-pages";
import pagePathTransform from "./page-path-transform";
import stripServerSideLogic from "../functions/bundler/strip-server-side-logic";
import grabRootFilePath from "../functions/server/web-pages/grab-root-file-path";
import { existsSync } from "fs";
export default async function rewritePagesModule(params) {
const { page_file_path } = params || {};
let target_pages;
@@ -15,17 +17,21 @@ export default async function rewritePagesModule(params) {
}
for (let i = 0; i < target_pages.length; i++) {
const page_path = target_pages[i];
const dst_path = pagePathTransform({ page_path });
if (page_path.match(/__root\.tsx?/)) {
continue;
}
const origin_page_content = await Bun.file(page_path).text();
const dst_page_content = stripServerSideLogic({
txt_code: origin_page_content,
file_path: page_path,
});
await Bun.write(dst_path, dst_page_content, {
createPath: true,
});
await transformFile(page_path);
}
const { root_file_path } = grabRootFilePath();
if (root_file_path && existsSync(root_file_path)) {
await transformFile(root_file_path);
}
}
async function transformFile(page_path) {
const dst_path = pagePathTransform({ page_path });
const origin_page_content = await Bun.file(page_path).text();
const dst_page_content = stripServerSideLogic({
txt_code: origin_page_content,
file_path: page_path,
});
await Bun.write(dst_path, dst_page_content, {
createPath: true,
});
}