2010-08-04 06:10:56 +08:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require 'fileutils'
|
|
|
|
|
2010-08-31 06:57:07 +08:00
|
|
|
class Update
|
2010-08-04 06:10:56 +08:00
|
|
|
attr_reader :android_sdk_path, :path
|
|
|
|
|
2010-08-31 06:57:07 +08:00
|
|
|
def initialize
|
|
|
|
@path = FileUtils.pwd
|
2010-09-01 04:21:23 +08:00
|
|
|
@android_sdk_path = Dir.getwd[0,1] != "/" ? `android-sdk-path.bat android.bat`.gsub('\\tools','').gsub('\\', '\\\\\\\\') : `which android`.gsub('/tools/android','')
|
2010-08-31 06:57:07 +08:00
|
|
|
@android_dir = File.expand_path(File.dirname(__FILE__))
|
|
|
|
@framework_dir = File.join(@android_dir, "..", "framework")
|
|
|
|
# puts "updating #{ @path } with phonegap from #{ @android_dir }"
|
2010-08-04 06:10:56 +08:00
|
|
|
build_jar
|
|
|
|
copy_libs
|
2010-08-31 06:57:07 +08:00
|
|
|
end
|
2010-08-04 06:10:56 +08:00
|
|
|
|
|
|
|
# removes local.properties and recreates based on android_sdk_path
|
2010-12-01 09:00:30 +08:00
|
|
|
# then generates framework/phonegap.jar & framework/assets/www/phonegap.js
|
2010-08-04 06:10:56 +08:00
|
|
|
def build_jar
|
2010-12-01 09:00:30 +08:00
|
|
|
puts "Building the JAR and combining JS files..."
|
2010-08-04 06:10:56 +08:00
|
|
|
%w(local.properties phonegap.js phonegap.jar).each do |f|
|
|
|
|
FileUtils.rm File.join(@framework_dir, f) if File.exists? File.join(@framework_dir, f)
|
|
|
|
end
|
|
|
|
open(File.join(@framework_dir, "local.properties"), 'w') do |f|
|
|
|
|
f.puts "sdk.dir=#{ @android_sdk_path }"
|
|
|
|
end
|
|
|
|
Dir.chdir(@framework_dir)
|
|
|
|
`ant jar`
|
|
|
|
Dir.chdir(@android_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
# copies stuff from framework into the project
|
|
|
|
# TODO need to allow for www import inc icon
|
|
|
|
def copy_libs
|
2010-12-01 09:00:30 +08:00
|
|
|
puts "Copying over libraries and assets..."
|
2011-06-04 01:59:48 +08:00
|
|
|
version = IO.read(File.join(@framework_dir, '../VERSION'))
|
2010-08-04 06:10:56 +08:00
|
|
|
|
2011-06-04 01:59:48 +08:00
|
|
|
FileUtils.cp File.join(@framework_dir, "phonegap.#{ version }.jar"), File.join(@path, "libs")
|
|
|
|
|
|
|
|
# concat JS and put into www folder. this can be overridden in the config.xml via @app_js_dir
|
|
|
|
js_dir = File.join(@framework_dir, "assets", "js")
|
|
|
|
phonegapjs = IO.read(File.join(js_dir, 'phonegap.js.base'))
|
|
|
|
Dir.new(js_dir).entries.each do |script|
|
|
|
|
next if script[0].chr == "." or script == "phonegap.js.base"
|
|
|
|
phonegapjs << IO.read(File.join(js_dir, script))
|
|
|
|
phonegapjs << "\n\n"
|
|
|
|
end
|
|
|
|
File.open(File.join(@path, "assets", "www", "phonegap.#{ version }.js"), 'w') {|f| f.write(phonegapjs) }
|
2010-08-04 06:10:56 +08:00
|
|
|
end
|
|
|
|
#
|
|
|
|
end
|