justfile について
プロジェクト固有のコマンドを実行するjustと、justfileの構文を扱うスキルです。繰り返し使うコマンドを整理したい開発者向けに、レシピ、変数、設定、条件分岐の例を示します。
主な機能
- 01既定および名前付きレシピの定義
- 02変数と環境変数の設定
- 03シェルとdotenv読み込みの設定
- 04OSとアーキテクチャによる分岐
- 05コマンドの一覧・確認・整形
活用シーン
- 01プロジェクトのビルドコマンドをまとめる
- 02引数付きの開発タスクを作成
- 03OSやアーキテクチャ別にインストールを選択
- 04GitHub Actionsでjustを実行
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ mizchi/ skills --skill justfileインストール後、Claude Code で/justfileを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
README.md.claude-plugin/manifest.jsonassets/gh_action_example.yamljustfile詳細
justfile スキル
just は、プロジェクト固有のコマンドを実行するためのコマンドランナーです。Make と似ていますが、よりシンプルです。
基本構文
# Default recipe (runs when just is called without arguments)
default:
@echo "Available: just --list"
# Basic recipe
build:
cargo build --release
# Dependencies
test: build
cargo test
# Arguments
greet name:
echo "Hello, {{name}}!"
# Default arguments
serve port="8080":
python -m http.server {{port}}
# Variadic arguments
run *args:
cargo run -- {{args}}
変数
# String
version := "1.0.0"
# Shell command result
git_hash := `git rev-parse --short HEAD`
# Environment variable with default
home := env_var_or_default("HOME", "/tmp")
# Usage
info:
echo "Version: {{version}}, Hash: {{git_hash}}"
設定
# Shell
set shell := ["bash", "-cu"]
# Load .env
set dotenv-load
# Continue on error
set ignore-errors
# Suppress command echo
set quiet
# Working directory
set working-directory := "subdir"
条件分岐
# OS detection
install:
{{if os() == "macos" { "brew install foo" } else { "apt install foo" }}}
# Architecture detection
build:
{{if arch() == "aarch64" { "make arm" } else { "make x86" }}}
組み込み関数
| 関数 | 説明 |
|---|---|
os() | OS 名(linux、macos、windows) |
arch() | アーキテクチャ(x86_64、aarch64) |
env_var("NAME") | 環境変数を取得します |
justfile_directory() | justfile を含むディレクトリ |
invocation_directory() | just を呼び出したディレクトリ |
よく使うコマンド
just # Run default recipe
just recipe # Run specific recipe
just recipe arg # Run with arguments
just --list # List recipes
just --dry-run # Show without running
just --choose # Select with fzf
just --fmt # Format justfile
GitHub Actions
extractions/setup-just@v4 を使用します。完全な例については assets/gh_action_example.yaml を参照してください。
steps:
- uses: actions/checkout@v7
- uses: extractions/setup-just@v4
# with:
# just-version: '1.58.0' # Optional pin (latest as of 2026-09)
- run: just build
- run: just test
実践例
set dotenv-load
set shell := ["bash", "-cu"]
default:
@just --list
# Dev server
dev:
npm run dev
# Build
build:
npm run build
# Test
test *args:
npm test {{args}}
# Lint + format
check:
npm run lint
npm run format:check
# CI (called from GitHub Actions)
ci: check build test
# Release
release version:
git tag -a v{{version}} -m "Release v{{version}}"
git push origin v{{version}}
# Cleanup
clean:
rm -rf dist node_modules
参考資料
コメント
Markdown 対応