-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deploy delete implementation done #37
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { spawn } from 'child_process'; | ||
import colors from 'colors'; | ||
import { NextFunction, Request, Response } from 'express'; | ||
import * as fs from 'fs'; | ||
import { hostname } from 'os'; | ||
import * as path from 'path'; | ||
|
||
|
@@ -11,6 +12,7 @@ import { | |
childProcessResponse, | ||
cps, | ||
currentFile, | ||
deleteBody, | ||
deployBody, | ||
fetchBranchListBody, | ||
fetchFilesFromRepoBody, | ||
|
@@ -253,6 +255,34 @@ export const showLogs = (req: Request, res: Response): Response => { | |
return res.send('Demo Logs...'); | ||
}; | ||
|
||
export const deployDelete = ( | ||
req: Omit<Request, 'body'> & { body: deleteBody }, | ||
res: Response, | ||
next: NextFunction | ||
): void => { | ||
const { suffix: appName } = req.body; | ||
|
||
try { | ||
if (cps[appName]) { | ||
cps[appName].kill(); | ||
delete cps[appName]; | ||
} | ||
|
||
const appPath = path.join(appsDir, appName); | ||
|
||
if (fs.existsSync(appPath)) { | ||
fs.rmdirSync(appPath, { recursive: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recursive: true will not work with higher node versions such as node:18x, it will be ignored as its deprecated, use the correct thing. |
||
} | ||
delete allApplications[appName]; | ||
|
||
res.send(`Deleting ${appName} deploy Succeed`); | ||
} catch (error) { | ||
next( | ||
new AppError('error occurred in deleting repository directory', 500) | ||
); | ||
} | ||
}; | ||
|
||
export const validateAndDeployEnabled = ( | ||
req: Request, | ||
res: Response | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,3 +108,7 @@ export interface childProcessResponse { | |
type: keyof typeof protocol; | ||
data: unknown; | ||
} | ||
|
||
export interface deleteBody { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incomplete schema of delete payload. |
||
suffix: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?