我正在努力寻找使用 node-powershell 调用 powershell 脚本的正确语法,并使用 zeit/pkg 语法将所有这些编译成单个 .exe 文件。如何指定使用https://github.com/zeit/pkg中的信息编译的正确 PS1 文件的路径并使其正确启动?我的文件夹结构和我的 package.json 如下。我认为我正确地遵循了指示,但是我花了几个小时尝试一切无济于事。因此,如果我遗漏了一些明显的东西,请寻找其他眼睛。
我在项目根目录中的文件夹结构有一个资产目录(见下文)。我有一个 PS1 文件,然后是其他三个目录,这些目录具有包含 PS1 模块、信息文件等的各种文件的子目录,我的 PS1 脚本使用这些文件来运行和锁定 IE。如果使用 Electron 之类的东西打包所有内容并公开源代码,所有脚本都可以正常工作。但是我们需要锁定源代码,所以 Electron 不是一个选项。
assets
IE-Start.ps1 <-- this is a file
InternetExplorer <-- this is a folder with files I read in with my script
modules <-- this is a folder with files I read in with my script
Windows <-- this is a folder with files I read in with my script
index.js
package-lock.json
package.json
README.md
node_modules
我从根目录编译.exe。我知道目录中的文件在那里,因为在我添加它们之后,我在 .exe 上的文件大小增加了很多。所以它确实添加了一些东西。我似乎无法正确引用内部路径。
pkg . -t node8-win
我在我的 index.js 中运行下面的代码但是它失败说它找不到 ps1 文件
let scriptPath = path.join(__dirname, 'assets/IE-Start.ps1')
ps.addCommand(scriptPath);
我得到的错误是这样的:
Cannot find path 'C:\snapshot\ielockdown\assets\InternetExplorer\'
because it does not exist.
我的 package.json 内容如下:
{
"name": "ielockdown",
"version": "1.0.0",
"description": "IE Lockdown Tool compiled for Win10",
"main": "index.js",
"scripts": {
"start": "npm start"
},
"author": "Dale Bingham",
"license": "ISC",
"dependencies": {
"node-powershell": "^4.0.0",
"path": "^0.12.7"
},
"bin": "index.js",
"pkg": {
"scripts": "*.js",
"assets": [
"assets/*.ps1",
"assets/**/*"
],
"targets" : [
"node8"
]
}
}
我在下面包含的一些 --debug 标志的输出以确保我看到的是正在添加文件。我只是没有正确引用它们吗?任何帮助表示赞赏。
> [debug] The file was included as asset content
/Users/dalebingham/cingulara/ielockdown/assets/IE-Start.ps1
> [debug] The file was included as asset content
/Users/dalebingham/cingulara/ielockdown/assets/modules/Excel.psm1
> [debug] The file was included as asset content
/Users/dalebingham/cingulara/ielockdown/assets/modules/GitHub.psm1
> [debug] The file was included as asset content
/Users/dalebingham/cingulara/ielockdown/assets/modules/GroupPolicy.psm1