wdwh 1.12.11 → 1.12.12-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wdwh",
3
- "version": "1.12.11",
3
+ "version": "1.12.12-dev.0",
4
4
  "author": "kubashh",
5
5
  "description": "The Bun Frontend Framework.",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "scripts": {
26
26
  "dev": "clear && bun dev/dev.ts",
27
27
  "build": "bun dev/scripts.ts",
28
- "pub": "bun dev/scripts.ts pub",
28
+ "pub": "bun dev/scripts.ts --publish",
29
29
  "zip": "zip -r template/template.zip template/template"
30
30
  },
31
31
  "bin": {
package/signal.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  type Listener = () => void;
2
2
  export type Signal<T> = {
3
3
  get(): T;
4
- set(value: T): void;
4
+ set(newValueOrFn: T | ((prev: T) => T)): void;
5
5
  subscribe(listener: Listener): () => void;
6
6
  use(): T;
7
7
  };
package/signal.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{useSyncExternalStore as o}from"react";function a(t){let r=t,n=new Set;function i(){return r}function s(e){return n.add(e),()=>n.delete(e)}return{get:i,set(e){let u=typeof e==="function"?e(r):e;if(Object.is(r,u))return;r=u,n.forEach((T)=>T())},subscribe:s,use(){return o(s,i)}}}function f(t){return o(t.subscribe,t.get)}export{f as useSignal,a as createSignal};
2
+ import{useSyncExternalStore as o}from"react";function a(t){let r=t,n=new Set;function i(){return r}function s(e){return n.add(e),()=>n.delete(e)}return{get:i,set(e){let u=typeof e==="function"?e(r):e;if(Object.is(r,u))return;r=u,n.forEach((c)=>c())},subscribe:s,use(){return o(s,i)}}}function f(t){return o(t.subscribe,t.get)}export{f as useSignal,a as createSignal};
package/wdwh.js CHANGED
@@ -1,26 +1,29 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{cpSync as F,existsSync as o,rmSync as P}from"fs";import d from"path";var X=`import { createRoot } from "react-dom/client";
4
- import "../../../src/app/global.css";
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";
4
+ import "CSS_PATH";
5
5
  import App from "APP_PATH";
6
6
 
7
7
  createRoot(document.getElementsByTagName("body")[0]).render(<App />);
8
- `;var O=`import index from "./index.html";
8
+ `;var X=`import index from "./index.html";
9
9
 
10
10
  const { url } = Bun.serve({
11
- routes: { "/*": index },
11
+ routes: {
12
+ "/": index,
13
+ "/*": new Response(\`Not found!\`),
14
+ },
12
15
  development: { hmr: true },
13
16
  });
14
17
 
15
- process.send?.(\`> Server running at \${url}\`);
16
- `;var L=`
18
+ console.log(\`> Server running at \${url}\`);
19
+ `;var G=`
17
20
  [serve.static]
18
21
  plugins = ["bun-plugin-tailwind"]
19
- env = "BUN_PUBLIC_*"`;var b="../../../src/app/App.tsx",B="./node_modules/.cache/wdwh",k={[`${B}/frontend.tsx`]:X.replace("APP_PATH",b),[`${B}/server.ts`]:O};import D from"path";async function M(U){for(let v of U){for(let N in k)await Bun.write(N,k[N]);let{headContent:R,body:_}=await x(v),A=D.join(B,v.urlPath,"index.html"),G=["<!DOCTYPE html>",'<html lang="en">',"<head>",'<meta charset="UTF-8" />','<meta name="viewport" content="width=device-width, initial-scale=1.0" />',R,'<script src="./frontend.tsx"></script>',"</head>",_,"</html>"];await Bun.write(A,G.join(`
20
- `))}}async function x(U){let v=await Bun.file(U.tsxPath).text(),R=$(v,"head").slice(6,-7),_=R.match(/<link\s+rel=["']icon["']\s+href=["']([^"']+)["']\s*\/?>/)?.at(1);if(_){let W=D.join("../".repeat(U.urlPath.split("/").length+2),"src/app",U.urlPath,_);R=R.replace(/<link\s+rel=["']icon["']\s+href=["'][^"']+["']\s*\/?>/,`<link rel="icon" href="${W}" />`)}let A=$(v,"body").replaceAll("className","class"),G=A.indexOf(">")+1,N=A.lastIndexOf("<");return A=A.replace(A.slice(G,N),""),{headContent:R,body:A}}function $(U,v){for(let R,_=U.indexOf("export default");;_++){if(!R&&U.startsWith(`<${v}`,_))R=_;if(R&&U.startsWith(`</${v}>`,_))return U.slice(R,_+v.length+3).replaceAll(`
21
- `," ").replaceAll(/\s{2,}/g," ").trim()}}function Q(){let U=new Bun.Glob("**/index.tsx"),v=[];for(let R of U.scanSync("src/app")){let _=D.join("src/app",R),A=R.replace(/index\.tsx$/,"").replace(/\\/g,"/");v.push({tsxPath:_,urlPath:A})}return v}async function w(){let U=Q();await M(U);let v=Bun.file("./bunfig.toml");if(await v.exists()){let R=await v.text();if(!R.includes("bun-plugin-tailwind"))R+=`${R===""?"":`
22
- `}${L}`,await v.write(R),await H()}else{await v.write(L);async function R(){let _=Bun.file("bunfig.toml");try{if(await _.exists())await _.delete()}catch{}}process.on("SIGINT",R),setTimeout(R,250),await H()}try{await Bun.spawn({cmd:["bun","node_modules/.cache/wdwh/server.ts"],stdio:["ignore","ignore","pipe"],ipc:(_)=>{console.log(_)}}).exited}catch(R){console.error(R)}}async function H(){try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}import u from"fs";import z from"path";import g from"bun-plugin-tailwind";async function T(){let U=Q(),v=performance.now(),_=(await Bun.file("package.json").json()).wdwh||{};if(!_.outdir)_.outdir="dist";await M(U);let G={entrypoints:U.map((Y)=>z.join(B,Y.urlPath,"index.html")),outdir:_.outdir,plugins:[g],minify:!0,target:"browser",sourcemap:"none",external:_.external,naming:_.hashFiles===!1?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0,define:{"process.env.NODE_ENV":'"production"'}};if(_.cleanPrev)u.rmSync(_.outdir,{recursive:!0,force:!0});let N=await Bun.build(G);for(let Y of U){let J=Bun.file(z.join(_.outdir,Y.urlPath,"index.html")),j=C(await J.text());if(U.length===1){let Z=N.outputs.find((K)=>K.path.endsWith(".css"));if(Z?.path){let K=Bun.file(Z.path),I=j.indexOf('<link rel="stylesheet"'),q=I;for(;q<j.length;q++)if(["/>",'">'].includes(j.slice(q,q+2))){q+=2;break}let E=j.slice(I,q),S=`<style>${C(await K.text())}</style>`;j=j.replace(E,S),await K.delete(),N.outputs.splice(N.outputs.indexOf(Z),1)}}await J.write(j)}let W=performance.now();if(process.argv.includes("--dir"))console.log(`See "${_.outdir}"`);if(process.argv.includes("--time"))console.log(`Build in ${W-v}ms`)}function C(U){return U.replaceAll(`
23
- `," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var V="./tmp.zip",f="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await w();break;case"build":await T();break;case"init":{let U=await fetch(f);if(!U.ok)console.log(`feach error: ${U.status}`),process.exit(1);let v=await U.bytes();await Bun.write(V,v);let R=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",V,"-DestinationPath",".","-Force"]:["unzip","-o",V,"-d","."];Bun.spawnSync(R);let _=new Bun.Glob("**/*");for(let A of _.scanSync("template/template"))if(!o(A))F(d.join("template/template",A),A),console.log(`+ ${A}`);F("./template/template",".",{recursive:!0}),P(V),P("./template",{recursive:!0}),console.log("Installing dependencies..."),await Bun.$`bun update`,console.log(`
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(`
24
27
  Run "bun dev" and start development!`);break}default:console.log(`Usage:
25
28
  wdwh dev
26
29
  wdwh build