Skip to content
Go back

Distribute a TypeScript CLI App

Edit page

Instructions to Distribute a TypeScript CLI App

1. Setup Your Project

mkdir mdtohtml-cli
cd mdtohtml-cli
npm init -y

Install dependencies:

npm install typescript ts-node @types/node yargs marked

Create tsconfig.json:

npx tsc --init

2. Build the CLI Logic

Create src/mdtohtml.ts and add your CLI logic (Markdown to HTML conversion).

Add a shebang to the top:

#!/usr/bin/env node

3. Configure for Distribution

Update package.json:

"bin": {
  "mdtohtml": "dist/mdtohtml.js"
},
"scripts": {
  "build": "tsc",
  "prepare": "npm run build"
}

Create a .npmignore file:

src/
tsconfig.json
.gitignore
.npmignore
node_modules/

4. Build and Test Locally

Compile your code:

npm run build

Link for testing:

npm link
mdtohtml --source input.md --output output.html
npm unlink

5. Publish to npm

Login and publish:

npm login
npm publish

To update: increment version and re-publish.


6. Optional: Create Standalone Executable

Install pkg:

npm install -g pkg

Build executable:

pkg .

Distribute the generated binaries for macOS, Windows, or Linux.


Edit page
Share this post on:

Previous Post
Systems Programming: Building a Unix-like Shell in Rust
Next Post
How to Transcribe Audio on Raspberry Pi