module Airake # Project for AIR application # class Project attr_reader :base_dir, :src_dirs, :lib_dir attr_reader :mxml_path, :appxml_path, :air_path, :swf_path attr_reader :debug, :assets, :certificate # Create project. # # ==== Options: # +env+: Environment, such as development, test, production. Defaults to ENV["AIRAKE_ENV"]. # +base_dir+: Base (project) directory. Defaults to ENV["AIRAKE_ROOT"] # +options+: If nil, options are loaded from airake.yml in root. (All paths relative to base directory) # - +mxml_path+: Path to the ProjectName.mxml # - +appxml_path+: Path to application descriptor # - +src_dirs+: Paths to source # - +lib_dir+: Path to lib directory # - +air_path+: Path to AIR file # - +swf_path+: Path to SWF file # - +debug+: "true" or "false" # - +assets+: Path to assets # - +certificate+: Path to certificate # # ==== More options: # * mxmlc_path # * adt_path # * adl_path # * asdoc_path # * mxmlc_extra_opts # * adt_extra_opts # * adl_extra_opts # * asdoc_extra_opts # def initialize(env = nil, base_dir = nil, options = nil) env = ENV["AIRAKE_ENV"] if env.nil? base_dir = ENV["AIRAKE_ROOT"] if base_dir.nil? raise "Need to specify an AIRAKE_ROOT (project root)" if base_dir.blank? if options.nil? conf_path = File.join(base_dir, "airake.yml") unless File.exist?(conf_path) raise <<-EOS You are missing your #{conf_path} configuration file. For existing projects, please regenerate an airake project and look at Rakefile and airake.yml for an example. EOS end options = YAML.load_file(File.join(base_dir, "airake.yml")) env_options = options[env] options = options.merge(env_options) if env_options options.symbolize_keys! end @base_dir = base_dir @mxml_path = File.join(base_dir, options[:mxml_path]) @appxml_path = File.join(base_dir, options[:appxml_path]) @src_dirs = options[:src_dirs].collect { |src_dir| File.join(base_dir, src_dir) } @lib_dir = File.join(base_dir, options[:lib_dir]) if options[:lib_dir] # Dest package files @air_path = File.join(base_dir, options[:air_path]) @swf_path = File.join(base_dir, options[:swf_path]) # Debug options @debug = options[:debug] with_keyed_options([ :assets, :certificate, :mxmlc_path, :adt_path, :adl_path, :asdoc_path, :mxmlc_extra_opts, :adt_extra_opts, :adl_extra_opts, :asdoc_extra_opts ], options) ensure_exists([ @mxml_path, @appxml_path, *@src_dirs ]) end # Flex compiler command (under AIR) for this project def amxmlc mxmlc({ :config_name => "air" }) end # Flex compiler command for this project def mxmlc(options = {}) options = options.merge({ :swf_path => @swf_path, :mxml_path => @mxml_path, :lib_dir => @lib_dir, :src_dirs => @src_dirs, :debug => @debug, :mxmlc_extra_opts => @mxmlc_extra_opts, :mxmlc_path => @mxmlc_path }) Airake::Commands::Mxmlc.new(options) end # ADL command for this project def adl options = { :appxml_path => @appxml_path, :base_dir => @base_dir, :adl_extra_opts => @adl_extra_opts, :adl_path => @adl_path } Airake::Commands::Adl.new(options) end # ADT command for this project def adt options = { :air_path => @air_path, :appxml_path => @appxml_path, :swf_path => @swf_path, :base_dir => @base_dir, :assets => @assets, :cert => @certificate, :adt_extra_opts => @adt_extra_opts, :adt_path => @adt_path } Airake::Commands::Adt.new(options) end # AS docs def asdoc src_dirs = [ @src_dir ] options = { :lib_dir => @lib_dir, :src_dirs => @src_dirs, :asdoc_extra_opts => @asdoc_extra_opts, :asdoc_path => @asdoc_path } Airake::Commands::Asdoc.new(options) end # Remove files def clean paths = [ swf_path, air_path ] paths.each do |path| FileUtils.rm(path, :verbose => true) if File.exist?(path) end end protected # Load options into instance vars def with_keyed_options(keys, options) keys.each do |key| value = options[key] instance_variable_set("@#{key}", value) if value end end def ensure_exists(paths) paths.each do |path| raise "Path not found: #{path}" unless File.exist?(path) end end end end