I am struggling to find the right syntax of calling a powershell script using node-powershell and compile all that into a single .exe file using the zeit/pkg syntax. How can I specify the path to the correct PS1 file that is compiled in using the information from https://github.com/zeit/pkg and have it fire off correctly? My folder structure and my package.json is below. I think I am following the directions correctly however I have spent a few hours trying things to no avail. So asking for other eyes in case I am missing something blatantly obvious.
My folder structure in the root of the project has an assets directory (see below). In that I have a single PS1 file, and then three other directories that have subdirectories of various files that contain PS1 modules, info files, etc. that my PS1 script uses to run and lock down IE. All the scripts work correctly if run using something like Electron to package everything up and expose the source. However we need to lock the source code down so Electron is not an option.
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
I compile the .exe as this from the root. I know the files in the directories are in there because after I added them my file size on the .exe went up a LOT. So it did add something. I just cannot seem to reference the internal paths correctly.
pkg . -t node8-win
I am running the code below in my index.js however it fails saying it cannot find the ps1 file
let scriptPath = path.join(__dirname, 'assets/IE-Start.ps1')
ps.addCommand(scriptPath);
The errors I get are along the lines of this:
Cannot find path 'C:\snapshot\ielockdown\assets\InternetExplorer\'
because it does not exist.
My package.json contents are below:
{
"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"
]
}
}
Some of the output of the --debug flag I included below to ensure what I am seeing is that the files are being added. I am just not referencing them correctly maybe? Any help is appreciated.
> [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