I think many people know the situation when own invented bicycle is not used anywhere later. Therefore, I did not dare to publish this development for a long time, until I noticed that I was dragging it from project to project. And so, one of the essential elements of modern development is the so-called task runners - these are Grunt / Gulp for nodejs, Rake for Ruby, Make for C / C ++, etc. And for the main developer tool - the console - there is nothing like that. More precisely, there is, but, as is usually the case, not quite that. As a result of the research, the Bake tool, a bash scriptr written with the support of a modular structure, was born.
Key Features:
Bake is well suited for automating routine actions, such as starting / restarting necessary services, clearing the cache, creating a directory structure, executing commands for ssh / sftp (for example, for loading configuration data with setting the correct access rights).
The tool is extremely simple to use; all you need is to add task functions to bake.sh
and you can call them from the command line:
bake [OPTIONS] <TASK> [TASK_ARGS]
Tasks are stored in the bake.sh
file. Bake will search for this file in the current directory, if not, then in the parent, up to the root of the system. The directory where bake.sh
is located is the project root and is assigned to the $PWD
variable. Accordingly, all tasks are executed relative to the root, not the current directory, which is stored in the $CWD
variable.
Tasks are functions whose names begin with task:
Example:
task:greet() { echo "Hello World" }
Call from console:
bake greet # -> Hello World
Attention! Hyphens in the task name are replaced with underscores by task:hello_world
can be called by bake hello-world
and bake hello_world
.
The arguments following the task name are passed to the function:
task:greet() { echo "Hello $1" }
bake greet World # -> Hello World
Bake allows you to divide the code into modules and connect them as needed. The modules are stored in the bake_modules directory as scripts, for example ssh.sh
Modules are connected using the bake:module <name>
command. Example:
bake:module ssh # include "bake_modules/ssh.sh" bake:module mysql # include "bake_modules/mysql.sh"
Like Node.js, Bake searches for modules along the ascending path in the bake_modules
directories bake_modules
down to the root of the system. For example, if the current project path is /home/user/projects/my-app
, then the module will be sequentially searched in directories:
/home/user/projects/my-app/bake_modules /home/user/projects/bake_modules /home/user/bake_modules /home/bake_modules /bake_modules
wget https://github.com/rumkin/bake/releases/download/v0.12.5/bake_0.12-5.deb sudo dpkg -i bake_012-5.deb
git clone https://github.com/rumkin/bake sudo cp bake/bake.sh /usr/bin/bake
Source: https://habr.com/ru/post/323956/
All Articles