@typed-assistant/builder 0.0.36 → 0.0.37
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 +1 -1
- package/src/appProcess.tsx +44 -55
- package/src/setupWebserver.tsx +1 -0
package/package.json
CHANGED
package/src/appProcess.tsx
CHANGED
|
@@ -18,6 +18,44 @@ import { restartAddon } from "./restartAddon"
|
|
|
18
18
|
import { getAddonInfo as getAddonInfoAPI } from "./getAddonInfo"
|
|
19
19
|
import debounce from "debounce"
|
|
20
20
|
|
|
21
|
+
export async function setup({
|
|
22
|
+
entryFile,
|
|
23
|
+
mdiPaths,
|
|
24
|
+
onProcessError,
|
|
25
|
+
}: {
|
|
26
|
+
entryFile: string
|
|
27
|
+
} & Parameters<typeof generateTypes>[0] &
|
|
28
|
+
Pick<Parameters<typeof checkProcesses>[1], "onProcessError">) {
|
|
29
|
+
const addonInfo = await getAddonInfo()
|
|
30
|
+
const basePath = addonInfo?.data.ingress_entry ?? ""
|
|
31
|
+
const slug = addonInfo?.data.slug ?? ""
|
|
32
|
+
const directoryToWatch = join(process.cwd(), "./src")
|
|
33
|
+
const addonUrl = `${slug}/ingress`
|
|
34
|
+
|
|
35
|
+
checkProcesses(entryFile, { addonUrl, onProcessError })
|
|
36
|
+
await setupGitSync()
|
|
37
|
+
|
|
38
|
+
let subprocesses = await buildAndStartAppProcess(entryFile, {
|
|
39
|
+
mdiPaths: mdiPaths,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
startWebappServer({
|
|
43
|
+
basePath,
|
|
44
|
+
getSubprocesses: () => subprocesses,
|
|
45
|
+
})
|
|
46
|
+
setupWatcher({
|
|
47
|
+
directoryToWatch,
|
|
48
|
+
entryFile,
|
|
49
|
+
mdiPaths,
|
|
50
|
+
onSubprocessChange: (newSubprocesses) => {
|
|
51
|
+
subprocesses = newSubprocesses
|
|
52
|
+
},
|
|
53
|
+
getSubprocesses: () => subprocesses,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return subprocesses
|
|
57
|
+
}
|
|
58
|
+
|
|
21
59
|
type Processes = Awaited<ReturnType<typeof buildAndStartAppProcess>>
|
|
22
60
|
|
|
23
61
|
async function buildAndStartAppProcess(
|
|
@@ -59,29 +97,21 @@ const checkProcesses = async (
|
|
|
59
97
|
{
|
|
60
98
|
addonUrl,
|
|
61
99
|
onProcessError,
|
|
62
|
-
restartAddonUrl,
|
|
63
100
|
}: {
|
|
64
101
|
addonUrl: string
|
|
65
|
-
onProcessError?: (
|
|
66
|
-
message: string,
|
|
67
|
-
addonUrl: string,
|
|
68
|
-
restartAddonUrl?: string,
|
|
69
|
-
) => void
|
|
70
|
-
restartAddonUrl: string
|
|
102
|
+
onProcessError?: (message: string, addonUrl: string) => void
|
|
71
103
|
},
|
|
72
104
|
) => {
|
|
73
105
|
const ps = await $`ps -f`.text()
|
|
74
106
|
const matches = ps.match(new RegExp(`bun .+${entryFile}`, "gmi")) ?? []
|
|
75
|
-
onProcessError?.("message", addonUrl, restartAddonUrl)
|
|
76
107
|
|
|
77
108
|
if (matches.length > 1) {
|
|
78
109
|
multipleProcessesErrorCount++
|
|
79
110
|
if (multipleProcessesErrorCount > 5) {
|
|
80
|
-
const message = `🚨 Multiple processes detected.
|
|
111
|
+
const message = `🚨 Multiple processes detected. Check the logs...`
|
|
81
112
|
log(message)
|
|
82
113
|
log(ps)
|
|
83
|
-
onProcessError?.(message, addonUrl
|
|
84
|
-
// restartAddon()
|
|
114
|
+
onProcessError?.(message, addonUrl)
|
|
85
115
|
return
|
|
86
116
|
}
|
|
87
117
|
} else {
|
|
@@ -91,11 +121,10 @@ const checkProcesses = async (
|
|
|
91
121
|
if (matches.length === 0) {
|
|
92
122
|
noProcessesErrorCount++
|
|
93
123
|
if (noProcessesErrorCount > 5) {
|
|
94
|
-
const message = `🚨 No processes detected.
|
|
124
|
+
const message = `🚨 No processes detected. Check the logs...`
|
|
95
125
|
log(message)
|
|
96
126
|
log(ps)
|
|
97
|
-
onProcessError?.(message, addonUrl
|
|
98
|
-
// restartAddon()
|
|
127
|
+
onProcessError?.(message, addonUrl)
|
|
99
128
|
return
|
|
100
129
|
}
|
|
101
130
|
} else {
|
|
@@ -103,50 +132,11 @@ const checkProcesses = async (
|
|
|
103
132
|
}
|
|
104
133
|
|
|
105
134
|
setTimeout(
|
|
106
|
-
() =>
|
|
107
|
-
checkProcesses(entryFile, { addonUrl, onProcessError, restartAddonUrl }),
|
|
135
|
+
() => checkProcesses(entryFile, { addonUrl, onProcessError }),
|
|
108
136
|
5000,
|
|
109
137
|
)
|
|
110
138
|
}
|
|
111
139
|
|
|
112
|
-
export async function setup({
|
|
113
|
-
entryFile,
|
|
114
|
-
mdiPaths,
|
|
115
|
-
onProcessError,
|
|
116
|
-
}: {
|
|
117
|
-
entryFile: string
|
|
118
|
-
} & Parameters<typeof generateTypes>[0] &
|
|
119
|
-
Pick<Parameters<typeof checkProcesses>[1], "onProcessError">) {
|
|
120
|
-
const addonInfo = await getAddonInfo()
|
|
121
|
-
const basePath = addonInfo?.data.ingress_entry ?? ""
|
|
122
|
-
const directoryToWatch = join(process.cwd(), "./src")
|
|
123
|
-
const addonUrl = basePath
|
|
124
|
-
const restartAddonUrl = `${basePath}/restart-addon`
|
|
125
|
-
|
|
126
|
-
checkProcesses(entryFile, { addonUrl, onProcessError, restartAddonUrl })
|
|
127
|
-
await setupGitSync()
|
|
128
|
-
|
|
129
|
-
let subprocesses = await buildAndStartAppProcess(entryFile, {
|
|
130
|
-
mdiPaths: mdiPaths,
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
startWebappServer({
|
|
134
|
-
basePath,
|
|
135
|
-
getSubprocesses: () => subprocesses,
|
|
136
|
-
})
|
|
137
|
-
setupWatcher({
|
|
138
|
-
directoryToWatch,
|
|
139
|
-
entryFile,
|
|
140
|
-
mdiPaths,
|
|
141
|
-
onSubprocessChange: (newSubprocesses) => {
|
|
142
|
-
subprocesses = newSubprocesses
|
|
143
|
-
},
|
|
144
|
-
getSubprocesses: () => subprocesses,
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
return subprocesses
|
|
148
|
-
}
|
|
149
|
-
|
|
150
140
|
const getAddonInfo = async () => {
|
|
151
141
|
log("🔍 Getting addon info...")
|
|
152
142
|
|
|
@@ -204,7 +194,6 @@ function setupWatcher({
|
|
|
204
194
|
directoryToWatch,
|
|
205
195
|
{ recursive: true },
|
|
206
196
|
debounce(async function onFileChange(event, filename) {
|
|
207
|
-
console.log("😅😅😅 ~ event:", event)
|
|
208
197
|
if (!filename) return
|
|
209
198
|
if (shouldIgnoreFileOrFolder(filename)) return
|
|
210
199
|
log(`⚠️ Change to ${filename} detected.`)
|
package/src/setupWebserver.tsx
CHANGED
|
@@ -108,6 +108,7 @@ export const startWebappServer = async ({
|
|
|
108
108
|
.get("/restart-addon", async () => {
|
|
109
109
|
await killSubprocess(getSubprocesses().app)
|
|
110
110
|
restartAddon()
|
|
111
|
+
return { message: "Restarting addon..." }
|
|
111
112
|
})
|
|
112
113
|
.get("/addon-info", async () => {
|
|
113
114
|
const { data, error } = await getAddonInfo()
|