-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from aakritiawasthi/issue/33/patch
- Loading branch information
Showing
5 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ChildProcess } from 'child_process'; | ||
import { rmSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
import { Request, Response } from 'express'; | ||
|
||
import { allApplications, cps, deleteBody } from '../constants'; | ||
import { appsDirectory } from '../utils/config'; | ||
import { deleteStatusMessage } from '../utils/resposeTexts'; | ||
|
||
export default ( | ||
Check warning on line 11 in src/controller/delete.ts
|
||
req: Omit<Request, 'body'> & { body: deleteBody }, | ||
res: Response | ||
) => { | ||
// Extract the suffix (application name) of the application from the request body | ||
const { suffix: app } = req.body; | ||
|
||
// Initialize isError flag | ||
let isError = false; | ||
|
||
// Check if the application exists in cps and allApplications objects | ||
if (!(app in cps && app in allApplications)) { | ||
isError = true; | ||
} | ||
|
||
// Retrieve the child process associated with the application and kill it | ||
const appCP: ChildProcess = cps[app]; | ||
appCP.kill(); | ||
|
||
// Remove the application from cps and allApplications objects | ||
delete cps[app]; | ||
delete allApplications[app]; | ||
|
||
// Determine the location of the application | ||
const appLocation = join(appsDirectory(), app); | ||
|
||
// Delete the directory of the application | ||
rmSync(appLocation, { recursive: true, force: true }); | ||
|
||
// Send response based on whether there was an error during deletion | ||
return res.send( | ||
isError | ||
? deleteStatusMessage(app)['error'] | ||
: deleteStatusMessage(app)['success'] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const deleteStatusMessage = ( | ||
app: string | ||
): { | ||
success: string; | ||
error: string; | ||
} => ({ | ||
success: 'Deploy Delete Succeed', | ||
error: `Oops! It looks like the application (${app}) hasn't been deployed yet. Please deploy it before you delete it.` | ||
}); |