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
nodeexecutable.
- 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!
Very nice! A couple of tiny mods to
myscript.batyou might consider? Changing%0to%~f0in line 3 would allow invoking from the Windows command line using simplymyscriptrather thanmyscript.bat. Also changing0in line 4 to%errorlevel%would propagate any exit code to a parent process: