toys 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +0,0 @@
1
- # Copyright 2018 Daniel Azuma
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the copyright holder, nor the names of any other
14
- # contributors to this software, may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
- ;
29
-
30
- require "toys/utils/module_lookup"
31
-
32
- module Toys
33
- ##
34
- # Namespace for common templates
35
- #
36
- module Templates
37
- ##
38
- # Return a template class by name.
39
- #
40
- # Currently recognized template names are:
41
- #
42
- # * `:clean` : Creates a tool that cleans build artifacts.
43
- # * `:gem_build` : Creates a tool that builds and/or releases gems.
44
- # * `:minitest` : Creates a tool that runs unit tests.
45
- # * `:rubocop` : Creates a tool that runs rubocop.
46
- # * `:yardoc` : Creates a tool that generates YARD documentation.
47
- #
48
- # @param [String,Symbol] name Name of the template class to return
49
- # @return [Class,nil] The class, or `nil` if not found
50
- #
51
- def self.lookup(name)
52
- Utils::ModuleLookup.lookup(:templates, name)
53
- end
54
- end
55
- end
@@ -1,80 +0,0 @@
1
- # Copyright 2018 Daniel Azuma
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the copyright holder, nor the names of any other
14
- # contributors to this software, may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
- ;
29
-
30
- module Toys
31
- module Templates
32
- ##
33
- # A template for tools that clean build artifacts
34
- #
35
- class Clean
36
- include Template
37
-
38
- ##
39
- # Create the template settings for the Clean template.
40
- #
41
- # You may provide a hash of options when expanding this template.
42
- # Supported options include:
43
- #
44
- # * `:name` (String) Name of the tool to create. Defaults to "clean".
45
- # * `:paths` (Array<String>) An array of glob patterns indicating what
46
- # to clean.
47
- #
48
- # @param [Hash] opts Options.
49
- #
50
- def initialize(opts = {})
51
- @name = opts[:name] || "clean"
52
- @paths = opts[:paths] || []
53
- end
54
-
55
- attr_accessor :name
56
- attr_accessor :paths
57
-
58
- to_expand do |template|
59
- tool(template.name) do
60
- desc "Clean built files and directories."
61
-
62
- use :file_utils
63
-
64
- execute do
65
- files = []
66
- patterns = Array(template.paths)
67
- patterns.each do |pattern|
68
- files.concat(::Dir.glob(pattern))
69
- end
70
- files.uniq!
71
-
72
- files.each do |file|
73
- rm_rf file
74
- end
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
@@ -1,115 +0,0 @@
1
- # Copyright 2018 Daniel Azuma
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the copyright holder, nor the names of any other
14
- # contributors to this software, may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
- ;
29
-
30
- require "rubygems/package"
31
-
32
- module Toys
33
- module Templates
34
- ##
35
- # A template for tools that build and release gems
36
- #
37
- class GemBuild
38
- include Template
39
-
40
- ##
41
- # Create the template settings for the GemBuild template.
42
- #
43
- # You may provide a hash of options when expanding this template.
44
- # Supported options include:
45
- #
46
- # * `:name` (String) Name of the tool to create. Defaults to "build".
47
- # * `:gem_name` (String) Name of the gem to build. If not provided,
48
- # defaults to the first gemspec file it finds.
49
- # * `:push_gem` (Boolean) If true, pushes the built gem to rubygems.
50
- # * `:tag` (Boolean) If true, tags the git repo with the gem version.
51
- # * `:push_tag` (Boolean,String) If truthy, pushes the new tag to
52
- # a git remote. You may specify which remote by setting the value to
53
- # a string. Otherwise, if the value is simply `true`, the "origin"
54
- # remote is used by default.
55
- #
56
- # @param [Hash] opts Options.
57
- #
58
- def initialize(opts = {})
59
- @name = opts[:name] || "build"
60
- @gem_name = opts[:gem_name]
61
- @push_gem = opts[:push_gem]
62
- @tag = opts[:tag]
63
- @push_tag = opts[:push_tag]
64
- end
65
-
66
- attr_accessor :name
67
- attr_accessor :gem_name
68
- attr_accessor :push_gem
69
- attr_accessor :tag
70
- attr_accessor :push_tag
71
-
72
- to_expand do |template|
73
- unless template.gem_name
74
- candidates = ::Dir.glob("*.gemspec")
75
- if candidates.empty?
76
- raise ToolDefinitionError, "Could not find a gemspec"
77
- end
78
- template.gem_name = candidates.first.sub(/\.gemspec$/, "")
79
- end
80
- task_type = template.push_gem ? "Release" : "Build"
81
-
82
- tool(template.name) do
83
- desc "#{task_type} the gem: #{template.gem_name}"
84
-
85
- use :file_utils
86
- use :exec
87
-
88
- execute do
89
- configure_exec(exit_on_nonzero_status: true)
90
- gemspec = ::Gem::Specification.load "#{template.gem_name}.gemspec"
91
- version = gemspec.version
92
- gemfile = "#{template.gem_name}-#{version}.gem"
93
- ::Gem::Package.build gemspec
94
- mkdir_p "pkg"
95
- mv gemfile, "pkg"
96
- if template.push_gem
97
- if ::File.directory?(".git") && capture("git status -s").strip != ""
98
- logger.error "Cannot push the gem when there are uncommited changes"
99
- exit(1)
100
- end
101
- sh "gem push pkg/#{gemfile}"
102
- if template.tag
103
- sh "git tag v#{version}"
104
- if template.push_tag
105
- template.push_tag = "origin" if template.push_tag == true
106
- sh "git push #{template.push_tag} v#{version}"
107
- end
108
- end
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
115
- end
@@ -1,108 +0,0 @@
1
- # Copyright 2018 Daniel Azuma
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the copyright holder, nor the names of any other
14
- # contributors to this software, may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
- ;
29
-
30
- module Toys
31
- module Templates
32
- ##
33
- # A template for tools that run minitest
34
- #
35
- class Minitest
36
- include Template
37
-
38
- ##
39
- # Create the template settings for the Minitest template.
40
- #
41
- # You may provide a hash of options when expanding this template.
42
- # Supported options include:
43
- #
44
- # * `:name` (String) Name of the tool to create. Defaults to "test".
45
- # * `:lib` (Array<String>) An array of library paths to add to the
46
- # ruby require path.
47
- # * `:files` (Array<String>) An array of globs indicating the test
48
- # files to load.
49
- # * `:warnings` (Boolean) If true, runs tests with Ruby warnings.
50
- #
51
- # @param [Hash] opts Options.
52
- #
53
- def initialize(opts = {})
54
- @name = opts[:name] || "test"
55
- @libs = opts[:libs] || ["lib"]
56
- @files = opts[:files] || ["test/**/test*.rb"]
57
- @warnings = opts.include?(:warnings) ? opts[:warnings] : true
58
- end
59
-
60
- attr_accessor :name
61
- attr_accessor :libs
62
- attr_accessor :files
63
- attr_accessor :warnings
64
-
65
- to_expand do |template|
66
- tool(template.name) do
67
- desc "Run minitest on the current project."
68
-
69
- use :exec
70
-
71
- switch(
72
- :warnings, "-w", "--[no-]warnings",
73
- default: template.warnings,
74
- doc: "Turn on Ruby warnings (defaults to #{template.warnings})"
75
- )
76
- remaining_args(:tests, doc: "Paths to the tests to run (defaults to all tests)")
77
-
78
- execute do
79
- ruby_args = []
80
- unless template.libs.empty?
81
- lib_path = template.libs.join(::File::PATH_SEPARATOR)
82
- ruby_args << "-I#{lib_path}"
83
- end
84
- ruby_args << "-w" if self[:warnings]
85
-
86
- tests = self[:tests]
87
- if tests.empty?
88
- Array(template.files).each do |pattern|
89
- tests.concat(::Dir.glob(pattern))
90
- end
91
- tests.uniq!
92
- end
93
-
94
- result = ruby(ruby_args, in_from: :controller) do |controller|
95
- tests.each do |file|
96
- controller.in.puts("load '#{file}'")
97
- end
98
- end
99
- if result.error?
100
- logger.error("Minitest failed!")
101
- exit(result.exit_code)
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,81 +0,0 @@
1
- # Copyright 2018 Daniel Azuma
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the copyright holder, nor the names of any other
14
- # contributors to this software, may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
- ;
29
-
30
- module Toys
31
- module Templates
32
- ##
33
- # A template for tools that run rubocop
34
- #
35
- class Rubocop
36
- include Template
37
-
38
- ##
39
- # Create the template settings for the Rubocop template.
40
- #
41
- # You may provide a hash of options when expanding this template.
42
- # Supported options include:
43
- #
44
- # * `:name` (String) Name of the tool to create. Defaults to "rubocop".
45
- # * `:fail_on_error` (Boolean) If true, exits with a nonzero code if
46
- # Rubocop fails. Defaults to true.
47
- # * `:options` (Hash) Additional options passed to the Rubocop CLI.
48
- #
49
- # @param [Hash] opts Options.
50
- #
51
- def initialize(opts = {})
52
- @name = opts[:name] || "rubocop"
53
- @fail_on_error = opts.include?(:fail_on_error) ? opts[:fail_on_error] : true
54
- @options = opts[:options] || []
55
- end
56
-
57
- attr_accessor :name
58
- attr_accessor :fail_on_error
59
- attr_accessor :options
60
-
61
- to_expand do |template|
62
- tool(template.name) do
63
- desc "Run rubocop on the current project."
64
-
65
- use :exec
66
-
67
- execute do
68
- require "rubocop"
69
- cli = ::RuboCop::CLI.new
70
- logger.info "Running RuboCop..."
71
- result = cli.run(template.options)
72
- if result.nonzero?
73
- logger.error "RuboCop failed!"
74
- exit(1) if template.fail_on_error
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,95 +0,0 @@
1
- # Copyright 2018 Daniel Azuma
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the copyright holder, nor the names of any other
14
- # contributors to this software, may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
- ;
29
-
30
- module Toys
31
- module Templates
32
- ##
33
- # A template for tools that run yardoc
34
- #
35
- class Yardoc
36
- include Template
37
-
38
- ##
39
- # Create the template settings for the Yardoc template.
40
- #
41
- # You may provide a hash of options when expanding this template.
42
- # Supported options include:
43
- #
44
- # * `:name` (String) Name of the tool to create. Defaults to "yardoc".
45
- # * `:files` (Array<String>) An array of globs indicating the files
46
- # to document.
47
- # * `:options` (Hash) Additional options passed to YARD
48
- # * `:stats_options` (Hash) Additional options passed to YARD stats
49
- #
50
- # @param [Hash] opts Options.
51
- #
52
- def initialize(opts = {})
53
- @name = opts[:name] || "yardoc"
54
- @files = opts[:files] || []
55
- @options = opts[:options] || []
56
- @stats_options = opts[:stats_options] || []
57
- end
58
-
59
- attr_accessor :name
60
- attr_accessor :files
61
- attr_accessor :options
62
- attr_accessor :stats_options
63
-
64
- to_expand do |template|
65
- tool(template.name) do
66
- desc "Run yardoc on the current project."
67
-
68
- use :exec
69
-
70
- execute do
71
- require "yard"
72
- files = []
73
- patterns = Array(template.files)
74
- patterns = ["lib/**/*.rb"] if patterns.empty?
75
- patterns.each do |pattern|
76
- files.concat(::Dir.glob(pattern))
77
- end
78
- files.uniq!
79
-
80
- unless template.stats_options.empty?
81
- template.options << "--no-stats"
82
- template.stats_options << "--use-cache"
83
- end
84
-
85
- yardoc = ::YARD::CLI::Yardoc.new
86
- yardoc.run(*(template.options + files))
87
- unless template.stats_options.empty?
88
- ::YARD::CLI::Stats.run(*template.stats_options)
89
- end
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end