gbud 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gbud +16 -0
- data/lib/assets/LICENSE +674 -0
- data/lib/gbud.rb +91 -3
- data/lib/gbud/project_builder.rb +113 -0
- data/lib/gbud/project_metadata.rb +83 -0
- data/lib/gbud/user_prompt.rb +43 -0
- data/lib/templates/executable.rb.erb +24 -0
- data/lib/templates/gemfile.rb.erb +24 -0
- data/lib/templates/gemspec.rb.erb +40 -0
- data/lib/templates/guardfile.erb.rb +0 -0
- data/lib/templates/hello.rb.erb +24 -0
- data/lib/templates/main.rb.erb +19 -0
- data/lib/templates/rakefile.rb.erb +22 -0
- data/lib/templates/readme.rb.erb +12 -0
- data/lib/templates/test_hello.rb.erb +25 -0
- data/test/test_project_builder.rb +33 -0
- data/test/test_project_metadata.rb +90 -0
- metadata +22 -10
- data/lib/gbud/base.rb +0 -91
- data/lib/gbud/getinfo.rb +0 -29
- data/test/test_getinfo.rb +0 -54
data/lib/gbud.rb
CHANGED
@@ -1,3 +1,91 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
|
1
|
+
# Copyright 2016 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
|
+
require 'fileutils'
|
19
|
+
require 'optparse'
|
20
|
+
require 'erb'
|
21
|
+
|
22
|
+
require 'gbud/user_prompt'
|
23
|
+
require 'gbud/project_metadata'
|
24
|
+
require 'gbud/project_builder'
|
25
|
+
|
26
|
+
trap('INT') do
|
27
|
+
puts "\nTerminating..."
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
options = {}
|
32
|
+
|
33
|
+
optparse = OptionParser.new do |opts|
|
34
|
+
opts.banner = 'Usage: gbud [options]'
|
35
|
+
|
36
|
+
opts.on('-n', '--new NAME', 'Creates a project given a name') do |name|
|
37
|
+
options[:name] = name
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on('--cli', 'Creates an executable with option parsing') do
|
41
|
+
options[:cli] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on('-l', '--license', 'Displays the copyright notice') do
|
45
|
+
puts "This program is free software: you can redistribute it and/or modify
|
46
|
+
it under the terms of the GNU General Public License as published by
|
47
|
+
the Free Software Foundation, either version 3 of the License, or
|
48
|
+
(at your option) any later version.
|
49
|
+
"
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('-w', '--warranty', 'Displays the warranty statement') do
|
53
|
+
puts "This program is distributed in the hope that it will be useful,
|
54
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
55
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
56
|
+
GNU General Public License for more details.
|
57
|
+
"
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on_tail('-h', '--help', 'Displays the help screen') do
|
61
|
+
puts opts
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
optparse.parse!
|
67
|
+
|
68
|
+
if options[:name]
|
69
|
+
metadata = GBud::ProjectMetadata.new
|
70
|
+
metadata.name = options[:name]
|
71
|
+
if metadata.name.nil?
|
72
|
+
puts 'Invalid gem name. See RubyGems for gem naming conventions.'
|
73
|
+
exit 1
|
74
|
+
end
|
75
|
+
metadata.authors = GBud::UserPrompt.get_value 'Project authors => '
|
76
|
+
loop do
|
77
|
+
metadata.email = GBud::UserPrompt.get_value 'Project email => '
|
78
|
+
break unless metadata.email.nil?
|
79
|
+
puts 'Please enter a valid email address.'
|
80
|
+
end
|
81
|
+
loop do
|
82
|
+
metadata.url = GBud::UserPrompt.get_value 'Project website => '
|
83
|
+
break unless metadata.url.nil?
|
84
|
+
puts 'Please enter a valid project URL'
|
85
|
+
end
|
86
|
+
metadata.summary = GBud::UserPrompt.get_value 'Enter a short summary of the project => '
|
87
|
+
metadata.description = GBud::UserPrompt.get_value 'Enter a description of the project => '
|
88
|
+
project = GBud::ProjectBuilder.new metadata.to_hash, false
|
89
|
+
project.build
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright 2016 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
|
+
module GBud
|
19
|
+
class ProjectBuilder
|
20
|
+
attr_reader :metadata, :cli, :files, :paths
|
21
|
+
|
22
|
+
##
|
23
|
+
# Instantiates the ProjectBuilder object using information provided
|
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
|
+
#
|
29
|
+
def initialize metadata, cli
|
30
|
+
@metadata = metadata
|
31
|
+
@cli = cli
|
32
|
+
@files = {
|
33
|
+
readme: 'README.md',
|
34
|
+
gemspec: "#{metadata[:name]}.gemspec",
|
35
|
+
gemfile: 'Gemfile',
|
36
|
+
rakefile: 'Rakefile',
|
37
|
+
main: "#{metadata[:name]}.rb",
|
38
|
+
hello: "hello.rb",
|
39
|
+
test_hello: "test_hello.rb"
|
40
|
+
}
|
41
|
+
@paths = {
|
42
|
+
project_dir: "#{metadata[:name]}/",
|
43
|
+
project_lib_dir: "#{metadata[:name]}/lib/",
|
44
|
+
project_lib_project_dir: "#{metadata[:name]}/lib/#{metadata[:name]}/",
|
45
|
+
project_test_dir: "#{metadata[:name]}/test/"
|
46
|
+
}
|
47
|
+
if cli == true
|
48
|
+
@files[:executable] = "#{metadata[:name]}"
|
49
|
+
@paths[:project_bin_dir] = "#{metadata[:name]}/bin/"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def build
|
54
|
+
make_directories
|
55
|
+
make_files
|
56
|
+
make_executable :executable if @cli == true
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
##
|
62
|
+
# make_directories
|
63
|
+
# Creates the project directory structure
|
64
|
+
def make_directories
|
65
|
+
@paths.each do |path, dir|
|
66
|
+
FileUtils.mkdir_p(dir)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def make_files
|
71
|
+
@files.each do |template, filename|
|
72
|
+
directory = map_template template
|
73
|
+
file = File.new "#{directory}#{filename}", 'w+'
|
74
|
+
file.puts(render template)
|
75
|
+
file.close
|
76
|
+
make_executable if template == :executable
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def map_template template
|
81
|
+
dir = case template
|
82
|
+
when :readme
|
83
|
+
@paths[:project_dir]
|
84
|
+
when :gemspec
|
85
|
+
@paths[:project_dir]
|
86
|
+
when :gemfile
|
87
|
+
@paths[:project_dir]
|
88
|
+
when :rakefile
|
89
|
+
@paths[:project_dir]
|
90
|
+
when :main
|
91
|
+
@paths[:project_lib_dir]
|
92
|
+
when :hello
|
93
|
+
@paths[:project_lib_project_dir]
|
94
|
+
when :executable
|
95
|
+
@paths[:project_bin_dir]
|
96
|
+
when :test_hello
|
97
|
+
@paths[:project_test_dir]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def render template
|
102
|
+
path = File.expand_path(File.join(File.dirname(__FILE__),
|
103
|
+
'..',
|
104
|
+
'templates',
|
105
|
+
"#{template.to_s}.rb.erb"))
|
106
|
+
ERB.new(File.read(path)).result(binding)
|
107
|
+
end
|
108
|
+
|
109
|
+
def make_executable
|
110
|
+
File.chmod(0755, "#{@paths[:project_bin_dir]}#{@files[:executable]}")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright 2016 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
|
+
module GBud
|
19
|
+
class ProjectMetadata
|
20
|
+
attr_reader :name,
|
21
|
+
:summary,
|
22
|
+
:description,
|
23
|
+
:authors,
|
24
|
+
:email,
|
25
|
+
:url,
|
26
|
+
:version,
|
27
|
+
:license
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@version = '0.0.1'
|
31
|
+
@license = 'GPL-3.0'
|
32
|
+
end
|
33
|
+
|
34
|
+
def name= name
|
35
|
+
@name = name unless validate_name(name).nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def authors= authors
|
39
|
+
@authors = authors.split(', ')
|
40
|
+
end
|
41
|
+
|
42
|
+
def email= email
|
43
|
+
@email = email unless validate_email(email).nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def url= url
|
47
|
+
@url = url unless validate_url(url).nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def summary= summary
|
51
|
+
@summary = summary
|
52
|
+
end
|
53
|
+
|
54
|
+
def description= description
|
55
|
+
@description = description
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_hash
|
59
|
+
{
|
60
|
+
name: @name,
|
61
|
+
authors: @authors,
|
62
|
+
email: @email,
|
63
|
+
url: @url,
|
64
|
+
summary: @summary,
|
65
|
+
description: @description,
|
66
|
+
version: @version,
|
67
|
+
license: @license
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def validate_name name
|
72
|
+
/\A[a-z][a-z0-9_\-]*\Z/i =~ name
|
73
|
+
end
|
74
|
+
|
75
|
+
def validate_email email
|
76
|
+
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i =~ email
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate_url url
|
80
|
+
/https?:\/\/[\S]+/ =~ url
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright 2016 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
|
+
module GBud
|
19
|
+
module UserPrompt
|
20
|
+
@value = ''
|
21
|
+
|
22
|
+
def self.get_value prompt
|
23
|
+
prompt_user prompt
|
24
|
+
@value
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.prompt_user prompt
|
28
|
+
loop do
|
29
|
+
print prompt
|
30
|
+
@value = gets.chomp.to_s
|
31
|
+
break if confirm_input
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.confirm_input
|
36
|
+
puts "You have entered: #{@value}"
|
37
|
+
print 'Is this correct? (Y/N) => '
|
38
|
+
confirm = gets.chomp.to_s.upcase
|
39
|
+
return false unless confirm == 'Y'
|
40
|
+
true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby'
|
2
|
+
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
3
|
+
#
|
4
|
+
# This file is part of <%= @metadata[:name] %>.
|
5
|
+
#
|
6
|
+
# <%= @metadata[:name] %> is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# <%= @metadata[:name] %> is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
begin
|
20
|
+
require '<%= @metadata[:name] %>'
|
21
|
+
rescue LoadError
|
22
|
+
require 'rubygems'
|
23
|
+
require '<%= @metadata[:name] %>'
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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
|
+
source 'https://rubygems.org'
|
19
|
+
ruby '2.3.1'
|
20
|
+
|
21
|
+
gem 'pry', '~> 0.10.4'
|
22
|
+
gem 'rake', '~> 12.0'
|
23
|
+
gem 'minitest', '~> 5.0'
|
24
|
+
gem 'rubocop', '~> 0.46.0'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Copyright <%= Date.today.year %> <%= metadata[:authors].join(', ') %>
|
3
|
+
#
|
4
|
+
# This file is part of <%= @metadata[:name] %>.
|
5
|
+
#
|
6
|
+
# <%= @metadata[:name] %> is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# <%= @metadata[:name] %> is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with <%= @metadata[:name] %>. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
lib = File.expand_path('../lib', __FILE__)
|
20
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
21
|
+
|
22
|
+
Gem::Specification.new do |s|
|
23
|
+
s.name = '<%= @metadata[:name] %>'
|
24
|
+
s.version = '<%= @metadata[:version] %>'
|
25
|
+
s.platform = Gem::Platform::RUBY
|
26
|
+
s.authors = <%= @metadata[:authors] %>
|
27
|
+
s.email = '<%= @metadata[:email] %>'
|
28
|
+
s.homepage = '<%= @metadata[:url] %>'
|
29
|
+
s.summary = '<%= @metadata[:summary] %>'
|
30
|
+
s.description = <<-EOF
|
31
|
+
<%= @metadata[:description] %>
|
32
|
+
EOF
|
33
|
+
s.license = '<%= @metadata[:license] %>'
|
34
|
+
s.files = Dir['lib/**/*']
|
35
|
+
<% if @cli == true %>
|
36
|
+
s.executables = ['<%= @metadata[:name] %>']
|
37
|
+
<% end %>
|
38
|
+
s.test_files = Dir['test/**/*']
|
39
|
+
s.require_path = ['lib']
|
40
|
+
end
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
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
|
+
module <%= @metadata[:name].split('-').each{ |s| s.capitalize! }.join %>
|
19
|
+
class Hello
|
20
|
+
def self.greeting
|
21
|
+
'Hello, friend.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|