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
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}`));
Top comments (0)