@typed-assistant/builder 0.0.11 → 0.0.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/src/appProcess.tsx +2 -2
- package/src/setupWebserver.tsx +59 -16
- package/src/webserver/Terminal.tsx +64 -0
- package/src/webserver/index.html +9 -0
- package/src/webserver/index.tsx +7 -0
- package/src/webserver/input.css +3 -0
- package/src/webserver/tailwind.config.js +13 -0
- package/src/webserver/terminal.html +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed-assistant/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"exports": {
|
|
5
5
|
"./appProcess": "./src/appProcess.tsx",
|
|
6
6
|
"./bunInstall": "./src/bunInstall.tsx",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"home-assistant-js-websocket": "^8.2.0",
|
|
21
21
|
"typescript": "^5.3.3",
|
|
22
22
|
"@typed-assistant/eslint-config": "0.0.4",
|
|
23
|
-
"@typed-assistant/logger": "0.0.5",
|
|
24
23
|
"@typed-assistant/typescript-config": "0.0.4",
|
|
24
|
+
"@typed-assistant/logger": "0.0.5",
|
|
25
25
|
"@typed-assistant/utils": "0.0.7"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
package/src/appProcess.tsx
CHANGED
|
@@ -60,6 +60,7 @@ export async function setupWatcher(
|
|
|
60
60
|
...args: Parameters<typeof buildAndStartAppProcess>
|
|
61
61
|
) {
|
|
62
62
|
const { data: addonInfo, error: addonInfoError } = await getAddonInfo()
|
|
63
|
+
console.log("😅😅😅 ~ addonInfo:", addonInfo)
|
|
63
64
|
if (addonInfoError) {
|
|
64
65
|
log(`🚨 Failed to get addon info: ${addonInfoError}`)
|
|
65
66
|
}
|
|
@@ -81,12 +82,11 @@ export async function setupWatcher(
|
|
|
81
82
|
},
|
|
82
83
|
)
|
|
83
84
|
|
|
84
|
-
startWebappServer({getSubprocesses: () => subprocesses})
|
|
85
|
+
startWebappServer({ getSubprocesses: () => subprocesses })
|
|
85
86
|
|
|
86
87
|
return subprocesses
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
|
|
90
90
|
const setupGitSync = async ({
|
|
91
91
|
gitPullPollDuration,
|
|
92
92
|
}: {
|
package/src/setupWebserver.tsx
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import { log } from "@typed-assistant/logger"
|
|
1
2
|
import Convert from "ansi-to-html"
|
|
2
|
-
import type { Context } from "elysia"
|
|
3
|
-
import { Elysia, t } from "elysia"
|
|
4
3
|
import type { Subprocess } from "bun"
|
|
5
|
-
import
|
|
4
|
+
import { $ } from "bun"
|
|
5
|
+
import type { Context } from "elysia"
|
|
6
|
+
import { Elysia } from "elysia"
|
|
7
|
+
import { basename, join } from "path"
|
|
8
|
+
|
|
9
|
+
const indexHtmlFilePath = `${import.meta.dir}/webserver/index.html`
|
|
10
|
+
const cssFile = `${import.meta.dir}/webserver/input.css`
|
|
11
|
+
const terminalHtmlUrl = `${import.meta.dir}/webserver/terminal.html`
|
|
12
|
+
const tsEntryPoint = `${import.meta.dir}/webserver/index.tsx`
|
|
13
|
+
const tailwindConfig = `${import.meta.dir}/webserver/tailwind.config.js`
|
|
14
|
+
const cssOutputFile = join(process.cwd(), `./build/output.css`)
|
|
6
15
|
|
|
7
16
|
const convert = new Convert()
|
|
8
17
|
const decoder = new TextDecoder()
|
|
@@ -38,7 +47,38 @@ export const startWebappServer = async ({
|
|
|
38
47
|
app: Subprocess<"ignore", "pipe", "pipe">
|
|
39
48
|
}
|
|
40
49
|
}) => {
|
|
41
|
-
|
|
50
|
+
const buildResult = await Bun.build({
|
|
51
|
+
entrypoints: [tsEntryPoint],
|
|
52
|
+
outdir: "./build",
|
|
53
|
+
define: {
|
|
54
|
+
"process.env.BASE_PATH": "'lmao'",
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
if (!buildResult.success) {
|
|
58
|
+
for (const message of buildResult.logs) {
|
|
59
|
+
// Bun will pretty print the message object
|
|
60
|
+
console.error(message)
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Build failed")
|
|
63
|
+
}
|
|
64
|
+
log("🛠️ Web server built successfully")
|
|
65
|
+
|
|
66
|
+
await $`bunx tailwindcss -c ${tailwindConfig} -i ${cssFile} -o ${cssOutputFile}`.quiet()
|
|
67
|
+
log("💄 Tailwind built successfully")
|
|
68
|
+
|
|
69
|
+
const indexHtml = (await Bun.file(indexHtmlFilePath).text())
|
|
70
|
+
.replace("{{ STYLESHEET }}", `/assets/${basename(cssOutputFile)}`)
|
|
71
|
+
.replace(
|
|
72
|
+
"{{ SCRIPTS }}",
|
|
73
|
+
buildResult.outputs
|
|
74
|
+
.map(
|
|
75
|
+
(output) =>
|
|
76
|
+
`<script type="module" src="/assets/${basename(output.path)}"></script>`,
|
|
77
|
+
)
|
|
78
|
+
.join("\n"),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
const server = new Elysia()
|
|
42
82
|
.get("/", ({ request }) => {
|
|
43
83
|
getIngressPath(request)
|
|
44
84
|
return new Response(
|
|
@@ -55,29 +95,32 @@ export const startWebappServer = async ({
|
|
|
55
95
|
)
|
|
56
96
|
})
|
|
57
97
|
.get("/terminal", Bun.file(terminalHtmlUrl))
|
|
98
|
+
.get(
|
|
99
|
+
"/terminal2",
|
|
100
|
+
() =>
|
|
101
|
+
new Response(indexHtml, {
|
|
102
|
+
headers: { "content-type": "text/html" },
|
|
103
|
+
}),
|
|
104
|
+
)
|
|
58
105
|
.get("/log.txt", Bun.file("./log.txt"))
|
|
59
|
-
.get("/*", ({ request }) => {
|
|
60
|
-
getIngressPath(request)
|
|
61
|
-
return "Hello Elysia"
|
|
62
|
-
})
|
|
63
106
|
.ws("/ws", {
|
|
64
|
-
body: t.Object({
|
|
65
|
-
id: t.String(),
|
|
66
|
-
}),
|
|
67
107
|
async open(ws) {
|
|
68
108
|
ws.send("Connected successfully. Awaiting messages...")
|
|
69
109
|
subscribers.set(ws.id, (message) => {
|
|
70
110
|
ws.send(message)
|
|
71
111
|
})
|
|
72
|
-
console.log("😅😅😅 ~ ws.id:", ws.id)
|
|
73
112
|
},
|
|
74
|
-
close(ws
|
|
75
|
-
console.log("ws closed", code, message, ws.id)
|
|
76
|
-
console.log("😅😅😅 ~ ws.id:", ws.id)
|
|
113
|
+
close(ws) {
|
|
77
114
|
subscribers.delete(ws.id)
|
|
78
115
|
},
|
|
79
116
|
})
|
|
80
|
-
|
|
117
|
+
|
|
118
|
+
server.get(`/assets/${basename(cssOutputFile)}`, Bun.file(cssOutputFile))
|
|
119
|
+
buildResult.outputs.forEach((output) => {
|
|
120
|
+
server.get(`/assets/${basename(output.path)}`, Bun.file(output.path))
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
server.listen(8099)
|
|
81
124
|
|
|
82
125
|
// eslint-disable-next-line no-constant-condition
|
|
83
126
|
while (true) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useEffect, useState } from "react"
|
|
2
|
+
|
|
3
|
+
const basePath = process.env.BASE_PATH
|
|
4
|
+
console.log("😅😅😅 ~ basePath:", basePath)
|
|
5
|
+
|
|
6
|
+
const getWS = () => {
|
|
7
|
+
const url = new URL(window.location.href)
|
|
8
|
+
const endPathname = url.pathname.split("/")
|
|
9
|
+
url.pathname = url.pathname.replace(
|
|
10
|
+
`/${endPathname[endPathname.length - 1]}`,
|
|
11
|
+
"/ws",
|
|
12
|
+
)
|
|
13
|
+
url.protocol = "ws:"
|
|
14
|
+
const ws = new WebSocket(url)
|
|
15
|
+
|
|
16
|
+
return ws
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Terminal() {
|
|
20
|
+
const [content, setContent] = useState("")
|
|
21
|
+
const [ws, setWS] = useState<WebSocket>(() => getWS())
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
let timeout: NodeJS.Timeout
|
|
25
|
+
|
|
26
|
+
ws.onclose = function () {
|
|
27
|
+
timeout = setTimeout(() => {
|
|
28
|
+
if (ws.readyState === WebSocket.OPEN) return
|
|
29
|
+
setWS(getWS())
|
|
30
|
+
}, 1000)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
ws.onmessage = function (event) {
|
|
34
|
+
setContent(event.data)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
clearTimeout(timeout)
|
|
39
|
+
ws.close()
|
|
40
|
+
}
|
|
41
|
+
}, [ws])
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<h1 className="text-white text-2xl">
|
|
46
|
+
Terminal{" "}
|
|
47
|
+
{ws.readyState === WebSocket.OPEN ? (
|
|
48
|
+
<span className="py-1 px-2 rounded-sm bg-emerald-300 text-emerald-800 text-xs uppercase">
|
|
49
|
+
Connected
|
|
50
|
+
</span>
|
|
51
|
+
) : (
|
|
52
|
+
<span className="py-1 px-2 rounded-sm bg-rose-300 text-rose-800 text-xs uppercase">
|
|
53
|
+
Disconnected
|
|
54
|
+
</span>
|
|
55
|
+
)}
|
|
56
|
+
</h1>
|
|
57
|
+
<p>
|
|
58
|
+
Logs are also available at <a href="/log.txt">/log.txt</a>
|
|
59
|
+
</p>
|
|
60
|
+
|
|
61
|
+
<pre className="" dangerouslySetInnerHTML={{ __html: content }} />
|
|
62
|
+
</>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { join } from "path"
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line no-undef
|
|
4
|
+
const content = [join(__dirname, "./**/*.tsx"), join(__dirname, "./**/*.html")]
|
|
5
|
+
|
|
6
|
+
/** @type {import('tailwindcss').Config} */
|
|
7
|
+
export default {
|
|
8
|
+
content,
|
|
9
|
+
theme: {
|
|
10
|
+
extend: {},
|
|
11
|
+
},
|
|
12
|
+
plugins: [],
|
|
13
|
+
}
|