feat: correctly show whether a project has been deployed

This commit is contained in:
James Murdza
2024-12-01 11:14:25 -08:00
parent 0d0eed34b2
commit ee51ae7a33
5 changed files with 110 additions and 17 deletions

View File

@ -31,9 +31,30 @@ export class DokkuClient extends SSHSocketClient {
// List all deployed Dokku apps
async listApps(): Promise<string[]> {
const response = await this.sendCommand("apps:list")
// Split the output by newline and remove the header
return response.output.split("\n").slice(1)
const response = await this.sendCommand("--quiet apps:list")
return response.output.split("\n")
}
// Get the creation timestamp of an app
async getAppCreatedAt(appName: string): Promise<number> {
const response = await this.sendCommand(
`apps:report --app-created-at ${appName}`
)
const createdAt = parseInt(response.output.trim(), 10)
if (isNaN(createdAt)) {
throw new Error(
`Failed to retrieve creation timestamp for app ${appName}`
)
}
return createdAt
}
// Check if an app exists
async appExists(appName: string): Promise<boolean> {
const response = await this.sendCommand(`apps:exists ${appName}`)
return response.output.includes("App") === false
}
}

View File

@ -156,6 +156,28 @@ export class Sandbox {
return { success: true, apps: await this.dokkuClient.listApps() }
}
// Handle getting app creation timestamp
const handleGetAppCreatedAt: SocketHandler = async ({ appName }) => {
if (!this.dokkuClient)
throw new Error(
"Failed to retrieve app creation timestamp: No Dokku client"
)
return {
success: true,
createdAt: await this.dokkuClient.getAppCreatedAt(appName),
}
}
// Handle checking if an app exists
const handleAppExists: SocketHandler = async ({ appName }) => {
if (!this.dokkuClient)
throw new Error("Failed to check app existence: No Dokku client")
return {
success: true,
exists: await this.dokkuClient.appExists(appName),
}
}
// Handle deploying code
const handleDeploy: SocketHandler = async (_: any) => {
if (!this.gitClient) throw Error("No git client")
@ -253,7 +275,9 @@ export class Sandbox {
getFolder: handleGetFolder,
saveFile: handleSaveFile,
moveFile: handleMoveFile,
list: handleListApps,
listApps: handleListApps,
getAppCreatedAt: handleGetAppCreatedAt,
getAppExists: handleAppExists,
deploy: handleDeploy,
createFile: handleCreateFile,
createFolder: handleCreateFolder,

View File

@ -146,6 +146,8 @@ io.on("connection", async (socket) => {
)
})
socket.emit("ready")
// Handle disconnection event
socket.on("disconnect", async () => {
try {