wdwh 1.12.13-dev.1 → 1.12.14-dev.0

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/README.md CHANGED
@@ -56,8 +56,8 @@ bun i wdwh@latest
56
56
 
57
57
  - `src/app/index.tsx` and additional `src/app/` subfolders – **all**
58
58
  `index.tsx` files are treated as separate pages and will produce
59
- `/dist/index.html`, `/dist/foo/index.html`, etc.
60
- - `src/app/App.tsx`
59
+ `/DIST_DIR/index.html`, `/DIST_DIR/foo/index.html`, etc.
60
+ - `src/app/App.tsx` <!-- to remove in future -->
61
61
  - `src/app/react.svg` (favicon, can be any other image, bun path must be specify in `src/app/index.tsx`)
62
62
  - `src/app/global.css` (must contain `@import "tailwindcss";`)
63
63
  - `package.json` (with scripts `dev` `build`)
@@ -66,6 +66,8 @@ bun i wdwh@latest
66
66
 
67
67
  ### Optional helper utilities
68
68
 
69
- - You can use built‑in helpers such as `useUrl()` (client side hook that
70
- returns the current path) and other future `comptime` helpers for compiling
71
- data at build time. Extend them by editing `src/lib/*` or adding plugins.
69
+ - `clsx` build in
70
+ - `useSearchParam`
71
+
72
+ <!-- - `useUrl` -->
73
+ <!-- - `comptime` executes js in build -->
package/index.d.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  type Listener = () => void;
2
+ export type Metadata = {
3
+ title: string;
4
+ iconPath: string;
5
+ description: string;
6
+ author?: string;
7
+ [key: string]: string | undefined;
8
+ };
2
9
  export type Signal<T> = {
3
10
  get(): T;
4
11
  set(newValueOrFn: T | ((prev: T) => T)): void;
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{useSyncExternalStore as l}from"react";function c(n){let e=n,t=new Set;function s(){return e}function i(r){return t.add(r),()=>t.delete(r)}return{get:s,set(r){let o=typeof r==="function"?r(e):r;if(Object.is(e,o))return;e=o,t.forEach((u)=>u())},subscribe:i,use(){return l(i,s)}}}function f(...n){let e="";for(let t of n.flat()){if(!t)continue;if(typeof t==="string")e&&(e+=" "),e+=t}return e}export{c as createSignal,f as clsx};
2
+ import{useSyncExternalStore as u}from"react";function p(n){let e=n,t=new Set;function s(){return e}function i(r){return t.add(r),()=>t.delete(r)}return{get:s,set(r){let o=typeof r==="function"?r(e):r;if(Object.is(e,o))return;e=o,t.forEach((a)=>a())},subscribe:i,use(){return u(i,s)}}}function l(...n){let e="";for(let t of n){if(!t)continue;if(typeof t==="string")e&&(e+=" "),e+=t;else if(Array.isArray(t))e&&(e+=" "),e+=l(e)}return e}export{p as createSignal,l as clsx};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wdwh",
3
- "version": "1.12.13-dev.1",
3
+ "version": "1.12.14-dev.0",
4
4
  "author": "kubashh",
5
5
  "description": "The Bun Frontend Framework.",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "dev": "clear && bun dev/dev.ts",
28
28
  "build": "bun dev/scripts.ts",
29
29
  "pub": "bun dev/scripts.ts --publish",
30
- "zip": "zip -r template/template.zip template/template"
30
+ "zip": "rm -f template/template.zip && zip -r template/template.zip template/template"
31
31
  },
32
32
  "bin": {
33
33
  "wdwh": "./wdwh.js"
@@ -39,7 +39,7 @@
39
39
  "@types/bun": "^1.3.11",
40
40
  "@types/react": "^19.2.14",
41
41
  "tailwindcss": "^4.2.2",
42
- "typescript": "^5.9.3",
42
+ "typescript": "^6.0.2",
43
43
  "react": "^19.2.4",
44
44
  "react-dom": "^19.2.4"
45
45
  },
