I have a command line application written in TypeScript with some npm scripts defined in package.json.
"scripts": {
"start": "ts-node src/index.ts",
"start-args": "ts-node src/index.ts -- some args"
},
I would like to link and alias the TypeScript file so that I can call the program easily, so I am looking for something like a "bin" key in the package.json file.
"scripts": {
"start": "ts-node ./src/index.ts",
"start-args": "ts-node src/index.ts -- some args"
},
"bin": {
"foobar": "./src/index.ts",
"bazqux": "./src/index.ts some args"
}
ts-node is installed locally.
However, since TypeScript is not natively supported by node, just putting a shebang on ./src/index.ts won't work.
I would also like to be able to create an aliased command with default arguments, like bazqux above. When I link or install the package as global, I can run "foobar" globally as if I run "npm run start" inside the repository; or run "bazqux" globally as it's "npm run start-args".
How to achieve this?