目次
結論
プロジェクトのルートに Justfile というファイルを作ってレシピを書くだけで、just test や just deploy のようにコマンドを呼び出せます。
test:
echo "Running tests..."
cargo test
シェルワンライナーをそのまま書くだけです。
justとは?Makeとの違い
just はRust製のコマンドランナーです。Makefileと同じような感覚で使えますが、ビルドの依存関係解決は行いません。
| 特徴 | Make | just |
|---|---|---|
| 目的 | ビルドシステム | コマンドランナー |
| .PHONY | 必要 | 不要 |
| タブ強制 | あり | スペースでもOK |
| 引数 | 環境変数経由 | 自然に渡せる |
| シェル | /bin/sh固定 | shebangで変更可 |
| Windows対応 | WSL必須 | ネイティブバイナリ |
Makeはビルドツールとして設計されています。ところが最近では npm run build でビルド本体は各言語のツールチェーンに任せるのが普通ですよね。そうなるとMakeに求められるのはコマンドのラッパーだけで、.PHONYを書く儀式が手間になります。
インストール方法
各環境に合わせて選べます。
macOS
brew install just
Windows
scoop install just
winget install --id Casey.Just
Linux
sudo apt-get install just
sudo dnf install just
sudo apk add just
cargo from source
cargo install just
基本的な使い方
Justfileの書き方
プロジェクトルートに Justfile を作ります。
test:
echo "Running tests..."
cargo test
lint:
cargo clippy --all-targets -- -D warnings
デフォルトレシピ
[default]
dev:
just setup
just build
echo "Ready!"
引数の受け渡し
greet name:
echo "Hello, {{name}}!"
build target="debug":
cargo build --{{target}}
変数
version := "1.0.0"
image := "myapp:" + version
build:
docker build -t {{image}} .
echo "Building version {{version}}"
依存関係
setup:
npm install
build: setup
npm run build
test: build
npm test
実践ユースケース
1. Node.js/TypeScriptプロジェクト
node_version := `node --version`
setup:
npm install
@echo "Node {{node_version}} ready"
dev:
npm run dev
lint:
npm run lint
npm run typecheck
test:
npm test
build: lint test
npm run build
docker-build: build
docker build -t myapp:latest .
deploy: docker-build
docker push myapp:latest
clean:
rm -rf node_modules dist
@echo "Cleaned up!"
2. Rustプロジェクト
[default]
test-all: fmt clippy test doc
fmt:
cargo fmt --all -- --check
clippy:
cargo clippy --all-targets -- -D warnings
test:
cargo test --all-features
doc:
cargo doc --no-deps --document-private-items
bench:
cargo bench
release:
cargo build --release
clean:
cargo clean
よくある質問
MakefileからJustfileへの移行は簡単?
かなり簡単です。既存のターゲットをそのままコピーして、タブをスペースに直すくらいで動きます。
justとnpm scriptsの使い分けは?
一つの言語だけで完結しているならnpm scriptsで十分です。複数の言語やツールを扱う場合はjustのほうが一貫性があります。
まとめ
justはコマンドをまとめて管理したい場面にぴったりのツールです。インストールは一発、Justfileの文法は直感的です。
【広告】お名前.comならドメイン取得が格安。![]()
【広告】このサイトはConoHa WINGで運営しています。いつもありがとう!!![]()

コメント