~alterae/alterae.srht.site

dd540f21879804d35243751ea9d1fe89ec175b3e — Michelle S 2 years ago c00a599
Convert Makefile to justfile

This makes my life a lot easier.  See
<https://alterae.sr.ht/blog/makefile-to-just> for details.
3 files changed, 95 insertions(+), 14 deletions(-)

D Makefile
A content/blog/makefile-to-just.md
A justfile
D Makefile => Makefile +0 -14
@@ 1,14 0,0 @@
site.tar.gz: public
	tar -C public -cvz . > site.tar.gz

public: clean
	zola build

upload: site.tar.gz
	curl --oauth2-bearer $$(bat ~/.srht-token) -Fcontent=@site.tar.gz https://pages.sr.ht/publish/alterae.srht.site

clean:
	rm -rf public site.tar.gz

serve: clean
	zola serve --interface 0.0.0.0 --base-url $$(hostname -f)

A content/blog/makefile-to-just.md => content/blog/makefile-to-just.md +72 -0
@@ 0,0 1,72 @@
+++
title = "makefile to just"
description = "converting this site's Makefile to `just`"
+++

i recently discovered the lovely little [`just`](https://github.com/casey/just) command runner.  it's lovely.  for an explanation of why it's lovely, see its readme.

as for why *i* love it:  it replaces `make`.

make is a very poweful, useful tool.  it is also incredibly messy and i by definition use it wrong, since most of my usage of `make` is as less a build tool and more a general-purpose command runner, which is something it is not designed to do.  it *works*, but lacks a lot of quality of life features which `just` provides, such as the ability to list recipes from the command line.

## converting this site

this was the old Makefile:

```make
site.tar.gz: public
	tar -C public -cvz . > site.tar.gz

public: clean
	zola build

upload: site.tar.gz
	curl --oauth2-bearer $$(bat ~/.srht-token) \
	    -Fcontent=@site.tar.gz https://pages.sr.ht/publish/alterae.srht.site

clean:
	rm -rf public site.tar.gz

serve: clean
	zola serve --interface 0.0.0.0 --base-url $$(hostname -f)
```

it has some issues, including the fact that it was written before i knew what phonies were.

this is the new justfile:

```make
# Build the site.
build: clean
    zola build

# Compress the built site into a tarball for uploading.
tarball: build
    tar -C public -cvz . > site.tar.gz

# Publish the site to `alterae.srht.site`.
publish: tarball
    @# not very secure, requires that i remember to keep the token file in my 
    @# home dir
    curl \
        --oauth2-bearer $(cat ~/.srht-token) \
        -Fcontent=@site.tar.gz https://pages.sr.ht/publish/alterae.srht.site

# Remove all build artifacts.
clean:
    -rm -rf public site.tar.gz

# Build the site in watch mode and serve it at `hostname:1111.
serve: clean
    zola serve --interface 0.0.0.0 --base-url $(hostname -f)
```

admittedly the difference is mostly in the names of the recipes, but that alone is an improvement.  one of the big features just *doesn't* have is conditional running based on whether or not files have changed.  honestly, that's not something i miss or need much, and here is not really an exception.  additionally, without it, we don't need `.PHONY` targets everywhere.

what we lose in file-update checking, we gain in ease-of-use.  running `just --list` displays all the available recipes, using the comments as documentation.

the transition was really easy, though i should really move the token into a .env file in the project directory at some point.

## TL;DR

this site had a Makefile.  now it has a justfile instead.

A justfile => justfile +23 -0
@@ 0,0 1,23 @@
# Build the site.
build: clean
	zola build

# Compress the built site into a tarball for uploading.
tarball: build
	tar -C public -cvz . > site.tar.gz

# Publish the site to `alterae.srht.site`.
publish: tarball
	@# not very secure, requires that i remember to keep the token file in my 
	@# home dir
	curl \
		--oauth2-bearer $(cat ~/.srht-token) \
		-Fcontent=@site.tar.gz https://pages.sr.ht/publish/alterae.srht.site

# Remove all build artifacts.
clean:
	-rm -rf public site.tar.gz

# Build the site in watch mode and serve it at `hostname:1111.
serve: clean
	zola serve --interface 0.0.0.0 --base-url $(hostname -f)