gem-release 0.0.7 → 0.0.8

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.
@@ -0,0 +1,18 @@
1
+ module Kernel
2
+ def silence
3
+ silence_stream(STDOUT, STDERR) { yield }
4
+ end
5
+
6
+ def silence_stream(*streams)
7
+ on_hold = streams.collect{ |stream| stream.dup }
8
+ streams.each do |stream|
9
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
10
+ stream.sync = true
11
+ end
12
+ yield
13
+ ensure
14
+ streams.each_with_index do |stream, i|
15
+ stream.reopen(on_hold[i])
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def camelize
3
+ split(/[^a-z0-9]/i).map { |word| word.capitalize }.join
4
+ end
5
+ end unless String.new.respond_to?(:camelize)
@@ -0,0 +1,7 @@
1
+ module GemRelease
2
+ autoload :CommandOptions, 'gem_release/command_options'
3
+ autoload :Gemspec, 'gem_release/gemspec'
4
+ autoload :Helpers, 'gem_release/helpers'
5
+ autoload :Template, 'gem_release/template'
6
+ autoload :Version, 'gem_release/version'
7
+ end
@@ -0,0 +1,11 @@
1
+ module GemRelease
2
+ module CommandOptions
3
+ def option(key, short, description)
4
+ long = "--[no-]#{key}"
5
+ default = self.class::OPTIONS[key]
6
+ add_option(short, long, description, "Defaults to #{default}") do |value, options|
7
+ options[key] = value
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module GemRelease
2
+ class Gemspec < Template
3
+ attr_reader :authors, :email, :homepage, :summary, :description
4
+
5
+ def initialize(options = {})
6
+ super
7
+
8
+ @authors ||= [`git config --get user.name`.strip]
9
+ @email ||= `git config --get user.email`.strip
10
+ @github_user ||= `git config --get github.user`.strip
11
+ @homepage ||= "http://github.com/#{@github_user}/#{name}" || "[your github name]"
12
+
13
+ @summary ||= '[summary]'
14
+ @description ||= '[description]'
15
+ end
16
+
17
+ def files
18
+ case @strategy || :git
19
+ when :glob
20
+ "Dir['{lib/**/*,[A-Z]*}']"
21
+ when :git
22
+ '`git ls-files {app,lib}`.split("\n")'
23
+ end
24
+ end
25
+
26
+ def filename
27
+ "#{name}.gemspec"
28
+ end
29
+
30
+ def template_name
31
+ 'gemspec.erb'
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,19 @@
1
+ require 'core_ext/kernel/silence'
2
+
1
3
  module GemRelease
2
4
  module Helpers
5
+ def github_user
6
+ @github_user ||= `git config --get github.user`.strip
7
+ end
8
+
9
+ def github_token
10
+ @github_token ||= `git config --get github.token`.strip
11
+ end
12
+
13
+ def gem_name
14
+ @gem_name ||= gemspec ? gemspec.name : File.basename(Dir.pwd)
15
+ end
16
+
3
17
  def gem_filename
4
18
  gemspec.file_name
5
19
  end
@@ -9,7 +23,9 @@ module GemRelease
9
23
  end
10
24
 
11
25
  def gemspec
12
- @gemspec ||= Gem::Specification.load(gemspec_filename)
26
+ @gemspec ||= silence { Gem::Specification.load(gemspec_filename) }
27
+ rescue LoadError, RuntimeError
28
+ nil
13
29
  end
14
30
 
15
31
  def gemspec_filename
@@ -0,0 +1,30 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+ require 'core_ext/string/camelize'
4
+
5
+ module GemRelease
6
+ class Template
7
+ attr_reader :name, :module_name, :module_path
8
+
9
+ def initialize(options = {})
10
+ options.each { |key, value| instance_variable_set(:"@#{key}", value) }
11
+
12
+ @name ||= File.basename(Dir.pwd)
13
+ @module_path ||= name.gsub('-', '_')
14
+ @module_name ||= module_path.camelize
15
+ end
16
+
17
+ def write
18
+ FileUtils.mkdir_p(File.dirname(filename))
19
+ File.open(filename, 'w+') { |f| f.write(render) }
20
+ end
21
+
22
+ def render
23
+ ERB.new(template, nil, "%").result(binding)
24
+ end
25
+
26
+ def template
27
+ File.new(File.expand_path("../templates/#{template_name}", __FILE__)).read
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ $: << File.expand_path('../lib', __FILE__)
4
+ require '<%= module_path %>/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = <%= name.inspect %>
8
+ s.version = <%= module_name %>::VERSION
9
+ s.authors = <%= authors.inspect %>
10
+ s.email = <%= email.inspect %>
11
+ s.homepage = <%= homepage.inspect %>
12
+ s.summary = <%= summary.inspect %>
13
+ s.description = <%= description.inspect %>
14
+
15
+ s.files = <%= files %>
16
+ s.platform = Gem::Platform::RUBY
17
+ s.require_path = 'lib'
18
+ s.rubyforge_project = '[none]'
19
+ s.required_rubygems_version = '>= 1.3.6'
20
+ end
@@ -0,0 +1,3 @@
1
+ module <%= module_name %>
2
+ VERSION = <%= version.inspect %>
3
+ end
@@ -1,3 +1,20 @@
1
1
  module GemRelease
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
+
4
+ class Version < Template
5
+ attr_reader :version
6
+
7
+ def initialize(options = {})
8
+ super
9
+ @version ||= '0.0.1'
10
+ end
11
+
12
+ def filename
13
+ "lib/#{module_path}/version.rb"
14
+ end
15
+
16
+ def template_name
17
+ 'version.erb'
18
+ end
19
+ end
3
20
  end
