mattknox-jeweler 0.7.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.
- data/ChangeLog.markdown +14 -0
- data/LICENSE +20 -0
- data/README.markdown +90 -0
- data/Rakefile +43 -0
- data/TODO +13 -0
- data/VERSION.yml +4 -0
- data/bin/jeweler +72 -0
- data/lib/jeweler.rb +231 -0
- data/lib/jeweler/errors.rb +8 -0
- data/lib/jeweler/gemspec.rb +41 -0
- data/lib/jeweler/generator.rb +190 -0
- data/lib/jeweler/tasks.rb +109 -0
- data/lib/jeweler/templates/.gitignore +3 -0
- data/lib/jeweler/templates/LICENSE +20 -0
- data/lib/jeweler/templates/README +9 -0
- data/lib/jeweler/templates/Rakefile +40 -0
- data/lib/jeweler/templates/bacon/flunking_spec.rb +7 -0
- data/lib/jeweler/templates/bacon/spec_helper.rb +8 -0
- data/lib/jeweler/templates/shoulda/flunking_test.rb +7 -0
- data/lib/jeweler/templates/shoulda/test_helper.rb +10 -0
- data/lib/jeweler/version.rb +81 -0
- data/test/fixtures/bar/VERSION.yml +4 -0
- data/test/generators/initialization_test.rb +146 -0
- data/test/shoulda_macros/jeweler_macros.rb +35 -0
- data/test/test_gemspec.rb +32 -0
- data/test/test_generator.rb +269 -0
- data/test/test_helper.rb +63 -0
- data/test/test_jeweler.rb +133 -0
- data/test/test_tasks.rb +39 -0
- data/test/test_version.rb +115 -0
- metadata +102 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
class Jeweler
|
2
|
+
|
3
|
+
class GemSpecHelper
|
4
|
+
|
5
|
+
attr_accessor :spec, :base_dir
|
6
|
+
|
7
|
+
def initialize(spec, base_dir = nil)
|
8
|
+
self.spec = spec
|
9
|
+
self.base_dir = base_dir || ''
|
10
|
+
|
11
|
+
yield spec if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
begin
|
16
|
+
parse
|
17
|
+
true
|
18
|
+
rescue
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def write
|
24
|
+
File.open(path, 'w') do |f|
|
25
|
+
f.write @spec.to_ruby
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def path
|
30
|
+
denormalized_path = File.join(@base_dir, "#{@spec.name}.gemspec")
|
31
|
+
absolute_path = File.expand_path(denormalized_path)
|
32
|
+
absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse
|
36
|
+
data = File.read(path)
|
37
|
+
Thread.new { eval("$SAFE = 3\n#{data}", binding, path) }.join
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
class Jeweler
|
8
|
+
class NoGitUserName < StandardError
|
9
|
+
end
|
10
|
+
class NoGitUserEmail < StandardError
|
11
|
+
end
|
12
|
+
class FileInTheWay < StandardError
|
13
|
+
end
|
14
|
+
class NoGitHubRepoNameGiven < StandardError
|
15
|
+
end
|
16
|
+
class NoGitHubUser < StandardError
|
17
|
+
end
|
18
|
+
class NoGitHubToken < StandardError
|
19
|
+
end
|
20
|
+
class GitInitFailed < StandardError
|
21
|
+
end
|
22
|
+
|
23
|
+
class Generator
|
24
|
+
attr_accessor :target_dir, :user_name, :user_email, :summary,
|
25
|
+
:github_repo_name, :github_remote, :github_url,
|
26
|
+
:github_username, :github_token,
|
27
|
+
:lib_dir, :constant_name, :file_name_prefix, :config, :test_style,
|
28
|
+
:repo, :should_create_repo
|
29
|
+
|
30
|
+
def initialize(github_repo_name, options = {})
|
31
|
+
check_user_git_config()
|
32
|
+
|
33
|
+
if github_repo_name.nil?
|
34
|
+
raise NoGitHubRepoNameGiven
|
35
|
+
end
|
36
|
+
self.github_repo_name = github_repo_name
|
37
|
+
|
38
|
+
self.github_remote = "git@github.com:#{github_username}/#{github_repo_name}.git"
|
39
|
+
self.github_url = "http://github.com/#{github_username}/#{github_repo_name}"
|
40
|
+
|
41
|
+
self.test_style = options[:test_style] || :shoulda
|
42
|
+
self.target_dir = options[:directory] || self.github_repo_name
|
43
|
+
self.lib_dir = File.join(target_dir, 'lib')
|
44
|
+
self.constant_name = self.github_repo_name.split(/[-_]/).collect{|each| each.capitalize }.join
|
45
|
+
self.file_name_prefix = self.github_repo_name.gsub('-', '_')
|
46
|
+
self.should_create_repo = options[:create_repo]
|
47
|
+
self.summary = options[:summary] || 'TODO'
|
48
|
+
end
|
49
|
+
|
50
|
+
def run
|
51
|
+
create_files
|
52
|
+
gitify
|
53
|
+
puts "Jeweler has prepared your gem in #{github_repo_name}"
|
54
|
+
if should_create_repo
|
55
|
+
create_and_push_repo
|
56
|
+
puts "Jeweler has pushed your repo to #{github_url}"
|
57
|
+
enable_gem_for_repo
|
58
|
+
puts "Jeweler has enabled gem building for your repo"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def testspec
|
63
|
+
case test_style
|
64
|
+
when :shoulda
|
65
|
+
'test'
|
66
|
+
when :bacon
|
67
|
+
'spec'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_dir
|
72
|
+
File.join(target_dir, testspec)
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
private
|
77
|
+
def create_files
|
78
|
+
unless File.exists?(target_dir) || File.directory?(target_dir)
|
79
|
+
FileUtils.mkdir target_dir
|
80
|
+
else
|
81
|
+
raise FileInTheWay, "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?"
|
82
|
+
end
|
83
|
+
|
84
|
+
FileUtils.mkdir lib_dir
|
85
|
+
FileUtils.mkdir test_dir
|
86
|
+
|
87
|
+
output_template_in_target('.gitignore')
|
88
|
+
output_template_in_target('Rakefile')
|
89
|
+
output_template_in_target('LICENSE')
|
90
|
+
output_template_in_target('README')
|
91
|
+
output_template_in_target("#{test_style}/#{testspec}_helper.rb", "#{testspec}/#{testspec}_helper.rb")
|
92
|
+
output_template_in_target("#{test_style}/flunking_#{testspec}.rb", "#{testspec}/#{file_name_prefix}_#{testspec}.rb")
|
93
|
+
|
94
|
+
FileUtils.touch File.join(lib_dir, "#{file_name_prefix}.rb")
|
95
|
+
end
|
96
|
+
|
97
|
+
def check_user_git_config
|
98
|
+
self.config = read_git_config
|
99
|
+
|
100
|
+
unless config.has_key? 'user.name'
|
101
|
+
raise NoGitUserName
|
102
|
+
end
|
103
|
+
|
104
|
+
unless config.has_key? 'user.email'
|
105
|
+
raise NoGitUserEmail
|
106
|
+
end
|
107
|
+
|
108
|
+
unless config.has_key? 'github.user'
|
109
|
+
raise NoGitHubUser
|
110
|
+
end
|
111
|
+
|
112
|
+
unless config.has_key? 'github.token'
|
113
|
+
raise NoGitHubToken
|
114
|
+
end
|
115
|
+
|
116
|
+
self.user_name = config['user.name']
|
117
|
+
self.user_email = config['user.email']
|
118
|
+
self.github_username = config['github.user']
|
119
|
+
self.github_token = config['github.token']
|
120
|
+
end
|
121
|
+
|
122
|
+
def output_template_in_target(source, destination = source)
|
123
|
+
template = ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', source)))
|
124
|
+
|
125
|
+
File.open(File.join(target_dir, destination), 'w') {|file| file.write(template.result(binding))}
|
126
|
+
end
|
127
|
+
|
128
|
+
def gitify
|
129
|
+
saved_pwd = Dir.pwd
|
130
|
+
Dir.chdir(target_dir)
|
131
|
+
begin
|
132
|
+
begin
|
133
|
+
@repo = Git.init()
|
134
|
+
rescue Git::GitExecuteError => e
|
135
|
+
raise GitInitFailed, "Encountered an error during gitification. Maybe the repo already exists, or has already been pushed to?"
|
136
|
+
end
|
137
|
+
|
138
|
+
begin
|
139
|
+
@repo.add('.')
|
140
|
+
rescue Git::GitExecuteError => e
|
141
|
+
#raise GitAddFailed, "There was some problem adding this directory to the git changeset"
|
142
|
+
raise
|
143
|
+
end
|
144
|
+
|
145
|
+
begin
|
146
|
+
@repo.commit "Initial commit to #{github_repo_name}."
|
147
|
+
rescue Git::GitExecuteError => e
|
148
|
+
raise
|
149
|
+
end
|
150
|
+
|
151
|
+
begin
|
152
|
+
@repo.add_remote('origin', github_remote)
|
153
|
+
rescue Git::GitExecuteError => e
|
154
|
+
puts "Encountered an error while adding origin remote. Maybe you have some weird settings in ~/.gitconfig?"
|
155
|
+
raise
|
156
|
+
end
|
157
|
+
ensure
|
158
|
+
Dir.chdir(saved_pwd)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def create_and_push_repo
|
163
|
+
Net::HTTP.post_form URI.parse('http://github.com/repositories'),
|
164
|
+
'login' => github_username,
|
165
|
+
'token' => github_token,
|
166
|
+
'repository[description]' => summary,
|
167
|
+
'repository[name]' => github_repo_name
|
168
|
+
sleep 2
|
169
|
+
@repo.push('origin')
|
170
|
+
end
|
171
|
+
|
172
|
+
def enable_gem_for_repo
|
173
|
+
url = "https://github.com/#{github_username}/#{github_repo_name}/update"
|
174
|
+
`curl -F 'login=#{github_username}' -F 'token=#{github_token}' -F 'field=repository_rubygem' -F 'value=1' #{url} 2>/dev/null`
|
175
|
+
# FIXME use NET::HTTP instead of curl
|
176
|
+
#Net::HTTP.post_form URI.parse(url),
|
177
|
+
#'login' => github_username,
|
178
|
+
#'token' => github_token,
|
179
|
+
#'field' => 'repository_rubygem',
|
180
|
+
#'value' => '1'
|
181
|
+
end
|
182
|
+
|
183
|
+
def read_git_config
|
184
|
+
# we could just use Git::Base's .config, but that relies on a repo being around already
|
185
|
+
# ... which we don't have yet, since this is part of a sanity check
|
186
|
+
lib = Git::Lib.new(nil, nil)
|
187
|
+
config = lib.parse_config '~/.gitconfig'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
|
4
|
+
class Jeweler
|
5
|
+
class Tasks < ::Rake::TaskLib
|
6
|
+
attr_accessor :gemspec, :jeweler
|
7
|
+
|
8
|
+
def initialize(gemspec = nil, &block)
|
9
|
+
@gemspec = gemspec || Gem::Specification.new()
|
10
|
+
yield @gemspec if block_given?
|
11
|
+
|
12
|
+
@jeweler = Jeweler.new(@gemspec)
|
13
|
+
|
14
|
+
define
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def define
|
19
|
+
desc "Setup initial version of 0.0.0"
|
20
|
+
file "VERSION.yml" do
|
21
|
+
@jeweler.write_version 0, 0, 0, :commit => false
|
22
|
+
$stdout.puts "Created VERSION.yml: 0.0.0"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Build gem"
|
26
|
+
task :build => :'gem:build'
|
27
|
+
|
28
|
+
desc "Build gem"
|
29
|
+
task :gem => :'gem:build'
|
30
|
+
|
31
|
+
desc "Install gem using sudo"
|
32
|
+
task :install => :'gem:install'
|
33
|
+
|
34
|
+
namespace :gem do
|
35
|
+
desc "Install gem using sudo"
|
36
|
+
task :install => :build do
|
37
|
+
@jeweler.install_gem
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Build gem"
|
41
|
+
task :build => :'gemspec:validate' do
|
42
|
+
@jeweler.build_gem
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Generate and validates gemspec"
|
47
|
+
task :gemspec => ['gemspec:generate', 'gemspec:validate']
|
48
|
+
|
49
|
+
namespace :gemspec do
|
50
|
+
desc "Validates the gemspec"
|
51
|
+
task :validate => 'VERSION.yml' do
|
52
|
+
@jeweler.validate_gemspec
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Generates the gemspec, using version from VERSION.yml"
|
56
|
+
task :generate => 'VERSION.yml' do
|
57
|
+
@jeweler.write_gemspec
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Displays the current version"
|
62
|
+
task :version => 'version:display'
|
63
|
+
|
64
|
+
namespace :version do
|
65
|
+
task :bump => "bump:patch"
|
66
|
+
desc "Setup initial version of 0.0.0"
|
67
|
+
task :setup => "VERSION.yml"
|
68
|
+
|
69
|
+
desc "Writes out an explicit version. Respects the following environment variables, or defaults to 0: MAJOR, MINOR, PATCH"
|
70
|
+
task :write do
|
71
|
+
major, minor, patch = ENV['MAJOR'].to_i, ENV['MINOR'].to_i, ENV['PATCH'].to_i
|
72
|
+
@jeweler.write_version(major, minor, patch, :announce => false, :commit => false)
|
73
|
+
$stdout.puts "Updated version: #{@jeweler.version}"
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "Displays the current version"
|
77
|
+
task :display => :setup do
|
78
|
+
$stdout.puts "Current version: #{@jeweler.version}"
|
79
|
+
end
|
80
|
+
|
81
|
+
namespace :bump do
|
82
|
+
desc "Bump the gemspec by a major version."
|
83
|
+
task :major => ['VERSION.yml', :display] do
|
84
|
+
@jeweler.bump_major_version
|
85
|
+
$stdout.puts "Updated version: #{@jeweler.version}"
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Bump the gemspec by a minor version."
|
89
|
+
task :minor => ['VERSION.yml', 'version:display'] do
|
90
|
+
@jeweler.bump_minor_version
|
91
|
+
$stdout.puts "Updated version: #{@jeweler.version}"
|
92
|
+
end
|
93
|
+
|
94
|
+
desc "Bump the gemspec by a patch version."
|
95
|
+
task :patch => ['VERSION.yml', 'version:display'] do
|
96
|
+
@jeweler.bump_patch_version
|
97
|
+
$stdout.puts "Updated version: #{@jeweler.version}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
desc "Release the current version. Includes updating the gemspec, pushing, and tagging the release"
|
103
|
+
task :release do
|
104
|
+
@jeweler.release
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 <%= user_name %>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rcov/rcovtask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = "<%= github_repo_name %>"
|
10
|
+
s.summary = %Q{<%= summary %>}
|
11
|
+
s.email = "<%= user_email %>"
|
12
|
+
s.homepage = "<%= github_url %>"
|
13
|
+
s.description = "TODO"
|
14
|
+
s.authors = ["<%= user_name %>"]
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
Rake::TestTask.new do |t|
|
21
|
+
t.libs << 'lib'
|
22
|
+
t.pattern = '<%= testspec %>/**/*_<%= testspec %>.rb'
|
23
|
+
t.verbose = false
|
24
|
+
end
|
25
|
+
|
26
|
+
Rake::RDocTask.new do |rdoc|
|
27
|
+
rdoc.rdoc_dir = 'rdoc'
|
28
|
+
rdoc.title = '<%= github_repo_name %>'
|
29
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
30
|
+
rdoc.rdoc_files.include('README*')
|
31
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
32
|
+
end
|
33
|
+
|
34
|
+
Rcov::RcovTask.new do |t|
|
35
|
+
t.libs << '<%= testspec %>'
|
36
|
+
t.test_files = FileList['<%= testspec %>/**/*_<%= testspec %>.rb']
|
37
|
+
t.verbose = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :rcov
|