Skip to content

Instantly share code, notes, and snippets.

@Abica
Created January 3, 2010 12:17
Show Gist options
  • Save Abica/267958 to your computer and use it in GitHub Desktop.
Save Abica/267958 to your computer and use it in GitHub Desktop.
a build script for corona applications
#!/usr/bin/env ruby
# this is a build script for corona iphone applications (www.anscamobile.com)
#
# it will combine all lua files and any images inside an image directory into
# a project that you can then build for a device with the corona simulator
#
# the resulting combined project is put inside the build directory
#
# simply put the file inside your current corona project and run it with
# ruby build.rb
main_file = IO.read("main.lua")
app_name = Dir.pwd[ /([^\/]+)\/?$/ ]
build_dir = "build"
app_dir = File.join( build_dir, "#{ app_name }Build" )
app_main_file = File.join( app_dir, "main.lua" )
already_required = []
puts "Merging files"
while editing = main_file[ /require\s?"/ ]
main_file.gsub!( /(require\s?"(\w+)")/ ) do
filename = "#{ $2 }.lua"
if File.exists?( filename )
if already_required.include?( filename )
""
else
already_required << filename
IO.read( filename )
end
else
raise "Cannot find #{ filename }"
end
end
end
unless File.exists?( build_dir )
puts "Creating build/"
Dir.mkdir( build_dir )
end
if File.exists?( app_dir )
puts "Old build found, cleaning up..."
Dir[ File.join( app_dir, "*" ) ].each do | file |
puts "* removing #{ file }"
File.delete( file )
end
else
Dir.mkdir( app_dir )
end
puts "* writing #{ app_main_file }"
open( app_main_file , "w+" ) do | file |
file.write( main_file )
end
if File.exists?( "images" )
puts "* copying images"
`cp images/* #{ app_dir }/`
end
puts "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment