Reputation: 1
I tried to make cli app by typescript. this is my code.
//package.json
{
"name": "jihea-cli",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"bin": {
"cli": "./bin/index.ts"
},
"scripts": {
"build": "npx tsc",
"cli": "ts-node ./bin/index.ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.12.7"
},
"dependencies": {
"ts-node": "^10.9.2"
}
}
/bin/index.ts
#!/usr/bin/env node
console.log(`!!! Please enter a valid name for your new app.`);
process.exit(0);
And I publish, and install global.
I checked by npm ls -g
.
Desktop (main*) » npm ls -g ~/Desktop
/opt/homebrew/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
But if I tried jihea-cli cli
, it does not work.
zsh: command not found: jieha-cli
Please help me.
I want to make cli app that can be used by installed global. Please help me.
Upvotes: 0
Views: 107
Reputation: 4608
zsh: command not found: jieha-cli ?
Actually it is working, just run this in terminal
cli
why?
It's a simple mistake in bin
field of your package.json
, because the bin
field determines the name of the executable either in local or global like npx name
or npm exec name
or name
in global
so you named of your executable as
cli
If you have a single executable, and its name should be the name of the package, then you can just supply it as a string. For example
{
"name": "jihea-cli",
"version": "1.0.1",
"bin": "./bin/index.ts",
...
}
would be same as this
{
"name": "jihea-cli",
"version": "1.0.1",
"bin": {
"jihea-cli": "./bin/index.ts"
},
...
}
Upvotes: 2