wdwh 1.12.0 → 1.12.4

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.
Files changed (4) hide show
  1. package/README.md +1 -1
  2. package/hooks.js +1 -1
  3. package/package.json +12 -12
  4. package/wdwh.js +20 -12
package/README.md CHANGED
@@ -13,7 +13,7 @@ bunx wdwh@latest init
13
13
  ### 1. Install `wdwh`
14
14
 
15
15
  ```sh
16
- bun i -d wdwh
16
+ bun i wdwh@latest
17
17
  ```
18
18
 
19
19
  ### 2. Add script `dev` `build` to `package.json`
package/hooks.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{useState as t}from"react";function s(){let e=t(!1)[1];return()=>e((o)=>!o)}function n(e){return t(e)[0]}function u(){let[e,o]=t(!1);return[e,{onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1)}]}export{s as useRefresh,u as useHover,n as useConst};
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};
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "wdwh",
3
- "version": "1.12.0",
3
+ "version": "1.12.4",
4
4
  "author": "kubashh",
5
5
  "description": "The Bun framework. Easyer web dev without html for static sites",
6
6
  "license": "MIT",
7
- "repository": "https://github.com/kubashh/wdwh",
7
+ "repository": "kubashh/wdwh",
8
8
  "keywords": [
9
9
  "react",
10
- "bun",
10
+ "framework",
11
11
  "wdwh",
12
12
  "web",
13
- "html",
14
- "css",
13
+ "bun",
15
14
  "typescript",
16
- "framework"
15
+ "frontend"
17
16
  ],
18
17
  "files": [
19
18
  "LICENSE",
@@ -26,6 +25,7 @@
26
25
  "signal.d.ts"
27
26
  ],
28
27
  "scripts": {
28
+ "dev": "bun dev/dev.ts",
29
29
  "build": "bun dev/scripts.ts",
30
30
  "pub": "bun dev/scripts.ts pub",
31
31
  "zip": "zip -r template/template.zip template/template"
@@ -34,15 +34,15 @@
34
34
  "wdwh": "./wdwh.js"
35
35
  },
36
36
  "dependencies": {
37
- "bun-plugin-tailwind": "^0.1.2",
38
- "react": "^19.2.4",
39
- "react-dom": "^19.2.4",
40
- "tailwindcss": "^4.2.0",
41
- "@types/react": "^19.2.14"
37
+ "bun-plugin-tailwind": "latest"
42
38
  },
43
39
  "devDependencies": {
44
40
  "@types/bun": "^1.3.9",
45
- "typescript": "^5.9.3"
41
+ "@types/react": "^19.2.14",
42
+ "tailwindcss": "^4.2.1",
43
+ "typescript": "^5.9.3",
44
+ "react": "^19.2.4",
45
+ "react-dom": "^19.2.4"
46
46
  },
