如何使 npx 与我的自定义 npm 包一起工作? [英] How to make npx work with my custom npm pakage?
问题描述
我发布了一个新包,旨在通过 cli 为节点开源项目生成一个非常小的样板.目前,它只是几个 npx 命令的组合,需要其他 npm 包,如 gitignore、license 才能工作.我想使用以下命令在 package.json 中执行构建脚本.
npx get-set-node-oss build youremailaddress@xyz.com
链接到 npm 包:get-set-node-oss一>.我知道这个名字有点长.
<代码>{名称":get-set-node-oss",版本":1.0.1",描述":为您的 Node OSS 项目设置一个命令",脚本":{build":npx license mit"许可&&npx gitignore 节点 &&npx covgen"},作者":Harshit Juneja",许可证":MIT",存储库":{类型":git",url":git+https://github.com/harshitjuneja/get-set-node-oss.git"},关键词":[节点",样板"、gitignore"、MIT"、OSS"],错误":{网址":https://github.com/harshitjuneja/get-set-node-oss/issues"},主页":https://github.com/harshitjuneja/get-set-node-oss#readme"}
我希望用户创建一个新文件夹并将 cd 放入该文件夹并执行
npx get-set-node-oss build emailstring
并获取生成的样板文件.
要使 npx 工作,您需要指定 get-set-node-oss
命令的含义.幸运的是,这可以通过使用 package.json 文件中的 bin
字段来完成.来自 NPM 文档的更多信息,供您参考:
要使用它,请在 package.json 中提供一个 bin 字段,它是命令名到本地文件名的映射.在安装时,npm 会将该文件符号链接到 prefix/bin 以进行全局安装,或者 ./node_modules/.bin/进行本地安装.
下面的一个例子.
bin":{get-set-node-oss"://你喜欢运行的脚本},
希望对你有用.我已经将 bin 理解为 package.json 中的脚本.我们可以在其中执行 npm run foo
或 npx foo
两者都产生相同的结果.如果你想要一个例子,你去https://github.com/vipulgupta2048/balenaclone>
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 youremailaddress@xyz.com
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.
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
这篇关于如何使 npx 与我的自定义 npm 包一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!