wdwh 1.9.1 → 1.10.1
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 +2 -2
- package/dist/wdwh.js +9 -7
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/wdwh.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var l="./node_modules/.cache/wdwh",
|
|
3
|
+
var l="./node_modules/.cache/wdwh",d=`
|
|
4
4
|
[serve.static]
|
|
5
5
|
plugins = ["bun-plugin-tailwind"]
|
|
6
|
-
env = "BUN_PUBLIC_*"`,
|
|
6
|
+
env = "BUN_PUBLIC_*"`,u={["./node_modules/.cache/wdwh/frontend.tsx"]:`import { createRoot } from "react-dom/client"
|
|
7
7
|
import "../../../src/app/index.css"
|
|
8
8
|
import App from "../../../src/app/App.tsx"
|
|
9
9
|
|
|
@@ -15,9 +15,11 @@ const server = Bun.serve({
|
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
console.log(\`> Server running at \${server.url}\`)
|
|
18
|
-
`};async function f(){let e=await Bun.file("./src/app/index.tsx").text(),t=m(e,"export const config"),n=m(e,"export const metadata");if(n.iconPath&&n.iconPath[0]===".")n.iconPath=`../../../src/app${n.iconPath.slice(1)}`;return{config:t,metadata:n}}function m(e,t){let n=e.indexOf("{",e.indexOf(t)),i=e.indexOf("}",n)+1;return v(e.slice(n,i))}function v(e){let t=e.trim();return t=t.replace(/\/\/.*$/gm,""),t=t.replace(/\/\*[\s\S]*?\*\//g,""),t=t.replace(/,\s*([}\]])/g,"$1"),t=t.replace(/([{,]\s*)([A-Za-z0-9_$]+)\s*:/g,'$1"$2":'),t=t.replace(/'|`/g,'"'),JSON.parse(t)}async function
|
|
18
|
+
`};async function f(){let e=await Bun.file("./src/app/index.tsx").text(),t=m(e,"export const config"),n=m(e,"export const metadata");if(n.iconPath&&n.iconPath[0]===".")n.iconPath=`../../../src/app${n.iconPath.slice(1)}`;return{config:t,metadata:n}}function m(e,t){let n=e.indexOf("{",e.indexOf(t)),i=e.indexOf("}",n)+1;return v(e.slice(n,i))}function v(e){let t=e.trim();return t=t.replace(/\/\/.*$/gm,""),t=t.replace(/\/\*[\s\S]*?\*\//g,""),t=t.replace(/,\s*([}\]])/g,"$1"),t=t.replace(/([{,]\s*)([A-Za-z0-9_$]+)\s*:/g,'$1"$2":'),t=t.replace(/'|`/g,'"'),JSON.parse(t)}async function p(){let{metadata:e}=await f();for(let a in u)await Bun.write(a,u[a]);let{headContent:t,body:n}=await B(),{title:i,iconPath:r,...s}=e,c=["<!DOCTYPE html>",'<html lang="en">',"<head>",'<meta charset="UTF-8" />','<meta name="viewport" content="width=device-width, initial-scale=1.0" />',t,Object.keys(s).map((a)=>`<meta name="${a}" content="${s[a]}" />`),`<link rel="icon" href="${r}" />`,`<title>${i}</title>`,'<script src="./frontend.tsx"></script>',"</head>",n,"</html>"];await Bun.write(`${l}/index.html`,c.join(`
|
|
19
19
|
`))}async function B(){let e=await Bun.file("./src/app/index.tsx").text(),t=g(e,"head").slice(6,-7),n=g(e,"body").replaceAll("className","class"),i=n.indexOf(">")+1,r=n.lastIndexOf("<");return n=n.replace(n.slice(i,r),""),{headContent:t,body:n}}function g(e,t){for(let n,i=e.indexOf("export default");;i++){if(!n&&e.startsWith(`<${t}`,i))n=i;if(n&&e.startsWith(`</${t}>`,i))return e.slice(n,i+t.length+3).replaceAll(`
|
|
20
|
-
`," ").replaceAll(/\s{2,}/g," ").trim()}}async function h(){
|
|
21
|
-
`}${
|
|
22
|
-
`," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}switch(process.argv
|
|
23
|
-
|
|
20
|
+
`," ").replaceAll(/\s{2,}/g," ").trim()}}async function h(){await p();let e=Bun.file("./bunfig.toml");if(await e.exists()){let t=await e.text();if(!t.includes("bun-plugin-tailwind")){t+=`${t===""?"":`
|
|
21
|
+
`}${d}`,await e.write(t);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}}else{await e.write(d);async function t(){let n=Bun.file("bunfig.toml");try{if(await n.exists())await n.delete()}catch{}}process.on("SIGINT",t),setTimeout(t,250);try{await Bun.$`bunx wdwh dev`}catch{}process.exit()}await Bun.$`bun node_modules/.cache/wdwh/server.ts`}import A from"bun-plugin-tailwind";import w from"fs";async function b(){let{config:e}=await f();await p();let t={entrypoints:[`${l}/index.html`],outdir:e.outdir,plugins:[A],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&&w.existsSync(e.outdir))w.rmSync(e.outdir,{recursive:!0});let n=await Bun.build(t),i=Bun.file(`${e.outdir}/index.html`),r=x(await i.text());if(e.bundleCss){let s=n.outputs.find((c)=>c.path.endsWith(".css"));if(s?.path){let c=Bun.file(s.path),a=r.indexOf('<link rel="stylesheet"'),o=a;for(;o<r.length;o++)if(["/>",'">'].includes(r.slice(o,o+2))){o+=2;break}let y=r.slice(a,o),$=`<style>${x(await c.text())}</style>`;r=r.replace(y,$),await c.delete(),n.outputs.splice(n.outputs.indexOf(s),1)}}await i.write(r),console.log(`See "${e.outdir}"`)}function x(e){return e.replaceAll(`
|
|
22
|
+
`," ").replaceAll(/\s{2,}/g," ").replaceAll(/ > | >|> /g,">").replaceAll(/ < | <|< /g,"<").replaceAll(/ ; | ;|; /g,";").replaceAll(/ { | {|{ /g,"{").replaceAll(/ } | }|} /g,"}").replaceAll(/ " | "|" /g,'"').replaceAll(/ , | ,|, /g,",")}switch(process.argv[2]){case"dev":await h();break;case"build":await b();break;case"init":if(!process.argv[3])console.log(`USAGE:
|
|
23
|
+
|
|
24
|
+
bunx wdwh@latest init my-app # create app in 'my-app' directory, "." for current directory`),process.exit(1);Bun.spawnSync(["bun","create","wdwh-app@latest",process.argv[3]]);break;default:console.log(`wrong command: "${process.argv.at(2)}"
|
|
25
|
+
try "dev" | "build"`),process.exit(1)}
|