Delete git repo on app removal via app:delete event

This commit is contained in:
Chris Wanstrath 2026-03-01 09:45:50 -08:00
parent be7a7bd35b
commit 0efc25834c
2 changed files with 7 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import { Hype } from '@because/hype'
import { define, stylesToCSS } from '@because/forge'
import { baseStyles, ToolScript, theme } from '@because/toes/tools'
import { baseStyles, ToolScript, theme, on } from '@because/toes/tools'
import { mkdirSync } from 'fs'
import { mkdir, readdir, readlink, rm, stat } from 'fs/promises'
import { join, resolve } from 'path'
@ -406,6 +406,11 @@ async function withDeployLock<T>(repo: string, fn: () => Promise<T>): Promise<T>
mkdirSync(REPOS_DIR, { recursive: true })
on('app:delete', async ({ app: name }) => {
const bare = repoPath(name)
if (await dirExists(bare)) await rm(bare, { recursive: true, force: true })
})
app.get('/ok', c => c.text('ok'))
app.get('/styles.css', c =>

View File

@ -2,11 +2,10 @@ import { APPS_DIR, allApps, emit, registerApp, removeApp, restartApp, startApp }
import { computeHash, generateManifest } from '../sync'
import { loadGitignore } from '@gitignore'
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, symlinkSync, unlinkSync, watch, writeFileSync } from 'fs'
import { dirname, join, resolve } from 'path'
import { dirname, join } from 'path'
import { Hype } from '@because/hype'
const MAX_VERSIONS = 5
const REPOS_DIR = resolve(process.env.DATA_DIR ?? '.', 'repos')
interface FileChangeEvent {
hash?: string
@ -211,11 +210,6 @@ router.delete('/apps/:app', c => {
removeApp(appName)
rmSync(appPath, { recursive: true })
// Remove bare git repo if one exists
const repoPath = join(REPOS_DIR, `${appName}.git`)
if (existsSync(repoPath)) rmSync(repoPath, { recursive: true })
return c.json({ ok: true })
})