Skip to content

Commit df616fd

Browse files
committed
build: src-node injection in elelectron dev stage
1 parent 194cac1 commit df616fd

File tree

6 files changed

+68
-9
lines changed

6 files changed

+68
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ phoenix
2121

2222
# Electron things
2323
src-electron/bin
24+
src-electron/src-node
2425

2526
node_modules
2627
dist

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,19 @@
1919
"releaseDistDebug": "npm run _make_src-node && npm run _createDistReleaseConfig && tauri build --config ./src-tauri/tauri-local.conf.json --debug --verbose",
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",
22-
"_src-node_npm_install": "cd src-tauri/src-node && npm ci --production && cd ../../ && npm run _src-node_remove_unsupported_bin",
23-
"_src-node_remove_unsupported_bin": "shx rm -f src-tauri/src-node/node_modules/@msgpackr-extract/msgpackr-extract-linux-*/*.musl.node src-tauri/src-node/node_modules/@lmdb/lmdb-linux-*/*.musl.node",
24-
"_make_src-node": "shx rm -rf src-tauri/src-node && shx cp -r ../phoenix/src-node src-tauri/src-node && npm run _src-node_npm_install",
25-
"_make_src-node_debug_dev": "npm run _make_src-node && shx rm -rf src-tauri/target/debug/src-node && shx cp -r src-tauri/src-node src-tauri/target/debug/src-node",
26-
"_ci_make_src-node": "shx rm -rf src-tauri/src-node && shx cp -r phoenix/src-node src-tauri/src-node && npm run _src-node_npm_install",
22+
"_make_src-node": "node ./src-build/makeSrcNode.js ../phoenix/src-node",
23+
"_ci_make_src-node": "node ./src-build/makeSrcNode.js phoenix/src-node",
2724
"_servePhoenix": "echo -e \"\nEnsure to start phoenix server at http://localhost:8000 for development.\n Follow https://github.com/phcode-dev/phoenix#running-phoenix for instructions.\"",
2825
"_ci-clonePhoenixForTests": "npm run _ci-env-warn && node ./src-build/clonePhoenixForTests.js",
2926
"_ci-cloneAndBuildPhoenix": "npm run _ci-env-warn && node ./src-build/clonePhoenix.js && cd phoenix && npm ci && npm run build && cd ..",
3027
"_ci-release:dev": "npm run _ci-env-warn && npm run _ci-cloneAndBuildPhoenix && cd phoenix && npm run release:dev && cd .. && npm run _ci-createDistReleaseConfig && npm run _ci_make_src-node",
3128
"_ci-release:staging": "npm run _ci-env-warn && npm run _ci-cloneAndBuildPhoenix && cd phoenix && npm run release:staging && cd .. && npm run _ci-createDistReleaseConfig && npm run _ci_make_src-node",
3229
"_ci-release:prod": "npm run _ci-env-warn && npm run _ci-cloneAndBuildPhoenix && cd phoenix && npm run release:prod && cd .. && npm run _ci-createDistReleaseConfig && npm run _ci_make_src-node",
3330
"_ci-update-phcode-build": "node src-build/update-phcode-build.js",
34-
"_watch_src-node": "chokidar '../phoenix/src-node/**/*' --ignore '../phoenix/src-node/node_modules/**/*' -c 'npm run _make_src-node_debug_dev'",
3531
"serve": "node src-build/serveForPlatform.js",
3632
"_serveTauri": "npm run _servePhoenix && npm run _make_src-node && tauri dev",
3733
"_serveElectron": "npm run _servePhoenix && npm run _make_src-node && ./src-electron/node_modules/.bin/electron src-electron/main.js",
38-
"postinstall": "node ./src-build/downloadNodeBinary.js",
34+
"postinstall": "node ./src-build/downloadNodeBinary.js && node ./src-build/setupElectron.js",
3935
"cleanNodeBinary": "node src-build/cleanNodeBinary.js",
4036
"installNodeArmDarwin": "node ./src-build/downloadNodeBinary.js '{\"platform\":\"darwin\",\"arch\":\"arm64\"}'",
4137
"getPackageVersion": "node ./src-build/getVersion.js"

src-build/makeSrcNode.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { execSync } from 'child_process';
2+
import { fileURLToPath } from 'url';
3+
import { dirname, join } from 'path';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
8+
// Get source path from command line argument
9+
const srcNodeSource = process.argv[2];
10+
if (!srcNodeSource) {
11+
console.error('Usage: node makeSrcNode.js <src-node-path>');
12+
console.error('Example: node makeSrcNode.js ../phoenix/src-node');
13+
process.exit(1);
14+
}
15+
16+
const targets = [
17+
join(__dirname, '..', 'src-tauri', 'src-node'),
18+
join(__dirname, '..', 'src-electron', 'src-node')
19+
];
20+
21+
function setupTarget(srcPath, destPath) {
22+
console.log(`\nSetting up ${destPath}...`);
23+
24+
// Remove existing and copy from source
25+
execSync(`shx rm -rf ${destPath}`, { stdio: 'inherit' });
26+
execSync(`shx cp -r ${srcPath} ${destPath}`, { stdio: 'inherit' });
27+
28+
// Install production dependencies
29+
console.log('Installing production dependencies...');
30+
execSync('npm ci --production', { cwd: destPath, stdio: 'inherit' });
31+
32+
// Remove unsupported musl binaries
33+
console.log('Removing unsupported musl binaries...');
34+
execSync(`shx rm -f ${destPath}/node_modules/@msgpackr-extract/msgpackr-extract-linux-*/*.musl.node`, { stdio: 'pipe' });
35+
execSync(`shx rm -f ${destPath}/node_modules/@lmdb/lmdb-linux-*/*.musl.node`, { stdio: 'pipe' });
36+
37+
console.log(`${destPath} setup complete!`);
38+
}
39+
40+
function main() {
41+
const absoluteSrc = join(process.cwd(), srcNodeSource);
42+
43+
for (const target of targets) {
44+
setupTarget(absoluteSrc, target);
45+
}
46+
47+
console.log('\nAll targets setup successfully!');
48+
}
49+
50+
main();

src-build/setupElectron.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { execSync } from 'child_process';
2+
import { fileURLToPath } from 'url';
3+
import { dirname, join } from 'path';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
8+
const electronDir = join(__dirname, '..', 'src-electron');
9+
10+
console.log('Installing src-electron dependencies...');
11+
execSync('npm ci', { cwd: electronDir, stdio: 'inherit' });
12+
console.log('src-electron dependencies installed successfully!');

src-tauri/tauri.conf.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
33
"build": {
44
"beforeBuildCommand": "",
5-
"beforeDevCommand": "npm run _watch_src-node",
65
"devPath": "http://localhost:8000/src/",
76
"distDir": "../src/",
87
"withGlobalTauri": true
@@ -484,4 +483,4 @@
484483
}
485484
]
486485
}
487-
}
486+
}

0 commit comments

Comments
 (0)