Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add better logging in entry_sorter. Make sc-server reload projects ev…

…ery 5 sec
  • Loading branch information...
commit 0ba703ee3ab2661f31e7aaa0d0bd66d343e009c3 1 parent e27e11b
Charles Jolley authored
4 Buildfile
View
@@ -70,7 +70,9 @@ mode :debug do
:build_prefix => 'tmp/debug/build',
:staging_prefix => 'tmp/debug/staging',
- :serve_exceptions => true
+ # debug settings for sc-server
+ :serve_exceptions => true,
+ :reload_project => true
end
24 lib/sproutcore/helpers/entry_sorter.rb
View
@@ -24,12 +24,13 @@ def sort(entries)
entries = entries.sort do |a,b|
(a.filename || '').to_s.downcase <=> (b.filename || '').to_s.downcase
end
+ all_entries = entries.dup # needed for sort...
# now process each entry to handle requires
seen = []
ret = []
while cur = next_entry(entries)
- add_entry_to_set(cur, ret, seen, entries)
+ add_entry_to_set(cur, ret, seen, entries, all_entries)
end
return ret
@@ -38,19 +39,27 @@ def sort(entries)
protected
# Converts a passed set of requires into entries
- def required_entries(required, entries)
+ def required_entries(required, entries, requiring_entry, all_entries)
return [] if required.nil?
required.map do |filename|
filename = filename.to_s.downcase.ext('')
source_filename = "source/#{filename}"
- entry = entries.find { |e| e.filename.to_s.downcase.ext('') == source_filename }
+ entry = all_entries.find do |e|
+ e.filename.to_s.downcase.ext('') == source_filename
+ end
# try localized version...
if entry.nil? && !(filename =~ /^lproj\//)
source_filename = "source/lproj/#{filename}"
- entry = entries.find { |e| e.filename.to_s.downcase.ext('') == source_filename }
+ entry = all_entries.find do |e|
+ e.filename.to_s.downcase.ext('') == source_filename
+ end
end
+ if entry.nil?
+ SC.logger.warn "Could not find entry '#{filename}' required in #{requiring_entry.target.target_name.to_s.sub(/^\//,'')}:#{requiring_entry.filename} - entries: \n #{entries.map { |e| e.filename } * " \n"}"
+ end
+
entry
end
end
@@ -72,13 +81,14 @@ def next_entry(entries)
end
# Adds the specified entry to the ordered array, adding required first
- def add_entry_to_set(entry, ret, seen, entries)
+ def add_entry_to_set(entry, ret, seen, entries, all_entries)
return if seen.include?(entry)
seen << entry
- required_entries(entry.required, entries).each do |required|
+ req = required_entries(entry.required, entries, entry, all_entries)
+ req.each do |required|
next if required.nil?
- add_entry_to_set(required, ret, seen, entries)
+ add_entry_to_set(required, ret, seen, entries, all_entries)
end
ret << entry
end
11 lib/sproutcore/models/manifest_entry.rb
View
@@ -157,6 +157,17 @@ def stage!
build_to self.staging_path
end
+ # Removes the build and staging files for this entry so the next
+ # build will rebuild.
+ #
+ # === Returns
+ # self
+ def clean!
+ FileUtils.rm(self.build_path) if File.exist?(self.build_path)
+ FileUtils.rm(self.staging_path) if File.exist?(self.staging_path)
+ return self
+ end
+
private
def build_to(dst_path)
26 lib/sproutcore/rack/builder.rb
View
@@ -66,8 +66,6 @@ class Builder
def initialize(project)
@project = project
@last_reload_time = Time.now
-
- puts "Builder: #{project.project_root} - #{project.targets.keys * ","}"
end
# Main entry point for this Rack application. Returns 404 if no
@@ -99,13 +97,16 @@ def _call(env)
return not_found("No matching entry in target")
end
+ # Clean the entry so it will rebuild if we are serving an index
+ entry.clean! if entry.filename =~ /index.html$/
+
# Now build entry and return a file object
build_path = entry.build!.build_path
unless File.file?(build_path) && File.readable?(build_path)
return not_found("File could not build (entry: #{entry.filename} - build_paht: #{build_path}")
end
- SC.logger << " ~ Serving #{target.target_name.to_s.sub(/^\//,'')}:#{entry.filename}\n"
+ SC.logger.info "Serving #{target.target_name.to_s.sub(/^\//,'')}:#{entry.filename}"
[200, {
"Last-Modified" => File.mtime(build_path).httpdate,
"Content-Type" => ::Rack::Mime.mime_type(File.extname(build_path), 'text/plain'),
@@ -145,13 +146,22 @@ def reload_project!
end
def target_for(url)
- project.targets.values.find do |target|
- target.prepare!
- # look for a url_root match...
- (url =~ /^#{Regexp.escape target.url_root}/) ||
- (url =~ /^#{Regexp.escape target.index_root}/)
+ # get targets
+ targets = project.targets.values.dup
+ targets.each { |t| t.prepare! }
+
+ # split the url into parts. pop parts until we find a matching
+ # target. This ensures that we end up with the deepest matching
+ # target.
+ url_parts = url.split '/'
+ ret = nil
+ while url_parts.size>0 && ret.nil?
+ url = url_parts.join '/'
+ ret = targets.find { |t| t.url_root == url || t.index_root == url }
+ url_parts.pop
end
+ return ret
end
# Helper method. This will normalize a URL into one that can map
Please sign in to comment.
Something went wrong with that request. Please try again.