bun-plugin-stx 0.1.15 → 0.1.16
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/dist/chunk-h0s48z3v.js +3 -0
- package/dist/chunk-mjj2b826.js +678 -0
- package/dist/client.js +1 -143
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -9712
- package/dist/preload.d.ts +0 -0
- package/dist/preload.js +2 -0
- package/dist/serve.d.ts +0 -0
- package/dist/serve.js +41 -0
- package/package.json +12 -2
|
File without changes
|
package/dist/preload.js
ADDED
package/dist/serve.d.ts
ADDED
|
File without changes
|
package/dist/serve.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
import{a as W}from"./index.js";import"./chunk-mjj2b826.js";import{h as Y,i as Z}from"./chunk-h0s48z3v.js";var{serve:_,Glob:V}=globalThis.Bun;import N from"process";async function $(){let C=N.argv.slice(2);if(C[0]==="serve")C.shift();let J=C.indexOf("--port"),O=J!==-1&&C[J+1]?Number.parseInt(C[J+1]):3456,U=C.filter((j)=>!j.startsWith("--")&&j!==C[J+1]);if(U.length===0)console.error("Usage: serve <files...> [--port 3000]"),console.error(`
|
|
4
|
+
Examples:`),console.error(" serve pages/*.stx"),console.error(" serve pages/*.md"),console.error(" serve pages/*.html"),console.error(" serve pages/ --port 3000"),console.error(" serve index.stx about.md page.html"),console.error(`
|
|
5
|
+
After installing: bun add bun-plugin-stx`),N.exit(1);console.log(`\uD83D\uDE80 Starting stx development server...
|
|
6
|
+
`);let D=[],X=[".stx",".md",".html"];for(let j of U)try{if((await(await import("fs/promises")).stat(j).catch(()=>null))?.isDirectory())for(let B of[".stx",".md",".html"]){let z=new V(`**/*${B}`),Q=await Array.fromAsync(z.scan(j));D.push(...Q.map((M)=>`${j}/${M}`.replace(/\/+/g,"/")))}else if(j.includes("*")){let B=new V(j),z=j.split("*")[0].replace(/\/$/,""),Q=await Array.fromAsync(B.scan(z||"."));D.push(...Q.map((M)=>z?`${z}/${M}`:M))}else if(X.some((B)=>j.endsWith(B)))D.push(j)}catch(k){console.error(`Error processing pattern "${j}":`,k)}if(D.length===0)console.error("\u274C No .stx, .md, or .html files found"),N.exit(1);console.log(`\uD83D\uDCC4 Found ${D.length} file(s):`),D.forEach((j)=>console.log(` - ${j}`)),console.log(`
|
|
7
|
+
\uD83D\uDD28 Building...`);let L=await Bun.build({entrypoints:D,outdir:"./.stx-serve",plugins:[W()],splitting:!1});if(!L.success)console.error(`
|
|
8
|
+
\u274C Build failed!`),console.error(L.logs),N.exit(1);console.log(`\u2705 Build complete
|
|
9
|
+
`);let H=new Map;console.log(`
|
|
10
|
+
\uD83D\uDCE6 Processing ${L.outputs.length} build outputs...`);for(let j of L.outputs)try{let k=j.path.split("/").pop()||"index";if(!k.endsWith(".html")){console.log(` \u2298 Skipping ${k} (not HTML)`);continue}let A=await j.text(),B=k.replace(".html","").replace(".md","").replace(".stx",""),z=["index","home"].includes(B)?"/":`/${B}`;console.log(` \u2713 ${k} -> ${z}`),H.set(z,A)}catch(k){console.warn(` \u2717 Skipping output: ${j.path} (${k})`)}let w=_({port:O,async fetch(j){let A=new URL(j.url).pathname;if(A==="/index")A="/";if(H.has(A))return new Response(H.get(A),{headers:{"Content-Type":"text/html","Cache-Control":"no-cache"}});if(H.has(`${A}.html`))return new Response(H.get(`${A}.html`),{headers:{"Content-Type":"text/html","Cache-Control":"no-cache"}});let B=Array.from(H.keys()).map((z)=>`<li><a href="${z}">${z}</a></li>`).join(`
|
|
11
|
+
`);return new Response(`
|
|
12
|
+
<!DOCTYPE html>
|
|
13
|
+
<html>
|
|
14
|
+
<head>
|
|
15
|
+
<title>404 - Not Found</title>
|
|
16
|
+
<style>
|
|
17
|
+
body {
|
|
18
|
+
font-family: system-ui, sans-serif;
|
|
19
|
+
max-width: 800px;
|
|
20
|
+
margin: 4rem auto;
|
|
21
|
+
padding: 2rem;
|
|
22
|
+
text-align: center;
|
|
23
|
+
}
|
|
24
|
+
h1 { color: #e53e3e; }
|
|
25
|
+
ul { list-style: none; padding: 0; margin: 2rem 0; }
|
|
26
|
+
li { margin: 0.5rem 0; }
|
|
27
|
+
a { color: #667eea; text-decoration: none; font-size: 1.1rem; }
|
|
28
|
+
a:hover { text-decoration: underline; }
|
|
29
|
+
</style>
|
|
30
|
+
</head>
|
|
31
|
+
<body>
|
|
32
|
+
<h1>404 - Page Not Found</h1>
|
|
33
|
+
<p>The page "${A}" doesn't exist.</p>
|
|
34
|
+
<h2>Available pages:</h2>
|
|
35
|
+
<ul>${B}</ul>
|
|
36
|
+
</body>
|
|
37
|
+
</html>
|
|
38
|
+
`,{status:404,headers:{"Content-Type":"text/html"}})}});console.log(`\uD83C\uDF10 Server running at: http://localhost:${O}
|
|
39
|
+
`),console.log("\uD83D\uDCDA Available routes:"),H.forEach((j,k)=>{console.log(` http://localhost:${O}${k}`)}),console.log(`
|
|
40
|
+
\uD83D\uDCA1 Press Ctrl+C to stop
|
|
41
|
+
`),await Bun.sleep(Number.POSITIVE_INFINITY)}$().catch(console.error);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.16",
|
|
5
5
|
"description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,12 +32,22 @@
|
|
|
32
32
|
"types": "./dist/client.d.ts",
|
|
33
33
|
"import": "./dist/client.js"
|
|
34
34
|
},
|
|
35
|
+
"./preload": {
|
|
36
|
+
"import": "./dist/preload.js"
|
|
37
|
+
},
|
|
38
|
+
"./serve": {
|
|
39
|
+
"import": "./dist/serve.js"
|
|
40
|
+
},
|
|
35
41
|
"./*": {
|
|
36
42
|
"import": "./dist/*"
|
|
37
43
|
}
|
|
38
44
|
},
|
|
39
45
|
"module": "./dist/index.js",
|
|
40
46
|
"types": "./dist/index.d.ts",
|
|
47
|
+
"bin": {
|
|
48
|
+
"serve": "./dist/serve.js",
|
|
49
|
+
"stx-serve": "./dist/serve.js"
|
|
50
|
+
},
|
|
41
51
|
"files": [
|
|
42
52
|
"LICENSE.md",
|
|
43
53
|
"README.md",
|
|
@@ -57,6 +67,6 @@
|
|
|
57
67
|
"typecheck": "bun tsc --noEmit"
|
|
58
68
|
},
|
|
59
69
|
"dependencies": {
|
|
60
|
-
"@stacksjs/stx": "0.1.
|
|
70
|
+
"@stacksjs/stx": "0.1.15"
|
|
61
71
|
}
|
|
62
72
|
}
|