wdwh 1.12.14-dev.0 → 1.12.15-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/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export type Signal<T> = {
13
13
  use(): T;
14
14
  };
15
15
  export declare function createSignal<T>(initial: T): Signal<T>;
16
+ export declare function useInlineSignal<T>(init: T): Signal<T>;
16
17
  export type ClassValue = ClassArray | string | number | null | boolean | undefined;
17
18
  export type ClassArray = ClassValue[];
18
19
  export declare function clsx(...inputs: ClassValue[]): string;
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
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};
2
+ import{useSyncExternalStore as l}from"react";import{useState as c,useSyncExternalStore as S}from"react";function a(r){return c(r)[0]}function f(r){let e=r,t=new Set;function s(){return e}function o(n){return t.add(n),()=>t.delete(n)}return{get:s,set(n){let i=typeof n==="function"?n(e):n;if(Object.is(e,i))return;e=i,t.forEach((u)=>u())},subscribe:o,use(){return l(o,s)}}}function d(r){return a(f(r))}function p(...r){let e="";for(let t of r){if(!t)continue;if(typeof t==="string")e&&(e+=" "),e+=t;else if(Array.isArray(t))e&&(e+=" "),e+=p(e)}return e}export{d as useInlineSignal,f as createSignal,p as clsx};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wdwh",
3
- "version": "1.12.14-dev.0",
3
+ "version": "1.12.15-dev.0",
4
4
  "author": "kubashh",
5
5
  "description": "The Bun Frontend Framework.",
6
6
  "license": "MIT",
package/wdwh.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{cpSync as $,existsSync as g,rmSync as k}from"fs";import o from"path";var O=`import { createRoot } from "react-dom/client";
3
+ import{cpSync as $,existsSync as d,rmSync as k}from"fs";import g from"path";var M=`import { createRoot } from "react-dom/client";
4
4
  import "CSS_PATH";
5
5
  import App from "APP_PATH";
6
6
 
@@ -16,14 +16,14 @@ const { url } = Bun.serve({
16
16
  });
17
17
 
18
18
  console.log(\`> Server running at \${url}\`);
19
- `;var K=`
19
+ `;var L=`
20
20
  [serve.static]
21
21
  plugins = ["bun-plugin-tailwind"]
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(`
22
+ env = "BUN_PUBLIC_*"`;var F="../../../src/app/App.tsx",S="../../../src/app/global.css",D="./node_modules/.cache/wdwh",Z={[`${D}/frontend.tsx`]:M.replace("CSS_PATH",S).replace("APP_PATH",F),[`${D}/server.ts`]:q},v={outdir:"dist",hashFiles:!0,cleanPrev:!1,tailwind:!0,external:[]};import Q from"path";async function V(A){let _=[];for(let R of A)_.push(P(R));await Promise.all(_)}async function P(A){C("Create entry:",A.urlPath);for(let j in Z)await Bun.write(j,Z[j]);C("Creating index.html...");let _=m(A),{title:R,iconPath:U,...N}=await b(A),G=Q.join("../".repeat(A.urlPath.split("/").length+2),"src/app",A.urlPath,U),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="${G}" />`,...Object.entries(N).map(([j,K])=>`<meta name="${j}" content="${K}" />`),`<script src="${A.frontendPath}"></script>`,"</head>",_,"</html>"];await Bun.write(A.htmlOutPath,H.join(`
23
+ `))}function m(A){let _=p(A.tsxText,"body").replaceAll("className","class"),R=_.indexOf(">")+1,U=_.lastIndexOf("<");return _.replace(_.slice(R,U),"")}function p(A,_){for(let R,U=A.indexOf("export default");;U++){if(!R&&A.startsWith(`<${_}`,U))R=U;if(R&&A.startsWith(`</${_}>`,U))return A.slice(R,U+_.length+3).replaceAll(`
24
+ `," ").replaceAll(/\s{2,}/g," ").trim()}}async function W(){let A=new Bun.Glob("**/index.tsx"),_=[];for(let R of A.scanSync("src/app")){let U=Q.join("src/app",R),N=R.replace(/index\.tsx$/,"").replace(/\\/g,"/"),G=Q.join(N,"./frontend.tsx"),H=Q.join(D,N,"index.html");_.push({tsxPath:U,tsxText:await Bun.file(U).text(),urlPath:N,frontendPath:G,htmlOutPath:H})}return _}async function b(A){let _=A.tsxText.replaceAll(/'|`/g,'"').replaceAll(/([{,]\s*)([a-zA-Z0-9_]+)\s*:/g,'$1"$2":').replace(/,\s*([}\]])/g,"$1"),R=_.indexOf("{",_.indexOf("export const metadata")),U=_.indexOf("}",R)+1;_=_.slice(R,U);let N=JSON.parse(_);if(typeof N.title!=="string")B('Matadata must contain "title"');if(typeof N.iconPath!=="string")B('Matadata must contain "iconPath"');if(typeof N.description!=="string")B('Matadata must contain "description"');return N}function B(A){console.error("[error]",A),process.exit(1)}function C(...A){console.log("[log]",...A)}async function J(){let A=await W();await V(A);let _=Bun.file("./bunfig.toml");if(await _.exists()){let R=await _.text();if(!R.includes("bun-plugin-tailwind"))R+=`${R===""?"":`
25
+ `}${L}`,await _.write(R),await I()}else{await _.write(L);async function R(){let U=Bun.file("bunfig.toml");try{if(await U.exists())await U.delete()}catch{}}process.on("SIGINT",R),setTimeout(R,250),await I()}Bun.spawnSync({cmd:["bun","node_modules/.cache/wdwh/server.ts"],stdio:["ignore","inherit","inherit"]})}async function I(){try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}import u from"fs";import O from"path";import x from"bun-plugin-tailwind";async function X(){let A=await W(),_=performance.now(),R=await Bun.file("package.json").json(),U=Object.assign(v,R.wdwh);await V(A);let G={entrypoints:A.map((j)=>O.join(D,j.urlPath,"index.html")),outdir:U.outdir,plugins:U.tailwind?[x]:void 0,minify:!0,target:"browser",external:U.external,naming:!U.hashFiles?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0,define:{"process.env.NODE_ENV":'"production"'}};if(U.cleanPrev)u.rmSync(U.outdir,{recursive:!0,force:!0});await Bun.build(G);for(let j of A){let K=Bun.file(O.join(U.outdir,j.urlPath,"index.html")),w=o(await K.text());await K.write(w)}let H=performance.now();if(process.argv.includes("--dir"))console.log(`See "${U.outdir}"`);if(process.argv.includes("--time"))console.log(`Build in ${H-_}ms`)}function o(A){return A.replaceAll(`
26
+ `," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var Y="./tmp.zip",f="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await J();break;case"build":await X();break;case"init":{let A=await fetch(f);if(!A.ok)console.log(`feach error: ${A.status}`),process.exit(1);let _=await A.bytes();await Bun.write(Y,_);let R=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",Y,"-DestinationPath",".","-Force"]:["unzip","-o",Y,"-d","."];Bun.spawnSync(R);let U=new Bun.Glob("**/*");for(let N of U.scanSync("template/template"))if(!d(N))$(g.join("template/template",N),N),console.log(`+ ${N}`);$("./template/template",".",{recursive:!0}),k(Y),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