diff --git a/hakit/config.json b/hakit/config.json index 1147064..166effe 100644 --- a/hakit/config.json +++ b/hakit/config.json @@ -1,6 +1,6 @@ { "name": "Hakit", - "version": "1.0.30", + "version": "1.0.31", "slug": "hakit", "init": false, "ingress": true, diff --git a/hakit/server/routes/remove-build.ts b/hakit/server/routes/remove-build.ts index fece413..c91acea 100644 --- a/hakit/server/routes/remove-build.ts +++ b/hakit/server/routes/remove-build.ts @@ -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'); } }; \ No newline at end of file diff --git a/hakit/server/routes/run-application.ts b/hakit/server/routes/run-application.ts index 87a1296..a76a889 100644 --- a/hakit/server/routes/run-application.ts +++ b/hakit/server/routes/run-application.ts @@ -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; @@ -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; } } @@ -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;