Created
July 18, 2012 16:43
-
-
Save lemieuxster/3137369 to your computer and use it in GitHub Desktop.
Rake/Flash Build example
This file contains hidden or 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/env ruby | |
require "./mxmlc_interface" | |
require "./as3_annotation_parser" | |
BUILD_ANNOTATION_NAME = "Build" | |
PROJECT_DIRECTORY = "/foo" | |
OUTPUT_DIRECTORY = "/foo/output" | |
#Set up compiler settings | |
MXMLCInterface.mxmlc = File.join(ENV["FLEX_HOME"], "/bin/mxmlc") #Flex SDK directory | |
MXMLCInterface.flex_config = File.join(PROJECT_DIRECTORY, "flex-config.xml") #Flex Config XML | |
MXMLCInterface.source_path = File.join(PROJECT_DIRECTORY, "src/main") #Class path for project | |
desc "Builds SWFs" | |
task :build do |t, args| | |
puts "Building SWFs" | |
#Find all .as files and filter by annotation | |
found_files = Array.new | |
if FileTest::directory?(PROJECT_DIRECTORY) | |
Dir.chdir(PROJECT_DIRECTORY) | |
Dir.glob("**/*.as") { |filename| | |
file = File.open(filename, "r") | |
contents = file.read | |
if AS3AnnotationParser.has_annotation contents, BUILD_ANNOTATION_NAME | |
found_files << File.join(Dir.pwd, filename) | |
end | |
} | |
end | |
#Atempt to build each found Build file | |
found_files.each { |filename| | |
basename = File.basename(filename).gsub(/\.as$/, ".swf") | |
success = MXMLCInterface.compile(filename, File.join(OUTPUT_DIRECTORY, basename)) | |
if !success | |
puts "Build failed: #{basename}" | |
Process.abort | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment