lib/airake/project.rb in airake-0.1.4 vs lib/airake/project.rb in airake-0.1.5

- old
+ new

@@ -1,14 +1,15 @@ module Airake + # Project settings for AIR app class Project attr_reader :project_name, :mxmlc_path, :adt_path attr_reader :base_dir, :bin_dir, :src_dir, :lib_dir, :test_dir attr_reader :mxml_path, :appxml_path, :air_path, :swf_path attr_reader :debug - def initialize(base_dir, mxml_path, env = [], options = {}) + def initialize(base_dir, mxml_path, options = {}) @mxmlc_path = "mxmlc" @adt_path = "adt" @base_dir = base_dir @bin_dir = File.join(base_dir, "bin") @@ -24,38 +25,60 @@ # Dest package files @air_path = options[:air_path] || "#{@bin_dir}/#{project_name}.air" @swf_path = options[:swf_path] || "#{@bin_dir}/#{project_name}.swf" - @debug = env["DEBUG"] || options[:debug] || false + @debug = options[:debug] || false end - def lib_source_paths - Dir["#{@lib_dir}/*"].collect { |f| f if File.directory?(f) }.compact + [ @test_dir, @src_dir ] + def run_adt + run(adt_command) end - def source_path_option - @source_paths ||= lib_source_paths - @source_paths.empty? ? "" : "-source-path #{@source_paths.join(" ")}" + def run_mxmlc + run(mxmlc_command) end - def debug_option - "-debug=#{@debug}" if @debug + def run_adl + run(adl_command) end - + def mxmlc_command "#{@mxmlc_path} +configname=air #{source_path_option} -library-path+=#{@lib_dir} -output #{@swf_path} #{debug_option} -disable-incremental-optimizations=true -- #{@mxml_path}" end def adt_command "#{@adt_path} -package #{relative_path(@air_path)} #{relative_path(@appxml_path)} #{relative_path(@swf_path)}" end def adl_command "adl #{@appxml_path} #{@base_dir}" + end + + # Create project from ENV (for rake tasks) + def self.new_from_rake(env, is_test = false) + base_dir = env["BASE_DIR"] + mxml = is_test ? env["MXML_TEST"] : env["MXML"] + options = { :debug => env["DEBUG"] } + self.new(base_dir, mxml, options) end + + protected + + def lib_source_paths + Dir["#{@lib_dir}/*"].collect { |f| f if File.directory?(f) }.compact + [ @test_dir, @src_dir ] + end + def source_path_option + @source_paths ||= lib_source_paths + @source_paths.empty? ? "" : "-source-path #{@source_paths.join(" ")}" + end + + def debug_option + "-debug=#{@debug}" if @debug + end + def relative_path(path) Pathname.new(path).relative_path_from(Pathname.new(@base_dir)) end def fail(cmd, error_status) @@ -75,21 +98,9 @@ end def run(cmd) puts "Running: #{cmd}" system cmd or fail(cmd, $?) - end - - def run_adt - run(adt_command) - end - - def run_mxmlc - run(mxmlc_command) - end - - def run_adl - run(adl_command) end end end \ No newline at end of file