Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix dumb build bugs

Config memoization, template build order, don't be confusing about
variable/method scope
  • Loading branch information...
commit a514b23d4fd4587052b786294e6a084e880b8ad2 1 parent 556aed3
Ches Martin authored

Showing 1 changed file with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. +12 9 Rakefile
21 Rakefile
@@ -28,7 +28,8 @@ PMS_PLUGIN_DATA_DIR = PMS_SUPPORT_DIR + 'Plug-in Support'
28 28 PMS_BIN = PLEX_SUPPORT_DIR + 'Plex Media Server.app/Contents/MacOS/Plex Media Server'
29 29
30 30 def config(env=:release)
31   - @config ||= YAML.load_file(PLUGIN_BUNDLE_DIR + 'Contents/config.yml')[env.to_s]
  31 + @config ||= YAML.load_file(PLUGIN_BUNDLE_DIR + 'Contents/config.yml')
  32 + @config[env.to_s]
32 33 end
33 34
34 35 PLUGIN_PACKAGE_NAME = "#{config['PLUGIN_NAME']}-#{config['PLUGIN_VERSION']}".gsub " ", "_"
@@ -70,7 +71,7 @@ def bundle_name(config)
70 71 end
71 72
72 73 # Really lo-fi 'erb' :-)
73   -def erb(config, file)
  74 +def erb(cfg, file)
74 75 warning = <<-EOW
75 76 DO NOT EDIT THIS FILE
76 77 It was generated from a template. Your changes will be overwritten
@@ -88,7 +89,7 @@ def erb(config, file)
88 89 File.open(file).each_line do |line|
89 90 temp << line.gsub(/<%=(.*?)%>/) do
90 91 prop = $1.strip
91   - if value = config[prop]
  92 + if value = cfg[prop]
92 93 value
93 94 else
94 95 raise "couldn't find property `#{prop}' (in #{file})"
@@ -107,7 +108,7 @@ end
107 108 task :default => :build
108 109
109 110 namespace :build do
110   - def build_templates(config, build_dir)
  111 + def build_templates(cfg, build_dir)
111 112 FileList[PLUGIN_TEMPLATE_DIR + '**/*'].each do |file|
112 113 if File.file?(file)
113 114 dest_dir = File.join build_dir, File.dirname(file[PLUGIN_TEMPLATE_DIR.to_s.length + 1, file.length])
@@ -115,15 +116,15 @@ namespace :build do
115 116
116 117 mkdir_p dest_dir
117 118 cp file, dest_dir
118   - erb(config, dest_file) unless File.binary?(dest_file)
  119 + erb(cfg, dest_file) unless File.binary?(dest_file)
119 120 end
120 121 end
121 122 end
122 123
123   - def build(env, config)
  124 + def build(env, cfg)
124 125 File.rm_if_exists PLUGIN_BUILD_DIR
125 126 mkdir_p PLUGIN_BUILD_DIR
126   - bundle_dir = PLUGIN_BUILD_DIR + bundle_name(config)
  127 + bundle_dir = PLUGIN_BUILD_DIR + bundle_name(cfg)
127 128 cp_r PLUGIN_BUNDLE_DIR, bundle_dir
128 129 add_env_file env, bundle_dir
129 130
@@ -135,15 +136,15 @@ namespace :build do
135 136
136 137 desc 'Build a dev distribution.'
137 138 task :development do
138   - build_templates config(:development), PLUGIN_BUNDLE_DIR
139 139 build :development, config(:development)
  140 + build_templates config(:development), PLUGIN_BUNDLE_DIR
140 141 end
141 142 task :dev => :development
142 143
143 144 desc 'Build a release distribution.'
144 145 task :release do
145   - build_templates config, File.join(PLUGIN_BUILD_DIR, bundle_name(config))
146 146 build :release, config
  147 + build_templates config, File.join(PLUGIN_BUILD_DIR, bundle_name(config))
147 148 end
148 149 end
149 150 desc 'Alias for build:development'
@@ -206,6 +207,7 @@ desc 'Alias for package:release'
206 207 task :package => 'package:release'
207 208
208 209 namespace :pms do
  210 + desc 'Restart Plex Media Server'
209 211 task :restart => [ :stop, :start ]
210 212
211 213 desc 'Start Plex Media Server'
@@ -213,6 +215,7 @@ namespace :pms do
213 215 exec '"' + PMS_BIN + '"'
214 216 end
215 217
  218 + desc 'Stop Plex Media Server'
216 219 task :stop do
217 220 system 'killall', 'Plex Media Server'
218 221 end

0 comments on commit a514b23

Please sign in to comment.
Something went wrong with that request. Please try again.