From ed496c37dc4fec109463179d183f833a775abfa4 Mon Sep 17 00:00:00 2001 From: sauravniraula Date: Sun, 11 May 2025 06:41:58 +0545 Subject: [PATCH] Adds: Electron Builder setup --- .gitignore | 2 ++ app/main.ts | 10 ++++------ app/servers.ts | 2 +- build.js | 20 ++++++++++++++++++++ package.json | 14 +++++++++----- tsconfig.json | 2 +- 6 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 build.js diff --git a/.gitignore b/.gitignore index 2eff22f1..8017ee0e 100644 --- a/.gitignore +++ b/.gitignore @@ -176,6 +176,8 @@ dist # Finder (MacOS) folder config .DS_Store +app_dist + env .venv __pycache__ diff --git a/app/main.ts b/app/main.ts index 6da4995b..21ebe2ff 100644 --- a/app/main.ts +++ b/app/main.ts @@ -7,10 +7,9 @@ import { ChildProcessByStdio } from "child_process"; import { localhost } from "./constants"; var isDev = !app.isPackaged; -var baseDir = isDev ? process.cwd() : process.resourcesPath; -var resourcesDir = path.join(baseDir, "resources"); -var fastapiDir = isDev ? path.join(baseDir, "servers/fastapi") : path.join(resourcesDir, "fastapi"); -var nextjsDir = isDev ? path.join(baseDir, "servers/nextjs") : path.join(resourcesDir, "nextjs"); +var baseDir = app.getAppPath(); +var fastapiDir = isDev ? path.join(baseDir, "servers/fastapi") : path.join(baseDir, "resources/fastapi"); +var nextjsDir = isDev ? path.join(baseDir, "servers/nextjs") : path.join(baseDir, "resources/nextjs"); var tempDir = app.getPath("temp"); var dataDir = app.getPath("userData"); @@ -74,8 +73,7 @@ async function stopServers() { app.whenReady().then(async () => { createWindow(); - win?.loadFile(path.join(resourcesDir, "ui/homepage/index.html")); - + win?.loadFile(path.join(baseDir, "resources/ui/homepage/index.html")); win?.webContents.openDevTools(); createUserConfig(app, { diff --git a/app/servers.ts b/app/servers.ts index e57d2c26..74c46e81 100644 --- a/app/servers.ts +++ b/app/servers.ts @@ -51,7 +51,7 @@ export async function startNextJsServer( ["run", "dev", "--", "-p", port.toString()], ] : [ "npx", - ["next", "start", "--", "-p", port.toString()], + ["next", "start", "-p", port.toString()], ]; diff --git a/build.js b/build.js new file mode 100644 index 00000000..d2b2d8c9 --- /dev/null +++ b/build.js @@ -0,0 +1,20 @@ +const builder = require("electron-builder") + +const config = { + appId: "ai.presenton", + asar: false, + directories: { + output: "dist", + }, + files: [ + "resources", + "app_dist", + "node_modules", + ], + linux: { + target: ["AppImage"], + }, +} + + +builder.build({ config }) \ No newline at end of file diff --git a/package.json b/package.json index 8c538dc2..2357eb2b 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,26 @@ { "name": "presenton_open_source", - "main": "dist/main.js", + "main": "app_dist/main.js", "version": "0.0.0", "description": "Presenton Open Source", + "homepage": "https://presenton.ai", + "author": { + "name": "Presenton", + "email": "contact@presenton.ai" + }, "scripts": { "dev": "tsc && electron --gtk-version=3 .", - "start": "tsc && electron-forge start", - "package": "tsc && electron-forge package", - "make": "tsc && electron-forge make", "setup:env": "npm install && cd servers/fastapi && poetry install && cd ../../servers/nextjs && npm install", "build:ts": "tsc", "build:css": "tailwindcss -i ./resources/ui/assets/tailwind.import.css -o ./resources/ui/assets/tailwind.css", - "build:nextjs": "rm -rf resources/nextjs && mkdir -p resources/nextjs && cd servers/nextjs && npm run build && cp -r .next ../../resources/nextjs", + "build:nextjs": "rm -rf resources/nextjs && cp -r servers/nextjs resources/nextjs && cd resources/nextjs && npm install && npm run build", "build:fastapi": "rm -rf resources/fastapi && cd servers/fastapi && .venv/bin/pyinstaller --name fastapi --distpath ../../resources server.py", + "build:electron": "tsc && node build.js", "clean:build": "rm -rf resources/nextjs && rm -rf resources/fastapi" }, "devDependencies": { "electron": "^36.1.0", + "electron-builder": "^26.0.12", "typescript": "^5.8.3" }, "peerDependencies": { diff --git a/tsconfig.json b/tsconfig.json index 5424fe01..b77b1d36 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -54,7 +54,7 @@ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ // "noEmit": true, /* Disable emitting files from a compilation. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - "outDir": "./dist", /* Specify an output folder for all emitted files. */ + "outDir": "./app_dist", /* Specify an output folder for all emitted files. */ // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */