Compare commits
2 Commits
c10ebe3c98
...
6afefcec5b
| Author | SHA1 | Date | |
|---|---|---|---|
| 6afefcec5b | |||
| 1b563106fe |
|
|
@ -37,18 +37,10 @@ async function waitForState(name: string, target: string, timeout: number): Prom
|
||||||
export async function configShow() {
|
export async function configShow() {
|
||||||
console.log(`Host: ${color.bold(HOST)}`)
|
console.log(`Host: ${color.bold(HOST)}`)
|
||||||
|
|
||||||
const source = process.env.TOES_URL ? 'TOES_URL' : process.env.DEV ? 'DEV' : '(default)'
|
|
||||||
console.log(`Source: ${color.gray(source)}`)
|
|
||||||
|
|
||||||
if (process.env.TOES_URL) {
|
|
||||||
console.log(` TOES_URL=${process.env.TOES_URL}`)
|
|
||||||
}
|
|
||||||
if (process.env.DEV) {
|
|
||||||
console.log(` DEV=${process.env.DEV}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const syncState = readSyncState(process.cwd())
|
const syncState = readSyncState(process.cwd())
|
||||||
console.log(`Version: ${syncState ? color.bold(syncState.version) : color.gray('(not deployed)')}`)
|
if (syncState) {
|
||||||
|
console.log(`Version: ${color.bold(syncState.version)}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function infoApp(arg?: string) {
|
export async function infoApp(arg?: string) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync,
|
||||||
import { dirname, join } from 'path'
|
import { dirname, join } from 'path'
|
||||||
import { Hype } from '@because/hype'
|
import { Hype } from '@because/hype'
|
||||||
|
|
||||||
|
const MAX_VERSIONS = 5
|
||||||
|
|
||||||
interface FileChangeEvent {
|
interface FileChangeEvent {
|
||||||
hash?: string
|
hash?: string
|
||||||
path: string
|
path: string
|
||||||
|
|
@ -294,7 +296,7 @@ router.post('/apps/:app/activate', async c => {
|
||||||
// Atomic rename over old symlink/directory
|
// Atomic rename over old symlink/directory
|
||||||
renameSync(tempLink, currentLink)
|
renameSync(tempLink, currentLink)
|
||||||
|
|
||||||
// Clean up old versions (keep 5 most recent)
|
// Clean up old versions
|
||||||
try {
|
try {
|
||||||
const entries = readdirSync(appDir, { withFileTypes: true })
|
const entries = readdirSync(appDir, { withFileTypes: true })
|
||||||
|
|
||||||
|
|
@ -305,13 +307,24 @@ router.post('/apps/:app/activate', async c => {
|
||||||
.sort()
|
.sort()
|
||||||
.reverse() // Newest first
|
.reverse() // Newest first
|
||||||
|
|
||||||
// Keep 5 most recent, delete the rest
|
// Keep most recent, delete the rest
|
||||||
const toDelete = versionDirs.slice(5)
|
const toDelete = versionDirs.slice(MAX_VERSIONS)
|
||||||
for (const dir of toDelete) {
|
for (const dir of toDelete) {
|
||||||
const dirPath = join(appDir, dir)
|
const dirPath = join(appDir, dir)
|
||||||
rmSync(dirPath, { recursive: true, force: true })
|
rmSync(dirPath, { recursive: true, force: true })
|
||||||
console.log(`Cleaned up old version: ${dir}`)
|
console.log(`Cleaned up old version: ${dir}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete node_modules from old kept versions (not the active one)
|
||||||
|
const toKeep = versionDirs.slice(0, MAX_VERSIONS)
|
||||||
|
for (const dir of toKeep) {
|
||||||
|
if (dir === version) continue
|
||||||
|
const nm = join(appDir, dir, 'node_modules')
|
||||||
|
if (existsSync(nm)) {
|
||||||
|
rmSync(nm, { recursive: true, force: true })
|
||||||
|
console.log(`Removed node_modules from old version: ${dir}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Log but don't fail activation if cleanup fails
|
// Log but don't fail activation if cleanup fails
|
||||||
console.error(`Failed to clean up old versions: ${e}`)
|
console.error(`Failed to clean up old versions: ${e}`)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user