npx and yarn dlx
Using npx or yarn dlx is a great ways to publish reusable TypeScript tools to GitHub without precompiling or packaging.
Check out our working example: TypeStrong/ts-node-npx-example
shellnpx typestrong/ts-node-npx-example --helpnpx typestrong/ts-node-npx-example --first Arthur --last Dent
shellnpx typestrong/ts-node-npx-example --helpnpx typestrong/ts-node-npx-example --first Arthur --last Dent
TODO publish demo and link to it TODO test demo:
- uninstall global ts-node
- try running demo
- does ts-node need to be installed globally?
This boilerplate is a good starting point:
package.jsonjson{"bin": "./cli.ts","dependencies": {"ts-node": "latest","@swc/core": "latest","@swc/helpers": "latest","@tsconfig/node16": "latest"}}
package.jsonjson{"bin": "./cli.ts","dependencies": {"ts-node": "latest","@swc/core": "latest","@swc/helpers": "latest","@tsconfig/node16": "latest"}}
tsconfig.jsonjson{"extends": "@tsconfig/node16/tsconfig.json","ts-node": {"swc": true}}
tsconfig.jsonjson{"extends": "@tsconfig/node16/tsconfig.json","ts-node": {"swc": true}}
cli.tstypescript#!/usr/bin/env ts-nodeconsole .log ("Hello world!")
cli.tstypescript#!/usr/bin/env ts-nodeconsole .log ("Hello world!")
If you require native ESM support, use ts-node-esm in your shebang and follow the configuration instructions for ESM: Native ECMAScript modules
cli.tstypescript#!/usr/bin/env ts-node-esm
cli.tstypescript#!/usr/bin/env ts-node-esm