Skip to content

Commit

Permalink
:electron: Separate build folders for easier switching between web and electron (
Browse files Browse the repository at this point in the history
actualbudget#3801)

* seperate build folders for easier switching between web and electron builds

* gitignore

* release notes

* one directory back from electron

* spelling mistake

* Update 3801.md

* test

* making it correct

* huh

* urghh

* again

* account for api bundle which uses electron bundle for some reason

* hu-

* lets go

* remove comment
  • Loading branch information
MikesGlitch authored Nov 12, 2024
1 parent d132440 commit 1e1092e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bin/package-electron
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fi

yarn workspace loot-core build:node

yarn workspace @actual-app/web build --mode=desktop
yarn workspace @actual-app/web build --mode=desktop # electron specific build

yarn workspace desktop-electron update-client

Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ playwright-report

# production
build
build-electron
build-stats
stats.json

Expand Down
6 changes: 3 additions & 3 deletions packages/desktop-client/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const addWatchers = (): Plugin => ({
configureServer(server) {
server.watcher
.add([
path.resolve('../loot-core/lib-dist/*.js'),
path.resolve('../loot-core/lib-dist/electron/*.js'),
path.resolve('../loot-core/lib-dist/browser/*.js'),
])
.on('all', function () {
Expand Down Expand Up @@ -109,7 +109,7 @@ export default defineConfig(async ({ mode }) => {
build: {
target: 'es2022',
sourcemap: true,
outDir: 'build',
outDir: mode === 'desktop' ? 'build-electron' : 'build',
assetsDir: 'static',
manifest: true,
assetsInlineLimit: 0,
Expand Down Expand Up @@ -148,7 +148,7 @@ export default defineConfig(async ({ mode }) => {
extensions: resolveExtensions,
},
plugins: [
// Macos electron (desktop) builds do not support PWA
// electron (desktop) builds do not support PWA
mode === 'desktop'
? undefined
: VitePWA({
Expand Down
7 changes: 3 additions & 4 deletions packages/desktop-electron/bin/update-client
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ROOT=`dirname $0`/..

rm -rf ${ROOT}/build
mkdir -p ${ROOT}/build
cp -r ${ROOT}/../desktop-client/build ${ROOT}/build/client-build
cp -r ${ROOT}/../desktop-client/build-electron ${ROOT}/build/client-build

# Remove the embedded backend for the browser version. Will improve
# this process
Expand All @@ -14,9 +14,8 @@ rm -rf ${ROOT}/build/client-build/*.wasm
rm -rf ${ROOT}/build/client-build/*.map

# Copy loot-core into build directory
mkdir -p ${ROOT}/build/loot-core/lib-dist
ls ${ROOT}/build/loot-core/lib-dist
cp ${ROOT}/../loot-core/lib-dist/bundle.desktop.js ${ROOT}/build/loot-core/lib-dist/bundle.desktop.js
mkdir -p ${ROOT}/build/loot-core/lib-dist/electron
cp ${ROOT}/../loot-core/lib-dist/electron/bundle.desktop.js ${ROOT}/build/loot-core/lib-dist/electron/bundle.desktop.js
cp ${ROOT}/../loot-core/default-db.sqlite ${ROOT}/build/loot-core/default-db.sqlite
cp -r ${ROOT}/../loot-core/migrations ${ROOT}/build/loot-core/migrations

4 changes: 2 additions & 2 deletions packages/desktop-electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import './security';
const isDev = !app.isPackaged; // dev mode if not packaged

process.env.lootCoreScript = isDev
? 'loot-core/lib-dist/bundle.desktop.js' // serve from local output in development (provides hot-reloading)
: path.resolve(__dirname, 'loot-core/lib-dist/bundle.desktop.js'); // serve from build in production
? 'loot-core/lib-dist/electron/bundle.desktop.js' // serve from local output in development (provides hot-reloading)
: path.resolve(__dirname, 'loot-core/lib-dist/electron/bundle.desktop.js'); // serve from build in production

// This allows relative URLs to be resolved to app:// which makes
// local assets load correctly
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"!**/*.js.map",
"!**/stats.json",
"!build/client-build/sql-wasm.wasm",
"!build/loot-core/lib-dist/{browser,bundle.mobile*}"
"!build/loot-core/lib-dist/electron/{browser,bundle.mobile*}"
],
"beforePack": "./build/beforePackHook.js",
"mac": {
Expand Down
13 changes: 9 additions & 4 deletions packages/loot-core/src/platform/server/fs/index.electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ export { getDocumentDir, getBudgetDir, _setDocumentDir } from './shared';

let rootPath = path.join(__dirname, '..', '..', '..', '..');

if (__filename.match('bundle')) {
// The file name is not our filename and indicates that we're in the
// bundled form. Because of this, the root path is different.
rootPath = path.join(__dirname, '..');
switch (path.basename(__filename)) {
case 'bundle.api.js': // api bundle uses the electron bundle - account for its file structure
rootPath = path.join(__dirname, '..');
break;
case 'bundle.desktop.js': // electron app
rootPath = path.join(__dirname, '..', '..');
break;
default:
break;
}

export const init = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/webpack/webpack.desktop.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
target: 'node',
devtool: 'source-map',
output: {
path: path.resolve(path.join(__dirname, '/../lib-dist')),
path: path.resolve(path.join(__dirname, '/../lib-dist/electron')),
filename: 'bundle.desktop.js',
sourceMapFilename: 'bundle.desktop.js.map',
libraryTarget: 'commonjs2',
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3801.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MikesGlitch]
---

Update build folder structure to allow separation of web and electron builds

0 comments on commit 1e1092e

Please sign in to comment.