A typescript cli template powered by typescript, prettier, zx, esbuild, and pkg
Replace the following templated variables globally:
YOUR_NAME (author's name)
YOUR_EMAIL (author's email)
GITHUB_USERNAME (github username)
smol-cli (package name)
smol--cli (package name)
I needed a lightweight approach that had all the tools I preferred using that resulted in smol binaries that worked across all major platforms.
- Is this the best way to develop a CLI in javascript? Doubtful.
- Is it usable? By my standards sure.
- Is the output small? No... its
smol
😉.
Install the dreaded 💀 node_modules 💀 with your package manager of choice:
npm i
-
Run the
watch
script to create a minified CommonJS bundle atdist/out.cjs
(using esbuild) and update it when changes are made to any files in./src/**/*
. -
There is no testing framework (yet) so to test it run
node ./dist/out.cjs
. -
zx
utils can be used to run shell commands, get options and arguments, and access common utils (path
,fs
,fetch
,cd
,echo
, etc). -
src/utils.ts
includes a couple functions for normalizing shorthand argument names and showing a formatted help message.
pkg
is used to create binaries for all major platforms. The package
script will create binaries for windows, macos, and linux from the ./dist/out.cjs
bundle.
Script | Description |
---|---|
compile |
Bundles the source files from the src directory into a single CommonJS module, minifying the output. |
watch |
Runs the compile script in watch mode, recompiling automatically on source file changes. |
package |
Packages the compiled CommonJS module into standalone executables for Windows, macOS, and Linux. |