From 9b8e80728e3c9217fd7ca60926cd1424c960f426 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Wed, 18 Mar 2026 17:38:48 +0100 Subject: [PATCH] Update dist --- .../functions/bundler/all-pages-bundler.js | 52 ------------- dist/src/functions/grab-config.js | 19 ----- dist/src/functions/init.js | 20 ----- dist/src/functions/router/get-route.js | 26 ------- dist/src/functions/server/handle-routes.js | 36 --------- .../src/functions/server/server-params-gen.js | 62 --------------- dist/src/functions/server/start-server.js | 14 ---- dist/src/functions/server/watcher.js | 78 ------------------- .../server/web-pages/generate-web-html.js | 32 -------- .../server/web-pages/grab-page-component.js | 62 --------------- .../server/web-pages/handle-web-pages.js | 30 ------- .../write-web-page-hydration-script.js | 23 ------ dist/src/presets/server-error.js | 11 --- dist/src/types/index.js | 1 - dist/src/utils/bundle.js | 15 ---- dist/src/utils/deserialize-query.js | 18 ----- dist/src/utils/ejson.js | 33 -------- dist/src/utils/exit-with-error.js | 4 - dist/src/utils/grab-all-pages.js | 57 -------------- dist/src/utils/grab-app-names.js | 7 -- dist/src/utils/grab-app-port.js | 17 ---- dist/src/utils/grab-assets-prefix.js | 8 -- dist/src/utils/grab-constants.js | 15 ---- dist/src/utils/grab-dir-names.js | 34 -------- dist/src/utils/grab-origin.js | 8 -- dist/src/utils/grab-page-name.js | 10 --- dist/src/utils/grab-route-params.js | 20 ----- dist/src/utils/grab-router.js | 11 --- dist/src/utils/is-development.js | 6 -- dist/src/utils/numberfy.js | 31 -------- tsconfig.json | 2 +- 31 files changed, 1 insertion(+), 761 deletions(-) delete mode 100644 dist/src/functions/bundler/all-pages-bundler.js delete mode 100644 dist/src/functions/grab-config.js delete mode 100644 dist/src/functions/init.js delete mode 100644 dist/src/functions/router/get-route.js delete mode 100644 dist/src/functions/server/handle-routes.js delete mode 100644 dist/src/functions/server/server-params-gen.js delete mode 100644 dist/src/functions/server/start-server.js delete mode 100644 dist/src/functions/server/watcher.js delete mode 100644 dist/src/functions/server/web-pages/generate-web-html.js delete mode 100644 dist/src/functions/server/web-pages/grab-page-component.js delete mode 100644 dist/src/functions/server/web-pages/handle-web-pages.js delete mode 100644 dist/src/functions/server/web-pages/write-web-page-hydration-script.js delete mode 100644 dist/src/presets/server-error.js delete mode 100644 dist/src/types/index.js delete mode 100644 dist/src/utils/bundle.js delete mode 100644 dist/src/utils/deserialize-query.js delete mode 100644 dist/src/utils/ejson.js delete mode 100644 dist/src/utils/exit-with-error.js delete mode 100644 dist/src/utils/grab-all-pages.js delete mode 100644 dist/src/utils/grab-app-names.js delete mode 100644 dist/src/utils/grab-app-port.js delete mode 100644 dist/src/utils/grab-assets-prefix.js delete mode 100644 dist/src/utils/grab-constants.js delete mode 100644 dist/src/utils/grab-dir-names.js delete mode 100644 dist/src/utils/grab-origin.js delete mode 100644 dist/src/utils/grab-page-name.js delete mode 100644 dist/src/utils/grab-route-params.js delete mode 100644 dist/src/utils/grab-router.js delete mode 100644 dist/src/utils/is-development.js delete mode 100644 dist/src/utils/numberfy.js diff --git a/dist/src/functions/bundler/all-pages-bundler.js b/dist/src/functions/bundler/all-pages-bundler.js deleted file mode 100644 index 92d9d41..0000000 --- a/dist/src/functions/bundler/all-pages-bundler.js +++ /dev/null @@ -1,52 +0,0 @@ -import { readdirSync, statSync, unlinkSync } from "fs"; -import grabAllPages from "../../utils/grab-all-pages"; -import grabDirNames from "../../utils/grab-dir-names"; -import grabPageName from "../../utils/grab-page-name"; -import writeWebPageHydrationScript from "../server/web-pages/write-web-page-hydration-script"; -import path from "path"; -import bundle from "../../utils/bundle"; -const { BUNX_HYDRATION_SRC_DIR, HYDRATION_DST_DIR } = grabDirNames(); -export default async function allPagesBundler() { - console.time("build"); - const pages = grabAllPages({ exclude_api: true }); - for (let i = 0; i < pages.length; i++) { - const page = pages[i]; - const pageName = grabPageName({ path: page.local_path }); - writeWebPageHydrationScript({ - pageName, - page_file: page.local_path, - }); - } - const hydration_files = readdirSync(BUNX_HYDRATION_SRC_DIR); - for (let i = 0; i < hydration_files.length; i++) { - const hydration_file = hydration_files[i]; - const valid_file = pages.find((p) => { - const pageName = grabPageName({ path: p.local_path }); - const file_tsx_name = `${pageName}.tsx`; - if (file_tsx_name == hydration_file) { - return true; - } - return false; - }); - if (!valid_file) { - unlinkSync(path.join(BUNX_HYDRATION_SRC_DIR, hydration_file)); - } - } - const entrypoints = readdirSync(BUNX_HYDRATION_SRC_DIR) - .filter((f) => f.endsWith(".tsx")) - .map((f) => path.join(BUNX_HYDRATION_SRC_DIR, f)) - .filter((f) => statSync(f).isFile()); - // await Bun.build({ - // entrypoints, - // outdir: HYDRATION_DST_DIR, - // minify: true, - // target: "browser", - // format: "esm", - // }); - bundle({ - src: entrypoints.join(" "), - out_dir: HYDRATION_DST_DIR, - exec_options: { stdio: "ignore" }, - }); - console.timeEnd("build"); -} diff --git a/dist/src/functions/grab-config.js b/dist/src/functions/grab-config.js deleted file mode 100644 index 5acb65f..0000000 --- a/dist/src/functions/grab-config.js +++ /dev/null @@ -1,19 +0,0 @@ -import { existsSync } from "fs"; -import grabDirNames from "../utils/grab-dir-names"; -import exitWithError from "../utils/exit-with-error"; -export default async function grabConfig() { - try { - const { CONFIG_FILE } = grabDirNames(); - if (!existsSync(CONFIG_FILE)) { - exitWithError(`Config file \`${CONFIG_FILE}\` doesn't exist!`); - } - const config = (await import(CONFIG_FILE)).default; - if (!config) { - exitWithError(`Config file \`${CONFIG_FILE}\` is invalid! Please provide a valid default export in your config file.`); - } - return config; - } - catch (error) { - return undefined; - } -} diff --git a/dist/src/functions/init.js b/dist/src/functions/init.js deleted file mode 100644 index d4ffbf4..0000000 --- a/dist/src/functions/init.js +++ /dev/null @@ -1,20 +0,0 @@ -import { existsSync, mkdirSync, statSync, writeFileSync } from "fs"; -import grabDirNames from "../utils/grab-dir-names"; -export default async function () { - const dirNames = grabDirNames(); - const keys = Object.keys(dirNames); - for (let i = 0; i < keys.length; i++) { - const key = keys[i]; - const dir = dirNames[key]; - if (!existsSync(dir) && !dir.match(/\.\w+$/)) { - mkdirSync(dir, { recursive: true }); - continue; - } - if (key == "CONFIG_FILE" && !existsSync(dir)) { - let basicConfig = ``; - basicConfig += `const config = {};\n`; - basicConfig += `export default config;\n`; - writeFileSync(dir, basicConfig); - } - } -} diff --git a/dist/src/functions/router/get-route.js b/dist/src/functions/router/get-route.js deleted file mode 100644 index 3c3bd66..0000000 --- a/dist/src/functions/router/get-route.js +++ /dev/null @@ -1,26 +0,0 @@ -import grabDirNames from "../../utils/grab-dir-names"; -import grabAssetsPrefix from "../../utils/grab-assets-prefix"; -import grabOrigin from "../../utils/grab-origin"; -import grabRouter from "../../utils/grab-router"; -export default async function getRoute({ route, }) { - const {} = grabDirNames(); - if (route.match(/\(/)) { - return null; - } - const router = grabRouter(); - const match = router.match(route); - if (!match?.filePath) { - console.error(`Route ${route} not found`); - return null; - } - const module = await import(match.filePath); - return { - match, - module, - component: module.default, - serverProps: module.serverProps, - staticProps: module.staticProps, - staticPaths: module.staticPaths, - staticParams: module.staticParams, - }; -} diff --git a/dist/src/functions/server/handle-routes.js b/dist/src/functions/server/handle-routes.js deleted file mode 100644 index f61f43f..0000000 --- a/dist/src/functions/server/handle-routes.js +++ /dev/null @@ -1,36 +0,0 @@ -import grabRouteParams from "../../utils/grab-route-params"; -import grabConstants from "../../utils/grab-constants"; -import grabRouter from "../../utils/grab-router"; -export default async function ({ req, server, }) { - const url = new URL(req.url); - const { MBInBytes, ServerDefaultRequestBodyLimitBytes } = await grabConstants(); - const router = grabRouter(); - const match = router.match(url.pathname); - if (!match?.filePath) { - const errMsg = `Route ${url.pathname} not found`; - console.error(errMsg); - return { - success: false, - status: 401, - msg: errMsg, - }; - } - const routeParams = await grabRouteParams({ req }); - const module = await import(match.filePath); - const config = module.config; - const contentLength = req.headers.get("content-length"); - if (contentLength) { - const size = parseInt(contentLength, 10); - if ((config?.maxRequestBodyMB && - size > config.maxRequestBodyMB * MBInBytes) || - size > ServerDefaultRequestBodyLimitBytes) { - return { - success: false, - status: 413, - msg: "Request Body Too Large!", - }; - } - } - const res = await module["default"](routeParams); - return res; -} diff --git a/dist/src/functions/server/server-params-gen.js b/dist/src/functions/server/server-params-gen.js deleted file mode 100644 index 0da56e5..0000000 --- a/dist/src/functions/server/server-params-gen.js +++ /dev/null @@ -1,62 +0,0 @@ -import path from "path"; -import grabAppPort from "../../utils/grab-app-port"; -import grabDirNames from "../../utils/grab-dir-names"; -import handleWebPages from "./web-pages/handle-web-pages"; -import handleRoutes from "./handle-routes"; -import isDevelopment from "../../utils/is-development"; -export default async function (params) { - const port = grabAppPort(); - const { PUBLIC_DIR } = grabDirNames(); - return { - async fetch(req, server) { - try { - const url = new URL(req.url); - if (url.pathname === "/__hmr" && isDevelopment()) { - let controller; - const stream = new ReadableStream({ - start(c) { - controller = c; - global.HMR_CONTROLLERS.add(c); - }, - cancel() { - global.HMR_CONTROLLERS.delete(controller); - }, - }); - return new Response(stream, { - headers: { - "Content-Type": "text/event-stream", - "Cache-Control": "no-cache", - Connection: "keep-alive", - }, - }); - } - else if (url.pathname.startsWith("/api/")) { - const res = await handleRoutes({ req, server }); - return new Response(JSON.stringify(res), { - status: res?.status, - headers: { - "Content-Type": "application/json", - }, - }); - } - else if (url.pathname.startsWith("/public/")) { - const file = Bun.file(path.join(PUBLIC_DIR, url.pathname.replace(/^\/public/, ""))); - return new Response(file); - } - else if (url.pathname.startsWith("/favicon.")) { - const file = Bun.file(path.join(PUBLIC_DIR, url.pathname)); - return new Response(file); - } - else { - return await handleWebPages({ req }); - } - } - catch (error) { - return new Response(`Server Error: ${error.message}`, { - status: 500, - }); - } - }, - port, - }; -} diff --git a/dist/src/functions/server/start-server.js b/dist/src/functions/server/start-server.js deleted file mode 100644 index 1b125fc..0000000 --- a/dist/src/functions/server/start-server.js +++ /dev/null @@ -1,14 +0,0 @@ -import AppNames from "../../utils/grab-app-names"; -import serverParamsGen from "./server-params-gen"; -import watcher from "./watcher"; -export default async function startServer(params) { - const { name } = AppNames; - const serverParams = await serverParamsGen(); - const server = Bun.serve(serverParams); - global.SERVER = server; - console.log(`${name} Server Running on http://localhost:${server.port} ...`); - if (params?.dev) { - watcher(); - } - return server; -} diff --git a/dist/src/functions/server/watcher.js b/dist/src/functions/server/watcher.js deleted file mode 100644 index f84b447..0000000 --- a/dist/src/functions/server/watcher.js +++ /dev/null @@ -1,78 +0,0 @@ -import { watch } from "fs"; -import grabDirNames from "../../utils/grab-dir-names"; -import grabPageName from "../../utils/grab-page-name"; -import path from "path"; -import serverParamsGen from "./server-params-gen"; -import bundle from "../../utils/bundle"; -import grabRouter from "../../utils/grab-router"; -import allPagesBundler from "../bundler/all-pages-bundler"; -const { ROOT_DIR, BUNX_HYDRATION_SRC_DIR, HYDRATION_DST_DIR, PAGES_DIR } = grabDirNames(); -export default function watcher() { - watch(ROOT_DIR, { recursive: true, persistent: true }, async (event, filename) => { - if (global.RECOMPILING) - return; - if (!filename) - return; - if (filename.match(/ /)) - return; - if (filename.match(/^node_modules\//)) - return; - if (filename.match(/\.bunext|\/?public\//)) - return; - if (!filename.match(/\.(tsx|ts|css|js|jsx)$/)) - return; - if (filename.match(/\/pages\//)) { - try { - clearTimeout(global.WATCHER_TIMEOUT); - global.RECOMPILING = true; - await allPagesBundler(); - global.LAST_BUILD_TIME = Date.now(); - for (const controller of global.HMR_CONTROLLERS) { - controller.enqueue(`event: update\ndata: reload\n\n`); - } - global.RECOMPILING = false; - } - catch (error) { - console.error(`Bundler ERROR => ${error.message.substring(0, 120)} ...`); - } - // if (event == "change") { - // } else if (event == "rename") { - // await reloadServer(); - // } - } - else if (filename.match(/\.(js|ts|tsx|jsx)$/)) { - clearTimeout(global.WATCHER_TIMEOUT); - await reloadServer(); - } - }); - // watch(BUNX_HYDRATION_SRC_DIR, async (event, filename) => { - // if (!filename) return; - // const targetFile = path.join(BUNX_HYDRATION_SRC_DIR, filename); - // await Bun.build({ - // entrypoints: [targetFile], - // outdir: HYDRATION_DST_DIR, - // minify: true, - // target: "browser", - // format: "esm", - // }); - // global.SERVER?.publish("__bun_hmr", "update"); - // setTimeout(() => { - // global.RECOMPILING = false; - // }, 200); - // }); - // watch(HYDRATION_DST_DIR, async (event, filename) => { - // const encoder = new TextEncoder(); - // global.HMR_CONTROLLER?.enqueue(encoder.encode(`event: update\ndata: reload\n\n`)); - // global.RECOMPILING = false; - // }); - // let cmd = `bun build`; - // cmd += ` ${BUNX_HYDRATION_SRC_DIR}/*.tsx --outdir ${HYDRATION_DST_DIR}`; - // cmd += ` --watch --minify`; - // execSync(cmd, { stdio: "inherit" }); -} -async function reloadServer() { - const serverParams = await serverParamsGen(); - console.log(`Reloading Server ...`); - global.SERVER?.stop(); - global.SERVER = Bun.serve(serverParams); -} diff --git a/dist/src/functions/server/web-pages/generate-web-html.js b/dist/src/functions/server/web-pages/generate-web-html.js deleted file mode 100644 index cdca8d0..0000000 --- a/dist/src/functions/server/web-pages/generate-web-html.js +++ /dev/null @@ -1,32 +0,0 @@ -import path from "path"; -import { renderToString } from "react-dom/server"; -import grabContants from "../../../utils/grab-constants"; -import EJSON from "../../../utils/ejson"; -import isDevelopment from "../../../utils/is-development"; -export default async function genWebHTML({ component, pageProps, pageName, module, }) { - const { ClientRootElementIDName, ClientWindowPagePropsName } = await grabContants(); - const componentHTML = renderToString(component); - const SCRIPT_SRC = path.join("/public/pages", pageName + ".js"); - let html = `\n`; - html += `\n`; - html += ` \n`; - html += ` \n`; - if (isDevelopment()) { - html += `\n`; - } - html += ` \n`; - html += ` \n`; - html += `
${componentHTML}
\n`; - html += ` \n`; - html += ` \n`; - html += ` \n`; - html += `\n`; - return html; -} diff --git a/dist/src/functions/server/web-pages/grab-page-component.js b/dist/src/functions/server/web-pages/grab-page-component.js deleted file mode 100644 index 5a61441..0000000 --- a/dist/src/functions/server/web-pages/grab-page-component.js +++ /dev/null @@ -1,62 +0,0 @@ -import { jsx as _jsx } from "react/jsx-runtime"; -import grabDirNames from "../../../utils/grab-dir-names"; -import grabPageName from "../../../utils/grab-page-name"; -import grabRouteParams from "../../../utils/grab-route-params"; -import grabRouter from "../../../utils/grab-router"; -import bundle from "../../../utils/bundle"; -export default async function grabPageComponent({ req, file_path: passed_file_path, }) { - const url = req?.url ? new URL(req.url) : undefined; - const router = grabRouter(); - const { BUNX_ROOT_500_PRESET_COMPONENT, HYDRATION_DST_DIR, BUNX_ROOT_500_FILE_NAME, } = grabDirNames(); - const routeParams = req ? await grabRouteParams({ req }) : undefined; - try { - const match = url ? router.match(url.pathname) : undefined; - if (!match?.filePath && url?.pathname) { - const errMsg = `Page ${url.pathname} not found`; - console.error(errMsg); - throw new Error(errMsg); - } - const file_path = match?.filePath || passed_file_path; - if (!file_path) { - const errMsg = `No File Path (\`file_path\`) or Request Object (\`req\`) provided not found`; - console.error(errMsg); - throw new Error(errMsg); - } - const pageName = grabPageName({ path: file_path }); - const module = await import(`${file_path}?t=${global.LAST_BUILD_TIME ?? 0}`); - const serverRes = await (async () => { - try { - if (routeParams) { - return await module["server"]?.(routeParams); - } - return {}; - } - catch (error) { - return {}; - } - })(); - const Component = module.default; - const component = _jsx(Component, { ...serverRes }); - return { component, serverRes, routeParams, pageName, module }; - } - catch (error) { - const match = router.match("/500"); - const filePath = match?.filePath || BUNX_ROOT_500_PRESET_COMPONENT; - // if (!match?.filePath) { - // bundle({ - // out_dir: HYDRATION_DST_DIR, - // src: `${BUNX_ROOT_500_PRESET_COMPONENT}`, - // debug: true, - // }); - // } - const module = await import(`${filePath}?t=${global.LAST_BUILD_TIME ?? 0}`); - const Component = module.default; - const component = _jsx(Component, {}); - return { - component, - pageName: BUNX_ROOT_500_FILE_NAME, - routeParams, - module, - }; - } -} diff --git a/dist/src/functions/server/web-pages/handle-web-pages.js b/dist/src/functions/server/web-pages/handle-web-pages.js deleted file mode 100644 index 313be4d..0000000 --- a/dist/src/functions/server/web-pages/handle-web-pages.js +++ /dev/null @@ -1,30 +0,0 @@ -import genWebHTML from "./generate-web-html"; -import grabPageComponent from "./grab-page-component"; -import writeWebPageHydrationScript from "./write-web-page-hydration-script"; -export default async function ({ req }) { - try { - const { component, pageName, module, serverRes } = await grabPageComponent({ req }); - const html = await genWebHTML({ - component, - pageProps: serverRes, - pageName, - module, - }); - // writeWebPageHydrationScript({ - // component, - // pageName, - // module, - // pageProps: serverRes, - // }); - return new Response(html, { - headers: { - "Content-Type": "text/html", - }, - }); - } - catch (error) { - return new Response(error.message || `Page Not Found`, { - status: 404, - }); - } -} diff --git a/dist/src/functions/server/web-pages/write-web-page-hydration-script.js b/dist/src/functions/server/web-pages/write-web-page-hydration-script.js deleted file mode 100644 index 40727b9..0000000 --- a/dist/src/functions/server/web-pages/write-web-page-hydration-script.js +++ /dev/null @@ -1,23 +0,0 @@ -import { writeFileSync } from "fs"; -import path from "path"; -import grabDirNames from "../../../utils/grab-dir-names"; -import grabContants from "../../../utils/grab-constants"; -const { BUNX_HYDRATION_SRC_DIR } = grabDirNames(); -export default async function (params) { - const { pageName, page_file } = params; - const { ClientRootElementIDName, ClientWindowPagePropsName } = await grabContants(); - const pageSrcTsFileName = `${pageName}.tsx`; - let script = ""; - script += `import React from "react";\n`; - script += `import { hydrateRoot } from "react-dom/client";\n`; - script += `import App from "${page_file}";\n`; - script += `declare global {\n`; - script += ` interface Window {\n`; - script += ` ${ClientWindowPagePropsName}: any;\n`; - script += ` }\n`; - script += `}\n`; - script += `const container = document.getElementById("${ClientRootElementIDName}");\n`; - script += `hydrateRoot(container, );\n`; - const SRC_WRITE_FILE = path.join(BUNX_HYDRATION_SRC_DIR, pageSrcTsFileName); - writeFileSync(SRC_WRITE_FILE, script, "utf-8"); -} diff --git a/dist/src/presets/server-error.js b/dist/src/presets/server-error.js deleted file mode 100644 index 66dab43..0000000 --- a/dist/src/presets/server-error.js +++ /dev/null @@ -1,11 +0,0 @@ -import { jsx as _jsx } from "react/jsx-runtime"; -export default function DefaultServerErrorPage() { - return (_jsx("div", { style: { - width: "100vw", - height: "100vh", - overflow: "hidden", - display: "flex", - alignItems: "center", - justifyContent: "center", - }, children: _jsx("span", { children: "500 Internal Server Error" }) })); -} diff --git a/dist/src/types/index.js b/dist/src/types/index.js deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/src/types/index.js +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/src/utils/bundle.js b/dist/src/utils/bundle.js deleted file mode 100644 index 96274f4..0000000 --- a/dist/src/utils/bundle.js +++ /dev/null @@ -1,15 +0,0 @@ -import { execSync } from "child_process"; -export default function bundle({ out_dir, src, minify = true, exec_options, debug, }) { - let cmd = `bun build`; - cmd += ` ${src} --outdir ${out_dir}`; - if (minify) { - cmd += ` --minify`; - } - if (debug) { - console.log("cmd =>", cmd); - } - execSync(cmd, { - stdio: "inherit", - ...exec_options, - }); -} diff --git a/dist/src/utils/deserialize-query.js b/dist/src/utils/deserialize-query.js deleted file mode 100644 index 4cc68f5..0000000 --- a/dist/src/utils/deserialize-query.js +++ /dev/null @@ -1,18 +0,0 @@ -import EJSON from "./ejson"; -/** - * # Convert Serialized Query back to object - */ -export default function deserializeQuery(query) { - let queryObject = typeof query == "object" ? query : Object(EJSON.parse(query)); - const keys = Object.keys(queryObject); - for (let i = 0; i < keys.length; i++) { - const key = keys[i]; - const value = queryObject[key]; - if (typeof value == "string") { - if (value.match(/^\{|^\[/)) { - queryObject[key] = EJSON.parse(value); - } - } - } - return queryObject; -} diff --git a/dist/src/utils/ejson.js b/dist/src/utils/ejson.js deleted file mode 100644 index 799eb22..0000000 --- a/dist/src/utils/ejson.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * # EJSON parse string - */ -function parse(string, reviver) { - if (!string) - return undefined; - if (typeof string == "object") - return string; - if (typeof string !== "string") - return undefined; - try { - return JSON.parse(string, reviver); - } - catch (error) { - return undefined; - } -} -/** - * # EJSON stringify object - */ -function stringify(value, replacer, space) { - try { - return JSON.stringify(value, replacer || undefined, space); - } - catch (error) { - return undefined; - } -} -const EJSON = { - parse, - stringify, -}; -export default EJSON; diff --git a/dist/src/utils/exit-with-error.js b/dist/src/utils/exit-with-error.js deleted file mode 100644 index 221bf53..0000000 --- a/dist/src/utils/exit-with-error.js +++ /dev/null @@ -1,4 +0,0 @@ -export default function exitWithError(msg, code) { - console.error(msg); - process.exit(code || 1); -} diff --git a/dist/src/utils/grab-all-pages.js b/dist/src/utils/grab-all-pages.js deleted file mode 100644 index 11e1b18..0000000 --- a/dist/src/utils/grab-all-pages.js +++ /dev/null @@ -1,57 +0,0 @@ -import { existsSync, readdirSync, statSync } from "fs"; -import grabDirNames from "./grab-dir-names"; -import path from "path"; -export default function grabAllPages(params) { - const { PAGES_DIR } = grabDirNames(); - const pages = grabPageDirRecursively({ page_dir: PAGES_DIR }); - if (params?.exclude_api) { - return pages.filter((p) => !Boolean(p.url_path.startsWith("/api/"))); - } - return pages; -} -function grabPageDirRecursively({ page_dir }) { - const pages = readdirSync(page_dir); - const pages_files = []; - const root_pages_file = grabPageFileObject({ file_path: `` }); - if (root_pages_file) { - pages_files.push(root_pages_file); - } - for (let i = 0; i < pages.length; i++) { - const page = pages[i]; - const full_page_path = path.join(page_dir, page); - if (!existsSync(full_page_path)) { - continue; - } - const page_stat = statSync(full_page_path); - if (page_stat.isDirectory()) { - if (page.match(/\(|\)/)) - continue; - const new_page_files = grabPageDirRecursively({ - page_dir: full_page_path, - }); - pages_files.push(...new_page_files); - } - else if (page.match(/\.(ts|js)x?$/)) { - const pages_file = grabPageFileObject({ - file_path: full_page_path, - }); - if (pages_file) { - pages_files.push(pages_file); - } - } - } - return pages_files; -} -function grabPageFileObject({ file_path, }) { - let url_path = file_path - .replace(/.*\/pages\//, "/") - ?.replace(/\.(ts|js)x?$/, ""); - let file_name = url_path.split("/").pop(); - if (!file_name) - return; - return { - local_path: file_path, - url_path, - file_name, - }; -} diff --git a/dist/src/utils/grab-app-names.js b/dist/src/utils/grab-app-names.js deleted file mode 100644 index 8b8eae4..0000000 --- a/dist/src/utils/grab-app-names.js +++ /dev/null @@ -1,7 +0,0 @@ -const AppNames = { - defaultPort: 7000, - defaultAssetPrefix: "_bunext/static", - name: "Bunext", - defaultDistDir: ".bunext", -}; -export default AppNames; diff --git a/dist/src/utils/grab-app-port.js b/dist/src/utils/grab-app-port.js deleted file mode 100644 index 9f25de5..0000000 --- a/dist/src/utils/grab-app-port.js +++ /dev/null @@ -1,17 +0,0 @@ -import AppNames from "./grab-app-names"; -import numberfy from "./numberfy"; -export default function grabAppPort() { - const { defaultPort } = AppNames; - try { - if (process.env.PORT) { - return numberfy(process.env.PORT); - } - if (global.CONFIG.port) { - return global.CONFIG.port; - } - return numberfy(defaultPort); - } - catch (error) { - return numberfy(defaultPort); - } -} diff --git a/dist/src/utils/grab-assets-prefix.js b/dist/src/utils/grab-assets-prefix.js deleted file mode 100644 index 1802e51..0000000 --- a/dist/src/utils/grab-assets-prefix.js +++ /dev/null @@ -1,8 +0,0 @@ -import AppNames from "./grab-app-names"; -export default function grabAssetsPrefix() { - if (global.CONFIG.assetsPrefix) { - return global.CONFIG.assetsPrefix; - } - const { defaultAssetPrefix } = AppNames; - return defaultAssetPrefix; -} diff --git a/dist/src/utils/grab-constants.js b/dist/src/utils/grab-constants.js deleted file mode 100644 index bc9ccfb..0000000 --- a/dist/src/utils/grab-constants.js +++ /dev/null @@ -1,15 +0,0 @@ -import path from "path"; -import grabConfig from "../functions/grab-config"; -export default async function grabConstants() { - const config = await grabConfig(); - const MB_IN_BYTES = 1024 * 1024; - const ClientWindowPagePropsName = "__PAGE_PROPS__"; - const ClientRootElementIDName = "__bunext"; - const ServerDefaultRequestBodyLimitBytes = MB_IN_BYTES * 10; - return { - ClientRootElementIDName, - ClientWindowPagePropsName, - MBInBytes: MB_IN_BYTES, - ServerDefaultRequestBodyLimitBytes, - }; -} diff --git a/dist/src/utils/grab-dir-names.js b/dist/src/utils/grab-dir-names.js deleted file mode 100644 index 96f7ee8..0000000 --- a/dist/src/utils/grab-dir-names.js +++ /dev/null @@ -1,34 +0,0 @@ -import path from "path"; -export default function grabDirNames() { - const ROOT_DIR = process.cwd(); - const SRC_DIR = path.join(ROOT_DIR, "src"); - const PAGES_DIR = path.join(SRC_DIR, "pages"); - const API_DIR = path.join(PAGES_DIR, "api"); - const PUBLIC_DIR = path.join(ROOT_DIR, "public"); - const HYDRATION_DST_DIR = path.join(PUBLIC_DIR, "pages"); - const CONFIG_FILE = path.join(ROOT_DIR, "bunext.config.ts"); - const BUNX_CWD_DIR = path.resolve(ROOT_DIR, ".bunext"); - const BUNX_TMP_DIR = path.resolve(BUNX_CWD_DIR, ".tmp"); - const BUNX_HYDRATION_SRC_DIR = path.resolve(BUNX_CWD_DIR, "client", "hydration-src"); - const BUNX_ROOT_DIR = path.resolve(__dirname, "../../"); - const BUNX_ROOT_SRC_DIR = path.join(BUNX_ROOT_DIR, "src"); - const BUNX_ROOT_PRESETS_DIR = path.join(BUNX_ROOT_SRC_DIR, "presets"); - const BUNX_ROOT_500_FILE_NAME = `server-error`; - const BUNX_ROOT_500_PRESET_COMPONENT = path.join(BUNX_ROOT_PRESETS_DIR, `${BUNX_ROOT_500_FILE_NAME}.tsx`); - return { - ROOT_DIR, - SRC_DIR, - PAGES_DIR, - API_DIR, - PUBLIC_DIR, - HYDRATION_DST_DIR, - BUNX_ROOT_DIR, - CONFIG_FILE, - BUNX_TMP_DIR, - BUNX_HYDRATION_SRC_DIR, - BUNX_ROOT_SRC_DIR, - BUNX_ROOT_PRESETS_DIR, - BUNX_ROOT_500_PRESET_COMPONENT, - BUNX_ROOT_500_FILE_NAME, - }; -} diff --git a/dist/src/utils/grab-origin.js b/dist/src/utils/grab-origin.js deleted file mode 100644 index badc4d7..0000000 --- a/dist/src/utils/grab-origin.js +++ /dev/null @@ -1,8 +0,0 @@ -import grabAppPort from "./grab-app-port"; -export default function grabOrigin() { - if (global.CONFIG.origin) { - return global.CONFIG.origin; - } - const port = grabAppPort(); - return `http://localhost:${port}`; -} diff --git a/dist/src/utils/grab-page-name.js b/dist/src/utils/grab-page-name.js deleted file mode 100644 index 8cf090c..0000000 --- a/dist/src/utils/grab-page-name.js +++ /dev/null @@ -1,10 +0,0 @@ -export default function grabPageName(params) { - const pathArr = params.path.split("/"); - const routesIndex = pathArr.findIndex((p) => p == "pages"); - const newPathArr = [...pathArr].slice(routesIndex + 1); - const filename = newPathArr - .filter((p) => Boolean(p.match(/./))) - .map((p) => p.replace(/\.\w+$/, "").replace(/[^a-z]/g, "")) - .join("-"); - return filename; -} diff --git a/dist/src/utils/grab-route-params.js b/dist/src/utils/grab-route-params.js deleted file mode 100644 index 9b4a3ac..0000000 --- a/dist/src/utils/grab-route-params.js +++ /dev/null @@ -1,20 +0,0 @@ -import deserializeQuery from "./deserialize-query"; -export default async function grabRouteParams({ req, }) { - const url = new URL(req.url); - const query = deserializeQuery(Object.fromEntries(url.searchParams)); - const body = await (async () => { - try { - return req.method == "GET" ? undefined : await req.json(); - } - catch (error) { - return {}; - } - })(); - const routeParams = { - req, - url, - query, - body, - }; - return routeParams; -} diff --git a/dist/src/utils/grab-router.js b/dist/src/utils/grab-router.js deleted file mode 100644 index 9852198..0000000 --- a/dist/src/utils/grab-router.js +++ /dev/null @@ -1,11 +0,0 @@ -import grabDirNames from "./grab-dir-names"; -export default function grabRouter() { - const { PAGES_DIR } = grabDirNames(); - if (process.env.NODE_ENV == "production") { - return global.ROUTER; - } - return new Bun.FileSystemRouter({ - style: "nextjs", - dir: PAGES_DIR, - }); -} diff --git a/dist/src/utils/is-development.js b/dist/src/utils/is-development.js deleted file mode 100644 index 91ae2d9..0000000 --- a/dist/src/utils/is-development.js +++ /dev/null @@ -1,6 +0,0 @@ -export default function isDevelopment() { - const config = global.CONFIG; - if (config.development) - return true; - return false; -} diff --git a/dist/src/utils/numberfy.js b/dist/src/utils/numberfy.js deleted file mode 100644 index c4ac120..0000000 --- a/dist/src/utils/numberfy.js +++ /dev/null @@ -1,31 +0,0 @@ -export default function numberfy(num, decimals) { - try { - const numberString = String(num) - .replace(/[^0-9\.]/g, "") - .replace(/\.$/, ""); - if (!numberString.match(/./)) - return 0; - const existingDecimals = numberString.match(/\./) - ? numberString.split(".").pop()?.length - : undefined; - const numberfiedNum = Number(numberString); - if (typeof numberfiedNum !== "number") - return 0; - if (isNaN(numberfiedNum)) - return 0; - if (decimals == 0) { - return Math.round(Number(numberfiedNum)); - } - else if (decimals) { - return Number(numberfiedNum.toFixed(decimals)); - } - if (existingDecimals) - return Number(numberfiedNum.toFixed(existingDecimals)); - return Math.round(numberfiedNum); - } - catch (error) { - console.log(`Numberfy ERROR: ${error.message}`); - return 0; - } -} -export const _n = numberfy; diff --git a/tsconfig.json b/tsconfig.json index c0d18c2..2fdbdfc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,6 @@ "noPropertyAccessFromIndexSignature": false, "outDir": "dist" }, - "include": ["src", "commands", "src/index.ts"], + "include": ["src"], "exclude": ["node_modules", "dist"] }