1 min read

Dev scripts with Google's zx

Stefan Bauer

Out of curiosity, I decided to use Google's zx for scripting in a new project. I will not go into too much detail here, but the project requires several servers plus asset compilation with live reload at the same time. Usually, my workflow in hybrid apps is as follows:

  • I open a terminal window and run dev command one.
  • I open another terminal window and run dev command two.
  • etc.

It is possible to write scripts that run all servers and asset processes at once, but it is rather tricky. zx makes this easy to do, though:

#!/usr/bin/env zx

console.log('Starting all tasks...\n');

await Promise.all([
  $`yarn server1:dev`,
  $`yarn server2:dev`,
  $`yarn assets:dev`,
]);

I also found writing scripts with zx, in general, is a lot of fun. Mixing JS and Bash on the fly is a blast.