zx README

The project's README from github.com/google/zx. As one markdown file: README.md.

Zx logo zx

#!/usr/bin/env zx

await $`cat package.json | grep name`

const branch = await $`git branch --show-current`
await $`dep deploy --branch=${branch}`

await Promise.all([
  $`sleep 1; echo 1`,
  $`sleep 2; echo 2`,
  $`sleep 3; echo 3`,
])

const name = 'foo bar'
await $`mkdir /tmp/${name}`

Bash is great, but when it comes to writing more complex scripts, many people prefer a more convenient programming language. JavaScript is a perfect choice, but the Node.js standard library requires additional hassle before using. No compromise, take the best of both. The zx package provides useful cross-platform wrappers around child_process, escapes arguments and gives sensible defaults.

Install

npm install zx

All setup options: zx/setup. See also zx@lite.

Usage

Compatibility

See also

License

Apache-2.0

Disclaimer: This is not an officially supported Google product.

zx (google/zx)

Searching Database…

45.8K ·GitHub
这是什么?zx 是 Google 推出的一款工具,让你可以用 JavaScript 而不是 Bash 来编写 shell 脚本。它封装了 Node 的 child_process,并提供参数转义和合理的默认设置。
这是一个可以导入的库,还是独立的命令行工具?两者都是:zx 是一个 JS/TS 包,可以导入到你自己的代码中;它也附带一个 CLI,可以直接运行 .mjs 脚本,并提供全局的 $ 模板标签来执行 shell 命令。
我该怎么开始使用?安装 zx 包,然后用 $ 标签模板编写脚本来运行 shell 命令;完整的安装选项记录在 zx/setup 中,使用文档位于 google.github.io/zx。
运行 zx 脚本需要什么运行时?基础要求是 Node.js >= 12.17.0,但它也可以在 Bun >= 1.0.0、Deno 1.x/2.x 或 GraalVM Node.js 上运行,并且可以配合 Bash 或 PowerShell 使用。
它只支持一种模块格式吗?不是,它同时支持 CommonJS 和 ESM 模块,你可以用纯 JavaScript 或 TypeScript 编写脚本。
它也能在 Windows 上运行,还是只支持类 Unix 系统?它是跨平台的,可在 Linux、macOS 和 Windows 上运行:在 Windows 上使用 PowerShell,在类 Unix 系统上使用 Bash。
这是 Google 官方产品吗?它采用 Apache-2.0 许可证,但明确声明它不是 Google 官方支持的产品,尽管它位于 google 的 GitHub 组织下。
README 中提到的 MAML 是什么?MAML 是 zx 的 README 中提到的一个相关项目:一种类似 JSON 的配置格式,增加了注释、多行字符串、无引号的键名以及可选的逗号。
为什么我要用 zx,而不是直接写 Bash 脚本?zx 让你可以使用完整的编程语言(JavaScript/TypeScript),为复杂脚本提供真正的数据结构和错误处理;同时仍然能方便地执行 shell 命令,无需编写通常繁琐的 Node.js child_process 样板代码。
Creator
google
Size
4.1 MB
Stars
45.8K
Age
5y
Commits · 90 Days