Creating a new project
Creating a new PhoneGap project is easy thanks to PhoneGap CLI. Unlike older versions of PhoneGap, where we needed to download the project template manually, we can create new projects directly from the command line. With just a single command, we can create a new project and start writing our application.
How to do it…
To create a new PhoneGap project, open your terminal or cmd
. Then go to the directory where you want to maintain your source code. Run the following command:
phonegap create hello com.myapp.hello HelloWorld
It may take some time to complete the process, so be patient and let PhoneGap CLI do its magic. You will see some message during the project creation process:
Congratulations! You have created your first PhoneGap project. Now, let's browse the project directory. You will see the directories as shown in the following screenshot:
Most of the directories are empty; we will discuss the use of each directory later in the next recipe. The www/
directory is where you write code for your application. PhoneGap generated the initial starter app to work with.
How it works…
The phonegap create
command is a command used to create a new project. The first argument, hello
, specifies a directory for your project. Note that this directory must not exist initially; phonegap
will create it for you.
The second argument, com.myapp.hello
, is your application ID. The application ID is used as a unique identifier for an application. Two identical applications with different application IDs will be considered two different applications. The application ID is in reverse domain style. You can create something like com.yourdomain.applicationname
.
The third argument, HelloWorld
, is your application name. The application name will be used as the application's display title. This argument is optional. If you are not setting the application name, it will use the name from the first argument. If you want to change the name, you can open config.xml
and edit the name
element.
While we are running the phonegap create
command, there are several things happening in the background:
- The
phonegap
creates a new PhoneGap project with the given name and ID in the newly created directory. In our case, a PhoneGap project with the name asHelloWorld
and ID ascom.myapp.hello
will be created under thehello
directory. - The
phonegap
downloads the starter application and places it inwww/
so that we can run the project directly after creating it.Tip
You can use the
-d
option with anyphonegap
command to allow a verbose output. The-d
option will give clear information about what is going on and the current status of the command.