Skip to content

Commit

Permalink
initial copy from slugc
Browse files Browse the repository at this point in the history
  • Loading branch information
ddollar committed May 24, 2011
0 parents commit 11771c5
Show file tree
Hide file tree
Showing 1,232 changed files with 64,182 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/compile
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby

$:.unshift File.expand_path("../../lib", __FILE__)
require "language_pack"

if pack = LanguagePack.detect(ARGV[0], ARGV[1])
pack.compile
end
12 changes: 12 additions & 0 deletions bin/detect
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby

$:.unshift File.expand_path("../../lib", __FILE__)
require "language_pack"

if pack = LanguagePack.detect(ARGV.first)
puts pack.name
exit 0
else
puts "no"
exit 1
end
9 changes: 9 additions & 0 deletions bin/release
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby

$:.unshift File.expand_path("../../lib", __FILE__)
require "language_pack"

if pack = LanguagePack.detect(ARGV[0], ARGV[1])
puts pack.release
end

21 changes: 21 additions & 0 deletions lib/language_pack.rb
@@ -0,0 +1,21 @@
require "pathname"

module LanguagePack

def self.detect(*args)
Dir.chdir(args.first)

pack = [ Rails3, Rails2, Rack, Ruby ].detect do |klass|
klass.use?
end

pack ? pack.new(*args) : nil
end

end

require "language_pack/ruby"
require "language_pack/rack"
require "language_pack/rails2"
require "language_pack/rails3"

107 changes: 107 additions & 0 deletions lib/language_pack/base.rb
@@ -0,0 +1,107 @@
require "language_pack"
require "pathname"
require "yaml"

class LanguagePack::Base

attr_reader :build_path, :cache_path

def initialize(build_path, cache_path=nil)
@build_path = build_path
@cache_path = cache_path

Dir.chdir build_path
end

def self.===(build_path)
raise "must subclass"
end

def name
raise "must subclass"
end

def default_addons
raise "must subclass"
end

def default_config_vars
raise "must subclass"
end

def default_process_types
raise "must subclass"
end

def compile
end

def release
{
"addons" => default_addons,
"config_vars" => default_config_vars,
"default_process_types" => default_process_types
}.to_yaml
end

private ##################################

def error(message)
Kernel.puts " !"
message.split("\n").each do |line|
Kernel.puts " ! #{line.strip}"
end
Kernel.puts " !"
exit 1
end

def run(command)
%x{ #{command} 2>&1 }
end

def pipe(command)
IO.popen(command) do |io|
until io.eof?
puts io.gets
end
end
end

def topic(message)
Kernel.puts "-----> #{message}"
$stdout.flush
end

def puts(message)
message.split("\n").each do |line|
super " #{line.strip}"
end
$stdout.flush
end

def cache_base
Pathname.new(cache_path)
end

def cache_clear(path)
target = (cache_base + path)
target.exist? && target.rmtree
end

def cache_store(path, clear_first=true)
cache_clear(path) if clear_first
cache_copy path, (cache_base + path)
end

def cache_load(path)
cache_copy (cache_base + path), path
end

def cache_copy(from, to)
return false unless File.exist?(from)
FileUtils.mkdir_p File.dirname(to)
system("cp -ax #{from}/. #{to}")
end

end

31 changes: 31 additions & 0 deletions lib/language_pack/rack.rb
@@ -0,0 +1,31 @@
require "language_pack"
require "language_pack/ruby"

class LanguagePack::Rack < LanguagePack::Ruby

def self.use?
super && File.exist?("config.ru")
end

def name
"Rack"
end

def default_config_vars
super.merge({
"RACK_ENV" => "production"
})
end

def default_process_types
web_process = gem_is_bundled?("thin") ?
"bundle exec thin start -R config.ru -p $PORT" :
"bundle exec rackup config.ru -p $PORT"

super.merge({
"web" => web_process
})
end

end

66 changes: 66 additions & 0 deletions lib/language_pack/rails2.rb
@@ -0,0 +1,66 @@
require "fileutils"
require "language_pack"
require "language_pack/rack"

class LanguagePack::Rails2 < LanguagePack::Ruby

def self.use?
super && File.exist?("config/environment.rb")
end

def name
"Rails"
end

def default_config_vars
super.merge({
"RAILS_ENV" => "production",
"RACK_ENV" => "production"
})
end

def default_process_types
web_process = gem_is_bundled?("thin") ?
"bundle exec thin start -e $RAILS_ENV -p $PORT" :
"bundle exec ruby script/server -p $PORT"

super.merge({
"web" => web_process,
"worker" => "bundle exec rake jobs:work",
"console" => "bundle exec script/console"
})
end

def default_addons
%w( shared-database:5mb )
end

def compile
super
install_plugins
end

private

def plugins
%w( rails_log_stdout )
end

def plugin_root
File.expand_path("../../../vendor/plugins", __FILE__)
end

def install_plugins
topic "Rails plugin injection"
plugins.each { |plugin| install_plugin(plugin) }
end

def install_plugin(name)
return if File.exist?("vendor/plugins/#{name}")
puts "Injecting #{name}"
FileUtils.mkdir_p "vendor/plugins"
FileUtils.cp_r File.join(plugin_root, name), "vendor/plugins"
end

end

38 changes: 38 additions & 0 deletions lib/language_pack/rails3.rb
@@ -0,0 +1,38 @@
require "language_pack"
require "language_pack/rails2"

class LanguagePack::Rails3 < LanguagePack::Rails2

def self.use?
super &&
File.exists?("config/application.rb") &&
File.read("config/application.rb") =~ /Rails::Application/
end

def name
"Rails"
end

def default_process_types
web_process = gem_is_bundled?("thin") ?
"bundle exec thin start -R config.ru -e $RAILS_ENV -p $PORT" :
"bundle exec rails server -p $PORT"

super.merge({
"web" => web_process,
"console" => "bundle exec rails console"
})
end

def compile
super
end

private

def plugins
super.concat(%w( rails3_serve_static_assets )).uniq
end

end

0 comments on commit 11771c5

Please sign in to comment.