Well, this is just a simple example of how you can support out of the box Independent Terminal Emulators for your nodejs CLI application when generating executables with npm pkg.
Generated package will work both on windows and Linux.
- Make sure you have globally installed "pkg" module from npm.
- Clone repo:
git clone https://github.com/AndoGhevian/VT-pkg.git
- Change current directory:
cd VT-pkg
- Run packing script and get "vt-pkg" executable in current folder:
npm run pkgpack
- Move it anywhere you want and run created executable:
./vt-pkg
You see it works from anywhere, it automatically finds and runs terminal, and executes main.js script from Internal FileSystem in this new opened terminal. Vuola!:)
Be sure to read Important Notes section!!
- If you want to access your "Internal node" from your generated by pkg executable, when trying to spawn another
node
process, or trying to use that "Internal node" from spawned terminal as we doe's, simply use instead ofnode
your executable path.Use
$ /path/to/pkg/generated-exe your-script.js
, Where:/path/to/pkg/generated-exe
- Replacement for original "node".your-script.js
- Script which you want to execute with "Internal node" instead of your system-wide "node".
const child = require('child_process') // this hold's executable path. const internalNode = process.execPath // when project is packed, this refer to internal filesystem. // See: https://www.npmjs.com/package/pkg#snapshot-filesystem const internalFs = __dirname const cmdProcess = child.spawn(`${internalNode}`, [`${internalFs}/main.js`], { stdio: 'inherit' })
- Remember that first argument of "Internal node" if provided, must allways be existing file path, eather from your actual FileSystem or from Internal FileSystem( See Snapshot filesystem ): i.e. --arg1, -arg1, or anything else, to nonexisting file, will lead to fail for first argument.