From 221bf645b3a866c3c6711e641a6aede1fd08293c Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Tue, 13 Aug 2024 03:29:02 +0600 Subject: [PATCH] Add (#3971) * Add * Add * Phase 1 * Add * Add --- seeder/electron.vite.config.ts | 8 +++++--- seeder/src/main/constants/os.ts | 8 +++----- seeder/src/main/index.ts | 6 +++--- seeder/src/main/interfaces/shiinobi.ts | 2 +- seeder/src/main/workers/express_worker.ts | 16 ++++++++++++++++ seeder/tsconfig.node.json | 9 ++++++--- 6 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 seeder/src/main/workers/express_worker.ts diff --git a/seeder/electron.vite.config.ts b/seeder/electron.vite.config.ts index 9fc060cf9b..ad25fdd813 100644 --- a/seeder/electron.vite.config.ts +++ b/seeder/electron.vite.config.ts @@ -19,9 +19,11 @@ export default defineConfig({ }, resolve: { alias: { - "@main": resolve(__dirname, "./src/main"), - "@constants": resolve(__dirname, "./src/main/constants"), - "@interfaces": resolve(__dirname, "./src/main/interfaces") + $constants: resolve(__dirname, "./src/main/constants"), + $interfaces: resolve(__dirname, "./src/main/interfaces"), + $backend: resolve(__dirname, "./src/main/backend"), + $worker: resolve(__dirname, "./src/main/workers"), + $utils: resolve(__dirname, "./src/main/utils") } } }, diff --git a/seeder/src/main/constants/os.ts b/seeder/src/main/constants/os.ts index 3bcdc4e82b..63976eef71 100644 --- a/seeder/src/main/constants/os.ts +++ b/seeder/src/main/constants/os.ts @@ -1,5 +1,3 @@ -const IS_MAC = process.platform === "darwin"; -const IS_WINDOWS = process.platform === "win32"; -const IS_LINUX = process.platform === "linux"; - -export { IS_MAC, IS_WINDOWS, IS_LINUX }; +export const IS_MAC = process.platform === "darwin"; +export const IS_WINDOWS = process.platform === "win32"; +export const IS_LINUX = process.platform === "linux"; diff --git a/seeder/src/main/index.ts b/seeder/src/main/index.ts index 4d9d0a6ce7..46d9bfe8f0 100644 --- a/seeder/src/main/index.ts +++ b/seeder/src/main/index.ts @@ -2,9 +2,9 @@ import { app, shell, BrowserWindow, ipcMain } from "electron"; import { join } from "path"; import { electronApp, optimizer, is } from "@electron-toolkit/utils"; import icon from "../../resources/icon.png?asset"; -import { Shiinobi as _Shiinobi } from "@interfaces/shiinobi"; -import { get_free_port } from "./utils/port"; -import ExpressWorder from "./worker/express_worker?nodeWorker"; +import { Shiinobi as _Shiinobi } from "$interfaces/shiinobi"; +import { get_free_port } from "$utils/port"; +import ExpressWorder from "$worker/express_worker?nodeWorker"; const Shiinobi = new _Shiinobi(); diff --git a/seeder/src/main/interfaces/shiinobi.ts b/seeder/src/main/interfaces/shiinobi.ts index deca61f54a..6ea62e58d7 100644 --- a/seeder/src/main/interfaces/shiinobi.ts +++ b/seeder/src/main/interfaces/shiinobi.ts @@ -1,5 +1,5 @@ import { spawn } from "child_process"; -import { IS_LINUX, IS_MAC, IS_WINDOWS } from "@constants/os"; +import { IS_LINUX, IS_MAC, IS_WINDOWS } from "$constants/os"; import { join } from "path"; type _COMMANDS = diff --git a/seeder/src/main/workers/express_worker.ts b/seeder/src/main/workers/express_worker.ts new file mode 100644 index 0000000000..d95ad477d0 --- /dev/null +++ b/seeder/src/main/workers/express_worker.ts @@ -0,0 +1,16 @@ +import { parentPort, workerData } from "node:worker_threads"; +import { app } from "$backend/index"; + +const port = parentPort; +if (!port) throw new Error("IllegalState"); + +port.on("message", () => { + const _port = workerData.port; + try { + app.listen(_port, () => { + port.postMessage(`Listening on ${_port}`); + }); + } catch (err) { + port.postMessage(`Couldnot launch express.js, reason ${err}`); + } +}); diff --git a/seeder/tsconfig.node.json b/seeder/tsconfig.node.json index 9b3bdc2346..da3efd161c 100644 --- a/seeder/tsconfig.node.json +++ b/seeder/tsconfig.node.json @@ -5,9 +5,12 @@ "composite": true, "types": ["electron-vite/node"], "paths": { - "@main/*": ["./src/main/*"], - "@constants/*": ["./src/main/constants/*"], - "@interfaces/*": ["./src/main/interfaces/*"], + "$main/*": ["./src/main/*"], + "$constants/*": ["./src/main/constants/*"], + "$interfaces/*": ["./src/main/interfaces/*"], + "$workers/*":["./src/main/workers/*"], + "$backend/*":["./src/main/backend/*"], + "$utils/*":["./src/main/utils/*"], } } }