--run
这会从 package.json 的 "scripts" 对象中运行指定的命令。如果提供了一个不存在的 "command",它将列出可用的脚本。
【This runs a specified command from a package.json's "scripts" object.
If a missing "command" is provided, it will list the available scripts.】
--run 将向上遍历到根目录,并找到一个 package.json 文件来运行命令。
--run 会将每个当前目录的祖级目录下的 ./node_modules/.bin 添加到 PATH 中,以便在存在多个 node_modules 目录的不同文件夹中执行二进制文件,如果 ancestor-folder/node_modules/.bin 是一个目录。
--run 在包含相关 package.json 的目录中执行命令。
例如,以下命令将在当前文件夹中运行 package.json 的 test 脚本:
【For example, the following command will run the test script of
the package.json in the current folder:】
$ node --run test 你也可以向命令传递参数。-- 之后的任何参数都会被追加到脚本中:
【You can also pass arguments to the command. Any argument after -- will
be appended to the script:】
$ node --run test -- --verbose