Skip to content

Commit 964210b

Browse files
committed
build: linux electron app image dev builds generation
1 parent bced3d5 commit 964210b

7 files changed

Lines changed: 3328 additions & 247 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ phoenix
2323
src-electron/bin
2424
src-electron/src-node
2525
src-electron/config-effective.json
26+
src-electron/dist
2627

2728
node_modules
2829
dist

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"releaseDistTest": "npm run _make_src-node && npm run _createDistTestReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json",
2121
"releaseDistTestDebug": "npm run _make_src-node && npm run _createDistTestReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json --debug",
2222
"_make_src-node": "node ./src-build/makeSrcNode.js ../phoenix/src-node",
23+
"build:electron": "npm run _make_src-node && cd src-electron && npm run build:appimage",
2324
"_ci_make_src-node": "node ./src-build/makeSrcNode.js phoenix/src-node",
2425
"_ci-clonePhoenixForTests": "npm run _ci-env-warn && node ./src-build/clonePhoenixForTests.js",
2526
"_ci-cloneAndBuildPhoenix": "npm run _ci-env-warn && node ./src-build/clonePhoenix.js && cd phoenix && npm ci && npm run build && cd ..",

src-build/setupElectron.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ const __dirname = dirname(__filename);
88

99
const electronDir = join(__dirname, '..', 'src-electron');
1010

11-
console.log('Installing src-electron dependencies...');
12-
execSync('npm ci', { cwd: electronDir, stdio: 'inherit' });
11+
// Use the same npm command that was used at root level (npm install vs npm ci)
12+
const npmCommand = process.env.npm_command === 'install' ? 'npm install' : 'npm ci';
13+
console.log(`Installing src-electron dependencies with ${npmCommand}...`);
14+
execSync(npmCommand, { cwd: electronDir, stdio: 'inherit' });
1315
console.log('src-electron dependencies installed successfully!');
1416

1517
// Copy config.json to config-effective.json (dev config by default)

src-electron/electron-builder.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
appId: io.phcode.dev
2+
productName: Phoenix Code
3+
copyright: Copyright © 2024 phcode.dev
4+
5+
asar: true
6+
7+
linux:
8+
target:
9+
- AppImage
10+
category: Development
11+
icon: ../src-tauri/icons
12+
13+
files:
14+
- "**/*"
15+
- "!dist/**"
16+
- "!src-node/**"
17+
- "!bin/**"
18+
19+
asarUnpack:
20+
- "node_modules/keytar/**"
21+
22+
extraResources:
23+
- from: "src-node"
24+
to: "src-node"
25+
- from: "bin"
26+
to: "bin"
27+
28+
extraMetadata:
29+
main: main.js

src-electron/main.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ const gotTheLock = app.requestSingleInstanceLock();
1616
if (!gotTheLock) {
1717
// Another instance is running, quit this one immediately
1818
app.quit();
19+
// Return value is ignored but this stops further module execution
20+
return;
21+
}
22+
23+
function getPhNodePath() {
24+
if (!app.isPackaged) {
25+
return path.resolve(__dirname, 'bin', 'phnode');
26+
}
27+
// extraResources places files directly in resources/
28+
return path.join(process.resourcesPath, 'bin', 'phnode');
29+
}
30+
31+
function getSrcNodePath() {
32+
if (!app.isPackaged) {
33+
// Dev: use phoenix repo's src-node
34+
return path.resolve(__dirname, '..', '..', 'phoenix', 'src-node');
35+
}
36+
// extraResources places files directly in resources/
37+
return path.join(process.resourcesPath, 'src-node');
1938
}
2039

2140
// In-memory key-value store shared across all windows (mirrors Tauri's put_item/get_all_items)
@@ -126,17 +145,17 @@ ipcMain.handle('toggle-dev-tools', (event) => {
126145
// Get path to phnode binary
127146
ipcMain.handle('get-phnode-path', (event) => {
128147
assertTrusted(event);
129-
const phNodePath = path.resolve(__dirname, 'bin', 'phnode');
148+
const phNodePath = getPhNodePath();
130149
if (!fs.existsSync(phNodePath)) {
131150
throw new Error(`phnode binary does not exist: ${phNodePath}`);
132151
}
133152
return phNodePath;
134153
});
135154

136-
// Get path to src-node (for development)
155+
// Get path to src-node
137156
ipcMain.handle('get-src-node-path', (event) => {
138157
assertTrusted(event);
139-
const srcNodePath = path.resolve(__dirname, '..', '..', 'phoenix', 'src-node');
158+
const srcNodePath = getSrcNodePath();
140159
if (!fs.existsSync(srcNodePath)) {
141160
throw new Error(`src-node path does not exist: ${srcNodePath}`);
142161
}

0 commit comments

Comments
 (0)