Approach:
- The file starts with shell code.
- That code uses Node.js to execute the file in ESM mode, after it removes the initial non-JavaScript lines.
- Node.js does not currently have CLI flags for achieving what we do in this step. Therefore, we have to pipe to the
node
executable.
- Node.js does not currently have CLI flags for achieving what we do in this step. Therefore, we have to pipe to the
When editing this file, we want to use the JavaScript mode of our IDE or editor. Therefore, we try to “hide” the shell code from JavaScript as much as possible.
Suggestions for improvements welcome!
@sgourley Excellent suggestions, thanks! I’ve changed
myscript.bat
accordingly.