@ts.adligo.org/cli-howto
v1.1.0
Published
This is a simple CLI application.
Downloads
22
Maintainers
Readme
cli-howto.ts.adligo.org
This is the simplest possible, tutorial on how to write a node.js cli (Command Line Interface) typescript program. It targets the Linux or MacOs CLI, or Gitbash on Windows.
Summary of Creating a CLI tool
- Edit package.json to have a bin section like the following in this package.json file;
"bin": {
"cli-howto": "./src/cli-howto.ts"
}- Add the link to node js at the top of the cli-howto.ts file
#! /usr/bin/env node- Install typescript, etc;
npm i typescript --save-dev
npm i @types/node --save-dev
npm i ts-node --save-dev- Configure Typescript using the tsconfg.json file
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"lib": ["es6"],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"resolveJsonModule": true,
"sourceMap": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "**/*.spec.ts"],
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node",
}
}- Run it locally from the current directory;
npm run-script run- Install on the local machine with;
npm install -g .- View the current installed packages on the local machine;
npm list -g | grep adligo- Uninstall the package;
npm uninstall -g @ts.adligo.org/cli-howtoSummary of Publishing your CLI tool
- Create an account at https://www.npmjs.com/
- Create a organzation (i.e. ts.adligo.org)
- Login on your local gitbash with a command like;
npm login [email protected]- Run the publish command
npm publish --access public- Install on other machines
npm install -g @ts.adligo.org/cli-howto- Test to see if it runs
cli-howtoCitations
- Official Doc) https://docs.npmjs.com/configuring-your-npm-client-with-your-organization-settings
- Helpful Article) https://medium.com/@manavshrivastava/lets-build-a-cli-command-line-interface-with-node-js-d3b5faacc5ea
- Helpful Article) https://itnext.io/how-to-create-your-own-typescript-cli-with-node-js-1faf7095ef89
