mcornick-jeweler 1.2.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/.gitignore +9 -0
- data/ChangeLog.markdown +111 -0
- data/LICENSE +20 -0
- data/README.markdown +185 -0
- data/ROADMAP +12 -0
- data/Rakefile +103 -0
- data/VERSION.yml +4 -0
- data/bin/jeweler +8 -0
- data/features/generator/cucumber.feature +83 -0
- data/features/generator/directory_layout.feature +76 -0
- data/features/generator/dotdocument.feature +14 -0
- data/features/generator/env_options.feature +9 -0
- data/features/generator/git.feature +94 -0
- data/features/generator/license.feature +11 -0
- data/features/generator/rakefile.feature +151 -0
- data/features/generator/readme.feature +12 -0
- data/features/generator/test.feature +41 -0
- data/features/generator/test_helper.feature +49 -0
- data/features/placeholder.feature +5 -0
- data/features/step_definitions/debug_steps.rb +6 -0
- data/features/step_definitions/filesystem_steps.rb +68 -0
- data/features/step_definitions/generator_steps.rb +284 -0
- data/features/step_definitions/task_steps.rb +6 -0
- data/features/support/env.rb +29 -0
- data/features/tasks/build_gem.feature +9 -0
- data/features/tasks/version.feature +24 -0
- data/features/tasks/version_bumping.feature +33 -0
- data/jeweler.gemspec +225 -0
- data/lib/jeweler.rb +153 -0
- data/lib/jeweler/commands.rb +14 -0
- data/lib/jeweler/commands/build_gem.rb +31 -0
- data/lib/jeweler/commands/check_dependencies.rb +52 -0
- data/lib/jeweler/commands/install_gem.rb +40 -0
- data/lib/jeweler/commands/release.rb +86 -0
- data/lib/jeweler/commands/release_to_rubyforge.rb +51 -0
- data/lib/jeweler/commands/setup_rubyforge.rb +57 -0
- data/lib/jeweler/commands/validate_gemspec.rb +30 -0
- data/lib/jeweler/commands/version/base.rb +41 -0
- data/lib/jeweler/commands/version/bump_major.rb +13 -0
- data/lib/jeweler/commands/version/bump_minor.rb +12 -0
- data/lib/jeweler/commands/version/bump_patch.rb +14 -0
- data/lib/jeweler/commands/version/write.rb +12 -0
- data/lib/jeweler/commands/write_gemspec.rb +39 -0
- data/lib/jeweler/errors.rb +20 -0
- data/lib/jeweler/gemspec_helper.rb +79 -0
- data/lib/jeweler/generator.rb +306 -0
- data/lib/jeweler/generator/application.rb +54 -0
- data/lib/jeweler/generator/bacon_mixin.rb +43 -0
- data/lib/jeweler/generator/micronaut_mixin.rb +41 -0
- data/lib/jeweler/generator/minitest_mixin.rb +42 -0
- data/lib/jeweler/generator/options.rb +102 -0
- data/lib/jeweler/generator/rdoc_mixin.rb +9 -0
- data/lib/jeweler/generator/rspec_mixin.rb +42 -0
- data/lib/jeweler/generator/shoulda_mixin.rb +42 -0
- data/lib/jeweler/generator/testunit_mixin.rb +39 -0
- data/lib/jeweler/generator/yard_mixin.rb +14 -0
- data/lib/jeweler/rubyforge_tasks.rb +98 -0
- data/lib/jeweler/specification.rb +66 -0
- data/lib/jeweler/tasks.rb +135 -0
- data/lib/jeweler/templates/.document +5 -0
- data/lib/jeweler/templates/.gitignore +5 -0
- data/lib/jeweler/templates/LICENSE +20 -0
- data/lib/jeweler/templates/README.rdoc +18 -0
- data/lib/jeweler/templates/Rakefile +153 -0
- data/lib/jeweler/templates/bacon/flunking.rb +7 -0
- data/lib/jeweler/templates/bacon/helper.rb +8 -0
- data/lib/jeweler/templates/features/default.feature +9 -0
- data/lib/jeweler/templates/features/support/env.rb +8 -0
- data/lib/jeweler/templates/micronaut/flunking.rb +7 -0
- data/lib/jeweler/templates/micronaut/helper.rb +17 -0
- data/lib/jeweler/templates/minitest/flunking.rb +7 -0
- data/lib/jeweler/templates/minitest/helper.rb +11 -0
- data/lib/jeweler/templates/rspec/flunking.rb +7 -0
- data/lib/jeweler/templates/rspec/helper.rb +10 -0
- data/lib/jeweler/templates/shoulda/flunking.rb +7 -0
- data/lib/jeweler/templates/shoulda/helper.rb +10 -0
- data/lib/jeweler/templates/testunit/flunking.rb +7 -0
- data/lib/jeweler/templates/testunit/helper.rb +9 -0
- data/lib/jeweler/version_helper.rb +128 -0
- data/test/fixtures/bar/VERSION.yml +4 -0
- data/test/fixtures/bar/bin/foo_the_ultimate_bin +1 -0
- data/test/fixtures/bar/hey_include_me_in_gemspec +0 -0
- data/test/fixtures/bar/lib/foo_the_ultimate_lib.rb +1 -0
- data/test/fixtures/existing-project-with-version-plaintext/.document +5 -0
- data/test/fixtures/existing-project-with-version-plaintext/.gitignore +5 -0
- data/test/fixtures/existing-project-with-version-plaintext/LICENSE +20 -0
- data/test/fixtures/existing-project-with-version-plaintext/README.rdoc +7 -0
- data/test/fixtures/existing-project-with-version-plaintext/Rakefile +82 -0
- data/test/fixtures/existing-project-with-version-plaintext/VERSION +1 -0
- data/test/fixtures/existing-project-with-version-plaintext/existing-project-with-version.gemspec +29 -0
- data/test/fixtures/existing-project-with-version-plaintext/lib/existing_project_with_version.rb +0 -0
- data/test/fixtures/existing-project-with-version-plaintext/test/existing_project_with_version_test.rb +7 -0
- data/test/fixtures/existing-project-with-version-plaintext/test/test_helper.rb +10 -0
- data/test/fixtures/existing-project-with-version-yaml/.document +5 -0
- data/test/fixtures/existing-project-with-version-yaml/.gitignore +5 -0
- data/test/fixtures/existing-project-with-version-yaml/LICENSE +20 -0
- data/test/fixtures/existing-project-with-version-yaml/README.rdoc +7 -0
- data/test/fixtures/existing-project-with-version-yaml/Rakefile +82 -0
- data/test/fixtures/existing-project-with-version-yaml/VERSION.yml +4 -0
- data/test/fixtures/existing-project-with-version-yaml/bin/foo_the_ultimate_bin +0 -0
- data/test/fixtures/existing-project-with-version-yaml/existing-project-with-version.gemspec +29 -0
- data/test/fixtures/existing-project-with-version-yaml/lib/existing_project_with_version.rb +0 -0
- data/test/fixtures/existing-project-with-version-yaml/test/existing_project_with_version_test.rb +7 -0
- data/test/fixtures/existing-project-with-version-yaml/test/test_helper.rb +10 -0
- data/test/geminstaller.yml +12 -0
- data/test/jeweler/commands/test_build_gem.rb +72 -0
- data/test/jeweler/commands/test_install_gem.rb +74 -0
- data/test/jeweler/commands/test_release.rb +362 -0
- data/test/jeweler/commands/test_release_to_rubyforge.rb +157 -0
- data/test/jeweler/commands/test_setup_rubyforge.rb +182 -0
- data/test/jeweler/commands/test_validate_gemspec.rb +27 -0
- data/test/jeweler/commands/test_write_gemspec.rb +92 -0
- data/test/jeweler/commands/version/test_base.rb +32 -0
- data/test/jeweler/commands/version/test_bump_major.rb +22 -0
- data/test/jeweler/commands/version/test_bump_minor.rb +19 -0
- data/test/jeweler/commands/version/test_bump_patch.rb +20 -0
- data/test/jeweler/commands/version/test_write.rb +23 -0
- data/test/shoulda_macros/jeweler_macros.rb +35 -0
- data/test/test_application.rb +139 -0
- data/test/test_gemspec_helper.rb +40 -0
- data/test/test_generator.rb +166 -0
- data/test/test_generator_initialization.rb +156 -0
- data/test/test_generator_mixins.rb +18 -0
- data/test/test_helper.rb +159 -0
- data/test/test_jeweler.rb +174 -0
- data/test/test_options.rb +149 -0
- data/test/test_specification.rb +61 -0
- data/test/test_tasks.rb +35 -0
- data/test/test_version_helper.rb +153 -0
- metadata +283 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
class Jeweler
|
2
|
+
module Commands
|
3
|
+
class WriteGemspec
|
4
|
+
attr_accessor :base_dir, :gemspec, :version, :output, :gemspec_helper, :version_helper
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.output = $stdout
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
version_helper.refresh
|
12
|
+
gemspec_helper.spec.version = version_helper.to_s
|
13
|
+
gemspec_helper.spec.date = Time.now
|
14
|
+
|
15
|
+
gemspec_helper.write
|
16
|
+
|
17
|
+
output.puts "Generated: #{gemspec_helper.path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def gemspec_helper
|
21
|
+
@gemspec_helper ||= GemSpecHelper.new(self.gemspec, self.base_dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.build_for(jeweler)
|
25
|
+
command = new
|
26
|
+
|
27
|
+
command.base_dir = jeweler.base_dir
|
28
|
+
command.gemspec = jeweler.gemspec
|
29
|
+
command.version = jeweler.version
|
30
|
+
command.output = jeweler.output
|
31
|
+
command.gemspec_helper = jeweler.gemspec_helper
|
32
|
+
command.version_helper = jeweler.version_helper
|
33
|
+
|
34
|
+
command
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Jeweler
|
2
|
+
# Gemspec related error
|
3
|
+
class GemspecError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class VersionYmlError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
# Occurs when interacting with RubyForge, and an expected project isn't available on RubyForge.
|
10
|
+
class MissingRubyForgePackageError < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
# Occurs when interacting with RubyForge, and 'rubyforge_project' isn't set on the Gem::Specification
|
14
|
+
class NoRubyForgeProjectInGemspecError < StandardError
|
15
|
+
end
|
16
|
+
|
17
|
+
# Occurs when interacting with RubyForge, and the 'rubyforge_project' isn't setup in ~/.rubyforge/autoconfig.yml or it doesn't exist on RubyForge
|
18
|
+
class RubyForgeProjectNotConfiguredError < StandardError
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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
|
+
normalize_files(:files)
|
25
|
+
normalize_files(:files)
|
26
|
+
normalize_files(:extra_rdoc_files)
|
27
|
+
|
28
|
+
File.open(path, 'w') do |f|
|
29
|
+
gemspec_ruby = @spec.to_ruby
|
30
|
+
gemspec_ruby = prettyify_array(gemspec_ruby, :files)
|
31
|
+
gemspec_ruby = prettyify_array(gemspec_ruby, :test_files)
|
32
|
+
gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files)
|
33
|
+
f.puts "# Generated by jeweler"
|
34
|
+
f.puts "# DO NOT EDIT THIS FILE"
|
35
|
+
f.puts "# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`"
|
36
|
+
f.write gemspec_ruby
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def path
|
41
|
+
denormalized_path = File.join(@base_dir, "#{@spec.name}.gemspec")
|
42
|
+
absolute_path = File.expand_path(denormalized_path)
|
43
|
+
absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse
|
47
|
+
data = File.read(path)
|
48
|
+
parsed_gemspec = nil
|
49
|
+
Thread.new { parsed_gemspec = eval("$SAFE = 3\n#{data}", binding, path) }.join
|
50
|
+
parsed_gemspec
|
51
|
+
end
|
52
|
+
|
53
|
+
def normalize_files(array_name)
|
54
|
+
array = @spec.send(array_name)
|
55
|
+
# only keep files, no directories, and sort
|
56
|
+
array = array.select do |path|
|
57
|
+
File.file? File.join(@base_dir, path)
|
58
|
+
end.sort
|
59
|
+
|
60
|
+
@spec.send("#{array_name}=", array)
|
61
|
+
end
|
62
|
+
|
63
|
+
def prettyify_array(gemspec_ruby, array_name)
|
64
|
+
gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
|
65
|
+
leadin, files = match[0..-2].split("[")
|
66
|
+
leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def gem_path
|
71
|
+
File.join(@base_dir, 'pkg', parse.file_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_version(version)
|
75
|
+
@spec.version = version.to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,306 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
require 'jeweler/generator/bacon_mixin'
|
8
|
+
require 'jeweler/generator/micronaut_mixin'
|
9
|
+
require 'jeweler/generator/minitest_mixin'
|
10
|
+
require 'jeweler/generator/rspec_mixin'
|
11
|
+
require 'jeweler/generator/shoulda_mixin'
|
12
|
+
require 'jeweler/generator/testunit_mixin'
|
13
|
+
|
14
|
+
require 'jeweler/generator/rdoc_mixin'
|
15
|
+
require 'jeweler/generator/yard_mixin'
|
16
|
+
|
17
|
+
class Jeweler
|
18
|
+
class NoGitUserName < StandardError
|
19
|
+
end
|
20
|
+
class NoGitUserEmail < StandardError
|
21
|
+
end
|
22
|
+
class FileInTheWay < StandardError
|
23
|
+
end
|
24
|
+
class NoGitHubRepoNameGiven < StandardError
|
25
|
+
end
|
26
|
+
class NoGitHubUser < StandardError
|
27
|
+
end
|
28
|
+
class NoGitHubToken < StandardError
|
29
|
+
end
|
30
|
+
class GitInitFailed < StandardError
|
31
|
+
end
|
32
|
+
|
33
|
+
class Generator
|
34
|
+
attr_accessor :target_dir, :user_name, :user_email, :summary,
|
35
|
+
:description, :project_name, :github_username, :github_token,
|
36
|
+
:repo, :should_create_repo,
|
37
|
+
:testing_framework, :documentation_framework,
|
38
|
+
:should_use_cucumber, :should_setup_gemcutter,
|
39
|
+
:should_setup_rubyforge, :should_use_reek, :should_use_roodi,
|
40
|
+
:development_dependencies
|
41
|
+
|
42
|
+
DEFAULT_TESTING_FRAMEWORK = :shoulda
|
43
|
+
DEFAULT_DOCUMENTATION_FRAMEWORK = :rdoc
|
44
|
+
|
45
|
+
def initialize(project_name, options = {})
|
46
|
+
if project_name.nil? || project_name.squeeze.strip == ""
|
47
|
+
raise NoGitHubRepoNameGiven
|
48
|
+
end
|
49
|
+
|
50
|
+
self.development_dependencies = []
|
51
|
+
|
52
|
+
self.project_name = project_name
|
53
|
+
|
54
|
+
self.testing_framework = (options[:testing_framework] || DEFAULT_TESTING_FRAMEWORK).to_sym
|
55
|
+
self.documentation_framework = options[:documentation_framework] || DEFAULT_DOCUMENTATION_FRAMEWORK
|
56
|
+
begin
|
57
|
+
generator_mixin_name = "#{self.testing_framework.to_s.capitalize}Mixin"
|
58
|
+
generator_mixin = self.class.const_get(generator_mixin_name)
|
59
|
+
extend generator_mixin
|
60
|
+
rescue NameError => e
|
61
|
+
raise ArgumentError, "Unsupported testing framework (#{testing_framework})"
|
62
|
+
end
|
63
|
+
|
64
|
+
begin
|
65
|
+
generator_mixin_name = "#{self.documentation_framework.to_s.capitalize}Mixin"
|
66
|
+
generator_mixin = self.class.const_get(generator_mixin_name)
|
67
|
+
extend generator_mixin
|
68
|
+
rescue NameError => e
|
69
|
+
raise ArgumentError, "Unsupported documentation framework (#{documentation_framework})"
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
self.target_dir = options[:directory] || self.project_name
|
74
|
+
|
75
|
+
self.should_create_repo = options[:create_repo]
|
76
|
+
self.summary = options[:summary] || 'TODO: one-line summary of your gem'
|
77
|
+
self.description = options[:description] || 'TODO: longer description of your gem'
|
78
|
+
self.should_use_cucumber = options[:use_cucumber]
|
79
|
+
self.should_use_reek = options[:use_reek]
|
80
|
+
self.should_use_roodi = options[:use_roodi]
|
81
|
+
self.should_setup_gemcutter = options[:gemcutter]
|
82
|
+
self.should_setup_rubyforge = options[:rubyforge]
|
83
|
+
|
84
|
+
development_dependencies << "cucumber" if should_use_cucumber
|
85
|
+
|
86
|
+
use_user_git_config
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def run
|
91
|
+
create_files
|
92
|
+
gitify
|
93
|
+
$stdout.puts "Jeweler has prepared your gem in #{target_dir}"
|
94
|
+
if should_create_repo
|
95
|
+
create_and_push_repo
|
96
|
+
$stdout.puts "Jeweler has pushed your repo to #{project_homepage}"
|
97
|
+
enable_gem_for_repo
|
98
|
+
$stdout.puts "Jeweler has enabled gem building for your repo"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def git_remote
|
103
|
+
"git@github.com:#{github_username}/#{project_name}.git"
|
104
|
+
end
|
105
|
+
|
106
|
+
def project_homepage
|
107
|
+
"http://github.com/#{github_username}/#{project_name}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def constant_name
|
111
|
+
self.project_name.split(/[-_]/).collect{|each| each.capitalize }.join
|
112
|
+
end
|
113
|
+
|
114
|
+
def lib_filename
|
115
|
+
"#{project_name}.rb"
|
116
|
+
end
|
117
|
+
|
118
|
+
def require_name
|
119
|
+
self.project_name
|
120
|
+
end
|
121
|
+
|
122
|
+
def file_name_prefix
|
123
|
+
self.project_name.gsub('-', '_')
|
124
|
+
end
|
125
|
+
|
126
|
+
def lib_dir
|
127
|
+
'lib'
|
128
|
+
end
|
129
|
+
|
130
|
+
def feature_filename
|
131
|
+
"#{project_name}.feature"
|
132
|
+
end
|
133
|
+
|
134
|
+
def steps_filename
|
135
|
+
"#{project_name}_steps.rb"
|
136
|
+
end
|
137
|
+
|
138
|
+
def features_dir
|
139
|
+
'features'
|
140
|
+
end
|
141
|
+
|
142
|
+
def features_support_dir
|
143
|
+
File.join(features_dir, 'support')
|
144
|
+
end
|
145
|
+
|
146
|
+
def features_steps_dir
|
147
|
+
File.join(features_dir, 'step_definitions')
|
148
|
+
end
|
149
|
+
|
150
|
+
protected
|
151
|
+
|
152
|
+
# This is in a separate method so we can stub it out during testing
|
153
|
+
def read_git_config
|
154
|
+
Git.global_config
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
def create_files
|
159
|
+
unless File.exists?(target_dir) || File.directory?(target_dir)
|
160
|
+
FileUtils.mkdir target_dir
|
161
|
+
else
|
162
|
+
raise FileInTheWay, "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?"
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
output_template_in_target '.gitignore'
|
167
|
+
output_template_in_target 'Rakefile'
|
168
|
+
output_template_in_target 'LICENSE'
|
169
|
+
output_template_in_target 'README.rdoc'
|
170
|
+
output_template_in_target '.document'
|
171
|
+
|
172
|
+
mkdir_in_target lib_dir
|
173
|
+
touch_in_target File.join(lib_dir, lib_filename)
|
174
|
+
|
175
|
+
mkdir_in_target test_dir
|
176
|
+
output_template_in_target File.join(testing_framework.to_s, 'helper.rb'), File.join(test_dir, test_helper_filename)
|
177
|
+
output_template_in_target File.join(testing_framework.to_s, 'flunking.rb'), File.join(test_dir, test_filename)
|
178
|
+
|
179
|
+
if should_use_cucumber
|
180
|
+
mkdir_in_target features_dir
|
181
|
+
output_template_in_target File.join(%w(features default.feature)), File.join('features', feature_filename)
|
182
|
+
|
183
|
+
mkdir_in_target features_support_dir
|
184
|
+
output_template_in_target File.join(features_support_dir, 'env.rb')
|
185
|
+
|
186
|
+
mkdir_in_target features_steps_dir
|
187
|
+
touch_in_target File.join(features_steps_dir, steps_filename)
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
def use_user_git_config
|
193
|
+
git_config = self.read_git_config
|
194
|
+
|
195
|
+
unless git_config.has_key? 'user.name'
|
196
|
+
raise NoGitUserName
|
197
|
+
end
|
198
|
+
|
199
|
+
unless git_config.has_key? 'user.email'
|
200
|
+
raise NoGitUserEmail
|
201
|
+
end
|
202
|
+
|
203
|
+
unless git_config.has_key? 'github.user'
|
204
|
+
raise NoGitHubUser
|
205
|
+
end
|
206
|
+
|
207
|
+
if should_create_repo
|
208
|
+
unless git_config.has_key? 'github.token'
|
209
|
+
raise NoGitHubToken
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
self.user_name = git_config['user.name']
|
214
|
+
self.user_email = git_config['user.email']
|
215
|
+
self.github_username = git_config['github.user']
|
216
|
+
self.github_token = git_config['github.token']
|
217
|
+
end
|
218
|
+
|
219
|
+
def output_template_in_target(source, destination = source)
|
220
|
+
final_destination = File.join(target_dir, destination)
|
221
|
+
|
222
|
+
template_contents = File.read(File.join(template_dir, source))
|
223
|
+
template = ERB.new(template_contents, nil, '<>')
|
224
|
+
|
225
|
+
template_result = template.result(binding).gsub(/\n\n\n+/, "\n\n")
|
226
|
+
|
227
|
+
File.open(final_destination, 'w') {|file| file.write(template_result)}
|
228
|
+
|
229
|
+
$stdout.puts "\tcreate\t#{destination}"
|
230
|
+
end
|
231
|
+
|
232
|
+
def template_dir
|
233
|
+
File.join(File.dirname(__FILE__), 'templates')
|
234
|
+
end
|
235
|
+
|
236
|
+
def mkdir_in_target(directory)
|
237
|
+
final_destination = File.join(target_dir, directory)
|
238
|
+
|
239
|
+
FileUtils.mkdir final_destination
|
240
|
+
|
241
|
+
$stdout.puts "\tcreate\t#{directory}"
|
242
|
+
end
|
243
|
+
|
244
|
+
def touch_in_target(destination)
|
245
|
+
final_destination = File.join(target_dir, destination)
|
246
|
+
FileUtils.touch final_destination
|
247
|
+
$stdout.puts "\tcreate\t#{destination}"
|
248
|
+
end
|
249
|
+
|
250
|
+
def gitify
|
251
|
+
saved_pwd = Dir.pwd
|
252
|
+
Dir.chdir(target_dir)
|
253
|
+
begin
|
254
|
+
begin
|
255
|
+
@repo = Git.init()
|
256
|
+
rescue Git::GitExecuteError => e
|
257
|
+
raise GitInitFailed, "Encountered an error during gitification. Maybe the repo already exists, or has already been pushed to?"
|
258
|
+
end
|
259
|
+
|
260
|
+
begin
|
261
|
+
@repo.add('.')
|
262
|
+
rescue Git::GitExecuteError => e
|
263
|
+
#raise GitAddFailed, "There was some problem adding this directory to the git changeset"
|
264
|
+
raise
|
265
|
+
end
|
266
|
+
|
267
|
+
begin
|
268
|
+
@repo.commit "Initial commit to #{project_name}."
|
269
|
+
rescue Git::GitExecuteError => e
|
270
|
+
raise
|
271
|
+
end
|
272
|
+
|
273
|
+
begin
|
274
|
+
@repo.add_remote('origin', git_remote)
|
275
|
+
rescue Git::GitExecuteError => e
|
276
|
+
puts "Encountered an error while adding origin remote. Maybe you have some weird settings in ~/.gitconfig?"
|
277
|
+
raise
|
278
|
+
end
|
279
|
+
ensure
|
280
|
+
Dir.chdir(saved_pwd)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def create_and_push_repo
|
285
|
+
Net::HTTP.post_form URI.parse('http://github.com/repositories'),
|
286
|
+
'login' => github_username,
|
287
|
+
'token' => github_token,
|
288
|
+
'repository[description]' => summary,
|
289
|
+
'repository[name]' => project_name
|
290
|
+
# TODO do a HEAD request to see when it's ready
|
291
|
+
@repo.push('origin')
|
292
|
+
end
|
293
|
+
|
294
|
+
def enable_gem_for_repo
|
295
|
+
url = "https://github.com/#{github_username}/#{project_name}/update"
|
296
|
+
`curl -F 'login=#{github_username}' -F 'token=#{github_token}' -F 'field=repository_rubygem' -F 'value=1' #{url} 2>/dev/null`
|
297
|
+
# FIXME use NET::HTTP instead of curl
|
298
|
+
#Net::HTTP.post_form URI.parse(url),
|
299
|
+
#'login' => github_username,
|
300
|
+
#'token' => github_token,
|
301
|
+
#'field' => 'repository_rubygem',
|
302
|
+
#'value' => '1'
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
end
|