wdwh 1.11.0 → 1.11.2-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.
Potentially problematic release.
This version of wdwh might be problematic. Click here for more details.
- package/README.md +2 -2
- package/package.json +10 -8
- package/signal.d.ts +9 -0
- package/signal.js +2 -0
- package/{dist/wdwh.js → wdwh.js} +1 -1
- package/signal.ts +0 -57
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Works only with Bun runtime
|
|
|
5
5
|
## Init project
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
bunx wdwh@latest init
|
|
8
|
+
bunx wdwh@latest init
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Adding to project
|
|
@@ -27,7 +27,7 @@ bun i -d wdwh
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
### 3. [Add files](https://github.com/kubashh/
|
|
30
|
+
### 3. [Add files](https://github.com/kubashh/wdwh/tree/main/template/template)
|
|
31
31
|
|
|
32
32
|
- `src/app/index.tsx` (contains only `html` `head` `body` tags and `metadata`)
|
|
33
33
|
- `src/app/App.tsx` (app entry point)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wdwh",
|
|
3
|
-
"version": "1.11.0",
|
|
3
|
+
"version": "1.11.2-dev.0",
|
|
4
4
|
"author": "kubashh",
|
|
5
5
|
"description": "The Bun framework. Easyer web dev without html for static sites",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,25 +9,26 @@
|
|
|
9
9
|
"react",
|
|
10
10
|
"bun",
|
|
11
11
|
"wdwh",
|
|
12
|
-
"kubashh",
|
|
13
12
|
"web",
|
|
14
13
|
"html",
|
|
15
14
|
"css",
|
|
16
|
-
"typescript"
|
|
15
|
+
"typescript",
|
|
16
|
+
"framework"
|
|
17
17
|
],
|
|
18
18
|
"files": [
|
|
19
19
|
"LICENSE",
|
|
20
20
|
"README.md",
|
|
21
21
|
"dist",
|
|
22
22
|
"index.d.ts",
|
|
23
|
-
"signal.
|
|
23
|
+
"signal.js",
|
|
24
|
+
"signal.d.ts"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
|
-
"build": "bun
|
|
27
|
-
"pub": "bun
|
|
27
|
+
"build": "bun scripts.ts",
|
|
28
|
+
"pub": "bun scripts.ts pub"
|
|
28
29
|
},
|
|
29
30
|
"bin": {
|
|
30
|
-
"wdwh": "./
|
|
31
|
+
"wdwh": "./wdwh.js"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"bun-plugin-tailwind": "^0.1.2",
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
"@types/react": "^19.2.14"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/bun": "^1.3.9"
|
|
41
|
+
"@types/bun": "^1.3.9",
|
|
42
|
+
"typescript": "^5.9.3"
|
|
41
43
|
},
|
|
42
44
|
"prettier": {
|
|
43
45
|
"semi": false,
|
package/signal.d.ts
ADDED
package/signal.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{useState as s}from"react";function o(e){return s(e)[0]}function n(){let e=s(!1)[1];return()=>e((r)=>!r)}class t{v;refresh=()=>{throw Error("Refresh not bind!")};constructor(e){this.v=e}bind(e){if(e){let r=n();this.refresh=()=>{e(),r()}}else this.refresh=n()}get value(){return this.v}set value(e){this.v=e,this.refresh?.()}}function f(e){return new t(e)}function T(e,r){let i=o(new t(e));return i.bind(r),i}export{T as useSignal,f as signal};
|
package/{dist/wdwh.js → wdwh.js}
RENAMED
|
@@ -19,5 +19,5 @@ console.log(\`> Server running at \${server.url}\`)
|
|
|
19
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
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
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})}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)}"
|
|
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
23
|
try "dev" | "build" | "init"`),process.exit(1)}
|
package/signal.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { useState } from "react"
|
|
2
|
-
|
|
3
|
-
type Void = () => void
|
|
4
|
-
|
|
5
|
-
export type Signal<T> = {
|
|
6
|
-
refresh: Void
|
|
7
|
-
bind: (fn?: Void) => void
|
|
8
|
-
value: T
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function useConst<T>(v: T) {
|
|
12
|
-
return useState<T>(v)[0]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function useRefresh() {
|
|
16
|
-
const f = useState(false)[1]
|
|
17
|
-
return () => f((prev) => !prev)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
class Sig<T> implements Signal<T> {
|
|
21
|
-
private v: T
|
|
22
|
-
refresh: Void = () => {
|
|
23
|
-
throw Error(`Refresh not bind!`)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
constructor(v: T) {
|
|
27
|
-
this.v = v
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
bind(fn?: Void) {
|
|
31
|
-
if (fn) {
|
|
32
|
-
const refresh = useRefresh()
|
|
33
|
-
this.refresh = () => {
|
|
34
|
-
fn()
|
|
35
|
-
refresh()
|
|
36
|
-
}
|
|
37
|
-
} else this.refresh = useRefresh()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get value() {
|
|
41
|
-
return this.v
|
|
42
|
-
}
|
|
43
|
-
set value(v: T) {
|
|
44
|
-
this.v = v
|
|
45
|
-
this.refresh?.()
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function signal<T>(v: T): Signal<T> {
|
|
50
|
-
return new Sig(v)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function useSignal<T>(v: T, f?: Void): Signal<T> {
|
|
54
|
-
const sig = useConst(new Sig(v))
|
|
55
|
-
sig.bind(f)
|
|
56
|
-
return sig
|
|
57
|
-
}
|