@typed-assistant/builder 0.0.5 → 0.0.7

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/appProcess.tsx +21 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed-assistant/builder",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
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/typescript-config": "0.0.3",
21
- "@typed-assistant/eslint-config": "0.0.3",
22
- "@typed-assistant/utils": "0.0.4",
23
- "@typed-assistant/logger": "0.0.4"
20
+ "@typed-assistant/eslint-config": "0.0.4",
21
+ "@typed-assistant/logger": "0.0.5",
22
+ "@typed-assistant/typescript-config": "0.0.4",
23
+ "@typed-assistant/utils": "0.0.6"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "home-assistant-js-websocket": "^8.2.0"
@@ -5,8 +5,9 @@ import { readFileSync, watch } from "fs"
5
5
  import { join, relative } from "path"
6
6
  import ignore from "ignore"
7
7
  import { ONE_SECOND } from "@typed-assistant/utils/durations"
8
- import { getHassAPI } from "@typed-assistant/utils/getHassAPI"
8
+ import { fetchWithAuth, 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("♻️ Restarting app...")
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(`⚠️ Change to ${filename} detected.`)
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
- const duration = gitPullPollDuration ?? 5
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("♻️ Restarting addon...")
102
- await getHassAPI(`http://supervisor/addons/self/restart`, { method: "POST" })
108
+ log("♻️ Restarting addon...")
109
+ await fetchWithAuth(`http://supervisor/addons/self/restart`, {
110
+ method: "POST",
111
+ })
112
+ }
113
+
114
+ const getAddonInfo = async () => {
115
+ log("🔍 Getting addon info...")
116
+
117
+ return withErrorHandling(fetchWithAuth)("http://supervisor/addons/self/info")
103
118
  }