Skip to content

Commit

Permalink
stuppoid
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonhochkins committed Jul 5, 2024
1 parent b8d88d7 commit c943c54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hakit/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Hakit",
"version": "1.0.30",
"version": "1.0.31",
"slug": "hakit",
"init": false,
"ingress": true,
Expand Down
27 changes: 14 additions & 13 deletions hakit/server/routes/remove-build.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { Request, Response } from 'express';
import { join } from 'path';
import { existsSync } from 'fs';
import { rm } from 'fs/promises'
import { APP_DIRECTORY } from '../constants.js';
import { translateError } from '../helpers/index.js';

export async function removeBuildDirectory() {
// remove the directory .next
const buildDir = join(APP_DIRECTORY, 'app', '.next');
await rm(buildDir, { recursive: true, force: true });
console.log('.next directory removed successfully');
}


export async function removeBuild(_req: Request, res: Response) {
const buildDir = join(APP_DIRECTORY, 'app', '.next');
const nextJsBuilt = existsSync(buildDir);
if (nextJsBuilt) {
// remove the directory .next
try {
await rm(buildDir, { recursive: true, force: true });
console.log('.next directory removed successfully');
return res.status(200).send('Directory removed successfully');
} catch (error) {
console.error('Error removing build directory:', translateError(error));
return res.status(500).send('Error removing build directory');
}
try {
await removeBuildDirectory();
console.log('.next directory removed successfully');
return res.status(200).send('Directory removed successfully');
} catch (error) {
console.error('Error removing build directory:', translateError(error));
return res.status(500).send('Error removing build directory');
}
};
3 changes: 2 additions & 1 deletion hakit/server/routes/run-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { APP_DIRECTORY, DEFAULT_HTML_FILE } from '../constants.js';
import { execSync } from 'child_process';
import { translateError } from '../helpers/index.js';
import { getAddonInfo } from '../helpers/get-addon-info.js';
import { removeBuildDirectory } from './remove-build.js';

let isAppRunning = false;

Expand Down Expand Up @@ -36,6 +37,7 @@ export async function runApplication(app: Express) {
} catch (error) {
isAppRunning = false;
console.error('Error starting Next.js server:', error);
await removeBuildDirectory();
throw error;
}
}
Expand All @@ -46,7 +48,6 @@ export async function runApplication(app: Express) {
// Start the Next.js server if the application is available
try {
await startApp();

} catch (error) {
console.error('Error starting Next.js server:', translateError(error));
throw error;
Expand Down

0 comments on commit c943c54

Please sign in to comment.