@typed-assistant/builder 0.0.5 → 0.0.6
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 +5 -5
- package/src/appProcess.tsx +19 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed-assistant/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"exports": {
|
|
5
5
|
"./appProcess": "./src/appProcess.tsx",
|
|
6
6
|
"./bunInstall": "./src/bunInstall.tsx",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"eslint": "^8.56.0",
|
|
18
18
|
"home-assistant-js-websocket": "^8.2.0",
|
|
19
19
|
"typescript": "^5.3.3",
|
|
20
|
-
"@typed-assistant/
|
|
21
|
-
"@typed-assistant/
|
|
22
|
-
"@typed-assistant/
|
|
23
|
-
"@typed-assistant/
|
|
20
|
+
"@typed-assistant/logger": "0.0.5",
|
|
21
|
+
"@typed-assistant/utils": "0.0.5",
|
|
22
|
+
"@typed-assistant/typescript-config": "0.0.4",
|
|
23
|
+
"@typed-assistant/eslint-config": "0.0.4"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"home-assistant-js-websocket": "^8.2.0"
|
package/src/appProcess.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import ignore from "ignore"
|
|
|
7
7
|
import { ONE_SECOND } from "@typed-assistant/utils/durations"
|
|
8
8
|
import { getHassAPI } from "@typed-assistant/utils/getHassAPI"
|
|
9
9
|
import { pullChanges } from "./pullChanges"
|
|
10
|
+
import { withErrorHandling } from "@typed-assistant/utils/withErrorHandling"
|
|
10
11
|
|
|
11
12
|
type Processes = Awaited<ReturnType<typeof buildAndStartAppProcess>>
|
|
12
13
|
|
|
@@ -33,7 +34,7 @@ async function kill(process: Subprocess) {
|
|
|
33
34
|
let settingUp = { current: false }
|
|
34
35
|
async function killAndRestartApp(subprocesses: Processes) {
|
|
35
36
|
if (settingUp.current) return subprocesses
|
|
36
|
-
log("♻️
|
|
37
|
+
log("♻️ Restarting app...")
|
|
37
38
|
settingUp.current = true
|
|
38
39
|
if (subprocesses.app) await kill(subprocesses.app)
|
|
39
40
|
const newSubprocesses = await buildAndStartAppProcess()
|
|
@@ -54,6 +55,11 @@ function setupWatcherInternal(...args: Parameters<typeof watch>) {
|
|
|
54
55
|
export async function setupWatcher(
|
|
55
56
|
...args: Parameters<typeof buildAndStartAppProcess>
|
|
56
57
|
) {
|
|
58
|
+
const { data: addonInfo, error: addonInfoError } = await getAddonInfo()
|
|
59
|
+
if (addonInfoError) {
|
|
60
|
+
log(`🚨 Failed to get addon info: ${addonInfoError}`)
|
|
61
|
+
}
|
|
62
|
+
console.log("ℹ️ ~ addonInfo:", addonInfo)
|
|
57
63
|
await setupGitSync()
|
|
58
64
|
|
|
59
65
|
let subprocesses = await buildAndStartAppProcess(...args)
|
|
@@ -63,7 +69,7 @@ export async function setupWatcher(
|
|
|
63
69
|
async function onFileChange(event, filename) {
|
|
64
70
|
if (!filename) return
|
|
65
71
|
if (shouldIgnoreFileOrFolder(filename)) return
|
|
66
|
-
log(`⚠️
|
|
72
|
+
log(`⚠️ Change to ${filename} detected.`)
|
|
67
73
|
if (filename.endsWith("process.tsx")) {
|
|
68
74
|
await restartAddon()
|
|
69
75
|
} else {
|
|
@@ -81,7 +87,8 @@ const setupGitSync = async ({
|
|
|
81
87
|
/** Duration in seconds */
|
|
82
88
|
gitPullPollDuration?: number
|
|
83
89
|
} = {}) => {
|
|
84
|
-
|
|
90
|
+
log(`😅 Attempting to pull changes...`)
|
|
91
|
+
const duration = gitPullPollDuration ?? 30
|
|
85
92
|
const { error } = await pullChanges()
|
|
86
93
|
if (error) return
|
|
87
94
|
log(` ⏳ Pulling changes again in ${duration} seconds...`)
|
|
@@ -98,6 +105,14 @@ const shouldIgnoreFileOrFolder = (filename: string) =>
|
|
|
98
105
|
ig.ignores(relative(process.cwd(), filename))
|
|
99
106
|
|
|
100
107
|
const restartAddon = async () => {
|
|
101
|
-
log("♻️
|
|
108
|
+
log("♻️ Restarting addon...")
|
|
102
109
|
await getHassAPI(`http://supervisor/addons/self/restart`, { method: "POST" })
|
|
103
110
|
}
|
|
111
|
+
|
|
112
|
+
const getAddonInfo = async () => {
|
|
113
|
+
log("🔍 Getting addon info...")
|
|
114
|
+
|
|
115
|
+
return withErrorHandling(getHassAPI)<{
|
|
116
|
+
data: { ingress_entry: string }
|
|
117
|
+
}>("http://supervisor/addons/self/info")
|
|
118
|
+
}
|