MCPcopy Create free account
hub / github.com/TanStack/ai / startDev

Function startDev

examples/ts-react-native-chat/scripts/dev.mjs:287–346  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

285}
286
287function startDev() {
288 loadEnvFileIntoEnv()
289 const config = createDevConfig()
290
291 console.log(
292 `Using EXPO_PUBLIC_TANSTACK_AI_BASE_URL=${config.baseUrl}${
293 config.usedProvidedBaseUrl ? ' (from environment)' : ''
294 }`,
295 )
296 console.log(
297 config.usedProvidedPackagerHostname
298 ? `Using REACT_NATIVE_PACKAGER_HOSTNAME=${config.packagerHostname} (from environment)`
299 : 'Using Expo-managed Metro host detection',
300 )
301
302 if (!config.lanAddress && !config.usedProvidedBaseUrl) {
303 console.warn(
304 'No non-internal IPv4 address was detected. Set EXPO_PUBLIC_TANSTACK_AI_BASE_URL manually if your phone cannot reach the backend.',
305 )
306 }
307
308 const children = [
309 spawnProcess(config.pnpmCommand, ['dev:server'], config.serverEnv),
310 spawnProcess(
311 config.pnpmCommand,
312 ['exec', 'expo', 'start', '--lan', '--clear'],
313 config.expoEnv,
314 ),
315 ]
316
317 let shuttingDown = false
318
319 function shutdown(exitCode = 0) {
320 if (shuttingDown) return
321 shuttingDown = true
322 for (const child of children) {
323 killProcess(child)
324 }
325 process.exitCode = exitCode
326 }
327
328 for (const child of children) {
329 child.on('error', (error) => {
330 console.error(error)
331 shutdown(1)
332 })
333
334 child.on('exit', (code, signal) => {
335 if (shuttingDown) return
336 if (code === 0 || signal) {
337 shutdown(0)
338 } else {
339 shutdown(code ?? 1)
340 }
341 })
342 }
343
344 process.on('SIGINT', () => shutdown(0))

Callers 1

mainFunction · 0.85

Calls 7

loadEnvFileIntoEnvFunction · 0.85
createDevConfigFunction · 0.85
spawnProcessFunction · 0.85
shutdownFunction · 0.85
logMethod · 0.80
warnMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected