Refactor app building and simplify gitUrl

This commit is contained in:
Chris Wanstrath 2026-03-08 23:38:15 -07:00
parent d9533032bc
commit b410a74d15
4 changed files with 18 additions and 24 deletions

View File

@ -179,7 +179,7 @@ export async function newApp(name: string | undefined, options: NewAppOptions) {
await run(['git', 'init'])
await run(['git', 'add', '.'])
await run(['git', 'commit', '-m', 'init'])
await run(['git', 'remote', 'add', 'toes', await gitUrl(appName)])
await run(['git', 'remote', 'add', 'toes', gitUrl(appName)])
await run(['git', 'push', 'toes', 'main'])
console.log(color.green(`✓ Created ${appName}`))
@ -196,7 +196,7 @@ export async function getApp(name: string, directory?: string) {
return
}
const url = await gitUrl(name)
const url = gitUrl(name)
const args = ['git', 'clone', url]
if (directory) args.push(directory)
const proc = Bun.spawn(args, { stdout: 'inherit', stderr: 'inherit' })

View File

@ -1,4 +1,4 @@
import type { App, Manifest } from '@types'
import type { Manifest } from '@types'
import { buildAppUrl } from '@urls'
import { AsyncLocalStorage } from 'node:async_hooks'
@ -21,11 +21,7 @@ export const HOST = process.env.TOES_URL
? normalizeUrl(process.env.TOES_URL)
: DEFAULT_HOST
export async function gitUrl(name: string): Promise<string> {
const git: App | undefined = await get('/api/apps/git')
if (git?.tunnelUrl) return `${git.tunnelUrl}/${name}`
return `${buildAppUrl('git', HOST)}/${name}`
}
export const gitUrl = (name: string) => `${buildAppUrl('git', HOST)}/${name}`
export const getSignal = () => signalStore.getStore()

View File

@ -28,10 +28,9 @@ function convert(app: BackendApp): SharedApp {
router.sse('/stream', (send) => {
let queue = Promise.resolve()
const broadcast = () => {
const apps: SharedApp[] = allApps().map(({
name, state, icon, error, port, started, logs, tool, apps: apps_, dashboard, share, tunnelEnabled, tunnelUrl
}) => ({
name, state, icon, error, port, started, logs, tool, apps: apps_, dashboard, share, tunnelEnabled, tunnelUrl,
const apps: SharedApp[] = allApps().map(app => ({
...convert(app),
logs: app.logs,
}))
queue = queue.then(() => send(apps))
}

View File

@ -158,12 +158,7 @@ export function registerApp(dir: string) {
const { pkg, error } = loadApp(dir)
const state: AppState = error ? 'invalid' : 'stopped'
const icon = pkg.toes?.icon ?? DEFAULT_EMOJI
const tool = pkg.toes?.tool
const apps = pkg.toes?.apps
const dashboard = pkg.toes?.dashboard
const share = pkg.toes?.share
_apps.set(dir, { name: dir, state, icon, error, tool, apps, dashboard, share })
_apps.set(dir, buildApp(dir, pkg, state, error))
update()
emit({ type: 'app:create', app: dir })
if (!error) {
@ -302,6 +297,15 @@ export function updateAppIcon(dir: string, icon: string) {
}
}
const buildApp = (dir: string, pkg: any, state: AppState, error?: string): App => ({
name: dir, state, error,
icon: pkg.toes?.icon ?? DEFAULT_EMOJI,
tool: pkg.toes?.tool,
apps: pkg.toes?.apps,
dashboard: pkg.toes?.dashboard,
share: pkg.toes?.share,
})
const clearTimers = (app: App) => {
if (app.startupTimer) {
clearTimeout(app.startupTimer)
@ -350,12 +354,7 @@ function discoverApps() {
for (const dir of allAppDirs()) {
const { pkg, error } = loadApp(dir)
const state: AppState = error ? 'invalid' : 'stopped'
const icon = pkg.toes?.icon ?? DEFAULT_EMOJI
const tool = pkg.toes?.tool
const apps = pkg.toes?.apps
const dashboard = pkg.toes?.dashboard
const share = pkg.toes?.share
_apps.set(dir, { name: dir, state, icon, error, tool, apps, dashboard, share })
_apps.set(dir, buildApp(dir, pkg, state, error))
}
update()
}