@absolutejs/absolute 0.2.4 → 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 CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- var It=60,h=1000,y=60000,Nt=60,ft=24,mt=86400000,d=2,B=3000;import{rm as k,mkdir as w,writeFile as ot}from"fs/promises";import{join as n,basename as rt}from"path";import{cwd as nt,exit as st}from"process";var{$:C,build:et,Glob:A}=globalThis.Bun;import{readFile as X,writeFile as Z}from"fs/promises";var{Glob:tt}=globalThis.Bun;var H=async(r,s)=>{let e=new tt("*.html"),o=[];for await(let a of e.scan({cwd:s,absolute:!0}))o.push(a);for(let a of o){let i=await X(a,"utf8");for(let[u,l]of Object.entries(r)){let I=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),p=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${I})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");i=i.replace(p,(c,f,m,M,x)=>{return`${f}${l}${x}`})}await Z(a,i,"utf8")}};var yt=async({buildDir:r="build",assetsDir:s,reactIndexDir:e,javascriptDir:o,typeScriptDir:a,reactPagesDir:i,htmlDir:u,htmxDir:l})=>{let I=performance.now();console.log("Build Config",{buildDir:r,assetsDir:s,reactIndexDir:e,javascriptDir:o,typeScriptDir:a,reactPagesDir:i,htmlDir:u,htmxDir:l});let p=nt(),c=n(p,r),f=s&&n(p,s),m=e&&n(p,e),M=o&&n(p,o),x=a&&n(p,a),D=i&&n(p,i),E=u&&n(p,u),b=l&&n(p,l);await k(c,{force:!0,recursive:!0}),await w(c),D&&m&&await it(D,m);let q=new A("*.{tsx,jsx}"),T=[];for await(let t of q.scan({absolute:!0,cwd:m}))T.push(t);let z=new A("*.js"),R=[];for await(let t of z.scan({absolute:!0,cwd:M}))R.push(t);let J=new A("*.ts"),U=[];for await(let t of J.scan({absolute:!0,cwd:x}))U.push(t);let v=T.concat(R).concat(U);if(v.length===0)return console.warn("No entry points found, skipping build"),null;let{logs:K,outputs:Q}=await et({entrypoints:v,format:"esm",naming:"[dir]/[name].[hash].[ext]",outdir:c,target:"bun"}).catch((t)=>{console.error("Build failed:",t),st(1)});if(K.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)}),f&&await C`cp -R ${f} ${c}`,E)await w(n(c,"html")),await C`cp -R ${E} ${n(c)}`;if(b)await w(n(c,"htmx")),await C`cp -R ${b} ${n(c)}`;let P=Q.reduce((t,j)=>{let _=j.path;if(_.startsWith(c))_=_.slice(c.length);_=_.replace(/^\/+/,"");let g=_.split("/").pop();if(!g)return t;let O=`.${j.hash}.`;if(!g.includes(O))throw new Error(`Expected hash delimiter ${O} in ${g}`);let[V]=g.split(O);return t[V]="/"+_,t},{});E&&await H(P,E);let N=performance.now()-I,S;if(N<h)S=`${N.toFixed(d)}ms`;else if(N<y)S=`${(N/h).toFixed(d)}s`;else S=`${(N/y).toFixed(d)}m`;return console.log(`Build completed in ${S}`),P},it=async(r,s)=>{await k(s,{force:!0,recursive:!0}),await w(s);let e=new A("*.*"),o=[];for await(let i of e.scan({cwd:r}))o.push(i);let a=o.map(async(i)=>{let u=rt(i),[l]=u.split("."),I=["import { hydrateRoot } from 'react-dom/client';",`import { ${l} } from '../pages/${l}';
3
- `,`hydrateRoot(document, <${l} />);`].join(`
4
- `);return ot(n(s,`${l}Index.tsx`),I)});await Promise.all(a)};import{createElement as ct}from"react";import{renderToReadableStream as at}from"react-dom/server.browser";var bt=async(r,s)=>{let e=ct(r),o=await at(e,{bootstrapModules:[s]});return new Response(o,{headers:{"Content-Type":"text/html"}})},Tt=(r)=>Bun.file(r);import{argv as pt}from"process";var{env:G}=globalThis.Bun;import lt from"os";var F=()=>{let r=lt.networkInterfaces(),e=Object.values(r).flat().filter((o)=>o!==void 0).find((o)=>o.family==="IPv4"&&!o.internal);if(e)return e.address;return console.warn("No IP address found, falling back to localhost"),"localhost"};var L=G.HOST??"localhost",$=G.PORT??B,Y,ut=pt,W=ut.includes("--host");if(W)Y=F(),L="0.0.0.0";var Yt=(r)=>r.listen({hostname:L,port:$},()=>{if(W)console.log(`Server started on http://localhost:${$}`),console.log(`Server started on network: http://${Y}:${$}`);else console.log(`Server started on http://${L}:${$}`)});export{H as updateScriptTags,Yt as networkingPlugin,bt as handleReactPageRequest,Tt as handleHTMLPageRequest,F as getLocalIPAddress,yt as build,d as TIME_PRECISION,It as SECONDS_IN_A_MINUTE,Nt as MINUTES_IN_AN_HOUR,h as MILLISECONDS_IN_A_SECOND,y as MILLISECONDS_IN_A_MINUTE,mt as MILLISECONDS_IN_A_DAY,ft as HOURS_IN_A_DAY,B as DEFAULT_PORT};
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/absolute",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "A fullstack meta-framework for building web applications with TypeScript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,8 @@
1
+ import tailwindcss from "tailwindcss";
2
+ import autoprefixer from "autoprefixer";
3
+
4
+ const config = {
5
+ plugins: [tailwindcss, autoprefixer]
6
+ };
7
+
8
+ export default config;
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 reactEntryGlob = new Glob("*.{tsx,jsx}");
71
- const reactEntryPaths: string[] = [];
72
- for await (const file of reactEntryGlob.scan({
73
- absolute: true,
74
- cwd: reactIndexDirAbsolute
75
- })) {
76
- reactEntryPaths.push(file);
77
- }
78
-
79
- const javascriptEntryGlob = new Glob("*.js");
80
- const javascriptEntryPaths: string[] = [];
81
- for await (const file of javascriptEntryGlob.scan({
82
- absolute: true,
83
- cwd: javascriptDirAbsolute
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
+ };
@@ -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;