gemplate 1.1.2 → 2.0.0

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
  SHA1:
3
- metadata.gz: cf5a16e79a6f8f2d1f2c03bc8874f5123f0881ab
4
- data.tar.gz: f76157f458ce552ca27ded77611df91f2037eefd
3
+ metadata.gz: 5ab8d805386162f2bcd34bb9894e45b53b5dba99
4
+ data.tar.gz: a3691e3870fb55acc31649bf7193f867f310b711
5
5
  SHA512:
6
- metadata.gz: 42e0e47defbb3fc84ace865030d3a7d6ebeca7daa8a4b1d6df308c24bd50b1e68df81fbc37d37eee125576cb47732aa559d36229301d2bffebb174ff539760cc
7
- data.tar.gz: ce34c6ee232993a40663c882b3ed236332e9877be89d4b804c3056077da2f5bc0e8dcb17d766e5dcf30d3d15b099369e68984fdf6f8c22e5bbe7ff302f979787
6
+ metadata.gz: 37b24362c21916c73d7e0fc564435e0074a5deb137412a083ce50ee63e6d8e398a36762b6beb763ae9033a80271020dbae892749c7527727ff10fe1fb86bd4e3
7
+ data.tar.gz: 825790cbbf44693a76b93e632a47677c505c2f84b53c16f19c9409d6608c5446061ae33baa1300a0a889122ad8d92f2d753672994860cd3a38a512a1fbad98eb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 2.0.0 / 2015-11-05
2
+
3
+ * [FEATURE] Switch to Mercenary for better CLI interaction
4
+ * [ENHANCEMENT] Add --skip flag to skip GitHub steps
5
+
1
6
  # 1.1.0 / 2015-09-21
2
7
 
3
8
  * [FEATURE] Replace TravisCI with CircleCI
data/bin/gemplate CHANGED
@@ -4,41 +4,67 @@ require 'gemplate'
4
4
  require 'userinput'
5
5
  require 'rugged'
6
6
  require 'curb'
7
+ require 'mercenary'
7
8
 
8
- name = ARGV.first
9
- name = UserInput.new(message: 'Gem name', default: name).ask
9
+ Mercenary.program(:gemplate) do |p|
10
+ p.version Gemplate::VERSION
11
+ p.description 'Tool for bootstrapping new gems'
12
+ p.syntax 'gemplate [options] GEM_NAME'
10
13
 
11
- user = Rugged::Config.global['github.user'] || ENV['USER']
12
- user = UserInput.new(message: 'GitHub username', default: user).ask
14
+ p.option :user, '-u', '--user', 'GitHub username'
15
+ p.option :org, '-o', '--org', 'GitHub organization'
16
+ p.option :full_name, '-n', '--name', 'Full name'
17
+ p.option :email, '-e', '--email', 'Email address'
18
+ p.option :license, '-l', '--license', 'License'
19
+ p.option :skip_github, '-s', '--skip', 'Skip GitHub steps'
13
20
 
14
- org = user
15
- org = UserInput.new(message: 'GitHub organization', default: org).ask
21
+ p.action do |_, options|
22
+ options[:name] = ARGV.first || UserInput.new(message: 'Gem name').ask
16
23
 
17
- full_name = Rugged::Config.global['user.name']
18
- full_name = UserInput.new(message: 'Full name', default: full_name).ask
24
+ unless options[:user]
25
+ options[:user] = Rugged::Config.global['github.user'] || ENV['USER']
26
+ options[:user] = UserInput.new(
27
+ message: 'GitHub username', default: user
28
+ ).ask
29
+ end
19
30
 
20
- email = Rugged::Config.global['user.email']
21
- email = UserInput.new(message: 'Email address', default: email).ask
31
+ unless options[:org]
32
+ options[:org] = user
33
+ options[:org] = UserInput.new(
34
+ message: 'GitHub organization', default: org
35
+ ).ask
36
+ end
22
37
 
