@typed-assistant/builder 0.0.49 → 0.0.52

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed-assistant/builder",
3
- "version": "0.0.49",
3
+ "version": "0.0.52",
4
4
  "exports": {
5
5
  "./appProcess": "./src/appProcess.tsx",
6
6
  "./bunInstall": "./src/bunInstall.tsx",
@@ -24,9 +24,9 @@
24
24
  "home-assistant-js-websocket": "^8.2.0",
25
25
  "ts-toolbelt": "^9.6.0",
26
26
  "typescript": "^5.3.3",
27
- "@typed-assistant/typescript-config": "0.0.8",
28
27
  "@typed-assistant/eslint-config": "0.0.8",
29
- "@typed-assistant/logger": "0.0.14",
28
+ "@typed-assistant/logger": "0.0.16",
29
+ "@typed-assistant/typescript-config": "0.0.8",
30
30
  "@typed-assistant/utils": "0.0.14"
31
31
  },
32
32
  "peerDependencies": {
@@ -24,8 +24,8 @@ export async function setup({
24
24
  onProcessError,
25
25
  }: {
26
26
  entryFile: string
27
- } & Parameters<typeof generateTypes>[0] &
28
- Pick<Parameters<typeof checkProcesses>[1], "onProcessError">) {
27
+ onProcessError: (message: string, addonUrl: string) => void
28
+ } & Parameters<typeof generateTypes>[0]) {
29
29
  const addonInfo = await getAddonInfo()
30
30
  const basePath = addonInfo?.data.ingress_entry ?? ""
31
31
  const slug = addonInfo?.data.slug ?? ""
@@ -51,7 +51,24 @@ export async function setup({
51
51
  getSubprocesses: () => subprocesses,
52
52
  })
53
53
 
54
- checkProcesses(entryFile, { addonUrl, onProcessError })
54
+ checkProcesses(entryFile, {
55
+ onMultiProcessError: (ps) => {
56
+ const message = `Multiple processes detected. Restarting addon...`
57
+ logger.fatal({ additionalDetails: ps, emoji: "🚨" }, message)
58
+ onProcessError?.(message, addonUrl)
59
+ restartAddon()
60
+ },
61
+ onNoProcessError: async (ps) => {
62
+ const message = `No processes detected. Restarting app...`
63
+ logger.fatal({ additionalDetails: ps, emoji: "🚨" }, message)
64
+ onProcessError?.(message, addonUrl)
65
+ subprocesses = await killAndRestartApp(
66
+ entryFile,
67
+ { mdiPaths },
68
+ subprocesses,
69
+ )
70
+ },
71
+ })
55
72
  await setupGitSync(webhookUrl)
56
73
 
57
74
  return subprocesses
@@ -96,11 +113,11 @@ let noProcessesErrorCount = 0
96
113
  const checkProcesses = async (
97
114
  entryFile: string,
98
115
  {
99
- addonUrl,
100
- onProcessError,
116
+ onMultiProcessError,
117
+ onNoProcessError,
101
118
  }: {
102
- addonUrl: string
103
- onProcessError?: (message: string, addonUrl: string) => void
119
+ onMultiProcessError?: (psOutput: string) => void | Promise<void>
120
+ onNoProcessError?: (psOutput: string) => void | Promise<void>
104
121
  },
105
122
  ) => {
106
123
  const ps = await $`ps -f`.text()
@@ -109,9 +126,7 @@ const checkProcesses = async (
109
126
  if (matches.length > 1) {
110
127
  multipleProcessesErrorCount++
111
128
  if (multipleProcessesErrorCount > 5) {
112
- const message = `Multiple processes detected. Check the logs...`
113
- logger.fatal({ additionalDetails: ps, emoji: "🚨" }, message)
114
- onProcessError?.(message, addonUrl)
129
+ await onMultiProcessError?.(ps)
115
130
  return
116
131
  }
117
132
  } else {
@@ -121,9 +136,7 @@ const checkProcesses = async (
121
136
  if (matches.length === 0) {
122
137
  noProcessesErrorCount++
123
138
  if (noProcessesErrorCount > 5) {
124
- const message = `No processes detected. Check the logs...`
125
- logger.fatal({ additionalDetails: ps, emoji: "🚨" }, message)
126
- onProcessError?.(message, addonUrl)
139
+ await onNoProcessError?.(ps)
127
140
  return
128
141
  }
129
142
  } else {
@@ -131,7 +144,7 @@ const checkProcesses = async (
131
144
  }
132
145
 
133
146
  setTimeout(
134
- () => checkProcesses(entryFile, { addonUrl, onProcessError }),
147
+ () => checkProcesses(entryFile, { onMultiProcessError, onNoProcessError }),
135
148
  5000,
136
149
  )
137
150
  }
@@ -10,7 +10,7 @@ const App = () => {
10
10
  <Terminal basePath={basePath} />
11
11
  </div>
12
12
  <div className="col-span-1">
13
- <Logs />
13
+ <Logs basePath={basePath} />
14
14
  </div>
15
15
  </div>
16
16
  )
@@ -7,8 +7,9 @@ import { useWS } from "./useWS"
7
7
  import { getPrettyTimestamp } from "@typed-assistant/utils/getPrettyTimestamp"
8
8
  import { levels } from "@typed-assistant/logger/levels"
9
9
  import type { LogSchema } from "@typed-assistant/logger"
10
+ import { buttonStyle } from "./styles"
10
11
 
11
- export const Logs = () => {
12
+ export const Logs = ({ basePath }: { basePath: string }) => {
12
13
  const [limit, setLimit] = useState(200)
13
14
  const [level, setLevel] = useState<
14
15
  "trace" | "debug" | "info" | "warn" | "error" | "fatal"
@@ -39,6 +40,11 @@ export const Logs = () => {
39
40
  <h2 className="mb-2 text-2xl flex items-baseline gap-3">
40
41
  Logs <WSIndicator ws={ws.ws} />
41
42
  </h2>
43
+
44
+ <a className={buttonStyle} href={`${basePath}/log.txt?limit=500`}>
45
+ View raw log.txt
46
+ </a>
47
+
42
48
  <div className="flex flex-wrap gap-2">
43
49
  <div className="flex gap-2">
44
50
  <label htmlFor="dateTimeVisibility">Date/Time</label>
@@ -94,10 +100,7 @@ export const Logs = () => {
94
100
  .sort((a, b) => b.time - a.time)
95
101
  .map((log, index) => {
96
102
  return (
97
- <li
98
- key={(log.time ?? index) + log.time + log.msg}
99
- className="flex gap-1"
100
- >
103
+ <li key={index + JSON.stringify(log)} className="flex gap-1">
101
104
  <span className="text-slate-400 mr-2">
102
105
  {dateTimeVisibility === "hidden"
103
106
  ? null
@@ -3,6 +3,7 @@ import { app } from "./api"
3
3
  import { useWS } from "./useWS"
4
4
  import { WSIndicator } from "./WSIndicator"
5
5
  import { AppSection } from "./AppSection"
6
+ import { buttonStyle } from "./styles"
6
7
 
7
8
  export function Terminal({ basePath }: { basePath: string }) {
8
9
  const [content, setContent] = useState("")
@@ -22,9 +23,6 @@ export function Terminal({ basePath }: { basePath: string }) {
22
23
  <a className={buttonStyle} href={`${basePath}/restart-addon`}>
23
24
  Restart addon
24
25
  </a>
25
- <a className={buttonStyle} href={`${basePath}/log.txt?limit=500`}>
26
- View log.txt
27
- </a>
28
26
  </div>
29
27
  </>
30
28
  )}
@@ -33,5 +31,3 @@ export function Terminal({ basePath }: { basePath: string }) {
33
31
  </AppSection>
34
32
  )
35
33
  }
36
-
37
- const buttonStyle = "bg-slate-800 text-white px-3 py-1 rounded-md"
@@ -1,3 +1,4 @@
1
+ <!doctype html>
1
2
  <html class="h-full">
2
3
  <head>
3
4
  <link rel="stylesheet" href="{{ STYLESHEET }}" />
@@ -0,0 +1 @@
1
+ export const buttonStyle = "bg-slate-800 text-white px-3 py-1 rounded-md"