bake 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5064c2fb5970db1bfd61752e337a35cb1130655d2aa712cac405c4ef9b5ac99
4
- data.tar.gz: 34c28cb42f472d9cdb02bcde6576a784d7b9a1beeda8ffde67ddd1a16e7b2cdd
3
+ metadata.gz: 50c70583a03c13bc968e740c99eb323b533d650d2f4bdf0184cd3545ddbdfb01
4
+ data.tar.gz: 50c90c5e197996e3e95f4cabd57a19e1bb0708e9acfe0302f8b33cf734acf0b7
5
5
  SHA512:
6
- metadata.gz: 2aba107faf34db34af932925c0c6ba34fb906a7bd68a10c5ae286f537ba2ad1b085e01a3d7390f88225809fdf0570edb81522e8df98ff7f476b2b22613de5e98
7
- data.tar.gz: 5e75149322e7668879aaee32eea149dfdcbb98540f60bb29695fd4e5651a917b04f75d957a4710f77d5067e43e4eeb855d010ff31e85daa27ad3e700073fdacd
6
+ metadata.gz: 387d065fd0260080f352043f6288a59527944eb7d8b20af09285b39bafa7b6aedf3490ca497aadcdc4835cf0e2e518f1291998a3cc60292d6088b3eeba779b4c
7
+ data.tar.gz: 99d16f46df97a26509933df503906d1117487e07ab26e9d526c609128e95902219478ec98fedf3cd9b2ef01603d8a5cdbcf8c280fff4bf9c8bbe5e69d73e6ec5
@@ -0,0 +1,35 @@
1
+ name: Development
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ matrix:
9
+ os:
10
+ - ubuntu
11
+ - macos
12
+
13
+ ruby:
14
+ - 2.5
15
+ - 2.6
16
+ - 2.7
17
+
18
+ include:
19
+ - os: 'ubuntu'
20
+ ruby: '2.6'
21
+ env: COVERAGE=PartialSummary,Coveralls
22
+
23
+ runs-on: ${{matrix.os}}-latest
24
+
25
+ steps:
26
+ - uses: actions/checkout@v1
27
+ - uses: actions/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{matrix.ruby}}
30
+ - name: Install dependencies
31
+ run: |
32
+ command -v bundler || gem install bundler
33
+ bundle install
34
+ - name: Run tests
35
+ run: ${{matrix.env}} bundle exec rspec
data/.gitignore CHANGED
@@ -7,5 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ gems.locked
11
+
10
12
  # rspec failure tracking
11
13
  .rspec_status
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Bake
1
+ # Bake ![Development](https://github.com/ioquatix/bake/workflows/Development/badge.svg)
2
2
 
3
- Bake is a task execution tool, inspired by Rake, but codifying many of the typical use cases which are typically implemented in an ad-hoc manner.
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
+
5
+ ![Example](example.png)
4
6
 
5
7
  ## Motivation
6
8
 
@@ -28,27 +30,30 @@ Bake follows similar patterns to Rake.
28
30
  There is a root level `bake.rb` which contains project-specific configuration and recipes, e.g.:
29
31
 
30
32
  ```ruby
31
- recipe :deploy do
32
- call 'activerecord:migrations:deploy'
33
- call 'falcon:server:restart'
33
+ recipe :cake do
34
+ call 'supermarket:shop', 'flour,sugar,cocoa'
35
+ call 'mixer:add', 'everything'
34
36
  end
35
37
  ```
36
38
 
37
- This file is project specific and is the only file which can expose top level tasks (i.e. without a defined namespace).
39
+ 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.
38
40
 
39
41
  ## Recipes
40
42
 
41
- Alongside the `bake.rb`, there is a `recipes/` directory which contains files like `icons.rb`. These files contain recipes, e.g.:
43
+ Alongside the `bake.rb`, there is a `recipes/` directory which contains files like `supermarket.rb`. These files contain recipes, e.g.:
42
44
 
