问题
I have an installation file created by electron-builder and faced issue that can't find a way how to run powershell script after installation.
The idea is to make some changes in windows registry and set permission for application folder.
As far as I understand it should be configured in build
section in package.json
. In api I found that it is exist afterPack
method, but I can't figure it out how to execute powershell file through it.
Thank you.
回答1:
First, create an afterPack.js
file, containing this code:
exports.default = async function () {
const { exec } = require('child_process');
const bat = exec('powershell "& ""path/to/powershell/file.ps1"""');
}
Edit the path to the .ps1 file accordingly. You may need to add a '.\' to the start of the path. The console readout will tell you if you do.
Next, edit your package.json file to include an afterPack
parameter in your build settings, like so:
Now when you run your build script, it will run your .ps1
file.
来源:https://stackoverflow.com/questions/52724004/configure-electron-builder-to-run-powershell-script