hgraca / bake
Bash内建的Make-like功能。
v0.2.0
2023-08-12 12:05 UTC
Requires
Requires (Dev)
- ergebnis/composer-normalize: ^2.34
- hgraca/shunit: ^0
README
Bake 是一个用 Bash 编写的类似 Make 的构建系统。
目标是使其比 Make 更容易和更灵活。
如何使用
安装
使用 composer require hgraca\bake
安装。
您需要接受一些插件,以便可以使用 composer 管理bash脚本。
您可以通过运行 sudo ./vendor/bin/bake install
安装 bake 自动完成和全局链接。
全局安装
另外,您还可以全局安装它(在基于 Ubuntu 的发行版上进行了测试)。
使用 composer global require hgraca\bake
安装。
您需要接受一些插件,以便可以使用 composer 管理bash脚本。
您可以通过运行 sudo ~/.composer/vendor/bin/bake install
安装 bake 自动完成和全局链接。
设置 bake 主目录
bake 主目录必须是项目根目录下的 .bake
。
您可以在 bake 主目录的根目录放置一个引导文件,bootstrap.sh
。
配方必须位于 .bake/recipes/...
之下。
可选地,您可以根据环境变量 ENV
创建文件夹,您可以在 bootstrap.sh
中设置此变量。
在 bootstrap.sh
中,您还可以设置日志级别。您可以在这里找到所有日志级别。
示例 bootstrap.sh
#!/usr/bin/env bash
ENV='dev'
export BASH_OVERLAY_LOG_LEVEL=${BASH_OVERLAY_LOG_LEVEL_INFO}
示例 .bake
结构
.
├── .bake/
│ ├── bootstrap.sh
│ ├── recipes/
│ │ ├── global-recipes-file-01.sh
│ │ ├── dev/
│ │ │ ├── recipes-file-01.sh
│ │ │ ├── recipes-file-02.sh
│ │ │ └── ...
│ │ └── test/
│ │ ├── recipes-file-03.sh
│ │ ├── recipes-file-04.sh
│ │ └── ...
│ └── whatever-else/
│ └── ...
├── bin
├── src
├── tests
└── ...
创建和使用配方
在配方文件中,您创建一个以 bake.recipe.<my_recipe>
为前缀的函数,然后像 bake <my_recipe>
一样调用它。
例如,以下是一个配方文件的示例
#!/usr/bin/env bash
########################################################################################################################
# NAMING CONVENTIONS
#
# Please keep the functions ordered alphabetically
#
# Functions names must start with `bake.` so that on the main script we can find the functions available to our "bake".
# Use `.` as a namespace separator (When we double click, it selects only until the `.`)
# Use `-` as a sub separator (When we double click, it selects only until the `-`)
# Use `_` as a word separator (When we double click, it selects including and over the `_`)
#
# Use `.` as the first character in a function name to hide it
#
# At the end of the file place the aliases for backwards compatibility
#
########################################################################################################################
bake.recipe.my_new_command() {
echo ""
echo "==============================================="
echo "===== Hello word, in ${FUNCNAME[0]}, with arguments $* ..."
echo "==============================================="
}
########################################################################################################################
# Aliases for backwards compatibility
###
bake.recipe.my_old_command() {
bake.my_new_command "$@"
}