joe 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +3 -3
  2. data/bin/joe +55 -7
  3. data/lib/joe.rb +43 -39
  4. metadata +6 -7
@@ -17,13 +17,13 @@ Now go ahead and release your new gem to RubyGems.org:
17
17
 
18
18
  $ joe release
19
19
 
20
- Easy, right? Wait a few minutes until RubyGems.org updates its gems index and you will be able to run `sudo gem install foo`.
20
+ Easy, right? Wait until RubyGems.org updates its gems index and you will be able to run `gem install foo`.
21
21
 
22
22
 
23
23
  Maintaining a gemspec file
24
24
  --------------------------
25
25
 
26
- The easiest way we've found to maintain a gemspec file is by creating a `foo.gemspec.erb` template ([see example](http://github.com/soveran/ohm/blob/e3ff3fb20c1337cb2c4de244e09ce9fa04ef397d/ohm.gemspec.erb)). Then you can use Joe to produce the real gemspec file:
26
+ The easiest way we've found to maintain a gemspec file is by creating a `foo.gemspec.erb` template ([see example](https://github.com/soveran/ohm/blob/master/ohm.gemspec.erb)). Then you can use Joe to produce the real gemspec file:
27
27
 
28
28
  $ joe gemspec
29
29
 
@@ -31,7 +31,7 @@ The easiest way we've found to maintain a gemspec file is by creating a `foo.gem
31
31
  Installation
32
32
  ------------
33
33
 
34
- $ sudo gem install joe
34
+ $ gem install joe
35
35
 
36
36
  That's it. Try:
37
37
 
data/bin/joe CHANGED
@@ -1,13 +1,61 @@
1
1
  #! /usr/bin/env ruby -rubygems
2
2
 
3
3
  require File.join(File.dirname(__FILE__), "..", "lib", "joe")
4
+ require "clap"
4
5
 
5
- # A way to extend Joe is to write tasks in a Thorfile in the project's root directory.
6
- # Joe loads the Thorfile if there is one, and all the tasks that are declared in the
7
- # class Joe become available.
8
- if File.exists?("Thorfile")
9
- load("Thorfile")
6
+ help = <<-EOS
7
+ JOE(1)
8
+
9
+ NAME
10
+ joe -- Release your gems, no pain involved.
11
+
12
+ SYNOPSIS
13
+ joe COMMAND
14
+
15
+ DESCRIPTION
16
+ Joe is a small script that helps you build and release Ruby gems. It only
17
+ needs a gemspec file or an ERB gemspec template. With joe you can build the
18
+ gem, install it, archive it and release it to rubygems.org.
19
+
20
+ USAGE
21
+ Joe assumes you have a *.gemspec file in the current directory and it will
22
+ use it to build the gem. If you prefer to use an ERB template, make sure
23
+ you have the template named *.gemspec.erb.
24
+
25
+ COMMANDS
26
+ help Show this usage guide
27
+ gemspec Generate the gemspec file out of the ERB template
28
+ build Build the gem
29
+ install Build the gem, package it, and install it
30
+ archive Create a .tar.gz archive out of the current HEAD
31
+ release Push gem to rubygems.org
32
+
33
+ EXAMPLES
34
+ If your library is called foo, you need to have foo.gemspec or
35
+ foo.gemspec.erb available. If you do, the following command will build the
36
+ gem and release it to rubygems.org.
37
+
38
+ joe release
39
+
40
+ To install the gem locally without releasing it:
41
+
42
+ joe install
43
+
44
+ SEE ALSO
45
+ gem(1)
46
+ EOS
47
+
48
+ if ARGV.empty?
49
+ puts help
50
+ exit
10
51
  end
11
52
 
12
- # Start the joe tasks.
13
- Joe.start
53
+ joe = Joe.new
54
+
55
+ Clap.run ARGV,
56
+ "gemspec" => joe.method(:gemspec),
57
+ "build" => joe.method(:build),
58
+ "install" => joe.method(:install),
59
+ "archive" => joe.method(:archive),
60
+ "release" => joe.method(:release),
61
+ "help" => lambda { puts help }
data/lib/joe.rb CHANGED
@@ -1,67 +1,70 @@
1
- require "thor"
2
- require 'fileutils'
3
- require 'erb'
4
- require 'rubygems/gem_runner'
1
+ require "fileutils"
2
+ require "erb"
3
+ require "rubygems/gem_runner"
5
4
 
6
- class Joe < Thor
7
- VERSION = "0.0.3"
5
+ class Joe
6
+ VERSION = "0.1.0"
8
7
 
