just
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesejust - Command Runner
just - 命令运行器
IMPORTANT: is the PREFERRED command runner for project task automation. Use Justfiles instead of Makefiles for new projects and task automation.
just重要提示: 是项目任务自动化的首选命令运行器。在新项目和任务自动化中,请使用Justfile而非Makefile。
justCore Philosophy
核心理念
- Justfiles over Makefiles: Prefer just for task automation unless working with existing Make-based projects
- Simple recipes: Keep recipe definitions concise and readable
- Delegate to scripts: For complex logic, call external scripts rather than embedding in recipes
- Just as orchestrator: Use just to coordinate and invoke scripts, not to contain business logic
- 优先使用Justfile而非Makefile:除非处理基于Make的现有项目,否则优先用just进行任务自动化
- 简洁的任务定义:保持任务(recipe)定义简洁易读
- 委托给脚本:对于复杂逻辑,调用外部脚本而非嵌入到任务中
- just作为编排器:用just来协调和调用脚本,而非承载业务逻辑
Basic Usage Patterns
基本使用模式
Running Recipes
运行任务
bash
undefinedbash
undefinedList available recipes
列出可用任务
just --list
just -l
just --list
just -l
Run a recipe
运行任务
just build
just test
just build
just test
Run recipe with arguments
带参数运行任务
just deploy production
just run-test integration
just deploy production
just run-test integration
Run recipe from different directory
在不同目录运行任务
just --working-directory /path/to/project build
just --working-directory /path/to/project build
Choose a different Justfile
指定自定义Justfile
just --justfile custom.just build
undefinedjust --justfile custom.just build
undefinedRecipe Definition Basics
任务定义基础
just
undefinedjust
undefinedSimple recipe
简单任务
build:
cargo build --release
build:
cargo build --release
Recipe with description (shown in --list)
带描述的任务(会在--list中显示)
Run all tests
运行所有测试
test:
cargo test --quiet
test:
cargo test --quiet
Recipe with dependencies (runs setup first)
带依赖的任务(先运行setup)
deploy: build test
./scripts/deploy.sh
deploy: build test
./scripts/deploy.sh
Recipe with parameters
带参数的任务
run-test test_name:
cargo test {{test_name}}
run-test test_name:
cargo test {{test_name}}
Recipe with default parameter value
带默认参数值的任务
serve port="8080":
python -m http.server {{port}}
serve port="8080":
python -m http.server {{port}}
Recipe with multiple parameters
带多个参数的任务
deploy env branch="main":
./scripts/deploy.sh {{env}} {{branch}}
undefineddeploy env branch="main":
./scripts/deploy.sh {{env}} {{branch}}
undefinedDelegation Pattern (PREFERRED)
委托模式(推荐)
Good - Delegates to script:
just
undefined推荐 - 委托给脚本:
just
undefinedBuild the project
构建项目
build:
./scripts/build.sh
build:
./scripts/build.sh
Run integration tests
运行集成测试
test-integration:
./scripts/test-integration.sh
test-integration:
./scripts/test-integration.sh
Deploy to environment
部署到环境
deploy env:
./scripts/deploy.sh {{env}}
**Avoid - Complex logic in recipe:**
```justdeploy env:
./scripts/deploy.sh {{env}}
**避免 - 在任务中编写复杂逻辑:**
```just❌ Too complex - should be in a script
❌ 过于复杂 - 应放到脚本中
deploy env:
#!/usr/bin/env bash
set -euo pipefail
if [ "{{env}}" = "production" ]; then
echo "Deploying to production..."
git fetch origin
git checkout main
git pull
docker build -t app:latest .
docker push registry.example.com/app:latest
kubectl apply -f k8s/production/
kubectl rollout status deployment/app
else
echo "Deploying to staging..."
# ... many more lines ...
fi
**Better - Simple orchestration:**
```justdeploy env:
#!/usr/bin/env bash
set -euo pipefail
if [ "{{env}}" = "production" ]; then
echo "Deploying to production..."
git fetch origin
git checkout main
git pull
docker build -t app:latest .
docker push registry.example.com/app:latest
kubectl apply -f k8s/production/
kubectl rollout status deployment/app
else
echo "Deploying to staging..."
# ... 更多代码行 ...
fi
**更优 - 简单编排:**
```justDeploy to production
部署到生产环境
deploy-prod:
./scripts/deploy.sh production
deploy-prod:
./scripts/deploy.sh production
Deploy to staging
部署到预发布环境
deploy-staging:
./scripts/deploy.sh staging
deploy-staging:
./scripts/deploy.sh staging
Generic deploy with validation
带验证的通用部署
deploy env:
./scripts/validate-env.sh {{env}}
./scripts/deploy.sh {{env}}
undefineddeploy env:
./scripts/validate-env.sh {{env}}
./scripts/deploy.sh {{env}}
undefinedRecipe Features
任务特性
Dependencies
依赖关系
just
undefinedjust
undefinedRecipe runs after its dependencies
任务在其依赖完成后运行
all: clean build test deploy
all: clean build test deploy
Dependencies run in order specified
依赖按指定顺序运行
deploy: build test package
./scripts/deploy.sh
deploy: build test package
./scripts/deploy.sh
Multiple dependency chains
多依赖链
full-deploy: lint build test docker-build docker-push k8s-deploy
undefinedfull-deploy: lint build test docker-build docker-push k8s-deploy
undefinedVariables
变量
just
undefinedjust
undefinedSet variables at top of file
在文件顶部设置变量
version := "1.2.3"
registry := "registry.example.com"
image := registry + "/app:" + version
version := "1.2.3"
registry := "registry.example.com"
image := registry + "/app:" + version
Use in recipes
在任务中使用变量
docker-build:
docker build -t {{image}} .
docker-push:
docker push {{image}}
docker-build:
docker build -t {{image}} .
docker-push:
docker push {{image}}
Environment variables
环境变量
deploy:
API_KEY=$API_KEY ./scripts/deploy.sh
undefineddeploy:
API_KEY=$API_KEY ./scripts/deploy.sh
undefinedConditional Execution
条件执行
just
undefinedjust
undefinedUse shell conditionals in scripts
在脚本中使用shell条件判断
test:
./scripts/test.sh
test:
./scripts/test.sh
Or delegate to script
或委托给脚本
check-and-test:
./scripts/check-and-test.sh
undefinedcheck-and-test:
./scripts/check-and-test.sh
undefinedPrivate Recipes
私有任务
just
undefinedjust
undefinedPrivate recipe (not shown in --list, can't be run directly)
私有任务(不会在--list中显示,无法直接运行)
_setup:
./scripts/setup-env.sh
_setup:
./scripts/setup-env.sh
Public recipe uses private recipe
公开任务调用私有任务
deploy: _setup
./scripts/deploy.sh
undefineddeploy: _setup
./scripts/deploy.sh
undefinedRecipe Attributes
任务属性
just
undefinedjust
undefinedIgnore errors (continue even if fails)
忽略错误(即使失败也继续执行)
[ignore-errors]
lint:
./scripts/lint.sh
[ignore-errors]
lint:
./scripts/lint.sh
Run in specific directory
在指定目录运行
[working-directory: 'frontend']
build-ui:
npm run build
[working-directory: 'frontend']
build-ui:
npm run build
Confirm before running
运行前确认
[confirm]
deploy-prod:
./scripts/deploy.sh production
[confirm]
deploy-prod:
./scripts/deploy.sh production
Don't print recipe before running
运行前不打印任务内容
[no-quiet]
status:
./scripts/status.sh
undefined[no-quiet]
status:
./scripts/status.sh
undefinedCommon Patterns
常见模式
Development Workflow
开发工作流
just
undefinedjust
undefinedDefault recipe (runs when you type 'just')
默认任务(输入'just'时运行)
default: check test
default: check test
Quick validation
快速验证
check:
./scripts/check.sh
check:
./scripts/check.sh
Run all tests
运行所有测试
test:
./scripts/test.sh
test:
./scripts/test.sh
Full CI workflow
完整CI工作流
ci: check test lint build
undefinedci: check test lint build
undefinedBuild Automation
构建自动化
just
undefinedjust
undefinedClean build artifacts
清理构建产物
clean:
./scripts/clean.sh
clean:
./scripts/clean.sh
Build project
构建项目
build:
./scripts/build.sh
build:
./scripts/build.sh
Full rebuild
完整重构建
rebuild: clean build
rebuild: clean build
Build with caching
带缓存的构建
build-cached:
./scripts/build.sh --cache
undefinedbuild-cached:
./scripts/build.sh --cache
undefinedMulti-Environment Deployment
多环境部署
just
undefinedjust
undefinedDevelopment environment
开发环境
dev:
./scripts/run-dev.sh
dev:
./scripts/run-dev.sh
Staging deployment
预发布环境部署
deploy-staging:
./scripts/deploy.sh staging
deploy-staging:
./scripts/deploy.sh staging
Production deployment (with confirmation)
生产环境部署(带确认)
[confirm]
deploy-prod:
./scripts/deploy.sh production
[confirm]
deploy-prod:
./scripts/deploy.sh production
Deploy to any environment
部署到任意环境
deploy env:
./scripts/validate-env.sh {{env}}
./scripts/deploy.sh {{env}}
undefineddeploy env:
./scripts/validate-env.sh {{env}}
./scripts/deploy.sh {{env}}
undefinedDocker Workflows
Docker工作流
just
undefinedjust
undefinedBuild Docker image
构建Docker镜像
docker-build:
./scripts/docker-build.sh
docker-build:
./scripts/docker-build.sh
Run container locally
本地运行容器
docker-run:
./scripts/docker-run.sh
docker-run:
./scripts/docker-run.sh
Push to registry
推送到镜像仓库
docker-push: docker-build
./scripts/docker-push.sh
docker-push: docker-build
./scripts/docker-push.sh
Complete Docker workflow
完整Docker工作流
docker: docker-build docker-push
undefineddocker: docker-build docker-push
undefinedDatabase Operations
数据库操作
just
undefinedjust
undefinedRun migrations
运行迁移
migrate:
./scripts/db-migrate.sh
migrate:
./scripts/db-migrate.sh
Rollback migration
回滚迁移
migrate-rollback:
./scripts/db-rollback.sh
migrate-rollback:
./scripts/db-rollback.sh
Seed database
填充测试数据
seed:
./scripts/db-seed.sh
seed:
./scripts/db-seed.sh
Reset database (dev only)
重置数据库(仅开发环境)
[confirm]
db-reset:
./scripts/db-reset.sh
undefined[confirm]
db-reset:
./scripts/db-reset.sh
undefinedScript Organization
脚本组织
Recommended Structure
推荐结构
project/
├── justfile
├── scripts/
│ ├── build.sh
│ ├── test.sh
│ ├── deploy.sh
│ ├── validate-env.sh
│ └── utils/
│ ├── common.sh
│ └── logging.sh
└── src/
└── ...project/
├── justfile
├── scripts/
│ ├── build.sh
│ ├── test.sh
│ ├── deploy.sh
│ ├── validate-env.sh
│ └── utils/
│ ├── common.sh
│ └── logging.sh
└── src/
└── ...Script Best Practices
脚本最佳实践
Make scripts executable:
bash
chmod +x scripts/*.shUse shebang in scripts:
bash
#!/usr/bin/env bash
set -euo pipefail设置脚本可执行权限:
bash
chmod +x scripts/*.sh在脚本中添加shebang:
bash
#!/usr/bin/env bash
set -euo pipefailScript logic here
脚本逻辑
**Keep scripts focused:**
```bash
**保持脚本专注单一功能:**
```bashGood - single purpose
推荐 - 单一功能
scripts/build.sh
scripts/build.sh
#!/usr/bin/env bash
set -euo pipefail
echo "Building project..."
cargo build --release
**Source common utilities:**
```bash#!/usr/bin/env bash
set -euo pipefail
echo "正在构建项目..."
cargo build --release
**引入通用工具脚本:**
```bashscripts/deploy.sh
scripts/deploy.sh
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/utils/common.sh"
source "$(dirname "$0")/utils/logging.sh"
log_info "Starting deployment..."
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/utils/common.sh"
source "$(dirname "$0")/utils/logging.sh"
log_info "开始部署..."
Deployment logic
部署逻辑
undefinedundefinedAdvanced Features
高级特性
Command Evaluation
命令求值
just
undefinedjust
undefinedBackticks execute shell commands
反引号执行shell命令
commit :=
timestamp :=
git rev-parse --short HEADdate +%Y%m%d-%H%M%Scommit :=
timestamp :=
git rev-parse --short HEADdate +%Y%m%d-%H%M%SUse in recipes
在任务中使用
tag:
echo "Tagging {{commit}} at {{timestamp}}"
undefinedtag:
echo "为{{commit}}打标签,时间:{{timestamp}}"
undefinedMulti-line Constructs
多行结构
just
undefinedjust
undefinedMulti-line variables
多行变量
help := '''
Available commands:
build - Build the project
test - Run tests
deploy - Deploy to production
'''
help := '''
可用命令:
build - 构建项目
test - 运行测试
deploy - 部署到生产环境
'''
Print help
打印帮助信息
help:
@echo {{help}}
undefinedhelp:
@echo {{help}}
undefinedSettings
设置项
just
undefinedjust
undefinedChange shell (default is sh)
修改默认shell(默认是sh)
set shell := ["bash", "-c"]
set shell := ["bash", "-c"]
Make all recipes silent (@echo becomes echo)
所有任务静默运行(@echo变为echo)
set quiet := true
set quiet := true
Use PowerShell on Windows
在Windows上使用PowerShell
set windows-shell := ["powershell.exe", "-c"]
set windows-shell := ["powershell.exe", "-c"]
Use Python for recipes
使用Python执行任务
set shell := ["python3", "-c"]
undefinedset shell := ["python3", "-c"]
undefinedImports
导入
just
undefinedjust
undefinedImport recipes from other files
从其他文件导入任务
import 'ci.just'
import 'deploy.just'
import 'ci.just'
import 'deploy.just'
Use imported recipes
使用导入的任务
all: ci-check deploy-staging
undefinedall: ci-check deploy-staging
undefinedIntegration with Other Tools
与其他工具集成
With Cargo (Rust)
与Cargo(Rust)集成
just
undefinedjust
undefinedRust development workflow
Rust开发工作流
check:
cargo check --quiet
test:
cargo test --quiet
clippy:
cargo clippy
build: check test clippy
cargo build --release
check:
cargo check --quiet
test:
cargo test --quiet
clippy:
cargo clippy
build: check test clippy
cargo build --release
Or delegate to script
或委托给脚本
rust-workflow:
./scripts/rust-workflow.sh
undefinedrust-workflow:
./scripts/rust-workflow.sh
undefinedWith npm/pnpm/yarn
与npm/pnpm/yarn集成
just
undefinedjust
undefinedInstall dependencies
安装依赖
install:
pnpm install
install:
pnpm install
Run dev server
启动开发服务器
dev:
pnpm run dev
dev:
pnpm run dev
Build frontend
构建前端
build:
pnpm run build
build:
pnpm run build
Or use scripts
或使用脚本
ui-build:
./scripts/build-ui.sh
undefinedui-build:
./scripts/build-ui.sh
undefinedWith Docker
与Docker集成
just
undefinedjust
undefinedDocker operations via scripts
通过脚本执行Docker操作
docker-build:
./scripts/docker/build.sh
docker-run:
./scripts/docker/run.sh
docker-compose-up:
docker-compose up -d
undefineddocker-build:
./scripts/docker/build.sh
docker-run:
./scripts/docker/run.sh
docker-compose-up:
docker-compose up -d
undefinedWith Git
与Git集成
just
undefinedjust
undefinedGit workflow helpers
Git工作流助手
sync:
git fetch origin
git pull
push: test
git push origin main
release version:
./scripts/release.sh {{version}}
undefinedsync:
git fetch origin
git pull
push: test
git push origin main
release version:
./scripts/release.sh {{version}}
undefinedComplete Workflow Examples
完整工作流示例
Workflow 1: Web Application
示例1:Web应用
just
undefinedjust
undefinedDefault - run dev server
默认任务 - 启动开发服务器
default: dev
default: dev
Install dependencies
安装依赖
install:
./scripts/install.sh
install:
./scripts/install.sh
Development server
开发服务器
dev:
./scripts/dev.sh
dev:
./scripts/dev.sh
Run tests
运行测试
test:
./scripts/test.sh
test:
./scripts/test.sh
Build for production
生产环境构建
build:
./scripts/build.sh
build:
./scripts/build.sh
Deploy to staging
部署到预发布环境
deploy-staging: test build
./scripts/deploy.sh staging
deploy-staging: test build
./scripts/deploy.sh staging
Deploy to production
部署到生产环境
[confirm]
deploy-prod: test build
./scripts/deploy.sh production
undefined[confirm]
deploy-prod: test build
./scripts/deploy.sh production
undefinedWorkflow 2: Rust Project
示例2:Rust项目
just
undefinedjust
undefinedDefault - check code
默认任务 - 代码检查
default: check
default: check
Fast check
快速检查
check:
cargo check --quiet
check:
cargo check --quiet
Run tests
运行测试
test:
cargo test --quiet
test:
cargo test --quiet
Lint code
代码检查
lint:
cargo clippy
lint:
cargo clippy
Full validation
完整验证
ci: test lint
./scripts/verify-formatting.sh
ci: test lint
./scripts/verify-formatting.sh
Build release
构建发布版本
build:
cargo build --release
build:
cargo build --release
Install binary
安装二进制文件
install: build
cargo install --path .
undefinedinstall: build
cargo install --path .
undefinedWorkflow 3: Monorepo
示例3:单体仓库
just
undefinedjust
undefinedBuild all services
构建所有服务
build-all:
./scripts/build-all.sh
build-all:
./scripts/build-all.sh
Test all services
测试所有服务
test-all:
./scripts/test-all.sh
test-all:
./scripts/test-all.sh
Build specific service
构建指定服务
build-service service:
./scripts/build-service.sh {{service}}
build-service service:
./scripts/build-service.sh {{service}}
Deploy specific service
部署指定服务
deploy service env:
./scripts/deploy-service.sh {{service}} {{env}}
deploy service env:
./scripts/deploy-service.sh {{service}} {{env}}
Full deployment
完整部署
deploy-all env: test-all build-all
./scripts/deploy-all.sh {{env}}
undefineddeploy-all env: test-all build-all
./scripts/deploy-all.sh {{env}}
undefinedCommon Commands Quick Reference
常用命令速查
bash
undefinedbash
undefinedList recipes
列出任务
just --list
just --list
Run recipe
运行任务
just <recipe>
just <recipe>
Run with arguments
带参数运行任务
just <recipe> arg1 arg2
just <recipe> arg1 arg2
Set variable
设置变量
just var=value recipe
just var=value recipe
Choose Justfile
指定Justfile
just --justfile path/to/justfile recipe
just --justfile path/to/justfile recipe
Work in different directory
在指定目录运行
just --working-directory /path recipe
just --working-directory /path recipe
Dry run (show what would run)
空运行(显示将要执行的命令)
just --dry-run recipe
just --dry-run recipe
Verbose output
详细输出
just --verbose recipe
just --verbose recipe
Choose recipe interactively
交互式选择任务
just --choose
undefinedjust --choose
undefinedBest Practices Summary
最佳实践总结
- Keep recipes simple: 1-3 lines max; delegate complex logic to scripts
- Use descriptive names: not
deploy-prod,dpnottest-integrationti - Add comments: Describe what each recipe does
- Organize scripts: Keep scripts in directory with logical subdirectories
scripts/ - Make scripts executable: Use
chmod +x scripts/*.sh - Use dependencies: Chain recipes with dependencies rather than duplicating commands
- Confirm destructive operations: Use for deployments, database resets, etc.
[confirm] - Private recipes for setup: Use naming for internal setup steps
_recipe - Default recipe: Provide sensible default (usually or
dev)check - Document in comments: Add comments explaining complex workflows
- 保持任务简洁:最多1-3行;将复杂逻辑委托给脚本
- 使用描述性名称:用而非
deploy-prod,用dp而非test-integrationti - 添加注释:描述每个任务的作用
- 组织脚本:将脚本放在目录,并按逻辑划分子目录
scripts/ - 设置脚本可执行权限:使用
chmod +x scripts/*.sh - 使用依赖关系:通过依赖链串联任务,而非重复命令
- 对破坏性操作添加确认:对部署、数据库重置等操作使用
[confirm] - 用私有任务做准备工作:用命名格式作为内部准备步骤
_recipe - 设置默认任务:提供合理的默认任务(通常是或
dev)check - 在注释中记录:添加注释说明复杂工作流
When to Use Scripts vs. Recipes
何时使用脚本vs任务
Use Recipe Directly:
直接使用任务:
- Single command execution
- Simple chaining (3 commands or less)
- Setting environment variables for a command
- Quick aliases
- 单命令执行
- 简单串联(3个命令以内)
- 为命令设置环境变量
- 快速别名
Use Script (PREFERRED for most cases):
使用脚本(大多数情况推荐):
- Complex conditional logic
- Multiple steps with error handling
- Reusable logic across recipes
- Long command sequences (>3 commands)
- Anything requiring significant bash scripting
- 复杂条件逻辑
- 带错误处理的多步骤操作
- 可在多个任务间复用的逻辑
- 长命令序列(超过3个命令)
- 任何需要大量bash脚本的场景
Justfile Template
Justfile模板
just
undefinedjust
undefinedSet shell for all recipes
为所有任务设置shell
set shell := ["bash", "-c"]
set shell := ["bash", "-c"]
Variables
变量
version := "1.0.0"
version := "1.0.0"
Default recipe
默认任务
default: check
default: check
List all recipes
列出所有任务
help:
@just --list
help:
@just --list
Development
开发环境
dev:
./scripts/dev.sh
dev:
./scripts/dev.sh
Testing
测试
test:
./scripts/test.sh
test:
./scripts/test.sh
Build
构建
build:
./scripts/build.sh
build:
./scripts/build.sh
Full CI check
完整CI检查
ci: test build
./scripts/verify.sh
ci: test build
./scripts/verify.sh
Deploy to staging
部署到预发布环境
deploy-staging: ci
./scripts/deploy.sh staging
deploy-staging: ci
./scripts/deploy.sh staging
Deploy to production
部署到生产环境
[confirm]
deploy-prod: ci
./scripts/deploy.sh production
[confirm]
deploy-prod: ci
./scripts/deploy.sh production
Clean build artifacts
清理构建产物
clean:
./scripts/clean.sh
undefinedclean:
./scripts/clean.sh
undefinedMigration from Make
从Make迁移
Key Differences from Make
与Make的核心差异
- Not a build system: just is for running commands, not tracking file dependencies
- Recipes always run: Unlike Make targets, recipes run every time (no file timestamp checking)
- Simpler syntax: No need for , tabs vs. spaces issues, etc.
.PHONY - Better error messages: Clear, helpful error output
- 不是构建系统:just用于运行命令,而非跟踪文件依赖
- 任务总是会运行:与Make目标不同,任务每次都会运行(不检查文件时间戳)
- 更简单的语法:无需,无制表符与空格的问题等
.PHONY - 更友好的错误提示:清晰、有用的错误输出
Converting Makefile to Justfile
将Makefile转换为Justfile
Makefile:
make
.PHONY: build test deploy
build:
cargo build --release
test:
cargo test
deploy: build test
./deploy.shJustfile:
just
build:
cargo build --release
test:
cargo test
deploy: build test
./scripts/deploy.shMakefile:
make
.PHONY: build test deploy
build:
cargo build --release
test:
cargo test
deploy: build test
./deploy.shJustfile:
just
build:
cargo build --release
test:
cargo test
deploy: build test
./scripts/deploy.shResources
资源
- Official documentation: https://just.systems
- GitHub repository: https://github.com/casey/just
- Installation: (macOS) or
brew install justcargo install just
- 官方文档:https://just.systems
- GitHub仓库:https://github.com/casey/just
- 安装方式:macOS使用,或使用
brew install justcargo install just