parka 0.2.0 → 0.3.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/lib/parka/cli.rb ADDED
@@ -0,0 +1,103 @@
1
+ require "rubygems/commands/push_command"
2
+ require "rubygems/dependency_installer"
3
+ require "parka"
4
+ require "rest-client"
5
+ require "thor"
6
+
7
+ class Parka::CLI < Thor
8
+
9
+ desc "build [GEMSPEC]", "Build the gem"
10
+
11
+ def build(gemspec_filename=nil)
12
+ gemspec = Gem::Specification.load(gemspec_filename || default_gemspec)
13
+ filename = "pkg/#{gemspec.file_name}"
14
+
15
+ say "Building #{gemspec.file_name}"
16
+
17
+ FileUtils.mkdir_p File.dirname(filename)
18
+ Gem::Builder.new(gemspec).build
19
+ FileUtils.mv gemspec.file_name, filename
20
+
21
+ filename
22
+ end
23
+
24
+ desc "install [GEMSPEC]", "Build and install the gem"
25
+
26
+ def install(gemspec_filename=nil)
27
+ gemfile = build(gemspec_filename)
28
+ installer = Gem::DependencyInstaller.new
29
+ installer.install gemfile
30
+ say "Successfully installed #{File.basename(gemfile)}"
31
+ end
32
+
33
+ desc "push [GEMSPEC]", "Build the gem and push it to GitHub and RubyGems.org"
34
+
35
+ def push(gemspec_filename=nil)
36
+ gemspec = Gem::Specification.load(gemspec_filename || default_gemspec)
37
+ gemfile = build(gemspec_filename)
38
+
39
+ # create github remote
40
+ remotes = %x{ git remote }.strip.split("\n")
41
+ unless remotes.include?("github")
42
+ %x{ git remote add github git@github.com:#{github_username}/#{gemspec.name}.git }
43
+ end
44
+
45
+ # create github repo
46
+ repos = github_repositories
47
+ names = repos.map { |repo| repo["name"] }
48
+ unless names.include?(gemspec.name)
49
+ github["repos/create"].post(
50
+ :name => gemspec.name,
51
+ :description => gemspec.summary,
52
+ :homepage => gemspec.homepage,
53
+ :public => "1"
54
+ )
55
+ end
56
+
57
+ # create release tag
58
+ %x{ git tag v#{gemspec.version} }
59
+
60
+ # push to github
61
+ %x{ git push github master --tags }
62
+
63
+ # push to rubygems
64
+ pusher = Gem::Commands::PushCommand.new
65
+ pusher.send_gem gemfile
66
+ end
67
+
68
+ private ######################################################################
69
+
70
+ def chroot(dir)
71
+ FileUtils.mkdir_p dir
72
+
73
+ Dir.chdir(dir) { yield }
74
+ end
75
+
76
+ def default_gemspec
77
+ "#{File.basename(Dir.pwd)}.gemspec"
78
+ end
79
+
80
+ def error(message)
81
+ puts "ERROR: #{message}"
82
+ exit 1
83
+ end
84
+
85
+ def github
86
+ username = github_username + "/token"
87
+ password = github_token
88
+ RestClient::Resource.new("http://github.com/api/v2/json", username, password)
89
+ end
90
+
91
+ def github_username
92
+ %x{ git config github.user }.strip
93
+ end
94
+
95
+ def github_token
96
+ %x{ git config github.token }.strip
97
+ end
98
+
99
+ def github_repositories
100
+ Crack::JSON.parse(github["repos/show/#{github_username}"].get)["repositories"]
101
+ end
102
+
103
+ end
@@ -0,0 +1,60 @@
1
+ require "bundler"
2
+ require "parka"
3
+ require "rubygems"
4
+
5
+ class Parka::Specification < Gem::Specification
6
+
7
+ def self.new(&block)
8
+ gemspec_filename = caller.first.split(':').first
9
+
10
+ # add the lib/ dir of the gem to the load path
11
+ $:.unshift File.join(File.dirname(gemspec_filename), 'lib')
12
+
13
+ # autorequire the same name as the gem spec
14
+ require File.basename(gemspec_filename, File.extname(gemspec_filename))
15
+
16
+ spec = Gem::Specification.new(&block)
17
+
18
+ # set up some sensible defaults
19
+ spec.author ||= default_author
20
+ spec.email ||= default_email
21
+ spec.description ||= spec.summary
22
+
23
+ # hack to avoid rubyforge_project warning
24
+ spec.rubyforge_project = "nowarning"
25
+
26
+ # default file list if none specified
27
+ spec.files = (spec.files + default_files).uniq
28
+
29
+ # get dependencies from bundler
30
+ add_bundler_dependencies(spec)
31
+
32
+ spec
33
+ end
34
+
35
+ private ######################################################################
36
+
37
+ def self.default_author
38
+ %x{ git config user.name }
39
+ end
40
+
41
+ def self.default_email
42
+ %x{ git config user.email }
43
+ end
44
+
45
+ def self.default_files
46
+ %x{ git ls-files }.split("\n").select { |f| f.match(/^(bin|data|ext|lib|spec|test)/) }
47
+ end
48
+
49
+ def self.add_bundler_dependencies(spec)
50
+ groups = Bundler.definition.groups - [:development, :test]
51
+ deps = Bundler.definition.dependencies
52
+
53
+ runtime = deps.select { |d| (d.groups & groups).any? }
54
+ development = deps - runtime
55
+
56
+ development.each { |d| spec.add_development_dependency(d.name, d.requirement) }
57
+ runtime.each { |d| spec.add_dependency(d.name, d.requirement) }
58
+ end
59
+
60
+ end
data/lib/parka.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Parka
2
+ VERSION = "0.3.0"
3
+ end
4
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parka
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - |
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-08-19 00:00:00 -04:00
20
+ date: 2010-08-23 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -120,6 +120,9 @@ extra_rdoc_files: []
120
120
 
121
121
  files:
122
122
  - bin/parka
123
+ - lib/parka.rb
124
+ - lib/parka/cli.rb
125
+ - lib/parka/specification.rb
123
126
  has_rdoc: true
124
127
  homepage: http://github.com/ddollar/parka
125
128
  licenses: []