PhoneGap – Create New Project
I have just started with PhoneGap. First impressions are overly positive, though I see one subtle detail worth improving – the create script. Documentation (Android) suggests to invoke the script from within the installation directory. It can obviously be called using the absolute path from any location, but either way I find it too much of a hassle. In this post, I want to share a simple solution I have created to save myself some typing.
I have two objections when it comes to the create script which ships with PhoneGap:
- having to navigate deep into the installation directory or type a lengthy absolute path
- too many arguments
Let me explain my second point. PhoneGap documentation says:
#! /bin/bash #### GENERAL SETTINGS #### phonegap_home=~/development/phonegap-2.5.0 project_root=~/development/phonegap-apps #### INPUT VALIDATION #### function quit { echo "Usage:" echo "$0 [android | ios] project_name package_name" exit 1 } if [ ! $# -eq 3 ]; then quit; fi case $1 in android|ios) ;; *) echo "$1 is an unsupported platform"; quit esac project_dir=$project_root/$2 if [ -d "$project_dir" ]; then echo "$project_dir already exists"; quit fi #### PHONEGAP CREATE #### $phonegap_home/lib/$1/bin/create $project_dir $3 $2 echo "Project successfully created at $project_dir" exit 0
I saved the script as ~/bin/phonegap_create and updated the PATH variable in ~/.bash_profile:
export PATH=${PATH}:~/bin
That’s all. Here is how I create a new Android project:
phonegap_create android hello_world org.zezutom.helloworld
Output:
$ls -l ~/development/phonegap-apps/hello_world/ total 48 -rw-r--r-- 1 tom staff 3309 31 Mar 23:39 AndroidManifest.xml -rw-r--r-- 1 tom staff 698 31 Mar 23:39 ant.properties drwxr-xr-x@ 3 tom staff 102 31 Mar 23:39 assets drwxr-xr-x 2 tom staff 68 31 Mar 23:39 bin -rw-r--r-- 1 tom staff 3923 31 Mar 23:39 build.xml drwxr-xr-x 9 tom staff 306 31 Mar 23:39 cordova drwxr-xr-x 3 tom staff 102 31 Mar 23:39 libs -rw-r--r-- 1 tom staff 451 31 Mar 23:39 local.properties -rw-r--r-- 1 tom staff 781 31 Mar 23:39 proguard-project.txt -rw-r--r-- 1 tom staff 563 31 Mar 23:39 project.properties drwxr-xr-x@ 10 tom staff 340 31 Mar 23:39 res drwxr-xr-x 3 tom staff 102 31 Mar 23:39 src
Similarly for iOS I do:
$phonegap_create ios hello_world org.zezutom.helloworld
Which gives me:
$ls -l ~/development/phonegap-apps/hello_world/ total 0 drwxr-xr-x 6 tom staff 204 31 Mar 23:51 CordovaLib drwxr-xr-x@ 7 tom staff 238 31 Mar 23:51 cordova drwxr-xr-x@ 10 tom staff 340 31 Mar 23:51 hello_world drwxr-xr-x@ 3 tom staff 102 31 Mar 23:51 hello_world.xcodeproj drwxr-xr-x@ 10 tom staff 340 31 Mar 23:51 www