2010-08-31 06:57:07 +08:00
#!/usr/bin/env ruby
ROOT = File.expand_path(File.dirname(__FILE__).gsub('bin',''))
require 'fileutils'
require File.join(ROOT, "lib", "generate.rb")
2010-09-06 05:32:16 +08:00
require File.join(ROOT, "lib", "classic.rb")
2010-09-01 06:40:19 +08:00
require File.join(ROOT, "lib", "create.rb")
2010-08-31 06:57:07 +08:00
require File.join(ROOT, "lib", "run.rb")
require File.join(ROOT, "lib", "update.rb")
2010-09-06 05:32:16 +08:00
require File.join(ROOT, "lib", "test.rb")
2010-08-31 06:57:07 +08:00
# ---------------------------------------------------------- #
# #
# command line interface #
# #
# ---------------------------------------------------------- #
# droidgap gen [app name]
Generate.new(ARGV[1]) if ARGV.first == 'gen'
2010-09-06 05:32:16 +08:00
# droidgap classic (for windows users mostly)
Classic.new(ARGV[1..-1]) if ARGV.first == 'classic'
2010-09-01 06:40:19 +08:00
# droidgap create [path to phonegap project]
Create.new(ARGV[1]) if ARGV.first == 'create'
2010-08-31 06:57:07 +08:00
# droidgap run [optional directory]
2010-09-01 07:50:39 +08:00
Run.new if ARGV.first == 'run'
2010-08-31 06:57:07 +08:00
# droidgap update [params]
Update.new if ARGV.first == 'update'
# droidgap log
if ARGV.first == 'log'
$stdout.sync = true
IO.popen('adb logcat') do |f|
until f.eof?
puts f.gets
end
end
end
2010-09-06 05:32:16 +08:00
# droidgap test
Test.new if ARGV.first == 'test'
2010-09-01 06:40:19 +08:00
# TODO implement these!
2010-08-31 06:57:07 +08:00
puts "droidgap ship not implemented" if ARGV.first == 'ship'
if ARGV.first.nil? || ARGV.first == 'help'
help = <<-EOF
DroidGap: PhoneGap/Android Dev Script
-------------------------------------
Useful utilities for devlopers building mobile apps using PhoneGap for Android.
Usage:
droidgap <command> <parameters>
Commands:
2010-09-06 05:32:16 +08:00
help ...... See this message. Type help [command name] to see specific help topics.
gen ....... Generate an example PhoneGap application to current directory.
create .... Creates an Android compatible project from a www folder. Careful, this clobbers previous packaging.
classic ... Backwards support for droidgap script. Run "droidgap help classic" for more info.
run ....... Installs a valid PhoneGap Project to first device found.
log ....... Attach a logger that listens for console.log statements.
update .... Copy a fresh phonegap.jar and phonegap.js into a valid PhoneGap/Android project.
test ...... Gets edge copy of mobile-spec and runs in first device or emulator attached.
ship ...... Build and sign an APK suitable for submission to an Android Marketplace.
2010-08-31 06:57:07 +08:00
Quickstart:
$ droidgap gen example
$ cd example
2010-09-06 05:32:16 +08:00
$ droidgap create
$ cd ../example_android
2010-08-31 06:57:07 +08:00
$ droidgap run
Now you can launch your app and optionally start a logger with:
$ droidgap log
EOF
gen = <<-EOF
DroidGap Generate
-----------------
Generate an example PhoneGap application to path supplied or current working directory if none is supplied.
Usage:
droidgap gen [path]
EOF
run = <<-EOF
DroidGap Run
------------
Launches PhoneGap project to first device found and attaches a logger that listens for console.log statements.
Usage:
droidgap run <path>
EOF
ship = <<-EOF
DroidGap Ship
-------------
Build and sign an APK suitable for submission to an Android Marketplace.
Usage:
droidgap ship <path>
EOF
log = <<-EOF
DroidGap Log
-------------
Launches LogCat
Usage:
droidgap log
EOF
2010-09-01 06:40:19 +08:00
create = <<-EOF
2010-08-31 06:57:07 +08:00
2010-09-01 06:40:19 +08:00
DroidGap Create
2010-08-31 06:57:07 +08:00
----------------
2010-09-01 04:08:07 +08:00
Creates an Android compatable project from a PhoneGap project. For example, if you have MyProject with index.html this command will create MyProject-android.
2010-08-31 06:57:07 +08:00
Usage:
2010-09-01 06:40:19 +08:00
droidgap create <path>
2010-08-31 06:57:07 +08:00
EOF
update = <<-EOF
2010-09-01 06:40:19 +08:00
DroidGap Update
~~~~~~~~~~~~~~~
2010-08-31 06:57:07 +08:00
2010-09-01 06:40:19 +08:00
Builds the JS and PhoneGap Android jar file and copies them to your project.
2010-08-31 06:57:07 +08:00
EOF
2010-09-06 05:32:16 +08:00
classic = <<-EOF
DroidGap Classic
~~~~~~~~~~~~-~~~
Compatability for older droidgap scripts.
Usage:
droidgap classic [android_sdk_path] [name] [package_name] [www] [path]
android_sdk_path ... The path to your Android SDK install.
name ............... The name of your application.
package_name ....... The name of your package (For example: com.nitobi.demo)
www ................ The path to your www folder. (Wherein your HTML, CSS and JS app is.)
path ............... The path to generate the application.
EOF
2010-08-31 06:57:07 +08:00
puts ARGV[1].nil? ? help : eval(ARGV[1])
end