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 +1 -1
- package/hooks.d.ts +1 -0
- package/hooks.js +1 -1
- package/index.d.ts +9 -0
- package/package.json +3 -5
- package/wdwh.js +16 -15
- package/config.d.ts +0 -17
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/
|
|
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
package/hooks.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{useState as
|
|
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
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wdwh",
|
|
3
|
-
"version": "1.12.
|
|
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
|
-
"
|
|
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
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
}
|