bake 0.10.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -87
- data/bake.gemspec +1 -4
- data/bake.rb +0 -4
- data/gems.rb +6 -0
- data/guides/command-line-interface/README.md +55 -0
- data/guides/gem-integration/README.md +69 -0
- data/guides/getting-started/README.md +109 -0
- data/guides/links.yaml +8 -0
- data/guides/project-integration/README.md +64 -0
- data/lib/bake/base.rb +19 -0
- data/lib/bake/command.rb +1 -0
- data/lib/bake/command/call.rb +1 -0
- data/lib/bake/command/list.rb +43 -19
- data/lib/bake/command/top.rb +3 -2
- data/lib/bake/context.rb +21 -4
- data/lib/bake/documentation.rb +100 -0
- data/lib/bake/loader.rb +9 -12
- data/lib/bake/loaders.rb +15 -18
- data/lib/bake/recipe.rb +43 -22
- data/lib/bake/scope.rb +11 -4
- data/lib/bake/types.rb +2 -0
- data/lib/bake/types/any.rb +35 -8
- data/lib/bake/types/input.rb +42 -0
- data/lib/bake/types/output.rb +42 -0
- data/lib/bake/version.rb +1 -1
- metadata +14 -35
- data/example.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c21d6d91f4610a4abdca6e513279db3532f535b879fd284efd0d93f39915bb1c
|
4
|
+
data.tar.gz: 52648fc8729a487d1873eca3c90a5222a0837a5b66934810e197ee75d7740cc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6642cfd94507b0654e3cfef28a9c89440bae8f2c28b219d3e742c7eb089f3230596c23e0a7c278cd956dcfa3d664ca90d3becb9ebb041539171d3e093f3885da
|
7
|
+
data.tar.gz: f13b33176b5be8a0bc5083e2832022fbb5e8f11c6242d20679f768a35e03e6e92e0db3fe25ead0da5fe7eb5c5b1f8678debfca8913e0725d8878eeb329eb5fdd
|
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
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.
|
4
4
|
|
5
|
-
[](https://github.com/ioquatix/bake/actions?workflow=Development)
|
6
6
|
|
7
|
-
##
|
7
|
+
## Features
|
8
8
|
|
9
9
|
Rake is an awesome tool and loved by the community. So, why reinvent it? Bake provides the following features that Rake does not:
|
10
10
|
|
@@ -15,97 +15,20 @@ Rake is an awesome tool and loved by the community. So, why reinvent it? Bake pr
|
|
15
15
|
|
16
16
|
That being said, Rake and Bake can exist side by side in the same project.
|
17
17
|
|
18
|
-
## Installation
|
19
|
-
|
20
|
-
Execute the following in your project:
|
21
|
-
|
22
|
-
bundle add bake
|
23
|
-
|
24
18
|
## Usage
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-

|
29
|
-
|
30
|
-
## Bakefile
|
31
|
-
|
32
|
-
There is a root level `bake.rb` e.g.:
|
33
|
-
|
34
|
-
```ruby
|
35
|
-
def cake
|
36
|
-
ingredients = call 'supermarket:shop', 'flour,sugar,cocoa'
|
37
|
-
lookup('mixer:add').call(ingredients)
|
38
|
-
end
|
39
|
-
```
|
40
|
-
|
41
|
-
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.
|
42
|
-
|
43
|
-
## Recipes
|
44
|
-
|
45
|
-
Alongside the `bake.rb`, there is a `bake/` directory which contains files like `supermarket.rb`. These files contain recipes, e.g.:
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
# @param ingredients [Array(Any)] the ingredients to purchase.
|
49
|
-
def shop(ingredients)
|
50
|
-
supermarket = Supermarket.best
|
51
|
-
|
52
|
-
return supermarket.purchase(ingredients)
|
53
|
-
end
|
54
|
-
```
|
55
|
-
|
56
|
-
These methods are automatically scoped according to the file name, e.g. `bake/supermarket.rb` will define `supermarket:shop`.
|
57
|
-
|
58
|
-
## Gems
|
20
|
+
Please see the [project documentation](https://ioquatix.github.io/bake/).
|
59
21
|
|
60
|
-
|
61
|
-
|
62
|
-
```ruby
|
63
|
-
def setup
|
64
|
-
# ...
|
65
|
-
end
|
66
|
-
```
|
67
|
-
|
68
|
-
Then, in your project `myproject` which depends on `mygem`:
|
69
|
-
|
70
|
-
```
|
71
|
-
bake mygem:setup
|
72
|
-
```
|
73
|
-
|
74
|
-
## Arguments
|
75
|
-
|
76
|
-
Arguments work as normal. Documented types are used to parse strings from the command line. Both positional and optional parameters are supported.
|
77
|
-
|
78
|
-
### Positional Parameters
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
# @param x [Integer]
|
82
|
-
# @param y [Integer]
|
83
|
-
def add(x, y)
|
84
|
-
puts x + y
|
85
|
-
end
|
86
|
-
```
|
87
|
-
|
88
|
-
Which is invoked by `bake add 1 2`.
|
89
|
-
|
90
|
-
### Optional Parameters
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
# @param x [Integer]
|
94
|
-
# @param y [Integer]
|
95
|
-
def add(x:, y:)
|
96
|
-
puts x + y
|
97
|
-
end
|
98
|
-
```
|
22
|
+
## Contributing
|
99
23
|
|
100
|
-
|
24
|
+
We welcome contributions to this project.
|
101
25
|
|
102
|
-
|
26
|
+
1. Fork it.
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
30
|
+
5. Create new Pull Request.
|
103
31
|
|
104
|
-
1. Fork it
|
105
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
106
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
107
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
108
|
-
5. Create new Pull Request
|
109
32
|
|
110
33
|
## See Also
|
111
34
|
|
data/bake.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.metadata["donation_uri"] = "https://github.com/sponsors/ioquatix"
|
15
15
|
|
16
16
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(docs|test|spec|features)/}) }
|
18
18
|
end
|
19
19
|
|
20
20
|
spec.bindir = "bin"
|
@@ -23,10 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency 'samovar', '~> 2.1'
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bake-bundler'
|
27
|
-
|
28
26
|
spec.add_development_dependency 'covered'
|
29
27
|
spec.add_development_dependency 'bundler'
|
30
28
|
spec.add_development_dependency 'rspec'
|
31
|
-
spec.add_development_dependency 'rake'
|
32
29
|
end
|
data/bake.rb
CHANGED
data/gems.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Command Line Interface
|
2
|
+
|
3
|
+
The `bake` command is broken up into two main functions: `list` and `call`.
|
4
|
+
|
5
|
+
<pre>% bake --help
|
6
|
+
<b>bake [-h/--help] [-b/--bakefile <path>] <command></b>
|
7
|
+
<font color="#638FFF">Execute tasks using Ruby.</font>
|
8
|
+
|
9
|
+
[-h/--help] Show help.
|
10
|
+
[-b/--bakefile <path>] Override the path to the bakefile to use.
|
11
|
+
<command> One of: call, list. (default: call)
|
12
|
+
|
13
|
+
<b>call <commands...></b>
|
14
|
+
<font color="#638FFF">Execute one or more commands.</font>
|
15
|
+
|
16
|
+
<commands...> The commands & arguments to invoke. (default: ["default"])
|
17
|
+
|
18
|
+
<b>list <pattern></b>
|
19
|
+
<pattern> The pattern to filter tasks by.
|
20
|
+
</pre>
|
21
|
+
|
22
|
+
## List
|
23
|
+
|
24
|
+
The `bake list` command allows you to list all available recipes. By proving a pattern you will only see recipes that have a matching command name.
|
25
|
+
|
26
|
+
<pre>$ bake list console
|
27
|
+
<b>Bake::Loader console-1.8.2</b>
|
28
|
+
|
29
|
+
<b>console:info</b>
|
30
|
+
<font color="#638FFF">Increase the verbosity of the logger to info.</font>
|
31
|
+
|
32
|
+
<b>console:debug</b>
|
33
|
+
<font color="#638FFF">Increase the verbosity of the logger to debug.</font>
|
34
|
+
</pre>
|
35
|
+
|
36
|
+
The listing documents positional and optional arguments. The documentation is generated from the comments in the bakefiles.
|
37
|
+
|
38
|
+
## Call
|
39
|
+
|
40
|
+
The `bake call` (the default, so `call` can be omitted) allows you to execute one or more recipes. You must provide the name of the command, followed by any arguments.
|
41
|
+
|
42
|
+
<pre>$ bake async:http:head https://www.codeotaku.com/index
|
43
|
+
<font color="#638FFF"><b> HEAD</b></font>: https://www.codeotaku.com/index
|
44
|
+
<font color="#00AA00"><b> version</b></font>: h2
|
45
|
+
<font color="#00AA00"><b> status</b></font>: 200
|
46
|
+
<font color="#00AA00"><b> body</b></font>: body with length <b>7879B</b>
|
47
|
+
<b> content-type</b>: "text/html; charset=utf-8"
|
48
|
+
<b> cache-control</b>: "public, max-age=3600"
|
49
|
+
<b> expires</b>: "Mon, 04 May 2020 13:23:47 GMT"
|
50
|
+
<b> server</b>: "falcon/0.36.4"
|
51
|
+
<b> date</b>: "Mon, 04 May 2020 12:23:47 GMT"
|
52
|
+
<b> vary</b>: "accept-encoding"
|
53
|
+
</pre>
|
54
|
+
|
55
|
+
You can specify multiple commands and they will be executed sequentially.
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Gem Integration
|
2
|
+
|
3
|
+
This guide explains how to add `bake` to a Ruby gem and export standardised tasks for use by other gems and projects.
|
4
|
+
|
5
|
+
## Exporting Tasks
|
6
|
+
|
7
|
+
Adding a `bake/` 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 `mygem/bake/mygem.rb`:
|
8
|
+
|
9
|
+
~~~ ruby
|
10
|
+
def setup
|
11
|
+
# ...
|
12
|
+
end
|
13
|
+
~~~
|
14
|
+
|
15
|
+
Then, in a different project which depends on `mygem`, you can run tasks from `mygem` by invoking them using `bake`:
|
16
|
+
|
17
|
+
~~~ bash
|
18
|
+
$ bake mygem:setup
|
19
|
+
~~~
|
20
|
+
|
21
|
+
## Examples
|
22
|
+
|
23
|
+
There are many gems which export tasks in this way. Here are some notable examples:
|
24
|
+
|
25
|
+
### Variant
|
26
|
+
|
27
|
+
The [variant gem](https://github.com/socketry/variant) exposes bake tasks for setting the environment e.g. `development`, `testing`, or `production`.
|
28
|
+
|
29
|
+
<pre class="terminal">$ bake list variant
|
30
|
+
<b>Bake::Loader variant-0.1.1</b>
|
31
|
+
|
32
|
+
<b>variant:production</b> <font color="#00AA00">**overrides</font>
|
33
|
+
<font color="#638FFF">Select the production variant.</font>
|
34
|
+
<font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
|
35
|
+
|
36
|
+
<b>variant:staging</b> <font color="#00AA00">**overrides</font>
|
37
|
+
<font color="#638FFF">Select the staging variant.</font>
|
38
|
+
<font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
|
39
|
+
|
40
|
+
<b>variant:development</b> <font color="#00AA00">**overrides</font>
|
41
|
+
<font color="#638FFF">Select the development variant.</font>
|
42
|
+
<font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
|
43
|
+
|
44
|
+
<b>variant:testing</b> <font color="#00AA00">**overrides</font>
|
45
|
+
<font color="#638FFF">Select the testing variant.</font>
|
46
|
+
<font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
|
47
|
+
|
48
|
+
<b>variant:force</b> <font color="#AA0000">name</font> <font color="#00AA00">**overrides</font>
|
49
|
+
<font color="#638FFF">Force a specific variant.</font>
|
50
|
+
<font color="#00AA00">name</font> [Symbol] <font color="#638FFF">the default variant.</font>
|
51
|
+
<font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
|
52
|
+
|
53
|
+
<b>variant:show</b>
|
54
|
+
<font color="#638FFF">Show variant-related environment variables.</font>
|
55
|
+
</pre>
|
56
|
+
|
57
|
+
### Console
|
58
|
+
|
59
|
+
The [console gem](https://github.com/socketry/console) exposes bake tasks to change the log level.
|
60
|
+
|
61
|
+
<pre class="terminal">$ bake list console
|
62
|
+
<b>Bake::Loader console-1.8.2</b>
|
63
|
+
|
64
|
+
<b>console:info</b>
|
65
|
+
<font color="#638FFF">Increase the verbosity of the logger to info.</font>
|
66
|
+
|
67
|
+
<b>console:debug</b>
|
68
|
+
<font color="#638FFF">Increase the verbosity of the logger to debug.</font>
|
69
|
+
</pre>
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Getting Started
|
2
|
+
|
3
|
+
This guide gives a general overview of `bake` and how to use it.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to your project:
|
8
|
+
|
9
|
+
~~~ bash
|
10
|
+
$ bundle add bake
|
11
|
+
~~~
|
12
|
+
|
13
|
+
## Core Concepts
|
14
|
+
|
15
|
+
`bake` has several core concepts:
|
16
|
+
|
17
|
+
- A `bake` executable used for invoking one or more tasks.
|
18
|
+
- A {ruby Bake::Context} instance which is bound to a project or gem and exposes a hierarchy of runnable tasks.
|
19
|
+
- A {ruby Bake::Loaders} instance which is used for on-demand loading of bake files from the current project and all available gems.
|
20
|
+
|
21
|
+
## Executing Tasks
|
22
|
+
|
23
|
+
The `bake` executable can be used to execute tasks in a `bake.rb` file in the same directory.
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
# bake.rb
|
27
|
+
|
28
|
+
def add(x, y)
|
29
|
+
puts Integer(x) + Integer(y)
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
You can execute this task from the command line:
|
34
|
+
|
35
|
+
``` shell
|
36
|
+
% bake add 10 20
|
37
|
+
30
|
38
|
+
```
|
39
|
+
|
40
|
+
### Using Types
|
41
|
+
|
42
|
+
You can annotate your task with a type signature and `bake` will coerce your arguments to these types:
|
43
|
+
|
44
|
+
``` ruby
|
45
|
+
# bake.rb
|
46
|
+
|
47
|
+
# @parameter x [Integer]
|
48
|
+
# @parameter y [Integer]
|
49
|
+
def add(x, y)
|
50
|
+
puts x + y
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
You can execute this task from the command line:
|
55
|
+
|
56
|
+
``` shell
|
57
|
+
% bake add 10 20
|
58
|
+
30
|
59
|
+
```
|
60
|
+
|
61
|
+
The values are automatically coerced to `Integer`.
|
62
|
+
|
63
|
+
### Extending With Documentation
|
64
|
+
|
65
|
+
You can add documentation to your tasks and parameters (using Markdown formatting).
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
# bake.rb
|
69
|
+
|
70
|
+
# Add the x and y coordinate together and print the result.
|
71
|
+
# @parameter x [Integer] The x offset.
|
72
|
+
# @parameter y [Integer] The y offset.
|
73
|
+
def add(x, y)
|
74
|
+
puts x + y
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
You can see this documentation in the task listing:
|
79
|
+
|
80
|
+
``` shell
|
81
|
+
% bake list add
|
82
|
+
Bake::Context getting-started
|
83
|
+
|
84
|
+
add x y
|
85
|
+
Add the x and y coordinate together and print the result.
|
86
|
+
x [Integer] The x offset.
|
87
|
+
y [Integer] The y offset.
|
88
|
+
```
|
89
|
+
|
90
|
+
### Private Methods
|
91
|
+
|
92
|
+
If you want to add helper methods which don't show up as tasks, define them as `protected` or `private`.
|
93
|
+
|
94
|
+
``` ruby
|
95
|
+
# bake.rb
|
96
|
+
|
97
|
+
# Add the x and y coordinate together and print the result.
|
98
|
+
# @parameter x [Integer] The x offset.
|
99
|
+
# @parameter y [Integer] The y offset.
|
100
|
+
def add(x, y)
|
101
|
+
puts x + y
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def puts(*arguments)
|
107
|
+
$stdout.puts arguments.inspect
|
108
|
+
end
|
109
|
+
```
|
data/guides/links.yaml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Project Integration
|
2
|
+
|
3
|
+
This guide explains how to add `bake` to a Ruby project.
|
4
|
+
|
5
|
+
## Bakefile
|
6
|
+
|
7
|
+
At the top level of your project, you can create a `bake.rb` file, which contains top level tasks which are private to your project.
|
8
|
+
|
9
|
+
~~~ ruby
|
10
|
+
def cake
|
11
|
+
ingredients = call 'supermarket:shop', 'flour,sugar,cocoa'
|
12
|
+
lookup('mixer:add').call(ingredients)
|
13
|
+
end
|
14
|
+
~~~
|
15
|
+
|
16
|
+
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.
|
17
|
+
|
18
|
+
## Recipes
|
19
|
+
|
20
|
+
Alongside the `bake.rb`, there is a `bake/` directory which contains files like `supermarket.rb`. These files contain recipes, e.g.:
|
21
|
+
|
22
|
+
~~~ ruby
|
23
|
+
# @param ingredients [Array(Any)] the ingredients to purchase.
|
24
|
+
def shop(ingredients)
|
25
|
+
supermarket = Supermarket.best
|
26
|
+
|
27
|
+
return supermarket.purchase(ingredients)
|
28
|
+
end
|
29
|
+
~~~
|
30
|
+
|
31
|
+
These methods are automatically scoped according to the file name, e.g. `bake/supermarket.rb` will define `supermarket:shop`.
|
32
|
+
|
33
|
+
|
34
|
+
## Arguments
|
35
|
+
|
36
|
+
Arguments work as normal. Documented types are used to parse strings from the command line. Both positional and optional parameters are supported.
|
37
|
+
|
38
|
+
### Positional Parameters
|
39
|
+
|
40
|
+
Positional parameters are non-keyword parameters which may have a default value. However, because of the limits of the command line, all positional arguments must be specified.
|
41
|
+
|
42
|
+
~~~ ruby
|
43
|
+
# @param x [Integer]
|
44
|
+
# @param y [Integer]
|
45
|
+
def add(x, y)
|
46
|
+
puts x + y
|
47
|
+
end
|
48
|
+
~~~
|
49
|
+
|
50
|
+
Which is invoked by `bake add 1 2`.
|
51
|
+
|
52
|
+
### Optional Parameters
|
53
|
+
|
54
|
+
Optional parameters are keyword parameters which may have a default value. The parameter is set on the command line using the name of the parameter followed by an equals sign, followed by the value.
|
55
|
+
|
56
|
+
~~~ ruby
|
57
|
+
# @param x [Integer]
|
58
|
+
# @param y [Integer]
|
59
|
+
def add(x:, y: 2)
|
60
|
+
puts x + y
|
61
|
+
end
|
62
|
+
~~~
|
63
|
+
|
64
|
+
Which is invoked by `bake add x=1`. Because `y` is not specified, it will default to `2` as per the method definition.
|