@0x-lerna-fork/exec 中文文档教程
@0x-lerna-fork/exec
在每个包中执行任意命令
安装 lerna 以访问 lerna
CLI。
Usage
$ lerna exec -- <command> [..args] # runs the command in all packages
$ lerna exec -- rm -rf ./node_modules
$ lerna exec -- protractor conf.js
在每个包中运行任意命令。 双破折号 (--
) 是将破折号标志传递给派生命令所必需的,但当所有参数都是位置参数时则不是必需的。
当前包的名称可通过环境变量 LERNA_PACKAGE_NAME
获得:
$ lerna exec -- npm view \$LERNA_PACKAGE_NAME
您还可以通过环境变量 LERNA_ROOT_PATH
在复杂的目录结构中运行位于根目录中的脚本:
$ lerna exec -- node \$LERNA_ROOT_PATH/scripts/some-script.js
Options
lerna exec
遵守--concurrency
, --scope
, and --ignore
flags (see 过滤标志)。
$ lerna exec --scope my-component -- ls -la
命令是并行生成的,使用给定的并发性(
--parallel
除外)。 输出通过管道传输,因此不确定。 如果你想在一个又一个包中运行该命令,请像这样使用它:
$ lerna exec --concurrency 1 -- ls -la
--stream
立即从子进程流式输出,以原始进程为前缀 包裹名字。 这允许交错来自不同包的输出。
$ lerna exec --stream -- babel src -d lib
--parallel
类似于 --stream
,但完全无视并发性和拓扑排序,在所有匹配的包中立即运行给定的命令或脚本,并带有前缀流输出。 这是长时间运行的进程的首选标志,例如 babel src -d lib -w
运行在许多包上。
$ lerna exec --parallel -- babel src -d lib -w
注意:建议在使用时限制此命令的范围
--parallel
标志,因为可能会产生许多子进程 对你的 shell 的平静(或最大文件描述符限制, 例如)。 YMMV
--no-bail
# Run a command, ignoring non-zero (error) exit codes
$ lerna exec --no-bail <command>
默认情况下,如果 any 执行返回非零退出代码,lerna exec
将退出并出错。 传递 --no-bail
以禁用此行为,在所有 包中执行,而不管退出代码如何。
--no-prefix
流输出时禁用包名称前缀(--stream
或 --parallel
)。 当将结果通过管道传输到其他进程(例如编辑器插件)时,此选项很有用。
@0x-lerna-fork/exec
Execute an arbitrary command in each package
Install lerna for access to the lerna
CLI.
Usage
$ lerna exec -- <command> [..args] # runs the command in all packages
$ lerna exec -- rm -rf ./node_modules
$ lerna exec -- protractor conf.js
Run an arbitrary command in each package. A double-dash (--
) is necessary to pass dashed flags to the spawned command, but is not necessary when all the arguments are positional.
The name of the current package is available through the environment variable LERNA_PACKAGE_NAME
:
$ lerna exec -- npm view \$LERNA_PACKAGE_NAME
You may also run a script located in the root dir, in a complicated dir structure through the environment variable LERNA_ROOT_PATH
:
$ lerna exec -- node \$LERNA_ROOT_PATH/scripts/some-script.js
Options
lerna exec
respects the --concurrency
, --scope
, and --ignore
flags (see Filter Flags).
$ lerna exec --scope my-component -- ls -la
The commands are spawned in parallel, using the concurrency given (except with
--parallel
). The output is piped through, so not deterministic. If you want to run the command in one package after another, use it like this:
$ lerna exec --concurrency 1 -- ls -la
--stream
Stream output from child processes immediately, prefixed with the originating package name. This allows output from different packages to be interleaved.
$ lerna exec --stream -- babel src -d lib
--parallel
Similar to --stream
, but completely disregards concurrency and topological sorting, running a given command or script immediately in all matching packages with prefixed streaming output. This is the preferred flag for long-running processes such as babel src -d lib -w
run over many packages.
$ lerna exec --parallel -- babel src -d lib -w
Note: It is advised to constrain the scope of this command when using the
--parallel
flag, as spawning dozens of subprocesses may be harmful to your shell's equanimity (or maximum file descriptor limit, for example). YMMV
--no-bail
# Run a command, ignoring non-zero (error) exit codes
$ lerna exec --no-bail <command>
By default, lerna exec
will exit with an error if any execution returns a non-zero exit code. Pass --no-bail
to disable this behavior, executing in all packages regardless of exit code.
--no-prefix
Disable package name prefixing when output is streaming (--stream
or --parallel
). This option can be useful when piping results to other processes, such as editor plugins.