package/wdwh.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{cpSync as T,existsSync as u,rmSync as F}from"fs";import o from"path";var J=`import { createRoot } from "react-dom/client";
3
+ import{cpSync as $,existsSync as g,rmSync as k}from"fs";import o from"path";var O=`import { createRoot } from "react-dom/client";
4
4
  import "CSS_PATH";
5
5
  import App from "APP_PATH";
6
6
 
7
7
  createRoot(document.getElementsByTagName("body")[0]).render(<App />);
8
- `;var X=`import index from "./index.html";
8
+ `;var q=`import index from "./index.html";
9
9
 
10
10
  const { url } = Bun.serve({
11
11
  routes: {
@@ -16,14 +16,14 @@ const { url } = Bun.serve({
16
16
  });
17
17
 
18
18
  console.log(\`> Server running at \${url}\`);
19
- `;var G=`
19
+ `;var K=`
20
20
  [serve.static]
21
21
  plugins = ["bun-plugin-tailwind"]
22
- env = "BUN_PUBLIC_*"`;var p="../../../src/app/App.tsx",m="../../../src/app/global.css",q="./node_modules/.cache/wdwh",Z={[`${q}/frontend.tsx`]:J.replace("CSS_PATH",m).replace("APP_PATH",p),[`${q}/server.ts`]:X},H={outdir:"dist",hashFiles:!0,cleanPrev:!1,tailwind:!0,external:[]};import D from"path";async function K(R){for(let U of R){for(let N in Z)await Bun.write(N,Z[N]);let{headContent:A,body:_}=await y(U),v=D.join(q,U.urlPath,"index.html"),j=["<!DOCTYPE html>",'<html lang="en">',"<head>",'<meta charset="UTF-8" />','<meta name="viewport" content="width=device-width, initial-scale=1.0" />',A,'<script src="./frontend.tsx"></script>',"</head>",_,"</html>"];await Bun.write(v,j.join(`
23
- `))}}async function y(R){let U=await Bun.file(R.tsxPath).text(),A=I(U,"head").slice(6,-7),_=A.match(/<link\s+rel=["']icon["']\s+href=["']([^"']+)["']\s*\/?>/)?.at(1);if(_){let Q=D.join("../".repeat(R.urlPath.split("/").length+2),"src/app",R.urlPath,_);A=A.replace(/<link\s+rel=["']icon["']\s+href=["'][^"']+["']\s*\/?>/,`<link rel="icon" href="${Q}" />`)}let v=I(U,"body").replaceAll("className","class"),j=v.indexOf(">")+1,N=v.lastIndexOf("<");return v=v.replace(v.slice(j,N),""),{headContent:A,body:v}}function I(R,U){for(let A,_=R.indexOf("export default");;_++){if(!A&&R.startsWith(`<${U}`,_))A=_;if(A&&R.startsWith(`</${U}>`,_))return R.slice(A,_+U.length+3).replaceAll(`
24
- `," ").replaceAll(/\s{2,}/g," ").trim()}}function L(){let R=new Bun.Glob("**/index.tsx"),U=[];for(let A of R.scanSync("src/app")){let _=D.join("src/app",A),v=A.replace(/index\.tsx$/,"").replace(/\\/g,"/");U.push({tsxPath:_,urlPath:v})}return U}async function $(){let R=L();await K(R);let U=Bun.file("./bunfig.toml");if(await U.exists()){let A=await U.text();if(!A.includes("bun-plugin-tailwind"))A+=`${A===""?"":`
25
- `}${G}`,await U.write(A),await O()}else{await U.write(G);async function A(){let _=Bun.file("bunfig.toml");try{if(await _.exists())await _.delete()}catch{}}process.on("SIGINT",A),setTimeout(A,250),await O()}Bun.spawnSync({cmd:["bun","node_modules/.cache/wdwh/server.ts"],stdio:["ignore","inherit","inherit"]})}async function O(){try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}import x from"fs";import z from"path";import b from"bun-plugin-tailwind";async function w(){let R=L(),U=performance.now(),A=await Bun.file("package.json").json(),_=Object.assign(H,A.wdwh);await K(R);let j={entrypoints:R.map((V)=>z.join(q,V.urlPath,"index.html")),outdir:_.outdir,plugins:_.tailwind?[b]:void 0,minify:!0,target:"browser",external:_.external,naming:!_.hashFiles?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0,define:{"process.env.NODE_ENV":'"production"'}};if(_.cleanPrev)x.rmSync(_.outdir,{recursive:!0,force:!0});let N=await Bun.build(j);for(let V of R){let k=Bun.file(z.join(_.outdir,V.urlPath,"index.html")),W=C(await k.text());if(R.length===1){let Y=N.outputs.find((B)=>B.path.endsWith(".css"));if(Y?.path){let B=Bun.file(Y.path);W=await g(W,await B.text()),await B.delete(),N.outputs.splice(N.outputs.indexOf(Y),1)}}await k.write(W)}let Q=performance.now();if(process.argv.includes("--dir"))console.log(`See "${_.outdir}"`);if(process.argv.includes("--time"))console.log(`Build in ${Q-U}ms`)}async function g(R,U){let A=R.indexOf('<link rel="stylesheet"'),_=A;for(;_<R.length;_++)if(["/>",'">'].includes(R.slice(_,_+2))){_+=2;break}let v=R.slice(A,_),j=`<style>${C(U)}</style>`;return R.replace(v,j)}function C(R){return R.replaceAll(`
26
- `," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var M="./tmp.zip",d="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await $();break;case"build":await w();break;case"init":{let R=await fetch(d);if(!R.ok)console.log(`feach error: ${R.status}`),process.exit(1);let U=await R.bytes();await Bun.write(M,U);let A=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",M,"-DestinationPath",".","-Force"]:["unzip","-o",M,"-d","."];Bun.spawnSync(A);let _=new Bun.Glob("**/*");for(let v of _.scanSync("template/template"))if(!u(v))T(o.join("template/template",v),v),console.log(`+ ${v}`);T("./template/template",".",{recursive:!0}),F(M),F("./template",{recursive:!0}),console.log("Installing dependencies..."),await Bun.$`bun update`,console.log(`
22
+ env = "BUN_PUBLIC_*"`;var F="../../../src/app/App.tsx",S="../../../src/app/global.css",D="./node_modules/.cache/wdwh",B={[`${D}/frontend.tsx`]:O.replace("CSS_PATH",S).replace("APP_PATH",F),[`${D}/server.ts`]:q},v={outdir:"dist",hashFiles:!0,cleanPrev:!1,tailwind:!0,external:[]};import L from"path";async function Q(U){for(let A of U){for(let j in B)await Bun.write(j,B[j]);let _=await m(A),{title:R,iconPath:N,...Y}=await p(A),Z=L.join("../".repeat(A.urlPath.split("/").length+2),"src/app",A.urlPath,N),G=L.join(D,A.urlPath,"index.html"),H=["<!DOCTYPE html>",'<html lang="en">',"<head>",'<meta charset="UTF-8" />','<meta name="viewport" content="width=device-width, initial-scale=1.0" />',`<title>${R}</title>`,`<link rel="icon" href="${Z}" />`,...Object.entries(Y).map(([j,w])=>`<meta name="${j}" content="${w}" />`),`<script src="${L.join(A.urlPath,"./frontend.tsx")}"></script>`,"</head>",_,"</html>"];await Bun.write(G,H.join(`
23
+ `))}}async function m(U){let A=await Bun.file(U.tsxPath).text(),_=P(A,"body").replaceAll("className","class"),R=_.indexOf(">")+1,N=_.lastIndexOf("<");return _=_.replace(_.slice(R,N),""),_}function P(U,A){for(let _,R=U.indexOf("export default");;R++){if(!_&&U.startsWith(`<${A}`,R))_=R;if(_&&U.startsWith(`</${A}>`,R))return U.slice(_,R+A.length+3).replaceAll(`
24
+ `," ").replaceAll(/\s{2,}/g," ").trim()}}function V(){let U=new Bun.Glob("**/index.tsx"),A=[];for(let _ of U.scanSync("src/app")){let R=L.join("src/app",_),N=_.replace(/index\.tsx$/,"").replace(/\\/g,"/");A.push({tsxPath:R,urlPath:N})}return A}async function p(U){let A=await Bun.file(U.tsxPath).text();A=A.replaceAll(/'|`/g,'"').replaceAll(/([{,]\s*)([a-zA-Z0-9_]+)\s*:/g,'$1"$2":').replace(/,\s*([}\]])/g,"$1");let _=A.indexOf("{",A.indexOf("export const metadata")),R=A.indexOf("}",_)+1;A=A.slice(_,R);let N=JSON.parse(A);if(!N.title)M('Matadata must contain "title"');if(!N.iconPath)M('Matadata must contain "iconPath"');if(!N.description)M('Matadata must contain "description"');return N}function M(U){console.error("Error:",U),process.exit(1)}async function I(){let U=V();await Q(U);let A=Bun.file("./bunfig.toml");if(await A.exists()){let _=await A.text();if(!_.includes("bun-plugin-tailwind"))_+=`${_===""?"":`
25
+ `}${K}`,await A.write(_),await C()}else{await A.write(K);async function _(){let R=Bun.file("bunfig.toml");try{if(await R.exists())await R.delete()}catch{}}process.on("SIGINT",_),setTimeout(_,250),await C()}Bun.spawnSync({cmd:["bun","node_modules/.cache/wdwh/server.ts"],stdio:["ignore","inherit","inherit"]})}async function C(){try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}import b from"fs";import J from"path";import u from"bun-plugin-tailwind";async function X(){let U=V(),A=performance.now(),_=await Bun.file("package.json").json(),R=Object.assign(v,_.wdwh);await Q(U);let Y={entrypoints:U.map((G)=>J.join(D,G.urlPath,"index.html")),outdir:R.outdir,plugins:R.tailwind?[u]:void 0,minify:!0,target:"browser",external:R.external,naming:!R.hashFiles?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0,define:{"process.env.NODE_ENV":'"production"'}};if(R.cleanPrev)b.rmSync(R.outdir,{recursive:!0,force:!0});await Bun.build(Y);for(let G of U){let H=Bun.file(J.join(R.outdir,G.urlPath,"index.html")),j=y(await H.text());await H.write(j)}let Z=performance.now();if(process.argv.includes("--dir"))console.log(`See "${R.outdir}"`);if(process.argv.includes("--time"))console.log(`Build in ${Z-A}ms`)}function y(U){return U.replaceAll(`
26
+ `," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var W="./tmp.zip",x="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await I();break;case"build":await X();break;case"init":{let U=await fetch(x);if(!U.ok)console.log(`feach error: ${U.status}`),process.exit(1);let A=await U.bytes();await Bun.write(W,A);let _=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",W,"-DestinationPath",".","-Force"]:["unzip","-o",W,"-d","."];Bun.spawnSync(_);let R=new Bun.Glob("**/*");for(let N of R.scanSync("template/template"))if(!g(N))$(o.join("template/template",N),N),console.log(`+ ${N}`);$("./template/template",".",{recursive:!0}),k(W),k("./template",{recursive:!0}),console.log("Installing dependencies..."),await Bun.$`bun update`,console.log(`
27
27
  Run "bun dev" and start development!`);break}default:console.log(`Usage:
28
28
  wdwh dev
29
29
  wdwh build