wdwh 1.12.4 → 1.12.7

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
@@ -32,6 +32,6 @@ bun i wdwh@latest
32
32
  - `src/app/index.tsx` (contains only `html` `head` `body` tags and `metadata`)
33
33
  - `src/app/App.tsx` (app entry point)
34
34
  - `src/app/react.svg` (favicon, can be any other image, bun path must be specify in `src/app/index.tsx`)
35
- - `src/app/index.css` (must contain `@import "tailwindcss";`)
35
+ - `src/app/global.css` (must contain `@import "tailwindcss";`)
36
36
  - `package.json` (with scripts `dev` `build`)
37
37
  - `tsconfig.json` (for `typescript`)
package/hooks.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare function useHover(): (boolean | {
4
4
  onMouseEnter: () => void;
5
5
  onMouseLeave: () => void;
6
6
  })[];
7
+ export declare function useSearchParam(key: string, defaultValue: string): [string, import("react").Dispatch<import("react").SetStateAction<string>>];
package/hooks.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{useState as j}from"react";function x(){let b=j(!1)[1];return()=>b((h)=>!h)}function z(b){return j(b)[0]}function A(){let[b,h]=j(!1);return[b,{onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1)}]}export{x as useRefresh,A as useHover,z as useConst};
2
+ import{useState as n}from"react";function c(){let r=n(!1)[1];return()=>r((t)=>!t)}function u(r){return n(r)[0]}function i(){let[r,t]=n(!1);return[r,{onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1)}]}function f(r,t){let e=n(s(r,t));return a(r,e[0]),e}function s(r,t){let e=new URLSearchParams(location.search);return e.has(r)?decodeURI(e.get(r)):t}function a(r,t){let e=new URLSearchParams(location.search);e.set(r,t),history.pushState(null,"",`?${e.toString()}`)}export{f as useSearchParam,c as useRefresh,i as useHover,u as useConst};
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type Metadata = {
2
+ iconPath: string;
3
+ title: string;
4
+ description?: string;
5
+ author?: string;
6
+ keywords?: string;
7
+ themeColor?: string;
8
+ [name: string]: string | undefined;
9
+ };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "wdwh",
3
- "version": "1.12.4",
3
+ "version": "1.12.7",
4
4
  "author": "kubashh",
5
5
  "description": "The Bun framework. Easyer web dev without html for static sites",
6
6
  "license": "MIT",
7
- "repository": "kubashh/wdwh",
7
+ "repository": "https://github.com/kubashh/wdwh",
8
8
  "keywords": [
9
9
  "react",
10
10
  "framework",
@@ -17,8 +17,7 @@
17
17
  "files": [
18
18
  "LICENSE",
19
19
  "README.md",
20
- "dist",
21
- "config.d.ts",
20
+ "index.d.ts",
22
21
  "hooks.js",
23
22
  "hooks.d.ts",
24
23
  "signal.js",
@@ -45,7 +44,6 @@
45
44
  "react-dom": "^19.2.4"
46
45
  },
47
46
  "prettier": {
48
- "semi": false,
49
47
  "printWidth": 108
50
48
  }
51
49
  }
package/wdwh.js CHANGED
@@ -1,26 +1,27 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{cpSync as T,readdirSync as X,rmSync as I}from"fs";var m=`
4
- [serve.static]
5
- plugins = ["bun-plugin-tailwind"]
6
- env = "BUN_PUBLIC_*"`;var P=`import { createRoot } from "react-dom/client"
7
- import "../../../src/app/index.css"
8
- import App from "APP_PATH"
3
+ import{cpSync as D,existsSync as g,rmSync as P}from"fs";import f from"path";var q=`import { createRoot } from "react-dom/client";
4
+ import "../../../src/app/global.css";
5
+ import App from "APP_PATH";
9
6
 
