DEV Community

yanir manor
yanir manor

Posted on

3 1

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}`;
cd(`${folderName}`);
await $`pwd`;
await $`git init`;
await $`npm init -y`;
console.log(chalk.green.bold(`You are set to go - ${folderName}`));
Enter fullscreen mode Exit fullscreen mode

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay