Appearance
配置
¥Configuration
$.shell
指定使用什么外壳。默认为 which bash。
¥Specifies what shell is used. Default is which bash.
js
$.shell = '/usr/bin/bash'或者使用 CLI 参数:--shell=/bin/bash
¥Or use a CLI argument: --shell=/bin/bash
$.spawn
指定 spawn api。默认为 require('child_process').spawn。
¥Specifies a spawn api. Defaults to require('child_process').spawn.
要覆盖同步 API 实现,请相应地设置 $.spawnSync。
¥To override a sync API implementation, set $.spawnSync correspondingly.
$.prefix
指定将作为所有运行命令的前缀的命令。
¥Specifies the command that will be prefixed to all commands run.
默认为 set -euo pipefail;。
¥Default is set -euo pipefail;.
或者使用 CLI 参数:--prefix='set -e;'
¥Or use a CLI argument: --prefix='set -e;'
$.postfix
与 $.prefix 类似,但用于命令结束。
¥Like a $.prefix, but for the end of the command.
js
$.postfix = '; exit $LastExitCode' // for PowerShell compatibility$.preferLocal
指定是否优先使用位于 node_modules/.bin 的二进制文件而不是全局系统安装的二进制文件。
¥Specifies whether to prefer node_modules/.bin located binaries over globally system installed ones.
js
$.preferLocal = true
await $`c8 npm test`你还可以指定一个目录来搜索本地二进制文件:
¥You can also specify a directory to search for local binaries:
js
$.preferLocal = '/some/to/bin'
$.preferLocal = ['/path/to/bin', '/another/path/bin']$.quote
指定在命令替换期间转义特殊字符的函数。
¥Specifies a function for escaping special characters during command substitution.
$.verbose
指定详细程度。默认为 false。
¥Specifies verbosity. Default is false.
在详细模式下,zx 打印所有执行的命令及其输出。
¥In verbose mode, zx prints all executed commands alongside with their outputs.
或者使用 CLI 参数:--verbose 设置 true。
¥Or use the CLI argument: --verbose to set true.
$.quiet
抑制所有输出。默认为 false。
¥Suppresses all output. Default is false.
通过 CLI 参数:--quiet 设置 $.quiet = true。
¥Via CLI argument: --quiet sets $.quiet = true.
$.env
指定环境变量映射。
¥Specifies an environment variables map.
默认为 process.env。
¥Defaults to process.env.
$.cwd
指定使用 $ 创建的所有进程的当前工作目录。
¥Specifies a current working directory of all processes created with the $.
cd() 函数仅更改 process.cwd(),如果未指定 $.cwd,则所有 $ 进程默认使用 process.cwd()(与 spawn 行为相同)。
¥The cd() func changes only process.cwd() and if no $.cwd specified, all $ processes use process.cwd() by default (same as spawn behavior).
$.log
指定 日志函数。
¥Specifies a logging function.
ts
import {LogEntry, log} from 'zx/core'
$.log = (entry: LogEntry) => {
switch (entry.kind) {
case 'cmd':
// for example, apply custom data masker for cmd printing
process.stderr.write(masker(entry.cmd))
break
default:
log(entry)
}
}