lib/airake/project.rb in airake-0.2.8 vs lib/airake/project.rb in airake-0.2.9

- old
+ new

@@ -3,32 +3,31 @@ # Project settings for AIR app class Project 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 - attr_reader :options - attr_reader :assets + attr_reader :debug, :assets, :certificate + attr_reader :build_env # Options to override defaults Options = [ :certificate, :assets, :amxmlc_path, :adt_path, :adt_path, :bin_dir, :src_dir, :lib_dir, :test_dir, :appxml_path, :air_path, :swf_path, :debug, :amxmlc_extra_opts, :adl_extra_opts, :adt_extra_opts ] # Construct project # # base_dir:: Base (project) directory # mxml_path: Path to the project.mxml (relative) # options:: Override default paths, commands, extra opts, etc; See Options class var - def initialize(base_dir, mxml_path, options = {}) + def initialize(base_dir, mxml_path, options = {}, build_env = :normal) raise ArgumentError, "Invalid MXML path: #{mxml_path}" if mxml_path.blank? mxml_dir = File.expand_path(File.dirname(mxml_path)) project_name = File.basename(mxml_path, ".mxml") @base_dir = base_dir @mxml_path = File.join(mxml_dir, "#{project_name}.mxml") - @options = options + @build_env = build_env @bin_dir = options[:bin_dir] || File.join(base_dir, "bin") @src_dir = options[:src_dir] || File.join(base_dir, "src") @lib_dir = options[:lib_dir] || File.join(base_dir, "lib") @test_dir = options[:test_dir] || File.join(base_dir, "test") @@ -38,53 +37,74 @@ # Dest package files @air_path = options[:air_path] || File.join(@bin_dir, "#{project_name}.air") @swf_path = options[:swf_path] || File.join(@bin_dir, "#{project_name}.swf") # Debug options - @debug = options[:debug].is_a?(TrueClass) || options[:debug] == "true" + @debug = options[:debug].is_a?(TrueClass) || options[:debug] == "true" + + @assets = options[:assets] + @certificate = options[:certificate] end # Flex compiler command for this project def amxmlc - options = @options.merge({ :swf_path => swf_path, :mxml_path => mxml_path, :lib_dir => lib_dir, - :src_dir => src_dir, :test_dir => test_dir, :debug_option => debug_option }) + src_dirs = case build_env + when :normal then [ @src_dir ] + when :test then [ @src_dir, @test_dir ] + else raise "Invalid build_env setting: #{build_env}" + end + + options = { :swf_path => @swf_path, :mxml_path => @mxml_path, :lib_dir => @lib_dir, + :src_dirs => src_dirs, :debug => @debug } + Airake::Commands::Amxmlc.new(options) end # ADL command for this project def adl - options = @options.merge({ :appxml_path => appxml_path, :root_dir => base_dir }) + options = { :appxml_path => @appxml_path, :root_dir => @base_dir } Airake::Commands::Adl.new(options) end # ADT command for this project def adt - options = @options.merge({ :air_path => air_path, :appxml_path => appxml_path, :swf_path => swf_path, :base_dir => base_dir }) + options = { :air_path => @air_path, :appxml_path => @appxml_path, :swf_path => @swf_path, + :base_dir => @base_dir, :assets => @assets, :certificate => @certificate } Airake::Commands::Adt.new(options) end + + # List of files to remove on clean + def to_clean + case build_env + when :normal then [ swf_path, air_path ] + when :test then [ swf_path ] + end + end # Create project using parameters from rake ENV + # + # This shouldn't really be here, but a Rakefile is a bad place to be :O # # You can set any of the options via ENV; just upcase it. <tt>:foo_bar => ENV["FOO_BAR"]</tt> # # Booleans must be "true" for true - def self.new_from_rake(env, is_test = false) + def self.new_from_rake(env, build_env = :normal) base_dir = env["BASE_DIR"] - mxml = is_test ? env["MXML_TEST"] : env["MXML"] + mxml = case build_env + when :test then env["MXML_TEST"] + when :normal then env["MXML"] + else raise "Invalid build env: #{build_env}" + end # For any option check to see if its in the ENV options = {} Options.each do |option_key| - env_key = option_key.to_s.upcase + env_key = option_key.to_s.upcase options[option_key] = env[env_key] if env.has_key?(env_key) end #puts "Using options: #{options.inspect}" unless options.empty? - self.new(base_dir, mxml, options) + self.new(base_dir, mxml, options, build_env) end - - def debug_option - "-debug=#{@debug}" if @debug - end end end \ No newline at end of file