forked from github/cordova-android
Added JS concatenation and copy over to assets/www to build script.
This commit is contained in:
parent
edd0a2caf6
commit
0c585b7416
25
droidgap
25
droidgap
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
class Build
|
class Build
|
||||||
attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir
|
attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir
|
||||||
|
|
||||||
@ -11,17 +12,11 @@ class Build
|
|||||||
|
|
||||||
# runs the build script
|
# runs the build script
|
||||||
def run
|
def run
|
||||||
puts "Building the JAR..."
|
|
||||||
build_jar
|
build_jar
|
||||||
puts "Creating Android project..."
|
|
||||||
create_android
|
create_android
|
||||||
puts "Generating manifest..."
|
|
||||||
generate_manifest
|
generate_manifest
|
||||||
puts "Copying over libraries and assets..."
|
|
||||||
copy_libs
|
copy_libs
|
||||||
puts "Adding some application name to strings.xml..."
|
|
||||||
add_name_to_strings
|
add_name_to_strings
|
||||||
puts "Writing application Java code..."
|
|
||||||
write_java
|
write_java
|
||||||
puts "Complete!"
|
puts "Complete!"
|
||||||
end
|
end
|
||||||
@ -29,6 +24,7 @@ class Build
|
|||||||
# removes local.properties and recreates based on android_sdk_path
|
# removes local.properties and recreates based on android_sdk_path
|
||||||
# then generates framework/phonegap.jar
|
# then generates framework/phonegap.jar
|
||||||
def build_jar
|
def build_jar
|
||||||
|
puts "Building the JAR..."
|
||||||
FileUtils.rm "#{ @dir }framework#{@s}local.properties" if File.exists? "#{ @dir }framework#{@s}local.properties"
|
FileUtils.rm "#{ @dir }framework#{@s}local.properties" if File.exists? "#{ @dir }framework#{@s}local.properties"
|
||||||
FileUtils.rm "#{ @dir }framework#{@s}phonegap.js" if File.exists? "#{ @dir }framework#{@s}phonegap.js"
|
FileUtils.rm "#{ @dir }framework#{@s}phonegap.js" if File.exists? "#{ @dir }framework#{@s}phonegap.js"
|
||||||
FileUtils.rm "#{ @dir }framework#{@s}phonegap.jar" if File.exists? "#{ @dir }framework#{@s}phonegap.jar"
|
FileUtils.rm "#{ @dir }framework#{@s}phonegap.jar" if File.exists? "#{ @dir }framework#{@s}phonegap.jar"
|
||||||
@ -44,6 +40,7 @@ class Build
|
|||||||
# TODO need to allow more flexible SDK targetting
|
# TODO need to allow more flexible SDK targetting
|
||||||
# TODO validate Android SDK
|
# TODO validate Android SDK
|
||||||
def create_android
|
def create_android
|
||||||
|
puts "Creating Android project..."
|
||||||
`android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }`
|
`android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }`
|
||||||
FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www"
|
FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www"
|
||||||
FileUtils.cp_r "#{ @www }#{ @s }.", "#{ @path }#{ @s }assets#{ @s }www#{ @s }"
|
FileUtils.cp_r "#{ @www }#{ @s }.", "#{ @path }#{ @s }assets#{ @s }www#{ @s }"
|
||||||
@ -51,6 +48,7 @@ class Build
|
|||||||
|
|
||||||
# creates an AndroidManifest.xml for the project
|
# creates an AndroidManifest.xml for the project
|
||||||
def generate_manifest
|
def generate_manifest
|
||||||
|
puts "Generating manifest..."
|
||||||
manifest = ""
|
manifest = ""
|
||||||
open(@dir + 'framework/AndroidManifest.xml', 'r') do |old|
|
open(@dir + 'framework/AndroidManifest.xml', 'r') do |old|
|
||||||
manifest = old.read
|
manifest = old.read
|
||||||
@ -65,6 +63,7 @@ class Build
|
|||||||
# copies stuff from framework into the project
|
# copies stuff from framework into the project
|
||||||
# TODO need to allow for www import inc icon
|
# TODO need to allow for www import inc icon
|
||||||
def copy_libs
|
def copy_libs
|
||||||
|
puts "Copying over libraries and assets and creating phonegap.js..."
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs"
|
FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs"
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml"
|
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml"
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.xml"
|
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.xml"
|
||||||
@ -72,10 +71,23 @@ class Build
|
|||||||
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
|
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png"
|
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png"
|
||||||
end
|
end
|
||||||
|
# concat JS and put into www folder.
|
||||||
|
Dir.chdir("#{ @dir }framework#{ @s }assets#{ @s }js")
|
||||||
|
basedir = "."
|
||||||
|
js = Dir.new(basedir).entries
|
||||||
|
phonegapjs = ""
|
||||||
|
js.each do |script|
|
||||||
|
next if script[0].chr == "."
|
||||||
|
phonegapjs += IO.read(script)
|
||||||
|
phonegapjs += "\n\n"
|
||||||
|
end
|
||||||
|
Dir.chdir("#{ @dir}")
|
||||||
|
File.open("#{ @path }#{ @s }assets#{ @s }www#{ @s }phonegap.js", 'w') {|f| f.write(phonegapjs) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# puts app name in strings
|
# puts app name in strings
|
||||||
def add_name_to_strings
|
def add_name_to_strings
|
||||||
|
puts "Adding some application name to strings.xml..."
|
||||||
x = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
x = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name=\"app_name\">#{ @name }</string>
|
<string name=\"app_name\">#{ @name }</string>
|
||||||
@ -90,6 +102,7 @@ class Build
|
|||||||
# this is so fucking unholy yet oddly beautiful
|
# this is so fucking unholy yet oddly beautiful
|
||||||
# not sure if I should thank Ruby or apologize for this abusive use of string interpolation
|
# not sure if I should thank Ruby or apologize for this abusive use of string interpolation
|
||||||
def write_java
|
def write_java
|
||||||
|
puts "Writing application Java code..."
|
||||||
j = "
|
j = "
|
||||||
package #{ @pkg };
|
package #{ @pkg };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user