Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding modified-time detection to avoid rebuilding unchanged packages.

  • Loading branch information...
commit 3a3e57e09a224a52807f32650a30e3a554efd335 1 parent 45a4c43
@jcoglan jcoglan authored
View
0  README.rdoc → README.txt
File renamed without changes
View
18 lib/jake/buildable.rb
@@ -26,6 +26,13 @@ def build_path(build_name)
"#{ @build.build_directory }/#{ build_name }/#{ @name }.js"
end
+ def build_needed?(name)
+ path = build_path(name)
+ return true unless File.file?(path)
+ build_time = File.mtime(path)
+ files.any? { |path| File.mtime(path) > build_time }
+ end
+
def header
@config[:header] ?
Jake.read("#{ directory }/#{ @config[:header] }") :
@@ -41,14 +48,21 @@ def packer_settings(build_name)
def write!
puts "\nBuilding package #{@name}"
- puts " -- directory: #{ directory }"
- puts " -- files: #{ @config[:files].join(', ') }"
@build.builds.each do |name, settings|
+ unless build_needed?(name)
+ puts " -- build '#{ name }' up-to-date"
+ next
+ end
+
@build.helper.build = name
path = build_path(name)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'wb') { |f| f.write( (header + "\n" + code(name)).strip ) }
+
+ size = (File.size(path)/1024.0).ceil
+ path = path.sub(@build.build_directory, '')
+ puts " -- build '#{ name }' created #{ path }, #{ size } kb"
end
end
View
4 lib/jake/bundle.rb
@@ -1,6 +1,10 @@
module Jake
class Bundle < Buildable
+ def files
+ @config[:files].map { |pkg| @build.package(pkg).files }.flatten
+ end
+
def source
@source ||= @config[:files].map { |pkg|
@build.package(pkg).source
View
11 lib/jake/package.rb
@@ -3,15 +3,22 @@
module Jake
class Package < Buildable
+ def files
+ @config[:files].map do |path|
+ path = "#{ directory }/#{ path }"
+ File.file?(path) ? path : "#{ path }.js"
+ end
+ end
+
def source
- @source ||= @config[:files].map { |path| Jake.read("#{ directory }/#{ path }") }.join("\n")
+ @source ||= files.map { |path| Jake.read(path) }.join("\n")
end
def code(name)
return @code[name] if @code[name]
settings = packer_settings(name)
output = ERB.new(source).result(@build.helper.get_binding)
- @code[name] ||= settings ? Packr.pack(output, settings) : output
+ @code[name] = settings ? Packr.pack(output, settings) : output
end
def header
Please sign in to comment.
Something went wrong with that request. Please try again.