@@ -0,0 +1,64 @@
1
+ require 'gem_release/helpers'
2
+
3
+ class Gem::Commands::InitCommand < Gem::Command
4
+ include GemRelease
5
+ include Helpers, CommandOptions
6
+
7
+ OPTIONS = {
8
+ :gemspec => true,
9
+ :scaffold => false,
10
+ :github => false
11
+ }
12
+
13
+ attr_reader :arguments, :usage
14
+
15
+ def initialize
16
+ super 'init', 'Initialize a new gem source repository', OPTIONS
17
+
18
+ option :gemspec, '-g', 'Generate a .gemspec'
19
+ option :scaffold, '-s', 'Scaffold lib/[gem_name]/version.rb README test/'
20
+ option :github, '-h', 'Init a git repo, create on github and push'
21
+
22
+ @arguments = ''
23
+ @usage = "#{program_name}"
24
+ end
25
+
26
+ def execute
27
+ write_gemspec if options[:gemspec]
28
+ write_scaffold if options[:scaffold]
29
+ create_repo if options[:github]
30
+ end
31
+
32
+ def write_scaffold
33
+ `mkdir lib test`
34
+ `touch README`
35
+ Version.new(options).write
36
+ end
37
+
38
+ def write_gemspec
39
+ Gemspec.new(options).write
40
+ end
41
+
42
+ def create_repo
43
+ options = { :login => github_user, :token => github_token, :name => gem_name }
44
+ options = options.map { |name, value| "-F '#{name}=#{value}'" }.join(' ')
45
+
46
+ say 'Initializing git repository'
47
+ `git init`
48
+
49
+ say 'Staging files'
50
+ `git add .`
51
+
52
+ say 'Creating initial commit'
53
+ `git commit -m 'initial commit'`
54
+
55
+ say "Adding remote origin git@github.com:#{github_user}/#{gem_name}.git"
56
+ `git remote add origin git@github.com:#{github_user}/#{gem_name}.git`
57
+
58
+ say 'Creating repository on Github'
59
+ silence { `curl #{options} http://github.com/api/v2/yaml/repos/create` }
60
+
61
+ say 'Pushing to Github'
62
+ `git push origin master`
63
+ end
64
+ end
@@ -1,4 +1,6 @@
1
1
  require 'rubygems/command_manager'
2
+ require 'gem_release'
2
3
 
4
+ Gem::CommandManager.instance.register_command :init
3
5
  Gem::CommandManager.instance.register_command :release
4
6
  Gem::CommandManager.instance.register_command :tag
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sven Fuchs
@@ -27,13 +27,20 @@ extensions: []
27
27
  extra_rdoc_files: []
28
28
 
29
29
  files:
30
+ - lib/core_ext/kernel/silence.rb
31
+ - lib/core_ext/string/camelize.rb
32
+ - lib/gem_release.rb
33
+ - lib/gem_release/command_options.rb
34
+ - lib/gem_release/gemspec.rb
30
35
  - lib/gem_release/helpers.rb
36
+ - lib/gem_release/template.rb
37
+ - lib/gem_release/templates/gemspec.erb
38
+ - lib/gem_release/templates/version.erb
31
39
  - lib/gem_release/version.rb
40
+ - lib/rubygems/commands/init_command.rb
32
41
  - lib/rubygems/commands/release_command.rb
33
42
  - lib/rubygems/commands/tag_command.rb
34
43
  - lib/rubygems_plugin.rb
35
- - Gemfile
36
- - README.textile
37
44
  has_rdoc: true
38
45
  homepage: http://github.com/svenfuchs/gem-release
39
46
  licenses: []
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'http://gemcutter.org'
2
-
3
- group :test do
4
- gem 'test_declarative'
5
- gem 'mocha'
6
- end
@@ -1,24 +0,0 @@
1
- h1. gem release
2
-
3
- This gem plugin adds a `release` command to the rubygems `gem` command which
4
-
5
- * builds a gem from your gemspec and
6
- * pushes it to rubygems.org
7
- * deletes the gem file
8
-
9
- h2. Installation
10
-
11
- Obviously ...
12
-
13
- <pre>
14
- $ gem install gem-release
15
- </pre>
16
-
17
- h2. Usage
18
-
19
- <pre>
20
- $ gem release path/to/your.gemspec
21
- $ gem release
22
- </pre>
23
-
24
- If you don't specify a gemspec filename the first \*.gemspec file found in your current working directory will be used.