top | item 42351310

(no title)

gurgeous | 1 year ago

We love just and are using it in all projects now. So great. Our typical justfile has around ~20 rules. Here is an example rule (and helper) to illustrate how we use it in ci:

  export PATH := justfile_directory() + "/node_modules/.bin:" + env_var('PATH')

  ci:
    @just banner yarn install
    yarn install
    @just banner tsc
    tsc --noEmit
    @just banner lint
    eslint src
    prettier --check src
    @just banner vitest
    vitest --run
    @just banner done!
  
  banner *ARGS:
    @printf '\e[42;37;1m[%s] %-72s \e[m\n' "$(date +%H:%M:%S)" "{{ARGS}}"
This example is a bit contrived, more typically we would have a rule like "just lint" and you might call it from "just ci".

One of the best features is that just always runs from the project root directory. Little things like that add up after you've spent years wrestling with bash scripts.

discuss

order

stock_toaster|1 year ago

The banner readability could be slightly improved using constants[1] (and prefixing with _ to hide it from list output).

  # print all available commands by default
  default:
    @just --list

  ci:
    @just _banner yarn install
    yarn install
    @just _banner tsc
    tsc --noEmit
    @just _banner lint
    eslint src
    prettier --check src
    @just _banner vitest
    vitest --run
    @just _banner done!

  _banner *ARGS:
    @printf '{{BOLD + WHITE + BG_GREEN}}[%s] %-72s{{NORMAL}}\n' "$(date +%H:%M:%S)" "{{ARGS}}"

[1]: https://just.systems/man/en/constants.html

alsetmusic|1 year ago

> Little things like that add up after you've spent years wrestling with bash scripts.

Can you please explain what you mean here? I looked at the GitHub examples and wondered why this would be preferable to Bash aliases and functions. I must be missing something.

ricardobeat|1 year ago

Bash has a thousand pitfalls, and as you accumulate layers of scripting they start compounding. Little things like “what the hell directory is this command actually running from”, parsing input parameters, quoting rules, exit statuses, pipelining, etc.

Tools like just provide a very consistent and simple base to start with, and you can always still call a separate script, or drop directly into inline shell scripting.

3eb7988a1663|1 year ago

For me, the niceties are in the built in functions[0]. Commands to manipulate paths(!!), get cpu counts, mess with environment variables, string processing, hashing, etc. All the gyrations a more sophisticated script is going to eventually require. Instead of having to hack on it in shell, you get cross-platform utilities which are not going to blow up because of something as wild as a space or quote mark.

[0] https://just.systems/man/en/functions.html

gcmeplz|1 year ago

I love the look of `just` and have been meaning to try it out, but this feels like one of those examples where Make's dependency management shines—it lets you specify that many of these commands only need to run when particular files change:

    node_modules: package.json yarn.lock
         yarn install --pure-lockfile

    prettier: $(shell find src -type f -iname "\*.ts")
         prettier --check src

    ...

    ci: node_modules prettier eslint vitest

And as time goes on, I always end up wanting to parallelize the commands that can be parallelized (citest, lint, eslint), so I'll turn `make ci` (or `just ci`) into its own little script.