9
- include Thor::Actions
10
-
11
- desc "gemspec", "Generate the gemspec file out of the ERb template"
12
8
  def gemspec
13
- template "#{spec_file}.erb", spec_file, :force => true
14
- end
9
+ File.open(spec_file, "w") do |f|
10
+ f.write ERB.new(File.read("%s.erb" % spec_file), nil, "-").result
15
11
 
16
- desc "install", "Build the gem, package it and install it"
17
- def install
18
- build and
19
- gem "install", "pkg/#{gem_file}"
12
+ status :write, spec_file
13
+ end
14
+ rescue SyntaxError
15
+ fail "Parsing your gemspec failed. Please check its syntax."
20
16
  end
21
17
 
22
- desc "build", "Build the gem"
23
18
  def build
24
- gemspec if File.exists?("#{spec_file}.erb")
19
+ gemspec if File.exist?("%s.erb" % spec_file)
25
20
 
26
- gem "build", spec_file
21
+ gem("build", spec_file)
27
22
 
28
23
  if pkg(gem_file)
29
- say_status :created, gem_file
30
- true
24
+ status :created, "pkg/#{gem_file}"
31
25
  else
32
- say "Unable to build #{gem_file}"
33
- false
26
+ fail "Unable to build #{gem_file}"
34
27
  end
35
28
  end
36
29
 
37
- desc "archive", "Create a .tar.gz archive out of the current HEAD"
30
+ def install
31
+ build and gem("install", "pkg/#{gem_file}")
32
+ end
33
+
38
34
  def archive
39
- if system("git archive --prefix=#{spec.name}-#{spec.version}/ --format=tar HEAD | gzip > #{archive_file}") && pkg(archive_file)
40
- say_status :created, archive_file
41
- true
35
+ if git_archive && pkg(archive_file)
36
+ status :created, "pkg/#{archive_file}"
42
37
  end
43
38
  end
44
39
 
45
- desc "release", "Publish gem to RubyGems.org"
46
40
  def release
47
41
  build
48
- say "Releasing #{gem_file}..."
49
- gem "push", "pkg/#{gem_file}"
50
- end
51
-
52
- def self.source_root
53
- "."
42
+ status :releasing, gem_file
43
+ gem("push", "pkg/#{gem_file}")
54
44
  end
55
45
 
56
- protected
57
-
46
+ private
58
47
  def pkg(file)
59
48
  FileUtils.mkdir_p("pkg")
60
49
  File.exist?(file) && FileUtils.mv(file, "pkg")
61
50
  end
62
51
 
63
52
  def spec_file
64
- Dir["*.gemspec"].first || Dir["*.gemspec.erb"].first.sub(/\.erb$/, '')
53
+ Dir["*.gemspec"].first || Dir["*.gemspec.erb"].first.sub(/\.erb$/, "")
54
+ end
55
+
56
+ def fail(str)
57
+ puts "\e[1;31m#{str}\e[1;37m"
58
+ end
59
+
60
+ def status(type, message)
61
+ puts "\e[1;32m %10s \e[1;37m %s" % [type, message]
62
+
63
+ return type, message
64
+ end
65
+
66
+ def gem(*args)
67
+ Gem::GemRunner.new.run(args)
65
68
  end
66
69
 
67
70
  def spec
@@ -69,7 +72,7 @@ protected
69
72
  begin
70
73
  @spec = eval(File.read(spec_file))
71
74
  rescue Errno::ENOENT
72
- say_status :not_found, spec_file
75
+ log :not_found, spec_file
73
76
  exit 1
74
77
  end
75
78
  end
@@ -82,7 +85,8 @@ protected
82
85
  gem_file.sub(/\.gem$/, ".tar.gz")
83
86
  end
84
87
 
85
- def gem(*args)
86
- Gem::GemRunner.new.run(args)
88
+ def git_archive
89
+ system("git archive --prefix=#{spec.name}-#{spec.version}/ " +
90
+ "--format=tar HEAD | gzip > #{archive_file}")
87
91
  end
88
92
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 3
9
- version: 0.0.3
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Damian Janowski
@@ -15,21 +15,20 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-09 00:00:00 -03:00
18
+ date: 2010-11-05 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: thor
22
+ name: clap
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  segments:
30
30
  - 0
31
- - 11
32
- version: "0.11"
31
+ version: "0"
33
32
  type: :runtime
34
33
  version_requirements: *id001
35
34
  description: "Joe builds on top of Thor\xE2\x80\x99s awesomeness to take you from a gem specification to world domination in a single step."