@typed-assistant/builder 0.0.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed-assistant/builder",
3
- "version": "0.0.4",
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/eslint-config": "0.0.3",
21
- "@typed-assistant/logger": "0.0.4",
22
- "@typed-assistant/typescript-config": "0.0.3",
23
- "@typed-assistant/utils": "0.0.4"
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"
@@ -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("♻️ 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,8 +87,10 @@ const setupGitSync = async ({
81
87
  /** Duration in seconds */
82
88
  gitPullPollDuration?: number
83
89
  } = {}) => {
84
- const duration = gitPullPollDuration ?? 5
85
- await pullChanges()
90
+ log(`😅 Attempting to pull changes...`)
91
+ const duration = gitPullPollDuration ?? 30
92
+ const { error } = await pullChanges()
93
+ if (error) return
86
94
  log(` ⏳ Pulling changes again in ${duration} seconds...`)
87
95
 
88
96
  setTimeout(() => {
@@ -97,6 +105,14 @@ const shouldIgnoreFileOrFolder = (filename: string) =>
97
105
  ig.ignores(relative(process.cwd(), filename))
98
106
 
99
107
  const restartAddon = async () => {
100
- log("♻️ Restarting addon...")
108
+ log("♻️ Restarting addon...")
101
109
  await getHassAPI(`http://supervisor/addons/self/restart`, { method: "POST" })
102
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
+ }
@@ -11,7 +11,7 @@ export const pullChanges = async () => {
11
11
  log(
12
12
  "⚠️ Cannot pull changes without GITHUB_TOKEN, GITHUB_USERNAME, and GITHUB_REPO environment variables.",
13
13
  )
14
- return
14
+ return { error: {} }
15
15
  }
16
16
  log("⬇️ Pulling changes...")
17
17
  const gitPullText = await getSpawnText(["git", "pull"])
@@ -19,7 +19,7 @@ export const pullChanges = async () => {
19
19
  const nothingNew = /Already up to date./.test(gitPullText)
20
20
  if (nothingNew) {
21
21
  log(" 👌 No new changes.")
22
- return
22
+ return {}
23
23
  } else {
24
24
  log(" 👍 Changes pulled.")
25
25
  }
@@ -28,4 +28,5 @@ export const pullChanges = async () => {
28
28
  const { error } = await bunInstall()
29
29
  if (error) throw new Error(error.text)
30
30
  }
31
+ return {}
31
32
  }