#!/usr/local/bin/ruby # Path to your Flex library installation. FLEX_PATH = '/Users/cantrell/lib/flex' # Path to your ActionScript libraries. The optional '$' represents the portion # of the path which changes for each directory. You can add multiple directories # by separating them with ':'. If you don't wnat to include a classpath, make # this nil. AS_LIB_PATH = '/Users/cantrell/Projects/adobe/labs/flashplatform/projects/$/trunk/src/actionscript3' # Passing in the -t option will cause the log file specified below to be tailed # after compilation. TAIL_PATH = '/Users/cantrell/logs/flash.txt' # Passing in the -o option will cause the compiled SWF to open in the application # below. OPEN_APP = 'firefox' ## End configuration ## def usage puts "\nusage: mxmlc.rb [-htosc] [compiler flags] file\n\n" puts '-h: Help. Prints this help.' puts '-t: Tail. After compilation, tails the file specified by the TAIL_PATH variable.' puts '-o: Open. After compilation, opens the generated swf in the application specified by the OPEN_APP variable.' puts '-s: Show. Show the compilation command rather than actually running it. Good for debugging.' puts "-c: Clean. Remove cache files before compilation.\n\n" puts 'Note: Any additional arguments will be passed directly to the compiler.' puts "Note: The incremental flag is automatically included." puts "Note: Flags must be passed in individually like -o -t, not -ot.\n\n" exit end usage if ARGV.length < 1 # Start building the command. Point to the jar. command = "java -jar #{FLEX_PATH}/lib/mxmlc.jar" # Point to the framework. command << " -flexlib #{FLEX_PATH}/frameworks" # Split up the AS_LIB_PATH variable. if AS_LIB_PATH != nil command << " -actionscript-classpath" as_path_array = AS_LIB_PATH.split(':') as_path_array.each do |path| if path.count('$') != 0 as_path_parts = path.split('$') as_path_start = as_path_parts[0] as_path_end = as_path_parts[1] Dir.foreach(as_path_start) do |dir| # No files that start with dots. file_to_add = "#{as_path_start}#{dir}#{as_path_end}" unless dir =~ /^\./ || !File.exists?(file_to_add) command << " #{file_to_add}" end end else command << " #{path}" end end end # Parse options. open, tail, show_command = nil ARGV.each do |arg| case arg when '-h' usage when '-t' tail = 1 when '-o' open = 1 when '-s' show_command = 1 when '-c' puts 'Removing cache files.' rmc = "rm #{ARGV.last.sub(/\.as|\.mxml/, '_')}*.cache" `#{rmc}` else command << " #{arg}" if arg != ARGV.last end end command << " -incremental #{ARGV.last}" if show_command puts command else `#{command}` end `open -a #{OPEN_APP} #{ARGV.last.sub(/\.as|\.mxml/, '.swf')}` if open exec("tail -f #{TAIL_PATH}") if tail