Skip to content

@edavis10 /plugin_to_gem.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Script to convert a Rails/Redmine plugin to a RubyGem
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.