Created
June 13, 2010 07:34
-
-
Save tkdave/436440 to your computer and use it in GitHub Desktop.
MXMLC build script written in Ruby that extracts MXMLC command line parameters from the @mxmlc javadoc tag inside the AS3 file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
## | |
# MXMLC Quickbuild Script v.2010-06-13 | |
# | |
# Based on the Quickbuild feature found in FlashDevelop: | |
# http://www.flashdevelop.org/wikidocs/index.php?title=QuickBuild | |
# | |
# Author: | |
# David Knape, http://www.bumpslide.com/ | |
# | |
# Usage: | |
# quickbuild [-n] filename | |
# | |
# Options: | |
# -n No Launch, just build. | |
# | |
# This ruby script is meant to be run from the command line or | |
# from an IDE that has been configured to launch an external tool. | |
# | |
# The input file is used as the target for a call to mxmlc. | |
# Compiler options are parsed from the @mxmlc comment doc attribute. | |
# | |
# Example @mxmlc tag in AS3 Class: | |
# | |
# package { | |
# import flash.display.*; | |
# import flash.text.*; | |
# /** | |
# * Compile with $ quickbuild TestApp.as | |
# * @mxmlc -target-player=10 -static-link-runtime-shared-libraries -debug -default-size 500 200 -o test.swf | |
# */ | |
# public class TestApp extends Sprite { | |
# public function TestApp() { | |
# with(graphics){beginFill(0xDF6559);drawRect(10,10,480,180);endFill();} | |
# with(addChild(new TextField()) as TextField){ x=y=20; width=500; | |
# defaultTextFormat=new TextFormat('Arial', 30, 0xFFFFFF,true); | |
# text="Hello, Bumpslide Quickbuild."; }; | |
# } } } | |
## | |
# Use FLEX_HOME environment var to find MXMLC | |
MXMLC=ENV["FLEX_HOME"]+"/bin/mxmlc" | |
# Alternative: harcode path to MXMLC | |
#MXMLC="/Users/tkdave/resources/flash/lib/flex4_sdk/bin/mxmlc" | |
launch_swf=true | |
target_file="" | |
mxmlc_args="" | |
output_file="" | |
# if -n argument is specified, don't launch the swf | |
ARGV.each do|a| | |
launch_swf=false if a=='-n' | |
target_file=a | |
end | |
if(target_file==""): | |
print "\nYou must specify an ActionScript or MXML file to build.\n\n" | |
print "Usage: \n quickbuild [-n] filename \n\n" | |
print "Options:\n -n No Launch, just build. \n\n" | |
print "Example:\n $ quickbuild MyApp.mxml \n\n" | |
exit | |
end | |
# find line in file containing @mxmlc and get everything after that token as mxmlc args | |
File.open( target_file ).each { |line| | |
if line=~/.*@mxmlc.*/ then | |
mxmlc_args = line.split( "@mxmlc" ).pop.strip | |
break | |
end | |
} | |
# check for output file specified in mxmlc args | |
output_file=mxmlc_args.scan(/-o\s+(\S+)/) | |
if(output_file.length==0) then | |
f = target_file.split('.') | |
f.pop | |
output_file = f.join('.')+".swf" | |
end | |
print "#{MXMLC} #{mxmlc_args} #{target_file}\n" | |
system( "#{MXMLC} #{mxmlc_args} #{target_file}" ) | |
if($?==0 && launch_swf) then | |
system("open #{output_file}") | |
exit 0 | |
else | |
exit 1 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment