Created
September 1, 2011 01:08
-
-
Save pengwynn/1185160 to your computer and use it in GitHub Desktop.
Build titanium
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
require 'rubygems' | |
require 'nokogiri' | |
require 'colored' | |
PROJECT_NAME="GolfStatus" | |
PROJECT_ROOT = File.dirname(__FILE__) | |
IPHONE_SDK_VERSION="4.3" | |
TI_SDK_VERSION="1.6.2" | |
TI_DIR='/Library/Application\ Support/Titanium' | |
TI_ASSETS_DIR="#{TI_DIR}/mobilesdk/osx/#{TI_SDK_VERSION}" | |
TI_IPHONE_DIR="#{TI_ASSETS_DIR}/iphone" | |
TI_BUILD="#{TI_IPHONE_DIR}/builder.py" | |
APP_DEVICE="iphone" | |
# Get APP parameters from current tiapp.xml | |
config = File.open("tiapp.xml") | |
doc = Nokogiri::XML(config) | |
config.close | |
APP_ID = doc.xpath('ti:app/id').text | |
APP_NAME = doc.xpath('ti:app/name').text | |
task :default => ["build:iphone"] | |
namespace :compile do | |
desc "Compile all assets" | |
task :all do | |
compile | |
end | |
desc "Compile Sass into JSS" | |
task :styles do | |
compile_sass | |
end | |
desc "Compile CoffeeScript into JS" | |
task :coffee do | |
compile_coffee | |
end | |
end | |
namespace :build do | |
desc "build the app for iPhone" | |
task :iphone do | |
build | |
end | |
end | |
def compile | |
compile_coffee && compile_sass | |
end | |
def compile_sass | |
puts "Compiling stylesheets".blue | |
compilation = system "sass --compass -C -t expanded stylesheets/app.sass > Resources/app.jss" | |
end | |
def compile_coffee | |
paths = `find src/golf_status -name '*.coffee'`.split("\n") | |
compilation = ( | |
puts "Compiling CoffeeScript (golf_status.js)".blue | |
system "coffee --join Resources/golf_status.js -b -c #{paths.join(' ')}" and | |
puts "Compiling CoffeeScript (app.js)".blue | |
system "coffee -p --bare src/app.coffee > Resources/app.js" | |
) | |
if compilation | |
puts "Successfully compiled CoffeeScript".green | |
else | |
puts "Error compiling CoffeeScript".red | |
end | |
compilation | |
end | |
def build(options={}) | |
return unless compile | |
options[:device] ||= 'iphone' | |
puts "Building with Titanium... (DEVICE_TYPE:#{options[:device]})".blue | |
sh %Q{bash -c "#{TI_BUILD} run #{PROJECT_ROOT}/ #{IPHONE_SDK_VERSION} #{APP_ID} #{APP_NAME} #{APP_DEVICE}" \ | |
| perl -pe 's/^\\[DEBUG\\].*$/\\e[35m$&\\e[0m/g;s/^\\[INFO\\].*$/\\e[36m$&\\e[0m/g;s/^\\[WARN\\].*$/\\e[33m$&\\e[0m/g;s/^\\[ERROR\\].*$/\\e[31m$&\\e[0m/g;'} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment