@absolutejs/absolute 0.2.3 → 0.2.5
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 +3 -3
- package/dist/src/utils/networking.d.ts +0 -5
- package/package.json +1 -1
- package/postcss.config.ts +8 -0
- package/src/core/build.ts +24 -40
- package/src/utils/networking.ts +0 -27
- package/tailwind.config.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
`,`hydrateRoot(document, <${
|
|
4
|
-
`);return
|
|
2
|
+
var _t=60,O=1000,h=60000,mt=60,It=24,Nt=86400000,w=2,b=3000;import{rm as j,mkdir as A,writeFile as Z}from"fs/promises";import{join as e,basename as tt}from"path";import{cwd as ot,exit as rt}from"process";var{$:y,build:st,Glob:B}=globalThis.Bun;import{readFile as Q,writeFile as V}from"fs/promises";var{Glob:X}=globalThis.Bun;var v=async(o,s)=>{let r=new X("*.html"),t=[];for await(let i of r.scan({cwd:s,absolute:!0}))t.push(i);for(let i of t){let a=await Q(i,"utf8");for(let[m,p]of Object.entries(o)){let I=m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${I})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");a=a.replace(l,(c,E,N,x,S)=>{return`${E}${p}${S}`})}await V(i,a,"utf8")}};var $t=async({buildDir:o="build",assetsDir:s,reactIndexDir:r,javascriptDir:t,typeScriptDir:i,reactPagesDir:a,htmlDir:m,htmxDir:p})=>{let I=performance.now(),l=ot(),c=e(l,o),E=s&&e(l,s),N=r&&e(l,r),x=t&&e(l,t),S=i&&e(l,i),C=a&&e(l,a),f=m&&e(l,m),T=p&&e(l,p);await j(c,{force:!0,recursive:!0}),await A(c),C&&N&&await nt(C,N);let W=N&&await L(N,"*.tsx"),q=x&&await L(x,"*.js"),z=S&&await L(S,"*.ts"),P=[...W??[],...q??[],...z??[]];if(P.length===0)return console.warn("No entry points found, skipping build"),null;let{logs:G,outputs:J}=await st({entrypoints:P,format:"esm",naming:"[dir]/[name].[hash].[ext]",outdir:c,target:"bun"}).catch((n)=>{console.error("Build failed:",n),rt(1)});if(G.forEach((n)=>{if(n.level==="error")console.error(n);else if(n.level==="warning")console.warn(n);else if(n.level==="info"||n.level==="debug")console.info(n)}),E&&await y`cp -R ${E} ${c}`,f)await A(e(c,"html")),await y`cp -R ${f} ${e(c)}`;if(T)await A(e(c,"htmx")),await y`cp -R ${T} ${e(c)}`;let R=J.reduce((n,U)=>{let _=U.path;if(_.startsWith(c))_=_.slice(c.length);_=_.replace(/^\/+/,"");let d=_.split("/").pop();if(!d)return n;let $=`.${U.hash}.`;if(!d.includes($))throw new Error(`Expected hash delimiter ${$} in ${d}`);let[K]=d.split($);return n[K]="/"+_,n},{});f&&await v(R,f);let u=performance.now()-I,g;if(u<O)g=`${u.toFixed(w)}ms`;else if(u<h)g=`${(u/O).toFixed(w)}s`;else g=`${(u/h).toFixed(w)}m`;return console.log(`Build completed in ${g}`),R},nt=async(o,s)=>{await j(s,{force:!0,recursive:!0}),await A(s);let r=new B("*.*"),t=[];for await(let a of r.scan({cwd:o}))t.push(a);let i=t.map(async(a)=>{let m=tt(a),[p]=m.split("."),I=["import { hydrateRoot } from 'react-dom/client';",`import { ${p} } from '../pages/${p}';
|
|
3
|
+
`,`hydrateRoot(document, <${p} />);`].join(`
|
|
4
|
+
`);return Z(e(s,`${p}Index.tsx`),I)});await Promise.all(i)},L=async(o,s)=>{let r=[],t=new B(s);for await(let i of t.scan({absolute:!0,cwd:o}))r.push(i);return r};import{createElement as et}from"react";import{renderToReadableStream as it}from"react-dom/server.browser";var Mt=async(o,s)=>{let r=et(o),t=await it(r,{bootstrapModules:[s]});return new Response(t,{headers:{"Content-Type":"text/html"}})},Ct=(o)=>Bun.file(o);import{argv as at}from"process";var{env:k}=globalThis.Bun;import ct from"os";var H=()=>{let o=ct.networkInterfaces(),r=Object.values(o).flat().filter((t)=>t!==void 0).find((t)=>t.family==="IPv4"&&!t.internal);if(r)return r.address;return console.warn("No IP address found, falling back to localhost"),"localhost"};var M=k.HOST??"localhost",D=k.PORT??b,F,lt=at,Y=lt.includes("--host");if(Y)F=H(),M="0.0.0.0";var Ft=(o)=>o.listen({hostname:M,port:D},()=>{if(Y)console.log(`Server started on http://localhost:${D}`),console.log(`Server started on network: http://${F}:${D}`);else console.log(`Server started on http://${M}:${D}`)});export{v as updateScriptTags,Ft as networkingPlugin,Mt as handleReactPageRequest,Ct as handleHTMLPageRequest,H as getLocalIPAddress,$t as build,w as TIME_PRECISION,_t as SECONDS_IN_A_MINUTE,mt as MINUTES_IN_AN_HOUR,O as MILLISECONDS_IN_A_SECOND,h as MILLISECONDS_IN_A_MINUTE,Nt as MILLISECONDS_IN_A_DAY,It as HOURS_IN_A_DAY,b as DEFAULT_PORT};
|
package/package.json
CHANGED
package/src/core/build.ts
CHANGED
|
@@ -32,17 +32,6 @@ export const build = async ({
|
|
|
32
32
|
}: BuildConfig) => {
|
|
33
33
|
const start = performance.now();
|
|
34
34
|
|
|
35
|
-
console.log("Build Config", {
|
|
36
|
-
buildDir,
|
|
37
|
-
assetsDir,
|
|
38
|
-
reactIndexDir,
|
|
39
|
-
javascriptDir,
|
|
40
|
-
typeScriptDir,
|
|
41
|
-
reactPagesDir,
|
|
42
|
-
htmlDir,
|
|
43
|
-
htmxDir
|
|
44
|
-
});
|
|
45
|
-
|
|
46
35
|
const projectRoot = cwd();
|
|
47
36
|
const buildDirAbsolute = join(projectRoot, buildDir);
|
|
48
37
|
const assetsDirAbsolute = assetsDir && join(projectRoot, assetsDir);
|
|
@@ -67,35 +56,21 @@ export const build = async ({
|
|
|
67
56
|
reactIndexDirAbsolute
|
|
68
57
|
));
|
|
69
58
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
javascriptEntryPaths.push(file);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const typeScriptEntryGlob = new Glob("*.ts");
|
|
89
|
-
const typeScriptEntryPaths: string[] = [];
|
|
90
|
-
for await (const file of typeScriptEntryGlob.scan({
|
|
91
|
-
absolute: true,
|
|
92
|
-
cwd: typeScriptDirAbsolute
|
|
93
|
-
})) {
|
|
94
|
-
typeScriptEntryPaths.push(file);
|
|
95
|
-
}
|
|
96
|
-
const entryPaths = reactEntryPaths
|
|
97
|
-
.concat(javascriptEntryPaths)
|
|
98
|
-
.concat(typeScriptEntryPaths);
|
|
59
|
+
const reactEntryPaths =
|
|
60
|
+
reactIndexDirAbsolute &&
|
|
61
|
+
(await scanEntryPoints(reactIndexDirAbsolute, "*.tsx"));
|
|
62
|
+
const javascriptEntryPaths =
|
|
63
|
+
javascriptDirAbsolute &&
|
|
64
|
+
(await scanEntryPoints(javascriptDirAbsolute, "*.js"));
|
|
65
|
+
const typeScriptEntryPaths =
|
|
66
|
+
typeScriptDirAbsolute &&
|
|
67
|
+
(await scanEntryPoints(typeScriptDirAbsolute, "*.ts"));
|
|
68
|
+
|
|
69
|
+
const entryPaths = [
|
|
70
|
+
...(reactEntryPaths ?? []),
|
|
71
|
+
...(javascriptEntryPaths ?? []),
|
|
72
|
+
...(typeScriptEntryPaths ?? [])
|
|
73
|
+
];
|
|
99
74
|
|
|
100
75
|
if (entryPaths.length === 0) {
|
|
101
76
|
console.warn("No entry points found, skipping build");
|
|
@@ -202,3 +177,12 @@ const generateReactIndexFiles = async (
|
|
|
202
177
|
});
|
|
203
178
|
await Promise.all(promises);
|
|
204
179
|
};
|
|
180
|
+
|
|
181
|
+
const scanEntryPoints = async (dir: string, pattern: string) => {
|
|
182
|
+
const entryPaths: string[] = [];
|
|
183
|
+
const glob = new Glob(pattern);
|
|
184
|
+
for await (const file of glob.scan({ absolute: true, cwd: dir })) {
|
|
185
|
+
entryPaths.push(file);
|
|
186
|
+
}
|
|
187
|
+
return entryPaths;
|
|
188
|
+
};
|
package/src/utils/networking.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import os from "os";
|
|
2
|
-
import { argv, env } from "bun";
|
|
3
|
-
import { DEFAULT_PORT } from "../constants";
|
|
4
2
|
|
|
5
3
|
export const getLocalIPAddress = () => {
|
|
6
4
|
const interfaces = os.networkInterfaces();
|
|
@@ -19,28 +17,3 @@ export const getLocalIPAddress = () => {
|
|
|
19
17
|
|
|
20
18
|
return "localhost"; // Fallback to localhost if no IP found
|
|
21
19
|
};
|
|
22
|
-
|
|
23
|
-
export const getNetworkSettings = () => {
|
|
24
|
-
let host = env.HOST ?? "localhost";
|
|
25
|
-
const port = env.PORT ?? DEFAULT_PORT;
|
|
26
|
-
let localIP: string | undefined;
|
|
27
|
-
|
|
28
|
-
const args = argv;
|
|
29
|
-
const hostFlag = args.includes("--host");
|
|
30
|
-
|
|
31
|
-
if (hostFlag) {
|
|
32
|
-
localIP = getLocalIPAddress();
|
|
33
|
-
host = "0.0.0.0";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const listenCallback = () => {
|
|
37
|
-
if (hostFlag) {
|
|
38
|
-
console.log(`Server started on http://localhost:${port}`);
|
|
39
|
-
console.log(`Server started on network: http://${localIP}:${port}`);
|
|
40
|
-
} else {
|
|
41
|
-
console.log(`Server started on http://${host}:${port}`);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return { host, port, listenCallback };
|
|
46
|
-
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Config } from "tailwindcss";
|
|
2
|
+
import flowbite from "flowbite/plugin";
|
|
3
|
+
import tailwindForms from "@tailwindcss/forms";
|
|
4
|
+
|
|
5
|
+
const config: Config = {
|
|
6
|
+
content: ["./src/frontend/**/*.{js,ts,jsx,tsx,mdx}"],
|
|
7
|
+
plugins: [flowbite, tailwindForms]
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default config;
|