Reputation: 385
I've published a new package which aims to generate a very small boilerplate for a node open source project via cli. For now, it's just a combination of few npx commands and requires other npm packages like gitignore, license to work. I want to execute the build script in package.json with the following command.
npx get-set-node-oss build [email protected]
Link to the npm package: get-set-node-oss. I know the name is a bit too long.
{
"name": "get-set-node-oss",
"version": "1.0.1",
"description": "One command setup for your Node OSS project",
"scripts": {
"build": "npx license mit > LICENSE && npx gitignore node && npx covgen"
},
"author": "Harshit Juneja",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/harshitjuneja/get-set-node-oss.git"
},
"keywords": [
"node",
"boilerplate","gitignore","MIT","OSS"
],
"bugs": {
"url": "https://github.com/harshitjuneja/get-set-node-oss/issues"
},
"homepage": "https://github.com/harshitjuneja/get-set-node-oss#readme"
}
I expect the user to make a new folder and cd into the folder and do
npx get-set-node-oss build emailstring
and get the resulting boilerplate files.
Upvotes: 6
Views: 2569
Reputation: 303
For npx to work you need to specify what the get-set-node-oss
command means. Thankfully, this can be accomplished by using the bin
field in your package.json file. More information from NPM documentation for your reference:
To use this, supply a bin field in your package.json which is a map of command name to local file name. On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.
An example of it below.
"bin": {
"get-set-node-oss": //script you like to run
},
Hope it works out for you. I have understood bin as scripts in package.json. Where we can either do npm run foo
or npx foo
both yielding the same results. If you want an example, here you go https://github.com/vipulgupta2048/balenaclone
Upvotes: 3