23
- license_validation = proc do |lname|
24
- url = "https://raw.githubusercontent.com/akerl/licenses/master/#{lname}.txt"
25
- Curl::Easy.http_head(url).response_code == 200
26
- end
38
+ unless options[:full_name]
39
+ options[:full_name] = Rugged::Config.global['user.name']
40
+ options[:full_name] = UserInput.new(
41
+ message: 'Full name', default: full_name
42
+ ).ask
43
+ end
44
+
45
+ unless options[:email]
46
+ options[:email] = Rugged::Config.global['user.email']
47
+ options[:email] = UserInput.new(
48
+ message: 'Email address', default: email
49
+ ).ask
50
+ end
51
+
52
+ license_validation = proc do |x|
53
+ url = "https://raw.githubusercontent.com/akerl/licenses/master/#{x}.txt"
54
+ Curl::Easy.http_head(url).response_code == 200
55
+ end
27
56
 
28
- puts 'Available licenses can be found here: https://github.com/akerl/licenses'
29
- license = UserInput.new(
30
- message: 'License',
31
- default: 'MIT',
32
- validation: license_validation
33
- ).ask
34
-
35
- Gemplate.new(
36
- name: name,
37
- user: user,
38
- org: org,
39
- full_name: full_name,
40
- email: email,
41
- license: license
42
- ).create
43
-
44
- puts 'New gem has been created!'
57
+ unless options[:license]
58
+ puts 'List of licenses: https://github.com/akerl/licenses'
59
+ options[:license] = UserInput.new(
60
+ message: 'License',
61
+ default: 'MIT',
62
+ validation: license_validation
63
+ ).ask
64
+ end
65
+
66
+ Gemplate.new(options).create
67
+
68
+ puts 'New gem has been created!'
69
+ end
70
+ end
data/gemplate.gemspec CHANGED
@@ -1,6 +1,9 @@
1
+ $:.unshift File.expand_path('../lib/', __FILE__)
2
+ require 'gemplate/version'
3
+
1
4
  Gem::Specification.new do |s|
2
5
  s.name = 'gemplate'
3
- s.version = '1.1.2'
6
+ s.version = Gemplate::VERSION
4
7
  s.date = Time.now.strftime('%Y-%m-%d')
5
8
 
6
9
  s.summary = 'Bootstrap tool for making gems'
@@ -19,6 +22,7 @@ Gem::Specification.new do |s|
19
22
  s.add_dependency 'octoauth', '~> 1.3.0'
20
23
  s.add_dependency 'octokit', '~> 4.1.0'
21
24
  s.add_dependency 'curb', '~> 0.8.6'
25
+ s.add_dependency 'mercenary', '~> 0.3.4'
22
26
 
23
27
  s.add_development_dependency 'rubocop', '~> 0.34.0'
24
28
  s.add_development_dependency 'rake', '~> 10.4.0'
@@ -26,5 +30,5 @@ Gem::Specification.new do |s|
26
30
  s.add_development_dependency 'rspec', '~> 3.3.0'
27
31
  s.add_development_dependency 'fuubar', '~> 2.0.0'
28
32
  s.add_development_dependency 'webmock', '~> 1.22.0'
29
- s.add_development_dependency 'vcr', '~> 2.9.2'
33
+ s.add_development_dependency 'vcr', '~> 3.0.0'
30
34
  end
data/lib/gemplate.rb CHANGED
@@ -1,10 +1,3 @@
1
- require 'rugged'
2
- require 'pathname'
3
- require 'fileutils'
4
- require 'curb'
5
- require 'octoauth'
6
- require 'octokit'
7
-
8
1
  ##
9
2
  # Bootstrap tool for new gems
10
3
  module Gemplate
@@ -16,101 +9,7 @@ module Gemplate
16
9
  self::Gem.new(*args)
17
10
  end
18
11
  end
