You don't have to setup a bunch of tooling to just get started with a simple CLI.
A package with little code is often a better start as an open source package because it is easier for contributors to help initially in a lightweight repository.
To create a CLI make a folder:
mkdir my-cli
In this folder run:
npm init -y
cat <<EOF > cli.js
#!/usr/bin/env node
console.log('my cli');
EOF
chmod +x cli.js
open the created package.json file and add:
"bin": {
"my-cli": "cli.js"
},
To test the cli in your shell run npm link
while in the package folder.
You should now be able to run my-cli
in any terminal on your local machine.
To publish to npm
update the package.json file with the correct details and run npm publish
.
Other people can now run npm install -g my-cli
to use your CLI.
Top comments (0)