way-magefile
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMage
Mage
Mage is a make-like build tool using Go. You write plain-old go functions, and Mage automatically uses them as Makefile-like runnable targets.
Mage是一款类Make的Go语言构建工具。你可以编写普通的Go函数,Mage会自动将它们作为类Makefile的可运行目标。
When to Use
适用场景
- Creating build scripts for Go projects.
- Automating tasks (install, build, clean, release).
- Managing dependencies between tasks.
- 为Go项目创建构建脚本。
- 自动化任务(安装、构建、清理、发布)。
- 管理任务之间的依赖关系。
Core Concepts
核心概念
1. Magefiles
1. Magefile
- Any Go file with (or
//go:build magefor older Go).+build mage - Usually named or placed in
magefile.godirectory.magefiles/ - .
package main
- 任何包含的Go文件(旧版Go使用
//go:build mage)。+build mage - 通常命名为或放置在
magefile.go目录下。magefiles/ - 包声明为。
package main
2. Targets
2. 目标(Targets)
- Exported functions with specific signatures:
func Target()func Target() errorfunc Target(ctx context.Context) error- First sentence of doc comment is the short description ().
mage -l
- 具有特定签名的导出函数:
func Target()func Target() errorfunc Target(ctx context.Context) error- 文档注释的第一句是简短描述(可通过查看)。
mage -l
3. Dependencies
3. 依赖关系
- Use to declare dependencies.
mg.Deps(Func) - Dependencies run exactly once per execution.
- runs in parallel;
mg.Depsruns serially.mg.SerialDeps
- 使用声明依赖。
mg.Deps(Func) - 每个依赖在每次执行中仅运行一次。
- 并行运行依赖;
mg.Deps串行运行依赖。mg.SerialDeps
Quick Start
快速开始
To create a new magefile:
mage -init创建新的magefile:
mage -initCommon Tasks
常见任务
Running Commands:
Use for shell execution.
github.com/magefile/mage/shgo
import "github.com/magefile/mage/sh"
// ...
err := sh.Run("go", "build", "./...")Clean Up:
go
import "github.com/magefile/mage/sh"
// ...
sh.Rm("bin")运行命令:
使用执行shell命令。
github.com/magefile/mage/shgo
import "github.com/magefile/mage/sh"
// ...
err := sh.Run("go", "build", "./...")清理:
go
import "github.com/magefile/mage/sh"
// ...
sh.Rm("bin")References
参考资料
- Way Conventions: See references/way-style.md for Way-specific patterns and helpers.
- API Documentation: See references/api.md for ,
mg, andshpackage details.target - Examples: See references/examples.md for common patterns.
- Way约定:查看references/way-style.md获取Way专属的模式与工具函数。
- API文档:查看references/api.md了解、
mg和sh包的详细信息。target - 示例:查看references/examples.md获取常见使用模式。