toes logs
This commit is contained in:
parent
7763dc6314
commit
e1b53fc54d
3
TODO.txt
3
TODO.txt
|
|
@ -25,7 +25,8 @@
|
||||||
[x] `toes stop <app>`
|
[x] `toes stop <app>`
|
||||||
[x] `toes restart <app>`
|
[x] `toes restart <app>`
|
||||||
[x] `toes open <app>`
|
[x] `toes open <app>`
|
||||||
[ ] `toes logs <app>`
|
[x] `toes logs <app>`
|
||||||
|
[x] `toes logs -f <app>`
|
||||||
[ ] `toes new`
|
[ ] `toes new`
|
||||||
[ ] `toes pull`
|
[ ] `toes pull`
|
||||||
[ ] `toes push`
|
[ ] `toes push`
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { program } from 'commander'
|
import { program } from 'commander'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import type { App } from '@types'
|
import type { App, LogLine } from '@types'
|
||||||
import { APPS_DIR } from '$apps'
|
import { APPS_DIR } from '$apps'
|
||||||
|
|
||||||
const HOST = `http://localhost:${process.env.PORT ?? 3000}`
|
const HOST = `http://localhost:${process.env.PORT ?? 3000}`
|
||||||
|
|
@ -57,6 +57,22 @@ const restartApp = async (app: string) => {
|
||||||
await post(`/api/apps/${app}/restart`)
|
await post(`/api/apps/${app}/restart`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function logApp(name: string) {
|
||||||
|
const logs: LogLine[] | undefined = await get(`/api/apps/${name}/logs`)
|
||||||
|
if (!logs) {
|
||||||
|
console.error(`App not found: ${name}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (logs.length === 0) {
|
||||||
|
console.log('No logs yet')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for (const line of logs) {
|
||||||
|
const time = new Date(line.time).toLocaleTimeString()
|
||||||
|
console.log(`${time} ${line.text}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function openApp(name: string) {
|
async function openApp(name: string) {
|
||||||
const app: App | undefined = await get(`/api/apps/${name}`)
|
const app: App | undefined = await get(`/api/apps/${name}`)
|
||||||
if (!app) {
|
if (!app) {
|
||||||
|
|
@ -99,6 +115,17 @@ program
|
||||||
.argument('<name>', 'app name')
|
.argument('<name>', 'app name')
|
||||||
.action(restartApp)
|
.action(restartApp)
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('logs')
|
||||||
|
.description('Show logs for an app')
|
||||||
|
.argument('<name>', 'app name')
|
||||||
|
.action(logApp)
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('log', { hidden: true })
|
||||||
|
.argument('<name>', 'app name')
|
||||||
|
.action(logApp)
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('open')
|
.command('open')
|
||||||
.description('Open an app in browser')
|
.description('Open an app in browser')
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,16 @@ app.get('/api/apps/:app', c => {
|
||||||
return c.json(convert(app))
|
return c.json(convert(app))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/api/apps/:app/logs', c => {
|
||||||
|
const appName = c.req.param('app')
|
||||||
|
if (!appName) return c.json({ error: 'App not found' }, 404)
|
||||||
|
|
||||||
|
const app = allApps().find(a => a.name === appName)
|
||||||
|
if (!app) return c.json({ error: 'App not found' }, 404)
|
||||||
|
|
||||||
|
return c.json(app.logs ?? [])
|
||||||
|
})
|
||||||
|
|
||||||
app.post('/api/apps/:app/start', c => {
|
app.post('/api/apps/:app/start', c => {
|
||||||
const appName = c.req.param('app')
|
const appName = c.req.param('app')
|
||||||
if (!appName) return c.json({ error: 'App not found' }, 404)
|
if (!appName) return c.json({ error: 'App not found' }, 404)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user