edavis10 (owner)

Revisions

gist: 211054 Download_button fork
public
Description:
Script to convert a Rails/Redmine plugin to a RubyGem
Public Clone URL: git://gist.github.com/211054.git
Embed All Files: show embed
plugin_to_gem.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env ruby
# Usage:
# ruby plugin_to_gem.rb my_plugin_directory
require 'fileutils'
 
@plugin_dir = ARGV[0]
@plugin_name = ARGV[0]
 
def rakefile_content
  description = 'TODO'
  redmine_init_content = File.read('init.rb')
  if redmine_init_content.match(/description (.*$)/)
    description = $1.gsub("'",'').gsub('"','')
  end
 
  content =<<-EORAKE
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "#{@plugin_name}"
s.summary = "#{description}"
s.email = "edavis@littlestreamsoftware.com"
s.homepage = "https://projects.littlestreamsoftware.com/projects/TODO"
s.description = "#{description}"
s.authors = ["Eric Davis"]
s.rubyforge_project = "#{@plugin_name}" # TODO
s.files = FileList[
"[A-Z]*",
"init.rb",
"rails/init.rb",
"{bin,generators,lib,test,app,assets,config,lang}/**/*",
'lib/jeweler/templates/.gitignore'
]
end
Jeweler::GemcutterTasks.new
Jeweler::RubyforgeTasks.new do |rubyforge|
rubyforge.doc_task = "rdoc"
end
rescue LoadError
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
 
EORAKE
end
 
FileUtils.cd(@plugin_dir, :verbose => true) do |dir|
  system('rake clean')
  system('git status')
  system('git checkout master')
  system('git merge origin/master')
  system('git checkout -b gem')
 
  # Rakefile
  File.open('Rakefile','a') do |file|
    file.puts(rakefile_content)
  end
  system('git commit -am "Updated rakefile for jeweler"')
 
  # VERSION
  File.open('VERSION','w') do |version_file|
    redmine_init_content = File.read('init.rb')
    if redmine_init_content.match(/version (.*$)/)
      version = $1.gsub("'",'').gsub('"','')
      version_file.puts version
    end
  end
  system('git add VERSION')
  system('git commit -am "Added Version file"')
 
  # Rails GemPlugin init.rb
  FileUtils.mkdir_p('rails')
  system('git mv init.rb rails/init.rb')
  File.open('init.rb','w') do |init_file|
    init_file.puts('require File.dirname(__FILE__) + "/rails/init"')
  end
  system('git add init.rb')
  system('git commit -am "Added init file for Rails GemPlugin"')
 
 
 
  # Gemspec
  system('rake gemspec')
  system("git add #{@plugin_name}.gemspec")
  system('git commit -am "Added generated gemspec"')
 
  # Install to test
  system('rake install')
 
  # Back to master to allow merging
  system('git checkout master')
end