10
- createRoot(document.getElementsByTagName("body")[0]).render(<App />)
11
- `;var A=`import index from "./index.html"
7
+ createRoot(document.getElementsByTagName("body")[0]).render(<App />);
8
+ `;var B=`import index from "./index.html";
12
9
 
13
10
  const { url } = Bun.serve({
14
11
  routes: { "/*": index },
15
12
  development: { hmr: true },
16
- })
13
+ });
17
14
 
18
- process.send?.(\`> Server running at \${url}\`)
19
- `;var B="../../../src/app/App.tsx",s="./node_modules/.cache/wdwh",h={[`${s}/frontend.tsx`]:P.replace("APP_PATH",B),[`${s}/server.ts`]:A};async function w(){let r=await Bun.file("./src/app/index.tsx").text(),e=v(r,"export const config"),t=v(r,"export const metadata");if(t.iconPath&&t.iconPath[0]===".")t.iconPath=`../../../src/app${t.iconPath.slice(1)}`;return{config:e,metadata:t}}function v(r,e){let t=r.indexOf("{",r.indexOf(e)),o=r.indexOf("}",t)+1;return C(r.slice(t,o))}function C(r){let e=r.trim();return e=e.replace(/\/\/.*$/gm,""),e=e.replace(/\/\*[\s\S]*?\*\//g,""),e=e.replace(/,\s*([}\]])/g,"$1"),e=e.replace(/([{,]\s*)([A-Za-z0-9_$]+)\s*:/g,'$1"$2":'),e=e.replace(/'|`/g,'"'),JSON.parse(e)}async function i(){let{metadata:r}=await w();for(let n in h)await Bun.write(n,h[n]);let{headContent:e,body:t}=await D(),{title:o,iconPath:p,...a}=r,$=["<!DOCTYPE html>",'<html lang="en">',"<head>",'<meta charset="UTF-8" />','<meta name="viewport" content="width=device-width, initial-scale=1.0" />',e,Object.keys(a).map((n)=>`<meta name="${n}" content="${a[n]}" />`),`<link rel="icon" href="${p}" />`,`<title>${o}</title>`,'<script src="./frontend.tsx"></script>',"</head>",t,"</html>"];await Bun.write(`${s}/index.html`,$.join(`
20
- `))}async function D(){let r=await Bun.file("./src/app/index.tsx").text(),e=_(r,"head").slice(6,-7),t=_(r,"body").replaceAll("className","class"),o=t.indexOf(">")+1,p=t.lastIndexOf("<");return t=t.replace(t.slice(o,p),""),{headContent:e,body:t}}function _(r,e){for(let t,o=r.indexOf("export default");;o++){if(!t&&r.startsWith(`<${e}`,o))t=o;if(t&&r.startsWith(`</${e}>`,o))return r.slice(t,o+e.length+3).replaceAll(`
21
- `," ").replaceAll(/\s{2,}/g," ").trim()}}async function j(){await i();let r=Bun.file("./bunfig.toml");if(await r.exists()){let t=await r.text();if(!t.includes("bun-plugin-tailwind")){t+=`${t===""?"":`
22
- `}${m}`,await r.write(t);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}}else{await r.write(m);async function t(){let o=Bun.file("bunfig.toml");try{if(await o.exists())await o.delete()}catch{}}process.on("SIGINT",t),setTimeout(t,250);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}await Bun.spawn({cmd:["bun","node_modules/.cache/wdwh/server.ts"],stdout:"ignore",stderr:"inherit",ipc:(t)=>{console.log(t)}}).exited}import S from"bun-plugin-tailwind";import l from"fs";async function N(){let r=performance.now(),{config:e}=await w();await i();let t={entrypoints:[`${s}/index.html`],outdir:e.outdir,plugins:[S],minify:!0,target:"browser",sourcemap:"none",define:{"process.env.NODE_ENV":'"production"'},external:e.external,naming:!e.hashFiles?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0};if(e.cleanPrev&&l.existsSync(e.outdir))l.rmSync(e.outdir,{recursive:!0});let o=await Bun.build(t),p=Bun.file(`${e.outdir}/index.html`),a=y(await p.text());if(e.bundleCss){let n=o.outputs.find((d)=>d.path.endsWith(".css"));if(n?.path){let d=Bun.file(n.path),O=a.indexOf('<link rel="stylesheet"'),c=O;for(;c<a.length;c++)if(["/>",'">'].includes(a.slice(c,c+2))){c+=2;break}let J=a.slice(O,c),R=`<style>${y(await d.text())}</style>`;a=a.replace(J,R),await d.delete(),o.outputs.splice(o.outputs.indexOf(n),1)}}await p.write(a);let $=performance.now();if(process.argv.includes("--dir"))console.log(`See "${e.outdir}"`);if(process.argv.includes("--time"))console.log(`Build in ${$-r}ms`)}function y(r){return r.replaceAll(`
23
- `," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var x="./tmp.zip",Y="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await j();break;case"build":await N();break;case"init":{if(X(".").length===0){let t=await(await fetch(Y)).bytes();await Bun.write(x,t);let o=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",x,"-DestinationPath",".","-Force"]:["unzip","-o",x,"-d","."];Bun.spawnSync(o),T("./template/template",".",{recursive:!0}),I(x),I("./template",{recursive:!0}),console.log('Run "bun i && bun dev" and start development!')}else console.log("Cannot initialize wdwh project: folder is not empty. Use an empty directory."),process.exit(1);break}default:console.log(`Usage:
15
+ process.send?.(\`> Server running at \${url}\`);
16
+ `;var V=`
17
+ [serve.static]
18
+ plugins = ["bun-plugin-tailwind"]
19
+ env = "BUN_PUBLIC_*"`;var F="../../../src/app/App.tsx",L="./src/app/index.tsx",U="./node_modules/.cache/wdwh",X={[`${U}/frontend.tsx`]:q.replace("APP_PATH",F),[`${U}/server.ts`]:B};import K from"path";async function W(_){_=_;let v=await S();for(let N in X)await Bun.write(N,X[N]);let{headContent:$,body:p}=await r(),{title:A,iconPath:G,...I}=v,w=["<!DOCTYPE html>",'<html lang="en">',"<head>",'<meta charset="UTF-8" />','<meta name="viewport" content="width=device-width, initial-scale=1.0" />',$,...Object.keys(I).map((N)=>`<meta name="${N}" content="${I[N]}" />`),`<link rel="icon" href="${G}" />`,`<title>${A}</title>`,'<script src="./frontend.tsx"></script>',"</head>",p,"</html>"];await Bun.write(`${U}/index.html`,w.join(`
20
+ `))}async function S(){let _=await Bun.file(L).text(),v=E(_,"export const metadata");if(v.iconPath&&v.iconPath[0]===".")v.iconPath=K.join("../../../src/app",v.iconPath);return v}function E(_,v){let $=_.indexOf("{",_.indexOf(v)),p=_.indexOf("}",$)+1,A=_.slice($,p).trim();return A=A.replace(/\/\/.*$/gm,""),A=A.replace(/\/\*[\s\S]*?\*\//g,""),A=A.replace(/,\s*([}\]])/g,"$1"),A=A.replace(/([{,]\s*)([A-Za-z0-9_$]+)\s*:/g,'$1"$2":'),A=A.replace(/'|`/g,'"'),JSON.parse(A)}async function r(){let _=await Bun.file(L).text(),v=M(_,"head").slice(6,-7),$=M(_,"body").replaceAll("className","class"),p=$.indexOf(">")+1,A=$.lastIndexOf("<");return $=$.replace($.slice(p,A),""),{headContent:v,body:$}}function M(_,v){for(let $,p=_.indexOf("export default");;p++){if(!$&&_.startsWith(`<${v}`,p))$=p;if($&&_.startsWith(`</${v}>`,p))return _.slice($,p+v.length+3).replaceAll(`
21
+ `," ").replaceAll(/\s{2,}/g," ").trim()}}function Y(){let _=new Bun.Glob("**/index.tsx"),v=[];for(let $ of _.scanSync("src/app"))v.push({filePath:K.join("src/app",$),tmpPath:K.join(),htmlPath:K.join(),iconPath:K.join(),urlPath:""});return v}async function H(){let _=Y();await W(_);let v=Bun.file("./bunfig.toml");if(await v.exists()){let p=await v.text();if(!p.includes("bun-plugin-tailwind")){p+=`${p===""?"":`
22
+ `}${V}`,await v.write(p);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}}else{await v.write(V);async function p(){let A=Bun.file("bunfig.toml");try{if(await A.exists())await A.delete()}catch{}}process.on("SIGINT",p),setTimeout(p,250);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}await Bun.spawn({cmd:["bun","node_modules/.cache/wdwh/server.ts"],stdout:"ignore",stderr:"inherit",ipc:(p)=>{console.log(p)}}).exited}import y from"bun-plugin-tailwind";import b from"fs";async function z(){let _=performance.now(),v=Y(),p=(await Bun.file("package.json").json()).wdwh||{};if(!p.outdir)p.outdir="dist";await W(v);let A={entrypoints:[`${U}/index.html`],outdir:p.outdir,plugins:[y],minify:!0,target:"browser",sourcemap:"none",external:p.external,naming:p.hashFiles===!1?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0,define:{"process.env.NODE_ENV":'"production"'}};if(p.cleanPrev)b.rmSync(p.outdir,{recursive:!0,force:!0});let G=await Bun.build(A),I=Bun.file(`${p.outdir}/index.html`),w=k(await I.text());if(v.length===1){let J=G.outputs.find((Q)=>Q.path.endsWith(".css"));if(J?.path){let Q=Bun.file(J.path),j=w.indexOf('<link rel="stylesheet"'),R=j;for(;R<w.length;R++)if(["/>",'">'].includes(w.slice(R,R+2))){R+=2;break}let C=w.slice(j,R),T=`<style>${k(await Q.text())}</style>`;w=w.replace(C,T),await Q.delete(),G.outputs.splice(G.outputs.indexOf(J),1)}}await I.write(w);let N=performance.now();if(process.argv.includes("--dir"))console.log(`See "${p.outdir}"`);if(process.argv.includes("--time"))console.log(`Build in ${N-_}ms`)}function k(_){return _.replaceAll(`
23
+ `," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var Z="./tmp.zip",m="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await H();break;case"build":await z();break;case"init":{let _=await fetch(m);if(!_.ok)console.log(`feach error: ${_.status}`),process.exit(1);let v=await _.bytes();await Bun.write(Z,v);let $=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",Z,"-DestinationPath",".","-Force"]:["unzip","-o",Z,"-d","."];Bun.spawnSync($);let p=new Bun.Glob("**/*");for(let A of p.scanSync("template/template"))if(!g(A))D(f.join("template/template",A),A),console.log(`+ ${A}`);D("./template/template",".",{recursive:!0}),P(Z),P("./template",{recursive:!0}),console.log(`
24
+ Run "bun i && bun dev" and start development!`);break}default:console.log(`Usage:
24
25
  wdwh dev
25
26
  wdwh build
26
27
  --dir # Print out dir
package/config.d.ts DELETED
@@ -1,17 +0,0 @@
1
- type WdwhConfig = {
2
- outdir: string
3
- bundleCss?: boolean
4
- hashFiles?: boolean
5
- cleanPrev?: boolean
6
- external?: string[]
7
- }
8
-
9
- type Metadata = {
10
- iconPath: string
11
- title: string
12
- description?: string
13
- author?: string
14
- keywords?: string
15
- themeColor?: string
16
- [name: string]: string | undefined
17
- }