Re-wriiten to support Cordova and PhoneGap command-line.