How do I reference my powershell scripts in my electron application after building and packaging?

Multi tool use
Multi tool use


How do I reference my powershell scripts in my electron application after building and packaging?



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:



enter image description here



For this I'm using a combination of:



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:


node-powershell


.ps1


node-powershell


const p1 = require('path').resolve();
const scriptPath = require('path').join(p1, 'src/PowershellScripts/AddMailboxPermissions.ps1');



And then ps.addCommand(scriptPath, commands); (node-powershell)


ps.addCommand(scriptPath, commands);



As said before this works fine in development mode with a webpack server, but when run after packaging I get this error:



C:UsersHuberdoProjektePowershell-SAS-AppClientbuildsbasic-electron-react-boilerplate-win32-x64srcPowershellScriptsGetRemoteMac.ps1 cannot be found.



The reason is because the packaging has following structure. The .ps1 files now have following path:


.ps1



C:UsersHuberdoProjektePowershell-SAS-AppClientbuildsbasic-electron-react-boilerplate-win32-x64resourcesappsrcPowershellScripts



So this is the main issue. How do I package this "the right way" so that it's actually working afterwards.



Infos:


"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",



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:UsersHuberdoProjektePowershell-SAS-AppClientbuildsbasic-electron-react-boilerplate-win32-x64resourcesapp into the root C:UsersHuberdoProjektePowershell-SAS-AppClientbuildsbasic-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.


src


C:UsersHuberdoProjektePowershell-SAS-AppClientbuildsbasic-electron-react-boilerplate-win32-x64resourcesapp


C:UsersHuberdoProjektePowershell-SAS-AppClientbuildsbasic-electron-react-boilerplate-win32-x64



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:


ps1



https://github.com/dhuber666/Powershell-SAS-Tool/blob/SendAs/src/components/scriptsComponents/AddMailboxPermissions.js



!Thank you!




1 Answer
1



I am doing something similar, but the approach I am using for the PowerShell scripts is to create them as PowerShell modules. Then you can just place them in one of the valid PSModule location and you should be good to go. And you could just write a powershell script to copy you modules to the correct location and copy the package to the desktop or where ever it needs to be.





Thanks for your answer. It sounds interesting. Could please further explain how you are doing this? Do you have an example or something like that on github? Thx
– GeraltDieSocke
2 days ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

w 5dA,qV1f 9Gi537mNQFeiKmY,Z,8l8t6H aI96rk p
BpDvpN681nttn5jEfihIfX

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications