[英]Can I run a command from package.json bin script?
Is it possible to run a command from a bin
script in a package.json
?是否可以从package.json
的bin
脚本运行命令? I know it expects a path to file and trying to run a command there results in an error upon installation (after publishing to npm).我知道它需要一个文件路径并尝试在那里运行命令会导致安装时出错(发布到 npm 后)。 Is it possible to run a command like it is in an npm start
?是否可以像在npm start
一样运行命令?
Examples:例子:
{
"name": "myscript",
"version": "1.0.3",
"bin": {
"myscript": "app/main.js"
}
}
This will create a symlink from the app/main.js
script to /usr/local/bin/myscript
这将创建一个从app/main.js
脚本到/usr/local/bin/myscript
的符号链接
Instead, this is what I want to achieve:相反,这就是我想要实现的目标:
{
"name": "myscript",
"version": "1.0.3",
"bin": {
"myscript": "echo hello world"
}
}
Possible workarounds are also appreciated.可能的解决方法也受到赞赏。
Based on what you've written, it seems like you are looking for https://docs.npmjs.com/cli/run-script .根据您所写的内容,您似乎正在寻找https://docs.npmjs.com/cli/run-script 。
With the package.json
script property, you can define scripts as arbitrary shell commands or programs installed into the ./node_modules/.bin
.使用package.json
脚本属性,您可以将脚本定义为安装到./node_modules/.bin
任意 shell 命令或程序。
您是否尝试过运行npm link
https://docs.npmjs.com/cli/link这将创建指向您的二进制文件的链接,然后您可以在命令行上以myscript
运行您的脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.