配置电子生成器以运行Powershell脚本 [英] Configure electron-builder to run powershell script

查看:53
本文介绍了配置电子生成器以运行Powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由electronic-builder创建的安装文件,但遇到的问题是安装后找不到运行powershell脚本的方法.

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.

这个想法是要在Windows注册表中进行一些更改,并设置应用程序文件夹的权限.

The idea is to make some changes in windows registry and set permission for application folder.

据我了解,应该在 package.json build 部分中对其进行配置.在api中,我发现它存在 afterPack 方法,但是我无法弄清楚如何通过它执行powershell文件.

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.

谢谢.

推荐答案

首先,创建一个包含以下代码的 afterPack.js 文件:

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"""');
}

相应地编辑.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.

接下来,编辑您的package.json文件,以在构建设置中包含 afterPack 参数,如下所示:

Next, edit your package.json file to include an afterPack parameter in your build settings, like so:

现在,当您运行构建脚本时,它将运行您的 .ps1 文件.

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

这篇关于配置电子生成器以运行Powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