Add app publish/unpublish lifecycle hooks

This commit is contained in:
Chris Wanstrath 2026-05-11 14:46:55 -07:00
parent c0276389eb
commit 875c89de18

View File

@ -168,6 +168,8 @@ export function registerApp(dir: string) {
emit({ type: 'app:create', app: dir }) emit({ type: 'app:create', app: dir })
if (!error && !isStatic) { if (!error && !isStatic) {
runApp(dir, getPort(dir)) runApp(dir, getPort(dir))
} else if (isStatic) {
publishApp(dir)
} }
} }
@ -238,6 +240,7 @@ export function startApp(dir: string) {
app.manuallyStopped = false app.manuallyStopped = false
update() update()
emit({ type: 'app:start', app: dir }) emit({ type: 'app:start', app: dir })
publishApp(dir)
return return
} }
@ -294,6 +297,7 @@ export function stopApp(dir: string) {
app.state = 'stopped' app.state = 'stopped'
app.started = undefined app.started = undefined
app.manuallyStopped = true app.manuallyStopped = true
unpublishApp(dir)
update() update()
emit({ type: 'app:stop', app: dir }) emit({ type: 'app:stop', app: dir })
return return
@ -391,7 +395,10 @@ function discoverApps() {
const isStatic = !!pkg.toes?.static const isStatic = !!pkg.toes?.static
const state: AppState = error ? 'invalid' : (isStatic ? 'running' : 'stopped') const state: AppState = error ? 'invalid' : (isStatic ? 'running' : 'stopped')
const app = buildApp(dir, pkg, state, error) const app = buildApp(dir, pkg, state, error)
if (isStatic) app.started = Date.now() if (isStatic) {
app.started = Date.now()
publishApp(dir)
}
_apps.set(dir, app) _apps.set(dir, app)
} }
update() update()