I have made a Electron Application, mainly for my helpdesk colleagues at work.
What it does (Context):
It provides a simple gui with different "Tasks" it can do. Example:
For this I'm using a combination of:
- Node with Electron
- React
- Node-Powershell
The Problem:
The app when I run it in Development Mode is running as it should. But after I build and package it with electron, the NPM package node-powershell can't find the .ps1 scripts anymore.
I think I already identified the problem, but I don't know what the solution to this problem is.
node-powershell needs a path to a script and an array of commands.
I have set it up like this:
const p1 = require('path').resolve();
const scriptPath = require('path').join(p1, 'src/PowershellScripts/AddMailboxPermissions.ps1');
And then ps.addCommand(scriptPath, commands); (node-powershell)
As said before this works fine in development mode with a webpack server, but when run after packaging I get this error:
C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64\src\PowershellScripts\GetRemoteMac.ps1 cannot be found.
The reason is because the packaging has following structure. The .ps1 files now have following path:
C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64\resources\app\src\PowershellScripts
So this is the main issue. How do I package this "the right way" so that it's actually working afterwards.
Infos:
- I run this on a windows 10 x64 machine
- package.json scripts:
"dev": "webpack-dev-server --hot --host 0.0.0.0 --config=./webpack.dev.config.js", "build": "webpack --config webpack.build.config.js", "package": "webpack --config webpack.build.config.js",
- When I run it in dev mode it resolves the correct path and everything is working just fine
I hope someone of you can help me or guide me into the right direction.
Possible Idea:
Reference a completely other path and copy the ps1 files into another directory with a gulp task? Never used it. Could this be a possible solution? If yes how to best approach this?
Update
When I copy the src folder from C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64\resources\app into the root C:\Users\Huberdo\Projekte\Powershell-SAS-App\Client\builds\basic-electron-react-boilerplate-win32-x64 it's working again. So it's mainly a path issue and I don't know how to solve it.
Last but not least a direct link to the project on github:
https://github.com/dhuber666/Powershell-SAS-Tool
Here I call the ps1 script:
!Thank you!
