Just
Previous versions of my project layout suggested putting everything into a //scripts/
folder and adding that to the path using the project setup.
For the most part, that worked but I found it cumbersome after about a year. The scripts had to have extensions and I found myself obsessing about the logging prefixes to make things “pretty” even to go as far as to write a program to write a standard boilerplate for scripts to produce logging.
Realizing that I was losing the tree in the middle of the forest, I found another utility that did most of what I was looking for, was not maintained by me, and had cross-platform support: Just.
just
is a pretty solid program, with the ability to have a chooser when one doesn't know the application, can chain commands together, and has the ability to pull in things like the .env
file if present or chain to other just files.
The tool also has good online documentation and there is also a wonderful cheat sheet that is good for referencing.
Boilerplate
That isn't to say I don't have a standard boilerplate when it comes to just files. The main part is to make sure that running just
by itself gives some form of documentation or possibility of what can be done. Since the bulk of the use of this is via a user console window, I use the “choose” command and put the following stanza at top:
set dotenv-load
_default:
just --choose
Detailed Targets
For the most part, I'll set up a target such as build
but there are times when I only want to run a specific part of the build, such as only building the JavaScript assets or only generating files. In those cases, I prefix a more detailed target with the name of the general one and then have the general call that.
build: build-client build-server
build-client:
# Do stuff
build-server:
# Do stuff
Imports
I like my files to be small and readable, usually a hundred lines or less. With some projects, such as Rust or Python, it can get longer, but I still want to break that into different files.
In Just, I use the import
command to pull files from the //src/just
directory.
import 'src/just/build.just'
build: build-client build-server
Common Targets
The most common targets I set up are:
setup
Since I use CI servers for most of my work, I use the setup
target to download assets, install SSH keys, or install NPM packages. In most cases, I look for the presence of those files or directory to avoid doing the work excessively (and it avoid blowing away my SSH keys on accident).
build
Pretty much the most common target I'll create and use, build
will build the project. In many cases, it will run setup
first.
deploy
I use for projects that need to be deployed, like websites.
release
The release
target is for pushing up packages or doing the release process. These are the targets that would do semantic releases based on conventional commits.
clean
This is also a common task I use, clean
basically wipes out the folder and gets rid of directories like node_modules/
(for NPM) or target/
(for Rust projects). In most cases, I also have a clean-purge
that does a git -xfd
but ignores things like my .env
file to avoid blowing away my environment.
test
Performs any tests on the project.
format
I use code formatting a lot. In many cases, it is a dependency on build
to ensure everything is consistent.