19
-
20
- TEMPLATE = "#{Pathname.new(__FILE__).parent.parent}/template"
21
- LICENSE_URL = 'https://raw.githubusercontent.com/akerl/licenses/master'
22
-
23
- ##
24
- # Gem directory object
25
- class Gem
26
- def initialize(params = {})
27
- @name = params[:name]
28
- @user = params[:user]
29
- @org = params[:org]
30
- @full_name = params[:full_name]
31
- @email = params[:email]
32
- @license = params[:license]
33
- @authfile = params[:authfile] || :default
34
- end
35
-
36
- def create
37
- create_directory
38
- Dir.chdir @name
39
- add_license
40
- process_templates
41
- adjust_files
42
- make_repo
43
- Dir.chdir '..'
44
- end
45
-
46
- private
47
-
48
- def create_directory
49
- fail "#{@name} already exists" if File.exist? @name
50
- FileUtils.cp_r TEMPLATE, @name
51
- end
52
-
53
- def dependencies
54
- source = "#{TEMPLATE}/../gemplate.gemspec"
55
- File.read(source).lines.select { |x| x.include? 's.add_dev' }.join.strip
56
- end
57
-
58
- def add_license
59
- url = "#{LICENSE_URL}/#{@license}.txt"
60
- File.open('LICENSE', 'w') do |fh|
61
- license = Curl::Easy.perform(url)
62
- if license.response_code == 404
63
- fail ArgumentError, 'Invalid license name provided'
64
- end
65
- fh.write license.body_str
66
- end
67
- end
68
-
69
- def replacements
70
- [
71
- [/AUTHOR_NAME/, @user],
72
- [/LICENSE_NAME/, @license],
73
- [/FULL_NAME/, @full_name],
74
- [/REPO_NAME/, @name],
75
- [/EMAIL_ADDRESS/, @email],
76
- [/CURRENT_YEAR/, Time.now.strftime('%Y')],
77
- [/#DEV_DEPS/, dependencies]
78
- ]
79
- end
80
-
81
- def process_templates
82
- Dir.glob('**/*', File::FNM_DOTMATCH).each do |path|
83
- next unless File.file? path
84
- text = File.read path
85
- replacements.each { |regex, new| text.gsub! regex, new }
86
- File.open(path, 'w') { |fh| fh.write text }
87
- end
88
- end
89
-
90
- def adjust_files
91
- moves = [['REPO_NAME.gemspec', "#{@name}.gemspec"],
92
- ['lib/REPO_NAME.rb', "lib/#{@name}.rb"],
93
- ['spec/REPO_NAME_spec.rb', "spec/#{@name}_spec.rb"]]
94
- moves.each { |original, new| FileUtils.move original, new }
95
- end
96
-
97
- def make_repo
98
- Rugged::Repository.init_at '.'
99
- `git remote add origin "git@github.com:#{org || @user}/#{@name}"`
100
- `git config branch.master.remote origin`
101
- `git config branch.master.merge refs/heads/master`
102
- github_api.create_repo(@name, organization: org, has_wiki: false)
103
- end
104
-
105
- def org
106
- @org == @user ? nil : @org
107
- end
108
-
109
- def github_api
110
- return @api_client if @api_client
111
- auth = Octoauth.new note: 'gemplate', scopes: ['repo'], file: @authfile
112
- auth.save
113
- @api_client = Octokit::Client.new(access_token: auth.token)
114
- end
115
- end
116
12
  end
13
+
14
+ require 'gemplate/gem'
15
+ require 'gemplate/version'
@@ -0,0 +1,109 @@
1
+ require 'rugged'
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ require 'curb'
5
+ require 'octoauth'
6
+ require 'octokit'
7
+
8
+ ##
9
+ # Bootstrap tool for new gems
10
+ module Gemplate
11
+ TEMPLATE = "#{Pathname.new(__FILE__).parent.parent.parent}/template"
12
+ LICENSE_URL = 'https://raw.githubusercontent.com/akerl/licenses/master'
13
+
14
+ ##
15
+ # Gem directory object
16
+ class Gem
17
+ def initialize(params = {})
18
+ @name = params[:name]
19
+ @user = params[:user]
20
+ @org = params[:org]
21
+ @full_name = params[:full_name]
22
+ @email = params[:email]
23
+ @license = params[:license]
24
+ @authfile = params[:authfile] || :default
25
+ @skip_github = params[:skip_github]
26
+ end
27
+
28
+ def create
29
+ create_directory
30
+ Dir.chdir @name
31
+ add_license
32
+ process_templates
33
+ adjust_files
34
+ make_repo
35
+ Dir.chdir '..'
36
+ end
37
+
38
+ private
39
+
40
+ def create_directory
41
+ fail "#{@name} already exists" if File.exist? @name
42
+ FileUtils.cp_r TEMPLATE, @name
43
+ end
44
+
45
+ def dependencies
46
+ source = "#{TEMPLATE}/../gemplate.gemspec"
47
+ File.read(source).lines.select { |x| x.include? 's.add_dev' }.join.strip
48
+ end
49
+
50
+ def add_license
51
+ url = "#{LICENSE_URL}/#{@license}.txt"
52
+ File.open('LICENSE', 'w') do |fh|
53
+ license = Curl::Easy.perform(url)
54
+ if license.response_code == 404
55
+ fail ArgumentError, 'Invalid license name provided'
56
+ end
57
+ fh.write license.body_str
58
+ end
59
+ end
60
+
61
+ def replacements
62
+ [
63
+ [/AUTHOR_NAME/, @user],
64
+ [/LICENSE_NAME/, @license],
65
+ [/FULL_NAME/, @full_name],
66
+ [/REPO_NAME/, @name],
67
+ [/EMAIL_ADDRESS/, @email],
68
+ [/CURRENT_YEAR/, Time.now.strftime('%Y')],
69
+ [/#DEV_DEPS/, dependencies]
70
+ ]
71
+ end
72
+
73
+ def process_templates
74
+ Dir.glob('**/*', File::FNM_DOTMATCH).each do |path|
75
+ next unless File.file? path
76
+ text = File.read path
77
+ replacements.each { |regex, new| text.gsub! regex, new }
78
+ File.open(path, 'w') { |fh| fh.write text }
79
+ end
80
+ end
81
+
82
+ def adjust_files
83
+ moves = [['REPO_NAME.gemspec', "#{@name}.gemspec"],
84
+ ['lib/REPO_NAME.rb', "lib/#{@name}.rb"],
85
+ ['spec/REPO_NAME_spec.rb', "spec/#{@name}_spec.rb"]]
86
+ moves.each { |original, new| FileUtils.move original, new }
87
+ end
88
+
89
+ def make_repo
90
+ Rugged::Repository.init_at '.'
91
+ return if @skip_github
92
+ `git remote add origin "git@github.com:#{org || @user}/#{@name}"`
93
+ `git config branch.master.remote origin`
94
+ `git config branch.master.merge refs/heads/master`
95
+ github_api.create_repo(@name, organization: org, has_wiki: false)
96
+ end
97
+
98
+ def org
99
+ @org == @user ? nil : @org
100
+ end
101
+
102
+ def github_api
103
+ return @api_client if @api_client
104
+ auth = Octoauth.new note: 'gemplate', scopes: ['repo'], file: @authfile
105
+ auth.save
106
+ @api_client = Octokit::Client.new(access_token: auth.token)
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,5 @@
1
+ ##
2
+ # Declare version of module
3
+ module Gemplate
4
+ VERSION = '2.0.0'
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-01 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.8.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: mercenary
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.4
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +184,14 @@ dependencies:
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: 2.9.2
187
+ version: 3.0.0
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: 2.9.2
194
+ version: 3.0.0
181
195
  description: Creates a basic repository layout for a new gem
182
196
  email: me@lesaker.org
183
197
  executables:
@@ -198,6 +212,8 @@ files:
198
212
  - circle.yml
199
213
  - gemplate.gemspec
200
214
  - lib/gemplate.rb
215
+ - lib/gemplate/gem.rb
216
+ - lib/gemplate/version.rb
201
217
  - spec/creds.yml
202
218
  - spec/fixtures/cassettes/bad_license.yml
203
219
  - spec/fixtures/cassettes/subject_create.yml
@@ -235,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
251
  version: '0'
236
252
  requirements: []
237
253
  rubyforge_project:
238
- rubygems_version: 2.4.5.1
254
+ rubygems_version: 2.4.5
239
255
  signing_key:
240
256
  specification_version: 4
241
257
  summary: Bootstrap tool for making gems