"Just" -- command line tool inspired by make -- a recommendation

A tip inspired by @sukima’s mention of make in this earlier discussion, I too have been a big fan of make as a way to consolidate how to build and update things related to projects.

Lately I find the open source just command runner inspired by make to be a convenient way to collect and document recipes, comments, and dependencies in a Justfile for future reference - rather than maintaining collections of individual scripts and/or writing non-executable documentation.

As one short example, below is a Justfile recipe - part of a much larger Justfile - that I run to upgrade TiddlyWiki on node.js when a new version is released:

# Upgrade TiddlyWiki (after committing and backing up the current state)
upgrade: commit backup backup_node && restart
    #!/usr/bin/env bash
    set -o errexit -o nounset -o pipefail # -o xtrace
    cd {{justfile_directory()}} || exit 1
    [[ "$(uname -s)" = "Darwin" ]] && printf "\nWARNING: Expect Little Snitch network monitor alerts\n"
    sleep 2
    command -v npm || (printf "Requires npm installation\n" && exit 1)
    npm uninstall tiddlywiki
    npm install tiddlywiki
    tiddlywiki --version

The first, comment, line will be output if just is asked to list its recipes - making each recipe self documenting.

Similar to make, the second line identifies the upgrade recipe’s prior and subsequent dependencies. Here, before attempting an upgrade, I want to commit any unsaved changes, make an offsite backup copy of my TiddlyWiki content, and create a snapshot of the current node.js installation - all of which makes sure I have safety nets should any of the rest of the upgrade steps fail. If the upgrade completes successfully the subsequent dependency will restart the node.js server.

The remainder is just (pun intended) what might normally be part of a separate, in this case bash, script. Other Justfile recipes use some of those same dependents - which can rely on other scripting tools or be simple commands executed directly by just - to take repeated actions, restore from a backup, export TiddlyWiki content, … and in general help me stay DRY.

just is a command runner, not a build tool, and isn’t (yet) available by default, and so requires a separate install. But I find just's avoidance of make's other idiosyncrasies, and ability to use a variety of scripting languages for recipes, worth the effort. Realize too that while just works on multiple platforms, the recipes one creates will be platform-dependent without extra effort. Consider too the justifications described in the manual’s further ramblings.

4 Likes