Permalink
Browse files

Fix dumb build bugs

Config memoization, template build order, don't be confusing about
variable/method scope
  • Loading branch information...
ches committed Jan 9, 2011
1 parent 556aed3 commit a514b23d4fd4587052b786294e6a084e880b8ad2
Showing with 12 additions and 9 deletions.
  1. +12 −9 Rakefile
View
@@ -28,7 +28,8 @@ PMS_PLUGIN_DATA_DIR = PMS_SUPPORT_DIR + 'Plug-in Support'
PMS_BIN = PLEX_SUPPORT_DIR + 'Plex Media Server.app/Contents/MacOS/Plex Media Server'
def config(env=:release)
- @config ||= YAML.load_file(PLUGIN_BUNDLE_DIR + 'Contents/config.yml')[env.to_s]
+ @config ||= YAML.load_file(PLUGIN_BUNDLE_DIR + 'Contents/config.yml')
+ @config[env.to_s]
end
PLUGIN_PACKAGE_NAME = "#{config['PLUGIN_NAME']}-#{config['PLUGIN_VERSION']}".gsub " ", "_"
@@ -70,7 +71,7 @@ def bundle_name(config)
end
# Really lo-fi 'erb' :-)
-def erb(config, file)
+def erb(cfg, file)
warning = <<-EOW
DO NOT EDIT THIS FILE
It was generated from a template. Your changes will be overwritten
@@ -88,7 +89,7 @@ def erb(config, file)
File.open(file).each_line do |line|
temp << line.gsub(/<%=(.*?)%>/) do
prop = $1.strip
- if value = config[prop]
+ if value = cfg[prop]
value
else
raise "couldn't find property `#{prop}' (in #{file})"
@@ -107,23 +108,23 @@ end
task :default => :build
namespace :build do
- def build_templates(config, build_dir)
+ def build_templates(cfg, build_dir)
FileList[PLUGIN_TEMPLATE_DIR + '**/*'].each do |file|
if File.file?(file)
dest_dir = File.join build_dir, File.dirname(file[PLUGIN_TEMPLATE_DIR.to_s.length + 1, file.length])
dest_file = File.join dest_dir, File.basename(file)
mkdir_p dest_dir
cp file, dest_dir
- erb(config, dest_file) unless File.binary?(dest_file)
+ erb(cfg, dest_file) unless File.binary?(dest_file)
end
end
end
- def build(env, config)
+ def build(env, cfg)
File.rm_if_exists PLUGIN_BUILD_DIR
mkdir_p PLUGIN_BUILD_DIR
- bundle_dir = PLUGIN_BUILD_DIR + bundle_name(config)
+ bundle_dir = PLUGIN_BUILD_DIR + bundle_name(cfg)
cp_r PLUGIN_BUNDLE_DIR, bundle_dir
add_env_file env, bundle_dir
@@ -135,15 +136,15 @@ namespace :build do
desc 'Build a dev distribution.'
task :development do
- build_templates config(:development), PLUGIN_BUNDLE_DIR
build :development, config(:development)
+ build_templates config(:development), PLUGIN_BUNDLE_DIR
end
task :dev => :development
desc 'Build a release distribution.'
task :release do
- build_templates config, File.join(PLUGIN_BUILD_DIR, bundle_name(config))
build :release, config
+ build_templates config, File.join(PLUGIN_BUILD_DIR, bundle_name(config))
end
end
desc 'Alias for build:development'
@@ -206,13 +207,15 @@ desc 'Alias for package:release'
task :package => 'package:release'
namespace :pms do
+ desc 'Restart Plex Media Server'
task :restart => [ :stop, :start ]
desc 'Start Plex Media Server'
task :start do
exec '"' + PMS_BIN + '"'
end
+ desc 'Stop Plex Media Server'
task :stop do
system 'killall', 'Plex Media Server'
end

0 comments on commit a514b23

Please sign in to comment.