@absolutejs/absolute 0.2.0 → 0.2.2
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/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var at=60,$=1000,y=60000,pt=60,_t=24,ut=86400000,d=2,h=3000;import{rm as v,mkdir as x,writeFile as V}from"fs/promises";import{join as e,basename as X}from"path";import{cwd as Z,exit as F}from"process";var{$:C,build:tt,Glob:A}=globalThis.Bun;import{readFile as J,writeFile as K}from"fs/promises";var{Glob:Q}=globalThis.Bun;var H=async(r,o)=>{let s=new Q("*.html"),n=[];for await(let i of s.scan({cwd:o,absolute:!0}))n.push(i);for(let i of n){let c=await J(i,"utf8");for(let[u,p]of Object.entries(r)){let l=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),_=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${l})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");c=c.replace(_,(a,E,f,M,g)=>{return`${E}${p}${g}`})}await K(i,c,"utf8")}};var At=async({buildDir:r="build",assetsDir:o,reactIndexDir:s,javascriptDir:n,typeScriptDir:i,reactPagesDir:c,htmlDir:u,htmxDir:p})=>{let l=performance.now();console.log("Build Config",{buildDir:r,assetsDir:o,reactIndexDir:s,javascriptDir:n,typeScriptDir:i,reactPagesDir:c,htmlDir:u,htmxDir:p});let _=Z(),a=e(_,r),E=o&&e(_,o),f=s&&e(_,s),M=n&&e(_,n),g=i&&e(_,i),b=c&&e(_,c),S=u&&e(_,u),D=p&&e(_,p);await v(a,{force:!0,recursive:!0}),await x(a),b&&f&&await ot(b,f);let Y=new A("*.{tsx,jsx}"),L=[];for await(let t of Y.scan({absolute:!0,cwd:f}))L.push(t);let k=new A("*.js"),U=[];for await(let t of k.scan({absolute:!0,cwd:M}))U.push(t);let P=new A("*.ts"),R=[];for await(let t of P.scan({absolute:!0,cwd:g}))R.push(t);let T=L.concat(U).concat(R);if(T.length===0)return console.warn("No entry points found, skipping build"),null;let{logs:W,outputs:q}=await tt({entrypoints:T,format:"esm",naming:"[dir]/[name].[hash].[ext]",outdir:a,target:"bun"}).catch((t)=>{console.error("Build failed:",t),F(1)});if(W.forEach((t)=>{if(t.level==="error")console.error(t);else if(t.level==="warning")console.warn(t);else if(t.level==="info"||t.level==="debug")console.info(t)}),E&&await C`cp -R ${E} ${a}`,S)await x(e(a,"html")),await C`cp -R ${S} ${e(a)}`;if(D)await x(e(a,"htmx")),await C`cp -R ${D} ${e(a)}`;let j=q.reduce((t,B)=>{let N=B.path;if(N.startsWith(a))N=N.slice(a.length);N=N.replace(/^\/+/,"");let w=N.split("/").pop();if(!w)return t;let O=`.${B.hash}.`;if(!w.includes(O))throw new Error(`Expected hash delimiter ${O} in ${w}`);let[z]=w.split(O);return t[z]="/"+N,t},{});S&&await H(j,S);let I=performance.now()-l,m;if(I<$)m=`${I.toFixed(d)}ms`;else if(I<y)m=`${(I/$).toFixed(d)}s`;else m=`${(I/y).toFixed(d)}m`;return console.log(`Build completed in ${m}`),j},ot=async(r,o)=>{await v(o,{force:!0,recursive:!0}),await x(o);let s=new A("*.*"),n=[];for await(let c of s.scan({cwd:r}))n.push(c);let i=n.map(async(c)=>{let u=X(c),[p]=u.split("."),l=["import { hydrateRoot } from 'react-dom/client';",`import { ${p} } from '../pages/${p}';
|
|
3
3
|
`,`hydrateRoot(document, <${p} />);`].join(`
|
|
4
|
-
`);return
|
|
4
|
+
`);return V(e(o,`${p}Index.tsx`),l)});await Promise.all(i)};import{createElement as nt}from"react";import{renderToReadableStream as rt}from"react-dom/server.browser";var Ct=async(r,o)=>{let s=nt(r),n=await rt(s,{bootstrapModules:[o]});return new Response(n,{headers:{"Content-Type":"text/html"}})},Mt=(r)=>Bun.file(r);import st from"os";var{argv:it,env:G}=globalThis.Bun;var et=()=>{let r=st.networkInterfaces(),s=Object.values(r).flat().filter((n)=>n!==void 0).find((n)=>n.family==="IPv4"&&!n.internal);if(s)return s.address;return console.warn("No IP address found, falling back to localhost"),"localhost"},ht=()=>{let r=G.HOST??"localhost",o=G.PORT??h,s,i=it.includes("--host");if(i)s=et(),r="0.0.0.0";return{host:r,port:o,listenCallback:()=>{if(i)console.log(`Server started on http://localhost:${o}`),console.log(`Server started on network: http://${s}:${o}`);else console.log(`Server started on http://${r}:${o}`)}}};export{H as updateScriptTags,Ct as handleReactPageRequest,Mt as handleHTMLPageRequest,ht as getNetworkSettings,et as getLocalIPAddress,At as build,d as TIME_PRECISION,at as SECONDS_IN_A_MINUTE,pt as MINUTES_IN_AN_HOUR,$ as MILLISECONDS_IN_A_SECOND,y as MILLISECONDS_IN_A_MINUTE,ut as MILLISECONDS_IN_A_DAY,_t as HOURS_IN_A_DAY,h as DEFAULT_PORT};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Elysia } from "elysia";
|
|
2
|
+
export declare const networkingPlugin: (app: Elysia) => Elysia<"", false, {
|
|
3
|
+
decorator: {};
|
|
4
|
+
store: {};
|
|
5
|
+
derive: {};
|
|
6
|
+
resolve: {};
|
|
7
|
+
}, {
|
|
8
|
+
type: {};
|
|
9
|
+
error: {};
|
|
10
|
+
}, {
|
|
11
|
+
schema: {};
|
|
12
|
+
macro: {};
|
|
13
|
+
}, {}, {
|
|
14
|
+
derive: {};
|
|
15
|
+
resolve: {};
|
|
16
|
+
schema: {};
|
|
17
|
+
}, {
|
|
18
|
+
derive: {};
|
|
19
|
+
resolve: {};
|
|
20
|
+
schema: {};
|
|
21
|
+
}>;
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { argv } from "node:process";
|
|
2
|
+
import { env } from "bun";
|
|
3
|
+
import { Elysia } from "elysia";
|
|
4
|
+
import { getLocalIPAddress } from "../utils/networking";
|
|
5
|
+
import { DEFAULT_PORT } from "../constants";
|
|
6
|
+
|
|
7
|
+
let host = env.HOST ?? "localhost";
|
|
8
|
+
const port = env.PORT ?? DEFAULT_PORT;
|
|
9
|
+
let localIP: string | undefined;
|
|
10
|
+
|
|
11
|
+
const args = argv;
|
|
12
|
+
const hostFlag = args.includes("--host");
|
|
13
|
+
|
|
14
|
+
if (hostFlag) {
|
|
15
|
+
localIP = getLocalIPAddress();
|
|
16
|
+
host = "0.0.0.0";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const networkingPlugin = (app: Elysia) =>
|
|
20
|
+
app.listen(
|
|
21
|
+
{
|
|
22
|
+
hostname: host,
|
|
23
|
+
port: port
|
|
24
|
+
},
|
|
25
|
+
() => {
|
|
26
|
+
if (hostFlag) {
|
|
27
|
+
console.log(`Server started on http://localhost:${port}`);
|
|
28
|
+
console.log(
|
|
29
|
+
`Server started on network: http://${localIP}:${port}`
|
|
30
|
+
);
|
|
31
|
+
} else {
|
|
32
|
+
console.log(`Server started on http://${host}:${port}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
);
|