I am trying to package a python binary executable with angular-electron on Linux. I have followed this answer from stack overflow. bundling precompiled binary into electron app.
In main.ts I have written this extra code snippet. I have placed executable binary in node_modules/datapod/datapod and also symlinked this path in node_modules/.bin/ folder.
const spawn = require('child_process').spawn;
var appRootDir = require('app-root-dir').get();
var datapodpath=appRootDir+'/node_modules/datapod/datapod';
console.log(datapodpath)
const datapod = spawn(datapodpath, [], {}); //add whatever switches you need here
datapod.stdout.on( 'data', data => {
console.log( `stdout: ${data}` );
});
datapod.stderr.on( 'data', data => {
console.log( `stderr: ${data}` );
})
datapod.on( 'close', code => {
console.log( `child process exited with code ${code}` );
})
Everything works great when i do
npm start
I can also see the logs for python application. When I do ,
npm run electron:linux
The application compiles successfully with the binary (Because the size of the compiled app with binary is exactly equal to the bare angular app + size of the binary). When i try to run this compiled application, It fails with the following error.
UPDATE:
I tried a different method and still no result. I have create a new folder externals/bin and copied the executable binary "datapod" in this folder. To copy this folder into the packaged app, added these lines to electron-builder.js
"files": [
"**/*",
"!**/*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!angular.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json",
"externals/bin"
],
Edited my code in main.ts file
const appPath = process.env.NODE_ENV === 'production' ? process.resourcesPath : __dirname;
const execPath =path.join(appPath, 'externals/bin/datapod');
console.log(execPath)
Compiles succesffully, when i tried to run this app, i got the same error. I unpacked the app in /tmp/.moun-angular***/resources/app.asar with
npx asar extract /tmp/.mount_angulaG6ARST/resources/app.asar extrractedApp
The contents of the folder does have externals/bin/datapod file but couldnt run.