bhg-helper 1.0.4 → 1.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/cli/cli.js +29 -11
- package/package.json +1 -1
package/cli/cli.js
CHANGED
|
@@ -184,9 +184,16 @@ async function apiPost(pathname) {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
async function apiGet(pathname) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
try {
|
|
188
|
+
const controller = new AbortController()
|
|
189
|
+
const timer = setTimeout(() => controller.abort(), 800)
|
|
190
|
+
const res = await fetch(`${API_URL}${pathname}`, { signal: controller.signal })
|
|
191
|
+
clearTimeout(timer)
|
|
192
|
+
if (!res.ok) return null
|
|
193
|
+
return await res.json().catch(() => null)
|
|
194
|
+
} catch {
|
|
195
|
+
return null
|
|
196
|
+
}
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
async function apiHealth() {
|
|
@@ -203,14 +210,25 @@ async function apiHealth() {
|
|
|
203
210
|
|
|
204
211
|
async function ensureBackend() {
|
|
205
212
|
if (await apiHealth()) return true
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
try {
|
|
214
|
+
if (process.platform === 'win32') {
|
|
215
|
+
execSync('start "" /min cmd /c "npm run server:raw"', {
|
|
216
|
+
cwd: PROJECT_ROOT,
|
|
217
|
+
stdio: 'ignore',
|
|
218
|
+
shell: true,
|
|
219
|
+
})
|
|
220
|
+
} else {
|
|
221
|
+
const child = spawn('npm', ['run', 'server:raw'], {
|
|
222
|
+
cwd: PROJECT_ROOT,
|
|
223
|
+
detached: true,
|
|
224
|
+
stdio: 'ignore',
|
|
225
|
+
shell: false,
|
|
226
|
+
})
|
|
227
|
+
child.unref()
|
|
228
|
+
}
|
|
229
|
+
} catch {
|
|
230
|
+
return false
|
|
231
|
+
}
|
|
214
232
|
await new Promise(resolve => setTimeout(resolve, 1500))
|
|
215
233
|
return await apiHealth()
|
|
216
234
|
}
|