-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage with webpack #49
Comments
PowerShell runs the external .ps1 files not node-powershell, and so I'm not sure exactly what you are using Webpack (dev server?) for but it shouldn't make a big difference. There is no need to import the external script because PowerShell runs it with no help from Javascript. Here is a simple example. Note that x could be anything and the params could be anything. You could be generating the PowerShell script dynamically or maybe you have a huge archive of them or you just have 1 script it doesn't matter because running external scripts is fundamental for PowerShell. #when I have an external PowerShell file psexample.ps1
param (
[Parameter (Mandatory=$False,Position=0)]
[String]$myParam
)
$out = "[{message: $($myParam)}]"
$out | convertto-JSON | Out-Host const shell = require('node-powershell');
let ps = new shell({
executionPolicy: 'Bypass',
noProfile: true
});
let x = "./psexample.ps1",
params = [{myParam: 'Banana'}]
ps.addCommand(x, params)
ps.invoke()
.then(output => {
console.log(output);
ps.dispose();
})
.catch(err => {
console.log(err);
ps.dispose();
}); This will result in:
|
For complex scripting I reccomend you write out the parameters yourself using template literals and pass it as a single string. let scriptY = "./psexample.ps1",
paramX = "banana"
ps.addCommand(`${scriptY} -myParam '${paramX}' )
ps.invoke() |
Hey thanks for the quick reply. Sorry I realized i'd made some spelling mistakes in the original question. So I'm using your plugin within Electron and would like to be able to package the powershell scripts within the application its self. Currently I'm attempting to get webpack to package these scripts up (which does work with the file-loader, if I visit that url in my original question I can see the output on the .ps1 file displayed) so that they are pulled in with the buillt application. I'm using the Electron-React-Boilerplate if that helps. Does that make anymore sense? |
This issue has been raised and closed see #36 I use electron and I just make a zip file out of my project with my scripts included in the zip file. This is really a "problem" for PowerShell that you want it to execute precompiled scripts in non human readable format. Also note that asar electron apps can be unpacked extremely easily so you cant hide secrets in there. |
Ah I see, Alright well none of those solutions are ideal so we'll keep looking. For now we will use your suggestion of adding them line by line within the code. Thanks, I'll leave this open for now as I'll come back when we have our solution worked out! |
What is the problem you are trying to solve by obscuring the .ps1 files inside an asar? |
Note that hashing is the appropriate way to store passwords. You can use a library for example bcrypt |
So I'm not trying to obscure them at all, they just end up in the asar file as Electron-build will but the "files" within the .asar. I can see them in there when I open the asar up however I'm struggling to get a reference to them within the code to load them into .addCommand(); as it is always coming back undefined. Hence I attempted to use the Webpack file loader to do the importing, which it does however addCommand does not like it in that format. |
okay so what you want is to make 2 changes to you package.json file you want the electron build to "ignore" your script folder: "build": {
"productName": "example",
"win": {
"files":["!scripts/*"]
"target": "NSIS",
"icon": "myIcon.icon"
}, see: https://www.electron.build/configuration/contents#files also you want your build script to copy your ps scripts to your distribution folder: "scripts": {
"postinstall": "install-app-deps",
"start": "electron .",
"package-win": "electron-packager . --overwrite --asar=true --platform=win32 --arch=x64 --icon=build/myIcon.ico --prune=true --out=release-builds --version-string.CompanyName='coolguyInc' --version-string.FileDescription='myThing' --version-string.ProductName='thingyapp';xcopy ./scripts/ ./release-builds/thingyapp-win32-x64/"
}, Your mileage may vary with using xcopy of course but Im not sure of a platform agnostic way to write that |
Its probably best to copy your scripts with a post install gulp file //gulpfile.js
var gulp = require('gulp');
gulp.task('copyscripts', function() {
gulp.src('scripts/**.*')
.pipe(gulp.dest('release-builds/projectName/scripts'));
});
gulp.task('default', ['copyscripts']); |
I guess file-loader is the webpack tool that gives you the equivalent of this gulp task: https://github.com/webpack-contrib/file-loader |
@rannn505 feel free to close this and every other issue thats open currently for node-powershell |
Hey,
So I've used webpack "file-loader" to load my powershell,
with
then attempt to use it with
I get
I'm guessing I'll need to read in the file then paste it as string into the command to bypass this but it would be great if it supported it.
The text was updated successfully, but these errors were encountered: