wdwh 1.12.11 → 1.12.12
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/package.json +2 -2
- package/signal.d.ts +1 -1
- package/signal.js +1 -1
- package/wdwh.js +14 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wdwh",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.12",
|
|
4
4
|
"author": "kubashh",
|
|
5
5
|
"description": "The Bun Frontend Framework.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"dev": "clear && bun dev/dev.ts",
|
|
27
27
|
"build": "bun dev/scripts.ts",
|
|
28
|
-
"pub": "bun dev/scripts.ts
|
|
28
|
+
"pub": "bun dev/scripts.ts --publish",
|
|
29
29
|
"zip": "zip -r template/template.zip template/template"
|
|
30
30
|
},
|
|
31
31
|
"bin": {
|
package/signal.d.ts
CHANGED
package/signal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{useSyncExternalStore as o}from"react";function a(t){let r=t,n=new Set;function i(){return r}function s(e){return n.add(e),()=>n.delete(e)}return{get:i,set(e){let u=typeof e==="function"?e(r):e;if(Object.is(r,u))return;r=u,n.forEach((
|
|
2
|
+
import{useSyncExternalStore as o}from"react";function a(t){let r=t,n=new Set;function i(){return r}function s(e){return n.add(e),()=>n.delete(e)}return{get:i,set(e){let u=typeof e==="function"?e(r):e;if(Object.is(r,u))return;r=u,n.forEach((c)=>c())},subscribe:s,use(){return o(s,i)}}}function f(t){return o(t.subscribe,t.get)}export{f as useSignal,a as createSignal};
|
package/wdwh.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{cpSync as
|
|
4
|
-
import "
|
|
3
|
+
import{cpSync as T,existsSync as u,rmSync as F}from"fs";import o from"path";var J=`import { createRoot } from "react-dom/client";
|
|
4
|
+
import "CSS_PATH";
|
|
5
5
|
import App from "APP_PATH";
|
|
6
6
|
|
|
7
7
|
createRoot(document.getElementsByTagName("body")[0]).render(<App />);
|
|
8
|
-
`;var
|
|
8
|
+
`;var X=`import index from "./index.html";
|
|
9
9
|
|
|
10
10
|
const { url } = Bun.serve({
|
|
11
|
-
routes: {
|
|
11
|
+
routes: {
|
|
12
|
+
"/": index,
|
|
13
|
+
"/*": new Response(\`Not found!\`),
|
|
14
|
+
},
|
|
12
15
|
development: { hmr: true },
|
|
13
16
|
});
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
`;var
|
|
18
|
+
console.log(\`> Server running at \${url}\`);
|
|
19
|
+
`;var G=`
|
|
17
20
|
[serve.static]
|
|
18
21
|
plugins = ["bun-plugin-tailwind"]
|
|
19
|
-
env = "BUN_PUBLIC_*"`;var
|
|
20
|
-
`))}}async function
|
|
21
|
-
`," ").replaceAll(/\s{2,}/g," ").trim()}}function
|
|
22
|
-
`}${
|
|
23
|
-
`," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var
|
|
22
|
+
env = "BUN_PUBLIC_*"`;var p="../../../src/app/App.tsx",m="../../../src/app/global.css",q="./node_modules/.cache/wdwh",Z={[`${q}/frontend.tsx`]:J.replace("CSS_PATH",m).replace("APP_PATH",p),[`${q}/server.ts`]:X},H={outdir:"dist",hashFiles:!0,cleanPrev:!1,tailwind:!0,external:[]};import D from"path";async function K(R){for(let U of R){for(let N in Z)await Bun.write(N,Z[N]);let{headContent:A,body:_}=await y(U),v=D.join(q,U.urlPath,"index.html"),j=["<!DOCTYPE html>",'<html lang="en">',"<head>",'<meta charset="UTF-8" />','<meta name="viewport" content="width=device-width, initial-scale=1.0" />',A,'<script src="./frontend.tsx"></script>',"</head>",_,"</html>"];await Bun.write(v,j.join(`
|
|
23
|
+
`))}}async function y(R){let U=await Bun.file(R.tsxPath).text(),A=I(U,"head").slice(6,-7),_=A.match(/<link\s+rel=["']icon["']\s+href=["']([^"']+)["']\s*\/?>/)?.at(1);if(_){let Q=D.join("../".repeat(R.urlPath.split("/").length+2),"src/app",R.urlPath,_);A=A.replace(/<link\s+rel=["']icon["']\s+href=["'][^"']+["']\s*\/?>/,`<link rel="icon" href="${Q}" />`)}let v=I(U,"body").replaceAll("className","class"),j=v.indexOf(">")+1,N=v.lastIndexOf("<");return v=v.replace(v.slice(j,N),""),{headContent:A,body:v}}function I(R,U){for(let A,_=R.indexOf("export default");;_++){if(!A&&R.startsWith(`<${U}`,_))A=_;if(A&&R.startsWith(`</${U}>`,_))return R.slice(A,_+U.length+3).replaceAll(`
|
|
24
|
+
`," ").replaceAll(/\s{2,}/g," ").trim()}}function L(){let R=new Bun.Glob("**/index.tsx"),U=[];for(let A of R.scanSync("src/app")){let _=D.join("src/app",A),v=A.replace(/index\.tsx$/,"").replace(/\\/g,"/");U.push({tsxPath:_,urlPath:v})}return U}async function $(){let R=L();await K(R);let U=Bun.file("./bunfig.toml");if(await U.exists()){let A=await U.text();if(!A.includes("bun-plugin-tailwind"))A+=`${A===""?"":`
|
|
25
|
+
`}${G}`,await U.write(A),await O()}else{await U.write(G);async function A(){let _=Bun.file("bunfig.toml");try{if(await _.exists())await _.delete()}catch{}}process.on("SIGINT",A),setTimeout(A,250),await O()}Bun.spawnSync({cmd:["bun","node_modules/.cache/wdwh/server.ts"],stdio:["ignore","inherit","inherit"]})}async function O(){try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}import x from"fs";import z from"path";import b from"bun-plugin-tailwind";async function w(){let R=L(),U=performance.now(),A=await Bun.file("package.json").json(),_=Object.assign(H,A.wdwh);await K(R);let j={entrypoints:R.map((V)=>z.join(q,V.urlPath,"index.html")),outdir:_.outdir,plugins:_.tailwind?[b]:void 0,minify:!0,target:"browser",external:_.external,naming:!_.hashFiles?{chunk:"[name].[ext]",asset:"[name].[ext]"}:void 0,define:{"process.env.NODE_ENV":'"production"'}};if(_.cleanPrev)x.rmSync(_.outdir,{recursive:!0,force:!0});let N=await Bun.build(j);for(let V of R){let k=Bun.file(z.join(_.outdir,V.urlPath,"index.html")),W=C(await k.text());if(R.length===1){let Y=N.outputs.find((B)=>B.path.endsWith(".css"));if(Y?.path){let B=Bun.file(Y.path);W=await g(W,await B.text()),await B.delete(),N.outputs.splice(N.outputs.indexOf(Y),1)}}await k.write(W)}let Q=performance.now();if(process.argv.includes("--dir"))console.log(`See "${_.outdir}"`);if(process.argv.includes("--time"))console.log(`Build in ${Q-U}ms`)}async function g(R,U){let A=R.indexOf('<link rel="stylesheet"'),_=A;for(;_<R.length;_++)if(["/>",'">'].includes(R.slice(_,_+2))){_+=2;break}let v=R.slice(A,_),j=`<style>${C(U)}</style>`;return R.replace(v,j)}function C(R){return R.replaceAll(`
|
|
26
|
+
`," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}var M="./tmp.zip",d="https://raw.githubusercontent.com/kubashh/wdwh/main/template/template.zip";switch(process.argv[2]){case"dev":await $();break;case"build":await w();break;case"init":{let R=await fetch(d);if(!R.ok)console.log(`feach error: ${R.status}`),process.exit(1);let U=await R.bytes();await Bun.write(M,U);let A=process.platform==="win32"?["powershell","-Command","Expand-Archiv","-Path",M,"-DestinationPath",".","-Force"]:["unzip","-o",M,"-d","."];Bun.spawnSync(A);let _=new Bun.Glob("**/*");for(let v of _.scanSync("template/template"))if(!u(v))T(o.join("template/template",v),v),console.log(`+ ${v}`);T("./template/template",".",{recursive:!0}),F(M),F("./template",{recursive:!0}),console.log("Installing dependencies..."),await Bun.$`bun update`,console.log(`
|
|
24
27
|
Run "bun dev" and start development!`);break}default:console.log(`Usage:
|
|
25
28
|
wdwh dev
|
|
26
29
|
wdwh build
|