How to run a Typescript ... script directly, including imports from NPM, without the need for a package.json?
Suppose I want to write a quick script to alter a bunch of files quickly e.g.:
// my-script.ts
import fs from "fs";
import { someFunc } from "some-dep@^4"; // dep pulled from NPM during run
fs.readdir(process.argv[2], (err, files) => {
files.forEach(file => {
someFunc(file);
});
});
I'd like to run this easily, from a terminal, such as:
<cmd> my-script
Where <cmd> is whatever program allows me to do this. Does this mystery program exist?
TL;DR: I want to be able to run TS files (with NPM modules) as if they were bash scripts.
package.jsonand runningnpm install. I just want to write and run the script, and have modules be installed/handled for me. Along withts-node, there is alsoesrunwhich do similar things but I don't think either "solves" what I'm asking.