gbud 0.0.4 → 0.1.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/bin/gbud +8 -1
- data/lib/gbud.rb +14 -2
- data/lib/gbud/namespace.rb +26 -0
- data/lib/gbud/project_builder.rb +91 -36
- data/lib/gbud/project_metadata.rb +51 -25
- data/lib/gbud/user_prompt.rb +17 -3
- data/lib/templates/cli.rb.erb +43 -0
- data/lib/templates/executable.rb.erb +8 -1
- data/lib/templates/gemfile.rb.erb +15 -6
- data/lib/templates/gemspec.rb.erb +1 -1
- data/lib/templates/guardfile.rb.erb +25 -0
- data/lib/templates/hello.rb.erb +11 -4
- data/lib/templates/main.rb.erb +10 -2
- data/lib/templates/namespace.rb.erb +26 -0
- data/lib/templates/rakefile.rb.erb +13 -1
- data/lib/templates/readme.md.erb +113 -0
- data/lib/templates/test_hello.rb.erb +18 -3
- data/test/test_project_builder.rb +9 -4
- data/test/test_project_metadata.rb +37 -4
- metadata +8 -5
- data/lib/templates/guardfile.erb.rb +0 -0
- data/lib/templates/readme.rb.erb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7e2f94ee9de9401c74cf7ccba14ebe62bf010f1
|
4
|
+
data.tar.gz: 84e58b4233481373ebc72bc027cccf8da80dcd4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7ed8be48ba2c998643ecc1f6dc0326e046724dd6e1aec61e6eca160cb5d4cc1aaef4a11b435f7642879f4954d86a87beaa6738e8343522e01feb5ecf33993e4
|
7
|
+
data.tar.gz: d344a20157fb5e102f22fac06037b4995a6e3b219ef5c4f3497ed94258effa1ea3884cd54c3e2a5a2fdae4cf772648919f9cff2fd07d1455ef69d773cc274bdf
|
data/bin/gbud
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2017 Richard Davis
|
3
3
|
#
|
4
4
|
# This file is part of gbud.
|
5
5
|
#
|
@@ -16,6 +16,13 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with gbud. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
|
19
|
+
##
|
20
|
+
# = bin/gbud
|
21
|
+
# Author:: Richard Davis
|
22
|
+
# Copyright:: Copyright 2017 Richard Davis
|
23
|
+
# License:: GNU Public License 3
|
24
|
+
#
|
25
|
+
# Project executable file.
|
19
26
|
begin
|
20
27
|
require 'gbud'
|
21
28
|
rescue LoadError
|
data/lib/gbud.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2017 Richard Davis
|
2
2
|
#
|
3
3
|
# This file is part of gbud.
|
4
4
|
#
|
@@ -15,6 +15,13 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with gbud. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
+
##
|
19
|
+
# = gbud.rb
|
20
|
+
# Author:: Richard Davis
|
21
|
+
# Copyright:: Copyright 2017 Richard Davis
|
22
|
+
# License:: GNU Public License 3
|
23
|
+
#
|
24
|
+
# The main script for handling user input and program execution.
|
18
25
|
require 'fileutils'
|
19
26
|
require 'optparse'
|
20
27
|
require 'erb'
|
@@ -41,6 +48,10 @@ optparse = OptionParser.new do |opts|
|
|
41
48
|
options[:cli] = true
|
42
49
|
end
|
43
50
|
|
51
|
+
opts.on('--no-cli', 'Creates an executable without option parsing') do
|
52
|
+
options[:cli] = false
|
53
|
+
end
|
54
|
+
|
44
55
|
opts.on('-l', '--license', 'Displays the copyright notice') do
|
45
56
|
puts "This program is free software: you can redistribute it and/or modify
|
46
57
|
it under the terms of the GNU General Public License as published by
|
@@ -85,7 +96,8 @@ if options[:name]
|
|
85
96
|
end
|
86
97
|
metadata.summary = GBud::UserPrompt.get_value 'Enter a short summary of the project => '
|
87
98
|
metadata.description = GBud::UserPrompt.get_value 'Enter a description of the project => '
|
88
|
-
|
99
|
+
options[:cli] = true if options[:cli].nil?
|
100
|
+
project = GBud::ProjectBuilder.new metadata.to_hash, options[:cli]
|
89
101
|
project.build
|
90
102
|
end
|
91
103
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright 2017 Richard Davis
|
2
|
+
#
|
3
|
+
# This file is part of gbud.
|
4
|
+
#
|
5
|
+
# gbud is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# gbud is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with gbud. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
##
|
19
|
+
# = GBud
|
20
|
+
# Author:: Richard Davis
|
21
|
+
# Copyright:: Copyright 2017 Richard Davis
|
22
|
+
# License:: GNU Public License 3
|
23
|
+
#
|
24
|
+
# Module for namespacing application classes.
|
25
|
+
module GBud
|
26
|
+
end
|
data/lib/gbud/project_builder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2017 Richard Davis
|
2
2
|
#
|
3
3
|
# This file is part of gbud.
|
4
4
|
#
|
@@ -15,99 +15,154 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with gbud. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
+
require 'date'
|
19
|
+
|
18
20
|
module GBud
|
21
|
+
##
|
22
|
+
# = ProjectBuilder
|
23
|
+
# Author:: Richard Davis
|
24
|
+
# Copyright:: Copyright 2017 Richard Davis
|
25
|
+
# License:: GNU Public License 3
|
26
|
+
#
|
27
|
+
# The engine that is instantiated to build out the project directory
|
28
|
+
# skeleton and basic files using templates.
|
19
29
|
class ProjectBuilder
|
20
|
-
|
30
|
+
# Project metadata information supplied by user
|
31
|
+
attr_reader :metadata
|
32
|
+
# Option for making project executable
|
33
|
+
attr_reader :cli
|
34
|
+
# Hash containing file names for project templates
|
35
|
+
attr_reader :templates
|
36
|
+
# Hash containing file names for project assets
|
37
|
+
attr_reader :assets
|
38
|
+
# Hash specifying project directories
|
39
|
+
attr_reader :paths
|
21
40
|
|
22
41
|
##
|
23
|
-
# Instantiates
|
24
|
-
#
|
25
|
-
# metadata : a hash containing the name, summary, description, authors, email
|
26
|
-
# and URL for the project to be initialized
|
27
|
-
# cli : specifies the need for a CLI option parser and executable
|
28
|
-
#
|
42
|
+
# Instantiates a ProjectBuilder object
|
29
43
|
def initialize metadata, cli
|
30
44
|
@metadata = metadata
|
45
|
+
|
31
46
|
@cli = cli
|
32
|
-
@
|
33
|
-
readme: 'README.md',
|
34
|
-
gemspec: "#{metadata[:name]}.gemspec",
|
35
|
-
gemfile: 'Gemfile',
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
47
|
+
@templates = {
|
48
|
+
'readme.md': 'README.md',
|
49
|
+
'gemspec.rb': "#{metadata[:name]}.gemspec",
|
50
|
+
'gemfile.rb': 'Gemfile',
|
51
|
+
'guardfile.rb': 'Guardfile',
|
52
|
+
'rakefile.rb': 'Rakefile',
|
53
|
+
'main.rb': "#{metadata[:name]}.rb",
|
54
|
+
'hello.rb': 'hello.rb',
|
55
|
+
'test_hello.rb': 'test_hello.rb',
|
56
|
+
'namespace.rb': 'namespace.rb'
|
57
|
+
}
|
58
|
+
@assets = {
|
59
|
+
license: 'LICENSE'
|
40
60
|
}
|
41
61
|
@paths = {
|
42
62
|
project_dir: "#{metadata[:name]}/",
|
43
63
|
project_lib_dir: "#{metadata[:name]}/lib/",
|
44
64
|
project_lib_project_dir: "#{metadata[:name]}/lib/#{metadata[:name]}/",
|
45
|
-
project_test_dir: "#{metadata[:name]}/test/"
|
65
|
+
project_test_dir: "#{metadata[:name]}/test/",
|
46
66
|
}
|
47
67
|
if cli == true
|
48
|
-
@
|
68
|
+
@templates[:'executable.rb'] = "#{metadata[:name]}"
|
49
69
|
@paths[:project_bin_dir] = "#{metadata[:name]}/bin/"
|
50
70
|
end
|
51
71
|
end
|
52
72
|
|
73
|
+
##
|
74
|
+
# Builds the project
|
53
75
|
def build
|
54
76
|
make_directories
|
55
|
-
|
56
|
-
|
77
|
+
render_templates
|
78
|
+
copy_assets
|
57
79
|
end
|
58
80
|
|
59
81
|
private
|
60
82
|
|
61
83
|
##
|
62
|
-
#
|
63
|
-
# Creates the project directory structure
|
84
|
+
# Creates the project directories
|
64
85
|
def make_directories
|
65
86
|
@paths.each do |path, dir|
|
66
87
|
FileUtils.mkdir_p(dir)
|
67
88
|
end
|
68
89
|
end
|
69
90
|
|
70
|
-
|
71
|
-
|
91
|
+
##
|
92
|
+
# Makes the files using templates
|
93
|
+
def render_templates
|
94
|
+
@templates.each do |template, filename|
|
72
95
|
directory = map_template template
|
73
96
|
file = File.new "#{directory}#{filename}", 'w+'
|
74
97
|
file.puts(render template)
|
75
98
|
file.close
|
76
|
-
make_executable if template == :executable
|
99
|
+
make_executable if template == :'executable.rb'
|
77
100
|
end
|
78
101
|
end
|
79
102
|
|
103
|
+
##
|
104
|
+
# Maps each templated file to correct directory
|
80
105
|
def map_template template
|
81
|
-
|
82
|
-
when :readme
|
106
|
+
case template
|
107
|
+
when :'readme.md'
|
108
|
+
@paths[:project_dir]
|
109
|
+
when :'gemspec.rb'
|
83
110
|
@paths[:project_dir]
|
84
|
-
when :
|
111
|
+
when :'gemfile.rb'
|
85
112
|
@paths[:project_dir]
|
86
|
-
when :
|
113
|
+
when :'guardfile.rb'
|
87
114
|
@paths[:project_dir]
|
88
|
-
when :rakefile
|
115
|
+
when :'rakefile.rb'
|
89
116
|
@paths[:project_dir]
|
90
|
-
when :main
|
117
|
+
when :'main.rb'
|
91
118
|
@paths[:project_lib_dir]
|
92
|
-
when :hello
|
119
|
+
when :'hello.rb'
|
93
120
|
@paths[:project_lib_project_dir]
|
94
|
-
when :executable
|
121
|
+
when :'executable.rb'
|
95
122
|
@paths[:project_bin_dir]
|
96
|
-
when :test_hello
|
123
|
+
when :'test_hello.rb'
|
97
124
|
@paths[:project_test_dir]
|
98
125
|
end
|
99
126
|
end
|
100
127
|
|
128
|
+
##
|
129
|
+
# Renders the templates into files
|
101
130
|
def render template
|
102
131
|
path = File.expand_path(File.join(File.dirname(__FILE__),
|
103
132
|
'..',
|
104
133
|
'templates',
|
105
|
-
"#{template
|
134
|
+
"#{template}.erb"))
|
106
135
|
ERB.new(File.read(path)).result(binding)
|
107
136
|
end
|
108
137
|
|
138
|
+
##
|
139
|
+
# Flags the CLI file as executable
|
109
140
|
def make_executable
|
110
|
-
File.chmod(0755, "#{@paths[:project_bin_dir]}#{@
|
141
|
+
File.chmod(0755, "#{@paths[:project_bin_dir]}#{@templates[:'executable.rb']}")
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Copies the assets
|
146
|
+
def copy_assets
|
147
|
+
@assets.each do |asset, filename|
|
148
|
+
directory = map_asset asset
|
149
|
+
FileUtils.cp(File.expand_path(File.join(File.dirname(__FILE__),
|
150
|
+
'..',
|
151
|
+
'assets',
|
152
|
+
"#{filename}")),
|
153
|
+
"#{directory}#{filename}")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Maps each asset file to correct directory
|
159
|
+
def map_asset asset
|
160
|
+
case asset
|
161
|
+
when :gitignore
|
162
|
+
@paths[:project_dir]
|
163
|
+
when :license
|
164
|
+
@paths[:project_dir]
|
165
|
+
end
|
111
166
|
end
|
112
167
|
end
|
113
168
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2017 Richard Davis
|
2
2
|
#
|
3
3
|
# This file is part of gbud.
|
4
4
|
#
|
@@ -16,45 +16,65 @@
|
|
16
16
|
# along with gbud. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
18
|
module GBud
|
19
|
+
##
|
20
|
+
# = ProjectMetadata
|
21
|
+
# Author:: Richard Davis
|
22
|
+
# Copyright:: Copyright 2017 Richard Davis
|
23
|
+
# License:: GNU Public License 3
|
24
|
+
#
|
25
|
+
# The means by which user input describing project metadata is
|
26
|
+
# captured to be used by GBud::ProjectBuilder objects.
|
19
27
|
class ProjectMetadata
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
# The name of the project
|
29
|
+
attr_reader :name
|
30
|
+
# A short project summary
|
31
|
+
attr_accessor :summary
|
32
|
+
# A longer description of the project
|
33
|
+
attr_accessor :description
|
34
|
+
# List of the project authors
|
35
|
+
attr_reader :authors
|
36
|
+
# Email address for project
|
37
|
+
attr_reader :email
|
38
|
+
# The URL for project
|
39
|
+
attr_reader :url
|
40
|
+
# The project version (defaults to 0.0.1)
|
41
|
+
attr_reader :version
|
42
|
+
# The project license (defaults to GPL-3.0)
|
43
|
+
attr_reader :license
|
28
44
|
|
45
|
+
##
|
46
|
+
# Instantiates a ProjectMetadata object
|
29
47
|
def initialize
|
30
48
|
@version = '0.0.1'
|
31
49
|
@license = 'GPL-3.0'
|
32
50
|
end
|
33
51
|
|
34
|
-
|
52
|
+
##
|
53
|
+
# Sets the name attribute
|
54
|
+
def name=(name)
|
35
55
|
@name = name unless validate_name(name).nil?
|
36
56
|
end
|
37
57
|
|
38
|
-
|
58
|
+
##
|
59
|
+
# Sets the author attribute
|
60
|
+
def authors=(authors)
|
39
61
|
@authors = authors.split(', ')
|
40
62
|
end
|
41
63
|
|
42
|
-
|
64
|
+
##
|
65
|
+
# Sets the email attribute
|
66
|
+
def email=(email)
|
43
67
|
@email = email unless validate_email(email).nil?
|
44
68
|
end
|
45
69
|
|
46
|
-
|
70
|
+
##
|
71
|
+
# Sets the url attribute
|
72
|
+
def url=(url)
|
47
73
|
@url = url unless validate_url(url).nil?
|
48
74
|
end
|
49
75
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
def description= description
|
55
|
-
@description = description
|
56
|
-
end
|
57
|
-
|
76
|
+
##
|
77
|
+
# Returns the object attributes as a hash
|
58
78
|
def to_hash
|
59
79
|
{
|
60
80
|
name: @name,
|
@@ -68,16 +88,22 @@ module GBud
|
|
68
88
|
}
|
69
89
|
end
|
70
90
|
|
71
|
-
|
91
|
+
##
|
92
|
+
# Validates that the given name meets criteria
|
93
|
+
def validate_name(name)
|
72
94
|
/\A[a-z][a-z0-9_\-]*\Z/i =~ name
|
73
95
|
end
|
74
96
|
|
75
|
-
|
97
|
+
##
|
98
|
+
# Validates that the given email meets criteria
|
99
|
+
def validate_email(email)
|
76
100
|
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i =~ email
|
77
101
|
end
|
78
102
|
|
79
|
-
|
80
|
-
|
103
|
+
##
|
104
|
+
# Validates that the given url meets criteria
|
105
|
+
def validate_url(url)
|
106
|
+
%r{https?:\/\/[\S]+} =~ url
|
81
107
|
end
|
82
108
|
end
|
83
109
|
end
|
data/lib/gbud/user_prompt.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2017 Richard Davis
|
2
2
|
#
|
3
3
|
# This file is part of gbud.
|
4
4
|
#
|
@@ -16,15 +16,27 @@
|
|
16
16
|
# along with gbud. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
18
|
module GBud
|
19
|
+
##
|
20
|
+
# = UserPrompt
|
21
|
+
# Author:: Richard Davis
|
22
|
+
# Copyright:: Copyright 2017 Richard Davis
|
23
|
+
# License:: GNU Public License 3
|
24
|
+
#
|
25
|
+
# Module containing methods used to prompt the user for program
|
26
|
+
# input.
|
19
27
|
module UserPrompt
|
20
28
|
@value = ''
|
21
29
|
|
22
|
-
|
30
|
+
##
|
31
|
+
# Returns the value entered by the user
|
32
|
+
def self.get_value(prompt)
|
23
33
|
prompt_user prompt
|
24
34
|
@value
|
25
35
|
end
|
26
36
|
|
27
|
-
|
37
|
+
##
|
38
|
+
# Prompts the user for a value
|
39
|
+
def self.prompt_user(prompt)
|
28
40
|
loop do
|
29
41
|
print prompt
|
30
42
|
@value = gets.chomp.to_s
|
@@ -32,6 +44,8 @@ module GBud
|
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
47
|
+
##
|
48
|
+
# Confirms the value entered by the user
|
35
49
|
def self.confirm_input
|
36
50
|
puts "You have entered: #{@value}"
|
37
51
|
print 'Is this correct? (Y/N) => '
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
trap('INT') do
|
4
|
+
puts "\nTerminating..."
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
optparse = OptionParser.new do |opts|
|
11
|
+
opts.banner = 'Usage: <%= @metadata[:name] %> [options]'
|
12
|
+
|
13
|
+
opts.on('-g', '--greet NAME', 'Provides a greeting given a name.') do |name|
|
14
|
+
options[:greet] = name
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-l', '--license', 'Displays the copyright notice') do
|
18
|
+
puts "This program is free software: you can redistribute it and/or modify
|
19
|
+
it under the terms of the GNU General Public License as published by
|
20
|
+
the Free Software Foundation, either version 3 of the License, or
|
21
|
+
(at your option) any later version.
|
22
|
+
"
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-w', '--warranty', 'Displays the warranty statement') do
|
26
|
+
puts "This program is distributed in the hope that it will be useful,
|
27
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
29
|
+
GNU General Public License for more details.
|
30
|
+
"
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on_tail('-h', '--help', 'Displays the help screen') do
|
34
|
+
puts opts
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
optparse.parse!
|
40
|
+
|
41
|
+
if options[:greet]
|
42
|
+
puts <%= @metadata[:name].split(/-|_/).each{ |s| s.capitalize! }.join %>::Hello.greeting(options[:greet])
|
43
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby'
|
2
|
-
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
2
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
3
3
|
#
|
4
4
|
# This file is part of <%= @metadata[:name] %>.
|
5
5
|
#
|
@@ -16,6 +16,13 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
|
19
|
+
##
|
20
|
+
# = /bin/<%= @metadata[:name] %>
|
21
|
+
# Author:: <%= @metadata[:authors].join(', ') %>
|
22
|
+
# Copyright:: Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
23
|
+
# License:: GNU Public License 3
|
24
|
+
#
|
25
|
+
# Project executable file.
|
19
26
|
begin
|
20
27
|
require '<%= @metadata[:name] %>'
|
21
28
|
rescue LoadError
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
1
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
2
2
|
#
|
3
3
|
# This file is part of <%= @metadata[:name] %>.
|
4
4
|
#
|
@@ -16,9 +16,18 @@
|
|
16
16
|
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
18
|
source 'https://rubygems.org'
|
19
|
-
ruby '2.
|
19
|
+
ruby '2.4.1'
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
gem 'minitest', '~> 5.0'
|
24
|
-
|
21
|
+
group :development do
|
22
|
+
# Minitest for unit tests
|
23
|
+
gem 'minitest', '~> 5.0'
|
24
|
+
# Use Guard to run automated tests
|
25
|
+
gem 'guard', '~> 2.14', '>= 2.14.1'
|
26
|
+
gem 'guard-minitest', '~> 2.4', '>= 2.4.6'
|
27
|
+
# Rake executes tasks defined in the Rakefile
|
28
|
+
gem 'rake', '~> 12.0'
|
29
|
+
# Rubocop for code style guidelines
|
30
|
+
gem 'rubocop', '~> 0.48.1'
|
31
|
+
# RDoc for generating documentation
|
32
|
+
gem 'rdoc', '~> 5.1'
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
2
|
+
#
|
3
|
+
# This file is part of <%= @metadata[:name] %>.
|
4
|
+
#
|
5
|
+
# <%= @metadata[:name] %> is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# <%= @metadata[:name] %> is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
directories(%w[lib test])\
|
19
|
+
.select { |d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist") }
|
20
|
+
|
21
|
+
guard :minitest do
|
22
|
+
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
23
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
24
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
25
|
+
end
|
data/lib/templates/hello.rb.erb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
1
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
2
2
|
#
|
3
3
|
# This file is part of <%= @metadata[:name] %>.
|
4
4
|
#
|
@@ -15,10 +15,17 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
-
|
18
|
+
##
|
19
|
+
# = Hello
|
20
|
+
# Author:: <%= @metadata[:authors].join(', ') %>
|
21
|
+
# Copyright:: Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
22
|
+
# License:: GNU Public License 3
|
23
|
+
#
|
24
|
+
# Contains modularized code for project; given example provides a greeting
|
25
|
+
module <%= @metadata[:name].split(/-|_/).each{ |s| s.capitalize! }.join %>
|
19
26
|
class Hello
|
20
|
-
def self.greeting
|
21
|
-
|
27
|
+
def self.greeting name
|
28
|
+
"Hello, #{name}."
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
data/lib/templates/main.rb.erb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
1
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
2
2
|
#
|
3
3
|
# This file is part of <%= @metadata[:name] %>.
|
4
4
|
#
|
@@ -15,5 +15,13 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
+
##
|
19
|
+
# = /lib/<%= @metadata[:name] %>.rb
|
20
|
+
# Author:: <%= @metadata[:authors].join(', ') %>
|
21
|
+
# Copyright:: Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
22
|
+
# License:: GNU Public License 3
|
23
|
+
#
|
24
|
+
# Main application file that loads other files.
|
18
25
|
require '<%= @metadata[:name] %>/hello'
|
19
|
-
|
26
|
+
|
27
|
+
<%= render 'cli.rb' if @cli == true %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
2
|
+
#
|
3
|
+
# This file is part of <%= @metadata[:name] %>.
|
4
|
+
#
|
5
|
+
# <%= @metadata[:name] %> is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# <%= @metadata[:name] %> is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
##
|
19
|
+
# = <%= @metadata[:name].split(/-|_/).each{ |s| s.capitalize! }.join %>
|
20
|
+
# Author:: <%= @metadata[:authors].join(', ') %>
|
21
|
+
# Copyright:: Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
22
|
+
# License:: GNU Public License 3
|
23
|
+
#
|
24
|
+
# Module for namespacing application classes.
|
25
|
+
module <%= @metadata[:name].split(/-|_/).each{ |s| s.capitalize! }.join %>
|
26
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
1
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
2
2
|
#
|
3
3
|
# This file is part of <%= @metadata[:name] %>.
|
4
4
|
#
|
@@ -16,7 +16,19 @@
|
|
16
16
|
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
18
|
require 'rake/testtask'
|
19
|
+
require 'rdoc/task'
|
19
20
|
|
20
21
|
Rake::TestTask.new do |t|
|
21
22
|
t.libs << 'test'
|
22
23
|
end
|
24
|
+
|
25
|
+
RDoc::Task.new :rdoc do |rdoc|
|
26
|
+
rdoc.main = 'README.md'
|
27
|
+
rdoc.rdoc_files.include('README.md',
|
28
|
+
'./lib/*.rb',
|
29
|
+
'./lib/**/*.rb',
|
30
|
+
'./test/**/*.rb')
|
31
|
+
rdoc.title = '<%= @metadata[:name] %> Documentation'
|
32
|
+
rdoc.rdoc_dir = 'docs/'
|
33
|
+
rdoc.options << '--all'
|
34
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# A note from gbud
|
2
|
+
## Next Steps
|
3
|
+
* Initiate a git repo with `git init`
|
4
|
+
* Run `bundle install` to get the dependencies
|
5
|
+
* Write some code!
|
6
|
+
* Execute `gem build foobar.gemspec` to build your gem
|
7
|
+
* Execute `gem install foobar-0.0.1.gem` to install your gem
|
8
|
+
* Share!
|
9
|
+
# Name
|
10
|
+
<%= @metadata[:description] %>
|
11
|
+
|
12
|
+
## Table of Contents
|
13
|
+
* About
|
14
|
+
* Getting started
|
15
|
+
* Installation
|
16
|
+
* Usage
|
17
|
+
* Contributing
|
18
|
+
* Code of Conduct
|
19
|
+
* Code Style
|
20
|
+
* Documentation
|
21
|
+
* Testing
|
22
|
+
* TODO
|
23
|
+
* Changelog
|
24
|
+
|
25
|
+
## About
|
26
|
+
<%= @metadata[:description] %>
|
27
|
+
|
28
|
+
Documentation can be found [here](https://).
|
29
|
+
|
30
|
+
## License
|
31
|
+
See `LICENSE` in the project root directory for license information.
|
32
|
+
|
33
|
+
## Getting Started
|
34
|
+
### Installation
|
35
|
+
Put installation instructions here.
|
36
|
+
|
37
|
+
### Usage
|
38
|
+
Put usage instructions here.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
### Code of Conduct
|
42
|
+
All contributions are welcome, but are merged at the discretion of the core
|
43
|
+
contributor(s). Contributions to the project will be
|
44
|
+
judged on their merits without respect to a contributor's publicly or
|
45
|
+
privately held beliefs, opinions, ideology, nationality, ethnicity, or
|
46
|
+
demographic. Most communications within the project should be limited to
|
47
|
+
project planning, development, bugfixing, or other relevant topics; for
|
48
|
+
off-topic discussions, contributors are expected to use good judgement
|
49
|
+
and to avoid intentionally abusive behavior. Conflict should be resolved
|
50
|
+
at the lowest level possible with minimal disruption to the project. Core
|
51
|
+
contributor(s) reserve the right to request that a contributor alter their
|
52
|
+
behavior, however, nothing in this code of conduct should be construed in
|
53
|
+
such a manner that it infringes upon any contributor's freedom of expression.
|
54
|
+
|
55
|
+
### Code Style
|
56
|
+
To keep a consistent code style, it is recommended to use
|
57
|
+
[rubocop](https://github.com/bbatsov/rubocop). If you use `vim` and
|
58
|
+
[syntastic](https://github.com/vim-syntastic/syntastic), you
|
59
|
+
can use `rubocop` as a Ruby checker. To manually run `rubocop`, you
|
60
|
+
can run the following commands:
|
61
|
+
|
62
|
+
```
|
63
|
+
# Run rubocop for the entire project
|
64
|
+
bundle exec rubocop
|
65
|
+
# Run rubocop for a specific file
|
66
|
+
bundle exec rubocop foo/bar.rb
|
67
|
+
```
|
68
|
+
|
69
|
+
### Documentation
|
70
|
+
Comment any code contributions according to the existing conventions within the project.
|
71
|
+
Reference the examples listed below:
|
72
|
+
|
73
|
+
Example top-level comment:
|
74
|
+
|
75
|
+
```
|
76
|
+
##
|
77
|
+
# = ClassNameGoesHere
|
78
|
+
# Author:: [Author Information]
|
79
|
+
# Copyright:: Copyright [Year] [Author Information]
|
80
|
+
# License:: GNU Public License 3
|
81
|
+
#
|
82
|
+
# This is a class that is something and does something.
|
83
|
+
```
|
84
|
+
|
85
|
+
Example method comment:
|
86
|
+
|
87
|
+
```
|
88
|
+
##
|
89
|
+
# This is a method that does something
|
90
|
+
```
|
91
|
+
|
92
|
+
Documentation should be regenerated prior to merging any branches into master. The latest
|
93
|
+
[documentation](https://d3d1rty.github.io/gbud/) auto-sources off the `docs/` folder on
|
94
|
+
the master branch. For more information on RDoc, go
|
95
|
+
[here](https://rdoc.github.io/rdoc/index.html).
|
96
|
+
|
97
|
+
```
|
98
|
+
# Run custom rake task to regenerate RDoc documentation
|
99
|
+
rake rdoc
|
100
|
+
```
|
101
|
+
|
102
|
+
### Testing
|
103
|
+
Integration tests should be written for all classes and methods. The test suite
|
104
|
+
can be run manually `bundle exec rake test` or automatically using guard `bundle exec guard`.
|
105
|
+
|
106
|
+
## TODO
|
107
|
+
List action items here.
|
108
|
+
|
109
|
+
## Changelog
|
110
|
+
### [Date]
|
111
|
+
* Upgraded to version `X.X.X`.
|
112
|
+
* List other changes made.
|
113
|
+
* ...
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
1
|
+
# Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
2
2
|
#
|
3
3
|
# This file is part of <%= @metadata[:name] %>.
|
4
4
|
#
|
@@ -16,10 +16,25 @@
|
|
16
16
|
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
18
|
require 'minitest/autorun'
|
19
|
-
|
19
|
+
require_relative '../lib/<%= @metadata[:name] %>/hello'
|
20
20
|
|
21
|
+
##
|
22
|
+
# = HelloTest
|
23
|
+
# Author:: <%= @metadata[:authors].join(', ') %>
|
24
|
+
# Copyright:: Copyright <%= Date.today.year %> <%= @metadata[:authors].join(', ') %>
|
25
|
+
# License:: GNU Public License 3
|
26
|
+
#
|
27
|
+
# Contains modularized code for project; given example provides a greeting
|
21
28
|
class HelloTest < Minitest::Test
|
29
|
+
##
|
30
|
+
# Initializes test with sample data
|
31
|
+
def setup
|
32
|
+
@name = 'friend'
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Ensures the greeter is behaving as expected
|
22
37
|
def test_hello
|
23
|
-
assert_equal('Hello, friend.', <%=
|
38
|
+
assert_equal('Hello, friend.', <%= @metadata[:name].split(/-|_/).each{ |s| s.capitalize! }.join %>::Hello.greeting(@name))
|
24
39
|
end
|
25
40
|
end
|
@@ -1,7 +1,3 @@
|
|
1
|
-
# Copyright 2016 Richard Davis
|
2
|
-
#
|
3
|
-
# This file is part of gbud.
|
4
|
-
#
|
5
1
|
# gbud is free software: you can redistribute it and/or modify
|
6
2
|
# it under the terms of the GNU General Public License as published by
|
7
3
|
# the Free Software Foundation, either version 3 of the License, or
|
@@ -18,7 +14,16 @@
|
|
18
14
|
require 'minitest/autorun'
|
19
15
|
require_relative '../lib/gbud/project_builder'
|
20
16
|
|
17
|
+
##
|
18
|
+
# = ProjectBuilderTest
|
19
|
+
# Author:: Richard Davis
|
20
|
+
# Copyright:: Copyright 2017 Richard Davis
|
21
|
+
# License:: GNU Public License 3
|
22
|
+
#
|
23
|
+
# Tests for GBud::ProjectBuilder class functionality.
|
21
24
|
class ProjectBuilderTest < Minitest::Test
|
25
|
+
##
|
26
|
+
# Initializes test with sample data
|
22
27
|
def setup
|
23
28
|
metadata = {
|
24
29
|
name: 'gbud-test',
|
@@ -1,7 +1,3 @@
|
|
1
|
-
# Copyright 2016 Richard Davis
|
2
|
-
#
|
3
|
-
# This file is part of gbud.
|
4
|
-
#
|
5
1
|
# gbud is free software: you can redistribute it and/or modify
|
6
2
|
# it under the terms of the GNU General Public License as published by
|
7
3
|
# the Free Software Foundation, either version 3 of the License, or
|
@@ -18,66 +14,103 @@
|
|
18
14
|
require 'minitest/autorun'
|
19
15
|
require_relative '../lib/gbud/project_metadata'
|
20
16
|
|
17
|
+
##
|
18
|
+
# = ProjectMetadataTest
|
19
|
+
# Author:: Richard Davis
|
20
|
+
# Copyright:: Copyright 2017 Richard Davis
|
21
|
+
# License:: GNU Public License 3
|
22
|
+
#
|
23
|
+
# Tests for GBud::ProjectMetadata class functionality.
|
21
24
|
class ProjectMetadataTest < Minitest::Test
|
25
|
+
##
|
26
|
+
# Initializes test with sample data
|
22
27
|
def setup
|
23
28
|
@metadata = GBud::ProjectMetadata.new
|
24
29
|
end
|
25
30
|
|
31
|
+
##
|
32
|
+
# Tests that an invalid name is not accepted
|
26
33
|
def test_name_mutator_negative
|
27
34
|
@metadata.name = '-test'
|
28
35
|
assert_nil @metadata.name
|
29
36
|
end
|
30
37
|
|
38
|
+
##
|
39
|
+
# Tests that a valid name is accepted
|
31
40
|
def test_name_mutator_positive
|
32
41
|
@metadata.name = 'gbud-test'
|
33
42
|
assert_equal 'gbud-test', @metadata.name
|
34
43
|
end
|
35
44
|
|
45
|
+
##
|
46
|
+
# Tests that an invalid name is rejected by validate_name
|
36
47
|
def test_validate_name_negative
|
37
48
|
assert_nil @metadata.validate_name('-fail')
|
38
49
|
end
|
39
50
|
|
51
|
+
##
|
52
|
+
# Tests that a valid name is accepted by validate_name
|
40
53
|
def test_validate_name_positive
|
41
54
|
assert_equal 0, @metadata.validate_name('test-gem')
|
42
55
|
end
|
43
56
|
|
57
|
+
##
|
58
|
+
# Tests that an invalid email is rejected by validate_email
|
44
59
|
def test_validate_email_negative
|
45
60
|
assert_nil @metadata.validate_email('rvdavis')
|
46
61
|
end
|
47
62
|
|
63
|
+
##
|
64
|
+
# Tests that a valid email is accepted by validate_email
|
48
65
|
def test_validate_email_positive
|
49
66
|
assert_equal 0, @metadata.validate_email('rvdavis@member.fsf.org')
|
50
67
|
end
|
51
68
|
|
69
|
+
##
|
70
|
+
# Tests that an invalid URL is rejected by validate_url
|
52
71
|
def test_validate_url_negative
|
53
72
|
assert_nil @metadata.validate_url('github.com')
|
54
73
|
end
|
55
74
|
|
75
|
+
##
|
76
|
+
# Tests that a valid URL is accepted by validate_url
|
56
77
|
def test_validate_url_positive
|
57
78
|
assert_equal 0, @metadata.validate_url('https://github.com/d3d1rty/gbud')
|
58
79
|
end
|
59
80
|
|
81
|
+
##
|
82
|
+
# Tests that user-provided author list is split into an array
|
60
83
|
def test_authors_mutator
|
61
84
|
@metadata.authors = 'Richard Davis, d3d1rty'
|
62
85
|
assert_equal ['Richard Davis', 'd3d1rty'], @metadata.authors
|
63
86
|
end
|
64
87
|
|
88
|
+
##
|
89
|
+
# Tests that the summary attribute accepts assignment
|
65
90
|
def test_summary_mutator
|
66
91
|
assert_equal 'This is a test', @metadata.summary = 'This is a test'
|
67
92
|
end
|
68
93
|
|
94
|
+
##
|
95
|
+
# Tests that the description attribute accepts assignment
|
69
96
|
def test_description_mutator
|
70
97
|
assert_equal 'This is a test', @metadata.description = 'This is a test'
|
71
98
|
end
|
72
99
|
|
100
|
+
##
|
101
|
+
# Tests that the version attribute is able to be retrieved
|
73
102
|
def test_version_accessor
|
74
103
|
assert_equal '0.0.1', @metadata.version
|
75
104
|
end
|
76
105
|
|
106
|
+
##
|
107
|
+
# Tests that the license attribute is able to be retrieved
|
77
108
|
def test_license_accessor
|
78
109
|
assert_equal 'GPL-3.0', @metadata.license
|
79
110
|
end
|
80
111
|
|
112
|
+
##
|
113
|
+
# Tests that project metadata is properly converted to hash
|
81
114
|
def test_to_hash
|
82
115
|
@metadata.name = 'gbud-test'
|
83
116
|
@metadata.authors = 'Richard Davis, d3d1rty'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gbud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
This project aims to make starting a new gem project simple by automating
|
@@ -22,17 +22,20 @@ files:
|
|
22
22
|
- bin/gbud
|
23
23
|
- lib/assets/LICENSE
|
24
24
|
- lib/gbud.rb
|
25
|
+
- lib/gbud/namespace.rb
|
25
26
|
- lib/gbud/project_builder.rb
|
26
27
|
- lib/gbud/project_metadata.rb
|
27
28
|
- lib/gbud/user_prompt.rb
|
29
|
+
- lib/templates/cli.rb.erb
|
28
30
|
- lib/templates/executable.rb.erb
|
29
31
|
- lib/templates/gemfile.rb.erb
|
30
32
|
- lib/templates/gemspec.rb.erb
|
31
|
-
- lib/templates/guardfile.erb
|
33
|
+
- lib/templates/guardfile.rb.erb
|
32
34
|
- lib/templates/hello.rb.erb
|
33
35
|
- lib/templates/main.rb.erb
|
36
|
+
- lib/templates/namespace.rb.erb
|
34
37
|
- lib/templates/rakefile.rb.erb
|
35
|
-
- lib/templates/readme.
|
38
|
+
- lib/templates/readme.md.erb
|
36
39
|
- lib/templates/test_hello.rb.erb
|
37
40
|
- test/test_project_builder.rb
|
38
41
|
- test/test_project_metadata.rb
|
@@ -56,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
59
|
version: '0'
|
57
60
|
requirements: []
|
58
61
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
62
|
+
rubygems_version: 2.6.11
|
60
63
|
signing_key:
|
61
64
|
specification_version: 4
|
62
65
|
summary: Initializes the basic structure of a gem
|
File without changes
|
data/lib/templates/readme.rb.erb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#<%= @metadata[:name] %>
|
2
|
-
##Description
|
3
|
-
<%= @metadata[:description] %>
|
4
|
-
##Next Steps
|
5
|
-
* Initiate a git repo with `git init`
|
6
|
-
* Run `bundle install` to get the dependencies
|
7
|
-
* Write some code!
|
8
|
-
* Execute `gem build foobar.gemspec` to build your gem
|
9
|
-
* Execute `gem install foobar-0.0.1.gem` to install your gem
|
10
|
-
* Share!
|
11
|
-
##License
|
12
|
-
See `LICENSE` in the project root directory for license information.
|