DEV Community

yanir manor
yanir manor

Posted on

ZX - Replace bash Scripting using Javascript

From time to time, I found myself need to write some scripts for an automation process.
Then I found myself starting to remember the bash syntax.
Bash is great, but when it comes to writing scripts,
I prefer to choose a more convenient programming language.
JavaScript is a perfect choice, but the standard Node.js library requires additional hassle before using.
The ZX Google package makes it easy and readable.

I will show you a quick example.
First, you install it globally

npm i -g zx
Enter fullscreen mode Exit fullscreen mode

Then copy the script below.
It asks you for a name to create a folder then it git init and init a package json file.
You need to save to file as mjs.

#!/usr/bin/env zx
let folderName = await question("Please give me a name to create a folder? ");
await $`mkdir ${folderName}`;
await $`pwd`;
await $`git init`;
await $`npm init -y`;
console.log(`You are set to go - ${folderName}`));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)