43
45
  ```ruby
44
- recipe :generate do |name|
45
- MyProject::Icons::Generate.call(name)
46
+ recipe :shop do |ingredients|
47
+ supermarket = Supermarket.best
48
+ supermarket.shop(ingredients.split(","))
46
49
  end
47
50
  ```
48
51
 
52
+ These recipes are automatically scoped according to the file name, e.g. `recipes/supermarket.rb` with `recipe :shop` will define `supermarket:shop`.
53
+
49
54
  ## Gems
50
55
 
51
- Adding a `recipes/` directory to your gem, will expose those tasks to any project that depends on your gem. In order to prevent collisions, imported commands are prefixed with the name of the gem. If you want to provide top level commands, you may do so by naming a recipe the same as the namespace which encloses it, e.g. in `mygem/recipes/setup.rb`:
56
+ Adding a `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 `mygem/recipes/mygem.rb`:
52
57
 
53
58
  ```ruby
54
59
  recipe :setup do
@@ -62,6 +67,30 @@ Then, in your project `myproject` which depends on `mygem`:
62
67
  bake mygem:setup
63
68
  ```
64
69
 
70
+ ## Arguments
71
+
72
+ Both positional and optional parameters are supported, e.g.:
73
+
74
+ ### Positional Parameters
75
+
76
+ ```ruby
77
+ recipe :add do |x, y|
78
+ puts Integer(x) + Integer(y)
79
+ end
80
+ ```
81
+
82
+ Which is invoked by `bake add 1 2`.
83
+
84
+ ### Optional Parameters
85
+
86
+ ```ruby
87
+ recipe :add do |x:, y:|
88
+ puts Integer(x) + Integer(y)
89
+ end
90
+ ```
91
+
92
+ Which is invoked by `bake add x=1 y=2`.
93
+
65
94
  ## Contributing
66
95
 
67
96
  1. Fork it
@@ -22,4 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_dependency 'samovar', '~> 2.1'
25
+
26
+ spec.add_development_dependency 'covered'
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rake'
25
30
  end
Binary file
@@ -3,5 +3,3 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in bake.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
@@ -69,11 +69,5 @@ module Bake
69
69
 
70
70
  @recipes[name] = Recipe.new(self, name, **options, &block)
71
71
  end
72
-
73
- def attach(name, callable, **options)
74
- @recipes[name] = Recipe.new(self, name, **options) do |*arguments, **options|
75
- callable.call(*arguments, **options)
76
- end
77
- end
78
72
  end
79
73
  end
@@ -53,7 +53,7 @@ module Bake
53
53
  return nil
54
54
  end
55
55
 
56
- many :commands, "The commands & arguments to invoke."
56
+ many :commands, "The commands & arguments to invoke.", default: ["default"]
57
57
 
58
58
  def call
59
59
  context = @parent.context
@@ -26,6 +26,8 @@ module Bake
26
26
  def format_parameters(parameters, terminal)
27
27
  parameters.each do |type, name|
28
28
  case type
29
+ when :key
30
+ name = "#{name}="
29
31
  when :keyreq
30
32
  name = "#{name}="
31
33
  when :keyrest
@@ -34,7 +36,8 @@ module Bake
34
36
  name = name.to_s
35
37
  end
36
38
 
37
- terminal.print(type, name, " ")
39
+ terminal.print(:reset, " ")
40
+ terminal.print(type, name)
38
41
  end
39
42
  end
40
43
 
@@ -42,12 +45,12 @@ module Bake
42
45
  terminal.print(:command, recipe.command)
43
46
 
44
47
  if parameters = recipe.parameters
45
- terminal.write(" ")
46
48
  format_parameters(parameters, terminal)
47
49
  end
48
50
  end
49
51
 
50
52
  def call
53
+ first = true
51
54
  terminal = @parent.terminal
52
55
  context = @parent.context
53
56
  format_recipe = self.method(:format_recipe).curry
@@ -56,19 +59,35 @@ module Bake
56
59
  terminal.print_line(:loader, context)
57
60
 
58
61
  context.each do |recipe|
62
+ terminal.print_line
59
63
  terminal.print_line("\t", format_recipe[recipe])
64
+ if description = recipe.description
65
+ terminal.print_line("\t\t", :description, description)
66
+ end
60
67
  end
68
+
69
+ terminal.print_line
61
70
  end
62
71
 
63
72
  context.loaders.each do |loader|
73
+ terminal.print_line unless first
74
+ first = false
75
+
64
76
  terminal.print_line(:loader, loader)
65
77
  loader.each do |path|
66
78
  if book = loader.lookup(path)
79
+ # terminal.print_line("\t", book)
67
80
  book.each do |recipe|
81
+ terminal.print_line
68
82
  terminal.print_line("\t", format_recipe[recipe])
83
+ if description = recipe.description
84
+ terminal.print_line("\t\t", :description, description)
85
+ end
69
86
  end
70
87
  end
71
88
  end
89
+
90
+ terminal.print_line
72
91
  end
73
92
  end
74
93
  end
@@ -61,9 +61,10 @@ module Bake
61
61
  terminal = Console::Terminal.for(out)
62
62
 
63
63
  terminal[:loader] = terminal.style(nil, nil, :bold)
64
- terminal[:command] = terminal.style(:blue)
64
+ terminal[:command] = terminal.style(nil, nil, :bold)
65
+ terminal[:description] = terminal.style(:blue)
65
66
 
66
- terminal[:opt] = terminal.style(:green)
67
+ terminal[:key] = terminal[:opt] = terminal.style(:green)
67
68
  terminal[:req] = terminal.style(:red)
68
69
  terminal[:keyreq] = terminal.style(:red, nil, :bold)
69
70
  terminal[:keyrest] = terminal.style(:green)
@@ -34,18 +34,15 @@ module Bake
34
34
 
35
35
  attr :loaders
36
36
 
37
- def call(*commands, describe: false)
37
+ def call(*commands)
38
38
  while command = commands.shift
39
39
  if recipes = recipes_for(command)
40
40
  arguments, options = recipes.first.prepare(commands)
41
41
 
42
42
  recipes.each do |recipe|
43
- if describe
44
- recipe.explain(self, *arguments, **options)
45
- else
46
- with(recipe) do
47
- recipe.call(self, *arguments, **options)
48
- end
43
+ with(recipe) do
44
+ yield recipe, arguments, options if block_given?
45
+ recipe.call(self, *arguments, **options)
49
46
  end
50
47
  end
51
48
  else
@@ -22,9 +22,8 @@ require_relative 'book'
22
22
 
23
23
  module Bake
24
24
  class Loader
25
- def initialize(root, path = nil, name: nil)
25
+ def initialize(root, name: nil)
26
26
  @root = root
27
- @path = path
28
27
  @name = name
29
28
  @cache = {}
30
29
  end
@@ -39,13 +38,7 @@ module Bake
39
38
  return to_enum unless block_given?
40
39
 
41
40
  Dir.glob("**/*.rb", base: @root) do |file_path|
42
- path = file_path.sub(/\.rb$/, '').split(File::SEPARATOR)
43
-
44
- if @path
45
- yield(@path + path)
46
- else
47
- yield(path)
48
- end
41
+ yield file_path.sub(/\.rb$/, '').split(File::SEPARATOR)
49
42
  end
50
43
  end
51
44
 
@@ -64,7 +57,7 @@ module Bake
64
57
  def lookup(path)
65
58
  *directory, file = *path
66
59
 
67
- file_path = File.join(@root, @path || [], directory, "#{file}.rb")
60
+ file_path = File.join(@root, directory, "#{file}.rb")
68
61
 
69
62
  unless @cache.key?(path)
70
63
  if File.exist?(file_path)
@@ -49,11 +49,11 @@ module Bake
49
49
  @ordered.each(&block)
50
50
  end
51
51
 
52
- def append_path(current = Dir.pwd, recipes_path: RECIPES_PATH, path: nil, **options)
52
+ def append_path(current = Dir.pwd, recipes_path: RECIPES_PATH, **options)
53
53
  recipes_path = File.join(current, recipes_path)
54
54
 
55
55
  if File.directory?(recipes_path)
56
- insert(recipes_path, path, **options)
56
+ insert(recipes_path, **options)
57
57
  end
58
58
  end
59
59
 
@@ -73,8 +73,10 @@ module Bake
73
73
 
74
74
  def append_from_gems
75
75
  Gem.loaded_specs.each do |name, spec|
76
+ Console.logger.debug(self) {"Checking gem #{name}: #{spec.full_gem_path}..."}
77
+
76
78
  if path = spec.full_gem_path and File.directory?(path)
77
- append_path(path, path: name, name: spec.full_name)
79
+ append_path(path, name: spec.full_name)
78
80
  end
79
81
  end
80
82
  end
@@ -87,7 +89,7 @@ module Bake
87
89
 
88
90
  protected
89
91
 
90
- def insert(directory, path, **options)
92
+ def insert(directory, **options)
91
93
  unless @roots.key?(directory)
92
94
  Console.logger.debug(self) do
93
95
  if path
@@ -97,7 +99,7 @@ module Bake
97
99
  end
98
100
  end
99
101
 
100
- loader = Loader.new(directory, path, **options)
102
+ loader = Loader.new(directory, **options)
101
103
  @roots[directory] = loader
102
104
  @ordered << loader
103
105
 
@@ -28,11 +28,12 @@ module Bake
28
28
  end
29
29
 
30
30
  attr :book
31
+ attr :description
31
32
 
32
33
  def options?
33
34
  type, name = @block.parameters.last
34
35
 
35
- return type == :keyrest
36
+ return type == :keyrest || type == :keyreq || type == :key
36
37
  end
37
38
 
38
39
  def command
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Bake
22
- VERSION = "0.2.0"
22
+ VERSION = "0.2.1"
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -24,6 +24,62 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: covered
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
27
83
  description:
28
84
  email:
29
85
  - samuel.williams@oriontransfer.co.nz
@@ -32,15 +88,15 @@ executables:
32
88
  extensions: []
33
89
  extra_rdoc_files: []
34
90
  files:
91
+ - ".github/workflows/development.yml"
35
92
  - ".gitignore"
36
93
  - ".rspec"
37
- - ".travis.yml"
38
- - Gemfile
39
- - Gemfile.lock
40
94
  - README.md
41
95
  - Rakefile
42
96
  - bake.gemspec
43
97
  - bin/bake
98
+ - example.png
99
+ - gems.rb
44
100
  - lib/bake.rb
45
101
  - lib/bake/book.rb
46
102
  - lib/bake/command.rb
@@ -72,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
128
  - !ruby/object:Gem::Version
73
129
  version: '0'
74
130
  requirements: []
75
- rubygems_version: 3.1.2
131
+ rubygems_version: 3.0.6
76
132
  signing_key:
77
133
  specification_version: 4
78
134
  summary: A replacement for rake with a simpler syntax.
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.0
6
- before_install: gem install bundler -v 2.1.2
@@ -1,40 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bake (0.2.0)
5
- samovar (~> 2.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- console (1.8.0)
11
- diff-lcs (1.3)
12
- mapping (1.1.1)
13
- rake (12.3.3)
14
- rspec (3.9.0)
15
- rspec-core (~> 3.9.0)
16
- rspec-expectations (~> 3.9.0)
17
- rspec-mocks (~> 3.9.0)
18
- rspec-core (3.9.1)
19
- rspec-support (~> 3.9.1)
20
- rspec-expectations (3.9.0)
21
- diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.9.0)
23
- rspec-mocks (3.9.1)
24
- diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.9.0)
26
- rspec-support (3.9.2)
27
- samovar (2.1.4)
28
- console (~> 1.0)
29
- mapping (~> 1.0)
30
-
31
- PLATFORMS
32
- ruby
33
-
34
- DEPENDENCIES
35
- bake!
36
- rake (~> 12.0)
37
- rspec (~> 3.0)
38
-
39
- BUNDLED WITH
40
- 2.1.2