Bake is a task execution tool, inspired by Rake, but codifying many of the use cases which are typically implemented in an ad-hoc manner.
Rake is an awesome tool and loved by the community. So, why reinvent it? Bake provides the following features that Rake does not:
- On demand loading of files following a standard convention. This avoid loading all your rake tasks just to execute a single command.
- Better argument handling including support for positional and optional arguments.
- Focused on task execution not dependency resolution. Implementation is simpler and a bit more predictable.
- Canonical structure for integration with gems.
That being said, Rake and Bake can exist side by side in the same project.
Execute the following in your project:
bundle add bake
Bake follows similar patterns to Rake.
There is a root level
bake.rb which contains project-specific configuration and recipes, e.g.:
recipe :cake do call 'supermarket:shop', 'flour,sugar,cocoa' call 'mixer:add', 'everything' end
This file is project specific and is the only file which can expose top level tasks (i.e. without a defined namespace). When used in a gem, these tasks are not exposed to other gems/projects.
bake.rb, there is a
recipes/ directory which contains files like
supermarket.rb. These files contain recipes, e.g.:
recipe :shop do |ingredients| supermarket = Supermarket.best supermarket.shop(ingredients.split(",")) end
These recipes are automatically scoped according to the file name, e.g.
recipe :shop will define
recipes/ directory to your gem will allow other gems and projects to consume those recipes. In order to prevent collisions, you should prefix your commands with the name of the gem, e.g. in
recipe :setup do # ... end
Then, in your project
myproject which depends on
Both positional and optional parameters are supported, e.g.:
recipe :add do |x, y| puts Integer(x) + Integer(y) end
Which is invoked by
bake add 1 2.
recipe :add do |x:, y:| puts Integer(x) + Integer(y) end
Which is invoked by
bake add x=1 y=2.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
- Utopia — A website framework which uses bake for maintenance tasks.
Released under the MIT license.
Copyright, 2020, by Samuel G. D. Williams.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.