a tool to write better scripts
CLI scripts are most often written in Bash. However, writing Bash scripts is not a trivial task, especially for developers who are not comfortable with the Linux command line.
To get started, install zx globally with npm using the following command:
npm i -g zx
Before starting to write zx scripts, two important prerequisites should be noted.
First, we need to tell the operating system which interpreter is needed for our script. To do this, we use a special instruction called box (or hashbang). For zx scripts, we add the following line to the start of the file:
Second, we need to tell the operating system that the text file we wrote is an executable using
chmod +x ./
To help write meaningful CLI scripts, zx includes several tools that allow developers to interact with the user and the CLI.
These include three built-in packages: fs which allows you to interact with the file system, bone which provides utilities related to the operating system, and finally chalk which allows the terminal string style.
Additionally, zx provides lightweight wrappers around commonly used Node.js commands to address common use cases like data retrieval, user interaction, and of course, CLI command execution. For a complete list of commands, see the official documentation.
It should be mentioned that although zx is published under Google user Github, it is currently maintained by Anton Medvedev and is not officially supported by Google.