Skip to content

Commit

Permalink
Adding support for multiple builds. Still need to get bundles to resp…
Browse files Browse the repository at this point in the history
…ect packer settings for packages, and need to get Helper to report the name of the current build.
  • Loading branch information
jcoglan committed Jul 12, 2008
1 parent 02d539d commit ebe0ee1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
8 changes: 5 additions & 3 deletions lib/jake/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Build

DEFAULT_LAYOUT = 'together'

attr_reader :helper
attr_reader :helper, :builds

def initialize(dir, config = nil)
@dir = File.expand_path(dir)
Expand All @@ -18,6 +18,8 @@ def initialize(dir, config = nil)
helpers = "#{dir}/#{HELPER_FILE}"
load helpers if File.file?(helpers)

@builds = @config[:builds] || {:src => false, :min => @config[:packer]}

@packages = @config[:packages].inject({}) do |pkgs, (name, conf)|
pkgs[name] = Package.new(self, name, conf)
pkgs
Expand Down Expand Up @@ -52,8 +54,8 @@ def header
""
end

def packer_settings
@config[:packer] || {}
def packer_settings(build_name)
@builds[build_name] || false
end

def layout
Expand Down
33 changes: 14 additions & 19 deletions lib/jake/buildable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ def directory
"#{ @build.source_directory }/#{ @config[:directory] }"
end

def build_path
def build_path(build_name)
@build.layout == 'together' ?
"#{ @build.build_directory }/#{ @name }-src.js" :
"#{ @build.build_directory }/src/#{ @name }.js"
end

def minified_build_path
@build.layout == 'together' ?
"#{ @build.build_directory }/#{ @name }-min.js" :
"#{ @build.build_directory }/min/#{ @name }.js"
"#{ @build.build_directory }/#{ @name }-#{ build_name }.js" :
"#{ @build.build_directory }/#{ build_name }/#{ @name }.js"
end

def header
Expand All @@ -37,23 +31,24 @@ def header
@build.header
end

def packer_settings
{}.merge(@build.packer_settings).merge(@config[:packer] || {})
def packer_settings(build_name)
global = @build.packer_settings(build_name)
local = @config[:packer]
return false if global == false or local == false
{}.merge(global || {}).merge(local || {})
end

def write!
puts "\nBuilding package #{@name}"
puts " -- directory: #{ directory }"
puts " -- files: #{ @config[:files].join(', ') }"
puts " -- settings: #{ packer_settings.inspect }"

path, min_path = build_path, minified_build_path
[path, min_path].each { |p| FileUtils.mkdir_p(File.dirname(p)) }
File.open(path, 'wb') { |f| f.write( (header + "\n" + source).strip ) }
File.open(min_path, 'wb') { |f| f.write( (header + "\n" + minified).strip ) }

[path, min_path].each do |p|
puts " -- created #{p}, #{ (File.size(p)/1024.0).ceil } kb"
@build.builds.each do |name, settings|
settings = packer_settings(name)
code = settings ? Packr.pack(source, settings) : source
path = build_path(name)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'wb') { |f| f.write( (header + "\n" + code).strip ) }
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/jake/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ def source
@source ||= @config[:files].map { |name| @build.package(name).source }.join("\n")
end

def minified
@minified ||= @config[:files].map { |name| @build.package(name).minified }.join("\n")
end

end
end

4 changes: 0 additions & 4 deletions lib/jake/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ def source
@source = template.result(@build.helper.get_binding)
end

def minified
@minified ||= Packr.pack(source, packer_settings)
end

def header
reqs = @config[:requires] || []
[super, *reqs.map { |r| "// @require #{r}" }].join("\n")
Expand Down

0 comments on commit ebe0ee1

Please sign in to comment.