Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure electron-builder to run powershell script

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.

like image 675
ohmyfgod Avatar asked May 01 '26 03:05

ohmyfgod


1 Answers

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:

enter image description here

Now when you run your build script, it will run your .ps1 file.

like image 183
Darren Avatar answered May 02 '26 16:05

Darren