A minimal starter for a CLI written with TypeScript.
git clone https://github.com/FjellOverflow/ts-cli-starter.git
cd ts-cli-start
pnpm i
In VSCode, go to Extensions, type @recommended
and install recommended extensions.
Called with pnpm run <command>
command | effect |
---|---|
lint | lints src |
typecheck | typechecks src |
build | compiles src to lib |
dev | compiles and calls CLI |
update-deps | auto-updates dependencies |
-
main
:lib/index.js
entrypoint to import all exported members
-
types
:lib/index.d.ts
entrypoint to import types in TypeScript projects
-
bin
:{ "ts-cli-starter": "lib/cli.js" }
when installed, package can be called with
ts-cli-starter
on command line
Clone and modify this template, compile (and publish) as npm package. Replace ts-cli-starter
with your package/binary name.
# install
pnpm i -g ts-cli-starter
# call binary
ts-cli-starter test
Add to project (package.json
must already be present).
cd myProject
pnpm i ts-cli-starter
In code, import members.
import { ExampleType, exampleFunction } from 'ts-cli-starter'
// use in code
Add as npm scripts to call binary.
{
"scripts": {
"dev": "ts-cli-starter dev",
"build": "ts-cli-starter build --prod"
}
}