47
47
  "prettier": {
48
48
  "semi": false,
package/wdwh.js CHANGED
@@ -1,23 +1,31 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{cpSync as F,readdirSync as C,rmSync as P}from"fs";var l="./node_modules/.cache/wdwh",u=`
3
+ import{cpSync as T,readdirSync as X,rmSync as I}from"fs";var m=`
4
4
  [serve.static]
5
5
  plugins = ["bun-plugin-tailwind"]
6
- env = "BUN_PUBLIC_*"`,f={["./node_modules/.cache/wdwh/frontend.tsx"]:`import { createRoot } from "react-dom/client"
6
+ env = "BUN_PUBLIC_*"`;var P=`import { createRoot } from "react-dom/client"
7
7
  import "../../../src/app/index.css"
8
- import App from "../../../src/app/App.tsx"
8
+ import App from "APP_PATH"
9
9
 
10
- createRoot(document.getElementsByTagName("body")[0]).render(<App />)`,["./node_modules/.cache/wdwh/server.ts"]:`import index from "./index.html"
10
+ createRoot(document.getElementsByTagName("body")[0]).render(<App />)
11
+ `;var A=`import index from "./index.html"
11
12
 
12
- const server = Bun.serve({
13
+ const { url } = Bun.serve({
13
14
  routes: { "/*": index },
14
15
  development: { hmr: true },
15
16
  })
16
17
 
17
- console.log(\`> Server running at \${server.url}\`)
18
- `};async function m(){let t=await Bun.file("./src/app/index.tsx").text(),e=g(t,"export const config"),n=g(t,"export const metadata");if(n.iconPath&&n.iconPath[0]===".")n.iconPath=`../../../src/app${n.iconPath.slice(1)}`;return{config:e,metadata:n}}function g(t,e){let n=t.indexOf("{",t.indexOf(e)),i=t.indexOf("}",n)+1;return A(t.slice(n,i))}function A(t){let e=t.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 d(){let{metadata:t}=await m();for(let r in f)await Bun.write(r,f[r]);let{headContent:e,body:n}=await v(),{title:i,iconPath:s,...a}=t,c=["<!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((r)=>`<meta name="${r}" content="${a[r]}" />`),`<link rel="icon" href="${s}" />`,`<title>${i}</title>`,'<script src="./frontend.tsx"></script>',"</head>",n,"</html>"];await Bun.write(`${l}/index.html`,c.join(`
19
- `))}async function v(){let t=await Bun.file("./src/app/index.tsx").text(),e=h(t,"head").slice(6,-7),n=h(t,"body").replaceAll("className","class"),i=n.indexOf(">")+1,s=n.lastIndexOf("<");return n=n.replace(n.slice(i,s),""),{headContent:e,body:n}}function h(t,e){for(let n,i=t.indexOf("export default");;i++){if(!n&&t.startsWith(`<${e}`,i))n=i;if(n&&t.startsWith(`</${e}>`,i))return t.slice(n,i+e.length+3).replaceAll(`
20
- `," ").replaceAll(/\s{2,}/g," ").trim()}}async function x(){await d();let t=Bun.file("./bunfig.toml");if(await t.exists()){let e=await t.text();if(!e.includes("bun-plugin-tailwind")){e+=`${e===""?"":`
21
- `}${u}`,await t.write(e);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}}else{await t.write(u);async function e(){let n=Bun.file("bunfig.toml");try{if(await n.exists())await n.delete()}catch{}}process.on("SIGINT",e),setTimeout(e,250);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}await Bun.$`bun node_modules/.cache/wdwh/server.ts`}import O from"bun-plugin-tailwind";import w from"fs";async function b(){let{config:t}=await m();await d();let e={entrypoints:[`${l}/index.html`],outdir:t.outdir,plugins:[O],minify:!0,target:"browser",sourcemap:"none",define:{"process.env.NODE_ENV":'"production"'},external:t.external,naming:!t.hashFiles?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0};if(t.cleanPrev&&w.existsSync(t.outdir))w.rmSync(t.outdir,{recursive:!0});let n=await Bun.build(e),i=Bun.file(`${t.outdir}/index.html`),s=$(await i.text());if(t.bundleCss){let a=n.outputs.find((c)=>c.path.endsWith(".css"));if(a?.path){let c=Bun.file(a.path),r=s.indexOf('<link rel="stylesheet"'),o=r;for(;o<s.length;o++)if(["/>",'">'].includes(s.slice(o,o+2))){o+=2;break}let y=s.slice(r,o),B=`<style>${$(await c.text())}</style>`;s=s.replace(y,B),await c.delete(),n.outputs.splice(n.outputs.indexOf(a),1)}}await i.write(s),console.log(`See "${t.outdir}"`)}function $(t){return t.replaceAll(`
22
- `," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var p="./tmp.zip",S="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await x();break;case"build":await b();break;case"init":{if(C(".").length===0){let n=await(await fetch(S)).bytes();await Bun.write(p,n);let i=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",p,"-DestinationPath",".","-Force"]:["unzip","-o",p,"-d","."];Bun.spawnSync(i),F("./template/template",".",{recursive:!0}),await Bun.file(p).delete(),P("./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(`wrong command: "${process.argv.at(2)}"
23
- try "dev" | "build" | "init"`),process.exit(1)}
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:
24
+ wdwh dev
25
+ wdwh build
26
+ --dir # Print out dir
27
+ --time # Print build time
28
+
29
+ bunx wdwh@latest init # Init new project in current directory
30
+
31
+ wrong command: "${process.argv.at(2)}"`),process.exit(1)}